Mercurial > hg > jslab
view src/samer/core_/util/swing/Meter.java @ 8:5e3cbbf173aa tip
Reorganise some more
author | samer |
---|---|
date | Fri, 05 Apr 2019 22:41:58 +0100 |
parents | bf79fb79ee13 |
children |
line wrap: on
line source
/* * 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); } }