001: package com.nexes.wizard;
002:
003: import java.awt.*;
004: import javax.swing.*;
005:
006: /**
007: * A base descriptor class used to reference a Component panel for the Wizard, as
008: * well as provide general rules as to how the panel should behave.
009: */
010: public class WizardPanelDescriptor {
011:
012: private static final String DEFAULT_PANEL_IDENTIFIER = "defaultPanelIdentifier";
013:
014: /**
015: * Identifier returned by getNextPanelDescriptor() to indicate that this is the
016: * last panel and the text of the 'Next' button should change to 'Finish'.
017: */
018: public static final FinishIdentifier FINISH = new FinishIdentifier();
019:
020: private Wizard wizard;
021: private Component targetPanel;
022: private Object panelIdentifier;
023:
024: /**
025: * Default constructor. The id and the Component panel must be set separately.
026: */
027: public WizardPanelDescriptor() {
028: panelIdentifier = DEFAULT_PANEL_IDENTIFIER;
029: targetPanel = new JPanel();
030: }
031:
032: /**
033: * Constructor which accepts both the Object-based identifier and a reference to
034: * the Component class which makes up the panel.
035: * @param id Object-based identifier
036: * @param panel A class which extends java.awt.Component that will be inserted as a
037: * panel into the wizard dialog.
038: */
039: public WizardPanelDescriptor(Object id, Component panel) {
040: panelIdentifier = id;
041: targetPanel = panel;
042: }
043:
044: /**
045: * Returns to java.awt.Component that serves as the actual panel.
046: * @return A reference to the java.awt.Component that serves as the panel
047: */
048: public final Component getPanelComponent() {
049: return targetPanel;
050: }
051:
052: /**
053: * Sets the panel's component as a class that extends java.awt.Component
054: * @param panel java.awt.Component which serves as the wizard panel
055: */
056: public final void setPanelComponent(Component panel) {
057: targetPanel = panel;
058: }
059:
060: /**
061: * Returns the unique Object-based identifier for this panel descriptor.
062: * @return The Object-based identifier
063: */
064: public final Object getPanelDescriptorIdentifier() {
065: return panelIdentifier;
066: }
067:
068: /**
069: * Sets the Object-based identifier for this panel. The identifier must be unique
070: * from all the other identifiers in the panel.
071: * @param id Object-based identifier for this panel.
072: */
073: public final void setPanelDescriptorIdentifier(Object id) {
074: panelIdentifier = id;
075: }
076:
077: final void setWizard(Wizard w) {
078: wizard = w;
079: }
080:
081: /**
082: * Returns a reference to the Wizard component.
083: * @return The Wizard class hosting this descriptor.
084: */
085: public final Wizard getWizard() {
086: return wizard;
087: }
088:
089: /**
090: * Returns a reference to the current WizardModel for this Wizard component.
091: * @return The current WizardModel for this Wizard component.
092: */
093: public WizardModel getWizardModel() {
094: return wizard.getModel();
095: }
096:
097: // Override this method to provide an Object-based identifier
098: // for the next panel.
099:
100: /**
101: * Override this class to provide the Object-based identifier of the panel that the
102: * user should traverse to when the Next button is pressed. Note that this method
103: * is only called when the button is actually pressed, so that the panel can change
104: * the next panel's identifier dynamically at runtime if necessary. Return null if
105: * the button should be disabled. Return FinishIdentfier if the button text
106: * should change to 'Finish' and the dialog should end.
107: * @return Object-based identifier.
108: */
109: public Object getNextPanelDescriptor() {
110: return null;
111: }
112:
113: // Override this method to provide an Object-based identifier
114: // for the previous panel.
115:
116: /**
117: * Override this class to provide the Object-based identifier of the panel that the
118: * user should traverse to when the Back button is pressed. Note that this method
119: * is only called when the button is actually pressed, so that the panel can change
120: * the previous panel's identifier dynamically at runtime if necessary. Return null if
121: * the button should be disabled.
122: * @return Object-based identifier
123: */
124: public Object getBackPanelDescriptor() {
125: return null;
126: }
127:
128: // Override this method in the subclass if you wish it to be called
129: // just before the panel is displayed.
130:
131: /**
132: * Override this method to provide functionality that will be performed just before
133: * the panel is to be displayed.
134: */
135: public void aboutToDisplayPanel() {
136:
137: }
138:
139: // Override this method in the subclass if you wish to do something
140: // while the panel is displaying.
141:
142: /**
143: * Override this method to perform functionality when the panel itself is displayed.
144: */
145: public void displayingPanel() {
146:
147: }
148:
149: // Override this method in the subclass if you wish it to be called
150: // just before the panel is switched to another or finished.
151:
152: /**
153: * Override this method to perform functionality just before the panel is to be
154: * hidden.
155: */
156: public void aboutToHidePanel() {
157:
158: }
159:
160: static class FinishIdentifier {
161: public static final String ID = "FINISH";
162: }
163: }
|