package phw.onto.java;
import java.awt.*;
import java.util.*;
public class MeterCanvas extends Canvas { // Observer removed
 String title = "Title to be Supplied";
 int minValue = 0, maxValue = 30, value = 15;
 // Set the title:
 public void setTitle(String s) {title = s; repaint();}      
 // Set the current value:
 public void setValue(int v) {value = v; repaint();}
 // attachObservable removed
 // update removed
 public void paint(Graphics g) {
  // Obtain Dimension instance and draw:
  Dimension d = getSize(); 
  int meterWidth = d.width * 3 / 4;
  int dialPosition = meterWidth * (value - minValue)
                     / (maxValue - minValue);
  int xOrigin = (d.width - meterWidth) / 2; 
  int yOrigin = d.height / 2;
  g.drawLine(xOrigin, yOrigin, xOrigin + meterWidth, yOrigin);
  g.drawLine(xOrigin + dialPosition, yOrigin,
             xOrigin + dialPosition, yOrigin - 10);
  // Write title:
  g.setFont(new Font("Helvetica", Font.BOLD, 12));
  FontMetrics f = g.getFontMetrics();
  int stringWidth = f.stringWidth(title);
  int stringHeight = f.getHeight();
  xOrigin = (d.width - stringWidth) / 2; 
  yOrigin = (d.height / 2) + stringHeight * 2;                           
  g.drawString(title, xOrigin, yOrigin);
 }
 public Dimension getMinimumSize() {return new Dimension(150, 100);}
 public Dimension getPreferredSize() {return new Dimension(150, 100);}
}
