Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
StatusBar |
|
| 1.2;1.2 |
1 | /* $Id: StatusBar.java 18817 2010-10-27 15:52:25Z tfmorris $ | |
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 | * tfmorris | |
11 | ***************************************************************************** | |
12 | * | |
13 | * Some portions of this file was previously release using the BSD License: | |
14 | */ | |
15 | ||
16 | // Copyright (c) 1996-2006 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.BorderLayout; | |
42 | import java.awt.Color; | |
43 | import java.awt.Dimension; | |
44 | import java.awt.Font; | |
45 | import javax.swing.JLabel; | |
46 | import javax.swing.JPanel; | |
47 | import javax.swing.JProgressBar; | |
48 | import javax.swing.border.EtchedBorder; | |
49 | ||
50 | import org.argouml.taskmgmt.ProgressEvent; | |
51 | import org.argouml.taskmgmt.ProgressMonitor; | |
52 | import org.tigris.gef.ui.IStatusBar; | |
53 | ||
54 | /** | |
55 | * The status bar. | |
56 | * | |
57 | */ | |
58 | public class StatusBar | |
59 | extends JPanel | |
60 | implements Runnable, IStatusBar, ProgressMonitor { | |
61 | ||
62 | 900 | private JLabel msg = new JLabel(); |
63 | 900 | private JProgressBar progress = new JProgressBar(); |
64 | private String statusText; | |
65 | ||
66 | /** | |
67 | * The constructor. | |
68 | * | |
69 | */ | |
70 | 900 | public StatusBar() { |
71 | 900 | progress.setMinimum(0); |
72 | 900 | progress.setMaximum(100); |
73 | 900 | progress.setMinimumSize(new Dimension(100, 20)); |
74 | 900 | progress.setSize(new Dimension(100, 20)); |
75 | ||
76 | 900 | msg.setMinimumSize(new Dimension(300, 20)); |
77 | 900 | msg.setSize(new Dimension(300, 20)); |
78 | 900 | msg.setFont(new Font("Dialog", Font.PLAIN, 10)); |
79 | 900 | msg.setForeground(Color.black); |
80 | ||
81 | 900 | setLayout(new BorderLayout()); |
82 | 900 | setBorder(new EtchedBorder(EtchedBorder.LOWERED)); |
83 | 900 | add(msg, BorderLayout.CENTER); |
84 | 900 | add(progress, BorderLayout.EAST); |
85 | 900 | } |
86 | ||
87 | /** | |
88 | * @param s the status string to show | |
89 | */ | |
90 | public void showStatus(String s) { | |
91 | 22008 | msg.setText(s); |
92 | 22008 | paintImmediately(getBounds()); |
93 | 22008 | } |
94 | ||
95 | /** | |
96 | * @param percent the percentage of the progress bar to be shown | |
97 | */ | |
98 | public void showProgress(int percent) { | |
99 | 0 | progress.setValue(percent); |
100 | 0 | } |
101 | ||
102 | /** | |
103 | * @param delataPercent an increment for the progrss bar | |
104 | */ | |
105 | public void incProgress(int delataPercent) { | |
106 | 0 | progress.setValue(progress.getValue() + delataPercent); |
107 | 0 | } |
108 | ||
109 | /** | |
110 | * @param s the status bar text | |
111 | * @param work the work that has to be done, | |
112 | * i.e. the maximum value for the progress | |
113 | */ | |
114 | public synchronized void doFakeProgress(String s, int work) { | |
115 | 0 | statusText = s; |
116 | 0 | showStatus(statusText + "... not implemented yet ..."); |
117 | 0 | progress.setMaximum(work); |
118 | 0 | progress.setValue(0); |
119 | 0 | Thread t = new Thread(this); |
120 | 0 | t.start(); |
121 | 0 | } |
122 | ||
123 | /* | |
124 | * @see java.lang.Runnable#run() | |
125 | */ | |
126 | public synchronized void run() { | |
127 | 0 | int work = progress.getMaximum(); |
128 | 0 | for (int i = 0; i < work; i++) { |
129 | 0 | progress.setValue(i); |
130 | 0 | repaint(); |
131 | 0 | try { wait(10); } |
132 | 0 | catch (InterruptedException ex) { } |
133 | } | |
134 | 0 | showStatus(statusText + "... done."); |
135 | 0 | repaint(); |
136 | 0 | try { wait(1000); } |
137 | 0 | catch (InterruptedException ex) { } |
138 | 0 | progress.setValue(0); |
139 | 0 | showStatus(""); |
140 | 0 | repaint(); |
141 | 0 | } |
142 | ||
143 | public void progress(ProgressEvent event) throws InterruptedException { | |
144 | // TODO: Auto-generated method stub | |
145 | 0 | } |
146 | ||
147 | public void updateProgress(int value) { | |
148 | 0 | progress.setValue(value); |
149 | 0 | } |
150 | ||
151 | public void updateSubTask(String name) { | |
152 | 0 | msg.setText(name); |
153 | 0 | } |
154 | ||
155 | public void updateMainTask(String name) { | |
156 | 0 | msg.setText(name); |
157 | 0 | } |
158 | ||
159 | public boolean isCanceled() { | |
160 | 0 | return false; |
161 | } | |
162 | ||
163 | public void setMaximumProgress(int max) { | |
164 | 0 | progress.setMaximum(max); |
165 | 0 | } |
166 | ||
167 | 0 | public void notifyNullAction() {} |
168 | ||
169 | public void notifyMessage(String title, String introduction, String message) { | |
170 | // TODO: Auto-generated method stub | |
171 | ||
172 | 0 | } |
173 | ||
174 | public void close() { | |
175 | 0 | setVisible(false); |
176 | 0 | } |
177 | ||
178 | } |