001: package net.suberic.util.gui.propedit;
002:
003: import javax.swing.*;
004: import java.util.Vector;
005: import java.util.List;
006: import java.util.ArrayList;
007:
008: /**
009: * This will make an editor for a list of properties. Each property, in
010: * turn, should have a list of properties wihch it itself edits. Each
011: * top-level property will be a tab, with its values shown on the panel.
012: *
013: * So an example of a property definition for this would be:
014: *
015: * TabbedList=tabOne:tabTwo:tabThree
016: * TabbedList.tabOne=prop1:prop2:prop3:prop4
017: * TabbedList.tabTwo=prop5:prop6
018: * TabbedList.tabThree=prop7:prop8:prop9
019: *
020: * Options:
021: * TabbedList.templateScoped - add subproperty to the template. for instance,
022: * if true, the example will edit using the template
023: * TabbedList.tabOne.prop1. if false, it will use the template prop1.
024: * TabbedList.propertyScoped - add the subproperty to the property instead
025: * of using it as its own property. if true, this example would edit,
026: * for instance, MyProp.prop1 (since it would actually edit MyProp,
027: * TabbedList.tabOne, which would in turn probably edit MyProp.prop1,
028: * TabbedList.tabOne.prop1).
029: *
030: */
031: public class TabbedEditorPane extends CompositeSwingPropertyEditor {
032:
033: JTabbedPane tabbedPane;
034: protected boolean templateScoped = false;
035: protected boolean propertyScoped = false;
036:
037: /**
038: * This configures this editor with the following values.
039: *
040: * @param propertyName The property to be edited.
041: * @param template The property that will define the layout of the
042: * editor.
043: * @param manager The PropertyEditorManager that will manage the
044: * changes.
045: * @param isEnabled Whether or not this editor is enabled by default.
046: */
047: public void configureEditor(String propertyName, String template,
048: PropertyEditorManager newManager, boolean isEnabled) {
049: property = propertyName;
050: manager = newManager;
051: editorTemplate = template;
052: originalValue = manager.getProperty(property, "");
053:
054: debug = manager.getProperty("editors.debug", "false")
055: .equalsIgnoreCase("true");
056:
057: if (debug) {
058: System.out.println("configuring editor with property "
059: + propertyName + ", editorTemplate "
060: + editorTemplate);
061: }
062:
063: enabled = isEnabled;
064:
065: templateScoped = manager.getProperty(
066: editorTemplate + ".templateScoped", "false")
067: .equalsIgnoreCase("true");
068: propertyScoped = manager.getProperty(
069: editorTemplate + ".propertyScoped", "false")
070: .equalsIgnoreCase("true");
071:
072: tabbedPane = new JTabbedPane();
073:
074: // first, get the strings that we're going to edit.
075:
076: if (debug) {
077: System.out.println("creating prop from " + template + "="
078: + manager.getProperty(template, ""));
079: }
080:
081: List propsToEdit = manager.getPropertyAsList(template, "");
082:
083: editors = createEditors(property, propsToEdit);
084:
085: labelComponent = tabbedPane;
086:
087: if (debug) {
088: System.out.println("minimumSize for tabbedPane = "
089: + tabbedPane.getMinimumSize());
090: System.out.println("preferredSize for tabbedPane = "
091: + tabbedPane.getPreferredSize());
092: System.out.println("size for tabbedPane = "
093: + tabbedPane.getSize());
094: }
095:
096: this .add(tabbedPane);
097:
098: manager.registerPropertyEditor(property, this );
099: }
100:
101: /**
102: * Creates the appropriate editors for the given properties.
103: */
104: public List createEditors(String property, List propsToEdit) {
105:
106: List editorList = new ArrayList();
107: SwingPropertyEditor currentEditor;
108:
109: for (int i = 0; i < propsToEdit.size(); i++) {
110: String currentTemplate = (String) propsToEdit.get(i);
111: if (templateScoped)
112: currentTemplate = editorTemplate + "."
113: + currentTemplate;
114:
115: if (debug) {
116: System.out.println("getting editor using template "
117: + currentTemplate);
118: }
119:
120: if (propertyScoped) {
121: if (debug) {
122: System.out
123: .println("TEP: scoped. getting editor for "
124: + property + ", " + currentTemplate);
125: }
126: currentEditor = createEditorPane(property,
127: currentTemplate);
128: } else {
129: if (debug) {
130: System.out
131: .println("TEP: notPropScoped; getting editor for "
132: + currentTemplate
133: + ", "
134: + currentTemplate);
135: }
136: currentEditor = createEditorPane(currentTemplate,
137: currentTemplate);
138: }
139:
140: if (debug) {
141: System.out.println("adding " + currentEditor);
142: System.out.println("currentEditor.getMinimumSize() = "
143: + currentEditor.getMinimumSize());
144: }
145: editorList.add(currentEditor);
146: tabbedPane.add(manager.getProperty(currentTemplate
147: + ".label", currentTemplate), currentEditor);
148: }
149:
150: return editorList;
151: }
152:
153: /**
154: * Creates an editor pane for a group of values.
155: */
156: private SwingPropertyEditor createEditorPane(String subProperty,
157: String subTemplate) {
158: return (SwingPropertyEditor) manager.getFactory().createEditor(
159: subProperty, subTemplate, "Composite", manager, true);
160:
161: }
162:
163: }
|