1 /***
2 * Created by IntelliJ IDEA.
3 * User: Lennart
4 * Date: 16-jul-2003
5 * Time: 15:03:19
6 */
7 package comics.gui.progressbars;
8
9 import javax.swing.*;
10 import java.awt.*;
11
12 /*
13 * CVS information:
14 *
15 * $Revision: 1.1.1.1 $
16 * $Date: 2003/09/10 10:25:38 $
17 */
18
19 /***
20 * This class implements a simple JDialog with a title, a message and a progressbar.
21 *
22 * @author Lennart Martens
23 */
24 public class DefaultProgressBar extends JDialog {
25
26 /***
27 * The message to display on the progress bar.
28 */
29 private String iMessage = null;
30 /***
31 * The minimum for the progress bar.
32 */
33 private int iMinimum = 0;
34 /***
35 * The maximum for the progress bar.
36 */
37 private int iMaximum = 0;
38 /***
39 * The label.
40 */
41 private JLabel lblMessage = null;
42 /***
43 * The progressbar component.
44 */
45 private JProgressBar jpbProgress = null;
46
47 /***
48 * The constructor takes an owner, a title and minimum and
49 * maximum values for the progress. The message is set to "Progress..." <br />
50 * By default, the initial value is set to the minimum specified.
51 * You can specify another starting value by calling the 'setValue()' method after
52 * construction.
53 *
54 * @param aOwner Frame with the owner of this JDialog.
55 * @param aTitle String with the title for the JDialog.
56 * @param aMinimum int with the minimum value of the progress.
57 * @param aMaximum int with the maximum value of the progress.
58 */
59 public DefaultProgressBar(Frame aOwner, String aTitle, int aMinimum, int aMaximum) {
60 this(aOwner, aTitle, aMinimum, aMaximum, "Progress:");
61 }
62
63 /***
64 * The constructor takes an owner, a title, minimum and
65 * maximum values for the progress and a message for the dialog. <br />
66 * By default, the initial value is set to the minimum specified.
67 * You can specify another starting value by calling the 'setValue()' method after
68 * construction.
69 *
70 * @param aOwner Frame with the owner of this JDialog.
71 * @param aTitle String with the title for the JDialog.
72 * @param aMinimum int with the minimum value of the progress.
73 * @param aMaximum int with the maximum value of the progress.
74 * @param aMessage String with the message to be displayed on the JDialog
75 */
76 public DefaultProgressBar(Frame aOwner, String aTitle, int aMinimum, int aMaximum, String aMessage) {
77 // Super class.
78 super(aOwner, aTitle, true);
79
80 // Initializations.
81 iMinimum = aMinimum;
82 iMaximum = aMaximum;
83 iMessage = aMessage;
84 jpbProgress = new JProgressBar(iMinimum, iMaximum);
85 jpbProgress.setValue(iMinimum);
86 jpbProgress.setStringPainted(true);
87
88 // GUI.
89 this.constructScreen();
90 this.pack();
91 Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
92 this.setLocation((screen.width/4), (screen.height/4));
93 }
94
95 /***
96 * This method basically tells the progressbar to move on. <br />
97 * Note that setting a value that is greater than or equal to the maximum,
98 * will cause the progress bar to be disposed of.
99 *
100 * @param aValue int with the value to which the progressbar should move.
101 */
102 public void setValue(int aValue) {
103 if(aValue < iMinimum) {
104 throw new IllegalArgumentException("Cannot progress to a value (" + aValue + ") that is less than the minimum (" + iMinimum + ")!");
105 }
106 jpbProgress.setValue(aValue);
107 if(aValue >= iMaximum) {
108 this.setVisible(false);
109 this.dispose();
110 }
111 }
112
113 /***
114 * This method will return the current value of the progressbar.
115 *
116 * @return int with the current value of the progressbar.
117 */
118 public int getValue() {
119 return jpbProgress.getValue();
120 }
121
122 public int getMaximum() {
123 return iMaximum;
124 }
125
126 public int getMinimum() {
127 return iMinimum;
128 }
129
130 /***
131 * This method alters the message visible on the dialog.
132 *
133 * @param aMessage String with the message to display.
134 */
135 public void setMessage(String aMessage) {
136 this.iMessage = aMessage;
137 this.lblMessage.setText(aMessage);
138 }
139
140 /***
141 * This method create the GUI for this dialog.
142 */
143 private void constructScreen() {
144 JPanel jpanMain = new JPanel();
145 jpanMain.setLayout(new BoxLayout(jpanMain, BoxLayout.Y_AXIS));
146 lblMessage = new JLabel(iMessage);
147 jpanMain.add(Box.createVerticalStrut(5));
148 jpanMain.add(lblMessage);
149 jpanMain.add(Box.createVerticalStrut(10));
150 jpanMain.add(jpbProgress);
151 jpanMain.add(Box.createVerticalStrut(5));
152
153 this.getContentPane().add(jpanMain, BorderLayout.CENTER);
154 }
155 }
This page was automatically generated by Maven