001 package ui.recognizer; 002 003 import java.awt.*; 004 import javax.swing.*; 005 006 public class Rule extends JComponent { 007 008 public static final int INCH = Toolkit.getDefaultToolkit().getScreenResolution(); 009 010 protected Calibration calibration; 011 protected boolean dataUnits; 012 013 protected int increment; 014 protected int units; 015 016 public Rule(boolean isDataUnits, Calibration aCalibration) { 017 calibration = aCalibration; 018 dataUnits = isDataUnits; 019 setIncrementAndUnits(); 020 } 021 022 void setIncrementAndUnits() { 023 if (isDataUnits()) { 024 units = (int)((double)INCH / (double)2.54); // dots per centimeter 025 increment = units; 026 } else { 027 units = INCH; 028 increment = units / 2; 029 } 030 } 031 032 public int getIncrement() { 033 return increment; 034 } 035 036 //----------------Accessor methods--------------------------- 037 038 /** Get the coordinate display mode. 039 * @return true if tics are in data units 040 */ 041 public boolean isDataUnits() { 042 return dataUnits; 043 } 044 045 /** Set the coordinate display mode. 046 * @param isDataUnits if true tics are in data units 047 */ 048 public void setDataUnits(boolean isDataUnits) { 049 dataUnits = isDataUnits; 050 setIncrementAndUnits(); 051 repaint(); 052 } 053 054 /** Get the calibation object for this plot. 055 * @return an object representing the plot calibration 056 */ 057 public Calibration getCalibration() { 058 return calibration; 059 } 060 061 /** Set the coordinate calibration object. 062 * @param aCalibration an object representing the plot calibration 063 */ 064 public void setCalibration(Calibration aCalibration) { 065 calibration = aCalibration; 066 setIncrementAndUnits(); 067 repaint(); 068 } 069 070 }