diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/samer/core_/util/swing/Meter.java	Tue Jan 17 17:50:20 2012 +0000
@@ -0,0 +1,61 @@
+/*
+ *	Copyright (c) 2000, Samer Abdallah, King's College London.
+ *	All rights reserved.
+ *
+ *	This software is provided AS iS and WITHOUT ANY WARRANTY; 
+ *	without even the implied warranty of MERCHANTABILITY or 
+ *	FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
+package samer.core.util.swing;
+import  samer.core.util.*;
+import  samer.core.*;
+import  java.awt.*;
+import  java.util.*;
+import javax.swing.BorderFactory;
+
+public class Meter extends VCanvas
+{
+	IMap	map;
+	int		lasti, nexti;
+	double	x;
+
+	public Meter() { map = new LinearMap(0,1); lasti=0; }
+
+	public void exposeMap() { exposeMap(true); }
+	public void exposeMap(boolean reinit) {
+		final VMap	vmap=new VMap(map,reinit);
+		vmap.addObserver( new Observer() {
+			public void update(Observable o, Object args) {
+				if (args==VMap.NEW_MAP) setMap(vmap.getMap());
+				nexti=map.toInt(x); repaint();
+			}
+		} );
+		vmap.changed();
+		exposeCommands(vmap);
+	}
+
+	public void realized() {
+		setBorder(BorderFactory.createLineBorder(getForeground().darker().darker()));
+	}
+
+	protected void paintComponent(Graphics g) {
+		lasti=nexti;
+		g.setColor(getBackground());
+		g.fillRect(lasti,0,width-lasti,height);
+		g.setColor(getForeground());
+		g.fillRect(0,0,lasti,height);
+	}
+
+	public void next( double x) { 
+		nexti=map.toInt(x); this.x=x;
+		if (nexti!=lasti) repaint();
+	}
+
+	public Dimension getPreferredSize() { return new Dimension(96,6); }
+	public Dimension getMinimumSize() { return new Dimension(32,4); }
+
+	public IMap getMap() { return map; }
+	public void setMap(IMap m) { map=m; lasti=0; repaint(); }
+	protected void sized() { map.setIntRange(width); }
+}