1 package net.suberic.util.gui.propedit; 2 import java.util.*; 3 4 7 public class WizardController { 8 String template; 9 protected String mState; 10 protected List<String > mStateList = null; 11 WizardEditorPane editorPane; 12 PropertyEditorManager manager; 13 14 18 public WizardController(String sourceTemplate, WizardEditorPane wep) { 19 template = sourceTemplate; 20 editorPane = wep; 21 manager = wep.getManager(); 22 23 mStateList = manager.getPropertyAsList(template + "._states", ""); 24 if (mStateList.size() > 0) { 25 mState = mStateList.get(0); 26 } 27 28 } 29 30 33 void initialize() { 34 editorPane.createEditors(mStateList); 35 editorPane.loadState(mState); 36 } 37 38 41 public String getState() { 42 return mState; 43 } 44 45 48 public boolean inBeginningState() { 49 if (mState == mStateList.get(0)) 50 return true; 51 else 52 return false; 53 } 54 55 58 public boolean inEndState() { 59 if (mState == mStateList.get(mStateList.size() - 1)) 60 return true; 61 else 62 return false; 63 } 64 65 68 public void back() { 69 if (inBeginningState()) 70 return; 71 else { 72 String newState = getBackState(mState); 73 if (newState != null) { 74 mState = newState; 76 editorPane.loadState(newState); 77 } 78 } 79 80 } 81 82 85 public void next() throws PropertyValueVetoException { 86 if (inEndState()) { 87 finishWizard(); 88 } else { 89 String newState = getNextState(mState); 90 if (newState != null) { 91 checkStateTransition(mState, newState); 92 mState = newState; 93 editorPane.loadState(newState); 94 } 95 } 96 } 97 98 102 public void checkStateTransition(String oldState, String newState) throws PropertyValueVetoException { 103 } 105 106 109 public String getNextState(String currentState) { 110 int current = mStateList.indexOf(mState); 111 if (current > -1 && current < (mStateList.size() -1)) { 112 String newState = mStateList.get(current + 1); 113 return newState; 114 } else { 115 return null; 116 } 117 } 118 121 public String getBackState(String currentState) { 122 int current = mStateList.indexOf(currentState); 123 if (current >= 1) { 124 String newState = mStateList.get(current - 1); 125 return newState; 126 } else { 127 return null; 128 } 129 } 130 131 134 public void finishWizard() throws PropertyValueVetoException { 135 getEditorPane().getWizardContainer().closeWizard(); 137 } 138 139 142 public PropertyEditorManager getManager() { 143 return manager; 144 } 145 146 149 public WizardEditorPane getEditorPane() { 150 return editorPane; 151 } 152 } 153 154 | Popular Tags |