1 package net.suberic.util.gui.propedit; 2 import java.awt.CardLayout ; 3 import java.lang.reflect.Constructor ; 4 import java.util.*; 5 import javax.swing.*; 6 7 10 public class WizardEditorPane extends CompositeSwingPropertyEditor { 11 12 Map<String , SwingPropertyEditor> layoutMap = new HashMap<String , SwingPropertyEditor>(); 13 CardLayout layout; 14 WizardPropertyEditor wizardContainer = null; 15 WizardController controller = null; 16 17 20 public void configureEditor(String propertyName, String template, String propertyBaseName, PropertyEditorManager newManager) { 21 configureBasic(propertyName, template, propertyBaseName, newManager); 22 23 editors = new ArrayList<SwingPropertyEditor>(); 24 25 layout = new CardLayout (); 26 this.setLayout(layout); 27 28 String controllerClassString = manager.getProperty(template + ".controllerClass", ""); 30 if (controllerClassString.length() > 0) { 31 try { 32 Class controllerClass = Class.forName(controllerClassString); 33 Constructor constructor = controllerClass.getConstructor(Class.forName("java.lang.String"), Class.forName("net.suberic.util.gui.propedit.WizardEditorPane")); 34 controller = (WizardController) constructor.newInstance(template, this); 35 } catch (Exception e) { 36 getLogger().log(java.util.logging.Level.SEVERE, "Error loading controller class " + controllerClassString, e); 37 controller = new WizardController(template, this); 38 } 39 } else { 40 controller = new WizardController(template, this); 41 } 42 controller.initialize(); 43 } 44 45 48 public void createEditors(List<String > stateList) { 49 for (String stateString: stateList) { 50 String subProperty = createSubProperty(manager.getProperty(editorTemplate + "._states." + stateString + ".editor", "")); 51 String subTemplate = createSubTemplate(manager.getProperty(editorTemplate + "._states." + stateString + ".editor", "")); 52 SwingPropertyEditor newEditor = (SwingPropertyEditor) manager.getFactory().createEditor(subProperty, subTemplate, subTemplate, manager); 53 layoutMap.put(stateString, newEditor); 54 this.add(stateString, newEditor); 55 editors.add(newEditor); 56 } 57 } 58 59 62 public void setValue(String state) throws PropertyValueVetoException { 63 SwingPropertyEditor editor = layoutMap.get(state); 64 editor.setValue(); 65 } 66 67 70 public void validateProperty(String state) throws PropertyValueVetoException { 71 SwingPropertyEditor editor = layoutMap.get(state); 72 editor.validateProperty(); 73 } 74 75 78 public void loadState(String state) { 79 layout.show(this, state); 80 loadContainerState(); 81 SwingUtilities.invokeLater(new Runnable () { 82 public void run() { 83 acceptDefaultFocus(); 84 } 85 }); 86 } 87 88 91 public void loadContainerState() { 92 if (getWizardContainer() != null) { 93 getWizardContainer().setBeginningState(inBeginningState()); 94 getWizardContainer().setEndState(inEndState()); 95 } 96 } 97 98 101 public WizardController getController() { 102 return controller; 103 } 104 105 106 109 public String getState() { 110 return controller.getState(); 111 } 112 113 116 public boolean inBeginningState() { 117 return controller.inBeginningState(); 118 } 119 120 123 public boolean inEndState() { 124 return controller.inEndState(); 125 } 126 127 130 public void back() { 131 controller.back(); 132 } 133 134 137 public void next() throws PropertyValueVetoException { 138 controller.next(); 139 } 140 141 144 public void setWizardContainer(WizardPropertyEditor wpe) { 145 wizardContainer = wpe; 146 } 147 148 151 public WizardPropertyEditor getWizardContainer() { 152 return wizardContainer; 153 } 154 155 158 public boolean acceptDefaultFocus() { 159 SwingPropertyEditor currentEditor = layoutMap.get(getState()); 160 return currentEditor.acceptDefaultFocus(); 161 } 162 163 } 164 | Popular Tags |