samer@0: /* samer@0: * Copyright (c) 2000, Samer Abdallah, King's College London. samer@0: * All rights reserved. samer@0: * samer@0: * This software is provided AS iS and WITHOUT ANY WARRANTY; samer@0: * without even the implied warranty of MERCHANTABILITY or samer@0: * FITNESS FOR A PARTICULAR PURPOSE. samer@0: */ samer@0: samer@0: package samer.core.util.heavy; samer@0: import samer.core.util.*; samer@0: import samer.core.*; samer@0: import java.awt.*; samer@0: import java.util.*; samer@0: samer@0: public class Meter extends VCanvas samer@0: { samer@0: IMap map; samer@0: int lasti, nexti; samer@0: double x=0; samer@0: samer@0: public Meter() { map = new LinearMap(0,1); lasti=0; } samer@0: samer@0: public void exposeMap() { exposeMap(true); } samer@0: public void exposeMap(boolean reinit) { samer@0: final VMap vmap=new VMap(map,reinit); samer@0: vmap.addObserver( new Observer() { samer@0: public void update(Observable o, Object args) { samer@0: if (args==VMap.NEW_MAP) setMap(vmap.getMap()); samer@0: nexti=map.toInt(x); repaint(); samer@0: } samer@0: } ); samer@0: vmap.changed(); samer@0: exposeCommands(vmap); samer@0: } samer@0: samer@0: public void paint(Graphics g) samer@0: { samer@0: lasti=nexti=map.toInt(x); samer@0: g.setColor(getBackground()); samer@0: g.fillRect(lasti,0,width-lasti,height); samer@0: g.setColor(getForeground()); samer@0: g.fillRect(0,0,lasti,height); samer@0: } samer@0: samer@0: public void update(Graphics g) samer@0: { samer@0: if (nexti>lasti) { samer@0: g.setColor(getForeground()); samer@0: g.fillRect(lasti,0,nexti-lasti,height); samer@0: } else if (nexti