KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > form > editors2 > BorderEditor


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.editors2;
21
22 import java.awt.*;
23 import java.awt.event.ComponentAdapter JavaDoc;
24 import java.awt.event.ComponentEvent JavaDoc;
25 import java.beans.*;
26 import java.util.*;
27 import javax.swing.*;
28 import java.text.MessageFormat JavaDoc;
29 import java.io.IOException JavaDoc;
30 import javax.swing.border.*;
31
32 import org.openide.ErrorManager;
33 import org.openide.awt.Mnemonics;
34 import org.openide.nodes.*;
35 import org.openide.explorer.view.ListView;
36 import org.openide.explorer.propertysheet.PropertySheetView;
37 import org.openide.explorer.propertysheet.editors.XMLPropertyEditor;
38 import org.openide.explorer.*;
39
40 import org.netbeans.modules.form.*;
41 import org.netbeans.modules.form.palette.*;
42 import org.openide.nodes.Node.PropertySet;
43
44 /**
45  * A property editor for swing border class.
46  *
47  * This editor should be in some subpackage under developerx package,
48  * but it is not possible now, because this package is only package where are
49  * property editors searched.
50  */

51
52 public final class BorderEditor extends PropertyEditorSupport
53                                 implements FormAwareEditor,
54                                            XMLPropertyEditor,
55                                            NamedPropertyEditor,
56                        BeanPropertyEditor
57 {
58     /** Icon base for unknown border node. */
59     private static final String JavaDoc UNKNOWN_BORDER_BASE =
60         "org/netbeans/modules/form/editors2/unknownBorder.gif"; // NOI18N
61
/** Icon base for no border node. */
62     private static final String JavaDoc NO_BORDER_BASE =
63         "org/netbeans/modules/form/editors2/nullBorder.gif"; // NOI18N
64

65     private static FormProperty[] EMPTY_PROPERTIES = new FormProperty[0];
66     
67     // --------------
68
// variables
69

70     private Object JavaDoc current;
71
72     private FormPropertyContext propertyContext;
73     private BorderDesignSupport borderSupport;
74
75     // customizer
76
private BorderPanel bPanel;
77
78     // --------------
79
// init
80

81     public BorderEditor() {
82         bPanel = null;
83         current = null;
84     }
85
86     // FormAwareEditor implementation
87
public void setFormModel(FormModel model) {
88         propertyContext = createFormPropertyContext(model);
89     }
90
91     public static FormPropertyContext createFormPropertyContext(FormModel model) {
92         return new FormPropertyContext.DefaultImpl(model);
93     }
94     
95     // ------------------
96
// main methods
97

98     public Object JavaDoc getValue() {
99         return current;
100     }
101
102     public void setValue(Object JavaDoc value) {
103         if (current == value)
104             return;
105
106         current = value;
107         borderSupport = null;
108
109         if (value instanceof BorderDesignSupport) {
110             borderSupport = (BorderDesignSupport) value;
111         } else if (value != null) {
112             assert (value instanceof Border);
113             if (!(value instanceof javax.swing.plaf.UIResource JavaDoc))
114                 borderSupport = new BorderDesignSupport((Border)value);
115         }
116
117         if (borderSupport != null) {
118             borderSupport.setPropertyContext(propertyContext);
119
120             if (bPanel != null)
121                 bPanel.setValue(value);
122         }
123     }
124
125     public String JavaDoc getAsText() {
126         return null;
127     }
128
129     public void setAsText(String JavaDoc string) {
130     }
131
132     public boolean isPaintable() {
133         return true;
134     }
135
136     public void paintValue(Graphics g, Rectangle rectangle) {
137
138         String JavaDoc valueText;
139         Object JavaDoc value = getValue();
140
141         if (value == null)
142             valueText = getBundle().getString("LAB_NoBorder"); // NOI18N
143
else if (borderSupport != null)
144             valueText = "[" + borderSupport.getDisplayName() + "]"; // NOI18N
145
else
146             valueText = "[" + org.openide.util.Utilities.getShortClassName( // NOI18N
147
value.getClass()) + "]"; // NOI18N
148

149
150         FontMetrics fm = g.getFontMetrics();
151         g.drawString(valueText, rectangle.x,
152                        rectangle.y + (rectangle.height - fm.getHeight()) / 2 + fm.getAscent());
153     }
154
155     public String JavaDoc getJavaInitializationString() {
156         Object JavaDoc value = getValue();
157         if (value == null)
158             return "null"; // NOI18N
159
if (borderSupport != null)
160             return borderSupport.getJavaInitializationString();
161
162         // nothing to generate otherwise
163
return null;
164     }
165
166     public boolean supportsCustomEditor() {
167         return true;
168     }
169
170     public Component getCustomEditor() {
171         if (bPanel == null)
172             bPanel = new BorderPanel();
173
174         bPanel.setValue(current);
175         return bPanel;
176     }
177
178     // ------------------------------------------
179
// NamedPropertyEditor implementation
180

181     /** @return display name of the property editor */
182     public String JavaDoc getDisplayName() {
183         return getBundle().getString("CTL_BorderEditor_DisplayName"); // NOI18N
184
}
185
186     // ----------------
187

188     /** Update the BorderDesignSupport object according to recent changes.
189      * This is needed when another border was selected or some property of
190      * currently selected border was changed.
191      */

192     void updateBorder(Node node) {
193         if (node instanceof NoBorderNode) {
194             borderSupport = null;
195             current = null;
196         }
197         else if (node instanceof UnknownBorderNode) {
198             current = ((UnknownBorderNode)node).getBorder();
199         }
200         else {
201             borderSupport = ((BorderNode)node).getBorderSupport();
202             current = borderSupport;
203         }
204     }
205
206     // ---------
207

208     private static ResourceBundle getBundle() {
209         return org.openide.util.NbBundle.getBundle(BorderEditor.class);
210     }
211
212     // --------------------------
213
// innerclasses
214

215     final class BorderPanel extends JPanel
216                             implements PropertyChangeListener,
217                                        VetoableChangeListener,
218                                        ExplorerManager.Provider
219     {
220         private ExplorerManager manager = new ExplorerManager ();
221         private Node selectNode = null;
222         private BorderPanel() {
223             getExplorerManager().addPropertyChangeListener(this);
224             getExplorerManager().addVetoableChangeListener(this);
225
226             setLayout(new BorderLayout());
227             setBorder(new EmptyBorder(5, 5, 5, 5));
228
229             ResourceBundle bundle = getBundle();
230
231             ListView listView = new ListView();
232             listView.getAccessibleContext().setAccessibleDescription(
233                 bundle.getString("ACSD_AvailableBorders")); // NOI18N
234

235             JLabel label = new JLabel();
236             Mnemonics.setLocalizedText(label, bundle.getString("LAB_AvailableBorders")); // NOI18N
237
label.setLabelFor(listView);
238
239             JPanel panel = new JPanel();
240             panel.setLayout(new BorderLayout(0, 2));
241             panel.add(label, BorderLayout.NORTH);
242             panel.add(BorderLayout.CENTER, listView);
243
244             PropertySheetView sheetView = new PropertySheetView();
245             
246             JSplitPane split = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
247             split.setTopComponent(panel);
248             split.setBottomComponent(sheetView);
249             split.setUI(new javax.swing.plaf.basic.BasicSplitPaneUI JavaDoc());
250             split.setBorder(BorderFactory.createEmptyBorder());
251             split.setDividerLocation(170);
252             split.setContinuousLayout(true);
253             
254             add(BorderLayout.CENTER, split);
255             
256             getAccessibleContext().setAccessibleDescription(
257                 bundle.getString("ACSD_BorderCustomEditor")); // NOI18N
258
}
259
260         public void addNotify() {
261             super.addNotify();
262             EventQueue.invokeLater(new Runnable JavaDoc(){
263                 public void run() {
264                     try {
265                         getExplorerManager().setSelectedNodes(new Node[] { selectNode });
266                     }
267                     catch (PropertyVetoException e) {} // should not happen
268
}
269             });
270         }
271         
272         void setValue(Object JavaDoc border) {
273             ArrayList bordersList = new ArrayList(10);
274             selectNode = null;
275
276             PaletteItem[] items = PaletteUtils.getAllItems();
277             for (int i = 0; i < items.length; i++) {
278                 PaletteItem paletteItem = items[i];
279                 if (!paletteItem.isBorder())
280                     continue;
281
282                 BorderDesignSupport nodeBDS = null;
283                 try {
284                     // PENDING ClassSource should be used (and project classpath
285
// updated like in MetaComponentCreator.prepareClass)
286
// [now not needed - until custom borders are supported]
287
nodeBDS = new BorderDesignSupport(paletteItem.getComponentClass());
288                 }
289                 catch (Exception JavaDoc ex) {
290                     ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex);
291                 }
292                 if (nodeBDS == null)
293                     continue;
294
295                 Node borderNode;
296                 if (borderSupport != null
297                     && borderSupport.getBorderClass() == nodeBDS.getBorderClass())
298                 {
299                     try {
300                         nodeBDS.setPropertyContext(propertyContext);
301                         FormUtils.copyProperties(borderSupport.getProperties(),
302                                                  nodeBDS.getProperties(),
303                                                  FormUtils.CHANGED_ONLY|FormUtils.DISABLE_CHANGE_FIRING|FormUtils.DONT_CLONE_VALUES);
304                     }
305                     catch (Exception JavaDoc ex) {
306                         ex.printStackTrace();
307                         continue;
308                     }
309                     borderNode = new BorderNode(nodeBDS, paletteItem.getNode());
310                     selectNode = borderNode;
311                 }
312                 else {
313                     nodeBDS.setPropertyContext(propertyContext);
314                     borderNode = new BorderNode(nodeBDS, paletteItem.getNode());
315                 }
316
317                 bordersList.add(borderNode);
318             }
319
320             final Node root = new AbstractNode(new Children.Array());
321             Node noBorder = new NoBorderNode();
322             if (border == null)
323                 selectNode = noBorder;
324             root.getChildren().add(new Node[] { noBorder });
325
326             Node[] bordersArray = new Node[bordersList.size()];
327             bordersList.toArray(bordersArray);
328             Arrays.sort(bordersArray, new Comparator() {
329                 public int compare(Object JavaDoc o1, Object JavaDoc o2) {
330                     return ((Node)o1).getDisplayName().compareTo(
331                              ((Node)o2).getDisplayName());
332                 }
333             });
334             root.getChildren().add(bordersArray);
335
336             if (selectNode == null) {
337                 Node unknownBorder = new UnknownBorderNode(border);
338                 root.getChildren().add(new Node[] { unknownBorder });
339                 selectNode = unknownBorder;
340             }
341         
342         getExplorerManager().setRootContext(root);
343         }
344         
345         // track changes in nodes selection
346
public void propertyChange(PropertyChangeEvent evt) {
347             if (ExplorerManager.PROP_SELECTED_NODES.equals(evt.getPropertyName())) {
348                 Node[] nodes = (Node[]) evt.getNewValue();
349                 if (nodes.length == 1)
350                     updateBorder(nodes[0]);
351 // else if (nodes.length == 0) {
352
// try {
353
// getExplorerManager().setSelectedNodes(new Node[] { noBorder });
354
// }
355
// catch (PropertyVetoException e) {
356
// }
357
// }
358
}
359         }
360
361         // only one border can be selected
362
public void vetoableChange(PropertyChangeEvent evt) throws PropertyVetoException {
363             if (ExplorerManager.PROP_SELECTED_NODES.equals(evt.getPropertyName())) {
364                 Node[] nodes =(Node[]) evt.getNewValue();
365                 if (nodes.length != 1)
366                     throw new PropertyVetoException("", evt); // NOI18N
367
}
368         }
369
370         public Dimension getPreferredSize() {
371             return new Dimension(360, 440);
372         }
373         
374         public ExplorerManager getExplorerManager() {
375             return manager;
376         }
377     }
378
379     final class BorderNode extends FilterNode implements PropertyChangeListener {
380
381         private BorderDesignSupport nodeBorder;
382         private PropertySet[] properties;
383
384         BorderNode(BorderDesignSupport bds, Node paletteItemNode) {
385             super(paletteItemNode, Children.LEAF);
386             nodeBorder = bds;
387         }
388
389         public PropertySet[] getPropertySets () {
390             if (properties == null) {
391                 Node.Property[] props = nodeBorder.getProperties();
392                 Sheet.Set propSet = Sheet.createPropertiesSet();
393                 propSet.put(props);
394
395                 for (int i=0; i < props.length; i++)
396                     if (props[i] instanceof FormProperty)
397                         ((FormProperty)props[i]).addPropertyChangeListener(this);
398
399                 properties = new PropertySet[] { propSet };
400             }
401             return properties;
402         }
403
404         public BorderDesignSupport getBorderSupport() {
405             return nodeBorder;
406         }
407
408         public void propertyChange(PropertyChangeEvent evt) {
409             // update the border
410
updateBorder(this);
411         }
412     }
413
414     static final class NoBorderNode extends AbstractNode {
415         NoBorderNode() {
416             super(Children.LEAF);
417             setDisplayName(getBundle().getString("LAB_NoBorder")); // NOI18N
418
setIconBaseWithExtension(NO_BORDER_BASE);
419         }
420     }
421
422     static final class UnknownBorderNode extends AbstractNode {
423         private Object JavaDoc border;
424
425         UnknownBorderNode(Object JavaDoc border) {
426             super(Children.LEAF);
427             setBorder(border);
428             setIconBaseWithExtension(UNKNOWN_BORDER_BASE);
429         }
430
431         void setBorder(Object JavaDoc border) {
432             this.border = border;
433             String JavaDoc longName = border.getClass().getName();
434             int dot = longName.lastIndexOf('.');
435             String JavaDoc shortName =(dot < 0) ? longName : longName.substring(dot + 1);
436             setDisplayName(new MessageFormat JavaDoc(
437                                getBundle().getString("LAB_FMT_UnknownBorder")) // NOI18N
438
.format(new Object JavaDoc[] { longName, shortName }));
439         }
440
441         Object JavaDoc getBorder() {
442             return border;
443         }
444     }
445
446     //--------------------------------------------------------------------------
447
// XMLPropertyEditor implementation
448

