samer@0
|
1 /*
|
samer@0
|
2 * Copyright (c) 2000, Samer Abdallah, King's College London.
|
samer@0
|
3 * All rights reserved.
|
samer@0
|
4 *
|
samer@0
|
5 * This software is provided AS iS and WITHOUT ANY WARRANTY;
|
samer@0
|
6 * without even the implied warranty of MERCHANTABILITY or
|
samer@0
|
7 * FITNESS FOR A PARTICULAR PURPOSE.
|
samer@0
|
8 */
|
samer@0
|
9
|
samer@0
|
10 package samer.core.util.heavy;
|
samer@0
|
11 import samer.core.util.*;
|
samer@0
|
12 import samer.core.*;
|
samer@0
|
13 import java.awt.*;
|
samer@0
|
14 import java.util.*;
|
samer@0
|
15
|
samer@0
|
16 public class Meter extends VCanvas
|
samer@0
|
17 {
|
samer@0
|
18 IMap map;
|
samer@0
|
19 int lasti, nexti;
|
samer@0
|
20 double x=0;
|
samer@0
|
21
|
samer@0
|
22 public Meter() { map = new LinearMap(0,1); lasti=0; }
|
samer@0
|
23
|
samer@0
|
24 public void exposeMap() { exposeMap(true); }
|
samer@0
|
25 public void exposeMap(boolean reinit) {
|
samer@0
|
26 final VMap vmap=new VMap(map,reinit);
|
samer@0
|
27 vmap.addObserver( new Observer() {
|
samer@0
|
28 public void update(Observable o, Object args) {
|
samer@0
|
29 if (args==VMap.NEW_MAP) setMap(vmap.getMap());
|
samer@0
|
30 nexti=map.toInt(x); repaint();
|
samer@0
|
31 }
|
samer@0
|
32 } );
|
samer@0
|
33 vmap.changed();
|
samer@0
|
34 exposeCommands(vmap);
|
samer@0
|
35 }
|
samer@0
|
36
|
samer@0
|
37 public void paint(Graphics g)
|
samer@0
|
38 {
|
samer@0
|
39 lasti=nexti=map.toInt(x);
|
samer@0
|
40 g.setColor(getBackground());
|
samer@0
|
41 g.fillRect(lasti,0,width-lasti,height);
|
samer@0
|
42 g.setColor(getForeground());
|
samer@0
|
43 g.fillRect(0,0,lasti,height);
|
samer@0
|
44 }
|
samer@0
|
45
|
samer@0
|
46 public void update(Graphics g)
|
samer@0
|
47 {
|
samer@0
|
48 if (nexti>lasti) {
|
samer@0
|
49 g.setColor(getForeground());
|
samer@0
|
50 g.fillRect(lasti,0,nexti-lasti,height);
|
samer@0
|
51 } else if (nexti<lasti) {
|
samer@0
|
52 g.setColor(getBackground());
|
samer@0
|
53 g.fillRect(nexti,0,lasti-nexti,height);
|
samer@0
|
54 }
|
samer@0
|
55 lasti=nexti;
|
samer@0
|
56 }
|
samer@0
|
57
|
samer@0
|
58 protected void realized() {}
|
samer@0
|
59 public void next( double x) {
|
samer@0
|
60 nexti=map.toInt(x); this.x=x;
|
samer@0
|
61 if (nexti!=lasti) repaint();
|
samer@0
|
62 }
|
samer@0
|
63
|
samer@0
|
64 public Dimension getPreferredSize() { return new Dimension(96,6); }
|
samer@0
|
65 public Dimension getMinimumSize() { return new Dimension(32,4); }
|
samer@0
|
66
|
samer@0
|
67 public IMap getMap() { return map; }
|
samer@0
|
68 public void setMap(IMap m) { map=m; lasti=0; repaint(); }
|
samer@0
|
69 protected void sized() { map.setIntRange(width); }
|
samer@0
|
70 }
|