comparison src/samer/core_/util/swing/Meter.java @ 0:bf79fb79ee13

Initial Mercurial check in.
author samer
date Tue, 17 Jan 2012 17:50:20 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:bf79fb79ee13
1 /*
2 * Copyright (c) 2000, Samer Abdallah, King's College London.
3 * All rights reserved.
4 *
5 * This software is provided AS iS and WITHOUT ANY WARRANTY;
6 * without even the implied warranty of MERCHANTABILITY or
7 * FITNESS FOR A PARTICULAR PURPOSE.
8 */
9
10 package samer.core.util.swing;
11 import samer.core.util.*;
12 import samer.core.*;
13 import java.awt.*;
14 import java.util.*;
15 import javax.swing.BorderFactory;
16
17 public class Meter extends VCanvas
18 {
19 IMap map;
20 int lasti, nexti;
21 double x;
22
23 public Meter() { map = new LinearMap(0,1); lasti=0; }
24
25 public void exposeMap() { exposeMap(true); }
26 public void exposeMap(boolean reinit) {
27 final VMap vmap=new VMap(map,reinit);
28 vmap.addObserver( new Observer() {
29 public void update(Observable o, Object args) {
30 if (args==VMap.NEW_MAP) setMap(vmap.getMap());
31 nexti=map.toInt(x); repaint();
32 }
33 } );
34 vmap.changed();
35 exposeCommands(vmap);
36 }
37
38 public void realized() {
39 setBorder(BorderFactory.createLineBorder(getForeground().darker().darker()));
40 }
41
42 protected void paintComponent(Graphics g) {
43 lasti=nexti;
44 g.setColor(getBackground());
45 g.fillRect(lasti,0,width-lasti,height);
46 g.setColor(getForeground());
47 g.fillRect(0,0,lasti,height);
48 }
49
50 public void next( double x) {
51 nexti=map.toInt(x); this.x=x;
52 if (nexti!=lasti) repaint();
53 }
54
55 public Dimension getPreferredSize() { return new Dimension(96,6); }
56 public Dimension getMinimumSize() { return new Dimension(32,4); }
57
58 public IMap getMap() { return map; }
59 public void setMap(IMap m) { map=m; lasti=0; repaint(); }
60 protected void sized() { map.setIntRange(width); }
61 }