001: package com.nexes.wizard;
002:
003: import java.beans.*;
004: import java.awt.*;
005: import java.awt.event.*;
006: import java.util.*;
007:
008: import javax.swing.*;
009: import javax.swing.border.*;
010:
011: /**
012: * The model for the Wizard component, which tracks the text, icons, and enabled state
013: * of each of the buttons, as well as the current panel that is displayed. Note that
014: * the model, in its current form, is not intended to be subclassed.
015: */
016:
017: public class WizardModel {
018:
019: /**
020: * Identification string for the current panel.
021: */
022: public static final String CURRENT_PANEL_DESCRIPTOR_PROPERTY = "currentPanelDescriptorProperty";
023:
024: /**
025: * Property identification String for the Back button's text
026: */
027: public static final String BACK_BUTTON_TEXT_PROPERTY = "backButtonTextProperty";
028: /**
029: * Property identification String for the Back button's icon
030: */
031: public static final String BACK_BUTTON_ICON_PROPERTY = "backButtonIconProperty";
032: /**
033: * Property identification String for the Back button's enabled state
034: */
035: public static final String BACK_BUTTON_ENABLED_PROPERTY = "backButtonEnabledProperty";
036:
037: /**
038: * Property identification String for the Next button's text
039: */
040: public static final String NEXT_FINISH_BUTTON_TEXT_PROPERTY = "nextButtonTextProperty";
041: /**
042: * Property identification String for the Next button's icon
043: */
044: public static final String NEXT_FINISH_BUTTON_ICON_PROPERTY = "nextButtonIconProperty";
045: /**
046: * Property identification String for the Next button's enabled state
047: */
048: public static final String NEXT_FINISH_BUTTON_ENABLED_PROPERTY = "nextButtonEnabledProperty";
049:
050: /**
051: * Property identification String for the Cancel button's text
052: */
053: public static final String CANCEL_BUTTON_TEXT_PROPERTY = "cancelButtonTextProperty";
054: /**
055: * Property identification String for the Cancel button's icon
056: */
057: public static final String CANCEL_BUTTON_ICON_PROPERTY = "cancelButtonIconProperty";
058: /**
059: * Property identification String for the Cancel button's enabled state
060: */
061: public static final String CANCEL_BUTTON_ENABLED_PROPERTY = "cancelButtonEnabledProperty";
062:
063: private WizardPanelDescriptor currentPanel;
064:
065: private HashMap panelHashmap;
066:
067: private HashMap buttonTextHashmap;
068: private HashMap buttonIconHashmap;
069: private HashMap buttonEnabledHashmap;
070:
071: private PropertyChangeSupport propertyChangeSupport;
072:
073: /**
074: * Default constructor.
075: */
076: public WizardModel() {
077:
078: panelHashmap = new HashMap();
079:
080: buttonTextHashmap = new HashMap();
081: buttonIconHashmap = new HashMap();
082: buttonEnabledHashmap = new HashMap();
083:
084: propertyChangeSupport = new PropertyChangeSupport(this );
085:
086: }
087:
088: /**
089: * Returns the currently displayed WizardPanelDescriptor.
090: * @return The currently displayed WizardPanelDescriptor
091: */
092: WizardPanelDescriptor getCurrentPanelDescriptor() {
093: return currentPanel;
094: }
095:
096: /**
097: * Registers the WizardPanelDescriptor in the model using the Object-identifier specified.
098: * @param id Object-based identifier
099: * @param descriptor WizardPanelDescriptor that describes the panel
100: */
101: void registerPanel(Object id, WizardPanelDescriptor descriptor) {
102:
103: // Place a reference to it in a hashtable so we can access it later
104: // when it is about to be displayed.
105:
106: panelHashmap.put(id, descriptor);
107:
108: }
109:
110: /**
111: * Sets the current panel to that identified by the Object passed in.
112: * @param id Object-based panel identifier
113: * @return boolean indicating success or failure
114: */
115: boolean setCurrentPanel(Object id) {
116:
117: // First, get the hashtable reference to the panel that should
118: // be displayed.
119:
120: WizardPanelDescriptor nextPanel = (WizardPanelDescriptor) panelHashmap
121: .get(id);
122:
123: // If we couldn't find the panel that should be displayed, return
124: // false.
125:
126: if (nextPanel == null)
127: throw new WizardPanelNotFoundException();
128:
129: WizardPanelDescriptor oldPanel = currentPanel;
130: currentPanel = nextPanel;
131:
132: if (oldPanel != currentPanel)
133: firePropertyChange(CURRENT_PANEL_DESCRIPTOR_PROPERTY,
134: oldPanel, currentPanel);
135:
136: return true;
137:
138: }
139:
140: Object getBackButtonText() {
141: return buttonTextHashmap.get(BACK_BUTTON_TEXT_PROPERTY);
142: }
143:
144: void setBackButtonText(Object newText) {
145:
146: Object oldText = getBackButtonText();
147: if (!newText.equals(oldText)) {
148: buttonTextHashmap.put(BACK_BUTTON_TEXT_PROPERTY, newText);
149: firePropertyChange(BACK_BUTTON_TEXT_PROPERTY, oldText,
150: newText);
151: }
152: }
153:
154: Object getNextFinishButtonText() {
155: return buttonTextHashmap.get(NEXT_FINISH_BUTTON_TEXT_PROPERTY);
156: }
157:
158: void setNextFinishButtonText(Object newText) {
159:
160: Object oldText = getNextFinishButtonText();
161: if (!newText.equals(oldText)) {
162: buttonTextHashmap.put(NEXT_FINISH_BUTTON_TEXT_PROPERTY,
163: newText);
164: firePropertyChange(NEXT_FINISH_BUTTON_TEXT_PROPERTY,
165: oldText, newText);
166: }
167: }
168:
169: Object getCancelButtonText() {
170: return buttonTextHashmap.get(CANCEL_BUTTON_TEXT_PROPERTY);
171: }
172:
173: void setCancelButtonText(Object newText) {
174:
175: Object oldText = getCancelButtonText();
176: if (!newText.equals(oldText)) {
177: buttonTextHashmap.put(CANCEL_BUTTON_TEXT_PROPERTY, newText);
178: firePropertyChange(CANCEL_BUTTON_TEXT_PROPERTY, oldText,
179: newText);
180: }
181: }
182:
183: Icon getBackButtonIcon() {
184: return (Icon) buttonIconHashmap.get(BACK_BUTTON_ICON_PROPERTY);
185: }
186:
187: void setBackButtonIcon(Icon newIcon) {
188:
189: Object oldIcon = getBackButtonIcon();
190: if (!newIcon.equals(oldIcon)) {
191: buttonIconHashmap.put(BACK_BUTTON_ICON_PROPERTY, newIcon);
192: firePropertyChange(BACK_BUTTON_ICON_PROPERTY, oldIcon,
193: newIcon);
194: }
195: }
196:
197: Icon getNextFinishButtonIcon() {
198: return (Icon) buttonIconHashmap
199: .get(NEXT_FINISH_BUTTON_ICON_PROPERTY);
200: }
201:
202: public void setNextFinishButtonIcon(Icon newIcon) {
203:
204: Object oldIcon = getNextFinishButtonIcon();
205: if (!newIcon.equals(oldIcon)) {
206: buttonIconHashmap.put(NEXT_FINISH_BUTTON_ICON_PROPERTY,
207: newIcon);
208: firePropertyChange(NEXT_FINISH_BUTTON_ICON_PROPERTY,
209: oldIcon, newIcon);
210: }
211: }
212:
213: Icon getCancelButtonIcon() {
214: return (Icon) buttonIconHashmap
215: .get(CANCEL_BUTTON_ICON_PROPERTY);
216: }
217:
218: void setCancelButtonIcon(Icon newIcon) {
219:
220: Icon oldIcon = getCancelButtonIcon();
221: if (!newIcon.equals(oldIcon)) {
222: buttonIconHashmap.put(CANCEL_BUTTON_ICON_PROPERTY, newIcon);
223: firePropertyChange(CANCEL_BUTTON_ICON_PROPERTY, oldIcon,
224: newIcon);
225: }
226: }
227:
228: Boolean getBackButtonEnabled() {
229: return (Boolean) buttonEnabledHashmap
230: .get(BACK_BUTTON_ENABLED_PROPERTY);
231: }
232:
233: void setBackButtonEnabled(Boolean newValue) {
234:
235: Boolean oldValue = getBackButtonEnabled();
236: if (newValue != oldValue) {
237: buttonEnabledHashmap.put(BACK_BUTTON_ENABLED_PROPERTY,
238: newValue);
239: firePropertyChange(BACK_BUTTON_ENABLED_PROPERTY, oldValue,
240: newValue);
241: }
242: }
243:
244: Boolean getNextFinishButtonEnabled() {
245: return (Boolean) buttonEnabledHashmap
246: .get(NEXT_FINISH_BUTTON_ENABLED_PROPERTY);
247: }
248:
249: void setNextFinishButtonEnabled(Boolean newValue) {
250:
251: Boolean oldValue = getNextFinishButtonEnabled();
252: if (newValue != oldValue) {
253: buttonEnabledHashmap.put(
254: NEXT_FINISH_BUTTON_ENABLED_PROPERTY, newValue);
255: firePropertyChange(NEXT_FINISH_BUTTON_ENABLED_PROPERTY,
256: oldValue, newValue);
257: }
258: }
259:
260: Boolean getCancelButtonEnabled() {
261: return (Boolean) buttonEnabledHashmap
262: .get(CANCEL_BUTTON_ENABLED_PROPERTY);
263: }
264:
265: void setCancelButtonEnabled(Boolean newValue) {
266:
267: Boolean oldValue = getCancelButtonEnabled();
268: if (newValue != oldValue) {
269: buttonEnabledHashmap.put(CANCEL_BUTTON_ENABLED_PROPERTY,
270: newValue);
271: firePropertyChange(CANCEL_BUTTON_ENABLED_PROPERTY,
272: oldValue, newValue);
273: }
274: }
275:
276: public void addPropertyChangeListener(PropertyChangeListener p) {
277: propertyChangeSupport.addPropertyChangeListener(p);
278: }
279:
280: public void removePropertyChangeListener(PropertyChangeListener p) {
281: propertyChangeSupport.removePropertyChangeListener(p);
282: }
283:
284: protected void firePropertyChange(String propertyName,
285: Object oldValue, Object newValue) {
286: propertyChangeSupport.firePropertyChange(propertyName,
287: oldValue, newValue);
288: }
289:
290: }
|