1 /*
2 * Copyright (c) 2011, 2013, 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
71 }
72
73 private CDragSourceContextPeer(DragGestureEvent dge) {
74 super(dge);
75 }
76
77 public static CDragSourceContextPeer createDragSourceContextPeer(DragGestureEvent dge) throws InvalidDnDOperationException {
78 fInstance.setTrigger(dge);
79
80 return fInstance;
81 }
82
83 // We have to overload this method just to be able to grab the drag image and its offset as shared code doesn't store it:
84 public void startDrag(DragSourceContext dsc, Cursor cursor, Image dragImage, Point dragImageOffset) throws InvalidDnDOperationException {
85 fDragImage = dragImage;
86 fDragImageOffset = dragImageOffset;
87
88 super.startDrag(dsc, cursor, dragImage, dragImageOffset);
89 }
90
91 protected void startDrag(Transferable transferable, long[] formats, Map<Long, DataFlavor> formatMap) {
92 DragGestureEvent trigger = getTrigger();
93 InputEvent triggerEvent = trigger.getTriggerEvent();
94
95 Point dragOrigin = new Point(trigger.getDragOrigin());
96 int extModifiers = (triggerEvent.getModifiers() | triggerEvent.getModifiersEx());
97 long timestamp = triggerEvent.getWhen();
98 int clickCount = ((triggerEvent instanceof MouseEvent) ? (((MouseEvent) triggerEvent).getClickCount()) : 1);
99
100 Component component = trigger.getComponent();
101 // For a lightweight component traverse up the hierarchy to the root
102 Point loc = component.getLocation();
103 Component rootComponent = component;
104 while (!(rootComponent instanceof Window)) {
105 dragOrigin.translate(loc.x, loc.y);
106 rootComponent = rootComponent.getParent();
107 loc = rootComponent.getLocation();
108 }
109
110 // If there isn't any drag image make one of default appearance:
|
1 /*
2 * Copyright (c) 2011, 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
71 }
72
73 private CDragSourceContextPeer(DragGestureEvent dge) {
74 super(dge);
75 }
76
77 public static CDragSourceContextPeer createDragSourceContextPeer(DragGestureEvent dge) throws InvalidDnDOperationException {
78 fInstance.setTrigger(dge);
79
80 return fInstance;
81 }
82
83 // We have to overload this method just to be able to grab the drag image and its offset as shared code doesn't store it:
84 public void startDrag(DragSourceContext dsc, Cursor cursor, Image dragImage, Point dragImageOffset) throws InvalidDnDOperationException {
85 fDragImage = dragImage;
86 fDragImageOffset = dragImageOffset;
87
88 super.startDrag(dsc, cursor, dragImage, dragImageOffset);
89 }
90
91 @SuppressWarnings("deprecation")
92 protected void startDrag(Transferable transferable, long[] formats, Map<Long, DataFlavor> formatMap) {
93 DragGestureEvent trigger = getTrigger();
94 InputEvent triggerEvent = trigger.getTriggerEvent();
95
96 Point dragOrigin = new Point(trigger.getDragOrigin());
97 int extModifiers = (triggerEvent.getModifiers() | triggerEvent.getModifiersEx());
98 long timestamp = triggerEvent.getWhen();
99 int clickCount = ((triggerEvent instanceof MouseEvent) ? (((MouseEvent) triggerEvent).getClickCount()) : 1);
100
101 Component component = trigger.getComponent();
102 // For a lightweight component traverse up the hierarchy to the root
103 Point loc = component.getLocation();
104 Component rootComponent = component;
105 while (!(rootComponent instanceof Window)) {
106 dragOrigin.translate(loc.x, loc.y);
107 rootComponent = rootComponent.getParent();
108 loc = rootComponent.getLocation();
109 }
110
111 // If there isn't any drag image make one of default appearance:
|