1 /*
2 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package java.awt.dnd;
27
28 import java.awt.Component;
29 import java.awt.Cursor;
30 import java.awt.Image;
31 import java.awt.Point;
32 import java.awt.Toolkit;
33 import java.awt.datatransfer.DataFlavor;
34 import java.awt.datatransfer.Transferable;
35 import java.awt.datatransfer.UnsupportedFlavorException;
36 import java.awt.dnd.peer.DragSourceContextPeer;
37 import java.io.IOException;
38 import java.io.InvalidObjectException;
39 import java.io.ObjectInputStream;
40 import java.io.ObjectOutputStream;
41 import java.io.Serializable;
42 import java.util.TooManyListenersException;
43
44 import sun.awt.AWTAccessor;
45
46 /**
47 * The <code>DragSourceContext</code> class is responsible for managing the
48 * initiator side of the Drag and Drop protocol. In particular, it is responsible
49 * for managing drag event notifications to the
50 * {@linkplain DragSourceListener DragSourceListeners}
51 * and {@linkplain DragSourceMotionListener DragSourceMotionListeners}, and providing the
52 * {@link Transferable} representing the source data for the drag operation.
53 * <p>
54 * Note that the <code>DragSourceContext</code> itself
55 * implements the <code>DragSourceListener</code> and
56 * <code>DragSourceMotionListener</code> interfaces.
57 * This is to allow the platform peer
58 * (the {@link DragSourceContextPeer} instance)
59 * created by the {@link DragSource} to notify
60 * the <code>DragSourceContext</code> of
61 * state changes in the ongoing operation. This allows the
62 * <code>DragSourceContext</code> object to interpose
63 * itself between the platform and the
64 * listeners provided by the initiator of the drag operation.
167 * @param offset the offset of the image origin from the hotspot at the
168 * instant of the triggering event
169 * @param t the <code>Transferable</code>
170 * @param dsl the <code>DragSourceListener</code>
171 *
172 * @throws IllegalArgumentException if the <code>Component</code> associated
173 * with the trigger event is <code>null</code>.
174 * @throws IllegalArgumentException if the <code>DragSource</code> for the
175 * trigger event is <code>null</code>.
176 * @throws IllegalArgumentException if the drag action for the
177 * trigger event is <code>DnDConstants.ACTION_NONE</code>.
178 * @throws IllegalArgumentException if the source actions for the
179 * <code>DragGestureRecognizer</code> associated with the trigger
180 * event are equal to <code>DnDConstants.ACTION_NONE</code>.
181 * @throws NullPointerException if dscp, trigger, or t are null, or
182 * if dragImage is non-null and offset is null
183 */
184 public DragSourceContext(DragGestureEvent trigger, Cursor dragCursor,
185 Image dragImage, Point offset, Transferable t,
186 DragSourceListener dsl) {
187 DragSourceContextPeer dscp = Toolkit.getDefaultToolkit()
188 .createDragSourceContextPeer(trigger);
189
190 if (dscp == null) {
191 throw new NullPointerException("DragSourceContextPeer");
192 }
193
194 if (trigger == null) {
195 throw new NullPointerException("Trigger");
196 }
197
198 if (trigger.getDragSource() == null) {
199 throw new IllegalArgumentException("DragSource");
200 }
201
202 if (trigger.getComponent() == null) {
203 throw new IllegalArgumentException("Component");
204 }
205
206 if (trigger.getSourceAsDragGestureRecognizer().getSourceActions() ==
207 DnDConstants.ACTION_NONE) {
208 throw new IllegalArgumentException("source actions");
|
1 /*
2 * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package java.awt.dnd;
27
28 import java.awt.AWTError;
29 import java.awt.Component;
30 import java.awt.Cursor;
31 import java.awt.Image;
32 import java.awt.Point;
33 import java.awt.Toolkit;
34 import java.awt.datatransfer.DataFlavor;
35 import java.awt.datatransfer.Transferable;
36 import java.awt.datatransfer.UnsupportedFlavorException;
37 import java.awt.dnd.peer.DragSourceContextPeer;
38 import java.io.IOException;
39 import java.io.InvalidObjectException;
40 import java.io.ObjectInputStream;
41 import java.io.ObjectOutputStream;
42 import java.io.Serializable;
43 import java.util.TooManyListenersException;
44
45 import sun.awt.AWTAccessor;
46 import sun.awt.ComponentFactory;
47
48 /**
49 * The <code>DragSourceContext</code> class is responsible for managing the
50 * initiator side of the Drag and Drop protocol. In particular, it is responsible
51 * for managing drag event notifications to the
52 * {@linkplain DragSourceListener DragSourceListeners}
53 * and {@linkplain DragSourceMotionListener DragSourceMotionListeners}, and providing the
54 * {@link Transferable} representing the source data for the drag operation.
55 * <p>
56 * Note that the <code>DragSourceContext</code> itself
57 * implements the <code>DragSourceListener</code> and
58 * <code>DragSourceMotionListener</code> interfaces.
59 * This is to allow the platform peer
60 * (the {@link DragSourceContextPeer} instance)
61 * created by the {@link DragSource} to notify
62 * the <code>DragSourceContext</code> of
63 * state changes in the ongoing operation. This allows the
64 * <code>DragSourceContext</code> object to interpose
65 * itself between the platform and the
66 * listeners provided by the initiator of the drag operation.
169 * @param offset the offset of the image origin from the hotspot at the
170 * instant of the triggering event
171 * @param t the <code>Transferable</code>
172 * @param dsl the <code>DragSourceListener</code>
173 *
174 * @throws IllegalArgumentException if the <code>Component</code> associated
175 * with the trigger event is <code>null</code>.
176 * @throws IllegalArgumentException if the <code>DragSource</code> for the
177 * trigger event is <code>null</code>.
178 * @throws IllegalArgumentException if the drag action for the
179 * trigger event is <code>DnDConstants.ACTION_NONE</code>.
180 * @throws IllegalArgumentException if the source actions for the
181 * <code>DragGestureRecognizer</code> associated with the trigger
182 * event are equal to <code>DnDConstants.ACTION_NONE</code>.
183 * @throws NullPointerException if dscp, trigger, or t are null, or
184 * if dragImage is non-null and offset is null
185 */
186 public DragSourceContext(DragGestureEvent trigger, Cursor dragCursor,
187 Image dragImage, Point offset, Transferable t,
188 DragSourceListener dsl) {
189 Toolkit toolkit = Toolkit.getDefaultToolkit();
190 if (!(toolkit instanceof ComponentFactory)) {
191 throw new AWTError("Unsupported toolkit: " + toolkit);
192 }
193 DragSourceContextPeer dscp = ((ComponentFactory) toolkit).
194 createDragSourceContextPeer(trigger);
195
196 if (dscp == null) {
197 throw new NullPointerException("DragSourceContextPeer");
198 }
199
200 if (trigger == null) {
201 throw new NullPointerException("Trigger");
202 }
203
204 if (trigger.getDragSource() == null) {
205 throw new IllegalArgumentException("DragSource");
206 }
207
208 if (trigger.getComponent() == null) {
209 throw new IllegalArgumentException("Component");
210 }
211
212 if (trigger.getSourceAsDragGestureRecognizer().getSourceActions() ==
213 DnDConstants.ACTION_NONE) {
214 throw new IllegalArgumentException("source actions");
|