1 package net.suberic.util.gui.propedit; 2 import javax.swing.*; 3 import java.util.*; 4 import java.awt.event.ActionListener ; 5 import java.awt.event.ActionEvent ; 6 import java.awt.CardLayout ; 7 8 16 public class VariableEditorPane extends CompositeSwingPropertyEditor { 17 18 HashMap<String , PropertyEditorUI> idToEditorMap = new HashMap<String , PropertyEditorUI>(); 19 String keyProperty; 20 String currentKeyValue = null; 21 22 31 public void configureEditor(String propertyName, String template, String propertyBaseName, PropertyEditorManager newManager) { 32 configureBasic(propertyName, template, propertyBaseName, newManager); 33 debug = manager.getProperty("editors.debug", "false").equalsIgnoreCase("true"); 34 35 getLogger().fine("VEP: editorTemplate=" + editorTemplate + ", getProperty template.keyProperty = '" + manager.getProperty(editorTemplate + ".keyProperty", "") + "'"); 36 keyProperty = createSubProperty(manager.getProperty(editorTemplate + ".keyProperty", "")); 37 getLogger().fine("VEP: keying off property " + keyProperty); 38 39 editors = new Vector(); 40 41 manager.addPropertyEditorListener(keyProperty, new PropertyEditorAdapter() { 42 public void propertyChanged(PropertyEditorUI ui, String prop, String newValue) { 43 showPanel(newValue); 44 } 45 }); 46 47 this.setLayout(new java.awt.CardLayout ()); 48 49 String currentValue = manager.getProperty(keyProperty, ""); 50 getLogger().fine("VEP: currentValue for " + keyProperty + " = " + currentValue); 51 if (currentValue == "") { 52 PropertyEditorUI keyEditor = manager.getPropertyEditor(keyProperty); 54 if (keyEditor != null) { 55 currentValue = keyEditor.getValue().getProperty(keyProperty, ""); 56 } 57 } 58 59 showPanel(currentValue); 60 61 manager.registerPropertyEditor(property, this); 62 } 63 64 67 public void showPanel(String selectedId) { 68 boolean enableMe = true; 69 if (selectedId == null || selectedId.equals("")) { 70 enableMe = false; 71 } 72 73 CardLayout layout = (CardLayout ) getLayout(); 74 75 PropertyEditorUI newSelected = idToEditorMap.get(selectedId); 76 if (newSelected == null) { 77 if (selectedId == null || selectedId.equals("")) { 79 JPanel jp = new JPanel(); 80 this.add(selectedId, jp); 81 } else { 82 SwingPropertyEditor spe = createEditorPane(selectedId); 83 84 idToEditorMap.put(selectedId, spe); 86 editors.add(spe); 87 88 if (enableMe && isEditorEnabled()) { 89 spe.removeDisableMask(this); 90 } else { 91 spe.addDisableMask(this); 92 } 93 this.add(selectedId, spe); 94 } 95 } 96 layout.show(this, selectedId); 97 currentKeyValue = selectedId; 98 } 99 100 103 public SwingPropertyEditor createEditorPane(String selectedId) { 104 105 String editValue = createSubTemplate("." + selectedId); 106 107 SwingPropertyEditor returnValue = (SwingPropertyEditor)manager.getFactory().createEditor(property, editValue, propertyBase, manager); 108 return returnValue; 109 } 110 111 112 115 public String getHelpID() { 116 String subProperty = manager.getProperty(editorTemplate + ".helpController", ""); 117 if (subProperty.length() == 0) { 118 if (currentKeyValue != null) { 119 PropertyEditorUI selectedEditor = idToEditorMap.get(currentKeyValue); 120 if (selectedEditor == null) { 121 return super.getHelpID(); 122 } else { 123 return selectedEditor.getHelpID(); 124 } 125 } else { 126 return super.getHelpID(); 127 } 128 } else { 129 return super.getHelpID(); 130 } 131 } 132 133 137 public void setValue() throws PropertyValueVetoException { 138 validateProperty(); 139 if (currentKeyValue != null) { 140 PropertyEditorUI selectedEditor = idToEditorMap.get(currentKeyValue); 141 selectedEditor.setValue(); 142 } 143 } 144 145 148 public void validateProperty() throws PropertyValueVetoException { 149 if (currentKeyValue != null) { 150 PropertyEditorUI selectedEditor = idToEditorMap.get(currentKeyValue); 151 selectedEditor.validateProperty(); 152 } 153 } 154 155 159 public java.util.Properties getValue() { 160 java.util.Properties currentRetValue = new java.util.Properties (); 161 if (currentKeyValue != null) { 162 PropertyEditorUI selectedEditor = idToEditorMap.get(currentKeyValue); 163 currentRetValue.putAll(selectedEditor.getValue()); 164 } 165 return currentRetValue; 166 } 167 168 } 169 170 171 172 | Popular Tags |