author | henryjen |
Thu, 05 Jun 2014 13:59:01 -0700 | |
changeset 25192 | 4e2dc0f8702d |
parent 5506 | 202f599c92aa |
child 25200 | 360a141ded8f |
permissions | -rw-r--r-- |
2 | 1 |
/* |
5506 | 2 |
* Copyright (c) 1997, 2009, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 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 |
* |
|
5506 | 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. |
|
2 | 24 |
*/ |
25 |
||
26 |
package sun.awt.windows; |
|
27 |
||
28 |
import java.awt.Component; |
|
29 |
import java.awt.Cursor; |
|
4831
85d01a4fe115
4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
2
diff
changeset
|
30 |
import java.awt.Image; |
85d01a4fe115
4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
2
diff
changeset
|
31 |
import java.awt.Point; |
25192
4e2dc0f8702d
8044551: Fix raw and unchecked lint warnings in platform-specific sun.awt files
henryjen
parents:
5506
diff
changeset
|
32 |
import java.awt.datatransfer.DataFlavor; |
4831
85d01a4fe115
4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
2
diff
changeset
|
33 |
import java.awt.image.BufferedImage; |
85d01a4fe115
4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
2
diff
changeset
|
34 |
import java.awt.image.DataBufferInt; |
2 | 35 |
|
36 |
import java.awt.datatransfer.Transferable; |
|
37 |
||
38 |
import java.awt.dnd.DragGestureEvent; |
|
39 |
import java.awt.dnd.InvalidDnDOperationException; |
|
40 |
||
41 |
import java.awt.event.InputEvent; |
|
42 |
||
43 |
import java.util.Map; |
|
44 |
||
45 |
import sun.awt.dnd.SunDragSourceContextPeer; |
|
46 |
||
47 |
/** |
|
48 |
* <p> |
|
49 |
* TBC |
|
50 |
* </p> |
|
51 |
* |
|
52 |
* @since JDK1.2 |
|
53 |
* |
|
54 |
*/ |
|
55 |
||
56 |
final class WDragSourceContextPeer extends SunDragSourceContextPeer { |
|
57 |
public void startSecondaryEventLoop(){ |
|
58 |
WToolkit.startSecondaryEventLoop(); |
|
59 |
} |
|
60 |
public void quitSecondaryEventLoop(){ |
|
61 |
WToolkit.quitSecondaryEventLoop(); |
|
62 |
} |
|
63 |
||
64 |
private static final WDragSourceContextPeer theInstance = |
|
65 |
new WDragSourceContextPeer(null); |
|
66 |
||
67 |
/** |
|
68 |
* construct a new WDragSourceContextPeer. package private |
|
69 |
*/ |
|
70 |
||
71 |
private WDragSourceContextPeer(DragGestureEvent dge) { |
|
72 |
super(dge); |
|
73 |
} |
|
74 |
||
75 |
static WDragSourceContextPeer createDragSourceContextPeer(DragGestureEvent dge) throws InvalidDnDOperationException { |
|
76 |
theInstance.setTrigger(dge); |
|
77 |
return theInstance; |
|
78 |
} |
|
79 |
||
25192
4e2dc0f8702d
8044551: Fix raw and unchecked lint warnings in platform-specific sun.awt files
henryjen
parents:
5506
diff
changeset
|
80 |
@Override |
2 | 81 |
protected void startDrag(Transferable trans, |
25192
4e2dc0f8702d
8044551: Fix raw and unchecked lint warnings in platform-specific sun.awt files
henryjen
parents:
5506
diff
changeset
|
82 |
long[] formats, Map<Long, DataFlavor> formatMap) { |
2 | 83 |
|
84 |
long nativeCtxtLocal = 0; |
|
85 |
||
86 |
nativeCtxtLocal = createDragSource(getTrigger().getComponent(), |
|
87 |
trans, |
|
88 |
getTrigger().getTriggerEvent(), |
|
89 |
getTrigger().getSourceAsDragGestureRecognizer().getSourceActions(), |
|
90 |
formats, |
|
91 |
formatMap); |
|
92 |
||
93 |
if (nativeCtxtLocal == 0) { |
|
94 |
throw new InvalidDnDOperationException("failed to create native peer"); |
|
95 |
} |
|
96 |
||
4831
85d01a4fe115
4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
2
diff
changeset
|
97 |
int[] imageData = null; |
85d01a4fe115
4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
2
diff
changeset
|
98 |
Point op = null; |
85d01a4fe115
4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
2
diff
changeset
|
99 |
|
85d01a4fe115
4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
2
diff
changeset
|
100 |
Image im = getDragImage(); |
85d01a4fe115
4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
2
diff
changeset
|
101 |
int imageWidth = -1; |
85d01a4fe115
4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
2
diff
changeset
|
102 |
int imageHeight = -1; |
85d01a4fe115
4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
2
diff
changeset
|
103 |
if (im != null) { |
85d01a4fe115
4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
2
diff
changeset
|
104 |
//image is ready (partial images are ok) |
85d01a4fe115
4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
2
diff
changeset
|
105 |
try{ |
85d01a4fe115
4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
2
diff
changeset
|
106 |
imageWidth = im.getWidth(null); |
85d01a4fe115
4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
2
diff
changeset
|
107 |
imageHeight = im.getHeight(null); |
85d01a4fe115
4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
2
diff
changeset
|
108 |
if (imageWidth < 0 || imageHeight < 0) { |
85d01a4fe115
4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
2
diff
changeset
|
109 |
throw new InvalidDnDOperationException("drag image is not ready"); |
85d01a4fe115
4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
2
diff
changeset
|
110 |
} |
85d01a4fe115
4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
2
diff
changeset
|
111 |
//We could get an exception from user code here. |
85d01a4fe115
4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
2
diff
changeset
|
112 |
//"im" and "dragImageOffset" are user-defined objects |
85d01a4fe115
4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
2
diff
changeset
|
113 |
op = getDragImageOffset(); //op could not be null here |
85d01a4fe115
4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
2
diff
changeset
|
114 |
BufferedImage bi = new BufferedImage( |
85d01a4fe115
4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
2
diff
changeset
|
115 |
imageWidth, |
85d01a4fe115
4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
2
diff
changeset
|
116 |
imageHeight, |
85d01a4fe115
4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
2
diff
changeset
|
117 |
BufferedImage.TYPE_INT_ARGB); |
85d01a4fe115
4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
2
diff
changeset
|
118 |
bi.getGraphics().drawImage(im, 0, 0, null); |
85d01a4fe115
4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
2
diff
changeset
|
119 |
|
85d01a4fe115
4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
2
diff
changeset
|
120 |
//we can get out-of-memory here |
85d01a4fe115
4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
2
diff
changeset
|
121 |
imageData = ((DataBufferInt)bi.getData().getDataBuffer()).getData(); |
85d01a4fe115
4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
2
diff
changeset
|
122 |
} catch (Throwable ex) { |
85d01a4fe115
4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
2
diff
changeset
|
123 |
throw new InvalidDnDOperationException("drag image creation problem: " + ex.getMessage()); |
85d01a4fe115
4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
2
diff
changeset
|
124 |
} |
85d01a4fe115
4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
2
diff
changeset
|
125 |
} |
85d01a4fe115
4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
2
diff
changeset
|
126 |
|
85d01a4fe115
4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
2
diff
changeset
|
127 |
//We shouldn't have user-level exceptions since now. |
85d01a4fe115
4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
2
diff
changeset
|
128 |
//Any exception leads to corrupted D'n'D state. |
2 | 129 |
setNativeContext(nativeCtxtLocal); |
130 |
WDropTargetContextPeer.setCurrentJVMLocalSourceTransferable(trans); |
|
131 |
||
4831
85d01a4fe115
4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
2
diff
changeset
|
132 |
if (imageData != null) { |
85d01a4fe115
4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
2
diff
changeset
|
133 |
doDragDrop( |
85d01a4fe115
4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
2
diff
changeset
|
134 |
getNativeContext(), |
85d01a4fe115
4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
2
diff
changeset
|
135 |
getCursor(), |
85d01a4fe115
4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
2
diff
changeset
|
136 |
imageData, |
85d01a4fe115
4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
2
diff
changeset
|
137 |
imageWidth, imageHeight, |
85d01a4fe115
4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
2
diff
changeset
|
138 |
op.x, op.y); |
85d01a4fe115
4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
2
diff
changeset
|
139 |
} else { |
85d01a4fe115
4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
2
diff
changeset
|
140 |
doDragDrop( |
85d01a4fe115
4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
2
diff
changeset
|
141 |
getNativeContext(), |
85d01a4fe115
4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
2
diff
changeset
|
142 |
getCursor(), |
85d01a4fe115
4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
2
diff
changeset
|
143 |
null, |
85d01a4fe115
4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
2
diff
changeset
|
144 |
-1, -1, |
85d01a4fe115
4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
2
diff
changeset
|
145 |
0, 0); |
85d01a4fe115
4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
2
diff
changeset
|
146 |
} |
2 | 147 |
} |
148 |
||
149 |
/** |
|
150 |
* downcall into native code |
|
151 |
*/ |
|
152 |
||
153 |
native long createDragSource(Component component, |
|
154 |
Transferable transferable, |
|
155 |
InputEvent nativeTrigger, |
|
156 |
int actions, |
|
157 |
long[] formats, |
|
25192
4e2dc0f8702d
8044551: Fix raw and unchecked lint warnings in platform-specific sun.awt files
henryjen
parents:
5506
diff
changeset
|
158 |
Map<Long, DataFlavor> formatMap); |
2 | 159 |
|
160 |
/** |
|
161 |
* downcall into native code |
|
162 |
*/ |
|
163 |
||
4831
85d01a4fe115
4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
2
diff
changeset
|
164 |
native void doDragDrop( |
85d01a4fe115
4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
2
diff
changeset
|
165 |
long nativeCtxt, |
85d01a4fe115
4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
2
diff
changeset
|
166 |
Cursor cursor, |
85d01a4fe115
4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
2
diff
changeset
|
167 |
int[] imageData, |
85d01a4fe115
4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
2
diff
changeset
|
168 |
int imgWidth, int imgHight, |
85d01a4fe115
4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
2
diff
changeset
|
169 |
int offsetX, int offsetY); |
2 | 170 |
|
171 |
protected native void setNativeCursor(long nativeCtxt, Cursor c, int cType); |
|
172 |
||
173 |
} |