jdk/test/java/awt/dnd/ImageDecoratedDnDNegative/DnDSource.java
author serb
Tue, 12 Nov 2013 20:24:25 +0400
changeset 21596 0e3a39f29dbc
parent 5506 202f599c92aa
child 23010 6dadb192ad81
permissions -rw-r--r--
8027696: Incorrect copyright header in the tests Reviewed-by: alanb, malenkov, mullan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4831
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4831
diff changeset
     2
 * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
4831
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
     4
 *
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
21596
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 5506
diff changeset
     7
 * published by the Free Software Foundation.
4831
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
     8
 *
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    13
 * accompanied this code).
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    14
 *
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4831
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4831
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4831
diff changeset
    21
 * questions.
4831
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    22
 */
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    23
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    24
/*
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    25
*  AWT Button is a DragSource and also a transferable object
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    26
*/
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    27
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    28
import java.awt.*;
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    29
import java.awt.datatransfer.*;
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    30
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    31
import java.awt.image.ImageConsumer;
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    32
import java.awt.image.MemoryImageSource;
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    33
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    34
import java.awt.dnd.*;
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    35
import java.io.*;
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    36
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    37
class DnDSource extends Button implements Transferable,
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    38
        DragGestureListener,
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    39
        DragSourceListener {
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    40
    private DataFlavor df;
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    41
    private transient int dropAction;
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    42
    private final int dragOperation = DnDConstants.ACTION_COPY | DnDConstants.ACTION_MOVE | DnDConstants.ACTION_LINK;
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    43
    DragSource dragSource = new DragSource();
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    44
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    45
    DnDSource(String label) {
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    46
        super(label);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    47
        setBackground(Color.yellow);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    48
        setForeground(Color.blue);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    49
        df = new DataFlavor(DnDSource.class, "DnDSource");
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    50
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    51
        dragSource.createDefaultDragGestureRecognizer(
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    52
                this,
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    53
                dragOperation,
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    54
                this
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    55
        );
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    56
        dragSource.addDragSourceListener(this);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    57
    }
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    58
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    59
    public void changeCursor(
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    60
            DragSourceContext dsc,
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    61
            int ra
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    62
    ) {
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    63
        java.awt.Cursor c = null;
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    64
        if ((ra & DnDConstants.ACTION_LINK) == DnDConstants.ACTION_LINK)
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    65
            c = DragSource.DefaultLinkDrop;
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    66
        else if ((ra & DnDConstants.ACTION_MOVE) == DnDConstants.ACTION_MOVE)
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    67
            c = MyCursor.MOVE;//DragSource.DefaultMoveDrop;
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    68
        else if ((ra & DnDConstants.ACTION_COPY) == DnDConstants.ACTION_COPY)
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    69
            c = MyCursor.COPY;
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    70
        else
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    71
            c = MyCursor.NO_DROP;
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    72
        dsc.setCursor(c);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    73
    }
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    74
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    75
    /**
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    76
     * a Drag gesture has been recognized
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    77
     */
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    78
    int iProblem = 0;
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    79
    String[] problem = {"unready", "throw exeption", "good"};
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    80
    public void dragGestureRecognized(DragGestureEvent dge) {
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    81
        System.out.println("starting Drag");
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    82
        if( !DragSource.isDragImageSupported() ) {
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    83
            dge.startDrag(
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    84
                    null,
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    85
                    this,
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    86
                    this);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    87
        } else {
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    88
            setLabel("Drag ME! (with " + problem[iProblem] + " image)");
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    89
            int w = 100;
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    90
            int h = 100;
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    91
            int pix[] = new int[w * h];
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    92
            int index = 0;
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    93
            for (int y = 0; y < h; y++) {
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    94
                int red = (y * 255) / (h - 1);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    95
                for (int x = 0; x < w; x++) {
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    96
                    int blue = (x * 255) / (w - 1);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    97
                    pix[index++] = (255 << 24) | (red << 16) | blue;
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    98
                }
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
    99
            }
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   100
            try{
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   101
                dge.startDrag(
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   102
                        null,
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   103
                        Toolkit.getDefaultToolkit().createImage(new MemoryImageSource(w, h, pix, 0, w)
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   104
                            {
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   105
                                @Override
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   106
                                public void startProduction(ImageConsumer ic)
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   107
                                {
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   108
                                    switch(iProblem){
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   109
                                    case 0:
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   110
                                        //incomplite
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   111
                                        break;
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   112
                                    case 1:
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   113
                                        //exception
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   114
                                        throw new RuntimeException("test exception 1");
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   115
                                    default:
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   116
                                        super.startProduction(ic);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   117
                                        break;
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   118
                                    }
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   119
                                }
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   120
                            }
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   121
                        ),
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   122
                        new Point(15, 40) {
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   123
                            @Override
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   124
                            public double getX() {
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   125
                                if(2==iProblem){
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   126
                                    //never happen
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   127
                                    throw new RuntimeException("test exception 2");
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   128
                                }
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   129
                                return x;
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   130
                            }
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   131
                            @Override
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   132
                            public Point getLocation(){
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   133
                                //never happen
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   134
                                throw new RuntimeException("test exception 3");
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   135
                            }
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   136
                        },
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   137
                        this,
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   138
                        this);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   139
            }catch(InvalidDnDOperationException e){
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   140
                if( iProblem<=2 ){
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   141
                    System.err.println("good exception: " + e.getMessage() );
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   142
                } else {
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   143
                    System.err.println("bad exception");
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   144
                    e.printStackTrace();
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   145
                    throw new RuntimeException(e.getMessage());
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   146
                }
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   147
            } finally {
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   148
                ++iProblem;
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   149
            }
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   150
        }
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   151
    }
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   152
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   153
    /**
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   154
     * as the hotspot enters a platform dependent drop site
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   155
     */
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   156
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   157
    public void dragEnter(DragSourceDragEvent dsde) {
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   158
        System.out.println("[Source] dragEnter");
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   159
        changeCursor(
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   160
            dsde.getDragSourceContext(),
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   161
            dsde.getUserAction() & dsde.getDropAction()
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   162
        );
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   163
    }
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   164
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   165
    /**
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   166
     * as the hotspot moves over a platform dependent drop site
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   167
     */
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   168
    public void dragOver(DragSourceDragEvent dsde) {
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   169
        System.out.println("[Source] dragOver");
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   170
        changeCursor(
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   171
            dsde.getDragSourceContext(),
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   172
            dsde.getUserAction() & dsde.getDropAction()
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   173
        );
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   174
        dropAction = dsde.getUserAction() & dsde.getDropAction();
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   175
        System.out.println("dropAction = " + dropAction);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   176
    }
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   177
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   178
    /**
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   179
     * as the hotspot exits a platform dependent drop site
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   180
     */
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   181
    public void dragExit(DragSourceEvent dse) {
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   182
        System.out.println("[Source] dragExit");
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   183
        changeCursor(
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   184
                dse.getDragSourceContext(),
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   185
                DnDConstants.ACTION_NONE
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   186
        );
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   187
    }
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   188
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   189
    /**
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   190
     * as the operation changes
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   191
     */
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   192
    public void dragGestureChanged(DragSourceDragEvent dsde) {
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   193
        System.out.println("[Source] dragGestureChanged");
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   194
        changeCursor(
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   195
            dsde.getDragSourceContext(),
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   196
            dsde.getUserAction() & dsde.getDropAction()
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   197
        );
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   198
        dropAction = dsde.getUserAction() & dsde.getDropAction();
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   199
        System.out.println("dropAction = " + dropAction);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   200
    }
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   201
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   202
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   203
    /**
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   204
     * as the operation completes
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   205
     */
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   206
    public void dragDropEnd(DragSourceDropEvent dsde) {
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   207
        System.out.println("[Source] dragDropEnd");
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   208
    }
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   209
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   210
    public void dropActionChanged(DragSourceDragEvent dsde) {
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   211
        System.out.println("[Source] dropActionChanged");
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   212
        dropAction = dsde.getUserAction() & dsde.getDropAction();
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   213
        System.out.println("dropAction = " + dropAction);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   214
    }
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   215
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   216
    public DataFlavor[] getTransferDataFlavors() {
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   217
        return new DataFlavor[]{df};
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   218
    }
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   219
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   220
    public boolean isDataFlavorSupported(DataFlavor sdf) {
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   221
        return df.equals(sdf);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   222
    }
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   223
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   224
    public Object getTransferData(DataFlavor tdf) throws UnsupportedFlavorException, IOException {
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   225
        Object copy = null;
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   226
        if( !df.equals(tdf) ){
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   227
            throw new UnsupportedFlavorException(tdf);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   228
        }
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   229
        Container parent = getParent();
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   230
        switch (dropAction) {
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   231
            case DnDConstants.ACTION_COPY:
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   232
                try {
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   233
                    copy = this.clone();
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   234
                } catch (CloneNotSupportedException e) {
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   235
                    ByteArrayOutputStream baos = new ByteArrayOutputStream();
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   236
                    ObjectOutputStream oos = new ObjectOutputStream(baos);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   237
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   238
                    oos.writeObject(this);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   239
                    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   240
                    ObjectInputStream ois = new ObjectInputStream(bais);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   241
                    try {
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   242
                        copy = ois.readObject();
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   243
                    } catch (ClassNotFoundException cnfe) {
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   244
                        // do nothing
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   245
                    }
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   246
                }
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   247
                parent.add(this);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   248
                return copy;
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   249
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   250
            case DnDConstants.ACTION_MOVE:
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   251
                synchronized (this) {
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   252
                    if (parent != null) {
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   253
                        parent.remove(this);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   254
                        Label label = new Label("[empty]");
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   255
                        label.setBackground(Color.cyan);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   256
                        label.setBounds(this.getBounds());
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   257
                        parent.add(label);
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   258
                    }
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   259
                }
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   260
                return this;
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   261
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   262
            case DnDConstants.ACTION_LINK:
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   263
                return this;
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   264
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   265
            default:
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   266
                return null;
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   267
        }
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   268
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   269
    }
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   270
}
85d01a4fe115 4874070: invoking DragSource's startDrag with an Image renders no image on drag
uta
parents:
diff changeset
   271