KickJava   Java API By Example, From Geeks To Geeks.

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


1 package net.suberic.util.gui.propedit;
2 import javax.swing.*;
3 import java.util.Vector JavaDoc;
4 import java.util.List JavaDoc;
5 import java.util.ArrayList JavaDoc;
6
7 /**
8  * This will make an editor for a list of properties. Each property, in
9  * turn, should have a list of properties wihch it itself edits. Each
10  * top-level property will be a tab, with its values shown on the panel.
11  *
12  * So an example of a property definition for this would be:
13  *
14  * TabbedList=tabOne:tabTwo:tabThree
15  * TabbedList.tabOne=prop1:prop2:prop3:prop4
16  * TabbedList.tabTwo=prop5:prop6
17  * TabbedList.tabThree=prop7:prop8:prop9
18  *
19  * Options:
20  * TabbedList.templateScoped - add subproperty to the template. for instance,
21  * if true, the example will edit using the template
22  * TabbedList.tabOne.prop1. if false, it will use the template prop1.
23  * TabbedList.propertyScoped - add the subproperty to the property instead
24  * of using it as its own property. if true, this example would edit,
25  * for instance, MyProp.prop1 (since it would actually edit MyProp,
26  * TabbedList.tabOne, which would in turn probably edit MyProp.prop1,
27  * TabbedList.tabOne.prop1).
28  *
29  */

30 public class TabbedEditorPane extends CompositeSwingPropertyEditor {
31
32   JTabbedPane tabbedPane;
33   protected boolean templateScoped = false;
34   protected boolean propertyScoped = false;
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     configureBasic(propertyName, template, propertyBaseName, newManager);
47
48     debug = manager.getProperty("editors.debug", "false").equalsIgnoreCase("true");
49     getLogger().fine("configuring editor with property " + propertyName + ", editorTemplate " + editorTemplate);
50
51     tabbedPane = new JTabbedPane();
52
53     // first, get the strings that we're going to edit.
54

55     getLogger().fine("creating prop from " + template + "=" + manager.getProperty(template, ""));
56
57     List JavaDoc<String JavaDoc> propsToEdit = manager.getPropertyAsList(template, "");
58
59     editors = createEditors(propsToEdit);
60
61     getLogger().fine("minimumSize for tabbedPane = " + tabbedPane.getMinimumSize());
62     getLogger().fine("preferredSize for tabbedPane = " + tabbedPane.getPreferredSize());
63     getLogger().fine("size for tabbedPane = " + tabbedPane.getSize());
64
65     SpringLayout layout = new SpringLayout();
66     this.setLayout(layout);
67     this.add(tabbedPane);
68     layout.putConstraint(SpringLayout.WEST, tabbedPane, 0, SpringLayout.WEST, this);
69     layout.putConstraint(SpringLayout.NORTH, tabbedPane, 0, SpringLayout.NORTH, this);
70     layout.putConstraint(SpringLayout.SOUTH, this, 0 ,SpringLayout.SOUTH, tabbedPane);
71     layout.putConstraint(SpringLayout.EAST, this, 0 ,SpringLayout.EAST, tabbedPane);
72
73     manager.registerPropertyEditor(property, this);
74   }
75
76   /**
77    * Creates the appropriate editors for the given properties.
78    */

79   public List JavaDoc createEditors(List JavaDoc<String JavaDoc> propsToEdit) {
80     List JavaDoc editorList = new ArrayList JavaDoc();
81     SwingPropertyEditor currentEditor;
82
83     for (int i = 0; i < propsToEdit.size(); i++) {
84       String JavaDoc subTemplateString = propsToEdit.get(i);
85       String JavaDoc property = createSubProperty(subTemplateString);
86       String JavaDoc currentTemplate = createSubTemplate(subTemplateString);
87       currentEditor = createEditorPane(property, currentTemplate);
88
89       getLogger().fine("adding " + currentEditor);
90       getLogger().fine("currentEditor.getMinimumSize() = " + currentEditor.getMinimumSize());
91
92       editorList.add(currentEditor);
93       tabbedPane.add(manager.getProperty(currentTemplate + ".label", currentTemplate), currentEditor);
94     }
95
96     return editorList;
97   }
98
99
100   /**
101    * Creates an editor pane for a group of values.
102    */

103   private SwingPropertyEditor createEditorPane(String JavaDoc subProperty, String JavaDoc subTemplate) {
104     return (SwingPropertyEditor) manager.getFactory().createEditor(subProperty, subTemplate, subProperty, manager);
105
106   }
107
108   /**
109    * Returns the helpId for this editor.
110    */

111   public String JavaDoc getHelpID() {
112     String JavaDoc subProperty = manager.getProperty(editorTemplate + ".helpController", "");
113     if (subProperty.length() == 0) {
114       java.awt.Component JavaDoc selectedComponent = tabbedPane.getSelectedComponent();
115       if (selectedComponent == null || ! (selectedComponent instanceof PropertyEditorUI)) {
116         return super.getHelpID();
117       } else {
118         return ((PropertyEditorUI) selectedComponent).getHelpID();
119       }
120     } else {
121       return super.getHelpID();
122     }
123   }
124
125 }
126
127
128
129
Popular Tags