Clover Coverage Report - FEST Swing 1.2
Coverage timestamp: Tue Jun 1 2010 15:19:25 PDT
0   158   0   -
0   89   -   0
0     -  
1    
100% of code in this file is excluded from these metrics.
 
  DragAndDrop       Line # 41 0 100% 0 0 - -1.0
 
No Tests
 
1    /*
2    * Created on Feb 1, 2008
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5    * in compliance with the License. You may obtain a copy of the License at
6    *
7    * http://www.apache.org/licenses/LICENSE-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software distributed under the License
10    * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11    * or implied. See the License for the specific language governing permissions and limitations under
12    * the License.
13    *
14    * Copyright @2008-2010 the original author or authors.
15    */
16    package org.fest.swing.driver;
17   
18    import static org.fest.swing.core.MouseButton.LEFT_BUTTON;
19    import static org.fest.swing.exception.ActionFailedException.actionFailure;
20    import static org.fest.swing.timing.Pause.pause;
21    import static org.fest.swing.util.Platform.isMacintosh;
22    import static org.fest.swing.util.Platform.isWindows;
23    import static org.fest.swing.util.TimeoutWatch.startWatchWithTimeoutOf;
24   
25    import java.awt.*;
26   
27    import org.fest.swing.annotation.RunsInEDT;
28    import org.fest.swing.core.*;
29    import org.fest.swing.core.Robot;
30    import org.fest.swing.exception.ActionFailedException;
31    import org.fest.swing.util.TimeoutWatch;
32   
33    /**
34    * Understands drag and drop.
35    *
36    * @author Alex Ruiz
37    *
38    * @deprecated use <code>{@link ComponentDragAndDrop}</code> instead. This class will be removed in version 2.0.
39    */
40    @Deprecated
 
41    public class DragAndDrop {
42   
43    private final Robot robot;
44   
45    /**
46    * Creates a new </code>{@link DragAndDrop}</code>.
47    * @param robot the robot to use to simulate user input.
48    * @deprecated use <code>{@link ComponentDragAndDrop}</code> instead.
49    */
 
50    toggle @Deprecated
51    public DragAndDrop(Robot robot) {
52    this.robot = robot;
53    }
54   
55    /** Number of pixels traversed before a drag starts. */
56    public static final int DRAG_THRESHOLD = isWindows() || isMacintosh() ? 10 : 16;
57   
58    /**
59    * Performs a drag action at the given point.
60    * @param target the target component.
61    * @param where the point where to start the drag action.
62    * @deprecated use <code>{@link ComponentDragAndDrop}</code> instead.
63    */
 
64    toggle @RunsInEDT
65    @Deprecated public void drag(Component target, Point where) {
66    robot.pressMouse(target, where, LEFT_BUTTON);
67    int dragDelay = settings().dragDelay();
68    if (dragDelay > delayBetweenEvents()) pause(dragDelay);
69    mouseMove(target, where.x, where.y);
70    robot.waitForIdle();
71    }
72   
 
73    toggle @Deprecated private void mouseMove(Component target, int x, int y) {
74    if (isWindows() || isMacintosh()) {
75    mouseMoveOnWindowsAndMacintosh(target, x, y);
76    return;
77    }
78    mouseMove(target,
79    point(x + DRAG_THRESHOLD / 2, y + DRAG_THRESHOLD / 2),
80    point(x + DRAG_THRESHOLD, y + DRAG_THRESHOLD),
81    point(x + DRAG_THRESHOLD / 2, y + DRAG_THRESHOLD / 2),
82    point(x, y)
83    );
84    }
85   
 
86    toggle @RunsInEDT
87    @Deprecated private void mouseMoveOnWindowsAndMacintosh(Component target, int x, int y) {
88    Dimension size = target.getSize();
89    int dx = distance(x, size.width);
90    int dy = distance(y, size.height);
91    if (dx == 0 && dy == 0) dx = DRAG_THRESHOLD;
92    mouseMove(target,
93    point(x + dx / 4, y + dy / 4),
94    point(x + dx / 2, y + dy / 2),
95    point(x + dx, y + dy),
96    point(x + dx + 1, y + dy)
97    );
98    }
99   
 
100    toggle @Deprecated private int distance(int coordinate, int dimension) {
101    return coordinate + DRAG_THRESHOLD < dimension ? DRAG_THRESHOLD : 0;
102    }
103   
 
104    toggle @Deprecated private Point point(int x, int y) { return new Point(x, y); }
105   
106    /**
107    * Ends a drag operation, releasing the mouse button over the given target location.
108    * <p>
109    * This method is tuned for native drag/drop operations, so if you get odd behavior, you might try using a simple
110    * <code>{@link Robot#moveMouse(Component, int, int)}</code> and <code>{@link Robot#releaseMouseButtons()}</code>.
111    * @param target the target component.
112    * @param where the point where the drag operation ends.
113    * @throws ActionFailedException if there is no drag action in effect.
114    * @deprecated use <code>{@link ComponentDragAndDrop}</code> instead.
115    */
 
116    toggle @RunsInEDT
117    @Deprecated public void drop(Component target, Point where) {
118    dragOver(target, where);
119    TimeoutWatch watch = startWatchWithTimeoutOf(settings().eventPostingDelay() * 4);
120    while (!robot.isDragging()) {
121    if (watch.isTimeOut()) throw actionFailure("There is no drag in effect");
122    pause();
123    }
124    int dropDelay = settings().dropDelay();
125    int delayBetweenEvents = delayBetweenEvents();
126    if (dropDelay > delayBetweenEvents) pause(dropDelay - delayBetweenEvents);
127    robot.releaseMouseButtons();
128    robot.waitForIdle();
129    }
130   
 
131    toggle @Deprecated private int delayBetweenEvents() {
132    return settings().delayBetweenEvents();
133    }
134   
 
135    toggle @Deprecated private Settings settings() {
136    return robot.settings();
137    }
138   
139    /**
140    * Move the mouse appropriately to get from the source to the destination. Enter/exit events will be generated where
141    * appropriate.
142    * @param target the target component.
143    * @param where the point to drag over.
144    * @deprecated use <code>{@link ComponentDragAndDrop}</code> instead.
145    */
 
146    toggle @Deprecated public void dragOver(Component target, Point where) {
147    dragOver(target, where.x, where.y);
148    }
149   
 
150    toggle @Deprecated private void dragOver(Component target, int x, int y) {
151    robot.moveMouse(target, x - 4, y);
152    robot.moveMouse(target, x, y);
153    }
154   
 
155    toggle @Deprecated private void mouseMove(Component target, Point...points) {
156    for (Point p : points) robot.moveMouse(target, p.x, p.y);
157    }
158    }