diff --git a/jdk/src/share/classes/sun/awt/datatransfer/DataTransferer.java b/jdk/src/share/classes/sun/awt/datatransfer/DataTransferer.java index 277d3bd9e28..a0853088e42 100644 --- a/jdk/src/share/classes/sun/awt/datatransfer/DataTransferer.java +++ b/jdk/src/share/classes/sun/awt/datatransfer/DataTransferer.java @@ -203,6 +203,8 @@ public abstract class DataTransferer { private static final Map nativeEOLNs = Collections.synchronizedMap(new HashMap()); + private static final byte [] UNICODE_NULL_TERMINATOR = new byte [] {0,0}; + /** * The number of terminating NUL bytes for the Set of textNatives. */ @@ -1299,7 +1301,7 @@ search: } final List list = (List)obj; - final ArrayList fileList = new ArrayList(); + final ArrayList fileList = new ArrayList(); final ProtectionDomain userProtectionDomain = getUserProtectionDomain(contents); @@ -1331,13 +1333,24 @@ search: throw new IOException(pae.getMessage()); } - for (int i = 0; i < fileList.size(); i++) - { - byte[] bytes = ((String)fileList.get(i)).getBytes(); - if (i != 0) bos.write(0); - bos.write(bytes, 0, bytes.length); + if(fileList.isEmpty()) { + //store empty unicode string (null terminator) + bos.write(UNICODE_NULL_TERMINATOR); + } else { + for (int i = 0; i < fileList.size(); i++) { + byte[] bytes = fileList.get(i).getBytes(getDefaultUnicodeEncoding()); + //store unicode string with null terminator + bos.write(bytes, 0, bytes.length); + bos.write(UNICODE_NULL_TERMINATOR); + } } + // According to MSDN the byte array have to be double NULL-terminated. + // The array contains Unicode characters, so each NULL-terminator is + // a pair of bytes + + bos.write(UNICODE_NULL_TERMINATOR); + // Source data is an InputStream. For arbitrary flavors, just grab the // bytes and dump them into a byte array. For text flavors, decode back // to a String and recur to reencode according to the requested format. diff --git a/jdk/src/windows/native/sun/windows/awt_DnDDS.cpp b/jdk/src/windows/native/sun/windows/awt_DnDDS.cpp index bb2ac566493..b0438eae061 100644 --- a/jdk/src/windows/native/sun/windows/awt_DnDDS.cpp +++ b/jdk/src/windows/native/sun/windows/awt_DnDDS.cpp @@ -648,7 +648,7 @@ HRESULT __stdcall AwtDragSource::GetData(FORMATETC __RPC_FAR *pFormatEtc, dropfiles->pt.x = m_dropPoint.x; dropfiles->pt.y = m_dropPoint.y; dropfiles->fNC = m_fNC; - dropfiles->fWide = FALSE; // good guess! + dropfiles->fWide = TRUE; // good guess! dataout += sizeof(DROPFILES); } @@ -815,7 +815,7 @@ HRESULT __stdcall AwtDragSource::GetDataHere(FORMATETC __RPC_FAR *pFormatEtc, dropfiles->pt.x = m_dropPoint.x; dropfiles->pt.y = m_dropPoint.y; dropfiles->fNC = m_fNC; - dropfiles->fWide = FALSE; // good guess! + dropfiles->fWide = TRUE; // good guess! dataout += sizeof(DROPFILES); } diff --git a/jdk/test/java/awt/datatransfer/DragUnicodeBetweenJVMTest/AbsoluteComponentCenterCalculator.java b/jdk/test/java/awt/datatransfer/DragUnicodeBetweenJVMTest/AbsoluteComponentCenterCalculator.java new file mode 100644 index 00000000000..83bb3dfecd3 --- /dev/null +++ b/jdk/test/java/awt/datatransfer/DragUnicodeBetweenJVMTest/AbsoluteComponentCenterCalculator.java @@ -0,0 +1,34 @@ +/* + * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +import java.awt.*; + +class AbsoluteComponentCenterCalculator { + private AbsoluteComponentCenterCalculator () {} + public static int calculateXCenterCoordinate(Component component) { + return (int)component.getLocationOnScreen().getX()+(component.getWidth()/2); + } + public static int calculateYCenterCoordinate(Component component) { + return (int)component.getLocationOnScreen().getY()+(component.getHeight()/2); + } +} diff --git a/jdk/test/java/awt/datatransfer/DragUnicodeBetweenJVMTest/DragUnicodeBetweenJVMTest.html b/jdk/test/java/awt/datatransfer/DragUnicodeBetweenJVMTest/DragUnicodeBetweenJVMTest.html new file mode 100644 index 00000000000..49fbaced533 --- /dev/null +++ b/jdk/test/java/awt/datatransfer/DragUnicodeBetweenJVMTest/DragUnicodeBetweenJVMTest.html @@ -0,0 +1,25 @@ + + + + REG: DnD of File-List between JVM is broken for non ASCII file names - Win32 + + + +

DragUnicodeBetweenJVMTest
Bug ID: 5098433

+ +

This is an AUTOMATIC test, simply wait for completion

+ + + + diff --git a/jdk/test/java/awt/datatransfer/DragUnicodeBetweenJVMTest/DragUnicodeBetweenJVMTest.java b/jdk/test/java/awt/datatransfer/DragUnicodeBetweenJVMTest/DragUnicodeBetweenJVMTest.java new file mode 100644 index 00000000000..e64f15b63f2 --- /dev/null +++ b/jdk/test/java/awt/datatransfer/DragUnicodeBetweenJVMTest/DragUnicodeBetweenJVMTest.java @@ -0,0 +1,193 @@ +/* + * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +/* + test + @bug 5098433 + @summary REG: DnD of File-List between JVM is broken for non ASCII file names - Win32 + @author Denis Fokin: area=dnd + @library ../../regtesthelpers + @library ../../regtesthelpers/process + @build Util + @build ProcessResults ProcessCommunicator + + + @run applet/othervm DragUnicodeBetweenJVMTest.html +*/ + +/** + * DragUnicodeBetweenJVMTest.java + * + * summary: The test drags a list of files (DataFlavor.javaFileListFlavor) from one jvm to another. + * The files have Unicode names. The list on target side must be equal to + * the list on the source side. + */ + + +import java.awt.*; +import java.awt.event.*; +import java.applet.Applet; + +import test.java.awt.regtesthelpers.process.ProcessCommunicator; +import test.java.awt.regtesthelpers.process.ProcessResults; +import test.java.awt.regtesthelpers.Util; +import static java.lang.Thread.sleep; + +public class DragUnicodeBetweenJVMTest extends Applet +{ + + public void init() { + setLayout(new BorderLayout()); + }//End init() + + public void start() { + + String toolkit = Toolkit.getDefaultToolkit().getClass().getName(); + if (!toolkit.equals("sun.awt.windows.WToolkit")){ + System.out.println("This test is for Windows only. Passed."); + return; + } + else{ + System.out.println("Toolkit = " + toolkit); + } + + final Frame sourceFrame = new Frame("Source frame"); + final SourcePanel sourcePanel = new SourcePanel(); + sourceFrame.add(sourcePanel); + sourceFrame.pack(); + sourceFrame.addWindowListener( new WindowAdapter() { + @Override + public void windowClosing(WindowEvent e) { + sourceFrame.dispose(); + } + }); + sourceFrame.setVisible(true); + + Util.waitForIdle(null); + + NextFramePositionCalculator positionCalculator = new NextFramePositionCalculator(sourceFrame); + + String [] args = new String [] { + String.valueOf(positionCalculator.getNextLocationX()), + String.valueOf(positionCalculator.getNextLocationY()), + String.valueOf(AbsoluteComponentCenterCalculator.calculateXCenterCoordinate(sourcePanel)), + String.valueOf(AbsoluteComponentCenterCalculator.calculateYCenterCoordinate(sourcePanel)), + }; + + + ProcessResults processResults = + // ProcessCommunicator.executeChildProcess(this.getClass()," -cp \"C:\\Documents and Settings\\df153228\\IdeaProjects\\UnicodeTestDebug\\out\\production\\UnicodeTestDebug\" -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005 ", args); + ProcessCommunicator.executeChildProcess(this.getClass(), args); + + verifyTestResults(processResults); + + }// start() + + + + private static void verifyTestResults(ProcessResults processResults) { + if ( InterprocessMessages.FILES_ON_TARGET_ARE_CORRUPTED == + processResults.getExitValue()) + { + processResults.printProcessErrorOutput(System.err); + throw new RuntimeException("TEST IS FAILED: Target has recieved" + + " broken file list."); + } + processResults.verifyStdErr(System.err); + processResults.verifyProcessExitValue(System.err); + processResults.printProcessStandartOutput(System.out); + } + + //We cannot make an instance of the applet without the default constructor + public DragUnicodeBetweenJVMTest () { + super(); + } + + //We need in this constructor to pass frame position between JVMs + public DragUnicodeBetweenJVMTest (Point targetFrameLocation, Point dragSourcePoint) + throws InterruptedException + { + final Frame targetFrame = new Frame("Target frame"); + final TargetPanel targetPanel = new TargetPanel(targetFrame); + targetFrame.add(targetPanel); + targetFrame.addWindowListener( new WindowAdapter() { + @Override + public void windowClosing(WindowEvent e) { + targetFrame.dispose(); + } + }); + targetFrame.setLocation(targetFrameLocation); + targetFrame.pack(); + targetFrame.setVisible(true); + + doTest(dragSourcePoint, targetPanel); + } + + private void doTest(Point dragSourcePoint, TargetPanel targetPanel) { + Util.waitForIdle(null); + + final Robot robot = Util.createRobot(); + + robot.mouseMove((int)dragSourcePoint.getX(),(int)dragSourcePoint.getY()); + try { + sleep(100); + robot.mousePress(InputEvent.BUTTON1_MASK); + sleep(100); + robot.mouseRelease(InputEvent.BUTTON1_MASK); + sleep(100); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + Util.drag(robot, dragSourcePoint, new Point (AbsoluteComponentCenterCalculator.calculateXCenterCoordinate(targetPanel), + AbsoluteComponentCenterCalculator.calculateYCenterCoordinate(targetPanel)), + InputEvent.BUTTON1_MASK); + } + + + enum InterprocessArguments { + TARGET_FRAME_X_POSITION_ARGUMENT, + TARGET_FRAME_Y_POSITION_ARGUMENT, + DRAG_SOURCE_POINT_X_ARGUMENT, + DRAG_SOURCE_POINT_Y_ARGUMENT; + + int extract (String [] args) { + return Integer.parseInt(args[this.ordinal()]); + } + } + + public static void main (String [] args) { + Point dragSourcePoint = new Point(InterprocessArguments.DRAG_SOURCE_POINT_X_ARGUMENT.extract(args), + InterprocessArguments.DRAG_SOURCE_POINT_Y_ARGUMENT.extract(args)); + Point targetFrameLocation = new Point(InterprocessArguments.TARGET_FRAME_X_POSITION_ARGUMENT.extract(args), + InterprocessArguments.TARGET_FRAME_Y_POSITION_ARGUMENT.extract(args)); + + try { + new DragUnicodeBetweenJVMTest(targetFrameLocation, dragSourcePoint); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + +} diff --git a/jdk/test/java/awt/datatransfer/DragUnicodeBetweenJVMTest/FileListTransferable.java b/jdk/test/java/awt/datatransfer/DragUnicodeBetweenJVMTest/FileListTransferable.java new file mode 100644 index 00000000000..f2dcf607c4c --- /dev/null +++ b/jdk/test/java/awt/datatransfer/DragUnicodeBetweenJVMTest/FileListTransferable.java @@ -0,0 +1,68 @@ +/* + * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +import java.awt.datatransfer.Transferable; +import java.awt.datatransfer.DataFlavor; +import java.awt.datatransfer.UnsupportedFlavorException; +import java.io.IOException; +import java.io.File; +import java.util.Arrays; +import java.util.List; + +class FileListTransferable implements Transferable { + + public static File [] files = new File [] { + new File ("\u042f\u0020\u0441\u0440\u0430\u0437\u0443\u0020\u0441\u043c\u0430\u0437\u0430\u043b" + + "\u0020\u043a\u0430\u0440\u0442\u0443\u0020\u0431\u0443\u0434\u043d\u044f"), + new File ("\u043f\u043b\u0435\u0441\u043d\u0443\u0432\u0448\u0438\u0020\u043a\u0440\u0430\u0441" + + "\u043a\u0443\u0020\u0438\u0437\u0020\u0441\u0442\u0430\u043a\u0430\u043d\u0430"), + new File ("\u044f\u0020\u043f\u043e\u043a\u0430\u0437\u0430\u043b\u0020\u043d\u0430\u0020\u0431" + + "\u043b\u044e\u0434\u0435\u0020\u0441\u0442\u0443\u0434\u043d\u044f"), + new File ("\u043a\u043e\u0441\u044b\u0435\u0020\u0441\u043a\u0443\u043b\u044b\u0020\u043e\u043a" + + "\u0435\u0430\u043d\u0430"), + new File ("\u041d\u0430\u0020\u0447\u0435\u0448\u0443\u0435\u0020\u0436\u0435\u0441\u0442\u044f" + + "\u043d\u043e\u0439\u0020\u0440\u044b\u0431\u044b"), + new File ("\u043f\u0440\u043e\u0447\u0435\u043b\u0020\u044f\u0020\u0437\u043e\u0432\u044b\u0020" + + "\u043d\u043e\u0432\u044b\u0445\u0020\u0433\u0443\u0431"), + new File ("\u0410\u0020\u0432\u044b"), + new File ("\u043d\u043e\u043a\u0442\u044e\u0440\u043d\u0020\u0441\u044b\u0433\u0440\u0430\u0442" + + "\u044c"), + new File ("\u043c\u043e\u0433\u043b\u0438\u0020\u0431\u044b"), + new File ("\u043d\u0430\u0020\u0444\u043b\u0435\u0439\u0442\u0435\u0020\u0432\u043e\u0434\u043e" + + "\u0441\u0442\u043e\u0447\u043d\u044b\u0445\u0020\u0442\u0440\u0443\u0431"), + }; + + public DataFlavor[] getTransferDataFlavors() { + return new DataFlavor [] {DataFlavor.javaFileListFlavor}; + } + + public boolean isDataFlavorSupported(DataFlavor flavor) { + return flavor.equals(DataFlavor.javaFileListFlavor) ; + } + + public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException { + List list = Arrays.asList(files); + return list; + + } +} diff --git a/jdk/test/java/awt/datatransfer/DragUnicodeBetweenJVMTest/InterprocessMessages.java b/jdk/test/java/awt/datatransfer/DragUnicodeBetweenJVMTest/InterprocessMessages.java new file mode 100644 index 00000000000..33bb9a3cbd0 --- /dev/null +++ b/jdk/test/java/awt/datatransfer/DragUnicodeBetweenJVMTest/InterprocessMessages.java @@ -0,0 +1,28 @@ +/* + * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +interface InterprocessMessages { + final static int EXECUTION_IS_SUCCESSFULL = 0; + final static int FILES_ON_TARGET_ARE_CORRUPTED = 212; +} + diff --git a/jdk/test/java/awt/datatransfer/DragUnicodeBetweenJVMTest/NextFramePositionCalculator.java b/jdk/test/java/awt/datatransfer/DragUnicodeBetweenJVMTest/NextFramePositionCalculator.java new file mode 100644 index 00000000000..7d55be76e91 --- /dev/null +++ b/jdk/test/java/awt/datatransfer/DragUnicodeBetweenJVMTest/NextFramePositionCalculator.java @@ -0,0 +1,43 @@ +/* + * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +import java.awt.*; + + +class NextFramePositionCalculator { + + private final Frame currentFrame; + + public NextFramePositionCalculator (Frame currentFrame) { + this.currentFrame = currentFrame; + } + + public int getNextLocationX() { + return currentFrame.getX()+currentFrame.getWidth(); + } + + public int getNextLocationY() { + return currentFrame.getY(); + } + +} diff --git a/jdk/test/java/awt/datatransfer/DragUnicodeBetweenJVMTest/SourcePanel.java b/jdk/test/java/awt/datatransfer/DragUnicodeBetweenJVMTest/SourcePanel.java new file mode 100644 index 00000000000..075d64810f7 --- /dev/null +++ b/jdk/test/java/awt/datatransfer/DragUnicodeBetweenJVMTest/SourcePanel.java @@ -0,0 +1,50 @@ +/* + * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +import java.awt.dnd.DragSource; +import java.awt.dnd.DnDConstants; +import java.awt.dnd.DragGestureEvent; +import java.awt.dnd.DragGestureListener; +import java.awt.*; + +public class SourcePanel extends Panel +{ + + private final MyDragGestureListener dragGestureListener = + new MyDragGestureListener(); + + public SourcePanel () { + setPreferredSize(new Dimension(200, 200)); + DragSource defaultDragSource = + DragSource.getDefaultDragSource(); + defaultDragSource.createDefaultDragGestureRecognizer(this, + DnDConstants.ACTION_COPY_OR_MOVE, dragGestureListener); + setBackground(Color.RED); + } + + private class MyDragGestureListener implements DragGestureListener { + public void dragGestureRecognized(DragGestureEvent dge) { + dge.startDrag(null, new FileListTransferable()); + } + } +} diff --git a/jdk/test/java/awt/datatransfer/DragUnicodeBetweenJVMTest/TargetPanel.java b/jdk/test/java/awt/datatransfer/DragUnicodeBetweenJVMTest/TargetPanel.java new file mode 100644 index 00000000000..5688bf69ff2 --- /dev/null +++ b/jdk/test/java/awt/datatransfer/DragUnicodeBetweenJVMTest/TargetPanel.java @@ -0,0 +1,115 @@ +/* + * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +import java.awt.dnd.*; +import java.awt.*; +import java.awt.datatransfer.DataFlavor; +import java.awt.datatransfer.UnsupportedFlavorException; +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.Arrays; + +public class TargetPanel extends Panel implements DropTargetListener{ + + private java.util.List content = new ArrayList(); + + //private final CustomDropTargetListener dropTargetListener = new CustomDropTargetListener(); + + private Frame frame; + + public TargetPanel (Frame frame) + { + this.frame = frame; + setBackground(Color.DARK_GRAY); + setPreferredSize(new Dimension(200, 200)); + setDropTarget(new DropTarget(this, this)); + } + + public void dragEnter(DropTargetDragEvent dtde) { + if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { + dtde.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE); + } + } + + public void dragOver(DropTargetDragEvent dtde) { + if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { + dtde.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE); + } + } + + public void dropActionChanged(DropTargetDragEvent dtde) { + if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { + dtde.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE); + } + } + + public void dragExit(DropTargetEvent dte) { + + } + + public void drop(DropTargetDropEvent dtde) { + dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE); + if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { + try { + content = (java.util.List)dtde.getTransferable().getTransferData(DataFlavor.javaFileListFlavor); + repaint(); + } catch (UnsupportedFlavorException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + dtde.dropComplete(true); + + + + boolean listsAreEqual = true; + + for (int i = 0; i < content.size(); i++) { + if(!FileListTransferable.files[i].getName().equals(content.get(i).getName())) { + listsAreEqual = false; + } + } + + if (listsAreEqual) { + System.err.println(InterprocessMessages.EXECUTION_IS_SUCCESSFULL); + System.exit(0); + } + } + dtde.rejectDrop(); + System.err.println(InterprocessMessages.FILES_ON_TARGET_ARE_CORRUPTED); + System.exit(1); + } + + public void paint(Graphics g) { + g.setColor(Color.YELLOW); + int i = 0; + for (Iterator iterator = content.iterator(); iterator.hasNext();i++) { + g.drawString(iterator.next().getName(), 5, g.getFontMetrics().getAscent()*i+20); + } + + } + +}