Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/arranger/jarl/base/Time.java


1   package com.arranger.jarl.base;
2   
3   import org.w3c.dom.Element;
4   import com.arranger.jarl.util.StringTools;
5   
6   /**
7    * Time is the abstraction for time.
8    * Don't know if this is frames, or seconds, or measures, or what...
9    */
10  public class Time implements Cloneable {
11  
12      protected static double m_framesPerSec = 10;
13      protected int m_frame;
14  
15      public static void init(Element elem) {
16          String framesPerSec = elem.getAttribute("framesPerSec");
17          if (!StringTools.isEmpty(framesPerSec)) {
18              m_framesPerSec = Double.parseDouble(framesPerSec);
19          }
20      }
21  
22      public static double getFramesPerSec() {
23          return m_framesPerSec;
24      }
25  
26      public Time(int frame) {
27          m_frame = frame;
28      }
29  
30      public int getFrame() {
31          return m_frame;
32      }
33  
34      public void setFrame(int frame) {
35          m_frame = frame;
36      }
37  
38      public void increment() {
39          m_frame++;
40      }
41  
42      /**
43       * Returns true if this object is less then the other
44       * @param other what to compare
45       * @return true if this object is less then other
46       */
47      public boolean isLess(Time other) {
48          return m_frame < other.m_frame;
49      }
50  
51      /**
52       * Returns true if this object is greater then the other
53       * @param other to compare
54       * @return true if this object is greater then the other
55       */
56      public boolean isGreater(Time other) {
57          return m_frame > other.m_frame;
58      }
59  
60      public boolean equals(Object other) {
61          if (!(other instanceof Time)) {
62              return false;
63          }
64  
65          return ((Time)other).m_frame == m_frame;
66      }
67  
68      public String toString() {
69          return "Time : " + m_frame;
70      }
71  
72      public int hashCode() {
73          return m_frame;
74      }
75  
76      public static Time getTime(Element element, String attrName) {
77          String val = element.getAttribute(attrName);
78          return getTime(val);
79      }
80  
81      public static Time getTime(String val) {
82         if (StringTools.isEmpty(val)) {
83              return new Time(-1);
84          } else {
85              if (val.indexOf((int)'s') != -1) {
86                  val = val.substring(0, val.length() - 1);
87                  double seconds = Double.parseDouble(val);
88                  int frame = (int)(seconds * m_framesPerSec);
89                  return new Time(frame);
90              } else {
91                  int frame = Integer.parseInt(val);
92                  return new Time(frame);
93              }
94          }
95      }
96  
97      public Object clone() {
98          try {
99              return super.clone();
100         } catch (CloneNotSupportedException e) {
101             e.printStackTrace();
102         }
103         return this;
104     }
105 }