449     private static final String JavaDoc XML_BORDER = "Border"; // NOI18N
450
private static final String JavaDoc ATTR_INFO = "info"; // NOI18N
451
private static final String JavaDoc PROP_NAME = "PropertyName"; // NOI18N
452

453     /** Called to store current property value into XML subtree.
454      * @param doc The XML document to store the XML in - should be used for
455      * creating nodes only
456      * @return the XML DOM element representing a subtree of XML from which
457                the value should be loaded
458      */

459     public org.w3c.dom.Node JavaDoc storeToXML(org.w3c.dom.Document JavaDoc doc) {
460         Object JavaDoc value = getValue();
461         if ((value instanceof BorderDesignSupport || value instanceof Border)
462              && borderSupport != null)
463         {
464             org.w3c.dom.Node JavaDoc storedNode = null;
465
466             // we must preserve backward compatibility of storing standard
467
// swing borders (for which BorderInfo classes were used sooner)
468
Class JavaDoc borderClass = borderSupport.getBorderClass();
469
470             if (borderClass.isAssignableFrom(TitledBorder.class))
471                 storedNode = storeTitledBorder(doc);
472             else if (borderClass.isAssignableFrom(EtchedBorder.class))
473                 storedNode = storeEtchedBorder(doc);
474             else if (borderClass.isAssignableFrom(LineBorder.class))
475                 storedNode = storeLineBorder(doc);
476             else if (borderClass.isAssignableFrom(EmptyBorder.class))
477                 storedNode = storeEmptyBorder(doc);
478             else if (borderClass.isAssignableFrom(CompoundBorder.class))
479                 storedNode = storeCompoundBorder(doc);
480             else if (SoftBevelBorder.class.isAssignableFrom(borderClass))
481                 storedNode = storeBevelBorder(doc, ID_BI_SOFTBEVEL);
482             else if (BevelBorder.class.isAssignableFrom(borderClass))
483                 storedNode = storeBevelBorder(doc, ID_BI_BEVEL);
484             else if (borderClass.isAssignableFrom(MatteBorder.class))
485                 storedNode = storeMatteBorder(doc);
486         
487             // no other way of storing to XML ...
488
// [PENDING: store border as a bean]
489

490             return storedNode;
491         }
492
493         else if (value == null) {
494             return storeNullBorder(doc);
495         }
496
497         return null; // cannot be saved
498
}
499
500     /** Called to load property value from specified XML subtree.
501      * If succesfully loaded, the value should be available via getValue().
502      * An IOException should be thrown when the value cannot be restored from
503      * the specified XML element
504      * @param element the XML DOM element representing a subtree of XML from
505      * which the value should be loaded
506      * @exception IOException thrown when the value cannot be restored from
507                   the specified XML element
508      */

