01: /*
02: * argun 1.0
03: * Web 2.0 delivery framework
04: * Copyright (C) 2007 Hammurapi Group
05: *
06: * This program is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation; either
09: * version 2 of the License, or (at your option) any later version.
10: *
11: * This program is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: *
16: * You should have received a copy of the GNU Lesser General Public
17: * License along with this library; if not, write to the Free Software
18: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19: *
20: * URL: http://www.hammurapi.biz
21: * e-Mail: support@hammurapi.biz
22: */
23: package biz.hammurapi.web.util;
24:
25: import java.awt.geom.Point2D;
26: import java.awt.geom.Point2D.Double;
27:
28: /**
29: * Helper class to order transitions.
30: * @author Pavel Vlasov
31: */
32: public class ComparablePoint extends Double implements Comparable {
33:
34: private Object userObject;
35: private double tolerance;
36: private boolean isVertical;
37:
38: public ComparablePoint(Point2D source, Object userObject,
39: double tolerance, boolean isVertical) {
40: this (source.getX(), source.getY(), userObject, tolerance,
41: isVertical);
42: }
43:
44: public ComparablePoint(double x, double y, Object userObject,
45: double tolerance, boolean isVertical) {
46: super (x, y);
47: this .userObject = userObject;
48: if (tolerance < 0) {
49: throw new IllegalArgumentException(
50: "Tolerance cannot be negative");
51: }
52: this .tolerance = tolerance;
53: this .isVertical = isVertical;
54: }
55:
56: public Object getUserObject() {
57: return userObject;
58: }
59:
60: public int compareTo(Object o) {
61: if (o instanceof Double) {
62: double firstCoordinateDiff = isVertical ? getX()
63: - ((Double) o).getX() : getY()
64: - ((Double) o).getY();
65:
66: if (Math.abs(firstCoordinateDiff) > tolerance) {
67: return firstCoordinateDiff < 0 ? -1 : 1;
68: }
69:
70: double secondCoordinateDiff = isVertical ? getY()
71: - ((Double) o).getY() : getX()
72: - ((Double) o).getX();
73: if (secondCoordinateDiff < 0) {
74: return -1;
75: }
76:
77: if (secondCoordinateDiff > 0) {
78: return 1;
79: }
80: }
81:
82: return hashCode() - o.hashCode();
83: }
84: }
|