KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > module > builders > AnnotRel


1 /*
2
3 This software is OSI Certified Open Source Software.
4 OSI Certified is a certification mark of the Open Source Initiative.
5
6 The license (Mozilla version 1.0) can be read at the MMBase site.
7 See http://www.MMBase.org/license
8
9 */

10 package org.mmbase.module.builders;
11
12 import java.text.SimpleDateFormat JavaDoc;
13 import java.util.*;
14
15 import org.mmbase.module.core.MMObjectNode;
16 import org.mmbase.module.corebuilders.InsRel;
17 import org.mmbase.util.*;
18 import org.mmbase.util.logging.*;
19
20 /**
21  * @javadoc
22  * @application Tools
23  * @author David van Zeventer
24  * @version $Id: AnnotRel.java,v 1.22 2005/10/06 17:46:39 michiel Exp $
25  */

26 public class AnnotRel extends InsRel {
27
28     // Defining possible annotation types
29
public final static int HOURS = 0;
30     public final static int MINUTES = 1;
31     public final static int SECONDS = 2;
32     public final static int MILLIS = 3;
33     /*
34         public final static int LINES = 4;
35         public final static int WORDS = 5;
36         public final static int CHARS = 6;
37         public final static int PIXELS = 7;
38         public final static int ROWS = 8;
39         public final static int COLS = 9;
40     */

41
42     private static final Logger log = Logging.getLoggerInstance(AnnotRel.class);
43
44     /**
45      * Sets defaults for a node.
46      * Initializes all numeric fields to 0, and sets the annotation type to {@link #MILLIS}.
47      * @param node The node to set the defaults of.
48      */

49     public void setDefaults(MMObjectNode node) {
50         super.setDefaults(node);
51         // Set the default value for pos and length to 0 (0:0:0.0)
52
node.setValue("pos", 0);
53         node.setValue("end", 0);
54         node.setValue("length", 0);
55         // All time values are default stored in milliseconds.
56
node.setValue("type", MILLIS);
57     }
58
59     /**
60      * What should a GUI display for this node/field combo.
61      * Displays the pos, end, and length fields as time-values,
62      * and the annotation type field as a descriptive string.
63      * @param node The node to display
64      * @param field the name field of the field to display
65      * @return the display of the node's field as a <code>String</code>, null if not specified
66      */

67     public String JavaDoc getGUIIndicator(String JavaDoc field, MMObjectNode node) {
68         if (field.equals("pos")) {
69             int time = node.getIntValue("pos");
70             return RelativeTime.convertIntToTime(time);
71         } else if (field.equals("end")) {
72             int time = node.getIntValue("end");
73             return RelativeTime.convertIntToTime(time);
74         } else if (field.equals("length")) {
75             int time = node.getIntValue("length");
76             return RelativeTime.convertIntToTime(time);
77         } else if (field.equals("type")) {
78             int val = node.getIntValue("type");
79             if (val == HOURS) {
80                 return "Hours";
81             } else if (val == MINUTES) {
82                 return "Minuten"; // return "Minutes";
83
} else if (val == SECONDS) {
84                 return "Seconden"; // return "Seconds";
85
} else if (val == MILLIS) {
86                 return "Milliseconden"; // return "Milliseconds";
87
}
88
89             /*
90               else if (val==LINES) {
91                 return "Regels";
92             } else if (val==WORDS) {
93                 return "Woorden";
94             } else if (val==CHARS) {
95                 return "Karakters";
96             } else if (val==PIXELS) {
97                 return "Pixels";
98             } else if (val==ROWS) {
99                 return "Rijen";
100             } else if (val==COLS) {
101                 return "Kolommen";
102             }
103             */

104         }
105         return null;
106     }
107
108     /**
109      * The hook that passes all form related pages to the correct handler.
110      * This method is not supported.
111      * @param sp The PageInfo
112      * @param cmds the commands (PRC-CMD) to process
113      * @param vars variables (PRC-VAR) to use
114      * @return the result value as a <code>String</code>
115      */

116     public boolean process(PageInfo sp, Hashtable cmds, Hashtable vars) {
117         log.debug("process: This method isn't implemented yet.");
118         return false;
119     }
120
121     /**
122      * Obtains a string value by performing the provided command.
123      * This method is not supported.
124      * @param sp The PageInfo
125      * @param command the command to execute
126      * @return the result value as a <code>String</code>
127      */

128     public String JavaDoc replace(PageInfo sp, StringTokenizer command) {
129         log.debug("replace: This method isn't implemented yet.");
130         return "";
131     }
132
133     /**
134      * Provides additional functionality when setting field values.
135      * This method makes sure that the pos, end, and length values have the
136      * correct value.
137      * @param node the node whose fields are changed
138      * @param field the fieldname that is changed
139      * @return <code>true</code> if the call was handled.
140      */

141     public boolean setValue(MMObjectNode node, String JavaDoc field) {
142         if (field.equals("end")) {
143             int pos = node.getIntValue("pos");
144             int end = node.getIntValue("end");
145             if (end != -1)
146                 node.setValue("length", (end - pos));
147         } else if (field.equals("pos")) {
148             int pos = node.getIntValue("pos");
149             int end = node.getIntValue("end");
150             if (end != -1)
151                 node.setValue("length", (end - pos));
152         } else if (field.equals("length")) {
153             // extra check needed to make sure we don't create a loop !
154
// XXX: ???
155
int pos = node.getIntValue("pos");
156             int end = node.getIntValue("end");
157             int len = node.getIntValue("length");
158         }
159         return true;
160     }
161
162     public Object JavaDoc getValue(MMObjectNode node, String JavaDoc field) {
163         if (field.equals("ms_pos")) {
164             int pos = node.getIntValue("pos");
165             //format to pos is in ms
166
return new SimpleDateFormat JavaDoc("hh:mm.0").format(new Date(pos));
167         } else if (field.equals("ms_length")) {
168             int len = node.getIntValue("length");
169             return new SimpleDateFormat JavaDoc("hh:mm").format(new Date(len));
170         } else if (field.equals("end")) {
171             int pos = node.getIntValue("pos");
172             int len = node.getIntValue("length");
173             int end = pos + len;
174             return ("" + end);
175         }
176         return (null);
177     }
178 }
179
Popular Tags