509     public void readFromXML(org.w3c.dom.Node JavaDoc element) throws IOException JavaDoc {
510         if ( !XML_BORDER.equals(element.getNodeName()) )
511     {
512             IOException JavaDoc ex = new IOException JavaDoc("Missing \"Border\" XML element"); // NOI18N
513
ErrorManager.getDefault().annotate(
514                 ex, getBundle().getString("MSG_ERR_MissingMainElement")); // NOI18N
515
throw ex;
516         }
517             
518         org.w3c.dom.NamedNodeMap JavaDoc attributes = element.getAttributes();
519         String JavaDoc infoName = attributes.getNamedItem(ATTR_INFO).getNodeValue();
520         if (ID_BI_NULL_BORDER.equals(infoName))
521             return; // null border
522

523         org.w3c.dom.Node JavaDoc readNode = null;
524         org.w3c.dom.NodeList JavaDoc children = element.getChildNodes();
525         for (int i = 0; i < children.getLength(); i++)
526             if (children.item(i).getNodeType() == org.w3c.dom.Node.ELEMENT_NODE) {
527                 readNode = children.item(i);
528                 break;
529             }
530         if (readNode == null) {
531             IOException JavaDoc ex = new IOException JavaDoc("Missing border data"); // NOI18N
532
ErrorManager.getDefault().annotate(
533                 ex, getBundle().getString("MSG_ERR_MissingBorderData")); // NOI18N
534
throw ex;
535         }
536
537         if (ID_BI_TITLED.equals(infoName))
538             readTitledBorder(readNode);
539         else if (ID_BI_ETCHED.equals(infoName))
540             readEtchedBorder(readNode);
541         else if (ID_BI_LINE.equals(infoName))
542             readLineBorder(readNode);
543         else if (ID_BI_EMPTY.equals(infoName))
544             readEmptyBorder(readNode);
545         else if (ID_BI_COMPOUND.equals(infoName))
546             readCompoundBorder(readNode);
547         else if (ID_BI_SOFTBEVEL.equals(infoName))
548             readBevelBorder(readNode, SoftBevelBorder.class);
549         else if (ID_BI_BEVEL.equals(infoName))
550             readBevelBorder(readNode, BevelBorder.class);
551         else if (ID_BI_MATTECOLOR.equals(infoName)
552                  || ID_BI_MATTEICON.equals(infoName))
553             readMatteBorder(readNode);
554         else if (ID_BI_NULL_BORDER.equals(infoName)) { // no border
555
borderSupport = null;
556         }
557         // no other way of reading from XML
558
// [PENDING: read border as a bean]
559

560         current = borderSupport;
561     }
562     
563     // ------------------------------
564
// helper storing/reading methods
565

