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.dnd.DragGestureListener;
0N/Aimport java.awt.dnd.DragSource;
0N/Aimport java.awt.dnd.DnDConstants;
0N/Aimport java.awt.dnd.DragGestureEvent;
0N/Aimport java.io.File;
0N/Aimport java.util.Arrays;
0N/A
0N/A
0N/Aclass SourceFileListFrame extends Frame implements DragGestureListener {
0N/A
0N/A private final static int SOURCE_POINT_SHIFT = 3;
0N/A
0N/A private List list = new List(FileListBetweenJVMsTest.VISIBLE_RAWS_IN_LIST);
0N/A private File[] files;
0N/A
0N/A SourceFileListFrame() {
0N/A super("Source File List Frame");
0N/A extractFilesFromTheWorkingDirectory();
0N/A initList();
0N/A initGUI();
0N/A new DragSource().createDefaultDragGestureRecognizer(list,
0N/A DnDConstants.ACTION_COPY,this);
0N/A }
0N/A
0N/A private void extractFilesFromTheWorkingDirectory() {
0N/A files = new File(System.getProperty("java.home", "")).listFiles();
0N/A }
0N/A
0N/A private void initList() {
0N/A for (File currFile:files) {
0N/A list.add(currFile.getName());
0N/A }
0N/A }
0N/A
0N/A private void initGUI() {
0N/A this.addWindowListener(Util.getClosingWindowAdapter());
0N/A this.setLocation(300,250);
0N/A this.add(new Panel().add(list));
0N/A this.pack();
0N/A this.setVisible(true);
0N/A }
0N/A
0N/A int getNextLocationX() {
0N/A return getX()+getWidth();
0N/A }
0N/A
0N/A int getNextLocationY() {
0N/A return getY();
0N/A }
0N/A
0N/A int getDragSourcePointX() {
0N/A return (int)list.getLocationOnScreen().getX()+(list.getWidth()/2);
0N/A }
0N/A
0N/A int getDragSourcePointY() {
0N/A return (int)list.getLocationOnScreen().getY()+ SOURCE_POINT_SHIFT;
0N/A }
0N/A
0N/A int getSourceFilesNumber() {
0N/A return files.length;
0N/A }
0N/A
0N/A public void dragGestureRecognized(DragGestureEvent dge) {
0N/A String [] filesAsStringArray = list.getItems();
0N/A File [] files = new File[filesAsStringArray.length];
0N/A for (int fileNumber=0; fileNumber<filesAsStringArray.length ; fileNumber++ ) {
0N/A files[fileNumber]=new File(filesAsStringArray[fileNumber]);
0N/A }
0N/A dge.startDrag(null, new FileListTransferable(Arrays.asList(files)));
0N/A }
0N/A}