KickJava   Java API By Example, From Geeks To Geeks.

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


1 package net.suberic.util.gui.propedit;
2 import java.util.*;
3
4 /**
5  * This class handles things like
6  */

7 public class WizardController {
8   String JavaDoc template;
9   protected String JavaDoc mState;
10   protected List<String JavaDoc> mStateList = null;
11   WizardEditorPane editorPane;
12   PropertyEditorManager manager;
13
14   /**
15    * Creates a new WizardController using the given resource and
16    * WizardEditorPane.
17    */

18   public WizardController(String JavaDoc 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   /**
31    * Initializes the Controller and PropertyEditor.
32    */

33   void initialize() {
34     editorPane.createEditors(mStateList);
35     editorPane.loadState(mState);
36   }
37
38   /**
39    * Returns the current Wizard state.
40    */

41   public String JavaDoc getState() {
42     return mState;
43   }
44
45   /**
46    * Returns if this is the beginning state.
47    */

48   public boolean inBeginningState() {
49     if (mState == mStateList.get(0))
50       return true;
51     else
52       return false;
53   }
54
55   /**
56    * Returns if this is in a valid end state.
57    */

58   public boolean inEndState() {
59     if (mState == mStateList.get(mStateList.size() - 1))
60       return true;
61     else
62       return false;
63   }
64
65   /**
66    * Goes back a state.
67    */

68   public void back() {
69     if (inBeginningState())
70       return;
71     else {
72       String JavaDoc newState = getBackState(mState);
73       if (newState != null) {
74         //checkStateTransition(mState, newState);
75
mState = newState;
76         editorPane.loadState(newState);
77       }
78     }
79
80   }
81
82   /**
83    * Goes forward a state.
84    */

85   public void next() throws PropertyValueVetoException {
86     if (inEndState()) {
87       finishWizard();
88     } else {
89       String JavaDoc newState = getNextState(mState);
90       if (newState != null) {
91         checkStateTransition(mState, newState);
92         mState = newState;
93         editorPane.loadState(newState);
94       }
95     }
96   }
97
98   /**
99    * Checks the state transition to make sure that we can move from
100    * state to state.
101    */

102   public void checkStateTransition(String JavaDoc oldState, String JavaDoc newState) throws PropertyValueVetoException {
103     //editorPane.setValue(oldState);
104
}
105
106   /**
107    * Gets the next state.
108    */

109   public String JavaDoc getNextState(String JavaDoc currentState) {
110     int current = mStateList.indexOf(mState);
111     if (current > -1 && current < (mStateList.size() -1)) {
112       String JavaDoc newState = mStateList.get(current + 1);
113       return newState;
114     } else {
115       return null;
116     }
117   }
118   /**
119    * Gets the state that should be displayed next from a back request.
120    */

121   public String JavaDoc getBackState(String JavaDoc currentState) {
122     int current = mStateList.indexOf(currentState);
123     if (current >= 1) {
124       String JavaDoc newState = mStateList.get(current - 1);
125       return newState;
126     } else {
127       return null;
128     }
129   }
130
131   /**
132    * Finsihes the wizard.
133    */

134   public void finishWizard() throws PropertyValueVetoException {
135     //getManager().commit();
136
getEditorPane().getWizardContainer().closeWizard();
137   }
138
139   /**
140    * Returns the PropertyEditorManager.
141    */

142   public PropertyEditorManager getManager() {
143     return manager;
144   }
145
146   /**
147    * Returns the WizardEditorPane.
148    */

149   public WizardEditorPane getEditorPane() {
150     return editorPane;
151   }
152 }
153
154
Popular Tags