author | erikj |
Tue, 12 Sep 2017 19:03:39 +0200 | |
changeset 47216 | 71c04702a3d5 |
parent 27768 | jdk/test/javax/swing/DataTransfer/8059739/bug8059739.java@3a3e044d7e48 |
permissions | -rw-r--r-- |
27768
3a3e044d7e48
8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents:
diff
changeset
|
1 |
/* |
3a3e044d7e48
8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents:
diff
changeset
|
2 |
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
3a3e044d7e48
8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3a3e044d7e48
8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents:
diff
changeset
|
4 |
* |
3a3e044d7e48
8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
3a3e044d7e48
8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
3a3e044d7e48
8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
3a3e044d7e48
8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents:
diff
changeset
|
8 |
* |
3a3e044d7e48
8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
3a3e044d7e48
8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
3a3e044d7e48
8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
3a3e044d7e48
8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
3a3e044d7e48
8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents:
diff
changeset
|
13 |
* accompanied this code). |
3a3e044d7e48
8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents:
diff
changeset
|
14 |
* |
3a3e044d7e48
8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
3a3e044d7e48
8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
3a3e044d7e48
8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
3a3e044d7e48
8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents:
diff
changeset
|
18 |
* |
3a3e044d7e48
8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
3a3e044d7e48
8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
3a3e044d7e48
8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents:
diff
changeset
|
21 |
* questions. |
3a3e044d7e48
8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents:
diff
changeset
|
22 |
*/ |
3a3e044d7e48
8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents:
diff
changeset
|
23 |
|
3a3e044d7e48
8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents:
diff
changeset
|
24 |
/* @test |
3a3e044d7e48
8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents:
diff
changeset
|
25 |
@bug 8059739 |
3a3e044d7e48
8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents:
diff
changeset
|
26 |
@summary Dragged and Dropped data is corrupted for two data types |
3a3e044d7e48
8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents:
diff
changeset
|
27 |
@author Anton Nashatyrev |
3a3e044d7e48
8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents:
diff
changeset
|
28 |
*/ |
3a3e044d7e48
8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents:
diff
changeset
|
29 |
|
3a3e044d7e48
8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents:
diff
changeset
|
30 |
import javax.swing.*; |
3a3e044d7e48
8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents:
diff
changeset
|
31 |
import java.awt.datatransfer.Clipboard; |
3a3e044d7e48
8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents:
diff
changeset
|
32 |
import java.awt.datatransfer.DataFlavor; |
3a3e044d7e48
8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents:
diff
changeset
|
33 |
import java.io.BufferedReader; |
3a3e044d7e48
8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents:
diff
changeset
|
34 |
import java.io.InputStream; |
3a3e044d7e48
8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents:
diff
changeset
|
35 |
import java.io.InputStreamReader; |
3a3e044d7e48
8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents:
diff
changeset
|
36 |
|
3a3e044d7e48
8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents:
diff
changeset
|
37 |
public class bug8059739 { |
3a3e044d7e48
8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents:
diff
changeset
|
38 |
|
3a3e044d7e48
8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents:
diff
changeset
|
39 |
private static boolean passed = true; |
3a3e044d7e48
8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents:
diff
changeset
|
40 |
|
3a3e044d7e48
8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents:
diff
changeset
|
41 |
public static void main(String[] args) throws Exception { |
3a3e044d7e48
8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents:
diff
changeset
|
42 |
SwingUtilities.invokeAndWait(new Runnable() { |
3a3e044d7e48
8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents:
diff
changeset
|
43 |
@Override |
3a3e044d7e48
8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents:
diff
changeset
|
44 |
public void run() { |
3a3e044d7e48
8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents:
diff
changeset
|
45 |
try { |
3a3e044d7e48
8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents:
diff
changeset
|
46 |
runTest(); |
3a3e044d7e48
8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents:
diff
changeset
|
47 |
} catch (Exception e) { |
3a3e044d7e48
8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents:
diff
changeset
|
48 |
e.printStackTrace(); |
3a3e044d7e48
8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents:
diff
changeset
|
49 |
passed = false; |
3a3e044d7e48
8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents:
diff
changeset
|
50 |
} |
3a3e044d7e48
8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents:
diff
changeset
|
51 |
} |
3a3e044d7e48
8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents:
diff
changeset
|
52 |
}); |
3a3e044d7e48
8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents:
diff
changeset
|
53 |
|
3a3e044d7e48
8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents:
diff
changeset
|
54 |
if (!passed) { |
3a3e044d7e48
8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents:
diff
changeset
|
55 |
throw new RuntimeException("Test FAILED."); |
3a3e044d7e48
8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents:
diff
changeset
|
56 |
} else { |
3a3e044d7e48
8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents:
diff
changeset
|
57 |
System.out.println("Passed."); |
3a3e044d7e48
8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents:
diff
changeset
|
58 |
} |
3a3e044d7e48
8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents:
diff
changeset
|
59 |
} |
3a3e044d7e48
8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents:
diff
changeset
|
60 |
|
3a3e044d7e48
8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents:
diff
changeset
|
61 |
private static void runTest() throws Exception { |
3a3e044d7e48
8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents:
diff
changeset
|
62 |
String testString = "my string"; |
3a3e044d7e48
8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents:
diff
changeset
|
63 |
JTextField tf = new JTextField(testString); |
3a3e044d7e48
8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents:
diff
changeset
|
64 |
tf.selectAll(); |
3a3e044d7e48
8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents:
diff
changeset
|
65 |
Clipboard clipboard = new Clipboard("clip"); |
3a3e044d7e48
8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents:
diff
changeset
|
66 |
tf.getTransferHandler().exportToClipboard(tf, clipboard, TransferHandler.COPY); |
3a3e044d7e48
8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents:
diff
changeset
|
67 |
DataFlavor[] dfs = clipboard.getAvailableDataFlavors(); |
3a3e044d7e48
8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents:
diff
changeset
|
68 |
for (DataFlavor df: dfs) { |
3a3e044d7e48
8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents:
diff
changeset
|
69 |
String charset = df.getParameter("charset"); |
3a3e044d7e48
8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents:
diff
changeset
|
70 |
if (InputStream.class.isAssignableFrom(df.getRepresentationClass()) && |
3a3e044d7e48
8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents:
diff
changeset
|
71 |
charset != null) { |
3a3e044d7e48
8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents:
diff
changeset
|
72 |
BufferedReader br = new BufferedReader(new InputStreamReader( |
3a3e044d7e48
8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents:
diff
changeset
|
73 |
(InputStream) clipboard.getData(df), charset)); |
3a3e044d7e48
8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents:
diff
changeset
|
74 |
String s = br.readLine(); |
3a3e044d7e48
8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents:
diff
changeset
|
75 |
System.out.println("Content: '" + s + "'"); |
3a3e044d7e48
8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents:
diff
changeset
|
76 |
passed &= s.contains(testString); |
3a3e044d7e48
8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents:
diff
changeset
|
77 |
} |
3a3e044d7e48
8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents:
diff
changeset
|
78 |
} |
3a3e044d7e48
8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents:
diff
changeset
|
79 |
} |
3a3e044d7e48
8059739: Dragged and Dropped data is corrupted for two data types
anashaty
parents:
diff
changeset
|
80 |
} |