1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
package org.argouml.uml.reveng.ui; |
40 | |
|
41 | |
import java.awt.BorderLayout; |
42 | |
import java.awt.Container; |
43 | |
import java.awt.Dimension; |
44 | |
import java.awt.Frame; |
45 | |
import java.awt.GridBagConstraints; |
46 | |
import java.awt.GridBagLayout; |
47 | |
import java.awt.Toolkit; |
48 | |
import java.awt.event.ActionEvent; |
49 | |
import java.awt.event.ActionListener; |
50 | |
import java.awt.event.WindowEvent; |
51 | |
import java.awt.event.WindowListener; |
52 | |
|
53 | |
import javax.swing.JButton; |
54 | |
import javax.swing.JDialog; |
55 | |
import javax.swing.JLabel; |
56 | |
import javax.swing.JPanel; |
57 | |
import javax.swing.JProgressBar; |
58 | |
import javax.swing.JScrollPane; |
59 | |
import javax.swing.JTextArea; |
60 | |
import javax.swing.SwingConstants; |
61 | |
import javax.swing.SwingUtilities; |
62 | |
|
63 | |
import org.argouml.i18n.Translator; |
64 | |
import org.argouml.taskmgmt.ProgressEvent; |
65 | |
import org.argouml.taskmgmt.ProgressMonitor; |
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | 0 | public class ImportStatusScreen extends JDialog |
77 | |
implements ProgressMonitor, WindowListener { |
78 | |
|
79 | |
private JButton cancelButton; |
80 | |
private JLabel progressLabel; |
81 | |
private JProgressBar progress; |
82 | |
private JTextArea messageArea; |
83 | 0 | private boolean hasMessages = false; |
84 | 0 | private boolean canceled = false; |
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | |
|
92 | |
public ImportStatusScreen(Frame frame, String title, String iconName) { |
93 | 0 | super(frame, true); |
94 | 0 | if (title != null) { |
95 | 0 | setTitle(title); |
96 | |
} |
97 | 0 | Dimension scrSize = Toolkit.getDefaultToolkit().getScreenSize(); |
98 | 0 | getContentPane().setLayout(new BorderLayout(4, 4)); |
99 | 0 | Container panel = new JPanel(new GridBagLayout()); |
100 | |
|
101 | |
|
102 | 0 | progressLabel = new JLabel(); |
103 | 0 | progressLabel.setHorizontalAlignment(SwingConstants.RIGHT); |
104 | |
|
105 | 0 | GridBagConstraints gbc = new GridBagConstraints(); |
106 | 0 | gbc.anchor = GridBagConstraints.NORTH; |
107 | 0 | gbc.fill = GridBagConstraints.HORIZONTAL; |
108 | 0 | gbc.gridwidth = GridBagConstraints.REMAINDER; |
109 | 0 | gbc.gridheight = 1; |
110 | 0 | gbc.gridx = 0; |
111 | 0 | gbc.gridy = 0; |
112 | 0 | gbc.weightx = 0.1; |
113 | |
|
114 | 0 | panel.add(progressLabel, gbc); |
115 | 0 | gbc.gridy++; |
116 | |
|
117 | |
|
118 | 0 | progress = new JProgressBar(); |
119 | 0 | gbc.anchor = GridBagConstraints.CENTER; |
120 | 0 | panel.add(progress, gbc); |
121 | 0 | gbc.gridy++; |
122 | |
|
123 | 0 | panel.add( |
124 | |
new JLabel(Translator.localize("label.import-messages")), gbc); |
125 | 0 | gbc.gridy++; |
126 | |
|
127 | |
|
128 | 0 | messageArea = new JTextArea(10, 50); |
129 | 0 | gbc.weighty = 0.8; |
130 | |
|
131 | 0 | gbc.fill = GridBagConstraints.BOTH; |
132 | 0 | panel.add(new JScrollPane(messageArea), gbc); |
133 | 0 | gbc.gridy++; |
134 | |
|
135 | |
|
136 | 0 | cancelButton = new JButton(Translator.localize("button.cancel")); |
137 | |
|
138 | 0 | gbc.fill = GridBagConstraints.NONE; |
139 | 0 | gbc.anchor = GridBagConstraints.SOUTH; |
140 | 0 | gbc.weighty = 0.1; |
141 | 0 | gbc.gridheight = GridBagConstraints.REMAINDER; |
142 | 0 | panel.add(cancelButton, gbc); |
143 | 0 | gbc.gridy++; |
144 | |
|
145 | 0 | cancelButton.addActionListener(new ActionListener() { |
146 | |
|
147 | |
public void actionPerformed(ActionEvent e) { |
148 | 0 | if (isComplete()) { |
149 | 0 | close(); |
150 | |
} |
151 | 0 | canceled = true; |
152 | 0 | } |
153 | |
|
154 | |
}); |
155 | |
|
156 | 0 | getContentPane().add(panel); |
157 | 0 | pack(); |
158 | 0 | Dimension contentPaneSize = getContentPane().getPreferredSize(); |
159 | 0 | setLocation(scrSize.width / 2 - contentPaneSize.width / 2, |
160 | |
scrSize.height / 2 - contentPaneSize.height / 2); |
161 | 0 | setResizable(true); |
162 | 0 | setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); |
163 | 0 | addWindowListener(this); |
164 | 0 | } |
165 | |
|
166 | |
public void setMaximumProgress(final int i) { |
167 | 0 | SwingUtilities.invokeLater(new Runnable () { |
168 | |
public void run() { |
169 | 0 | progress.setMaximum(i); |
170 | 0 | setVisible(true); |
171 | 0 | } |
172 | |
}); |
173 | 0 | } |
174 | |
|
175 | |
public void updateProgress(final int i) { |
176 | 0 | SwingUtilities.invokeLater(new Runnable () { |
177 | |
public void run() { |
178 | 0 | progress.setValue(i); |
179 | 0 | if (isComplete()) { |
180 | 0 | if (hasMessages) { |
181 | 0 | cancelButton.setText( |
182 | |
Translator.localize("button.close")); |
183 | |
} else { |
184 | 0 | close(); |
185 | |
} |
186 | |
} |
187 | 0 | } |
188 | |
}); |
189 | 0 | } |
190 | |
|
191 | |
private boolean isComplete() { |
192 | 0 | return progress.getValue() == progress.getMaximum(); |
193 | |
} |
194 | |
|
195 | |
|
196 | |
|
197 | |
|
198 | |
private static final long serialVersionUID = -1336242911879462274L; |
199 | |
|
200 | |
|
201 | |
|
202 | |
|
203 | |
public void close() { |
204 | 0 | SwingUtilities.invokeLater(new Runnable () { |
205 | |
public void run() { |
206 | 0 | setVisible(false); |
207 | 0 | dispose(); |
208 | 0 | } |
209 | |
}); |
210 | 0 | } |
211 | |
|
212 | |
|
213 | |
|
214 | |
|
215 | |
public boolean isCanceled() { |
216 | 0 | return canceled; |
217 | |
} |
218 | |
|
219 | |
|
220 | |
|
221 | |
|
222 | |
public void notifyMessage(final String title, final String introduction, |
223 | |
final String message) { |
224 | 0 | hasMessages = true; |
225 | |
|
226 | 0 | messageArea.setText(messageArea.getText() + title + "\n" + introduction |
227 | |
+ "\n" + message + "\n\n"); |
228 | 0 | messageArea.setCaretPosition(messageArea.getText().length()); |
229 | 0 | } |
230 | |
|
231 | |
|
232 | |
|
233 | |
|
234 | |
public void notifyNullAction() { |
235 | 0 | String msg = Translator.localize("label.import.empty"); |
236 | 0 | notifyMessage(msg, msg, msg); |
237 | 0 | } |
238 | |
|
239 | |
|
240 | |
|
241 | |
|
242 | |
public void updateMainTask(final String name) { |
243 | 0 | SwingUtilities.invokeLater(new Runnable () { |
244 | |
public void run() { |
245 | 0 | setTitle(name); |
246 | 0 | } |
247 | |
}); |
248 | 0 | } |
249 | |
|
250 | |
|
251 | |
|
252 | |
|
253 | |
public void updateSubTask(final String action) { |
254 | 0 | SwingUtilities.invokeLater(new Runnable () { |
255 | |
public void run() { |
256 | 0 | progressLabel.setText(action); |
257 | 0 | } |
258 | |
}); |
259 | 0 | } |
260 | |
|
261 | |
|
262 | |
|
263 | |
|
264 | |
public void progress(ProgressEvent event) throws InterruptedException { |
265 | |
|
266 | 0 | } |
267 | |
|
268 | |
public void windowClosing(WindowEvent e) { |
269 | |
|
270 | 0 | canceled = true; |
271 | 0 | close(); |
272 | 0 | } |
273 | |
|
274 | 0 | public void windowActivated(WindowEvent e) { } |
275 | 0 | public void windowClosed(WindowEvent e) { } |
276 | 0 | public void windowDeactivated(WindowEvent e) { } |
277 | 0 | public void windowDeiconified(WindowEvent e) { } |
278 | 0 | public void windowIconified(WindowEvent e) { } |
279 | 0 | public void windowOpened(WindowEvent e) { } |
280 | |
|
281 | |
} |