1 /*
2 * NeonZip - archive tool
3 * Copyright (C) 2001 Peter Ivanov
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 *
19 *
20 * Extends standard input stream and update given ProgressMonitor
21 * while reading.
22 *
23 *
24 * @author Peter Ivanov
25 * <a href=mailto:peterivanov@europe.com>peterivanov@europe.com</a>,
26 * <br>Copyright (c) 2001 Peter K. Ivanov.
27 *
28 * @version (December 30 2001)
29 *
30 */
31
32
33 package net.sourceforge.neonzip;
34
35 import java.awt;
36 import java.awt.event;
37 import javax.swing;
38
39 public final class NeonMonitor extends JDialog {
40
41 private JFrame fOwner;
42
43 private JLabel fLabelNote;
44 private JLabel fLabelMessage;
45 private JProgressBar fProgress;
46
47 private int fMax = 0;
48 private int fMin = 0;
49 private int fCurrent = 0;
50
51 public boolean fIsCanceled = false;
52
53 public NeonMonitor(JFrame aOwner) {
54 super(aOwner, false);
55 initComponents();
56 pack();
57 setSize(350, 150);
58 Utils.centerWindow(this);
59 fOwner = aOwner;
60 }
61
62
63
64 public void dispose() {
65 //fIsCanceled = false;
66 super.dispose();
67 }
68
69
70
71 public void show() {
72 fIsCanceled = false;
73 super.show();
74 //pack();
75 }
76
77
78
79 public void setProgress(int aValue) {
80 if (aValue >= fMax) return;
81 fCurrent = aValue;
82 fProgress.setValue(aValue);
83 }
84
85
86
87 public int getMinimum() {
88 return fMin;
89 }
90
91
92
93 public void setMinimum(int aMinimum) {
94 fMin = aMinimum;
95 fProgress.setMinimum(fMin);
96 }
97
98
99
100 public int getMaximum() {
101 return fMax;
102 }
103
104
105
106 public void setMaximum(int aMaximum) {
107 fMax = aMaximum;
108 fProgress.setMaximum(fMax);
109 }
110
111
112
113 public boolean isCanceled() {
114 return fIsCanceled;
115 }
116
117
118
119 public String getNote() {
120 return fLabelNote.getText();
121 }
122
123
124
125 public void setNote(String aNote) {
126 fLabelNote.setText(aNote);
127 }
128
129
130
131 public String getMessage() {
132 return fLabelMessage.getText();
133 }
134
135
136
137 public void setMessage(String aMessage) {
138 fLabelMessage.setText(aMessage);
139 //pack();
140 }
141
142
143
144 private void initComponents() {
145 fLabelNote = new JLabel(" ");
146 fLabelNote.setAlignmentX(Component.LEFT_ALIGNMENT);
147 fLabelNote.setForeground(Color.black);
148 fLabelMessage = new JLabel(" ");
149 fLabelMessage.setAlignmentX(Component.LEFT_ALIGNMENT);
150 fLabelMessage.setHorizontalAlignment(SwingConstants.LEFT);
151 fProgress = new JProgressBar();
152 fProgress.setAlignmentX(Component.LEFT_ALIGNMENT);
153
154 setTitle(Main.fResources.getString("key.title.progress_monitor"));
155 setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
156 JPanel root = new JPanel(new BorderLayout());
157 getContentPane().add(root);
158
159 JPanel panelCenter = new JPanel();
160 panelCenter.setLayout(new BoxLayout(panelCenter, BoxLayout.Y_AXIS));
161
162 panelCenter.add(fLabelNote);
163 panelCenter.add(fLabelMessage);
164 panelCenter.add(fProgress);
165
166 root.add(panelCenter, "Center");
167
168 JPanel panelButtons = new JPanel();
169 JButton btnCancel = new JButton(new CancelAction());
170 panelButtons.add(btnCancel);
171
172 root.add(panelButtons, "South");
173 }
174
175
176
177 private final class CancelAction extends AbstractAction {
178 CancelAction() {
179 super(Main.fResources.getString("key.button.cancel"));
180 }
181
182 public void actionPerformed(ActionEvent e) {
183 fIsCanceled = true;
184 dispose();
185 fOwner.getGlassPane().setVisible(false);
186 }
187 }
188 }