001 package ui.recognizer;
002
003 import java.awt.*;
004 import javax.swing.*;
005
006 public class YRule extends Rule {
007 public static final int SIZE = 35;
008
009 public YRule(boolean isDataUnits, Calibration aCalibration) {
010 super(isDataUnits, aCalibration);
011 }
012
013 public void setPreferredHeight(int ph) {
014 setPreferredSize(new Dimension(SIZE, ph));
015 }
016
017 public void paintComponent(Graphics g) {
018 Graphics2D g2 = (Graphics2D) g;
019 Rectangle drawHere = g2.getClipBounds();
020
021 // Fill clipping area with dirty brown/orange.
022 //g2.setColor(new Color(230, 163, 4));
023 //g2.fillRect(drawHere.x, drawHere.y, drawHere.width, drawHere.height);
024
025 //TODO: Fill with gray gradient paint depending on calibration bounds.
026
027 Point p1 = new Point(drawHere.x, drawHere.y);
028 Color c1 = new Color(1.0f, 1.0f, 1.0f);
029 Point p2 = new Point(drawHere.x, drawHere.y + drawHere.height);
030 Color c2 = new Color(0.0f, 0.0f, 0.0f);
031 g2.setPaint(new GradientPaint(p1, c1, p2, c2));
032 g2.fillRect(drawHere.x, drawHere.y, drawHere.width, drawHere.height);
033
034 // Do the ruler labels in a small font that's black.
035 g2.setFont(new Font("SansSerif", Font.PLAIN, 10));
036 g2.setColor(Color.black);
037
038 // Some vars we need.
039
040 // Use clipping bounds to calculate first tick and last tick location.
041
042 int start = (drawHere.y / increment) * increment;
043 int end = (((drawHere.y + drawHere.height) / increment) + 1) * increment;
044
045 // ticks and labels
046 int tickLength = 0;
047 String text = null;
048 for (int i = start; i < end; i += increment) {
049 if (i % units == 0) {
050 tickLength = 10;
051 text = Integer.toString(i/units);
052 } else {
053 tickLength = 7;
054 text = null;
055 }
056 if (tickLength != 0) {
057 g.drawLine(SIZE-1, i, SIZE-tickLength-1, i);
058 if (text != null)
059 g.drawString(text, 9, i+3);
060 }
061 }
062 }
063 }