1
+ /*
2
+ * Copyright (C) 2016 United States Government as represented by the Administrator of the
3
+ * National Aeronautics and Space Administration.
4
+ * All Rights Reserved.
5
+ */
6
+
7
+ package gov .nasa .worldwind .drag ;
8
+
9
+ import gov .nasa .worldwind .*;
10
+ import gov .nasa .worldwind .avlist .AVKey ;
11
+ import gov .nasa .worldwind .globes .Globe ;
12
+ import gov .nasa .worldwind .util .Logging ;
13
+
14
+ import java .awt .*;
15
+
16
+ /**
17
+ * Provides information about mouse inputs and {@link WorldWindow} state for use in dragging operations.
18
+ */
19
+ public class DragContext
20
+ {
21
+ /**
22
+ * In accordance with the AWT screen coordinates the top left point of the window is the origin.
23
+ */
24
+ protected Point point ;
25
+ /**
26
+ * In accordance with the AWT screen coordinates the top left point of the window is the origin. This point is the
27
+ * previous screen point.
28
+ */
29
+ protected Point previousPoint ;
30
+ /**
31
+ * In accordance with the AWT screen coordinates the top left point of the window is the origin. This point refers
32
+ * to the initial point of the drag event.
33
+ */
34
+ protected Point initialPoint ;
35
+ /**
36
+ * The current {@link SceneController} of the {@link WorldWindow}.
37
+ */
38
+ protected SceneController sceneController ;
39
+ /**
40
+ * The current {@link Globe} of the {@link WorldWindow}.
41
+ */
42
+ protected Globe globe ;
43
+ /**
44
+ * The current{@link View} of the {@link WorldWindow}.
45
+ */
46
+ protected View view ;
47
+ /**
48
+ * The current drag state, which can be one of the three following values:
49
+ * {@link gov.nasa.worldwind.avlist.AVKey#DRAG_BEGIN}, {@link gov.nasa.worldwind.avlist.AVKey#DRAG_CHANGE},
50
+ * {@link gov.nasa.worldwind.avlist.AVKey#DRAG_ENDED}.
51
+ */
52
+ protected String dragState ;
53
+
54
+ /**
55
+ * Creates a new {@link DragContext} instance.
56
+ */
57
+ public DragContext ()
58
+ {
59
+ }
60
+
61
+ /**
62
+ * Returns the current screen point with the origin at the top left corner of the window.
63
+ *
64
+ * @return the current screen point.
65
+ */
66
+ public Point getPoint ()
67
+ {
68
+ return point ;
69
+ }
70
+
71
+ /**
72
+ * Set the {@link DragContext} current screen point.
73
+ *
74
+ * @param point the point to assign to the current screen point.
75
+ *
76
+ * @throws IllegalArgumentException if the point is null.
77
+ */
78
+ public void setPoint (Point point )
79
+ {
80
+ if (point == null )
81
+ {
82
+ String msg = Logging .getMessage ("nullValue.PointIsNull" );
83
+ Logging .logger ().severe (msg );
84
+ throw new IllegalArgumentException (msg );
85
+ }
86
+
87
+ this .point = point ;
88
+ }
89
+
90
+ /**
91
+ * Returns the previous screen point with the origin at the top left corner of the window.
92
+ *
93
+ * @return the previous point.
94
+ */
95
+ public Point getPreviousPoint ()
96
+ {
97
+ return previousPoint ;
98
+ }
99
+
100
+ /**
101
+ * Set the {@link DragContext} previous screen point.
102
+ *
103
+ * @param previousPoint the screen point to assign to the previous screen point.
104
+ *
105
+ * @throws IllegalArgumentException if the previousPoint is null.
106
+ */
107
+ public void setPreviousPoint (Point previousPoint )
108
+ {
109
+ if (point == null )
110
+ {
111
+ String msg = Logging .getMessage ("nullValue.PointIsNull" );
112
+ Logging .logger ().severe (msg );
113
+ throw new IllegalArgumentException (msg );
114
+ }
115
+
116
+ this .previousPoint = previousPoint ;
117
+ }
118
+
119
+ /**
120
+ * Returns the initial screen point with the origin at the top left corner of the window. The initial point is the
121
+ * screen point at the initiation of the drag event.
122
+ *
123
+ * @return the initial screen point.
124
+ */
125
+ public Point getInitialPoint ()
126
+ {
127
+ return initialPoint ;
128
+ }
129
+
130
+ /**
131
+ * Set the {@link DragContext} initial screen point.
132
+ *
133
+ * @param initialPoint the screen point to assign to the initial screen point.
134
+ *
135
+ * @throws IllegalArgumentException if the initialPoint is null.
136
+ */
137
+ public void setInitialPoint (Point initialPoint )
138
+ {
139
+ if (point == null )
140
+ {
141
+ String msg = Logging .getMessage ("nullValue.PointIsNull" );
142
+ Logging .logger ().severe (msg );
143
+ throw new IllegalArgumentException (msg );
144
+ }
145
+
146
+ this .initialPoint = initialPoint ;
147
+ }
148
+
149
+ /**
150
+ * Returns the current {@link SceneController} for this drag event.
151
+ *
152
+ * @return the current {@link SceneController}.
153
+ */
154
+ public SceneController getSceneController ()
155
+ {
156
+ return sceneController ;
157
+ }
158
+
159
+ /**
160
+ * Set the {@link DragContext} {@link SceneController}.
161
+ *
162
+ * @param sceneController the {@link SceneController} to assign to the {@link DragContext}.
163
+ *
164
+ * @throws IllegalArgumentException if the scene controller is null.
165
+ */
166
+ public void setSceneController (SceneController sceneController )
167
+ {
168
+ if (sceneController == null )
169
+ {
170
+ String msg = Logging .getMessage ("nullValue.SceneControllerIsNull" );
171
+ Logging .logger ().severe (msg );
172
+ throw new IllegalArgumentException (msg );
173
+ }
174
+
175
+ this .sceneController = sceneController ;
176
+ }
177
+
178
+ /**
179
+ * Returns the current {@link Globe} for this drag event.
180
+ *
181
+ * @return the current {@link Globe}.
182
+ */
183
+ public Globe getGlobe ()
184
+ {
185
+ return globe ;
186
+ }
187
+
188
+ /**
189
+ * Set the {@link DragContext} {@link Globe}.
190
+ *
191
+ * @param globe the {@link Globe} to assign to the {@link DragContext}.
192
+ *
193
+ * @throws IllegalArgumentException if the globe is null.
194
+ */
195
+ public void setGlobe (Globe globe )
196
+ {
197
+ if (globe == null )
198
+ {
199
+ String msg = Logging .getMessage ("nullValue.GlobeIsNull" );
200
+ Logging .logger ().severe (msg );
201
+ throw new IllegalArgumentException (msg );
202
+ }
203
+
204
+ this .globe = globe ;
205
+ }
206
+
207
+ /**
208
+ * Returns the current {@link View} for this drag event.
209
+ *
210
+ * @return the current {@link View}.
211
+ */
212
+ public View getView ()
213
+ {
214
+ return view ;
215
+ }
216
+
217
+ /**
218
+ * Set the {@link DragContext} {@link View}.
219
+ *
220
+ * @param view the {@link View} to assign to the {@link DragContext}.
221
+ *
222
+ * @throws IllegalArgumentException if the view is null.
223
+ */
224
+ public void setView (View view )
225
+ {
226
+ if (view == null )
227
+ {
228
+ String msg = Logging .getMessage ("nullValue.ViewIsNull" );
229
+ Logging .logger ().severe (msg );
230
+ throw new IllegalArgumentException (msg );
231
+ }
232
+
233
+ this .view = view ;
234
+ }
235
+
236
+ /**
237
+ * Returns the current drag state for this drag event.
238
+ *
239
+ * @return the drag state.
240
+ */
241
+ public String getDragState ()
242
+ {
243
+ return dragState ;
244
+ }
245
+
246
+ /**
247
+ * Set the {@link DragContext} drag state, which must be one of the following three states: {@link AVKey#DRAG_BEGIN}
248
+ * , {@link AVKey#DRAG_CHANGE}, or {@link AVKey#DRAG_ENDED}.
249
+ *
250
+ * @param dragState the drag state to assign to the {@link DragContext}.
251
+ *
252
+ * @throws IllegalArgumentException if the drag state is null or not one of the three states defined for dragging.
253
+ */
254
+ public void setDragState (String dragState )
255
+ {
256
+ if (dragState == null )
257
+ {
258
+ String msg = Logging .getMessage ("nullValue.DragStateIsNull" );
259
+ Logging .logger ().severe (msg );
260
+ throw new IllegalArgumentException (msg );
261
+ }
262
+
263
+ if (!(dragState .equals (AVKey .DRAG_BEGIN ) || dragState .equals (AVKey .DRAG_CHANGE )
264
+ || dragState .equals (AVKey .DRAG_ENDED )))
265
+ {
266
+ String msg = Logging .getMessage ("generic.UnknownDragState" , dragState );
267
+ Logging .logger ().severe (msg );
268
+ throw new IllegalArgumentException (msg );
269
+ }
270
+
271
+ this .dragState = dragState ;
272
+ }
273
+ }
0 commit comments