1967N/A/*
2362N/A * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
1967N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1967N/A *
1967N/A * This code is free software; you can redistribute it and/or modify it
1967N/A * under the terms of the GNU General Public License version 2 only, as
1967N/A * published by the Free Software Foundation.
1967N/A *
1967N/A * This code is distributed in the hope that it will be useful, but WITHOUT
1967N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1967N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1967N/A * version 2 for more details (a copy is included in the LICENSE file that
1967N/A * accompanied this code).
1967N/A *
1967N/A * You should have received a copy of the GNU General Public License version
1967N/A * 2 along with this work; if not, write to the Free Software Foundation,
1967N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1967N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
1967N/A */
1967N/A
1967N/Aimport java.awt.dnd.*;
1967N/Aimport java.awt.*;
1967N/Aimport java.awt.datatransfer.DataFlavor;
1967N/Aimport java.awt.datatransfer.UnsupportedFlavorException;
1967N/Aimport java.io.File;
1967N/Aimport java.io.IOException;
1967N/Aimport java.util.ArrayList;
1967N/Aimport java.util.Collection;
1967N/Aimport java.util.Iterator;
1967N/Aimport java.util.Arrays;
1967N/A
1967N/Apublic class TargetPanel extends Panel implements DropTargetListener{
1967N/A
1967N/A private java.util.List <File> content = new ArrayList<File>();
1967N/A
1967N/A //private final CustomDropTargetListener dropTargetListener = new CustomDropTargetListener();
1967N/A
1967N/A private Frame frame;
1967N/A
1967N/A public TargetPanel (Frame frame)
1967N/A {
1967N/A this.frame = frame;
1967N/A setBackground(Color.DARK_GRAY);
1967N/A setPreferredSize(new Dimension(200, 200));
1967N/A setDropTarget(new DropTarget(this, this));
1967N/A }
1967N/A
1967N/A public void dragEnter(DropTargetDragEvent dtde) {
1967N/A if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
1967N/A dtde.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE);
1967N/A }
1967N/A }
1967N/A
1967N/A public void dragOver(DropTargetDragEvent dtde) {
1967N/A if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
1967N/A dtde.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE);
1967N/A }
1967N/A }
1967N/A
1967N/A public void dropActionChanged(DropTargetDragEvent dtde) {
1967N/A if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
1967N/A dtde.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE);
1967N/A }
1967N/A }
1967N/A
1967N/A public void dragExit(DropTargetEvent dte) {
1967N/A
1967N/A }
1967N/A
1967N/A public void drop(DropTargetDropEvent dtde) {
1967N/A dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
1967N/A if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
1967N/A try {
1967N/A content = (java.util.List)dtde.getTransferable().getTransferData(DataFlavor.javaFileListFlavor);
1967N/A repaint();
1967N/A } catch (UnsupportedFlavorException e) {
1967N/A e.printStackTrace();
1967N/A } catch (IOException e) {
1967N/A e.printStackTrace();
1967N/A }
1967N/A dtde.dropComplete(true);
1967N/A
1967N/A
1967N/A
1967N/A boolean listsAreEqual = true;
1967N/A
1967N/A for (int i = 0; i < content.size(); i++) {
1967N/A if(!FileListTransferable.files[i].getName().equals(content.get(i).getName())) {
1967N/A listsAreEqual = false;
1967N/A }
1967N/A }
1967N/A
1967N/A if (listsAreEqual) {
1967N/A System.err.println(InterprocessMessages.EXECUTION_IS_SUCCESSFULL);
1967N/A System.exit(0);
1967N/A }
1967N/A }
1967N/A dtde.rejectDrop();
1967N/A System.err.println(InterprocessMessages.FILES_ON_TARGET_ARE_CORRUPTED);
1967N/A System.exit(1);
1967N/A }
1967N/A
1967N/A public void paint(Graphics g) {
1967N/A g.setColor(Color.YELLOW);
1967N/A int i = 0;
1967N/A for (Iterator <File> iterator = content.iterator(); iterator.hasNext();i++) {
1967N/A g.drawString(iterator.next().getName(), 5, g.getFontMetrics().getAscent()*i+20);
1967N/A }
1967N/A
1967N/A }
1967N/A
1967N/A}