1 package org.jacorb.poa.gui.beans; 2 3 22 23 30 public class FillLevelBar extends java.awt.Panel { 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 ivjAvgLabel = null; 38 private java.awt.Label ivjCurLabel = null; 39 private java.awt.Label ivjMaxLabel = null; 40 private java.awt.Label ivjMinLabel = null; 41 private FillLevelCanvas ivjFillLevelCanvas = null; 42 45 46 public FillLevelBar() { 47 super(); 48 initialize(); 49 } 50 54 public FillLevelBar(java.awt.LayoutManager layout) { 55 super(layout); 56 } 57 61 62 private java.awt.Label getAvgLabel() { 63 if (ivjAvgLabel == null) { 64 try { 65 ivjAvgLabel = new java.awt.Label (); 66 ivjAvgLabel.setName("AvgLabel"); 67 ivjAvgLabel.setText(""); 68 ivjAvgLabel.setBackground(java.awt.SystemColor.control); 69 ivjAvgLabel.setFont(new java.awt.Font ("dialog", 0, 10)); 70 ivjAvgLabel.setBounds(23, 54, 25, 10); 71 } catch (java.lang.Throwable ivjExc) { 74 handleException(ivjExc); 77 } 78 }; 79 return ivjAvgLabel; 80 } 81 85 86 private java.awt.Label getCurLabel() { 87 if (ivjCurLabel == null) { 88 try { 89 ivjCurLabel = new java.awt.Label (); 90 ivjCurLabel.setName("CurLabel"); 91 ivjCurLabel.setText(""); 92 ivjCurLabel.setBackground(java.awt.SystemColor.control); 93 ivjCurLabel.setFont(new java.awt.Font ("dialog", 0, 10)); 94 ivjCurLabel.setAlignment(1); 95 ivjCurLabel.setBounds(0, 115, 25, 12); 96 } catch (java.lang.Throwable ivjExc) { 99 handleException(ivjExc); 102 } 103 }; 104 return ivjCurLabel; 105 } 106 110 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 } catch (java.lang.Throwable ivjExc) { 120 handleException(ivjExc); 123 } 124 }; 125 return ivjFillLevelCanvas; 126 } 127 131 132 private java.awt.Label getMaxLabel() { 133 if (ivjMaxLabel == null) { 134 try { 135 ivjMaxLabel = new java.awt.Label (); 136 ivjMaxLabel.setName("MaxLabel"); 137 ivjMaxLabel.setText(""); 138 ivjMaxLabel.setBackground(java.awt.SystemColor.control); 139 ivjMaxLabel.setFont(new java.awt.Font ("dialog", 0, 10)); 140 ivjMaxLabel.setBounds(23, 7, 25, 10); 141 } catch (java.lang.Throwable ivjExc) { 144 handleException(ivjExc); 147 } 148 }; 149 return ivjMaxLabel; 150 } 151 155 156 private java.awt.Label getMinLabel() { 157 if (ivjMinLabel == null) { 158 try { 159 ivjMinLabel = new java.awt.Label (); 160 ivjMinLabel.setName("MinLabel"); 161 ivjMinLabel.setText(""); 162 ivjMinLabel.setBackground(java.awt.SystemColor.control); 163 ivjMinLabel.setFont(new java.awt.Font ("dialog", 0, 10)); 164 ivjMinLabel.setBounds(23, 104, 25, 10); 165 } catch (java.lang.Throwable ivjExc) { 168 handleException(ivjExc); 171 } 172 }; 173 return ivjMinLabel; 174 } 175 179 private void handleException(Throwable exception) { 180 181 182 } 185 public void init(int _min, int _avg, int _max, java.awt.Color _color1, java.awt.Color _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 203 204 private void initialize() { 205 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 } 219 223 public static void main(java.lang.String [] args) { 224 try { 225 java.awt.Frame frame; 226 try { 227 Class aFrameClass = Class.forName("com.ibm.uvm.abt.edit.TestFrame"); 228 frame = (java.awt.Frame )aFrameClass.newInstance(); 229 } catch (java.lang.Throwable ivjExc) { 230 frame = new java.awt.Frame (); 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 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 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 |