-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathHoverData.java
More file actions
191 lines (164 loc) · 4.39 KB
/
HoverData.java
File metadata and controls
191 lines (164 loc) · 4.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
package PamView;
import java.awt.Shape;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import PamUtils.Coordinate3d;
import PamguardMVC.PamDataUnit;
/**
* Holds hover data. Added to a list in a GeneralProjector every time a display
* is drawn. Was initially used to quickly obtain hover information on the
* map display but is now also being used to identify data units enclosed
* within marks made on the display with the OverlayMark system.
*
* @author Jamie Macaulay
*
*/
public class HoverData {
public HoverData() {
super();
}
public HoverData(Shape drawnShape, PamDataUnit pamDataUnit, int iSide, int subPlotNumber) {
super();
this.drawnShape = drawnShape;
this.pamDataUnit = pamDataUnit;
this.iSide = iSide;
this.subPlotNumber = subPlotNumber;
}
public HoverData(Coordinate3d c, PamDataUnit pamDataUnit, int iSide, int subPlotNumber) {
this.setCoordinate3D(c);
this.pamDataUnit = pamDataUnit;
this.iSide = iSide;
this.subPlotNumber = subPlotNumber;
}
/**
* The position of the hover text (null if a shape instead)
*/
// Coordinate3d coordinate3d;
private Shape drawnShape;
/**
* The shape in which the hover text is located (null if a coordinate instead).
*/
private TransformShape transformShape;
/**
* Pam data unit associated with hover text
*/
private PamDataUnit pamDataUnit;
/**
* The ambiguity.
*/
private int iSide;
/**
* Subplot number (used in general time displays and needed
* to reidentify marked / hover data. )
*/
private int subPlotNumber = -1;
/**
* Get the data unit associated with the hover data.
* @return a pma data unit.
*/
public PamDataUnit getDataUnit() {
return pamDataUnit;
}
public void setTransformShape(TransformShape shape2) {
this.transformShape=shape2;
}
public void setAmbiguity(int iSide) {
this.iSide=iSide;
}
public void setDataUnit(PamDataUnit pamDataUnit) {
this.pamDataUnit=pamDataUnit;
}
/**
* Get the drawn shape
* @return drawn shape
*/
public Shape getDrawnShape() {
return drawnShape;
}
/**
* Set the drawn shape
* @param drawnShape
*/
public void setDrawnShape(Shape drawnShape) {
this.drawnShape = drawnShape;
}
public double distFromCentre(double x, double y) {
if (drawnShape == null) {
return Double.NaN;
}
if (drawnShape.contains(x, y)) {
// return the distance from the shapes centre ?
return 0;
}
// otherwise the distance from the center.
Rectangle2D bounds = drawnShape.getBounds2D();
double xc = bounds.getCenterX();
double yc = bounds.getCenterY();
return (Math.sqrt(Math.pow(x-xc, 2)+Math.pow(y-yc, 2)));
}
/**
* Get the centre of the drawn shape. This is actually
* the centre of the bounding rectangle, which may be different to
* any concept of a geometric centre for some shapes.
* @return shape centre.
*/
public Point2D getShapeCentre() {
if (drawnShape == null) {
return null;
}
Rectangle2D bounds = drawnShape.getBounds2D();
return new Point2D.Double(bounds.getCenterX(), bounds.getCenterY());
}
// /**
// * @return the coordinate3d
// */
// public Coordinate3d getCoordinate3d() {
// return coordinate3d;
// }
//
public void setCoordinate3D(Coordinate3d coordinate3d) {
// this.coordinate3d=coordinate3d;
// create a zero sized rectangle.
drawnShape = new Rectangle2D.Double(coordinate3d.x, coordinate3d.y, 0, 0);
}
/**
* Get the ambiguity of the hover data i.e. one data unit may have multiple
* shapes/co-ordinates e.g. localisations on the map
* @return the ambiguity (previously refferred to as iSide)
*/
public int getAmbiguity() {
return iSide;
}
/**
* Get the shape in whihc hover text is located. May be null if CoOrdintate3d used instead.
* @return the hover shape. Hover text is allowed inside the shape boundary.
*/
public TransformShape getTransfromShape() {
return transformShape;
}
/**
* @return the subPlotNumber
*/
public int getSubPlotNumber() {
return subPlotNumber;
}
/**
* @param subPlotNumber the subPlotNumber to set
*/
public void setSubPlotNumber(int subPlotNumber) {
this.subPlotNumber = subPlotNumber;
}
/**
* Get a point for the item.
* @return a Point marking the center of this drawn object.
*/
// public Point2D getPoint2D() {
// if (coordinate3d != null) {
// return coordinate3d.getPoint2D();
// }
// if (shape != null) {
// return shape.getOrigin();
// }
// return null;
// }
}