566     private org.w3c.dom.Element JavaDoc createBorderInfoNode(org.w3c.dom.Document JavaDoc doc,
567                                                      String JavaDoc name) {
568         org.w3c.dom.Element JavaDoc el = doc.createElement(XML_BORDER);
569         el.setAttribute(ATTR_INFO, name);
570         return el;
571     }
572
573     private static void writeProperty(String JavaDoc propName, FormProperty prop,
574                                       org.w3c.dom.Element JavaDoc el,
575                                       org.w3c.dom.Document JavaDoc doc) {
576         org.w3c.dom.Node JavaDoc valueNode = null;
577
578         PropertyEditor propEd = prop.getCurrentEditor();
579         if (propEd instanceof XMLPropertyEditor) {
580             Object JavaDoc value;
581             try {
582                 value = prop.getValue();
583             }
584             catch (Exception JavaDoc ex) {
585                 ex.printStackTrace(); // problem getting value => ignore
586
return;
587             }
588             propEd.setValue(value);
589             valueNode = ((XMLPropertyEditor)propEd).storeToXML(doc);
590             if (valueNode != null) {
591                 el.appendChild(valueNode);
592                 if (valueNode.getNodeType() == org.w3c.dom.Node.ELEMENT_NODE)
593                     ((org.w3c.dom.Element JavaDoc)valueNode).setAttribute(PROP_NAME, propName);
594                 return;
595             }
596         }
597
598         // TODO for custom borders
599
/* // writing property to XML didn't succeed (should not happen
600         // for standard swing borders)
601         try {
602             String encodedSerializeValue = GandalfPersistenceManager
603                                                  .encodeValue(prop.getValue());
604             if (encodedSerializeValue != null)
605                 el.setAttribute(propName, encodedSerializeValue);
606
607
608
609
610
611
612         }
613         catch (Exception ex) { // should not happen
614             ex.printStackTrace();
615         } */

616     }
617
618     private static Object JavaDoc readProperty(String JavaDoc xmlPropName,
619                                        String JavaDoc borderPropName,
620                                        BorderDesignSupport bSupport,
621                                        org.w3c.dom.Node JavaDoc element)
622         throws IOException JavaDoc
623     {
624         boolean valueRead = false;
625         Object JavaDoc value = null;
626         org.w3c.dom.Node JavaDoc propNode = null;
627         org.w3c.dom.NodeList JavaDoc items = element.getChildNodes();
628
629         for (int i = 0; i < items.getLength(); i++)
630             if (items.item(i).getNodeType() == org.w3c.dom.Node.ELEMENT_NODE
631                 && ((org.w3c.dom.Element JavaDoc)items.item(i)).getAttribute(PROP_NAME)
632                                                          .equals(xmlPropName)) {
633                 propNode = items.item(i);
634                 break;
635             }
636
637         if (propNode != null) { // node found
638
FormProperty prop = (FormProperty)
639                 bSupport.getPropertyOfName(borderPropName);
640             if (prop == null) {
641                 IOException JavaDoc ex = new IOException JavaDoc("Unknown property"); // NOI18N
642

643                 ErrorManager.getDefault().annotate(
644                     ex,
645                     MessageFormat.format(
646                         getBundle().getString("FMT_ERR_UnknownProperty"), // NOI18N
647
new Object JavaDoc[] { borderPropName,
648                                        bSupport.getBorderClass().getName() }));
649                 throw ex;
650             }
651
652             IOException JavaDoc lastEx = null;
653             PropertyEditor editors[] = FormPropertyEditorManager.getAllEditors(prop);
654
655             for (int i=0; i < editors.length && !valueRead; i++) {
656                 PropertyEditor prEd = editors[i];
657                 if (prEd instanceof XMLPropertyEditor) {
658                     try {
659                         prop.getPropertyContext().initPropertyEditor(prEd);
660                         ((XMLPropertyEditor)prEd).readFromXML(propNode);
661                         value = prEd.getValue();
662                         prop.setValue(value);
663                         prop.setCurrentEditor(prEd);
664                         valueRead = true;
665                     }
666                     catch (IOException JavaDoc ex) {
667                         lastEx = ex;
668                     }
669                     catch (Exception JavaDoc ex) {
670                         lastEx = new IOException JavaDoc();
671                         ErrorManager.getDefault().annotate(lastEx, ex);
672                     }
673                 }
674             }
675             if (!valueRead && lastEx != null) {
676                 ErrorManager.getDefault().annotate(
677                     lastEx,
678                     MessageFormat.format(
679                         getBundle().getString("FMT_ERR_CannotReadBorderProperty"), // NOI18N
680
new Object JavaDoc[] { xmlPropName }));
681                 throw lastEx;
682             }
683         }
684     // TODO for custom borders
685
/* else { // node not found, try attribute (of the element) with encoded
686                // serialized value
687             org.w3c.dom.NamedNodeMap attributes = element.getAttributes();
688             org.w3c.dom.Node attr = attributes == null ? null :
689                                     attributes.getNamedItem(xmlPropName);
690             if (attr != null) { // but it happened...
691                 String valueText = attr.getNodeValue();
692                 if (valueText != null) {
693                     FormProperty prop = (FormProperty)bSupport
694                                             .getPropertyOfName(borderPropName);
695                     try {
696                         if (prop != null && (value = GandalfPersistenceManager
697
698                                             .decodeValue(valueText)) != null)
699                             prop.setValue(value);
700                     }
701                     catch (IOException ex) {
702                         ErrorManager.getDefault().annotate(
703                             ex,
704                             MessageFormat.format(
705                                 getBundle().getString(
706                                     "FMT_ERR_CannotReadBorderProperty"), // NOI18N
707                                 new Object[] { xmlPropName }));
708                         throw ex;
709                     }
710                     catch (Exception ex) {
711                         IOException ioex = new IOException();
712                         ErrorManager.getDefault().annotate(
713                             ioex,
714                             ErrorManager.EXCEPTION,
715                             null,
716                             MessageFormat.format(
717                                 getBundle().getString(
718                                     "FMT_ERR_CannotReadAndSetBorderProperty"), // NOI18N
719                                 new Object[] { xmlPropName }),
720                             ex,
721                             null);
722                         throw ioex;
723                     }
724                 }
725             }
726         } */

727
728         return value;
729     }
730
731     // -----------------
732
// No border (null)
733

734     private static final String JavaDoc ID_BI_NULL_BORDER = "null"; // NOI18N
735

736     private org.w3c.dom.Node JavaDoc storeNullBorder(org.w3c.dom.Document JavaDoc doc) {
737         try {
738             return createBorderInfoNode(doc, ID_BI_NULL_BORDER);
739         }
740         catch (Exception JavaDoc ex) { // should not happen
741
ex.printStackTrace();
742         }
743         return null;
744     }
745
746     // ------------------------------------------------------------------------
747
// TitledBorder XML persistence - compatible with former TitledBorderInfo
748

749     private static final String JavaDoc XML_TITLED_BORDER = "TitledBorder"; // NOI18N
750
private static final String JavaDoc ID_BI_TITLED // "ID" of former TitledBorderInfo
751
= "org.netbeans.modules.form.compat2.border.TitledBorderInfo"; // NOI18N
752

753     private static final String JavaDoc ATTR_TITLE = "title"; // NOI18N
754
private static final String JavaDoc ATTR_TITLE_X = "titleX"; // NOI18N
755
private static final String JavaDoc ATTR_BORDER = "innerBorder"; // NOI18N
756
private static final String JavaDoc ATTR_JUSTIFICATION = "justification"; // NOI18N
757
private static final String JavaDoc ATTR_POSITION = "position"; // NOI18N
758
private static final String JavaDoc ATTR_FONT = "font"; // NOI18N
759
private static final String JavaDoc ATTR_TITLE_COLOR = "color"; // NOI18N
760

