Skip to content

Commit f67dee9

Browse files
author
Zach Glueckert
committed
Add Draggable interface and shift drag execution from the BasicDragger to the new interface. Add DraggableSupport which provides utility methods that correct dragging issues observed with the legacy dragging behavior. Implemented Draggable on all objects implementing Movable and Movable2 and utilized the utility methods of DraggableSupport to correct the cursor drifting from the drag object behavior.
1 parent 2d1e121 commit f67dee9

22 files changed

+1642
-104
lines changed

src/gov/nasa/worldwind/avlist/AVKey.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,13 @@ public interface AVKey // TODO: Eliminate unused constants, if any
9797
final String DISPLAY_ICON = "gov.nasa.worldwind.avkey.DisplayIcon";
9898
final String DISPLAY_NAME = "gov.nasa.worldwind.avkey.DisplayName";
9999
final String DOCUMENT = "gov.nasa.worldwind.avkey.Document";
100+
/**
101+
* Indicates the state of dragging. Provided by the {@link gov.nasa.worldwind.drag.DragContext} object to objects
102+
* implementing {@link gov.nasa.worldwind.drag.Draggable}.
103+
*/
104+
final String DRAG_BEGIN = "gov.nasa.worldwind.avkey.DragBegin";
105+
final String DRAG_CHANGE = "gov.nasa.worldwind.avkey.DragChange";
106+
final String DRAG_ENDED = "gov.nasa.worldwind.avkey.DragEnded";
100107

101108
final String DTED_LEVEL = "gov.nasa.worldwind.avkey.DTED.Level";
102109

Lines changed: 273 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,273 @@
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+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
/**
10+
* An interface provided by objects that can be dragged. The {@link DragContext} provided in the {@link
11+
* Draggable#drag(DragContext)} method includes information on the screen coordinates and the state of the
12+
* {@link gov.nasa.worldwind.WorldWindow}.
13+
*/
14+
public interface Draggable
15+
{
16+
/**
17+
* Indicates whether the object is enabled for dragging.
18+
*
19+
* @return true if the object is enabled, else false.
20+
*/
21+
boolean isDragEnabled();
22+
23+
/**
24+
* Controls whether the object is enabled for dragging.
25+
*
26+
* @param enabled <code>true</code> if the object is enabled, else <code>false</code>.
27+
*/
28+
void setDragEnabled(boolean enabled);
29+
30+
/**
31+
* Drag the object given the provided {@link DragContext}.
32+
*
33+
* @param dragContext the {@link DragContext} of this dragging event.
34+
*/
35+
void drag(DragContext dragContext);
36+
}

0 commit comments

Comments
 (0)