KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > suberic > util > gui > propedit > CompositeEditorPane


1 package net.suberic.util.gui.propedit;
2 import javax.swing.*;
3 import java.awt.Container JavaDoc;
4 import java.awt.Component JavaDoc;
5 import java.util.Vector JavaDoc;
6 import java.util.ArrayList JavaDoc;
7 import java.util.List JavaDoc;
8 import net.suberic.util.VariableBundle;
9
10 /**
11  * This is a Property Editor which displays a group of properties.
12  * These properties should all be defined by a single property.
13  *
14  * An example:
15  *
16  * Configuration=foo:bar
17  * Configuration.propertyType=Composite
18  * Configuration.scoped=false
19  * foo=zork
20  * bar=frobozz
21  *
22  * Options:
23  *
24  * See CompositeSwingPropertyEditor for options.
25  *
26  */

27 public class CompositeEditorPane extends CompositeSwingPropertyEditor {
28
29   /**
30    * Creates a CompositeEditorPane.
31    */

32   public CompositeEditorPane() {
33
34   }
35
36   /**
37    * This configures this editor with the following values.
38    *
39    * @param propertyName The property to be edited.
40    * @param template The property that will define the layout of the
41    * editor.
42    * @param manager The PropertyEditorManager that will manage the
43    * changes.
44    */

45   public void configureEditor(String JavaDoc propertyName, String JavaDoc template, String JavaDoc propertyBaseName, PropertyEditorManager newManager) {
46
47     configureBasic(propertyName, template, propertyBaseName, newManager);
48
49     getLogger().fine("creating CompositeEditorPane for " + property + " with template " + editorTemplate);
50
51     //this.setBorder(BorderFactory.createEtchedBorder());
52

53     String JavaDoc borderLabel = manager.getProperty(editorTemplate + ".label.border", "");
54     if (borderLabel.length() > 0) {
55       this.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), borderLabel));
56     }
57
58     List JavaDoc<String JavaDoc> properties = new ArrayList JavaDoc<String JavaDoc>();
59     List JavaDoc<String JavaDoc> templates = new ArrayList JavaDoc<String JavaDoc>();
60
61     getLogger().fine("testing for template " + template);
62
63     List JavaDoc<String JavaDoc> templateNames = manager.getPropertyAsList(template, "");
64     getLogger().fine("templateNames = getProp(" + template + ") = " + manager.getProperty(template, ""));
65
66     for (int i = 0; i < templateNames.size() ; i++) {
67       String JavaDoc subTemplateString = templateNames.get(i);
68       properties.add(createSubProperty(subTemplateString));
69       templates.add(createSubTemplate(subTemplateString));
70     }
71
72     addEditors(properties, templates);
73   }
74
75   public void addEditors(List JavaDoc<String JavaDoc> properties, List JavaDoc<String JavaDoc> templates) {
76     SwingPropertyEditor currentEditor;
77
78     editors = new Vector JavaDoc();
79
80     SpringLayout layout = new SpringLayout();
81
82     this.setLayout(new SpringLayout());
83     Component JavaDoc[] labelComponents = new Component JavaDoc[properties.size()];
84     Component JavaDoc[] valueComponents = new Component JavaDoc[properties.size()];
85     for (int i = 0; i < properties.size(); i++) {
86       getLogger().fine("creating editor for " + properties.get(i) + ", template " + templates.get(i) + ", propertyBase " + propertyBase);
87       currentEditor = (SwingPropertyEditor) manager.createEditor(properties.get(i), templates.get(i), propertyBase);
88       getLogger().fine("got " + currentEditor.getClass().getName());
89       editors.add(currentEditor);
90
91       if (currentEditor instanceof LabelValuePropertyEditor) {
92         LabelValuePropertyEditor lvEditor = (LabelValuePropertyEditor) currentEditor;
93         this.add(lvEditor.labelComponent);
94         labelComponents[i] = lvEditor.labelComponent;
95         this.add(lvEditor.valueComponent);
96         valueComponents[i] = lvEditor.valueComponent;
97       } else {
98         this.add(currentEditor);
99         labelComponents[i] = currentEditor;
100       }
101     }
102     //makeCompactGrid(this, labelComponents, valueComponents, 5, 5, 5, 5);
103
layoutGrid(this, labelComponents, valueComponents, 5, 5, 5, 5, manager.getProperty(editorTemplate + ".nested", "false").equalsIgnoreCase("true"));
104     manager.registerPropertyEditor(property, this);
105   }
106
107
108 }
109
Popular Tags