File Source: InstallerDialog.java
/*
P/P * Method: com.dmdirc.installer.ui.InstallerDialog__static_init
*/
1 /*
2 *
3 * Copyright (c) 2006-2008 Chris Smith, Shane Mc Cormack, Gregory Holmes
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 * SOFTWARE.
22 */
23
24 package com.dmdirc.installer.ui;
25
26 import com.dmdirc.installer.Step;
27 import com.dmdirc.installer.StepListener;
28 import com.dmdirc.installer.WizardListener;
29 import com.dmdirc.ui.CoreUIUtils;
30 import com.dmdirc.util.ListenerList;
31
32 import java.awt.BorderLayout;
33 import java.awt.Dimension;
34 import java.awt.Toolkit;
35 import java.awt.event.ActionEvent;
36 import java.awt.event.ActionListener;
37 import java.awt.event.WindowAdapter;
38 import java.awt.event.WindowEvent;
39 import java.util.ArrayList;
40 import java.util.List;
41
42 import javax.swing.BorderFactory;
43 import javax.swing.JFrame;
44 import javax.swing.JOptionPane;
45 import javax.swing.UIManager;
46 import javax.swing.UnsupportedLookAndFeelException;
47
48 /**
49 *
50 */
51 public class InstallerDialog extends JFrame implements ActionListener {
52
53 private static final long serialVersionUID = -2001827768443747849L;
54 private final TitlePanel title;
55 private final WizardPanel wizard;
56 private final WizardControlPanel control;
57 private final ListenerList listeners;
58 /** Small UI Gap. */
59 public static final int SMALL_GAP = 5;
60
61 /**
62 * Instantiates a new installer dialog
63 *
64 * @param dialogTitle
65 */
66 public InstallerDialog(final String dialogTitle) {
/*
P/P * Method: void com.dmdirc.installer.ui.InstallerDialog(String)
*
* Presumptions:
* java.awt.Toolkit:getDefaultToolkit(...)@90 != null
* java.lang.Thread:currentThread(...)@90 != null
* java.lang.Thread:getContextClassLoader(...)@90 != null
*
* Postconditions:
* this.control == &new WizardControlPanel(InstallerDialog#3)
* this.listeners == &new ListenerList(InstallerDialog#4)
* this.title == &new TitlePanel(InstallerDialog#1)
* this.wizard == &new WizardPanel(InstallerDialog#2)
* new ArrayList(StepLayout#1) num objects == 1
* new JButton(WizardControlPanel#1) num objects == 1
* new JButton(WizardControlPanel#2) num objects == 1
* new JLabel(TitlePanel#2) num objects == 1
* new JLabel(TitlePanel#3) num objects == 1
* new JLabel(WizardControlPanel#3) num objects == 1
* ...
*/
67 super(dialogTitle);
68 title = new TitlePanel(null);
69 wizard = new WizardPanel(this);
70 control = new WizardControlPanel();
71 listeners = new ListenerList();
72
73 setLayout(new BorderLayout(SMALL_GAP, SMALL_GAP));
74
75
76 title.setBorder(BorderFactory.createCompoundBorder(
77 BorderFactory.createEmptyBorder(SMALL_GAP, SMALL_GAP,SMALL_GAP,
78 SMALL_GAP), title.getBorder()));
79 wizard.setBorder(BorderFactory.createCompoundBorder(
80 BorderFactory.createEmptyBorder(SMALL_GAP, SMALL_GAP,SMALL_GAP,
81 SMALL_GAP), wizard.getBorder()));
82 control.setBorder(BorderFactory.createCompoundBorder(
83 BorderFactory.createEmptyBorder(SMALL_GAP, SMALL_GAP,SMALL_GAP,
84 SMALL_GAP), control.getBorder()));
85
86 add(title, BorderLayout.NORTH);
87 add(wizard, BorderLayout.CENTER);
88 add(control, BorderLayout.SOUTH);
89
90 setIconImage(Toolkit.getDefaultToolkit().createImage(Thread.
91 currentThread().getContextClassLoader().getResource(
92 "com/dmdirc/res/icon.png")));
93 setPreferredSize(new Dimension(400, 350));
94 setMaximumSize(new Dimension(400, 350));
95
96 control.getPrevButton().addActionListener(this);
97 control.getNextButton().addActionListener(this);
98 }
99
100 /**
101 * Adds a step.
102 *
103 * @param step Step to add
104 */
105 public void addStep(final SwingStep step) {
/*
P/P * Method: void addStep(SwingStep)
*
* Preconditions:
* step != null
* this.wizard != null
*/
106 wizard.addStep(step);
107 }
108
109 /**
110 * Displays the installer.
111 */
112 public void display() {
/*
P/P * Method: void display()
*
* Preconditions:
* init'ed(this.control.step)
* init'ed(this.wizard.layout.currentStep)
* this.control != null
* this.control.progress != null
* this.listeners != null
* this.title != null
* this.title.image != null
* this.title.title != null
* this.wizard != null
* this.wizard.layout != null
* ...
*
* Postconditions:
* this.control.step >= -231+1
* init'ed(this.control.total)
* this.wizard.layout.currentStep <= 232-2
*/
113 wizard.display();
114 title.setStep(wizard.getCurrentStep());
115 control.setTotal(wizard.getTotalSteps());
116 control.setProgress(wizard.getCurrentStepIndex());
/*
P/P * Method: void com.dmdirc.installer.ui.InstallerDialog$1(InstallerDialog)
*/
117 addWindowListener(new WindowAdapter() {
118
119 /** {@inheritDoc} */
120 @Override
121 public void windowClosing(final WindowEvent e) {
/*
P/P * Method: void windowClosing(WindowEvent)
*
* Preconditions:
* this.listeners != null
*/
122 fireWizardCancelled();
123 }
124 });
125
126 pack();
127 setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
128 CoreUIUtils.centreWindow(this);
129 setVisible(true);
130 fireStepAboutToBeDisplayed(wizard.getStep(wizard.getCurrentStepIndex()));
131 }
132
133 /**
134 * Displays the installer with these steps added.
135 *
136 * @param steps Steps to add
137 */
138 public void display(final List<Step> steps) {
/*
P/P * Method: void display(List)
*
* Preconditions:
* init'ed(this.control.step)
* init'ed(this.wizard.layout.currentStep)
* steps != null
* this.control != null
* this.control.progress != null
* this.listeners != null
* this.title != null
* this.title.image != null
* this.title.title != null
* this.wizard != null
* ...
*
* Postconditions:
* this.control.step >= -231+1
* init'ed(this.control.total)
* this.wizard.layout.currentStep <= 232-2
*
* Test Vectors:
* java.util.Iterator:hasNext(...)@140: {0}, {1}
*/
139 final List<SwingStep> swingSteps = new ArrayList<SwingStep>();
140 for (Step step : steps) {
141 if (step instanceof SwingStep) {
142 swingSteps.add((SwingStep) step);
143 }
144 }
145 display();
146 }
147
148 /**
149 * Enables the next step.
150 *
151 * @param enable true to enable false to disable
152 */
153 public void enableNextStep(final boolean enable) {
/*
P/P * Method: void enableNextStep(bool)
*
* Preconditions:
* this.control != null
* this.control.next != null
*/
154 control.getNextButton().setEnabled(enable);
155 }
156
157 /**
158 * Enables the previous step.
159 *
160 * @param enable true to enable false to disable
161 */
162 public void enablePreviousStep(final boolean enable) {
/*
P/P * Method: void enablePreviousStep(bool)
*
* Preconditions:
* this.control != null
* this.control.prev != null
*/
163 control.getPrevButton().setEnabled(enable);
164 }
165
166 /**
167 * shows the cancel confirmation.
168 *
169 * @return true if confirmed
170 */
171 public boolean showCancelConfirmation() {
/*
P/P * Method: bool showCancelConfirmation()
*
* Postconditions:
* init'ed(return_value)
*/
172 return JOptionPane.showConfirmDialog(this,
173 "Are you sure you want to cancel?",
174 "Cancel confirmation",
175 JOptionPane.YES_NO_OPTION,
176 JOptionPane.WARNING_MESSAGE) ==
177 JOptionPane.YES_OPTION;
178 }
179
180 /**
181 *
182 *
183 * @param step
184 * @return
185 */
186 public Step getStep(final int step) {
/*
P/P * Method: Step getStep(int)
*
* Preconditions:
* this.wizard != null
* this.wizard.layout != null
* this.wizard.layout.steps != null
*
* Postconditions:
* init'ed(return_value)
*/
187 return wizard.getStep(step);
188 }
189
190 /**
191 *
192 * @param name
193 * @return
194 */
195 public Step getStep(final String name) {
/*
P/P * Method: Step getStep(String)
*
* Preconditions:
* this.wizard != null
* this.wizard.layout != null
* this.wizard.layout.steps != null
* (soft) name != null
*
* Postconditions:
* init'ed(return_value)
*/
196 return wizard.getStep(name);
197 }
198
199 /**
200 *
201 *
202 * @return
203 */
204 public Step getCurrentStep() {
/*
P/P * Method: Step getCurrentStep()
*
* Preconditions:
* this.wizard != null
* this.wizard.layout != null
* init'ed(this.wizard.layout.currentStep)
* this.wizard.layout.steps != null
*
* Postconditions:
* init'ed(return_value)
*/
205 return wizard.getCurrentStep();
206 }
207
208 /**
209 *
210 *
211 * @return
212 */
213 public int getCurrentStepIndex() {
/*
P/P * Method: int getCurrentStepIndex()
*
* Preconditions:
* this.wizard != null
* this.wizard.layout != null
* init'ed(this.wizard.layout.currentStep)
*
* Postconditions:
* return_value == this.wizard.layout.currentStep
* init'ed(return_value)
*/
214 return wizard.getCurrentStepIndex();
215 }
216
217 /**
218 *
219 *
220 * @return
221 */
222 public String getCurrentStepName() {
/*
P/P * Method: String getCurrentStepName()
*
* Preconditions:
* this.wizard != null
* this.wizard.layout != null
* init'ed(this.wizard.layout.currentStep)
* this.wizard.layout.steps != null
*
* Postconditions:
* init'ed(return_value)
*/
223 return wizard.getCurrentStepName();
224 }
225
226 /**
227 *
228 *
229 * @param step
230 */
231 void fireStepAboutToBeDisplayed(final Step step) {
/*
P/P * Method: void fireStepAboutToBeDisplayed(Step)
*
* Preconditions:
* this.listeners != null
*
* Presumptions:
* com.dmdirc.util.ListenerList:get(...)@232 != null
* java.util.Iterator:next(...)@232 != null
*
* Test Vectors:
* java.util.Iterator:hasNext(...)@232: {0}, {1}
*/
232 for (StepListener listener : listeners.get(StepListener.class)) {
233 listener.stepAboutToDisplay(step);
234 }
235 }
236
237 /**
238 *
239 *
240 * @param step
241 */
242 void fireStepHidden(final Step step) {
/*
P/P * Method: void fireStepHidden(Step)
*
* Preconditions:
* this.listeners != null
*
* Presumptions:
* com.dmdirc.util.ListenerList:get(...)@243 != null
* java.util.Iterator:next(...)@243 != null
*
* Test Vectors:
* java.util.Iterator:hasNext(...)@243: {0}, {1}
*/
243 for (StepListener listener : listeners.get(StepListener.class)) {
244 listener.stepHidden(step);
245 }
246 }
247
248 /**
249 *
250 *
251 * @param listener
252 */
253 public void addStepListener(final StepListener listener) {
/*
P/P * Method: void addStepListener(StepListener)
*
* Preconditions:
* this.listeners != null
*/
254 listeners.add(StepListener.class, listener);
255 }
256
257 /**
258 *
259 *
260 * @param listener
261 */
262 public void removeStepListener(final StepListener listener) {
/*
P/P * Method: void removeStepListener(StepListener)
*
* Preconditions:
* this.listeners != null
*/
263 listeners.remove(StepListener.class, listener);
264
265 }
266
267 /**
268 *
269 */
270 void fireWizardCancelled() {
/*
P/P * Method: void fireWizardCancelled()
*
* Preconditions:
* this.listeners != null
*
* Presumptions:
* com.dmdirc.util.ListenerList:get(...)@271 != null
* java.util.Iterator:next(...)@271 != null
*
* Test Vectors:
* java.util.Iterator:hasNext(...)@271: {0}, {1}
*/
271 for (WizardListener listener : listeners.get(WizardListener.class)) {
272 listener.wizardCancelled();
273 }
274 }
275
276 /**
277 *
278 */
279 void fireWizardFinished() {
/*
P/P * Method: void fireWizardFinished()
*
* Preconditions:
* this.listeners != null
*
* Presumptions:
* com.dmdirc.util.ListenerList:get(...)@280 != null
* java.util.Iterator:next(...)@280 != null
*
* Test Vectors:
* java.util.Iterator:hasNext(...)@280: {0}, {1}
*/
280 for (WizardListener listener : listeners.get(WizardListener.class)) {
281 listener.wizardFinished();
282 }
283 }
284
285 /**
286 *
287 *
288 * @param listener
289 */
290 public void addWizardListener(final WizardListener listener) {
/*
P/P * Method: void addWizardListener(WizardListener)
*
* Preconditions:
* this.listeners != null
*/
291 listeners.add(WizardListener.class, listener);
292 }
293
294 /**
295 *
296 *
297 * @param listener
298 */
299 public void removeWizardListener(final WizardListener listener) {
/*
P/P * Method: void removeWizardListener(WizardListener)
*
* Preconditions:
* this.listeners != null
*/
300 listeners.remove(WizardListener.class, listener);
301 }
302
303 /**
304 * Initialises any settings required by this UI (this is always called
305 * before any aspect of the UI is instansiated).
306 *
307 * @throws UnsupportedOperationException If unable to switch to the system
308 * look and feel
309 */
310 public static void initUISettings() {
311
312 try {
/*
P/P * Method: void initUISettings()
*/
313 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
314 } catch (InstantiationException ex) {
315 throw new UnsupportedOperationException("Unable to switch to the " +
316 "system look and feel", ex);
317 } catch (ClassNotFoundException ex) {
318 throw new UnsupportedOperationException("Unable to switch to the " +
319 "system look and feel", ex);
320 } catch (UnsupportedLookAndFeelException ex) {
321 throw new UnsupportedOperationException("Unable to switch to the " +
322 "system look and feel", ex);
323 } catch (IllegalAccessException ex) {
324 throw new UnsupportedOperationException("Unable to switch to the " +
325 "system look and feel", ex);
326 }
327
328 UIManager.put("swing.useSystemFontSettings", true);
329 UIManager.put("swing.boldMetal", false);
330 }
331
332 @Override
333 public void actionPerformed(ActionEvent e) {
/*
P/P * Method: void actionPerformed(ActionEvent)
*
* Preconditions:
* e != null
* this.control != null
* this.wizard != null
* this.wizard.layout != null
* (soft) this.wizard.layout.currentStep in {-231+1..232-2}
* (soft) this.control.next != null
* (soft) this.control.prev != null
* (soft) this.control.progress != null
* (soft) init'ed(this.control.total)
* (soft) this.listeners != null
* ...
*
* Postconditions:
* possibly_updated(this.control.step)
* this.wizard.layout.currentStep <= 232-2
*
* Test Vectors:
* java.lang.String:equals(...)@342: {0}, {1}
*/
334 final int currentStep = wizard.getCurrentStepIndex();
335 Step hiddenStep = null;
336 Step shownStep = null;
337 if (e.getSource() == control.getPrevButton()) {
338 wizard.previousStep();
339 hiddenStep = wizard.getStep(currentStep);
340 shownStep = wizard.getStep(currentStep - 1);
341 } else if (e.getSource() == control.getNextButton()) {
342 if ("Finish".equals(control.getNextButton().getText())) {
343 fireWizardFinished();
344 shownStep = wizard.getStep(currentStep);
345 dispose();
346 } else {
347 wizard.nextStep();
348 hiddenStep = wizard.getStep(currentStep);
349 shownStep = wizard.getStep(currentStep + 1);
350 }
351 } else {
352 return;
353 }
354 title.setStep(shownStep);
355 if (shownStep != null) {
356 fireStepAboutToBeDisplayed(shownStep);
357 }
358 if (hiddenStep != null) {
359 fireStepHidden(hiddenStep);
360 }
361 control.setProgress(wizard.getCurrentStepIndex());
362 }
363 }
SofCheck Inspector Build Version : 2.17854
| InstallerDialog.java |
2009-Jun-25 01:54:24 |
| InstallerDialog.class |
2009-Sep-02 17:04:16 |
| InstallerDialog$1.class |
2009-Sep-02 17:04:16 |