author | fyang |
Mon, 04 Nov 2019 16:10:39 +0800 | |
changeset 59307 | fc216dcef2bb |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
4362
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
1 |
/* |
5506 | 2 |
* Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. |
4362
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
4 |
* |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
8 |
* |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
13 |
* accompanied this code). |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
14 |
* |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
18 |
* |
5506 | 19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
4362
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
22 |
*/ |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
23 |
|
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
24 |
import java.awt.dnd.*; |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
25 |
import java.awt.*; |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
26 |
import java.awt.datatransfer.DataFlavor; |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
27 |
import java.awt.datatransfer.UnsupportedFlavorException; |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
28 |
import java.io.File; |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
29 |
import java.io.IOException; |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
30 |
import java.util.ArrayList; |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
31 |
import java.util.Collection; |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
32 |
import java.util.Iterator; |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
33 |
import java.util.Arrays; |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
34 |
|
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
35 |
public class TargetPanel extends Panel implements DropTargetListener{ |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
36 |
|
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
37 |
private java.util.List <File> content = new ArrayList<File>(); |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
38 |
|
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
39 |
//private final CustomDropTargetListener dropTargetListener = new CustomDropTargetListener(); |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
40 |
|
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
41 |
private Frame frame; |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
42 |
|
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
43 |
public TargetPanel (Frame frame) |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
44 |
{ |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
45 |
this.frame = frame; |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
46 |
setBackground(Color.DARK_GRAY); |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
47 |
setPreferredSize(new Dimension(200, 200)); |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
48 |
setDropTarget(new DropTarget(this, this)); |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
49 |
} |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
50 |
|
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
51 |
public void dragEnter(DropTargetDragEvent dtde) { |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
52 |
if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
53 |
dtde.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE); |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
54 |
} |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
55 |
} |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
56 |
|
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
57 |
public void dragOver(DropTargetDragEvent dtde) { |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
58 |
if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
59 |
dtde.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE); |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
60 |
} |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
61 |
} |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
62 |
|
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
63 |
public void dropActionChanged(DropTargetDragEvent dtde) { |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
64 |
if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
65 |
dtde.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE); |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
66 |
} |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
67 |
} |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
68 |
|
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
69 |
public void dragExit(DropTargetEvent dte) { |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
70 |
|
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
71 |
} |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
72 |
|
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
73 |
public void drop(DropTargetDropEvent dtde) { |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
74 |
dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE); |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
75 |
if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
76 |
try { |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
77 |
content = (java.util.List)dtde.getTransferable().getTransferData(DataFlavor.javaFileListFlavor); |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
78 |
repaint(); |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
79 |
} catch (UnsupportedFlavorException e) { |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
80 |
e.printStackTrace(); |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
81 |
} catch (IOException e) { |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
82 |
e.printStackTrace(); |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
83 |
} |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
84 |
dtde.dropComplete(true); |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
85 |
|
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
86 |
|
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
87 |
|
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
88 |
boolean listsAreEqual = true; |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
89 |
|
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
90 |
for (int i = 0; i < content.size(); i++) { |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
91 |
if(!FileListTransferable.files[i].getName().equals(content.get(i).getName())) { |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
92 |
listsAreEqual = false; |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
93 |
} |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
94 |
} |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
95 |
|
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
96 |
if (listsAreEqual) { |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
97 |
System.err.println(InterprocessMessages.EXECUTION_IS_SUCCESSFULL); |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
98 |
System.exit(0); |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
99 |
} |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
100 |
} |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
101 |
dtde.rejectDrop(); |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
102 |
System.err.println(InterprocessMessages.FILES_ON_TARGET_ARE_CORRUPTED); |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
103 |
System.exit(1); |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
104 |
} |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
105 |
|
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
106 |
public void paint(Graphics g) { |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
107 |
g.setColor(Color.YELLOW); |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
108 |
int i = 0; |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
109 |
for (Iterator <File> iterator = content.iterator(); iterator.hasNext();i++) { |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
110 |
g.drawString(iterator.next().getName(), 5, g.getFontMetrics().getAscent()*i+20); |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
111 |
} |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
112 |
|
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
113 |
} |
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
114 |
|
ad915ad8792f
5098433: REG: DnD of File-List between JVM is broken for non ASCII file names - Win32
denis
parents:
diff
changeset
|
115 |
} |