KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > poa > gui > beans > FillLevelBar


1 package org.jacorb.poa.gui.beans;
2
3 /*
4  * JacORB - a free Java ORB
5  *
6  * Copyright (C) 1997-2004 Gerald Brose.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the Free
20  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  */

22  
23 /**
24  * Provides the functionality of a fill level statebar.
25  *
26  * @author Reimo Tiedemann, FU Berlin
27  * @version 1.0, 05/03/99
28  * @see org.jacorb.poa.gui.beans.FillLevelCanvas
29  */

30 public class FillLevelBar extends java.awt.Panel JavaDoc {
31     private boolean useAvg;
32     private boolean isVariable;
33     private int max;
34     private int avg;
35     private int min;
36     private int cur;
37     private java.awt.Label JavaDoc ivjAvgLabel = null;
38     private java.awt.Label JavaDoc ivjCurLabel = null;
39     private java.awt.Label JavaDoc ivjMaxLabel = null;
40     private java.awt.Label JavaDoc ivjMinLabel = null;
41     private FillLevelCanvas ivjFillLevelCanvas = null;
42 /**
43  * Constructor
44  */

45 /* WARNING: THIS METHOD WILL BE REGENERATED. */
46 public FillLevelBar() {
47     super();
48     initialize();
49 }
50 /**
51  * FillLevelBar constructor comment.
52  * @param layout java.awt.LayoutManager
53  */

54 public FillLevelBar(java.awt.LayoutManager JavaDoc layout) {
55     super(layout);
56 }
57 /**
58  * Return the Label22 property value.
59  * @return java.awt.Label
60  */

61 /* WARNING: THIS METHOD WILL BE REGENERATED. */
62 private java.awt.Label JavaDoc getAvgLabel() {
63     if (ivjAvgLabel == null) {
64         try {
65             ivjAvgLabel = new java.awt.Label JavaDoc();
66             ivjAvgLabel.setName("AvgLabel");
67             ivjAvgLabel.setText("");
68             ivjAvgLabel.setBackground(java.awt.SystemColor.control);
69             ivjAvgLabel.setFont(new java.awt.Font JavaDoc("dialog", 0, 10));
70             ivjAvgLabel.setBounds(23, 54, 25, 10);
71             // user code begin {1}
72
// user code end
73
} catch (java.lang.Throwable JavaDoc ivjExc) {
74             // user code begin {2}
75
// user code end
76
handleException(ivjExc);
77         }
78     };
79     return ivjAvgLabel;
80 }
81 /**
82  * Return the Label1 property value.
83  * @return java.awt.Label
84  */

85 /* WARNING: THIS METHOD WILL BE REGENERATED. */
86 private java.awt.Label JavaDoc getCurLabel() {
87     if (ivjCurLabel == null) {
88         try {
89             ivjCurLabel = new java.awt.Label JavaDoc();
90             ivjCurLabel.setName("CurLabel");
91             ivjCurLabel.setText("");
92             ivjCurLabel.setBackground(java.awt.SystemColor.control);
93             ivjCurLabel.setFont(new java.awt.Font JavaDoc("dialog", 0, 10));
94             ivjCurLabel.setAlignment(1);
95             ivjCurLabel.setBounds(0, 115, 25, 12);
96             // user code begin {1}
97
// user code end
98
} catch (java.lang.Throwable JavaDoc ivjExc) {
99             // user code begin {2}
100
// user code end
101
handleException(ivjExc);
102         }
103     };
104     return ivjCurLabel;
105 }
106 /**
107  * Return the FillLevelCanvas property value.
108  * @return org.jacorb.poa.gui.beans.FillLevelCanvas
109  */

110 /* WARNING: THIS METHOD WILL BE REGENERATED. */
111 private FillLevelCanvas getFillLevelCanvas() {
112     if (ivjFillLevelCanvas == null) {
113         try {
114             ivjFillLevelCanvas = new org.jacorb.poa.gui.beans.FillLevelCanvas();
115             ivjFillLevelCanvas.setName("FillLevelCanvas");
116             ivjFillLevelCanvas.setBounds(5, 10, 15, 100);
117             // user code begin {1}
118
// user code end
119
} catch (java.lang.Throwable JavaDoc ivjExc) {
120             // user code begin {2}
121
// user code end
122
handleException(ivjExc);
123         }
124     };
125     return ivjFillLevelCanvas;
126 }
127 /**
128  * Return the Label21 property value.
129  * @return java.awt.Label
130  */

131 /* WARNING: THIS METHOD WILL BE REGENERATED. */
132 private java.awt.Label JavaDoc getMaxLabel() {
133     if (ivjMaxLabel == null) {
134         try {
135             ivjMaxLabel = new java.awt.Label JavaDoc();
136             ivjMaxLabel.setName("MaxLabel");
137             ivjMaxLabel.setText("");
138             ivjMaxLabel.setBackground(java.awt.SystemColor.control);
139             ivjMaxLabel.setFont(new java.awt.Font JavaDoc("dialog", 0, 10));
140             ivjMaxLabel.setBounds(23, 7, 25, 10);
141             // user code begin {1}
142
// user code end
143
} catch (java.lang.Throwable JavaDoc ivjExc) {
144             // user code begin {2}
145
// user code end
146
handleException(ivjExc);
147         }
148     };
149     return ivjMaxLabel;
150 }
151 /**
152  * Return the Label2 property value.
153  * @return java.awt.Label
154  */

155 /* WARNING: THIS METHOD WILL BE REGENERATED. */
156 private java.awt.Label JavaDoc getMinLabel() {
157     if (ivjMinLabel == null) {
158         try {
159             ivjMinLabel = new java.awt.Label JavaDoc();
160             ivjMinLabel.setName("MinLabel");
161             ivjMinLabel.setText("");
162             ivjMinLabel.setBackground(java.awt.SystemColor.control);
163             ivjMinLabel.setFont(new java.awt.Font JavaDoc("dialog", 0, 10));
164             ivjMinLabel.setBounds(23, 104, 25, 10);
165             // user code begin {1}
166
// user code end
167
} catch (java.lang.Throwable JavaDoc ivjExc) {
168             // user code begin {2}
169
// user code end
170
handleException(ivjExc);
171         }
172     };
173     return ivjMinLabel;
174 }
175 /**
176  * Called whenever the part throws an exception.
177  * @param exception java.lang.Throwable
178  */

179 private void handleException(Throwable JavaDoc exception) {
180
181     /* Uncomment the following lines to print uncaught exceptions to stdout */
182     // System.out.println("--------- UNCAUGHT EXCEPTION ---------");
183
// exception.printStackTrace(System.out);
184
}
185 public void init(int _min, int _avg, int _max, java.awt.Color JavaDoc _color1, java.awt.Color JavaDoc _color2, boolean _useAvg, boolean _isVariable) {
186     min = _min;
187     avg = _avg;
188     max = _max;
189     useAvg = _useAvg;
190     getFillLevelCanvas().init(min, avg, max, _color1, _color2, useAvg);
191     isVariable = _isVariable;
192     if (useAvg) {
193         getAvgLabel().setText(""+_avg);
194         getAvgLabel().setLocation(23, getFillLevelCanvas().getYAvg()+6);
195     }
196     getMaxLabel().setText(""+_max);
197     getMinLabel().setText(""+_min);
198     getCurLabel().setText(""+_min);
199 }
200 /**
201  * Initialize the class.
202  */

203 /* WARNING: THIS METHOD WILL BE REGENERATED. */
204 private void initialize() {
205     // user code begin {1}
206
// user code end
207
setName("FillLevelBar");
208     setLayout(null);
209     setBackground(java.awt.SystemColor.control);
210     setSize(50, 130);
211     add(getCurLabel(), getCurLabel().getName());
212     add(getMinLabel(), getMinLabel().getName());
213     add(getMaxLabel(), getMaxLabel().getName());
214     add(getAvgLabel(), getAvgLabel().getName());
215     add(getFillLevelCanvas(), getFillLevelCanvas().getName());
216     // user code begin {2}
217
// user code end
218
}
219 /**
220  * main entrypoint - starts the part when it is run as an application
221  * @param args java.lang.String[]
222  */

223 public static void main(java.lang.String JavaDoc[] args) {
224     try {
225         java.awt.Frame JavaDoc frame;
226         try {
227             Class JavaDoc aFrameClass = Class.forName("com.ibm.uvm.abt.edit.TestFrame");
228             frame = (java.awt.Frame JavaDoc)aFrameClass.newInstance();
229         } catch (java.lang.Throwable JavaDoc ivjExc) {
230             frame = new java.awt.Frame JavaDoc();
231         }
232         FillLevelBar aFillLevelBar;
233         aFillLevelBar = new FillLevelBar();
234         frame.add("Center", aFillLevelBar);
235         frame.setSize(aFillLevelBar.getSize());
236         frame.setVisible(true);
237     } catch (Throwable JavaDoc exception) {
238         System.err.println("Exception occurred in main() of java.awt.Panel");
239         exception.printStackTrace(System.out);
240     }
241 }
242 private int maxCompute(int current) {
243     
244     int tenPerCent = max/10;
245     
246     if (current < tenPerCent) {
247             
248         while (max > current*2 && max > 10) {
249             max = max/2 > 10 ? max/2 : 10;
250         }
251         
252     } else if (current > max-tenPerCent) {
253     
254         while (max < current+tenPerCent) {
255             max = max*2;
256         }
257     }
258     return max;
259 }
260 public void paint(java.awt.Graphics JavaDoc g) {
261     g.setColor(getBackground());
262     g.fill3DRect(3, 8, 19, 104, false);
263 }
264 public void setAvgValue(int value) {
265     if (avg == value) return;
266     avg = value;
267     if (useAvg) {
268         getFillLevelCanvas().setAvg(avg);
269         getAvgLabel().setLocation(23, getFillLevelCanvas().getYAvg()+6);
270         getAvgLabel().setText(""+avg);
271     }
272 }
273 public void setCurrentValue(int value) {
274     if (cur == value) return;
275     cur = value;
276     if (isVariable) {
277         if (max != maxCompute(cur)) {
278             getFillLevelCanvas().setMax(max);
279             getMaxLabel().setText(""+max);
280         }
281     }
282     getFillLevelCanvas().setCurrent(cur > min ? cur-min : 0);
283     getCurLabel().setText(""+cur);
284 }
285 public void setMaxValue(int value) {
286     if (max == value) return;
287     max = value;
288     getFillLevelCanvas().setMax(max);
289     if (useAvg) {
290         getAvgLabel().setLocation(23, getFillLevelCanvas().getYAvg()+6);
291     }
292     getMaxLabel().setText(""+max);
293 }
294 public void setMinValue(int value) {
295     if (min == value) return;
296     min = value;
297     getFillLevelCanvas().setMin(min);
298     if (useAvg) {
299         getAvgLabel().setLocation(23, getFillLevelCanvas().getYAvg()+6);
300     }
301     getFillLevelCanvas().setCurrent(cur > min ? cur-min : 0);
302     getMinLabel().setText(""+min);
303 }
304
305 }
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
Popular Tags