1968N/A/*
2362N/A * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
1968N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1968N/A *
1968N/A * This code is free software; you can redistribute it and/or modify it
1968N/A * under the terms of the GNU General Public License version 2 only, as
1968N/A * published by the Free Software Foundation.
1968N/A *
1968N/A * This code is distributed in the hope that it will be useful, but WITHOUT
1968N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1968N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1968N/A * version 2 for more details (a copy is included in the LICENSE file that
1968N/A * accompanied this code).
1968N/A *
1968N/A * You should have received a copy of the GNU General Public License version
1968N/A * 2 along with this work; if not, write to the Free Software Foundation,
1968N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1968N/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.
1968N/A */
1968N/A
1968N/Aimport test.java.awt.regtesthelpers.Util;
1968N/A
1968N/Aimport java.awt.*;
1968N/Aimport java.awt.dnd.DragGestureListener;
1968N/Aimport java.awt.dnd.DragSource;
1968N/Aimport java.awt.dnd.DnDConstants;
1968N/Aimport java.awt.dnd.DragGestureEvent;
1968N/Aimport java.io.File;
1968N/Aimport java.util.Arrays;
1968N/A
1968N/A
1968N/Aclass SourceFileListFrame extends Frame implements DragGestureListener {
1968N/A
1968N/A private final static int SOURCE_POINT_SHIFT = 3;
1968N/A
1968N/A private List list = new List(URIListBetweenJVMsTest.VISIBLE_RAWS_IN_LIST);
1968N/A private File[] files;
1968N/A
1968N/A SourceFileListFrame() {
1968N/A super("Source File List Frame");
1968N/A extractFilesFromTheWorkingDirectory();
1968N/A initList();
1968N/A initGUI();
1968N/A new DragSource().createDefaultDragGestureRecognizer(list,
1968N/A DnDConstants.ACTION_COPY,this);
1968N/A }
1968N/A
1968N/A private void extractFilesFromTheWorkingDirectory() {
1968N/A files = new File(System.getProperty("java.home", "")).listFiles();
1968N/A }
1968N/A
1968N/A private void initList() {
1968N/A for (File currFile:files) {
1968N/A list.add(currFile.getName());
1968N/A }
1968N/A }
1968N/A
1968N/A private void initGUI() {
1968N/A this.addWindowListener(Util.getClosingWindowAdapter());
1968N/A this.setLocation(300,250);
1968N/A this.add(new Panel().add(list));
1968N/A this.pack();
1968N/A this.setVisible(true);
1968N/A }
1968N/A
1968N/A int getNextLocationX() {
1968N/A return getX()+getWidth();
1968N/A }
1968N/A
1968N/A int getNextLocationY() {
1968N/A return getY();
1968N/A }
1968N/A
1968N/A int getDragSourcePointX() {
1968N/A return (int)list.getLocationOnScreen().getX()+(list.getWidth()/2);
1968N/A }
1968N/A
1968N/A int getDragSourcePointY() {
1968N/A return (int)list.getLocationOnScreen().getY()+ SOURCE_POINT_SHIFT;
1968N/A }
1968N/A
1968N/A int getSourceFilesNumber() {
1968N/A return files.length;
1968N/A }
1968N/A
1968N/A public void dragGestureRecognized(DragGestureEvent dge) {
1968N/A String [] filesAsStringArray = list.getItems();
1968N/A File [] files = new File[filesAsStringArray.length];
1968N/A for (int fileNumber=0; fileNumber<filesAsStringArray.length ; fileNumber++ ) {
1968N/A files[fileNumber]=new File(filesAsStringArray[fileNumber]);
1968N/A }
1968N/A dge.startDrag(null, new FileListTransferable(Arrays.asList(files)));
1968N/A }
1968N/A}