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

Quick Search    Search Deep

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


1   package com.arranger.jarl.base;
2   
3   import com.arranger.jarl.util.JarlInfoUtil;
4   import com.arranger.jarl.util.ObjectUtil;
5   import com.arranger.jarl.util.StringTools;
6   import org.w3c.dom.Element;
7   
8   /**
9    * BaseJarlObject created on Feb 26, 2003
10   * @widgetAttribute zOrder ## xs:integer ## the order of this widget
11   * @traitAttribute zOrder ## xs:integer ## the order of this trait
12   * @strokeAttribute zOrder ## xs:integer ## the order of this stroke
13   * @filterAttribute zOrder ## xs:integer ## the order of this filter
14   *
15   * @widgetAttribute useAbsoluteTime ## xs:boolean ## if true, then never be 'fooled' by a hold or echo collection
16   * @traitAttribute useAbsoluteTime ## xs:boolean ## if true, then never be 'fooled' by a hold or echo collection
17   * @strokeAttribute useAbsoluteTime ## xs:boolean ## if true, then never be 'fooled' by a hold or echo collection
18   * @filterAttribute useAbsoluteTime ## xs:boolean ## if true, then never be 'fooled' by a hold or echo collection
19   */
20  public abstract class BaseJarlObject implements IJarlObject {
21  
22      protected Element m_configElement;
23      protected int m_zOrder = 0;
24      protected boolean m_useAbsoluteTime;
25      protected String m_className = getName();
26  
27      protected transient Time m_cachedTime;
28  
29      /**
30       * Initialize this object
31       * @param context the global context
32       * @param element the element containing config info
33       */
34      public void init(IContext context, Element element) {
35          m_configElement = element;
36          initAttributes(context);
37      }
38  
39      /**
40       * Initialize this object
41       * @param context the global context
42       * @param element the element containing config info
43       */
44      public void initDef(IContext context, Element element) {
45          m_configElement = element;
46          initAttributes(context);
47      }
48  
49      public void preCheckTime(IContext context) {
50          if (m_useAbsoluteTime) {
51              m_cachedTime = context.getTime();
52              context.setTime(context.getAbsoluteTime());
53          }
54      }
55  
56      public void postCheckTime(IContext context) {
57          if (m_useAbsoluteTime) {
58              context.setTime(m_cachedTime);
59          }
60      }
61  
62      /**
63       * @return the zorder of the object
64       */
65      public int getZOrder() {
66          return m_zOrder;
67      }
68  
69      /**
70       * Set the zOrder of this object
71       * @param zOrder
72       */
73      public void setZOrder(int zOrder) {
74          m_zOrder = zOrder;
75      }
76  
77      public Object clone() {
78          try {
79              return super.clone();
80          } catch (CloneNotSupportedException e) {
81              throw new InternalError();
82          }
83      }
84  
85      public Element getConfigElement() {
86          return m_configElement;
87      }
88  
89      /**
90       * @return the info for this object
91       */
92      public IJarlObjectInfo getJarlObjectInfo() {
93          IJarlObjectInfo jarlObjectInfo = new BaseJarlObjectInfo(null, null, null);
94          addJarlObjectInfo(jarlObjectInfo);
95          return jarlObjectInfo;
96      }
97  
98      /**
99       * Override this, and for every field that you're using, call {@link #populateInfo}
100      * for example:
101      * <code>
102      *   populateInfo(jarlObjectInfo, "zOrder", "Z-Order", JarlInfoUtil.PRIMITIVE_DISPLAY);
103      * </code>
104      *
105      * @param jarlObjectInfo
106      *
107      * @see JarlInfoUtil#PRIMITIVE_DISPLAY
108      * @see #populateInfo
109      * @see ObjectUtil#initializeField
110      */
111     protected void addJarlObjectInfo(IJarlObjectInfo jarlObjectInfo) {
112         populateInfo(jarlObjectInfo, "className", "Class Name", JarlInfoUtil.PRIMITIVE_DISPLAY);
113         populateInfo(jarlObjectInfo, "zOrder", "Z-Order", JarlInfoUtil.PRIMITIVE_DISPLAY);
114         populateInfo(jarlObjectInfo, "useAbsoluteTime", "Use AbsoluteTime", JarlInfoUtil.PRIMITIVE_DISPLAY);
115     }
116 
117     /**
118      * Always remember some attrs might not be there
119      * @param context
120      */
121     protected void initAttributes(IContext context) {
122         ObjectUtil.initializeField("zOrder", m_configElement, this, ObjectUtil.PRIMITIVE_CONVERSION);
123         ObjectUtil.initializeField("useAbsoluteTime", m_configElement, this, ObjectUtil.PRIMITIVE_CONVERSION);
124     }
125 
126     protected String getName() {
127         return StringTools.getLastSegment(getClass().getName(), ".", false);
128     }
129 
130     /**
131      * for example:
132      * <code>
133      *   populateInfo(jarlObjectInfo, "zOrder", "Z-Order", JarlInfoUtil.PRIMITIVE_DISPLAY);
134      * </code>
135      *
136      * @param jarlObjectInfo
137      * @param fieldName the name of the field without the m_ prefix
138      * @param displayName
139      * @param jarlObjectDisplay
140      * @return the same jarlObjectInfo
141      */
142     protected IJarlObjectInfo populateInfo(IJarlObjectInfo jarlObjectInfo,
143                                            String fieldName,
144                                            String displayName,
145                                            IJarlObjectInfo.IJarlObjectDisplay jarlObjectDisplay) {
146         return JarlInfoUtil.populateInfo(this, jarlObjectInfo, fieldName, displayName, jarlObjectDisplay);
147     }
148 }