1/* 2 * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24import test.java.awt.regtesthelpers.Util; 25 26import java.awt.*; 27import java.awt.dnd.DragGestureListener; 28import java.awt.dnd.DragSource; 29import java.awt.dnd.DnDConstants; 30import java.awt.dnd.DragGestureEvent; 31import java.io.File; 32import java.util.Arrays; 33 34 35class SourceFileListFrame extends Frame implements DragGestureListener { 36 37 private final static int SOURCE_POINT_SHIFT = 3; 38 39 private List list = new List(URIListBetweenJVMsTest.VISIBLE_RAWS_IN_LIST); 40 private File[] files; 41 42 SourceFileListFrame() { 43 super("Source File List Frame"); 44 extractFilesFromTheWorkingDirectory(); 45 initList(); 46 initGUI(); 47 new DragSource().createDefaultDragGestureRecognizer(list, 48 DnDConstants.ACTION_COPY,this); 49 } 50 51 private void extractFilesFromTheWorkingDirectory() { 52 files = new File(System.getProperty("java.home", "")).listFiles(); 53 } 54 55 private void initList() { 56 for (File currFile:files) { 57 list.add(currFile.getName()); 58 } 59 } 60 61 private void initGUI() { 62 this.addWindowListener(Util.getClosingWindowAdapter()); 63 this.setLocation(300,250); 64 this.add(new Panel().add(list)); 65 this.pack(); 66 this.setVisible(true); 67 } 68 69 int getNextLocationX() { 70 return getX()+getWidth(); 71 } 72 73 int getNextLocationY() { 74 return getY(); 75 } 76 77 int getDragSourcePointX() { 78 return (int)list.getLocationOnScreen().getX()+(list.getWidth()/2); 79 } 80 81 int getDragSourcePointY() { 82 return (int)list.getLocationOnScreen().getY()+ SOURCE_POINT_SHIFT; 83 } 84 85 int getSourceFilesNumber() { 86 return files.length; 87 } 88 89 public void dragGestureRecognized(DragGestureEvent dge) { 90 String [] filesAsStringArray = list.getItems(); 91 File [] files = new File[filesAsStringArray.length]; 92 for (int fileNumber=0; fileNumber<filesAsStringArray.length ; fileNumber++ ) { 93 files[fileNumber]=new File(filesAsStringArray[fileNumber]); 94 } 95 dge.startDrag(null, new FileListTransferable(Arrays.asList(files))); 96 } 97} 98