jdk/test/java/awt/dnd/URIListToFileListBetweenJVMsTest/SourceFileListFrame.java
changeset 23238 57997d148fc0
equal deleted inserted replaced
22040:cb0198e8d989 23238:57997d148fc0
       
     1 /*
       
     2  * Copyright (c) 2013, 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 
       
    24 import test.java.awt.regtesthelpers.Util;
       
    25 
       
    26 import java.awt.*;
       
    27 import java.awt.dnd.DnDConstants;
       
    28 import java.awt.dnd.DragGestureEvent;
       
    29 import java.awt.dnd.DragGestureListener;
       
    30 import java.awt.dnd.DragSource;
       
    31 import java.io.File;
       
    32 import java.net.URI;
       
    33 import java.util.Arrays;
       
    34 import java.util.stream.Collectors;
       
    35 import java.util.stream.Stream;
       
    36 
       
    37 
       
    38 class SourceFileListFrame extends Frame implements DragGestureListener {
       
    39 
       
    40     private final static int SOURCE_POINT_SHIFT = 3;
       
    41 
       
    42     private List list = new List(URIListToFileListBetweenJVMsTest.VISIBLE_RAWS_IN_LIST);
       
    43     private File[] files;
       
    44 
       
    45     SourceFileListFrame() {
       
    46         super("Source File List Frame");
       
    47         extractFilesFromTheWorkingDirectory();
       
    48         initList();
       
    49         initGUI();
       
    50         new DragSource().createDefaultDragGestureRecognizer(list,
       
    51                 DnDConstants.ACTION_COPY,this);
       
    52     }
       
    53 
       
    54     private void extractFilesFromTheWorkingDirectory() {
       
    55         files = new File(System.getProperty("java.home", "")).listFiles();
       
    56     }
       
    57 
       
    58     private void initList() {
       
    59         for (File currFile:files) {
       
    60             list.add(currFile.getName());
       
    61         }
       
    62     }
       
    63 
       
    64     private void initGUI() {
       
    65         this.addWindowListener(Util.getClosingWindowAdapter());
       
    66         this.setLocation(300,250);
       
    67         this.add(new Panel().add(list));
       
    68         this.pack();
       
    69         this.setVisible(true);
       
    70     }
       
    71 
       
    72     int getNextLocationX() {
       
    73         return getX()+getWidth();
       
    74     }
       
    75 
       
    76     int getNextLocationY() {
       
    77         return getY();
       
    78     }
       
    79 
       
    80     int getDragSourcePointX() {
       
    81         return (int)list.getLocationOnScreen().getX()+(list.getWidth()/2);
       
    82     }
       
    83 
       
    84    int getDragSourcePointY() {
       
    85         return (int)list.getLocationOnScreen().getY()+ SOURCE_POINT_SHIFT;
       
    86     }
       
    87 
       
    88     int getSourceFilesNumber() {
       
    89         return files.length;
       
    90     }
       
    91 
       
    92     public void dragGestureRecognized(DragGestureEvent dge) {
       
    93         java.util.List<URI> uriList = Stream.of(list.getItems())
       
    94                                                 .map(File::new)
       
    95                                                 .map(File::toURI)
       
    96                                                 .collect(Collectors.toList());
       
    97 
       
    98         dge.startDrag(null, new URIListTransferable(uriList));
       
    99     }
       
   100 }