761     private org.w3c.dom.Node JavaDoc storeTitledBorder(org.w3c.dom.Document JavaDoc doc) {
762         try {
763             org.w3c.dom.Element JavaDoc el = doc.createElement(XML_TITLED_BORDER);
764             FormProperty prop;
765
766             prop = (FormProperty)borderSupport.getPropertyOfName("border"); // NOI18N
767
if (prop != null && prop.isChanged())
768                 writeProperty(ATTR_BORDER, prop, el, doc);
769
770             prop = (FormProperty)borderSupport.getPropertyOfName("title"); // NOI18N
771
if (prop != null && prop.isChanged()) {
772                 Object JavaDoc realValue = prop.getRealValue();
773                 el.setAttribute(ATTR_TITLE, realValue instanceof String JavaDoc ?
774                                             (String JavaDoc)realValue : ""); // NOI18N
775

776                 Object JavaDoc value = prop.getValue();
777                 if (value instanceof FormDesignValue)
778                     // store also FormDesignValue (for title only)
779
writeProperty(ATTR_TITLE_X, prop, el, doc);
780             }
781
782             prop = (FormProperty)borderSupport.getPropertyOfName("titleJustification"); // NOI18N
783
if (prop != null && prop.isChanged())
784                 el.setAttribute(ATTR_JUSTIFICATION, prop.getRealValue().toString());
785
786             prop = (FormProperty)borderSupport.getPropertyOfName("titlePosition"); // NOI18N
787
if (prop != null && prop.isChanged())
788                 el.setAttribute(ATTR_POSITION, prop.getRealValue().toString());
789
790             prop = (FormProperty)borderSupport.getPropertyOfName("titleFont"); // NOI18N
791
if (prop != null && prop.isChanged())
792                 writeProperty(ATTR_FONT, prop, el, doc);
793
794             prop = (FormProperty)borderSupport.getPropertyOfName("titleColor"); // NOI18N
795
if (prop != null && prop.isChanged())
796                 writeProperty(ATTR_TITLE_COLOR, prop, el, doc);
797
798             org.w3c.dom.Node JavaDoc nod = createBorderInfoNode(doc, ID_BI_TITLED);
799             nod.appendChild(el);
800             return nod;
801         }
802         catch (Exception JavaDoc ex) { // should not happen
803
ex.printStackTrace();
804         }
805         return null;
806     }
807
808     public void readTitledBorder(org.w3c.dom.Node JavaDoc element) throws IOException JavaDoc {
809         if (!XML_TITLED_BORDER.equals(element.getNodeName()))
810             throw new IOException JavaDoc("Invalid format: missing \""+XML_TITLED_BORDER+"\" element."); // NOI18N
811

812         try {
813             org.w3c.dom.NamedNodeMap JavaDoc attributes = element.getAttributes();
814             org.w3c.dom.Node JavaDoc node;
815
816             borderSupport = new BorderDesignSupport(TitledBorder.class);
817             borderSupport.setPropertyContext(propertyContext);
818             FormProperty prop;
819
820             readProperty(ATTR_BORDER, "border", borderSupport, element); // NOI18N
821

822             // for title, first try to read FormDesignValue
823
Object JavaDoc title = readProperty(ATTR_TITLE_X, "title", borderSupport, element); // NOI18N
824
if (title == null // no design value, get simple String attribute
825
&& (node = attributes.getNamedItem(ATTR_TITLE)) != null
826                   && (prop = (FormProperty)borderSupport
827                                           .getPropertyOfName("title")) != null) // NOI18N
828
prop.setValue(node.getNodeValue());
829
830             node = attributes.getNamedItem(ATTR_JUSTIFICATION);
831             if (node != null && (prop = (FormProperty)borderSupport
832                              .getPropertyOfName("titleJustification")) != null) // NOI18N
833
prop.setValue(new Integer JavaDoc(node.getNodeValue()));
834
835             node = attributes.getNamedItem(ATTR_POSITION);
836             if (node != null && (prop = (FormProperty)borderSupport
837                                   .getPropertyOfName("titlePosition")) != null) // NOI18N
838
prop.setValue(new Integer JavaDoc(node.getNodeValue()));
839
840             readProperty(ATTR_FONT, "titleFont", borderSupport, element); // NOI18N
841

842             readProperty(ATTR_TITLE_COLOR, "titleColor", borderSupport, element); // NOI18N
843
}
844         catch (IOException JavaDoc ex) {
845             throw ex;
846         }
847         catch (Exception JavaDoc ex) {
848             IOException JavaDoc ioex = new IOException JavaDoc();
849             ErrorManager.getDefault().annotate(ioex, ex);
850             throw ioex;
851         }
852     }
853
854     // ------------------------------------------------------------------------
855
// EtchedBorder XML persistence - compatible with former EtchedBorderInfo
856

857     private static final String JavaDoc XML_ETCHED_BORDER = "EtchetBorder"; // NOI18N
858
private static final String JavaDoc ID_BI_ETCHED // "ID" of former EtchedBorderInfo
859
= "org.netbeans.modules.form.compat2.border.EtchedBorderInfo"; // NOI18N
860

861     private static final String JavaDoc ATTR_ETCH_TYPE = "bevelType"; // NOI18N
862
private static final String JavaDoc ATTR_HIGHLIGHT = "highlight"; // NOI18N
863
private static final String JavaDoc ATTR_SHADOW = "shadow"; // NOI18N
864

865     public org.w3c.dom.Node JavaDoc storeEtchedBorder(org.w3c.dom.Document JavaDoc doc) {
866         try {
867             org.w3c.dom.Element JavaDoc el = doc.createElement(XML_ETCHED_BORDER);
868             FormProperty prop;
869
870             prop = (FormProperty)borderSupport.getPropertyOfName("etchType"); // NOI18N
871
if (prop != null && prop.isChanged())
872                 el.setAttribute(ATTR_ETCH_TYPE, prop.getRealValue().toString());
873
874             prop = (FormProperty)borderSupport.getPropertyOfName("highlightColor"); // NOI18N
875
if (prop != null && prop.isChanged())
876                 writeProperty(ATTR_HIGHLIGHT, prop, el, doc);
877
878             prop = (FormProperty)borderSupport.getPropertyOfName("shadowColor"); // NOI18N
879
if (prop != null && prop.isChanged())
880                 writeProperty(ATTR_SHADOW, prop, el, doc);
881
882             org.w3c.dom.Node JavaDoc nod = createBorderInfoNode(doc, ID_BI_ETCHED);
883             nod.appendChild(el);
884             return nod;
885         }
886         catch (Exception JavaDoc ex) { // should not happen
887
ex.printStackTrace();
888         }
889         return null;
890     }
891
892     public void readEtchedBorder(org.w3c.dom.Node JavaDoc element) throws IOException JavaDoc {
893         if (!XML_ETCHED_BORDER.equals(element.getNodeName()))
894             throw new IOException JavaDoc("Invalid format: missing \""+XML_ETCHED_BORDER+"\" element."); // NOI18N
895

896         try {
897             org.w3c.dom.NamedNodeMap JavaDoc attributes = element.getAttributes();
898             org.w3c.dom.Node JavaDoc node;
899
900             borderSupport = new BorderDesignSupport(EtchedBorder.class);
901             borderSupport.setPropertyContext(propertyContext);
902             FormProperty prop;
903
904             node = attributes.getNamedItem(ATTR_ETCH_TYPE);
905             if (node != null && (prop = (FormProperty)borderSupport
906                                        .getPropertyOfName("etchType")) != null) // NOI18N
907
prop.setValue(new Integer JavaDoc(node.getNodeValue()));
908
909             readProperty(ATTR_HIGHLIGHT, "highlightColor", borderSupport, element); // NOI18N
910

911             readProperty(ATTR_SHADOW, "shadowColor", borderSupport, element); // NOI18N
912
}
913         catch (IOException JavaDoc ex) {
914             throw ex;
915         }
916         catch (Exception JavaDoc ex) {
917             IOException JavaDoc ioex = new IOException JavaDoc();
918             ErrorManager.getDefault().annotate(ioex, ex);
919             throw ioex;
920         }
921     }
922
923     // ------------------------------------------------------------------------
924
// LineBorder XML persistence - compatible with former LineBorderInfo
925

926     private static final String JavaDoc XML_LINE_BORDER = "LineBorder"; // NOI18N
927
private static final String JavaDoc ID_BI_LINE // "ID" of former LineBorderInfo
928
= "org.netbeans.modules.form.compat2.border.LineBorderInfo"; // NOI18N
929

930     private static final String JavaDoc ATTR_THICKNESS = "thickness"; // NOI18N
931
private static final String JavaDoc ATTR_LINE_COLOR = "color"; // NOI18N
932
private static final String JavaDoc ATTR_CORNERS = "roundedCorners"; // NOI18N
933

