001    package ui.recognizer;
002    
003    
004    /** A class which can represent a data coordinate : an object containing an absissa (x) and ordinate (y) value
005     * and which can be printed and ordered appropriately.
006     * The units are in double precision because the data can represent any real number when calibrated.
007     * When sorted, data coordinates are ordered by their x coordinate.
008     * This class is compatible with <code>java.awt.Point2D</code>.
009     *
010     * @author John Talbot
011     */
012    public class DataCoordinate extends java.awt.geom.Point2D.Double implements Comparable {
013    
014        public DataCoordinate(DataCoordinate data) {
015            super(data.getX(), data.getY());
016        }
017    
018        public DataCoordinate(double aX, double aY) {
019            super(aX, aY);
020        }
021    
022        public void setLocation(double aX, double aY) {
023            setX(aX);
024            setY(aY);
025        }
026    
027        public void setX(double aX) {
028            x = aX;
029        };
030    
031        public void setY(double aY) {
032            y = aY;
033        };
034    
035        /** Scale a coordinate using a calibration object. Note : this data coordinate is modified.
036         */
037        public DataCoordinate scale(Calibration aCalibration) {
038            setX(getX() * aCalibration.getUnitX());
039            setY(getY() * aCalibration.getUnitY());
040            return this;
041        }
042    
043        /** This method from Object is overidden to provide a standard way to print [x,y] coordinates.
044         */
045        public String toString() {
046            return getX() + " " + getY();
047        }
048    
049        /** Implementation of Comparable so that when sorted, data coordinates are ordered by their x coordinate.
050         */
051        public int compareTo(Object aDataCoordinate) {
052            if (aDataCoordinate != null && aDataCoordinate instanceof DataCoordinate) {
053                DataCoordinate data = (DataCoordinate) aDataCoordinate;
054                java.lang.Double x1 = new java.lang.Double(getX());
055                java.lang.Double x2 = new java.lang.Double(data.getX());
056                return x1.compareTo(x2);
057            } else {
058                return 1;
059            }
060        }
061    }