Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
ProgressMonitorWindow |
|
| 1.2857142857142858;1.286 | ||||
ProgressMonitorWindow$1 |
|
| 1.2857142857142858;1.286 | ||||
ProgressMonitorWindow$2 |
|
| 1.2857142857142858;1.286 | ||||
ProgressMonitorWindow$3 |
|
| 1.2857142857142858;1.286 |
1 | /* $Id: ProgressMonitorWindow.java 17841 2010-01-12 19:17:52Z linus $ | |
2 | ***************************************************************************** | |
3 | * Copyright (c) 2009 Contributors - see below | |
4 | * All rights reserved. This program and the accompanying materials | |
5 | * are made available under the terms of the Eclipse Public License v1.0 | |
6 | * which accompanies this distribution, and is available at | |
7 | * http://www.eclipse.org/legal/epl-v10.html | |
8 | * | |
9 | * Contributors: | |
10 | * bobtarling | |
11 | ***************************************************************************** | |
12 | * | |
13 | * Some portions of this file was previously release using the BSD License: | |
14 | */ | |
15 | ||
16 | // Copyright (c) 2006-2008 The Regents of the University of California. All | |
17 | // Rights Reserved. Permission to use, copy, modify, and distribute this | |
18 | // software and its documentation without fee, and without a written | |
19 | // agreement is hereby granted, provided that the above copyright notice | |
20 | // and this paragraph appear in all copies. This software program and | |
21 | // documentation are copyrighted by The Regents of the University of | |
22 | // California. The software program and documentation are supplied "AS | |
23 | // IS", without any accompanying services from The Regents. The Regents | |
24 | // does not warrant that the operation of the program will be | |
25 | // uninterrupted or error-free. The end-user understands that the program | |
26 | // was developed for research purposes and is advised not to rely | |
27 | // exclusively on the program for any reason. IN NO EVENT SHALL THE | |
28 | // UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, | |
29 | // SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, | |
30 | // ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF | |
31 | // THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF | |
32 | // SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY | |
33 | // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
34 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE | |
35 | // PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF | |
36 | // CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, | |
37 | // UPDATES, ENHANCEMENTS, OR MODIFICATIONS. | |
38 | ||
39 | package org.argouml.ui; | |
40 | ||
41 | import java.awt.Frame; | |
42 | ||
43 | import javax.swing.JDialog; | |
44 | import javax.swing.ProgressMonitor; | |
45 | import javax.swing.SwingUtilities; | |
46 | import javax.swing.UIManager; | |
47 | ||
48 | import org.argouml.i18n.Translator; | |
49 | import org.argouml.taskmgmt.ProgressEvent; | |
50 | import org.argouml.util.ArgoFrame; | |
51 | ||
52 | /** | |
53 | * Manages a ProgressMonitor dialog. | |
54 | * | |
55 | * NOTE: Users of this class should use the type of the interface | |
56 | * {@link org.argouml.taskmgmt.ProgressMonitor} wherever possible to | |
57 | * maintain GUI independence. | |
58 | * | |
59 | * @author andrea_nironi@tigris.org | |
60 | * @deprecated in 0.29.1 This is only a helper class for save/load and will | |
61 | * become package scope. It is not designed for reuse outside this package. | |
62 | * | |
63 | * TODO: Bob says: I don't like the naming of this class. Its confusing that | |
64 | * its called ...Window and yet it is not a window. Lets rename once we have | |
65 | * it hidden. | |
66 | */ | |
67 | 0 | public class ProgressMonitorWindow implements |
68 | org.argouml.taskmgmt.ProgressMonitor { | |
69 | ||
70 | private ProgressMonitor pbar; | |
71 | ||
72 | /** | |
73 | * initializes a ProgressMonitor | |
74 | * | |
75 | * @param parent the Component to be set as parent | |
76 | * @param title the (internationalized) title of the ProgressMonitor | |
77 | */ | |
78 | 0 | public ProgressMonitorWindow(Frame parent, String title) { |
79 | 0 | pbar = new ProgressMonitor(parent, |
80 | title, | |
81 | null, 0, 100); | |
82 | 0 | pbar.setMillisToDecideToPopup(250); |
83 | 0 | pbar.setMillisToPopup(500); |
84 | 0 | parent.repaint(); |
85 | 0 | updateProgress(5); |
86 | ||
87 | 0 | } |
88 | ||
89 | /** | |
90 | * initializes a ProgressMonitor | |
91 | * | |
92 | * @param parent the Component to be set as parent | |
93 | * @param progressMonitor the ProgressMonitor | |
94 | */ | |
95 | public ProgressMonitorWindow( | |
96 | final Frame parent, | |
97 | 0 | final ProgressMonitor progressMonitor) { |
98 | 0 | pbar = progressMonitor; |
99 | 0 | pbar.setMillisToDecideToPopup(250); |
100 | 0 | pbar.setMillisToPopup(500); |
101 | 0 | parent.repaint(); |
102 | 0 | updateProgress(5); |
103 | 0 | } |
104 | ||
105 | /* | |
106 | * Report a progress to the ProgressMonitor window. | |
107 | * @see org.argouml.persistence.ProgressListener#progress(org.argouml.persistence.ProgressEvent) | |
108 | */ | |
109 | public void progress(final ProgressEvent event) { | |
110 | 0 | final int progress = (int) event.getPosition(); |
111 | 0 | if (pbar != null) { |
112 | // File load/save gets done on a background thread, so we'll | |
113 | // probably have to queue this to the Swing event thread | |
114 | 0 | if (!SwingUtilities.isEventDispatchThread()) { |
115 | 0 | SwingUtilities.invokeLater(new Runnable() { |
116 | public void run() { | |
117 | 0 | updateProgress(progress); |
118 | 0 | } |
119 | }); | |
120 | } else { | |
121 | 0 | updateProgress(progress); |
122 | } | |
123 | } | |
124 | 0 | } |
125 | ||
126 | /* | |
127 | * Report a progress to the ProgressMonitor window. | |
128 | * @see org.argouml.application.api.ProgressMonitor#updateProgress(int) | |
129 | */ | |
130 | public void updateProgress(final int progress) { | |
131 | 0 | if (pbar != null) { |
132 | 0 | pbar.setProgress(progress); |
133 | 0 | Object[] args = new Object[] {String.valueOf(progress)}; |
134 | 0 | pbar.setNote(Translator.localize("dialog.progress.note", args)); |
135 | } | |
136 | 0 | } |
137 | ||
138 | ||
139 | /* | |
140 | * @see org.argouml.application.api.ProgressMonitor#isCanceled() | |
141 | */ | |
142 | public boolean isCanceled() { | |
143 | 0 | return (pbar != null) && pbar.isCanceled(); |
144 | } | |
145 | ||
146 | /* | |
147 | * @see org.argouml.application.api.ProgressMonitor#close() | |
148 | */ | |
149 | public void close() { | |
150 | // Queue to event thread to prevent race during close | |
151 | 0 | SwingUtilities.invokeLater(new Runnable() { |
152 | public void run() { | |
153 | 0 | pbar.close(); |
154 | 0 | pbar = null; |
155 | 0 | } |
156 | }); | |
157 | ||
158 | 0 | } |
159 | ||
160 | // these settings are needed to make the ProgressMonitor pop up early | |
161 | static { | |
162 | 0 | UIManager.put("ProgressBar.repaintInterval", Integer.valueOf(150)); |
163 | 0 | UIManager.put("ProgressBar.cycleTime", Integer.valueOf(1050)); |
164 | 0 | } |
165 | ||
166 | /* | |
167 | * @see org.argouml.application.api.ProgressMonitor#notifyMessage(java.lang.String, java.lang.String, java.lang.String) | |
168 | */ | |
169 | public void notifyMessage(final String title, final String introduction, | |
170 | final String message) { | |
171 | 0 | final String messageString = introduction + " : " + message; |
172 | 0 | pbar.setNote(messageString); |
173 | 0 | SwingUtilities.invokeLater(new Runnable() { |
174 | public void run() { | |
175 | 0 | JDialog dialog = |
176 | new ExceptionDialog( | |
177 | ArgoFrame.getFrame(), | |
178 | title, | |
179 | introduction, | |
180 | message); | |
181 | 0 | dialog.setVisible(true); |
182 | 0 | } |
183 | }); | |
184 | 0 | } |
185 | ||
186 | /* | |
187 | * @see org.argouml.application.api.ProgressMonitor#notifyNullAction() | |
188 | */ | |
189 | public void notifyNullAction() { | |
190 | // ignored | |
191 | 0 | } |
192 | ||
193 | /* | |
194 | * @see org.argouml.application.api.ProgressMonitor#setMaximumProgress(int) | |
195 | */ | |
196 | public void setMaximumProgress(int max) { | |
197 | 0 | pbar.setMaximum(max); |
198 | 0 | } |
199 | ||
200 | public void updateSubTask(String action) { | |
201 | // TODO: concatenate? - tfm | |
202 | // overwrite for now | |
203 | 0 | pbar.setNote(action); |
204 | 0 | } |
205 | ||
206 | public void updateMainTask(String name) { | |
207 | 0 | pbar.setNote(name); |
208 | 0 | } |
209 | } |