934     public org.w3c.dom.Node JavaDoc storeLineBorder(org.w3c.dom.Document JavaDoc doc) {
935         try {
936             org.w3c.dom.Element JavaDoc el = doc.createElement(XML_LINE_BORDER);
937             FormProperty prop;
938
939             prop = (FormProperty)borderSupport.getPropertyOfName("lineColor"); // NOI18N
940
if (prop != null && prop.isChanged())
941                 writeProperty(ATTR_LINE_COLOR, prop, el, doc);
942
943             prop = (FormProperty)borderSupport.getPropertyOfName("thickness"); // NOI18N
944
if (prop != null && prop.isChanged())
945                 el.setAttribute(ATTR_THICKNESS, prop.getRealValue().toString());
946
947             prop = (FormProperty)borderSupport.getPropertyOfName("roundedCorners"); // NOI18N
948
if (prop != null && prop.isChanged())
949                 el.setAttribute(ATTR_CORNERS, prop.getRealValue().toString());
950
951             org.w3c.dom.Node JavaDoc nod = createBorderInfoNode(doc, ID_BI_LINE);
952             nod.appendChild(el);
953             return nod;
954         }
955         catch (Exception JavaDoc ex) { // should not happen
956
ex.printStackTrace();
957         }
958         return null;
959     }
960
961     public void readLineBorder(org.w3c.dom.Node JavaDoc element) throws IOException JavaDoc {
962         if (!XML_LINE_BORDER.equals(element.getNodeName()))
963             throw new IOException JavaDoc("Invalid format: missing \""+XML_LINE_BORDER+"\" element."); // NOI18N
964

965         try {
966             org.w3c.dom.NamedNodeMap JavaDoc attributes = element.getAttributes();
967             org.w3c.dom.Node JavaDoc node;
968
969             borderSupport = new BorderDesignSupport(LineBorder.class);
970             borderSupport.setPropertyContext(propertyContext);
971             FormProperty prop;
972
973             readProperty(ATTR_LINE_COLOR, "lineColor", borderSupport, element); // NOI18N
974

975             node = attributes.getNamedItem(ATTR_THICKNESS);
976             if (node != null && (prop = (FormProperty)borderSupport
977                                        .getPropertyOfName("thickness")) != null) // NOI18N
978
prop.setValue(new Integer JavaDoc(node.getNodeValue()));
979
980             node = attributes.getNamedItem(ATTR_CORNERS);
981             if (node != null && (prop = (FormProperty)borderSupport
982                                        .getPropertyOfName("roundedCorners")) != null) // NOI18N
983
prop.setValue(Boolean.valueOf(node.getNodeValue()));
984         }
985         catch (IOException JavaDoc ex) {
986             throw ex;
987         }
988         catch (Exception JavaDoc ex) {
989             IOException JavaDoc ioex = new IOException JavaDoc();
990             ErrorManager.getDefault().annotate(ioex, ex);
991             throw ioex;
992         }
993     }
994
995     // ------------------------------------------------------------------------
996
// EmptyBorder XML persistence - compatible with former EmptyBorderInfo
997

998     private static final String JavaDoc XML_EMPTY_BORDER = "EmptyBorder"; // NOI18N
999
private static final String JavaDoc ID_BI_EMPTY // "ID" of former EmptyBorderInfo
1000
= "org.netbeans.modules.form.compat2.border.EmptyBorderInfo"; // NOI18N
1001

1002    private static final String JavaDoc ATTR_TOP = "top"; // NOI18N
1003
private static final String JavaDoc ATTR_LEFT = "left"; // NOI18N
1004
private static final String JavaDoc ATTR_RIGHT = "right"; // NOI18N
1005
private static final String JavaDoc ATTR_BOTTOM = "bottom"; // NOI18N
1006

1007    public org.w3c.dom.Node JavaDoc storeEmptyBorder(org.w3c.dom.Document JavaDoc doc) {
1008        try {
1009            org.w3c.dom.Element JavaDoc el = doc.createElement(XML_EMPTY_BORDER);
1010            FormProperty prop = (FormProperty)borderSupport.getPropertyOfName(
1011                                                               "borderInsets"); // NOI18N
1012
Object JavaDoc value;
1013            if (prop != null && prop.isChanged()
1014                  && (value = prop.getRealValue()) instanceof Insets) {
1015                Insets insets = (Insets)value;
1016                el.setAttribute(ATTR_TOP, Integer.toString(insets.top));
1017                el.setAttribute(ATTR_LEFT, Integer.toString(insets.left));
1018                el.setAttribute(ATTR_BOTTOM, Integer.toString(insets.bottom));
1019                el.setAttribute(ATTR_RIGHT, Integer.toString(insets.right));
1020            }
1021
1022            org.w3c.dom.Node JavaDoc nod = createBorderInfoNode(doc, ID_BI_EMPTY);
1023            nod.appendChild(el);
1024            return nod;
1025        }
1026        catch (Exception JavaDoc ex) { // should not happen
1027
ex.printStackTrace();
1028        }
1029        return null;
1030    }
1031
1032    public void readEmptyBorder(org.w3c.dom.Node JavaDoc element) throws IOException JavaDoc {
1033        if (!XML_EMPTY_BORDER.equals(element.getNodeName()))
1034            throw new IOException JavaDoc("Invalid format: missing \""+XML_EMPTY_BORDER+"\" element."); // NOI18N
1035

1036        try {
1037            org.w3c.dom.NamedNodeMap JavaDoc attributes = element.getAttributes();
1038            org.w3c.dom.Node JavaDoc node;
1039
1040            int top=1, left=1, bottom=1, right=1;
1041
1042            if ((node = attributes.getNamedItem(ATTR_TOP)) != null)
1043                top = Integer.parseInt(node.getNodeValue());
1044            if ((node = attributes.getNamedItem(ATTR_LEFT)) != null)
1045                left = Integer.parseInt(node.getNodeValue());
1046            if ((node = attributes.getNamedItem(ATTR_BOTTOM)) != null)
1047                bottom = Integer.parseInt(node.getNodeValue());
1048            if ((node = attributes.getNamedItem(ATTR_RIGHT)) != null)
1049                right = Integer.parseInt(node.getNodeValue());
1050            
1051            borderSupport = new BorderDesignSupport(EmptyBorder.class);
1052            borderSupport.setPropertyContext(propertyContext);
1053            FormProperty prop;
1054
1055            if ((top != 1 || left != 1 || bottom != 1 || right != 1)
1056                  && (prop = (FormProperty)borderSupport
1057                                   .getPropertyOfName("borderInsets")) != null) // NOI18N
1058
prop.setValue(new Insets(top,left,bottom,right));
1059        }
1060        catch (Exception JavaDoc ex) {
1061            IOException JavaDoc ioex = new IOException JavaDoc();
1062            ErrorManager.getDefault().annotate(ioex, ex);
1063            throw ioex;
1064        }
1065    }
1066
1067    // ------------------------------------------------------------------------
1068
// CompoundBorder XML persistence - compatible with former CompoundBorderInfo
1069

1070    private static final String JavaDoc XML_COMPOUND_BORDER = "CompundBorder"; // NOI18N
1071
private static final String JavaDoc ID_BI_COMPOUND // "ID" of former CompoundBorderInfo
1072
= "org.netbeans.modules.form.compat2.border.CompoundBorderInfo"; // NOI18N
1073

