KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > form > layoutsupport > delegates > AbsoluteLayoutSupport


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.form.layoutsupport.delegates;
21
22 import java.awt.*;
23 import java.beans.*;
24 import java.util.*;
25 import java.lang.reflect.Constructor JavaDoc;
26
27 import org.openide.nodes.Node;
28 import org.openide.util.Utilities;
29 import org.openide.util.SharedClassObject;
30
31 import org.netbeans.lib.awtextra.AbsoluteLayout;
32 import org.netbeans.lib.awtextra.AbsoluteConstraints;
33
34 import org.netbeans.modules.form.layoutsupport.*;
35 import org.netbeans.modules.form.codestructure.*;
36 import org.netbeans.modules.form.FormProperty;
37 import org.netbeans.modules.form.FormLoaderSettings;
38
39 /**
40  * Support class for AbsoluteLayout - for absolute positioning and sizing of
41  * components using AbsoluteConstraints. This is an example of support for
42  * layout manager using component constraints as complex objects initialized
43  * by constructor with parameters mapped to properties. AbsoluteLayoutSupport
44  * is also the superclass of NullLayoutSupport and JLayeredPane support, so it
45  * is a bit more complicated than would be necessary for simple implementation.
46  *
47  * @author Tomas Pavek
48  */

49
50 public class AbsoluteLayoutSupport extends AbstractLayoutSupport {
51
52     /** The icon for AbsoluteLayout. */
53     private static String JavaDoc iconURL =
54         "org/netbeans/modules/form/layoutsupport/resources/AbsoluteLayout.gif"; // NOI18N
55
/** The icon for AbsoluteLayout. */
56     private static String JavaDoc icon32URL =
57         "org/netbeans/modules/form/layoutsupport/resources/AbsoluteLayout32.gif"; // NOI18N
58

59     private static Constructor JavaDoc constrConstructor;
60
61     private static FormLoaderSettings formSettings = (FormLoaderSettings)
62                    FormLoaderSettings.getInstance();
63
64     /** Gets the supported layout manager class - AbsoluteLayout.
65      * @return the class supported by this delegate
66      */

67     public Class JavaDoc getSupportedClass() {
68         return AbsoluteLayout.class;
69     }
70
71     /** Provides an icon to be used for the layout node in Component
72      * Inspector. Only 16x16 color icon is required.
73      * @param type is one of BeanInfo constants: ICON_COLOR_16x16,
74      * ICON_COLOR_32x32, ICON_MONO_16x16, ICON_MONO_32x32
75      * @return icon to be displayed for node in Component Inspector
76      */

77     public Image getIcon(int type) {
78         switch (type) {
79             case BeanInfo.ICON_COLOR_16x16:
80             case BeanInfo.ICON_MONO_16x16:
81                 return Utilities.loadImage(iconURL);
82             default:
83                 return Utilities.loadImage(icon32URL);
84         }
85     }
86
87     /** This method is called when switching layout - giving an opportunity to
88      * convert the previous constrainst of components to constraints of the new
89      * layout (this layout). For AbsoluteLayout, we can simply create new
90      * constraints from positions and sizes of real components.
91      * @param previousConstraints [input] layout constraints of components in
92      * the previous layout
93      * @param currentConstraints [output] array of converted constraints for
94      * the new layout - to be filled
95      * @param components [input] real components in a real container having the
96      * previous layout
97      */

98     public void convertConstraints(LayoutConstraints[] previousConstraints,
99                                    LayoutConstraints[] currentConstraints,
100                                    Component[] components)
101     {
102         if (currentConstraints == null || components == null)
103             return;
104
105         for (int i=0; i < currentConstraints.length; i++)
106             if (currentConstraints[i] == null) {
107                 Rectangle bounds = components[i].getBounds();
108                 Dimension prefSize = components[i].getPreferredSize();
109                 int x = bounds.x;
110                 int y = bounds.y;
111                 int w = computeConstraintSize(bounds.width, -1, prefSize.width);
112                 int h = computeConstraintSize(bounds.height, -1, prefSize.height);
113
114                 currentConstraints[i] = new AbsoluteLayoutConstraints(x, y, w, h);
115             }
116     }
117
118     /** This method calculates layout constraints for a component dragged
119      * over a container (or just for mouse cursor being moved over container,
120      * without any component).
121      * @param container instance of a real container over/in which the
122      * component is dragged
123      * @param containerDelegate effective container delegate of the container
124      * (for layout managers we always use container delegate instead of
125      * the container)
126      * @param component the real component being dragged, can be null
127      * @param index position (index) of the component in its container;
128      * -1 if there's no dragged component
129      * @param posInCont position of mouse in the container delegate
130      * @param posInComp position of mouse in the dragged component; null if
131      * there's no dragged component
132      * @return new LayoutConstraints object corresponding to the position of
133      * the component in the container
134      */

135     public LayoutConstraints getNewConstraints(Container container,
136                                                Container containerDelegate,
137                                                Component component,
138                                                int index,
139                                                Point posInCont,
140                                                Point posInComp)
141     {
142         int x = posInCont.x;
143         int y = posInCont.y;
144         int w = -1;
145         int h = -1;
146
147         LayoutConstraints constr = getConstraints(index);
148
149         if (component != null) {
150             int currentW;
151             int currentH;
152
153             if (constr instanceof AbsoluteLayoutConstraints) {
154                 currentW = ((AbsoluteLayoutConstraints)constr).w;
155                 currentH = ((AbsoluteLayoutConstraints)constr).h;
156             }
157             else {
158                 currentW = -1;
159                 currentH = -1;
160             }
161
162             Dimension size = component.getSize();
163             Dimension prefSize = component.getPreferredSize();
164
165             w = computeConstraintSize(size.width, currentW, prefSize.width);
166             h = computeConstraintSize(size.height, currentH, prefSize.height);
167         }
168
169         if (posInComp != null) {
170             x -= posInComp.x;
171             y -= posInComp.y;
172         }
173
174         if (formSettings.getApplyGridToPosition()) {
175             x = computeGridSize(x, formSettings.getGridX());
176             y = computeGridSize(y, formSettings.getGridY());
177         }
178
179         assistantParams = new Object JavaDoc[] {Integer.valueOf(x), Integer.valueOf(y)};
180         return createNewConstraints(constr, x, y, w, h);
181     }
182
183     private Object JavaDoc[] assistantParams;
184     public String JavaDoc getAssistantContext() {
185         return "absoluteLayout"; // NOI18N
186
}
187
188     public Object JavaDoc[] getAssistantParams() {
189         return assistantParams;
190     }
191
192     /** This method paints a dragging feedback for a component dragged over
193      * a container (or just for mouse cursor being moved over container,
194      * without any component). For AbsoluteLayout, it simply paints a rectangle
195      * corresponding to the component position and size.
196      * @param container instance of a real container over/in which the
197      * component is dragged
198      * @param containerDelegate effective container delegate of the container
199      * (for layout managers we always use container delegate instead of
200      * the container)
201      * @param component the real component being dragged, can be null
202      * @param newConstraints component layout constraints to be presented
203      * @param newIndex component's index position to be presented; not used
204      * for AbsoluteLayout
205      * @param g Graphics object for painting (with color and line style set)
206      * @return whether any feedback was painted (true in this case)
207      */

208     public boolean paintDragFeedback(Container container,
209                                      Container containerDelegate,
210                                      Component component,
211                                      LayoutConstraints newConstraints,
212                                      int newIndex,
213                                      Graphics g)
214     {
215         Rectangle r = ((AbsoluteLayoutConstraints)newConstraints).getBounds();
216         int w = r.width;
217         int h = r.height;
218
219         if (w == -1 || h == -1) {
220             // JInternalFrame.getPreferredSize() behaves suspiciously
221
Dimension pref = component instanceof javax.swing.JInternalFrame JavaDoc ?
222                              component.getSize() : component.getPreferredSize();
223             if (w == -1) w = pref.width;
224             if (h == -1) h = pref.height;
225         }
226
227         if (w < 4) w = 4;
228         if (h < 4) h = 4;
229
230         g.drawRect(r.x, r.y, w, h);
231
232         return true;
233     }
234
235     /** Provides resizing options for given component. It can combine the
236      * bit-flag constants RESIZE_UP, RESIZE_DOWN, RESIZE_LEFT, RESIZE_RIGHT.
237      * @param container instance of a real container in which the
238      * component is to be resized
239      * @param containerDelegate effective container delegate of the container
240      * (e.g. like content pane of JFrame)
241      * @param component real component to be resized
242      * @param index position of the component in its container
243      * @return resizing options for the component; 0 if no resizing is possible
244      */

245     public int getResizableDirections(Container container,
246                                       Container containerDelegate,
247                                       Component component,
248                                       int index)
249     {
250         return RESIZE_UP | RESIZE_DOWN | RESIZE_LEFT | RESIZE_RIGHT;
251     }
252
253     /** This method should calculate layout constraints for a component being
254      * resized.
255      * @param container instance of a real container in which the
256      * component is resized
257      * @param containerDelegate effective container delegate of the container
258      * (e.g. like content pane of JFrame)
259      * @param component real component being resized
260      * @param index position of the component in its container
261      * @param sizeChanges Insets object with size differences
262      * @param posInCont position of mouse in the container delegate
263      * @return component layout constraints for resized component; null if
264      * resizing is not possible or not implemented
265      */

266     public LayoutConstraints getResizedConstraints(Container container,
267                                                    Container containerDelegate,
268                                                    Component component,
269                                                    int index,
270                                                    Rectangle originalBounds,
271                                                    Insets sizeChanges,
272                                                    Point posInCont)
273     {
274         int x, y, w, h;
275         x = originalBounds.x;
276         y = originalBounds.y;
277         w = originalBounds.width;
278         h = originalBounds.height;
279
280         Dimension prefSize = component.getPreferredSize();
281         int currentW, currentH;
282
283         LayoutConstraints constr = getConstraints(index);
284         if (constr instanceof AbsoluteLayoutConstraints) {
285             Rectangle r = ((AbsoluteLayoutConstraints)constr).getBounds();
286             currentW = r.width;
287             currentH = r.height;
288         }
289         else {
290             currentW = computeConstraintSize(w, -1, prefSize.width);
291             currentH = computeConstraintSize(h, -1, prefSize.height);
292         }
293
294         int x2 = x + w;
295         int y2 = y + h;
296
297         if (sizeChanges.left + sizeChanges.right == 0)
298             w = currentW; // no change
299
else { // compute resized width and x coordinate
300
w += sizeChanges.left + sizeChanges.right;
301             w = w <= 0 ? -1 : computeConstraintSize(w, currentW, prefSize.width);
302
303             if (w > 0) {
304                 if (formSettings.getApplyGridToSize()) {
305                     int gridW = computeGridSize(w, formSettings.getGridX());
306                     x -= sizeChanges.left +
307                          (gridW - w) * sizeChanges.left
308                          / (sizeChanges.left + sizeChanges.right);
309                     w = gridW;
310                 }
311             }
312             else if (sizeChanges.left != 0)
313                 x = x2 - prefSize.width;
314         }
315
316         if (sizeChanges.top + sizeChanges.bottom == 0)
317             h = currentH; // no change
318
else { // compute resized height and y coordinate
319
h += sizeChanges.top + sizeChanges.bottom;
320             h = h <= 0 ? -1 : computeConstraintSize(h, currentH, prefSize.height);
321
322             if (h > 0) {
323                 if (formSettings.getApplyGridToSize()) {
324                     int gridH = computeGridSize(h, formSettings.getGridY());
325                     y -= sizeChanges.top +
326                          (gridH - h) * sizeChanges.top
327                          / (sizeChanges.top + sizeChanges.bottom);
328                     h = gridH;
329                 }
330             }
331             else if (sizeChanges.top != 0)
332                 y = y2 - prefSize.height;
333         }
334
335         return createNewConstraints(constr, x, y, w, h);
336     }
337
338     // -------
339

340     /** This method is called from readComponentCode method to read layout
341      * constraints of a component from code (AbsoluteConstraints in this case).
342      * @param constrExp CodeExpression object of the constraints (taken from
343      * add method in the code)
344      * @param constrCode CodeGroup to be filled with the relevant constraints
345      * initialization code; not needed here because AbsoluteConstraints
346      * object is represented only by a single code expression (based on
347      * constructor) and no statements
348      * @param compExp CodeExpression of the component for which the constraints
349      * are read (not needed here)
350      * @return LayoutConstraints based on information read form code
351      */

352     protected LayoutConstraints readConstraintsCode(CodeExpression constrExp,
353                                                     CodeGroup constrCode,
354                                                     CodeExpression compExp)
355     {
356         AbsoluteLayoutConstraints constr =
357             new AbsoluteLayoutConstraints(0, 0, -1, -1);
358
359         CodeExpression[] params = constrExp.getOrigin().getCreationParameters();
360         if (params.length == 4) {
361             // reading is done in AbsoluteLayoutConstraints
362
constr.readPropertyExpressions(params, 0);
363         }
364
365         return constr;
366     }
367
368     /** Called from createComponentCode method, creates code for a component
369      * layout constraints (opposite to readConstraintsCode).
370      * @param constrCode CodeGroup to be filled with constraints code; not
371      * needed here because AbsoluteConstraints object is represented
372      * only by a single constructor code expression and no statements
373      * @param constr layout constraints metaobject representing the constraints
374      * @param compExp CodeExpression object representing the component; not
375      * needed here
376      * @return created CodeExpression representing the layout constraints
377      */

378     protected CodeExpression createConstraintsCode(CodeGroup constrCode,
379                                                    LayoutConstraints constr,
380                                                    CodeExpression compExp,
381                                                    int index)
382     {
383         if (!(constr instanceof AbsoluteLayoutConstraints))
384             return null;
385
386         AbsoluteLayoutConstraints absConstr = (AbsoluteLayoutConstraints)constr;
387         // code expressions for constructor parameters are created in
388
// AbsoluteLayoutConstraints
389
CodeExpression[] params = absConstr.createPropertyExpressions(
390                                                  getCodeStructure(), 0);
391         return getCodeStructure().createExpression(getConstraintsConstructor(),
392                                                    params);
393     }
394
395     /** This method is called to get a default component layout constraints
396      * metaobject in case it is not provided (e.g. in addComponents method).
397      * @return the default LayoutConstraints object for the supported layout
398      */

399     protected LayoutConstraints createDefaultConstraints() {
400         return new AbsoluteLayoutConstraints(0, 0, -1, -1);
401     }
402
403     // --------
404

405     protected LayoutConstraints createNewConstraints(
406                                     LayoutConstraints currentConstr,
407                                     int x, int y, int w, int h)
408     {
409         return new AbsoluteLayoutConstraints(x, y, w, h);
410     }
411
412     private static int computeConstraintSize(int newSize,
413                                              int currSize,
414                                              int prefSize) {
415         return newSize != -1 && (newSize != prefSize
416                                  || (currSize != -1 && currSize == prefSize)) ?
417                newSize : -1;
418     }
419
420     private static int computeGridSize(int size, int step) {
421         if (step <= 0) return size;
422         int mod = size % step;
423         return mod >= step/2 ? size + step - mod : size - mod;
424     }
425
426     private static Constructor JavaDoc getConstraintsConstructor() {
427         if (constrConstructor == null) {
428             try {
429                 constrConstructor = AbsoluteConstraints.class.getConstructor(
430                                     new Class JavaDoc[] { Integer.TYPE, Integer.TYPE,
431                                                   Integer.TYPE, Integer.TYPE });
432             }
433             catch (NoSuchMethodException JavaDoc ex) { // should not happen
434
ex.printStackTrace();
435             }
436         }
437         return constrConstructor;
438     }
439
440     // -------------
441

442     /** LayoutConstraints implementation class for AbsoluteConstraints.
443      */

444     public static class AbsoluteLayoutConstraints implements LayoutConstraints {
445         int x, y, w, h; // position and size
446

447         private Node.Property[] properties;
448         boolean nullMode;
449         Component refComponent;
450
451         public AbsoluteLayoutConstraints(int x, int y, int w, int h)
452         {
453             this.x = x;
454             this.y = y;
455             this.w = w;
456             this.h = h;
457         }
458
459         public Node.Property[] getProperties() {
460             if (properties == null) {
461                 properties = createProperties();
462                 reinstateProperties();
463             }
464             return properties;
465         }
466
467         public Object JavaDoc getConstraintsObject() {
468             return new AbsoluteConstraints(x, y, w, h);
469         }
470
471         public LayoutConstraints cloneConstraints() {
472             return new AbsoluteLayoutConstraints(x, y, w, h);
473         }
474
475         // --------
476

477         public Rectangle getBounds() {
478             return new Rectangle(x, y, w, h);
479         }
480
481         protected Node.Property[] createProperties() {
482             return new Node.Property[] {
483                 new FormProperty("AbsoluteLayoutConstraints posx", // NOI18N
484
Integer.TYPE,
485                              getBundle().getString("PROP_posx"), // NOI18N
486
getBundle().getString("HINT_posx")) { // NOI18N
487

488                     public Object JavaDoc getTargetValue() {
489                         return new Integer JavaDoc(x);
490                     }
491                     public void setTargetValue(Object JavaDoc value) {
492                         x = ((Integer JavaDoc)value).intValue();
493                     }
494                     public void setPropertyContext(
495                         org.netbeans.modules.form.FormPropertyContext ctx)
496                     { // disabling this method due to limited persistence
497
} // capabilities (compatibility with previous versions)
498
},
499
500                 new FormProperty("AbsoluteLayoutConstraints posy", // NOI18N
501
Integer.TYPE,
502                              getBundle().getString("PROP_posy"), // NOI18N
503
getBundle().getString("HINT_posy")) { // NOI18N
504

505                     public Object JavaDoc getTargetValue() {
506                         return new Integer JavaDoc(y);
507                     }
508                     public void setTargetValue(Object JavaDoc value) {
509                         y = ((Integer JavaDoc)value).intValue();
510                     }
511                     public void setPropertyContext(
512                         org.netbeans.modules.form.FormPropertyContext ctx)
513                     { // disabling this method due to limited persistence
514
} // capabilities (compatibility with previous versions)
515
},
516
517                 new FormProperty("AbsoluteLayoutConstraints width", // NOI18N
518
Integer.TYPE,
519                              getBundle().getString("PROP_width"), // NOI18N
520
getBundle().getString("HINT_width")) { // NOI18N
521

522                     public Object JavaDoc getTargetValue() {
523                         return new Integer JavaDoc(w);
524                     }
525                     public void setTargetValue(Object JavaDoc value) {
526                         w = ((Integer JavaDoc)value).intValue();
527                     }
528                     public boolean supportsDefaultValue () {
529                         return true;
530                     }
531                     public Object JavaDoc getDefaultValue() {
532                         return new Integer JavaDoc(-1);
533                     }
534                     public PropertyEditor getExpliciteEditor() {
535                         return new SizeEditor();
536                     }
537                     public Object JavaDoc getValue(String JavaDoc key) {
538                         if ("canEditAsText".equals(key)) // NOI18N
539
return Boolean.TRUE;
540                         return super.getValue(key);
541                     }
542                     public String JavaDoc getJavaInitializationString() {
543                         if (nullMode && refComponent != null && !isChanged())
544                             return Integer.toString(
545                                      refComponent.getPreferredSize().width);
546                         return super.getJavaInitializationString();
547                     }
548                     public void setPropertyContext(
549                         org.netbeans.modules.form.FormPropertyContext ctx)
550                     { // disabling this method due to limited persistence
551
} // capabilities (compatibility with previous versions)
552
},
553
554                 new FormProperty("AbsoluteLayoutConstraints height", // NOI18N
555
Integer.TYPE,
556                              getBundle().getString("PROP_height"), // NOI18N
557
getBundle().getString("HINT_height")) { // NOI18N
558

559                     public Object JavaDoc getTargetValue() {
560                         return new Integer JavaDoc(h);
561                     }
562                     public void setTargetValue(Object JavaDoc value) {
563                         h = ((Integer JavaDoc)value).intValue();
564                     }
565                     public boolean supportsDefaultValue () {
566                         return true;
567                     }
568                     public Object JavaDoc getDefaultValue() {
569                         return new Integer JavaDoc(-1);
570                     }
571                     public PropertyEditor getExpliciteEditor() {
572                         return new SizeEditor();
573                     }
574                     public Object JavaDoc getValue(String JavaDoc key) {
575                         if ("canEditAsText".equals(key)) // NOI18N
576
return Boolean.TRUE;
577                         return super.getValue(key);
578                     }
579                     public String JavaDoc getJavaInitializationString() {
580                         if (nullMode && refComponent != null && !isChanged())
581                             return Integer.toString(
582                                      refComponent.getPreferredSize().height);
583                         return super.getJavaInitializationString();
584                     }
585                     public void setPropertyContext(
586                         org.netbeans.modules.form.FormPropertyContext ctx)
587                     { // disabling this method due to limited persistence
588
} // capabilities (compatibility with previous versions)
589
}
590             };
591         }
592
593         private void reinstateProperties() {
594             try {
595                 for (int i=0; i < properties.length; i++) {
596                     FormProperty prop = (FormProperty) properties[i];
597                     prop.reinstateProperty();
598                 }
599             }
600             catch(IllegalAccessException JavaDoc e1) {} // should not happen
601
catch(java.lang.reflect.InvocationTargetException JavaDoc e2) {} // should not happen
602
}
603
604         /** This method creates CodeExpression objects for properties of
605          * AbsoluteConstraints - this is used by the layout delegate's method
606          * createConstraintsCode which uses the expressions as parameters
607          * in AbsoluteConstraints constructor.
608          * @param codeStructure main CodeStructure object in which the code
609          * expressions are created
610          * @param shift this parameter is used only by subclasses of
611          * AbsoluteLayoutConstraints (which may insert another
612          * constructor parameters before x, y, w and h)
613          * @return array of created code expressions
614          */

615         protected final CodeExpression[] createPropertyExpressions(
616                                              CodeStructure codeStructure,
617                                              int shift)
618         {
619             // first make sure properties are created...
620
getProperties();
621
622             // ...then create code expressions based on the properties
623
CodeExpression xEl = codeStructure.createExpression(
624                            FormCodeSupport.createOrigin(properties[shift++]));
625             CodeExpression yEl = codeStructure.createExpression(
626                            FormCodeSupport.createOrigin(properties[shift++]));
627             CodeExpression wEl = codeStructure.createExpression(
628                            FormCodeSupport.createOrigin(properties[shift++]));
629             CodeExpression hEl = codeStructure.createExpression(
630                            FormCodeSupport.createOrigin(properties[shift]));
631             return new CodeExpression[] { xEl, yEl, wEl, hEl };
632         }
633
634         /** This method reads CodeExpression objects for properties (used as
635          * AbsoluteConstraints constructor parameters). Called by layout
636          * delegate's readConstraintsCode method.
637          * @param exps array of code expressions to read to properties
638          * @param shift this parameter is used only by subclasses of
639          * AbsoluteLayoutConstraints (which may insert another
640          * constructor parameters before x, y, w and h)
641          */

642         protected final void readPropertyExpressions(CodeExpression[] exps,
643                                                      int shift)
644         {
645             // first make sure properties are created...
646
getProperties();
647
648             // ...then map the properties to the code expressions
649
for (int i=0; i < exps.length; i++)
650                 FormCodeSupport.readPropertyExpression(exps[i],
651                                                        properties[i+shift],
652                                                        false);
653         }
654     }
655
656     // -----------
657

658     /** PropertyEditor for width and height properties of
659      * AbsoluteLayoutConstraints.
660      */

661     public static final class SizeEditor extends PropertyEditorSupport {
662
663         final Integer JavaDoc prefValue = new Integer JavaDoc(-1);
664         final String JavaDoc prefTag = getBundle().getString("VALUE_preferred"); // NOI18N
665

666         public String JavaDoc[] getTags() {
667             return new String JavaDoc[] { prefTag };
668         }
669
670         public String JavaDoc getAsText() {
671             Object JavaDoc value = getValue();
672             return prefValue.equals(value) ?
673                      prefTag : value.toString();
674         }
675
676         public void setAsText(String JavaDoc str) {
677             if (prefTag.equals(str))
678                 setValue(prefValue);
679             else
680                 try {
681                     setValue(new Integer JavaDoc(Integer.parseInt(str)));
682                 }
683                 catch (NumberFormatException JavaDoc e) {} // ignore
684
}
685
686         public String JavaDoc getJavaInitializationString() {
687             Object JavaDoc value = getValue();
688             return value != null ? value.toString() : null;
689         }
690     }
691 }
692
Popular Tags