File Source: WizardDialog.java
/*
P/P * Method: com.dmdirc.addons.ui_swing.wizard.WizardDialog__static_init
*/
1 /*
2 * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 */
22
23 package com.dmdirc.addons.ui_swing.wizard;
24
25 import com.dmdirc.addons.ui_swing.components.StandardDialog;
26
27 import com.dmdirc.ui.CoreUIUtils;
28 import java.awt.Window;
29 import java.awt.event.ActionEvent;
30 import java.awt.event.ActionListener;
31 import java.awt.event.WindowAdapter;
32 import java.awt.event.WindowEvent;
33 import java.util.List;
34
35 import javax.swing.JButton;
36
37 /**
38 * Basic wizard container.
39 */
/*
P/P * Method: WizardPanel access$000(WizardDialog)
*
* Preconditions:
* x0 != null
*
* Postconditions:
* return_value == x0.wizard
* init'ed(return_value)
*/
40 public final class WizardDialog extends StandardDialog implements ActionListener {
41
42 /**
43 * A version number for this class. It should be changed whenever the class
44 * structure is changed (or anything else that would prevent serialized
45 * objects being unserialized with the new class).
46 */
47 private static final long serialVersionUID = 2;
48 /** Wizard. */
49 private final WizardPanel wizard;
50 /** Parent container. */
51 private Window parentWindow;
52
53 /**
54 * Creates a new instance of WizardFrame that requires a mainframe.
55 *
56 * @param title Title for the wizard
57 * @param steps Steps for the wizard
58 * @param wizard Wizard to inform of changes
59 * @param parentWindow Parent component
60 */
61 public WizardDialog(final String title, final List<Step> steps,
62 final WizardListener wizard, final Window parentWindow) {
/*
P/P * Method: void com.dmdirc.addons.ui_swing.wizard.WizardDialog(String, List, WizardListener, Window)
*
* Preconditions:
* steps != null
*
* Presumptions:
* init'ed(java.awt.Dialog$ModalityType.MODELESS)
*
* Postconditions:
* this.parentWindow == parentWindow
* init'ed(this.parentWindow)
* this.wizard == &new WizardPanel(WizardDialog#3)
* new ArrayList(StepLayout#1) num objects == 1
* new JButton(initComponents#5) num objects == 1
* new JButton(initComponents#6) num objects == 1
* new JLabel(initComponents#4) num objects == 1
* new JPanel(initComponents#3) num objects == 1
* new ListenerList(WizardPanel#1) num objects == 1
* new StepLayout(WizardPanel#2) num objects == 1
* ...
*/
63 super(parentWindow, ModalityType.MODELESS);
64
65 setTitle(title);
66 setDefaultCloseOperation(DISPOSE_ON_CLOSE);
67 orderButtons(new JButton(), new JButton());
68 this.wizard = new WizardPanel(title, steps, wizard);
69 this.parentWindow = parentWindow;
70 layoutComponents();
71 }
72
73 /** Lays out the components. */
74 private void layoutComponents() {
/*
P/P * Method: void layoutComponents()
*/
75 setContentPane(wizard);
76 }
77
78 /** Displays the wizard. */
79 @Override
80 public void display() {
/*
P/P * Method: void display()
*
* Preconditions:
* init'ed(this.parentWindow)
* this.wizard != null
* this.wizard.steps != null
* this.wizard.steps.steps != null
* (soft) this.wizard.next != null
* (soft) this.wizard.prev != null
* (soft) this.wizard.progressLabel != null
* (soft) this.wizard.stepsPanel != null
* (soft) this.wizard.titleLabel != null
*
* Postconditions:
* this.wizard.currentStep == One-of{old this.wizard.currentStep, 0}
* possibly_updated(this.wizard.steps.currentStep)
*
* Test Vectors:
* this.parentWindow: Addr_Set{null}, Inverse{null}
*/
81 wizard.display();
82 if (parentWindow != null) {
83 setLocationRelativeTo(parentWindow);
84 } else {
85 CoreUIUtils.centreWindow(this);
86 }
/*
P/P * Method: void com.dmdirc.addons.ui_swing.wizard.WizardDialog$1(WizardDialog)
*/
87 addWindowListener(new WindowAdapter() {
88
89 /** {@inheritDoc} */
90 @Override
91 public void windowClosed(final WindowEvent e) {
/*
P/P * Method: void windowClosed(WindowEvent)
*
* Preconditions:
* this.wizard != null
* this.wizard.stepListeners != null
*/
92 removeWindowListener(this);
93 wizard.fireWizardCancelled();
94 }
95 });
96 setResizable(false);
97 setVisible(true);
98 }
99
100 /** {@inheritDoc} */
101 @Override
102 public void validate() {
/*
P/P * Method: void validate()
*
* Preconditions:
* init'ed(this.parentWindow)
*/
103 super.validate();
104
105 setLocationRelativeTo(parentWindow);
106 }
107
108 /**
109 * {@inheritDoc}
110 *
111 * @param e Action event
112 */
113 @Override
114 public void actionPerformed(final ActionEvent e) {
/*
P/P * Method: void actionPerformed(ActionEvent)
*
* Preconditions:
* e != null
* (soft) this.wizard != null
* (soft) this.wizard.stepListeners != null
*
* Postconditions:
* this.wizard.currentStep == old this.wizard.currentStep
* this.wizard.steps.currentStep == old this.wizard.steps.currentStep
*/
115 if (e.getSource() == getOkButton()) {
116 wizard.nextStep();
117 } else if (e.getSource() == getCancelButton()) {
118 wizard.fireWizardCancelled();
119 }
120 }
121
122 /**
123 * Adds a step to the wizard.
124 *
125 * @param step Step to add
126 */
127 public void addStep(final Step step) {
/*
P/P * Method: void addStep(Step)
*
* Preconditions:
* step != null
* this.wizard != null
* this.wizard.stepsPanel != null
*/
128 wizard.addStep(step);
129 }
130
131 /**
132 * Returns the step at the specified index.
133 *
134 * @param stepNumber step number
135 *
136 * @return Specified step.
137 */
138 public Step getStep(final int stepNumber) {
/*
P/P * Method: Step getStep(int)
*
* Preconditions:
* this.wizard != null
* this.wizard.steps != null
* this.wizard.steps.steps != null
*
* Postconditions:
* init'ed(return_value)
*/
139 return wizard.getStep(stepNumber);
140 }
141
142 /**
143 * Returns the current step.
144 *
145 * @return Current step number
146 */
147 public int getCurrentStep() {
/*
P/P * Method: int getCurrentStep()
*
* Preconditions:
* this.wizard != null
* init'ed(this.wizard.currentStep)
*
* Postconditions:
* return_value == this.wizard.currentStep
* init'ed(return_value)
*/
148 return wizard.getCurrentStep();
149 }
150
151 /**
152 * Enables or disables the "next step" button.
153 *
154 * @param newValue boolean true to make "next" button enabled, else false
155 */
156 public void enableNextStep(final boolean newValue) {
/*
P/P * Method: void enableNextStep(bool)
*
* Preconditions:
* this.wizard != null
* this.wizard.next != null
*/
157 wizard.enableNextStep(newValue);
158 }
159
160 /**
161 * Enables or disables the "previous step" button.
162 *
163 * @param newValue boolean true to make "previous" button enabled, else false
164 */
165 public void enablePreviousStep(final boolean newValue) {
/*
P/P * Method: void enablePreviousStep(bool)
*
* Preconditions:
* this.wizard != null
* this.wizard.prev != null
*/
166 wizard.enablePreviousStep(newValue);
167 }
168
169 /**
170 * Adds a step listener to the list.
171 *
172 * @param listener
173 */
174 public void addStepListener(final StepListener listener) {
/*
P/P * Method: void addStepListener(StepListener)
*
* Preconditions:
* this.wizard != null
* this.wizard.stepListeners != null
*/
175 wizard.addStepListener(listener);
176 }
177
178 /**
179 * Removes a step listener from the list.
180 *
181 * @param listener
182 */
183 public void removeStepListener(final StepListener listener) {
/*
P/P * Method: void removeStepListener(StepListener)
*
* Preconditions:
* this.wizard != null
* this.wizard.stepListeners != null
*/
184 wizard.removeStepListener(listener);
185 }
186
187 /**
188 * Adds a wizard listener to the list.
189 *
190 * @param listener
191 */
192 public void addWizardListener(final WizardListener listener) {
/*
P/P * Method: void addWizardListener(WizardListener)
*
* Preconditions:
* this.wizard != null
* this.wizard.stepListeners != null
*/
193 wizard.addWizardListener(listener);
194 }
195
196 /**
197 * Removes a wizard listener from the list.
198 *
199 * @param listener
200 */
201 public void removeWizardListener(final WizardListener listener) {
/*
P/P * Method: void removeWizardListener(WizardListener)
*
* Preconditions:
* this.wizard != null
* this.wizard.stepListeners != null
*/
202 wizard.removeWizardListener(listener);
203 }
204 }
SofCheck Inspector Build Version : 2.17854
| WizardDialog.java |
2009-Jun-25 01:54:24 |
| WizardDialog.class |
2009-Sep-02 17:04:16 |
| WizardDialog$1.class |
2009-Sep-02 17:04:16 |