1/*
2 * Copyright (c) 2014, 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/*
25  test
26  @bug 8031964
27  @summary Dragging images from the browser does not work
28  @author Petr Pchelko : area=dnd
29  @library ../../regtesthelpers
30  @build Sysout
31  @run applet/manual=yesno URLDragTest.html
32*/
33
34import test.java.awt.regtesthelpers.Sysout;
35
36import java.applet.Applet;
37import java.awt.*;
38import java.awt.datatransfer.DataFlavor;
39import java.awt.dnd.DnDConstants;
40import java.awt.dnd.DropTarget;
41import java.awt.dnd.DropTargetAdapter;
42import java.awt.dnd.DropTargetDragEvent;
43import java.awt.dnd.DropTargetDropEvent;
44
45public class URLDragTest extends Applet {
46
47
48    @Override
49    public void init() {
50        setBackground(Color.red);
51        setDropTarget(new DropTarget(this,
52                DnDConstants.ACTION_COPY,
53                new DropTargetAdapter() {
54                    @Override
55                    public void dragEnter(DropTargetDragEvent dtde) {
56                        dtde.acceptDrag(DnDConstants.ACTION_COPY);
57                    }
58
59                    @Override
60                    public void dragOver(DropTargetDragEvent dtde) {
61                        dtde.acceptDrag(DnDConstants.ACTION_COPY);
62                    }
63
64                    @Override
65                    public void drop(DropTargetDropEvent dtde) {
66                        dtde.acceptDrop(DnDConstants.ACTION_COPY);
67                        dtde.getCurrentDataFlavorsAsList()
68                                .stream()
69                                .map(DataFlavor::toString)
70                                .forEach(Sysout::println);
71                    }
72                }));
73
74        String[] instructions = {
75                "1) Open the browser.",
76                "2) Drag any image from the browser page to the red square",
77                "3) When the image is dropped you should se the list of available DataFlavors",
78                "4) If you see application/x-java-url and text/uri-list flavors - test PASSED",
79                "5) Otherwise the test is FAILED"};
80        Sysout.createDialogWithInstructions(instructions);
81    }
82
83    @Override
84    public void start() {
85        setSize(200, 200);
86        setVisible(true);
87    }
88}
89