1074    private static final String JavaDoc ATTR_OUTSIDE = "outside"; // NOI18N
1075
private static final String JavaDoc ATTR_INSIDE = "inside"; // NOI18N
1076

1077    private org.w3c.dom.Node JavaDoc storeCompoundBorder(org.w3c.dom.Document JavaDoc doc) {
1078        try {
1079            org.w3c.dom.Element JavaDoc el = doc.createElement(XML_COMPOUND_BORDER);
1080            FormProperty prop;
1081
1082            prop = (FormProperty)borderSupport.getPropertyOfName("outsideBorder"); // NOI18N
1083
if (prop != null && prop.isChanged())
1084                writeProperty(ATTR_OUTSIDE, prop, el, doc);
1085
1086            prop = (FormProperty)borderSupport.getPropertyOfName("insideBorder"); // NOI18N
1087
if (prop != null && prop.isChanged())
1088                writeProperty(ATTR_INSIDE, prop, el, doc);
1089
1090            org.w3c.dom.Node JavaDoc nod = createBorderInfoNode(doc, ID_BI_COMPOUND);
1091            nod.appendChild(el);
1092            return nod;
1093        }
1094        catch (Exception JavaDoc ex) { // should not happen
1095
ex.printStackTrace();
1096        }
1097        return null;
1098    }
1099
1100    public void readCompoundBorder(org.w3c.dom.Node JavaDoc element) throws IOException JavaDoc {
1101        if (!XML_COMPOUND_BORDER.equals(element.getNodeName()))
1102            throw new IOException JavaDoc("Invalid format: missing \""+XML_COMPOUND_BORDER+"\" element."); // NOI18N
1103

1104        try {
1105            borderSupport = new BorderDesignSupport(CompoundBorder.class);
1106            borderSupport.setPropertyContext(propertyContext);
1107
1108            readProperty(ATTR_OUTSIDE, "outsideBorder", borderSupport, element); // NOI18N
1109
readProperty(ATTR_INSIDE, "insideBorder", borderSupport, element); // NOI18N
1110
}
1111        catch (IOException JavaDoc ex) {
1112            throw ex;
1113        }
1114        catch (Exception JavaDoc ex) {
1115            IOException JavaDoc ioex = new IOException JavaDoc();
1116            ErrorManager.getDefault().annotate(ioex, ex);
1117            throw ioex;
1118        }
1119    }
1120
1121    // ------------------------------------------------------------------------
1122
// BevelBorder & SoftBevelBorder XML persistence - compatible with former
1123
// BevelAbstractBorderInfo
1124

1125    private static final String JavaDoc XML_BEVEL_BORDER = "BevelBorder"; // NOI18N
1126
private static final String JavaDoc ID_BI_BEVEL // "ID" of former BevelBorderInfo
1127
= "org.netbeans.modules.form.compat2.border.BevelBorderInfo"; // NOI18N
1128
private static final String JavaDoc ID_BI_SOFTBEVEL // "ID" of former SoftBevelBorderInfo
1129
= "org.netbeans.modules.form.compat2.border.SoftBevelBorderInfo"; // NOI18N
1130

1131    private static final String JavaDoc ATTR_BEVEL_TYPE = "bevelType"; // NOI18N
1132
private static final String JavaDoc ATTR_HIGHLIGHT_OUTER = "highlightOuter"; // NOI18N
1133
private static final String JavaDoc ATTR_HIGHLIGHT_INNER = "highlightInner"; // NOI18N
1134
private static final String JavaDoc ATTR_SHADOW_OUTER = "shadowOuter"; // NOI18N
1135
private static final String JavaDoc ATTR_SHADOW_INNER = "shadowInner"; // NOI18N
1136

1137    public org.w3c.dom.Node JavaDoc storeBevelBorder(org.w3c.dom.Document JavaDoc doc,
1138                                             String JavaDoc infoId) {
1139        try {
1140            org.w3c.dom.Element JavaDoc el = doc.createElement(XML_BEVEL_BORDER);
1141            FormProperty prop;
1142
1143            prop = (FormProperty)borderSupport.getPropertyOfName("bevelType"); // NOI18N
1144
if (prop != null && prop.isChanged())
1145                el.setAttribute(ATTR_BEVEL_TYPE, prop.getRealValue().toString());
1146
1147            prop = (FormProperty)borderSupport.getPropertyOfName("highlightOuterColor"); // NOI18N
1148
if (prop != null && prop.isChanged())
1149                writeProperty(ATTR_HIGHLIGHT_OUTER, prop, el, doc);
1150
1151            prop = (FormProperty)borderSupport.getPropertyOfName("highlightInnerColor"); // NOI18N
1152
if (prop != null && prop.isChanged())
1153                writeProperty(ATTR_HIGHLIGHT_INNER, prop, el, doc);
1154
1155            prop = (FormProperty)borderSupport.getPropertyOfName("shadowOuterColor"); // NOI18N
1156
if (prop != null && prop.isChanged())
1157                writeProperty(ATTR_SHADOW_OUTER, prop, el, doc);
1158
1159            prop = (FormProperty)borderSupport.getPropertyOfName("shadowInnerColor"); // NOI18N
1160
if (prop != null && prop.isChanged())
1161                writeProperty(ATTR_SHADOW_INNER, prop, el, doc);
1162
1163            org.w3c.dom.Node JavaDoc nod = createBorderInfoNode(doc, infoId);
1164            nod.appendChild(el);
1165            return nod;
1166        }
1167        catch (Exception JavaDoc ex) { // should not happen
1168
ex.printStackTrace();
1169        }
1170        return null;
1171    }
1172
1173    public void readBevelBorder(org.w3c.dom.Node JavaDoc element, Class JavaDoc borderClass)
1174        throws IOException JavaDoc
1175    {
1176        if (!XML_BEVEL_BORDER.equals(element.getNodeName()))
1177            throw new IOException JavaDoc("Invalid format: missing \""+XML_BEVEL_BORDER+"\" element."); // NOI18N
1178

1179        try {
1180            org.w3c.dom.NamedNodeMap JavaDoc attributes = element.getAttributes();
1181            org.w3c.dom.Node JavaDoc node;
1182
1183            borderSupport = new BorderDesignSupport(borderClass);
1184            FormProperty prop;
1185
1186            node = attributes.getNamedItem(ATTR_BEVEL_TYPE);
1187            if (node != null && (prop = (FormProperty)borderSupport
1188                                       .getPropertyOfName("bevelType")) != null) // NOI18N
1189
prop.setValue(new Integer JavaDoc(node.getNodeValue()));
1190
1191            readProperty(ATTR_HIGHLIGHT_OUTER, "highlightOuterColor", borderSupport, element); // NOI18N
1192
readProperty(ATTR_HIGHLIGHT_INNER, "highlightInnerColor", borderSupport, element); // NOI18N
1193
readProperty(ATTR_SHADOW_OUTER, "shadowOuterColor", borderSupport, element); // NOI18N
1194
readProperty(ATTR_SHADOW_INNER, "shadowInnerColor", borderSupport, element); // NOI18N
1195
}
1196        catch (IOException JavaDoc ex) {
1197            throw ex;
1198        }
1199        catch (Exception JavaDoc ex) {
1200            IOException JavaDoc ioex = new IOException JavaDoc();
1201            ErrorManager.getDefault().annotate(ioex, ex);
1202            throw ioex;
1203        }
1204    }
1205
1206    // ------------------------------------------------------------------------
1207
// MatteBorder XML persistence - compatible with former
1208
// MatteColorBorderInfo and MatteIconBorderInfo
1209

