KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > chart > renderer > Outlier


1 /* ===========================================================
2  * JFreeChart : a free chart library for the Java(tm) platform
3  * ===========================================================
4  *
5  * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
6  *
7  * Project Info: http://www.jfree.org/jfreechart/index.html
8  *
9  * This library is free software; you can redistribute it and/or modify it
10  * under the terms of the GNU Lesser General Public License as published by
11  * the Free Software Foundation; either version 2.1 of the License, or
12  * (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17  * License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public License
20  * along with this library; if not, write to the Free Software Foundation,
21  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
22  *
23  * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
24  * in the United States and other countries.]
25  *
26  * ------------
27  * Outlier.java
28  * ------------
29  * (C) Copyright 2003-2005, by David Browning and Contributors.
30  *
31  * Original Author: David Browning (for Australian Institute of Marine
32  * Science);
33  * Contributor(s): David Gilbert (for Object Refinery Limited);
34  *
35  * $Id: Outlier.java,v 1.4 2005/05/03 10:09:01 mungady Exp $
36  *
37  * Changes
38  * -------
39  * 05-Aug-2003 : Version 1, contributed by David Browning (DG);
40  * 28-Aug-2003 : Minor tidy-up (DG);
41  *
42  */

43
44 package org.jfree.chart.renderer;
45
46 import java.awt.geom.Point2D JavaDoc;
47
48 /**
49  * Represents one outlier in the box and whisker plot.
50  * <P>
51  * All the coordinates in this class are in Java2D space.
52  *
53  * @author David Browning
54  */

55 public class Outlier implements Comparable JavaDoc {
56
57     /**
58      * The xy coordinates of the bounding box containing the outlier ellipse.
59      */

60     private Point2D JavaDoc point;
61
62     /** The radius of the ellipse */
63     private double radius;
64
65     /**
66      * Constructs an outlier item consisting of a point and the radius of the
67      * outlier ellipse
68      *
69      * @param xCoord the x coordinate of the point.
70      * @param yCoord the y coordinate of the point.
71      * @param radius the radius of the ellipse.
72      */

73     public Outlier(double xCoord, double yCoord, double radius) {
74         this.point = new Point2D.Double JavaDoc(xCoord - radius, yCoord - radius);
75         this.radius = radius;
76     }
77
78     /**
79      * Returns the xy coordinates of the bounding box containing the outlier
80      * ellipse.
81      *
82      * @return The location of the outlier ellipse.
83      */

84     public Point2D JavaDoc getPoint() {
85         return this.point;
86     }
87
88     /**
89      * Sets the xy coordinates of the bounding box containing the outlier
90      * ellipse.
91      *
92      * @param point the location.
93      */

94     public void setPoint(Point2D JavaDoc point) {
95         this.point = point;
96     }
97
98     /**
99      * Returns the x coordinate of the bounding box containing the outlier
100      * ellipse.
101      *
102      * @return The x coordinate.
103      */

104     public double getX() {
105         return getPoint().getX();
106     }
107
108     /**
109      * Returns the y coordinate of the bounding box containing the outlier
110      * ellipse.
111      *
112      * @return The y coordinate.
113      */

114     public double getY() {
115         return getPoint().getY();
116     }
117
118     /**
119      * Returns the radius of the outlier ellipse.
120      *
121      * @return The radius.
122      */

123     public double getRadius() {
124         return this.radius;
125     }
126
127     /**
128      * Sets the radius of the outlier ellipse.
129      *
130      * @param radius the new radius.
131      */

132     public void setRadius(double radius) {
133         this.radius = radius;
134     }
135
136     /**
137      * Compares this object with the specified object for order, based on
138      * the outlier's point.
139      *
140      * @param o the Object to be compared.
141      * @return A negative integer, zero, or a positive integer as this object
142      * is less than, equal to, or greater than the specified object.
143      *
144      */

145     public int compareTo(Object JavaDoc o) {
146         Outlier outlier = (Outlier) o;
147         Point2D JavaDoc p1 = getPoint();
148         Point2D JavaDoc p2 = outlier.getPoint();
149         if (p1.equals(p2)) {
150             return 0;
151         }
152         else if ((p1.getX() < p2.getX()) || (p1.getY() < p2.getY())) {
153             return -1;
154         }
155         else {
156             return 1;
157         }
158     }
159
160     /**
161      * Returns a true if outlier is overlapped and false if it is not.
162      * Overlapping is determined by the respective bounding boxes plus
163      * a small margin.
164      *
165      * @param other the other outlier.
166      *
167      * @return A <code>boolean</code> indicating whether or not an overlap has
168      * occurred.
169      */

170     public boolean overlaps(Outlier other) {
171         return ((other.getX() >= getX() - (this.radius * 1.1))
172                 && (other.getX() <= getX() + (this.radius * 1.1))
173                 && (other.getY() >= getY() - (this.radius * 1.1))
174                 && (other.getY() <= getY() + (this.radius * 1.1)));
175     }
176
177     /**
178      * Returns a textual representation of the outlier.
179      *
180      * @return A <code>String</code> representing the outlier.
181      */

182     public String JavaDoc toString() {
183         return "{" + getX() + "," + getY() + "}";
184     }
185
186 }
187
Popular Tags