File Source: WizardControlPanel.java
/*
P/P * Method: com.dmdirc.installer.ui.WizardControlPanel__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.ui.EtchedLineBorder.BorderSide;
27 import java.awt.Dimension;
28 import javax.swing.Box;
29 import javax.swing.BoxLayout;
30 import javax.swing.JButton;
31 import javax.swing.JLabel;
32 import javax.swing.JPanel;
33 import javax.swing.border.EtchedBorder;
34
35 /**
36 * Simple Panel representing the control buttons for a wizard.
37 */
38 public class WizardControlPanel extends JPanel {
39
40 private static final long serialVersionUID = 7903362315297158222L;
41 private final JButton prev;
42 private final JButton next;
43 private final JLabel progress;
44 private int total;
45 private int step;
46
47 /**
48 * Instantiates a new wizard control panel.
49 */
50 public WizardControlPanel() {
/*
P/P * Method: void com.dmdirc.installer.ui.WizardControlPanel()
*
* Postconditions:
* this.next == &new JButton(WizardControlPanel#2)
* this.prev == &new JButton(WizardControlPanel#1)
* this.progress == &new JLabel(WizardControlPanel#3)
* init'ed(this.step)
* this.total == 0
* new JButton(WizardControlPanel#1) num objects == 1
* new JButton(WizardControlPanel#2) num objects == 1
* new JLabel(WizardControlPanel#3) num objects == 1
*/
51 this(0);
52 }
53
54 /**
55 * Instantiates a new wizard control panel using the specified number of
56 * steps.
57 *
58 * @param total Total number of steps
59 */
/*
P/P * Method: void com.dmdirc.installer.ui.WizardControlPanel(int)
*
* Presumptions:
* java.awt.Font:getSize(...)@69 <= 4_294_967_285
* java.awt.Font:getSize(...)@70 <= 4_294_967_285
* javax.swing.JButton:getFont(...)@69 != null
* javax.swing.JButton:getFont(...)@70 != null
*
* Postconditions:
* this.next == &new JButton(WizardControlPanel#2)
* this.prev == &new JButton(WizardControlPanel#1)
* this.progress == &new JLabel(WizardControlPanel#3)
* init'ed(this.step)
* this.total == total
* init'ed(this.total)
* new JButton(WizardControlPanel#1) num objects == 1
* new JButton(WizardControlPanel#2) num objects == 1
* new JLabel(WizardControlPanel#3) num objects == 1
*/
60 public WizardControlPanel(final int total) {
61 this.total = total;
62 this.step = 0;
63
64 prev = new JButton("\u00AB Previous");
65 next = new JButton("Next \u00BB");
66 progress = new JLabel();
67 updateProgressLabel();
68
69 prev.setPreferredSize(new Dimension(100, prev.getFont().getSize() + 2 * InstallerDialog.SMALL_GAP));
70 next.setPreferredSize(new Dimension(100, next.getFont().getSize() + 2 * InstallerDialog.SMALL_GAP));
71
72 setBorder(new EtchedLineBorder(EtchedBorder.LOWERED, BorderSide.TOP));
73 setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS));
74 add(progress);
75 add(Box.createHorizontalGlue());
76 add(prev);
77 add(Box.createHorizontalStrut(InstallerDialog.SMALL_GAP));
78 add(next);
79 }
80
81 /**
82 * Returns the previous button.
83 *
84 * @return Previous button
85 */
86 public JButton getPrevButton() {
/*
P/P * Method: JButton getPrevButton()
*
* Postconditions:
* return_value == this.prev
* init'ed(return_value)
*/
87 return prev;
88 }
89
90 /**
91 * Returns the next button.
92 *
93 * @return Next button
94 */
95 public JButton getNextButton() {
/*
P/P * Method: JButton getNextButton()
*
* Postconditions:
* return_value == this.next
* init'ed(return_value)
*/
96 return next;
97 }
98
99 /**
100 * Returns the progress label.
101 *
102 * @return Progress Label
103 */
104 public JLabel getProgressLabel() {
/*
P/P * Method: JLabel getProgressLabel()
*
* Postconditions:
* return_value == this.progress
* init'ed(return_value)
*/
105 return progress;
106 }
107
108 /**
109 * Updates the progress label.
110 */
111 public void updateProgressLabel() {
/*
P/P * Method: void updateProgressLabel()
*
* Preconditions:
* this.progress != null
* init'ed(this.step)
* init'ed(this.total)
*/
112 progress.setText("Step " + step + " of " + total);
113 }
114
115 /**
116 * Sets the new total number of steps.
117 *
118 * @param total New total number of steps
119 */
120 public void setTotal(final int total) {
/*
P/P * Method: void setTotal(int)
*
* Preconditions:
* this.progress != null
* init'ed(this.step)
*
* Postconditions:
* this.total == total
* init'ed(this.total)
*/
121 this.total = total;
122 updateProgressLabel();
123 }
124
125 /**
126 * Sets the current progress step.
127 *
128 * @param step Progress step
129 */
130 public void setProgress(final int step) {
/*
P/P * Method: void setProgress(int)
*
* Preconditions:
* step <= 232-2
* this.progress != null
* init'ed(this.total)
* (soft) this.next != null
* (soft) this.prev != null
*
* Postconditions:
* this.step == step + 1
* this.step >= -231+1
*
* Test Vectors:
* step: {-231..-1}, {0}, {1..232-2}
* this.total - step: {-231+1..0, 2..232-2}, {1}
*/
131 this.step = step + 1;
132 updateProgressLabel();
133 if (step + 1 == total) {
134 next.setText("Finish");
135 } else if (step == 0) {
136 prev.setEnabled(false);
137 } else if (step > 0) {
138 prev.setEnabled(true);
139 } else {
140 next.setText("Next \u00BB");
141 }
142 }
143 }
SofCheck Inspector Build Version : 2.17854
| WizardControlPanel.java |
2009-Jun-25 01:54:24 |
| WizardControlPanel.class |
2009-Sep-02 17:04:16 |