0N/A/*
2362N/A * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/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.
0N/A */
0N/A
0N/Aimport test.java.awt.regtesthelpers.Util;
0N/A
0N/Aimport java.awt.*;
0N/Aimport java.awt.datatransfer.DataFlavor;
0N/Aimport java.awt.datatransfer.UnsupportedFlavorException;
0N/Aimport java.awt.event.WindowAdapter;
0N/Aimport java.awt.event.WindowEvent;
0N/Aimport java.awt.dnd.*;
0N/Aimport java.io.File;
0N/Aimport java.io.IOException;
0N/A
0N/Aclass TargetFileListFrame extends Frame implements DropTargetListener {
0N/A
0N/A private List list = new List(FileListBetweenJVMsTest.VISIBLE_RAWS_IN_LIST);
0N/A private int expectationTransferredFilesNumber;
0N/A
0N/A TargetFileListFrame(Point location, int expectationTransferredFilesNumber) {
0N/A this.expectationTransferredFilesNumber = expectationTransferredFilesNumber;
0N/A initGUI(location);
0N/A setDropTarget(new DropTarget(list, DnDConstants.ACTION_COPY,
0N/A this));
0N/A }
0N/A
0N/A private void initGUI(Point location) {
0N/A this.setLocation(location);
0N/A this.addWindowListener(new WindowAdapter() {
0N/A public void windowClosing(WindowEvent e) {
0N/A TargetFileListFrame.this.dispose();
0N/A }
0N/A });
0N/A this.add(new Panel().add(list));
0N/A this.pack();
0N/A this.setVisible(true);
0N/A }
0N/A
0N/A public void dragEnter(DropTargetDragEvent dtde) {
0N/A if (dtde.getCurrentDataFlavorsAsList().contains(DataFlavor.javaFileListFlavor)) {
0N/A dtde.acceptDrag(DnDConstants.ACTION_COPY);
0N/A }
0N/A }
0N/A
0N/A public void dragOver(DropTargetDragEvent dtde) {
0N/A if (dtde.getCurrentDataFlavorsAsList().contains(DataFlavor.javaFileListFlavor)) {
0N/A dtde.acceptDrag(DnDConstants.ACTION_COPY);
0N/A }
0N/A }
0N/A
0N/A public void dropActionChanged(DropTargetDragEvent dtde) {
0N/A if (dtde.getCurrentDataFlavorsAsList().contains(DataFlavor.javaFileListFlavor)) {
0N/A dtde.acceptDrag(DnDConstants.ACTION_COPY);
0N/A }
0N/A }
0N/A
0N/A public void dragExit(DropTargetEvent dte) {}
0N/A
0N/A public void drop(DropTargetDropEvent dtde) {
0N/A list.removeAll();
0N/A dtde.acceptDrop(DnDConstants.ACTION_COPY);
0N/A java.util.List<File> fileList = extractListOfFiles(dtde);
0N/A for (File file:fileList) {
0N/A list.add(file.getName());
0N/A }
0N/A
0N/A if (fileList.size() != expectationTransferredFilesNumber)
0N/A {
0N/A System.err.println("ERROR: Expected file number:"
0N/A + expectationTransferredFilesNumber
0N/A + "; Received file number: "
0N/A + fileList.size());
0N/A TargetFileListFrame.this.dispose();
0N/A System.exit(InterprocessMessages.WRONG_FILES_NUMBER_ON_TARGET);
0N/A }
0N/A
0N/A TargetFileListFrame.this.dispose();
0N/A
0N/A }
0N/A
0N/A private java.util.List<File> extractListOfFiles(DropTargetDropEvent dtde) {
0N/A java.util.List<File> fileList = null;
0N/A try {
0N/A fileList = (java.util.List<File>)dtde.getTransferable().
0N/A getTransferData(DataFlavor.javaFileListFlavor);
0N/A } catch (UnsupportedFlavorException e) {
0N/A e.printStackTrace();
0N/A } catch (IOException e) {
0N/A e.printStackTrace();
0N/A }
0N/A return fileList;
0N/A }
0N/A
0N/A Point getDropTargetPoint() {
0N/A return new Point((int)list.getLocationOnScreen().getX()+(list.getWidth()/2),
0N/A (int)list.getLocationOnScreen().getY()+(list.getHeight()/2));
0N/A }
0N/A}