1210    private static final String JavaDoc XML_MATTE_COLOR_BORDER = "MatteColorBorder"; // NOI18N
1211
private static final String JavaDoc XML_MATTE_ICON_BORDER = "MatteIconBorder"; // NOI18N
1212
private static final String JavaDoc ID_BI_MATTECOLOR // "ID" of former MatteColorBorderInfo
1213
= "org.netbeans.modules.form.compat2.border.MatteColorBorderInfo"; // NOI18N
1214
private static final String JavaDoc ID_BI_MATTEICON // "ID" of former MatteIconBorderInfo
1215
= "org.netbeans.modules.form.compat2.border.MatteIconBorderInfo"; // NOI18N
1216

1217    private static final String JavaDoc ATTR_MATTE_COLOR = "color"; // NOI18N
1218
private static final String JavaDoc ATTR_MATTE_ICON = "icon"; // NOI18N
1219

1220    public org.w3c.dom.Node JavaDoc storeMatteBorder(org.w3c.dom.Document JavaDoc doc) {
1221        try {
1222            org.w3c.dom.Element JavaDoc el;
1223            String JavaDoc infoId;
1224            FormProperty prop;
1225
1226            prop = (FormProperty)borderSupport.getPropertyOfName("tileIcon"); // NOI18N
1227
if (prop.isChanged()) {
1228                el = doc.createElement(XML_MATTE_ICON_BORDER);
1229                infoId = ID_BI_MATTEICON;
1230                writeProperty(ATTR_MATTE_ICON, prop, el, doc);
1231            }
1232            else {
1233                el = doc.createElement(XML_MATTE_COLOR_BORDER);
1234                infoId = ID_BI_MATTECOLOR;
1235            }
1236
1237            prop = (FormProperty)borderSupport.getPropertyOfName("matteColor"); // NOI18N
1238
if (prop != null && prop.isChanged())
1239                writeProperty(ATTR_MATTE_COLOR, prop, el, doc);
1240
1241            prop = (FormProperty)borderSupport.getPropertyOfName("borderInsets"); // NOI18N
1242
Object JavaDoc value;
1243            if (prop != null && prop.isChanged()
1244                  && (value = prop.getRealValue()) instanceof Insets) {
1245                Insets insets = (Insets)value;
1246                el.setAttribute(ATTR_TOP, Integer.toString(insets.top));
1247                el.setAttribute(ATTR_LEFT, Integer.toString(insets.left));
1248                el.setAttribute(ATTR_BOTTOM, Integer.toString(insets.bottom));
1249                el.setAttribute(ATTR_RIGHT, Integer.toString(insets.right));
1250            }
1251
1252            org.w3c.dom.Node JavaDoc nod = createBorderInfoNode(doc, infoId);
1253            nod.appendChild(el);
1254            return nod;
1255        }
1256        catch (Exception JavaDoc ex) { // should not happen
1257
ex.printStackTrace();
1258        }
1259        return null;
1260    }
1261
1262    public void readMatteBorder(org.w3c.dom.Node JavaDoc element) throws IOException JavaDoc {
1263        if (!XML_MATTE_COLOR_BORDER.equals(element.getNodeName())
1264              && !XML_MATTE_ICON_BORDER.equals(element.getNodeName()))
1265            throw new IOException JavaDoc("Invalid format: missing \""+XML_MATTE_COLOR_BORDER+"\" or \""+XML_MATTE_ICON_BORDER+"\" element."); // NOI18N
1266

1267        try {
1268            borderSupport = new BorderDesignSupport(MatteBorder.class);
1269            borderSupport.setPropertyContext(propertyContext);
1270
1271            readProperty(ATTR_MATTE_ICON, "tileIcon", borderSupport, element); // NOI18N
1272
readProperty(ATTR_MATTE_COLOR, "matteColor", borderSupport, element); // NOI18N
1273

1274            org.w3c.dom.NamedNodeMap JavaDoc attributes = element.getAttributes();
1275            org.w3c.dom.Node JavaDoc node;
1276            FormProperty prop;
1277
1278            int top=1, left=1, bottom=1, right=1;
1279
1280            if ((node = attributes.getNamedItem(ATTR_TOP)) != null)
1281                top = Integer.parseInt(node.getNodeValue());
1282            if ((node = attributes.getNamedItem(ATTR_LEFT)) != null)
1283                left = Integer.parseInt(node.getNodeValue());
1284            if ((node = attributes.getNamedItem(ATTR_BOTTOM)) != null)
1285                bottom = Integer.parseInt(node.getNodeValue());
1286            if ((node = attributes.getNamedItem(ATTR_RIGHT)) != null)
1287                right = Integer.parseInt(node.getNodeValue());
1288            
1289            if ((top != 1 || left != 1 || bottom != 1 || right != 1)
1290                  && (prop = (FormProperty)borderSupport
1291                                   .getPropertyOfName("borderInsets")) != null) // NOI18N
1292
prop.setValue(new Insets(top,left,bottom,right));
1293        }
1294        catch (IOException JavaDoc ex) {
1295            throw ex;
1296        }
1297        catch (Exception JavaDoc ex) {
1298            IOException JavaDoc ioex = new IOException JavaDoc();
1299            ErrorManager.getDefault().annotate(ioex, ex);
1300            throw ioex;
1301        }
1302    }
1303
1304    public boolean valueIsBeanProperty() {
1305    return !isSupportedBorder();
1306    }
1307    
1308    private boolean isSupportedBorder() {
1309        Object JavaDoc value = getValue();
1310    if ((value == null) || (value instanceof javax.swing.plaf.UIResource JavaDoc)) {
1311        // supports also null value - see storeNullBorder()
1312
return true;
1313        }
1314    Class JavaDoc borderClass = borderSupport.getBorderClass();
1315    return borderClass.isAssignableFrom(TitledBorder.class)
1316            || borderClass.isAssignableFrom(EtchedBorder.class)
1317            || borderClass.isAssignableFrom(LineBorder.class)
1318            || borderClass.isAssignableFrom(EmptyBorder.class)
1319            || borderClass.isAssignableFrom(CompoundBorder.class)
1320            || SoftBevelBorder.class.isAssignableFrom(borderClass)
1321            || BevelBorder.class.isAssignableFrom(borderClass)
1322            || borderClass.isAssignableFrom(MatteBorder.class);
1323    }
1324
1325    public Node.Property[] getProperties() {
1326        Object JavaDoc value = getValue();
1327    if ((value == null) || (value instanceof javax.swing.plaf.UIResource JavaDoc)) {
1328        // supports also null value - see storeNullBorder()
1329
return EMPTY_PROPERTIES;
1330    }
1331    return borderSupport.getProperties();
1332    }
1333
1334    public void intializeFromType(Class JavaDoc type) throws Exception JavaDoc {
1335    borderSupport = new BorderDesignSupport(type);
1336    borderSupport.setPropertyContext(propertyContext);
1337    current = borderSupport;
1338    }
1339    
1340}
1341
Popular Tags