KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > form > RADVisualComponent


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;
21
22 import java.util.*;
23 import java.beans.*;
24 import javax.accessibility.*;
25
26 import org.openide.nodes.*;
27
28 import org.netbeans.modules.form.layoutdesign.*;
29 import org.netbeans.modules.form.layoutsupport.*;
30 import org.openide.util.NbBundle;
31
32 /**
33  *
34  * @author Ian Formanek
35  */

36
37 public class RADVisualComponent extends RADComponent {
38     private static final String JavaDoc PROP_LAYOUT_COMPONENT_HORIZONTAL_SIZE = "layoutComponentHorizontalSize"; // NOI18N
39
private static final String JavaDoc PROP_LAYOUT_COMPONENT_VERTICAL_SIZE = "layoutComponentVerticalSize"; // NOI18N
40
private static final String JavaDoc PROP_LAYOUT_COMPONENT_HORIZONTAL_RESIZABLE = "layoutComponentHorizontalResizable"; // NOI18N
41
private static final String JavaDoc PROP_LAYOUT_COMPONENT_VERTICAL_RESIZABLE = "layoutComponentVerticalResizable"; // NOI18N
42

43     // -----------------------------------------------------------------------------
44
// Private properties
45

46     // [??]
47
private HashMap constraints = new HashMap();
48 // transient private RADVisualContainer parent;
49

50     private Node.Property[] constraintsProperties;
51     private ConstraintsListenerConvertor constraintsListener;
52
53     private MetaAccessibleContext accessibilityData;
54     private FormProperty[] accessibilityProperties;
55
56     // -----------------------------------------------------------------------------
57
// Initialization
58

59 // public void setParentComponent(RADComponent parentComp) {
60
// super.setParentComponent(parentComp);
61
// if (parentComp != null)
62
// getConstraintsProperties();
63
// }
64

65 // void initParent(RADVisualContainer parent) {
66
// this.parent = parent;
67
// }
68

69 /* protected void setBeanInstance(Object beanInstance) {
70         if (beanInstance instanceof java.awt.Component) {
71             boolean attached = FakePeerSupport.attachFakePeer(
72                                             (java.awt.Component)beanInstance);
73             if (attached && beanInstance instanceof java.awt.Container)
74                 FakePeerSupport.attachFakePeerRecursively(
75                                             (java.awt.Container)beanInstance);
76         }
77
78         super.setBeanInstance(beanInstance);
79     } */

80
81     // -----------------------------------------------------------------------------
82
// Public interface
83

84     /** @return The JavaBean visual component represented by this RADVisualComponent */
85 // public java.awt.Component getComponent() { // [is it needed ???]
86
// return (java.awt.Component) getBeanInstance();
87
// }
88

89     public final RADVisualContainer getParentContainer() {
90         return (RADVisualContainer) getParentComponent();
91     }
92
93     /** @return The index of this component within visual components of its parent */
94     public final int getComponentIndex() {
95         RADVisualContainer parent = (RADVisualContainer) getParentComponent();
96         return parent != null ? parent.getIndexOf(this) : -1;
97 // return ((ComponentContainer)getParentComponent()).getIndexOf(this);
98
}
99
100     final LayoutSupportManager getParentLayoutSupport() {
101         RADVisualContainer parent = (RADVisualContainer) getParentComponent();
102         return parent != null ? parent.getLayoutSupport() : null;
103     }
104
105     // -----------------------------------------------------------------------------
106
// Layout constraints management
107

108     /** Sets component's constraints description for given layout-support class.
109      */

110     public void setLayoutConstraints(Class JavaDoc layoutDelegateClass,
111                                      LayoutConstraints constr)
112     {
113         if (constr != null)
114             constraints.put(layoutDelegateClass.getName(), constr);
115     }
116
117     /** Gets component's constraints description for given layout-support class.
118      */

119     public LayoutConstraints getLayoutConstraints(Class JavaDoc layoutDelegateClass) {
120         return (LayoutConstraints)
121                constraints.get(layoutDelegateClass.getName());
122     }
123
124     HashMap getConstraintsMap() {
125         return constraints;
126     }
127
128     void setConstraintsMap(Map map) {
129         constraints.putAll(map);
130     }
131
132     // ---------------
133
// Properties
134

135     protected void createPropertySets(List propSets) {
136         super.createPropertySets(propSets);
137
138         if (constraintsProperties == null)
139             createConstraintsProperties();
140
141         if (constraintsProperties != null && constraintsProperties.length > 0)
142             propSets.add(propSets.size() - 1,
143                          new Node.PropertySet("layout", // NOI18N
144
FormUtils.getBundleString("CTL_LayoutTab"), // NOI18N
145
FormUtils.getBundleString("CTL_LayoutTabHint")) // NOI18N
146
{
147                 public Node.Property[] getProperties() {
148                     return getConstraintsProperties();
149                 }
150             });
151
152         if (accessibilityProperties == null)
153             createAccessibilityProperties();
154
155         if (accessibilityProperties.length > 0)
156             propSets.add(new Node.PropertySet(
157                 "accessibility", // NOI18N
158
FormUtils.getBundleString("CTL_AccessibilityTab"), // NOI18N
159
FormUtils.getBundleString("CTL_AccessibilityTabHint")) // NOI18N
160
{
161                 public Node.Property[] getProperties() {
162                     return getAccessibilityProperties();
163                 }
164             });
165     }
166
167     public Node.Property getPropertyByName(String JavaDoc name,
168                                            Class JavaDoc propertyType,
169                                            boolean fromAll)
170     {
171         if (fromAll && accessibilityProperties == null)
172             createAccessibilityProperties();
173         return super.getPropertyByName(name, propertyType, fromAll);
174     }
175
176     /** Called to modify original properties obtained from BeanInfo.
177      * Properties may be added, removed etc. - due to specific needs
178      * of subclasses. Here used for adding ButtonGroupProperty.
179      */

180 /* protected void changePropertiesExplicitly(List prefProps,
181                                               List normalProps,
182                                               List expertProps) {
183
184         super.changePropertiesExplicitly(prefProps, normalProps, expertProps);
185
186         if (getBeanInstance() instanceof java.awt.TextComponent) {
187             // hack for AWT text components - "text" property should be first
188             for (int i=0, n=normalProps.size(); i < n; i++) {
189                 RADProperty prop = (RADProperty) normalProps.get(i);
190                 if ("text".equals(prop.getName())) { // NOI18N
191                     normalProps.remove(i);
192                     normalProps.add(0, prop);
193                     break;
194                 }
195             }
196         }
197
198         // hack for buttons - add a fake property for ButtonGroup
199 // if (getBeanInstance() instanceof javax.swing.AbstractButton)
200 // try {
201 // Node.Property prop = new ButtonGroupProperty(this);
202 // nameToProperty.put(prop.getName(), prop);
203 // if (getBeanInstance() instanceof javax.swing.JToggleButton)
204 // prefProps.add(prop);
205 // else
206 // normalProps.add(prop);
207 // }
208 // catch (IntrospectionException ex) {} // should not happen
209
210 // if (getBeanInstance() instanceof javax.swing.JLabel)
211 // try {
212 // PropertyDescriptor pd = new PropertyDescriptor("displayedMnemonic",
213 // javax.swing.JLabel.class, "getDisplayedMnemonic", "setDisplayedMnemonic");
214 // normalProps.add(createProperty(pd));
215 // }
216 // catch (IntrospectionException ex) {} // should not happen
217     } */

218
219     protected void clearProperties() {
220         super.clearProperties();
221         constraintsProperties = null;
222         accessibilityData = null;
223         accessibilityProperties = null;
224     }
225
226     // ---------
227
// constraints properties
228

229     public Node.Property[] getConstraintsProperties() {
230         if (constraintsProperties == null)
231             createConstraintsProperties();
232         return constraintsProperties;
233     }
234
235     public void resetConstraintsProperties() {
236         if (constraintsProperties != null) {
237             for (int i=0; i < constraintsProperties.length; i++)
238                 nameToProperty.remove(constraintsProperties[i].getName());
239
240             constraintsProperties = null;
241             propertySets = null;
242
243             RADComponentNode node = getNodeReference();
244             if (node != null)
245                 node.fireComponentPropertySetsChange();
246         }
247     }
248
249     private void createConstraintsProperties() {
250         constraintsProperties = null;
251
252         LayoutSupportManager layoutSupport = getParentLayoutSupport();
253         if (layoutSupport != null) {
254             LayoutConstraints constr = layoutSupport.getConstraints(this);
255             if (constr != null)
256                 constraintsProperties = constr.getProperties();
257         } else if (getParentContainer() != null) {
258             LayoutComponent component = getFormModel().getLayoutModel().getLayoutComponent(getId());
259             if (component == null) return; // Will be called again later
260
constraintsProperties = new Node.Property[] {
261                 new LayoutComponentSizeProperty(component, LayoutConstants.HORIZONTAL),
262                 new LayoutComponentSizeProperty(component, LayoutConstants.VERTICAL),
263                 new LayoutComponentResizableProperty(component, LayoutConstants.HORIZONTAL),
264                 new LayoutComponentResizableProperty(component, LayoutConstants.VERTICAL)
265             };
266             component.addPropertyChangeListener(new PropertyChangeListener() {
267                 public void propertyChange(PropertyChangeEvent evt) {
268                     RADComponentNode node = getNodeReference();
269                     if (node != null) {
270                         String JavaDoc propName = evt.getPropertyName();
271                         if (LayoutConstants.PROP_HORIZONTAL_PREF_SIZE.equals(propName)) {
272                             node.firePropertyChangeHelper(PROP_LAYOUT_COMPONENT_HORIZONTAL_SIZE, null, null);
273                         } else if (LayoutConstants.PROP_VERTICAL_PREF_SIZE.equals(propName)) {
274                             node.firePropertyChangeHelper(PROP_LAYOUT_COMPONENT_VERTICAL_SIZE, null, null);
275                         } else if (LayoutConstants.PROP_HORIZONTAL_MAX_SIZE.equals(propName)) {
276                             node.firePropertyChangeHelper(PROP_LAYOUT_COMPONENT_HORIZONTAL_RESIZABLE, null, null);
277                         } else if (LayoutConstants.PROP_VERTICAL_MAX_SIZE.equals(propName)) {
278                             node.firePropertyChangeHelper(PROP_LAYOUT_COMPONENT_VERTICAL_RESIZABLE, null, null);
279                         }
280                     }
281                 }
282             });
283         }
284
285         if (constraintsProperties == null) {
286             constraintsProperties = NO_PROPERTIES;
287             return;
288         }
289
290         for (int i=0; i < constraintsProperties.length; i++) {
291             if (constraintsProperties[i] instanceof FormProperty) {
292                 FormProperty prop = (FormProperty)constraintsProperties[i];
293
294                 // we suppose the constraint property is not a RADProperty...
295
prop.addVetoableChangeListener(getConstraintsListener());
296                 prop.addPropertyChangeListener(getConstraintsListener());
297                 prop.addValueConvertor(getConstraintsListener());
298
299                 prop.setPropertyContext(
300                     new RADProperty.RADPropertyContext(this));
301
302                 if (isReadOnly() || !isValid()) {
303                     int type = prop.getAccessType() | FormProperty.NO_WRITE;
304                     prop.setAccessType(type);
305                 }
306                 nameToProperty.put(prop.getName(), prop);
307             }
308         }
309     }
310
311     private ConstraintsListenerConvertor getConstraintsListener() {
312         if (constraintsListener == null)
313             constraintsListener = new ConstraintsListenerConvertor();
314         return constraintsListener;
315     }
316
317     private class ConstraintsListenerConvertor implements VetoableChangeListener,
318                              PropertyChangeListener, FormProperty.ValueConvertor
319     {
320         public void vetoableChange(PropertyChangeEvent ev)
321             throws PropertyVetoException
322         {
323             Object JavaDoc source = ev.getSource();
324             String JavaDoc eventName = ev.getPropertyName();
325             if (source instanceof FormProperty
326                 && (FormProperty.PROP_VALUE.equals(eventName)
327                     || FormProperty.PROP_VALUE_AND_EDITOR.equals(eventName)))
328             {
329                 i18nPropertyChanged(ev);
330
331                 LayoutSupportManager layoutSupport = getParentLayoutSupport();
332                 int index = getComponentIndex();
333                 LayoutConstraints constraints =
334                     layoutSupport.getConstraints(index);
335
336                 ev = new PropertyChangeEvent(constraints,
337                                              ((FormProperty)source).getName(),
338                                              ev.getOldValue(),
339                                              ev.getNewValue());
340
341                 layoutSupport.componentLayoutChanged(index, ev);
342             }
343         }
344
345         public void propertyChange(PropertyChangeEvent ev) {
346             Object JavaDoc source = ev.getSource();
347             if (source instanceof FormProperty
348                 && FormProperty.CURRENT_EDITOR.equals(ev.getPropertyName()))
349             {
350                 LayoutSupportManager layoutSupport = getParentLayoutSupport();
351                 int index = getComponentIndex();
352                 LayoutConstraints constraints =
353                     layoutSupport.getConstraints(index);
354
355                 ev = new PropertyChangeEvent(constraints, null, null, null);
356
357                 try {
358                     layoutSupport.componentLayoutChanged(index, ev);
359                 }
360                 catch (PropertyVetoException ex) {} // should not happen
361
}
362         }
363
364         public Object JavaDoc convert(Object JavaDoc value, FormProperty property) {
365             return i18nPropertyConvert(value, property);
366         }
367     }
368
369     // ----------
370
// accessibility properties
371

372     public FormProperty[] getAccessibilityProperties() {
373         if (accessibilityProperties == null)
374             createAccessibilityProperties();
375         return accessibilityProperties;
376     }
377
378     private void createAccessibilityProperties() {
379         Object JavaDoc comp = getBeanInstance();
380         if (comp instanceof Accessible
381             && ((Accessible)comp).getAccessibleContext() != null)
382         {
383             if (accessibilityData == null)
384                 accessibilityData = new MetaAccessibleContext();
385             accessibilityProperties = accessibilityData.getProperties();
386
387             for (int i=0; i < accessibilityProperties.length; i++) {
388                 FormProperty prop = accessibilityProperties[i];
389                 setPropertyListener(prop);
390                 prop.setPropertyContext(
391                     new RADProperty.RADPropertyContext(this));
392                 nameToProperty.put(prop.getName(), prop);
393             }
394         }
395         else {
396             accessibilityData = null;
397             accessibilityProperties = NO_PROPERTIES;
398         }
399     }
400
401     private class MetaAccessibleContext {
402         private Object JavaDoc accName = BeanSupport.NO_VALUE;
403         private Object JavaDoc accDescription = BeanSupport.NO_VALUE;
404         private Object JavaDoc accParent = BeanSupport.NO_VALUE;
405
406         private FormProperty[] properties;
407
408         FormProperty[] getProperties() {
409             if (properties == null) {
410                 properties = new FormProperty[] {
411                     new FormProperty(
412                         "AccessibleContext.accessibleName", // NOI18N
413
String JavaDoc.class,
414                         FormUtils.getBundleString("PROP_AccessibleName"), // NOI18N
415
FormUtils.getBundleString("PROP_AccessibleName")) // NOI18N
416
{
417                         public Object JavaDoc getTargetValue() {
418                             return accName != BeanSupport.NO_VALUE ?
419                                        accName : getDefaultValue();
420                         }
421                         public void setTargetValue(Object JavaDoc value) {
422                             accName = (String JavaDoc) value;
423                         }
424                         public boolean supportsDefaultValue () {
425                             return true;
426                         }
427                         public Object JavaDoc getDefaultValue() {
428                             return getAccessibleContext().getAccessibleName();
429                         }
430                         public void restoreDefaultValue()
431                             throws IllegalAccessException JavaDoc,
432                                    java.lang.reflect.InvocationTargetException JavaDoc
433                         {
434                             super.restoreDefaultValue();
435                             accName = BeanSupport.NO_VALUE;
436                         }
437                         String JavaDoc getPartialSetterCode(String JavaDoc javaInitStr) {
438                             return "getAccessibleContext().setAccessibleName(" // NOI18N
439
+ javaInitStr + ")"; // NOI18N
440
}
441                     },
442
443                     new FormProperty(
444                         "AccessibleContext.accessibleDescription", // NOI18N
445
String JavaDoc.class,
446                         FormUtils.getBundleString("PROP_AccessibleDescription"), // NOI18N
447
FormUtils.getBundleString("PROP_AccessibleDescription")) // NOI18N
448
{
449                         public Object JavaDoc getTargetValue() {
450                             return accDescription != BeanSupport.NO_VALUE ?
451                                        accDescription : getDefaultValue();
452                         }
453                         public void setTargetValue(Object JavaDoc value) {
454                             accDescription = (String JavaDoc) value;
455                         }
456                         public boolean supportsDefaultValue () {
457                             return true;
458                         }
459                         public Object JavaDoc getDefaultValue() {
460                             return getAccessibleContext().getAccessibleDescription();
461                         }
462                         public void restoreDefaultValue()
463                             throws IllegalAccessException JavaDoc,
464                                    java.lang.reflect.InvocationTargetException JavaDoc
465                         {
466                             super.restoreDefaultValue();
467                             accDescription = BeanSupport.NO_VALUE;
468                         }
469                         String JavaDoc getPartialSetterCode(String JavaDoc javaInitStr) {
470                             return
471                               "getAccessibleContext().setAccessibleDescription(" // NOI18N
472
+ javaInitStr + ")"; // NOI18N
473
}
474                     },
475
476                     new FormProperty(
477                         "AccessibleContext.accessibleParent", // NOI18N
478
Accessible.class,
479                         FormUtils.getBundleString("PROP_AccessibleParent"), // NOI18N
480
FormUtils.getBundleString("PROP_AccessibleParent")) // NOI18N
481
{
482                         public Object JavaDoc getTargetValue() {
483                             return accParent != BeanSupport.NO_VALUE ?
484                                        accParent : getDefaultValue();
485                         }
486                         public void setTargetValue(Object JavaDoc value) {
487                             accParent = value;
488                         }
489                         public boolean supportsDefaultValue () {
490                             return true;
491                         }
492                         public Object JavaDoc getDefaultValue() {
493                             Object JavaDoc acP = getAccessibleContext()
494                                              .getAccessibleParent();
495                             if (acP != null) {
496                                 RADVisualContainer metacont = getParentContainer();
497                                 if (metacont != null) {
498                                     Object JavaDoc cont = metacont.getContainerDelegate(
499                                                     metacont.getBeanInstance());
500                                     if (cont == acP)
501                                         return metacont;
502                                 }
503                             }
504                             return acP;
505                         }
506                         public void restoreDefaultValue()
507                             throws IllegalAccessException JavaDoc,
508                                    java.lang.reflect.InvocationTargetException JavaDoc
509                         {
510                             super.restoreDefaultValue();
511                             accParent = BeanSupport.NO_VALUE;
512                         }
513                         public PropertyEditor getExpliciteEditor() {
514                             return new AccessibleParentEditor();
515                         }
516                         String JavaDoc getPartialSetterCode(String JavaDoc javaInitStr) {
517                             return javaInitStr == null ? null :
518                                 "getAccessibleContext().setAccessibleParent(" // NOI18N
519
+ javaInitStr + ")"; // NOI18N
520
}
521                     }
522                 };
523             }
524             return properties;
525         }
526
527         private AccessibleContext getAccessibleContext() {
528             return ((Accessible)getBeanInstance()).getAccessibleContext();
529         }
530     }
531
532     public static class AccessibleParentEditor extends ComponentChooserEditor {
533         public AccessibleParentEditor() {
534             super();
535             setBeanTypes(new Class JavaDoc[] { Accessible.class });
536         }
537         
538         public String JavaDoc getDisplayName() {
539             return NbBundle.getBundle(getClass()).getString("CTL_AccessibleParentEditor_DisplayName"); // NOI18N
540
}
541     }
542     
543     /**
544      * Preferred size of the component in the layout.
545      */

546     private class LayoutComponentSizeProperty extends PropertySupport.ReadWrite {
547         private LayoutComponent component;
548         private int dimension;
549         
550         private LayoutComponentSizeProperty(LayoutComponent component, int dimension) {
551             super(dimension == LayoutConstants.HORIZONTAL ? PROP_LAYOUT_COMPONENT_HORIZONTAL_SIZE
552                 : PROP_LAYOUT_COMPONENT_VERTICAL_SIZE, Integer JavaDoc.class, null, null);
553             boolean horizontal = dimension == LayoutConstants.HORIZONTAL;
554             setDisplayName(FormUtils.getBundleString(horizontal ?
555                 "PROP_LAYOUT_COMPONENT_HORIZONTAL_SIZE" : "PROP_LAYOUT_COMPONENT_VERTICAL_SIZE")); // NOI18N
556
setShortDescription(FormUtils.getBundleString(horizontal ?
557                 "HINT_LAYOUT_COMPONENT_HORIZONTAL_SIZE" : "HINT_LAYOUT_COMPONENT_VERTICAL_SIZE")); // NOI18N
558
this.component = component;
559             this.dimension = dimension;
560             setValue("canEditAsText", Boolean.TRUE); // NOI18N
561
}
562             
563         public void setValue(Object JavaDoc value) {
564             if (!(value instanceof Integer JavaDoc))
565                 throw new IllegalArgumentException JavaDoc();
566             
567             Integer JavaDoc oldValue = (Integer JavaDoc)getValue();
568             Integer JavaDoc newValue = (Integer JavaDoc)value;
569             LayoutModel layoutModel = getFormModel().getLayoutModel();
570             LayoutInterval interval = component.getLayoutInterval(dimension);
571             Object JavaDoc layoutUndoMark = layoutModel.getChangeMark();
572             javax.swing.undo.UndoableEdit JavaDoc ue = layoutModel.getUndoableEdit();
573             boolean autoUndo = true;
574             try {
575                 layoutModel.setIntervalSize(interval, interval.getMinimumSize(false), newValue.intValue(), interval.getMaximumSize(false));
576                 getNodeReference().firePropertyChangeHelper(
577                     getName(), oldValue, newValue);
578                 autoUndo = false;
579             } finally {
580                 getFormModel().fireContainerLayoutChanged(getParentContainer(), null, null, null);
581                 if (!layoutUndoMark.equals(layoutModel.getChangeMark())) {
582                     getFormModel().addUndoableEdit(ue);
583                 }
584                 if (autoUndo) {
585                     getFormModel().forceUndoOfCompoundEdit();
586                 }
587             }
588         }
589         
590         public Object JavaDoc getValue() {
591             int size = component.getLayoutInterval(dimension).getPreferredSize(false);
592             return new Integer JavaDoc(size);
593         }
594
595         public boolean supportsDefaultValue() {
596             return true;
597         }
598         
599         public void restoreDefaultValue() {
600             setValue(new Integer JavaDoc(LayoutConstants.NOT_EXPLICITLY_DEFINED));
601         }
602         
603         public boolean isDefaultValue() {
604             return ((Integer JavaDoc)getValue()).intValue() == LayoutConstants.NOT_EXPLICITLY_DEFINED;
605         }
606         
607         public PropertyEditor getPropertyEditor() {
608             return new PropertyEditorSupport() {
609                 private String JavaDoc notExplicitelyDefined = FormUtils.getBundleString("VALUE_SizeNotExplicitelyDefined"); // NOI18N
610

611                 public String JavaDoc[] getTags() {
612                     return new String JavaDoc[] {notExplicitelyDefined};
613                 }
614
615                 public String JavaDoc getAsText() {
616                     Integer JavaDoc value = (Integer JavaDoc)getValue();
617                     if (value.intValue() == LayoutConstants.NOT_EXPLICITLY_DEFINED) {
618                         return notExplicitelyDefined;
619                     } else {
620                         return value.toString();
621                     }
622                 }
623
624                 public void setAsText(String JavaDoc str) {
625                     if (notExplicitelyDefined.equals(str)) {
626                         setValue(new Integer JavaDoc(LayoutConstants.NOT_EXPLICITLY_DEFINED));
627                     } else {
628                         try {
629                             setValue(new Integer JavaDoc(Integer.parseInt(str)));
630                         }
631                         catch (NumberFormatException JavaDoc e) {} // ignore
632
}
633                 }
634             };
635         }
636
637         public boolean canWrite() {
638             return !isReadOnly();
639         }
640     
641     }
642     
643     /**
644      * Property that determines whether the component should be resizable.
645      */

646     private class LayoutComponentResizableProperty extends PropertySupport.ReadWrite {
647         private LayoutComponent component;
648         private int dimension;
649         
650         private LayoutComponentResizableProperty(LayoutComponent component, int dimension) {
651             super(dimension == LayoutConstants.HORIZONTAL ? PROP_LAYOUT_COMPONENT_HORIZONTAL_RESIZABLE
652                 : PROP_LAYOUT_COMPONENT_VERTICAL_RESIZABLE, Boolean JavaDoc.class, null, null);
653             boolean horizontal = dimension == LayoutConstants.HORIZONTAL;
654             setDisplayName(FormUtils.getBundleString(horizontal ?
655                 "PROP_LAYOUT_COMPONENT_HORIZONTAL_RESIZABLE" : "PROP_LAYOUT_COMPONENT_VERTICAL_RESIZABLE")); // NOI18N
656
setShortDescription(FormUtils.getBundleString(horizontal ?
657                 "HINT_LAYOUT_COMPONENT_HORIZONTAL_RESIZABLE" : "HINT_LAYOUT_COMPONENT_VERTICAL_RESIZABLE")); // NOI18N
658
this.component = component;
659             this.dimension = dimension;
660         }
661             
662         public void setValue(Object JavaDoc value) {
663             if (!(value instanceof Boolean JavaDoc))
664                 throw new IllegalArgumentException JavaDoc();
665             
666             Boolean JavaDoc oldValue = (Boolean JavaDoc)getValue();
667             Boolean JavaDoc newValue = (Boolean JavaDoc)value;
668             boolean resizable = newValue.booleanValue();
669             LayoutModel layoutModel = getFormModel().getLayoutModel();
670             LayoutInterval interval = component.getLayoutInterval(dimension);
671             Object JavaDoc layoutUndoMark = layoutModel.getChangeMark();
672             javax.swing.undo.UndoableEdit JavaDoc ue = layoutModel.getUndoableEdit();
673             boolean autoUndo = true;
674             try {
675                 layoutModel.setIntervalSize(interval,
676                     resizable ? LayoutConstants.NOT_EXPLICITLY_DEFINED : LayoutConstants.USE_PREFERRED_SIZE,
677                     interval.getPreferredSize(false),
678                     resizable ? Short.MAX_VALUE : LayoutConstants.USE_PREFERRED_SIZE);
679                 getNodeReference().firePropertyChangeHelper(
680                     getName(), oldValue, newValue);
681                 autoUndo = false;
682             } finally {
683                 getFormModel().fireContainerLayoutChanged(getParentContainer(), null, null, null);
684                 if (!layoutUndoMark.equals(layoutModel.getChangeMark())) {
685                     getFormModel().addUndoableEdit(ue);
686                 }
687                 if (autoUndo) {
688                     getFormModel().forceUndoOfCompoundEdit();
689                 }
690             }
691         }
692         
693         public Object JavaDoc getValue() {
694             int pref = component.getLayoutInterval(dimension).getPreferredSize(false);
695             int max = component.getLayoutInterval(dimension).getMaximumSize(false);
696             return Boolean.valueOf((max != pref) && (max != LayoutConstants.USE_PREFERRED_SIZE));
697         }
698
699         public boolean supportsDefaultValue() {
700             return true;
701         }
702         
703         public void restoreDefaultValue() {
704             setValue(Boolean.FALSE);
705         }
706         
707         public boolean isDefaultValue() {
708             return getValue().equals(Boolean.FALSE);
709         }
710
711         public boolean canWrite() {
712             return !isReadOnly();
713         }
714
715     }
716
717 }
718
Popular Tags