)transfer.getTransferData(DataFlavor.javaFileListFlavor);
+ for(File f : fl){
+ add(new Button(f.getCanonicalPath()));
+ System.out.println("[Target] drop file:" + f.getCanonicalPath());
+ }
+ validate();
+ } catch(Exception ex) {
+ ex.printStackTrace();
+ }
+ setBackground(bgColor);
+ repaint();
+ success = true;
+ }
+ dtde.dropComplete(success);
+ }
+}
diff --git a/jdk/test/java/awt/dnd/ImageDecoratedDnD/DnDSource.java b/jdk/test/java/awt/dnd/ImageDecoratedDnD/DnDSource.java
new file mode 100644
index 00000000000..4c8f392c279
--- /dev/null
+++ b/jdk/test/java/awt/dnd/ImageDecoratedDnD/DnDSource.java
@@ -0,0 +1,235 @@
+/*
+ * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+* AWT Button is a DragSource and also a transferable object
+*/
+
+import java.awt.*;
+import java.awt.datatransfer.*;
+import java.awt.dnd.*;
+import java.io.*;
+
+class DnDSource extends Button implements Transferable,
+ DragGestureListener,
+ DragSourceListener {
+ private DataFlavor df;
+ private transient int dropAction;
+ private final int dragOperation = DnDConstants.ACTION_COPY | DnDConstants.ACTION_MOVE | DnDConstants.ACTION_LINK;
+ DragSource dragSource = new DragSource();
+
+ DnDSource(String label) {
+ super(label);
+ setBackground(Color.yellow);
+ setForeground(Color.blue);
+ df = new DataFlavor(DnDSource.class, "DnDSource");
+
+ dragSource.createDefaultDragGestureRecognizer(
+ this,
+ dragOperation,
+ this
+ );
+ dragSource.addDragSourceListener(this);
+ }
+
+ public void changeCursor(
+ DragSourceContext dsc,
+ int ra
+ ) {
+ java.awt.Cursor c = null;
+ if ((ra & DnDConstants.ACTION_LINK) == DnDConstants.ACTION_LINK)
+ c = DragSource.DefaultLinkDrop;
+ else if ((ra & DnDConstants.ACTION_MOVE) == DnDConstants.ACTION_MOVE)
+ c = MyCursor.MOVE;//DragSource.DefaultMoveDrop;
+ else if ((ra & DnDConstants.ACTION_COPY) == DnDConstants.ACTION_COPY)
+ c = MyCursor.COPY;
+ else
+ c = MyCursor.NO_DROP;
+ dsc.setCursor(c);
+ }
+
+ /**
+ * a Drag gesture has been recognized
+ */
+
+ public void dragGestureRecognized(DragGestureEvent dge) {
+ System.out.println("starting Drag");
+ try {
+ if (DragSource.isDragImageSupported()) {
+ System.out.println("starting Imaged Drag");
+ dge.startDrag(
+ null,
+ new ImageGenerator(50, 100, new Color(0xff, 0xff, 0xff, 0x00) ) {
+ @Override public void paint(Graphics gr) {
+ gr.translate(width/2, height/2);
+ ((Graphics2D)gr).setStroke(new BasicStroke(3));
+ int R = width/4+5;
+ gr.setColor(new Color(0x00, 0x00, 0xff, 0x7F));
+ gr.fillRect(-R, -R, 2*R, 2*R);
+ gr.setColor(new Color(0x00, 0x00, 0xff, 0xff));
+ gr.drawRect(-R, -R, 2*R, 2*R);
+
+
+ gr.translate(10, -10);
+ R -= 5;
+ gr.setColor(Color.RED);
+ gr.fillOval(-R, -R, 2*R, 2*R);
+ gr.setColor(Color.MAGENTA);
+ gr.drawOval(-R, -R, 2*R, 2*R);
+ }
+ }.getImage(),
+ new Point(15, 40),
+ this,
+ this);
+ } else {
+ dge.startDrag(
+ null,
+ this,
+ this);
+ }
+ } catch (InvalidDnDOperationException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * as the hotspot enters a platform dependent drop site
+ */
+
+ public void dragEnter(DragSourceDragEvent dsde) {
+ System.out.println("[Source] dragEnter");
+ changeCursor(
+ dsde.getDragSourceContext(),
+ dsde.getUserAction() & dsde.getDropAction()
+ );
+ }
+
+ /**
+ * as the hotspot moves over a platform dependent drop site
+ */
+ public void dragOver(DragSourceDragEvent dsde) {
+ System.out.println("[Source] dragOver");
+ changeCursor(
+ dsde.getDragSourceContext(),
+ dsde.getUserAction() & dsde.getDropAction()
+ );
+ dropAction = dsde.getUserAction() & dsde.getDropAction();
+ System.out.println("dropAction = " + dropAction);
+ }
+
+ /**
+ * as the hotspot exits a platform dependent drop site
+ */
+ public void dragExit(DragSourceEvent dse) {
+ System.out.println("[Source] dragExit");
+ changeCursor(
+ dse.getDragSourceContext(),
+ DnDConstants.ACTION_NONE
+ );
+ }
+
+ /**
+ * as the operation changes
+ */
+ public void dragGestureChanged(DragSourceDragEvent dsde) {
+ System.out.println("[Source] dragGestureChanged");
+ changeCursor(
+ dsde.getDragSourceContext(),
+ dsde.getUserAction() & dsde.getDropAction()
+ );
+ dropAction = dsde.getUserAction() & dsde.getDropAction();
+ System.out.println("dropAction = " + dropAction);
+ }
+
+
+ /**
+ * as the operation completes
+ */
+ public void dragDropEnd(DragSourceDropEvent dsde) {
+ System.out.println("[Source] dragDropEnd");
+ }
+
+ public void dropActionChanged(DragSourceDragEvent dsde) {
+ System.out.println("[Source] dropActionChanged");
+ dropAction = dsde.getUserAction() & dsde.getDropAction();
+ System.out.println("dropAction = " + dropAction);
+ }
+
+ public DataFlavor[] getTransferDataFlavors() {
+ return new DataFlavor[]{df};
+ }
+
+ public boolean isDataFlavorSupported(DataFlavor sdf) {
+ return df.equals(sdf);
+ }
+
+ public Object getTransferData(DataFlavor tdf) throws UnsupportedFlavorException, IOException {
+ Object copy = null;
+ if( !df.equals(tdf) ){
+ throw new UnsupportedFlavorException(tdf);
+ }
+ Container parent = getParent();
+ switch (dropAction) {
+ case DnDConstants.ACTION_COPY:
+ try {
+ copy = this.clone();
+ } catch (CloneNotSupportedException e) {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream oos = new ObjectOutputStream(baos);
+
+ oos.writeObject(this);
+ ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+ ObjectInputStream ois = new ObjectInputStream(bais);
+ try {
+ copy = ois.readObject();
+ } catch (ClassNotFoundException cnfe) {
+ // do nothing
+ }
+ }
+ parent.add(this);
+ return copy;
+
+ case DnDConstants.ACTION_MOVE:
+ synchronized (this) {
+ if (parent != null) {
+ parent.remove(this);
+ Label label = new Label("[empty]");
+ label.setBackground(Color.cyan);
+ label.setBounds(this.getBounds());
+ parent.add(label);
+ }
+ }
+ return this;
+
+ case DnDConstants.ACTION_LINK:
+ return this;
+
+ default:
+ return null;
+ }
+
+ }
+}
+
diff --git a/jdk/test/java/awt/dnd/ImageDecoratedDnD/DnDTarget.java b/jdk/test/java/awt/dnd/ImageDecoratedDnD/DnDTarget.java
new file mode 100644
index 00000000000..52d39c4928a
--- /dev/null
+++ b/jdk/test/java/awt/dnd/ImageDecoratedDnD/DnDTarget.java
@@ -0,0 +1,113 @@
+/*
+ * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+* Panel is a DropTarget
+*
+*/
+
+import java.awt.*;
+import java.awt.datatransfer.*;
+import java.awt.dnd.*;
+import java.io.*;
+
+
+class DnDTarget extends Panel implements DropTargetListener {
+ private int dragOperation = DnDConstants.ACTION_COPY | DnDConstants.ACTION_MOVE;
+ Color bgColor;
+ Color htColor;
+
+ DnDTarget(Color bgColor, Color htColor) {
+ super();
+ this.bgColor = bgColor;
+ this.htColor = htColor;
+ setBackground(bgColor);
+ setDropTarget(new DropTarget(this, this));
+ }
+
+
+ public void dragEnter(DropTargetDragEvent e) {
+ System.out.println("[Target] dragEnter");
+ setBackground(htColor);
+ repaint();
+ }
+
+ public void dragOver(DropTargetDragEvent e) {
+ System.out.println("[Target] dragOver");
+ }
+
+ public void dragExit(DropTargetEvent e) {
+ System.out.println("[Target] dragExit");
+ setBackground(bgColor);
+ repaint();
+ }
+
+ public void dragScroll(DropTargetDragEvent e) {
+ System.out.println("[Target] dragScroll");
+ }
+
+ public void dropActionChanged(DropTargetDragEvent e) {
+ System.out.println("[Target] dropActionChanged");
+ }
+
+ public void drop(DropTargetDropEvent dtde) {
+ System.out.println("[Target] drop");
+ boolean success = false;
+ if ((dtde.getDropAction() & dragOperation) == 0) {
+ dtde.rejectDrop();
+ Label label = new Label("[no links here :) ]");
+ label.setBackground(Color.cyan);
+ add(label);
+ } else {
+ dtde.acceptDrop(dragOperation);
+ DataFlavor[] dfs = dtde.getCurrentDataFlavors();
+ if (dfs != null && dfs.length >= 1){
+ Transferable transfer = dtde.getTransferable();
+ try {
+ Button button = (Button)transfer.getTransferData(dfs[0]);
+ if( button != null ){
+ add(button);
+ success = true;
+ }
+ } catch (IOException ioe) {
+ System.out.println(ioe.getMessage());
+ return;
+ } catch (UnsupportedFlavorException ufe) {
+ System.out.println(ufe.getMessage());
+ return;
+ } catch (Exception e) {
+ System.out.println(e.getMessage());
+ return;
+ }
+ }
+ }
+ setBackground(bgColor);
+ dtde.dropComplete(success);
+
+ invalidate();
+ validate();
+ repaint();
+ }
+}
diff --git a/jdk/test/java/awt/dnd/ImageDecoratedDnD/ImageDecoratedDnD.html b/jdk/test/java/awt/dnd/ImageDecoratedDnD/ImageDecoratedDnD.html
new file mode 100644
index 00000000000..620eea04d9b
--- /dev/null
+++ b/jdk/test/java/awt/dnd/ImageDecoratedDnD/ImageDecoratedDnD.html
@@ -0,0 +1,20 @@
+
+
+
+ ImageDecoratedDnD
+
+
+
+ImageDecoratedDnD
Bug ID: 4874070
+
+ See the dialog box (usually in upper left corner) for instructions
+
+
+
+
diff --git a/jdk/test/java/awt/dnd/ImageDecoratedDnD/ImageDecoratedDnD.java b/jdk/test/java/awt/dnd/ImageDecoratedDnD/ImageDecoratedDnD.java
new file mode 100644
index 00000000000..fe5e82084ff
--- /dev/null
+++ b/jdk/test/java/awt/dnd/ImageDecoratedDnD/ImageDecoratedDnD.java
@@ -0,0 +1,199 @@
+/*
+ * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ test %W% %E%
+ @bug 4874070
+ @summary Tests basic DnD functionality
+ @author Your Name: Alexey Utkin area=dnd
+ @run applet/manual=yesno ImageDecoratedDnD.html
+*/
+
+import java.applet.Applet;
+import java.awt.*;
+import java.awt.dnd.DragSource;
+
+
+
+public class ImageDecoratedDnD extends Applet {
+ //Declare things used in the test, like buttons and labels here
+
+ public void init() {
+ //Create instructions for the user here, as well as set up
+ // the environment -- set the layout manager, add buttons,
+ // etc.
+ this.setLayout(new BorderLayout());
+
+ String[] instructions =
+ {
+ "A Frame, which contains a yellow button labeled \"Drag ME!\" and ",
+ "a red panel, will appear below. ",
+ "1. Click on the button and drag to the red panel. ",
+ "2. When the mouse enters the red panel during the drag, the panel ",
+ "should turn yellow. On the systems that supports pictured drag, ",
+ "the image under the drag-cursor should appear (ancor is shifted ",
+ "from top-left corner of the picture inside the picture to 10pt in both dimensions ). ",
+ "In WIN32 systems the image under cursor would be visible ONLY over ",
+ "the drop targets with activated extended OLE D\'n\'D support (that are ",
+ "the desktop and IE ).",
+ "3. Release the mouse button.",
+ "The panel should turn red again and a yellow button labeled ",
+ "\"Drag ME!\" should appear inside the panel. You should be able ",
+ "to repeat this operation multiple times."
+ };
+ Sysout.createDialogWithInstructions(instructions);
+
+ }//End init()
+
+ public void start() {
+ Frame f = new Frame("Use keyboard for DnD change");
+ Panel mainPanel;
+ Component dragSource, dropTarget;
+
+ f.setBounds(0, 400, 200, 200);
+ f.setLayout(new BorderLayout());
+
+ mainPanel = new Panel();
+ mainPanel.setLayout(new BorderLayout());
+
+ mainPanel.setBackground(Color.blue);
+
+ dropTarget = new DnDTarget(Color.red, Color.yellow);
+ dragSource = new DnDSource("Drag ME! (" + (DragSource.isDragImageSupported()?"with ":"without") + " image)" );
+
+ mainPanel.add(dragSource, "North");
+ mainPanel.add(dropTarget, "Center");
+ f.add(mainPanel, BorderLayout.CENTER);
+
+ f.setVisible(true);
+ }// start()
+}// class DnDAcceptanceTest
+
+
+/**
+ * *************************************************
+ * Standard Test Machinery
+ * DO NOT modify anything below -- it's a standard
+ * chunk of code whose purpose is to make user
+ * interaction uniform, and thereby make it simpler
+ * to read and understand someone else's test.
+ * **************************************************
+ */
+class Sysout {
+ private static TestDialog dialog;
+
+ public static void createDialogWithInstructions(String[] instructions) {
+ dialog = new TestDialog(new Frame(), "Instructions");
+ dialog.printInstructions(instructions);
+ dialog.show();
+ println("Any messages for the tester will display here.");
+ }
+
+ public static void createDialog() {
+ dialog = new TestDialog(new Frame(), "Instructions");
+ String[] defInstr = {"Instructions will appear here. ", ""};
+ dialog.printInstructions(defInstr);
+ dialog.show();
+ println("Any messages for the tester will display here.");
+ }
+
+
+ public static void printInstructions(String[] instructions) {
+ dialog.printInstructions(instructions);
+ }
+
+
+ public static void println(String messageIn) {
+ dialog.displayMessage(messageIn);
+ }
+
+}// Sysout class
+
+
+class TestDialog extends Dialog {
+
+ TextArea instructionsText;
+ TextArea messageText;
+ int maxStringLength = 80;
+
+ //DO NOT call this directly, go through Sysout
+ public TestDialog(Frame frame, String name) {
+ super(frame, name);
+ int scrollBoth = TextArea.SCROLLBARS_BOTH;
+ instructionsText = new TextArea("", 15, maxStringLength, scrollBoth);
+ add("North", instructionsText);
+
+ messageText = new TextArea("", 5, maxStringLength, scrollBoth);
+ add("South", messageText);
+
+ pack();
+
+ show();
+ }// TestDialog()
+
+ //DO NOT call this directly, go through Sysout
+ public void printInstructions(String[] instructions) {
+ //Clear out any current instructions
+ instructionsText.setText("");
+
+ //Go down array of instruction strings
+
+ String printStr, remainingStr;
+ for (int i = 0; i < instructions.length; i++) {
+ //chop up each into pieces maxSringLength long
+ remainingStr = instructions[i];
+ while (remainingStr.length() > 0) {
+ //if longer than max then chop off first max chars to print
+ if (remainingStr.length() >= maxStringLength) {
+ //Try to chop on a word boundary
+ int posOfSpace = remainingStr.
+ lastIndexOf(' ', maxStringLength - 1);
+
+ if (posOfSpace <= 0) posOfSpace = maxStringLength - 1;
+
+ printStr = remainingStr.substring(0, posOfSpace + 1);
+ remainingStr = remainingStr.substring(posOfSpace + 1);
+ }
+ //else just print
+ else {
+ printStr = remainingStr;
+ remainingStr = "";
+ }
+
+ instructionsText.append(printStr + "\n");
+
+ }// while
+
+ }// for
+
+ }//printInstructions()
+
+ //DO NOT call this directly, go through Sysout
+ public void displayMessage(String messageIn) {
+ messageText.append(messageIn + "\n");
+ }
+
+}// TestDialog class
+
diff --git a/jdk/test/java/awt/dnd/ImageDecoratedDnD/ImageGenerator.java b/jdk/test/java/awt/dnd/ImageDecoratedDnD/ImageGenerator.java
new file mode 100644
index 00000000000..da6484a2d15
--- /dev/null
+++ b/jdk/test/java/awt/dnd/ImageDecoratedDnD/ImageGenerator.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * Image generator for cursor and drag
+ */
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.Image;
+import java.awt.image.BufferedImage;
+
+public abstract class ImageGenerator
+{
+ public int width;
+ public int height;
+ private final BufferedImage bi;
+ public ImageGenerator(int _width, int _height, Color bgColor)
+ {
+ width = _width;
+ height = _height;
+ bi = new BufferedImage(
+ width,
+ height,
+ BufferedImage.TYPE_INT_ARGB);
+ Graphics gr = bi.getGraphics();
+ if(null==bgColor){
+ bgColor = Color.WHITE;
+ }
+ gr.setColor(bgColor);
+ gr.fillRect(0, 0, width, height);
+ paint(gr);
+ gr.dispose();
+ }
+ public Image getImage() { return bi; }
+
+ public abstract void paint(Graphics gr);
+}
diff --git a/jdk/test/java/awt/dnd/ImageDecoratedDnD/MyCursor.java b/jdk/test/java/awt/dnd/ImageDecoratedDnD/MyCursor.java
new file mode 100644
index 00000000000..a9d2b6d5750
--- /dev/null
+++ b/jdk/test/java/awt/dnd/ImageDecoratedDnD/MyCursor.java
@@ -0,0 +1,86 @@
+/*
+ * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+import java.awt.BasicStroke;
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.Graphics2D;
+import java.awt.Toolkit;
+import java.awt.Point;
+
+/**
+ * An interface provides a set of custom cursors
+ */
+
+public interface MyCursor {
+ public static final java.awt.Cursor NO_DROP = Toolkit.getDefaultToolkit().createCustomCursor(
+ new ImageGenerator(32, 32, new Color(0xff, 0xff, 0xff, 0x00) ) {
+ @Override public void paint(Graphics gr) {
+ gr.setColor(Color.GREEN);
+ ((Graphics2D)gr).setStroke(new BasicStroke(3));
+
+ gr.translate(width/2, height/2);
+ int R = width/4;
+ gr.drawOval(-R, -R, 2*R, 2*R);
+ gr.drawLine(-R, R, R, -R);
+ }
+ }.getImage(),
+ new Point(0, 0),
+ "My NoDrop Cursor"
+ );
+ public static final java.awt.Cursor MOVE = Toolkit.getDefaultToolkit().createCustomCursor(
+ new ImageGenerator(32, 32, new Color(0xff, 0xff, 0xff, 0x00) ) {
+ @Override public void paint(Graphics gr) {
+ gr.setColor(Color.GREEN);
+ ((Graphics2D)gr).setStroke(new BasicStroke(3));
+
+ gr.drawLine(0, 0, width, height);
+ gr.drawLine(0, 0, width/2, 0);
+ gr.drawLine(0, 0, 0, height/2);
+ }
+ }.getImage(),
+ new Point(0, 0),
+ "My Move Cursor"
+ );
+ public static final java.awt.Cursor COPY = Toolkit.getDefaultToolkit().createCustomCursor(
+ new ImageGenerator(32, 32, new Color(0xff, 0xff, 0xff, 0x00) ) {
+ @Override public void paint(Graphics gr) {
+ gr.setColor(Color.GREEN);
+ ((Graphics2D)gr).setStroke(new BasicStroke(3));
+ //arrow
+ gr.drawLine(0, 0, width/2, height/2);
+ gr.drawLine(0, 0, width/2, 0);
+ gr.drawLine(0, 0, 0, height/2);
+ //plus
+ gr.drawRect(width/2 - 1, height/2 -1, width/2 - 1, height/2 - 1);
+ gr.drawLine(width*3/4 - 1, height/2 - 1, width*3/4 - 1, height);
+ gr.drawLine(width/2 - 1, height*3/4 - 1, width, height*3/4 - 1);
+ }
+ }.getImage(),
+ new Point(0, 0),
+ "My Copy Cursor"
+ );
+}
+
diff --git a/jdk/test/java/awt/dnd/ImageDecoratedDnDInOut/DnDSource.java b/jdk/test/java/awt/dnd/ImageDecoratedDnDInOut/DnDSource.java
new file mode 100644
index 00000000000..281d7030294
--- /dev/null
+++ b/jdk/test/java/awt/dnd/ImageDecoratedDnDInOut/DnDSource.java
@@ -0,0 +1,235 @@
+/*
+ * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+* AWT Button is a DragSource and also a transferable object
+*/
+
+import java.awt.*;
+import java.awt.datatransfer.*;
+import java.awt.dnd.*;
+import java.io.*;
+
+class DnDSource extends Button implements Transferable,
+ DragGestureListener,
+ DragSourceListener {
+ private DataFlavor df;
+ private transient int dropAction;
+ private final int dragOperation = DnDConstants.ACTION_COPY | DnDConstants.ACTION_MOVE | DnDConstants.ACTION_LINK;
+ DragSource dragSource = new DragSource();
+
+ DnDSource(String label) {
+ super(label);
+ setBackground(Color.yellow);
+ setForeground(Color.blue);
+ df = new DataFlavor(DnDSource.class, "DnDSource");
+
+ dragSource.createDefaultDragGestureRecognizer(
+ this,
+ dragOperation,
+ this
+ );
+ dragSource.addDragSourceListener(this);
+ }
+
+ public void changeCursor(
+ DragSourceContext dsc,
+ int ra
+ ) {
+ java.awt.Cursor c = null;
+ if ((ra & DnDConstants.ACTION_LINK) == DnDConstants.ACTION_LINK)
+ c = DragSource.DefaultLinkDrop;
+ else if ((ra & DnDConstants.ACTION_MOVE) == DnDConstants.ACTION_MOVE)
+ c = MyCursor.MOVE;//DragSource.DefaultMoveDrop;
+ else if ((ra & DnDConstants.ACTION_COPY) == DnDConstants.ACTION_COPY)
+ c = MyCursor.COPY;
+ else
+ c = MyCursor.NO_DROP;
+ dsc.setCursor(c);
+ }
+
+ /**
+ * a Drag gesture has been recognized
+ */
+
+ public void dragGestureRecognized(DragGestureEvent dge) {
+ System.out.println("starting Drag");
+ try {
+ if (DragSource.isDragImageSupported()) {
+ System.out.println("starting Imaged Drag");
+ dge.startDrag(
+ null,
+ new ImageGenerator(50, 100, new Color(0xff, 0xff, 0xff, 0x00) ) {
+ @Override public void paint(Graphics gr) {
+ gr.translate(width/2, height/2);
+ ((Graphics2D)gr).setStroke(new BasicStroke(3));
+ int R = width/4+5;
+ gr.setColor(Color.BLUE);
+ gr.fillRect(-R, -R, 2*R, 2*R);
+ gr.setColor(Color.CYAN);
+ gr.drawRect(-R, -R, 2*R, 2*R);
+
+
+ gr.translate(10, 10);
+ R -= 5;
+ gr.setColor(Color.RED);
+ gr.fillOval(-R, -R, 2*R, 2*R);
+ gr.setColor(Color.MAGENTA);
+ gr.drawOval(-R, -R, 2*R, 2*R);
+ }
+ }.getImage(),
+ new Point(15, 40),
+ this,
+ this);
+ } else {
+ dge.startDrag(
+ null,
+ this,
+ this);
+ }
+ } catch (InvalidDnDOperationException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * as the hotspot enters a platform dependent drop site
+ */
+
+ public void dragEnter(DragSourceDragEvent dsde) {
+ System.out.println("[Source] dragEnter");
+ changeCursor(
+ dsde.getDragSourceContext(),
+ dsde.getUserAction() & dsde.getDropAction()
+ );
+ }
+
+ /**
+ * as the hotspot moves over a platform dependent drop site
+ */
+ public void dragOver(DragSourceDragEvent dsde) {
+ System.out.println("[Source] dragOver");
+ changeCursor(
+ dsde.getDragSourceContext(),
+ dsde.getUserAction() & dsde.getDropAction()
+ );
+ dropAction = dsde.getUserAction() & dsde.getDropAction();
+ System.out.println("dropAction = " + dropAction);
+ }
+
+ /**
+ * as the hotspot exits a platform dependent drop site
+ */
+ public void dragExit(DragSourceEvent dse) {
+ System.out.println("[Source] dragExit");
+ changeCursor(
+ dse.getDragSourceContext(),
+ DnDConstants.ACTION_NONE
+ );
+ }
+
+ /**
+ * as the operation changes
+ */
+ public void dragGestureChanged(DragSourceDragEvent dsde) {
+ System.out.println("[Source] dragGestureChanged");
+ changeCursor(
+ dsde.getDragSourceContext(),
+ dsde.getUserAction() & dsde.getDropAction()
+ );
+ dropAction = dsde.getUserAction() & dsde.getDropAction();
+ System.out.println("dropAction = " + dropAction);
+ }
+
+
+ /**
+ * as the operation completes
+ */
+ public void dragDropEnd(DragSourceDropEvent dsde) {
+ System.out.println("[Source] dragDropEnd");
+ }
+
+ public void dropActionChanged(DragSourceDragEvent dsde) {
+ System.out.println("[Source] dropActionChanged");
+ dropAction = dsde.getUserAction() & dsde.getDropAction();
+ System.out.println("dropAction = " + dropAction);
+ }
+
+ public DataFlavor[] getTransferDataFlavors() {
+ return new DataFlavor[]{df};
+ }
+
+ public boolean isDataFlavorSupported(DataFlavor sdf) {
+ return df.equals(sdf);
+ }
+
+ public Object getTransferData(DataFlavor tdf) throws UnsupportedFlavorException, IOException {
+ Object copy = null;
+ if( !df.equals(tdf) ){
+ throw new UnsupportedFlavorException(tdf);
+ }
+ Container parent = getParent();
+ switch (dropAction) {
+ case DnDConstants.ACTION_COPY:
+ try {
+ copy = this.clone();
+ } catch (CloneNotSupportedException e) {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream oos = new ObjectOutputStream(baos);
+
+ oos.writeObject(this);
+ ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+ ObjectInputStream ois = new ObjectInputStream(bais);
+ try {
+ copy = ois.readObject();
+ } catch (ClassNotFoundException cnfe) {
+ // do nothing
+ }
+ }
+ parent.add(this);
+ return copy;
+
+ case DnDConstants.ACTION_MOVE:
+ synchronized (this) {
+ if (parent != null) {
+ parent.remove(this);
+ Label label = new Label("[empty]");
+ label.setBackground(Color.cyan);
+ label.setBounds(this.getBounds());
+ parent.add(label);
+ }
+ }
+ return this;
+
+ case DnDConstants.ACTION_LINK:
+ return this;
+
+ default:
+ return null;
+ }
+
+ }
+}
+
diff --git a/jdk/test/java/awt/dnd/ImageDecoratedDnDInOut/DnDTarget.java b/jdk/test/java/awt/dnd/ImageDecoratedDnDInOut/DnDTarget.java
new file mode 100644
index 00000000000..52d39c4928a
--- /dev/null
+++ b/jdk/test/java/awt/dnd/ImageDecoratedDnDInOut/DnDTarget.java
@@ -0,0 +1,113 @@
+/*
+ * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+* Panel is a DropTarget
+*
+*/
+
+import java.awt.*;
+import java.awt.datatransfer.*;
+import java.awt.dnd.*;
+import java.io.*;
+
+
+class DnDTarget extends Panel implements DropTargetListener {
+ private int dragOperation = DnDConstants.ACTION_COPY | DnDConstants.ACTION_MOVE;
+ Color bgColor;
+ Color htColor;
+
+ DnDTarget(Color bgColor, Color htColor) {
+ super();
+ this.bgColor = bgColor;
+ this.htColor = htColor;
+ setBackground(bgColor);
+ setDropTarget(new DropTarget(this, this));
+ }
+
+
+ public void dragEnter(DropTargetDragEvent e) {
+ System.out.println("[Target] dragEnter");
+ setBackground(htColor);
+ repaint();
+ }
+
+ public void dragOver(DropTargetDragEvent e) {
+ System.out.println("[Target] dragOver");
+ }
+
+ public void dragExit(DropTargetEvent e) {
+ System.out.println("[Target] dragExit");
+ setBackground(bgColor);
+ repaint();
+ }
+
+ public void dragScroll(DropTargetDragEvent e) {
+ System.out.println("[Target] dragScroll");
+ }
+
+ public void dropActionChanged(DropTargetDragEvent e) {
+ System.out.println("[Target] dropActionChanged");
+ }
+
+ public void drop(DropTargetDropEvent dtde) {
+ System.out.println("[Target] drop");
+ boolean success = false;
+ if ((dtde.getDropAction() & dragOperation) == 0) {
+ dtde.rejectDrop();
+ Label label = new Label("[no links here :) ]");
+ label.setBackground(Color.cyan);
+ add(label);
+ } else {
+ dtde.acceptDrop(dragOperation);
+ DataFlavor[] dfs = dtde.getCurrentDataFlavors();
+ if (dfs != null && dfs.length >= 1){
+ Transferable transfer = dtde.getTransferable();
+ try {
+ Button button = (Button)transfer.getTransferData(dfs[0]);
+ if( button != null ){
+ add(button);
+ success = true;
+ }
+ } catch (IOException ioe) {
+ System.out.println(ioe.getMessage());
+ return;
+ } catch (UnsupportedFlavorException ufe) {
+ System.out.println(ufe.getMessage());
+ return;
+ } catch (Exception e) {
+ System.out.println(e.getMessage());
+ return;
+ }
+ }
+ }
+ setBackground(bgColor);
+ dtde.dropComplete(success);
+
+ invalidate();
+ validate();
+ repaint();
+ }
+}
diff --git a/jdk/test/java/awt/dnd/ImageDecoratedDnDInOut/ImageDecoratedDnDInOut.html b/jdk/test/java/awt/dnd/ImageDecoratedDnDInOut/ImageDecoratedDnDInOut.html
new file mode 100644
index 00000000000..15ade246d0c
--- /dev/null
+++ b/jdk/test/java/awt/dnd/ImageDecoratedDnDInOut/ImageDecoratedDnDInOut.html
@@ -0,0 +1,20 @@
+
+
+
+ ImageDecoratedDnDInOut
+
+
+
+ImageDecoratedDnDInOut
Bug ID: 4874070
+
+ See the dialog box (usually in upper left corner) for instructions
+
+
+
+
diff --git a/jdk/test/java/awt/dnd/ImageDecoratedDnDInOut/ImageDecoratedDnDInOut.java b/jdk/test/java/awt/dnd/ImageDecoratedDnDInOut/ImageDecoratedDnDInOut.java
new file mode 100644
index 00000000000..336c561b2cf
--- /dev/null
+++ b/jdk/test/java/awt/dnd/ImageDecoratedDnDInOut/ImageDecoratedDnDInOut.java
@@ -0,0 +1,234 @@
+/*
+ * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ test %W% %E%
+ @bug 4874070
+ @summary Tests basic DnD functionality
+ @author Your Name: Alexey Utkin area=dnd
+ @run applet ImageDecoratedDnDInOut.html
+*/
+
+import java.applet.Applet;
+import java.awt.*;
+import java.awt.Robot;
+import java.awt.event.InputEvent;
+import java.awt.dnd.DragSource;
+
+
+public class ImageDecoratedDnDInOut extends Applet {
+ //Declare things used in the test, like buttons and labels here
+
+ public void init() {
+ //Create instructions for the user here, as well as set up
+ // the environment -- set the layout manager, add buttons,
+ // etc.
+ this.setLayout(new BorderLayout());
+
+ String[] instructions =
+ {
+ "Automatic test.",
+ "A Frame, which contains a yellow button labeled \"Drag ME!\" and ",
+ "a red panel, will appear below. ",
+ "1. The button would be clicked and dragged to the red panel. ",
+ "2. When the mouse enters the red panel during the drag, the panel ",
+ "should turn yellow. On the systems that supports pictured drag, ",
+ "the image under the drag-cursor should appear (ancor is shifted ",
+ "from top-left corner of the picture inside the picture to 10pt in both dimensions ). ",
+ "In WIN32 systems the image under cursor would be visible ONLY over ",
+ "the drop targets with activated extended OLE D\'n\'D support (that are ",
+ "the desktop and IE ).",
+ "3. The mouse would be released.",
+ "The panel should turn red again and a yellow button labeled ",
+ "\"Drag ME!\" should appear inside the panel. "
+ };
+ Sysout.createDialogWithInstructions(instructions);
+
+ }//End init()
+
+ public void start() {
+ Frame f = new Frame("Use keyboard for DnD change");
+ Panel mainPanel;
+ Component dragSource, dropTarget;
+
+ f.setBounds(0, 400, 200, 200);
+ f.setLayout(new BorderLayout());
+
+ mainPanel = new Panel();
+ mainPanel.setLayout(new BorderLayout());
+
+ mainPanel.setBackground(Color.blue);
+
+ dropTarget = new DnDTarget(Color.red, Color.yellow);
+ dragSource = new DnDSource("Drag ME! (" + (DragSource.isDragImageSupported()?"with ":"without") + " image)" );
+
+ mainPanel.add(dragSource, "North");
+ mainPanel.add(dropTarget, "Center");
+ f.add(mainPanel, BorderLayout.CENTER);
+
+ f.setVisible(true);
+ try {
+ Point sourcePoint = dragSource.getLocationOnScreen();
+ Dimension d = dragSource.getSize();
+ sourcePoint.translate(d.width / 2, d.height / 2);
+
+ Robot robot = new Robot();
+ robot.mouseMove(sourcePoint.x, sourcePoint.y);
+ robot.mousePress(InputEvent.BUTTON1_MASK);
+ Thread.sleep(2000);
+ for(int i = 0; i <100; ++i) {
+ robot.mouseMove(
+ sourcePoint.x + d.width / 2 + 10,
+ sourcePoint.y + d.height);
+ Thread.sleep(100);
+
+ robot.mouseMove(sourcePoint.x, sourcePoint.y);
+ Thread.sleep(100);
+
+ robot.mouseMove(
+ sourcePoint.x,
+ sourcePoint.y + d.height);
+ Thread.sleep(100);
+ }
+ sourcePoint.y += d.height;
+ robot.mouseMove(sourcePoint.x, sourcePoint.y);
+ Thread.sleep(100);
+
+ robot.mouseRelease(InputEvent.BUTTON1_MASK);
+ Thread.sleep(4000);
+ } catch( Exception e){
+ e.printStackTrace();
+ throw new RuntimeException("test failed: drop was not successful with exception " + e);
+ }
+
+ }// start()
+}// class DnDAcceptanceTest
+
+
+/**
+ * *************************************************
+ * Standard Test Machinery
+ * DO NOT modify anything below -- it's a standard
+ * chunk of code whose purpose is to make user
+ * interaction uniform, and thereby make it simpler
+ * to read and understand someone else's test.
+ * **************************************************
+ */
+class Sysout {
+ private static TestDialog dialog;
+
+ public static void createDialogWithInstructions(String[] instructions) {
+ dialog = new TestDialog(new Frame(), "Instructions");
+ dialog.printInstructions(instructions);
+ dialog.show();
+ println("Any messages for the tester will display here.");
+ }
+
+ public static void createDialog() {
+ dialog = new TestDialog(new Frame(), "Instructions");
+ String[] defInstr = {"Instructions will appear here. ", ""};
+ dialog.printInstructions(defInstr);
+ dialog.show();
+ println("Any messages for the tester will display here.");
+ }
+
+
+ public static void printInstructions(String[] instructions) {
+ dialog.printInstructions(instructions);
+ }
+
+
+ public static void println(String messageIn) {
+ dialog.displayMessage(messageIn);
+ }
+
+}// Sysout class
+
+
+class TestDialog extends Dialog {
+
+ TextArea instructionsText;
+ TextArea messageText;
+ int maxStringLength = 80;
+
+ //DO NOT call this directly, go through Sysout
+ public TestDialog(Frame frame, String name) {
+ super(frame, name);
+ int scrollBoth = TextArea.SCROLLBARS_BOTH;
+ instructionsText = new TextArea("", 15, maxStringLength, scrollBoth);
+ add("North", instructionsText);
+
+ messageText = new TextArea("", 5, maxStringLength, scrollBoth);
+ add("South", messageText);
+
+ pack();
+
+ show();
+ }// TestDialog()
+
+ //DO NOT call this directly, go through Sysout
+ public void printInstructions(String[] instructions) {
+ //Clear out any current instructions
+ instructionsText.setText("");
+
+ //Go down array of instruction strings
+
+ String printStr, remainingStr;
+ for (int i = 0; i < instructions.length; i++) {
+ //chop up each into pieces maxSringLength long
+ remainingStr = instructions[i];
+ while (remainingStr.length() > 0) {
+ //if longer than max then chop off first max chars to print
+ if (remainingStr.length() >= maxStringLength) {
+ //Try to chop on a word boundary
+ int posOfSpace = remainingStr.
+ lastIndexOf(' ', maxStringLength - 1);
+
+ if (posOfSpace <= 0) posOfSpace = maxStringLength - 1;
+
+ printStr = remainingStr.substring(0, posOfSpace + 1);
+ remainingStr = remainingStr.substring(posOfSpace + 1);
+ }
+ //else just print
+ else {
+ printStr = remainingStr;
+ remainingStr = "";
+ }
+
+ instructionsText.append(printStr + "\n");
+
+ }// while
+
+ }// for
+
+ }//printInstructions()
+
+ //DO NOT call this directly, go through Sysout
+ public void displayMessage(String messageIn) {
+ messageText.append(messageIn + "\n");
+ }
+
+}// TestDialog class
+
diff --git a/jdk/test/java/awt/dnd/ImageDecoratedDnDInOut/ImageGenerator.java b/jdk/test/java/awt/dnd/ImageDecoratedDnDInOut/ImageGenerator.java
new file mode 100644
index 00000000000..da6484a2d15
--- /dev/null
+++ b/jdk/test/java/awt/dnd/ImageDecoratedDnDInOut/ImageGenerator.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * Image generator for cursor and drag
+ */
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.Image;
+import java.awt.image.BufferedImage;
+
+public abstract class ImageGenerator
+{
+ public int width;
+ public int height;
+ private final BufferedImage bi;
+ public ImageGenerator(int _width, int _height, Color bgColor)
+ {
+ width = _width;
+ height = _height;
+ bi = new BufferedImage(
+ width,
+ height,
+ BufferedImage.TYPE_INT_ARGB);
+ Graphics gr = bi.getGraphics();
+ if(null==bgColor){
+ bgColor = Color.WHITE;
+ }
+ gr.setColor(bgColor);
+ gr.fillRect(0, 0, width, height);
+ paint(gr);
+ gr.dispose();
+ }
+ public Image getImage() { return bi; }
+
+ public abstract void paint(Graphics gr);
+}
diff --git a/jdk/test/java/awt/dnd/ImageDecoratedDnDInOut/MyCursor.java b/jdk/test/java/awt/dnd/ImageDecoratedDnDInOut/MyCursor.java
new file mode 100644
index 00000000000..a9d2b6d5750
--- /dev/null
+++ b/jdk/test/java/awt/dnd/ImageDecoratedDnDInOut/MyCursor.java
@@ -0,0 +1,86 @@
+/*
+ * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+import java.awt.BasicStroke;
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.Graphics2D;
+import java.awt.Toolkit;
+import java.awt.Point;
+
+/**
+ * An interface provides a set of custom cursors
+ */
+
+public interface MyCursor {
+ public static final java.awt.Cursor NO_DROP = Toolkit.getDefaultToolkit().createCustomCursor(
+ new ImageGenerator(32, 32, new Color(0xff, 0xff, 0xff, 0x00) ) {
+ @Override public void paint(Graphics gr) {
+ gr.setColor(Color.GREEN);
+ ((Graphics2D)gr).setStroke(new BasicStroke(3));
+
+ gr.translate(width/2, height/2);
+ int R = width/4;
+ gr.drawOval(-R, -R, 2*R, 2*R);
+ gr.drawLine(-R, R, R, -R);
+ }
+ }.getImage(),
+ new Point(0, 0),
+ "My NoDrop Cursor"
+ );
+ public static final java.awt.Cursor MOVE = Toolkit.getDefaultToolkit().createCustomCursor(
+ new ImageGenerator(32, 32, new Color(0xff, 0xff, 0xff, 0x00) ) {
+ @Override public void paint(Graphics gr) {
+ gr.setColor(Color.GREEN);
+ ((Graphics2D)gr).setStroke(new BasicStroke(3));
+
+ gr.drawLine(0, 0, width, height);
+ gr.drawLine(0, 0, width/2, 0);
+ gr.drawLine(0, 0, 0, height/2);
+ }
+ }.getImage(),
+ new Point(0, 0),
+ "My Move Cursor"
+ );
+ public static final java.awt.Cursor COPY = Toolkit.getDefaultToolkit().createCustomCursor(
+ new ImageGenerator(32, 32, new Color(0xff, 0xff, 0xff, 0x00) ) {
+ @Override public void paint(Graphics gr) {
+ gr.setColor(Color.GREEN);
+ ((Graphics2D)gr).setStroke(new BasicStroke(3));
+ //arrow
+ gr.drawLine(0, 0, width/2, height/2);
+ gr.drawLine(0, 0, width/2, 0);
+ gr.drawLine(0, 0, 0, height/2);
+ //plus
+ gr.drawRect(width/2 - 1, height/2 -1, width/2 - 1, height/2 - 1);
+ gr.drawLine(width*3/4 - 1, height/2 - 1, width*3/4 - 1, height);
+ gr.drawLine(width/2 - 1, height*3/4 - 1, width, height*3/4 - 1);
+ }
+ }.getImage(),
+ new Point(0, 0),
+ "My Copy Cursor"
+ );
+}
+
diff --git a/jdk/test/java/awt/dnd/ImageDecoratedDnDNegative/DnDSource.java b/jdk/test/java/awt/dnd/ImageDecoratedDnDNegative/DnDSource.java
new file mode 100644
index 00000000000..5ae8f08ac01
--- /dev/null
+++ b/jdk/test/java/awt/dnd/ImageDecoratedDnDNegative/DnDSource.java
@@ -0,0 +1,273 @@
+/*
+ * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+* AWT Button is a DragSource and also a transferable object
+*/
+
+import java.awt.*;
+import java.awt.datatransfer.*;
+
+import java.awt.image.ImageConsumer;
+import java.awt.image.MemoryImageSource;
+
+import java.awt.dnd.*;
+import java.io.*;
+
+class DnDSource extends Button implements Transferable,
+ DragGestureListener,
+ DragSourceListener {
+ private DataFlavor df;
+ private transient int dropAction;
+ private final int dragOperation = DnDConstants.ACTION_COPY | DnDConstants.ACTION_MOVE | DnDConstants.ACTION_LINK;
+ DragSource dragSource = new DragSource();
+
+ DnDSource(String label) {
+ super(label);
+ setBackground(Color.yellow);
+ setForeground(Color.blue);
+ df = new DataFlavor(DnDSource.class, "DnDSource");
+
+ dragSource.createDefaultDragGestureRecognizer(
+ this,
+ dragOperation,
+ this
+ );
+ dragSource.addDragSourceListener(this);
+ }
+
+ public void changeCursor(
+ DragSourceContext dsc,
+ int ra
+ ) {
+ java.awt.Cursor c = null;
+ if ((ra & DnDConstants.ACTION_LINK) == DnDConstants.ACTION_LINK)
+ c = DragSource.DefaultLinkDrop;
+ else if ((ra & DnDConstants.ACTION_MOVE) == DnDConstants.ACTION_MOVE)
+ c = MyCursor.MOVE;//DragSource.DefaultMoveDrop;
+ else if ((ra & DnDConstants.ACTION_COPY) == DnDConstants.ACTION_COPY)
+ c = MyCursor.COPY;
+ else
+ c = MyCursor.NO_DROP;
+ dsc.setCursor(c);
+ }
+
+ /**
+ * a Drag gesture has been recognized
+ */
+ int iProblem = 0;
+ String[] problem = {"unready", "throw exeption", "good"};
+ public void dragGestureRecognized(DragGestureEvent dge) {
+ System.out.println("starting Drag");
+ if( !DragSource.isDragImageSupported() ) {
+ dge.startDrag(
+ null,
+ this,
+ this);
+ } else {
+ setLabel("Drag ME! (with " + problem[iProblem] + " image)");
+ int w = 100;
+ int h = 100;
+ int pix[] = new int[w * h];
+ int index = 0;
+ for (int y = 0; y < h; y++) {
+ int red = (y * 255) / (h - 1);
+ for (int x = 0; x < w; x++) {
+ int blue = (x * 255) / (w - 1);
+ pix[index++] = (255 << 24) | (red << 16) | blue;
+ }
+ }
+ try{
+ dge.startDrag(
+ null,
+ Toolkit.getDefaultToolkit().createImage(new MemoryImageSource(w, h, pix, 0, w)
+ {
+ @Override
+ public void startProduction(ImageConsumer ic)
+ {
+ switch(iProblem){
+ case 0:
+ //incomplite
+ break;
+ case 1:
+ //exception
+ throw new RuntimeException("test exception 1");
+ default:
+ super.startProduction(ic);
+ break;
+ }
+ }
+ }
+ ),
+ new Point(15, 40) {
+ @Override
+ public double getX() {
+ if(2==iProblem){
+ //never happen
+ throw new RuntimeException("test exception 2");
+ }
+ return x;
+ }
+ @Override
+ public Point getLocation(){
+ //never happen
+ throw new RuntimeException("test exception 3");
+ }
+ },
+ this,
+ this);
+ }catch(InvalidDnDOperationException e){
+ if( iProblem<=2 ){
+ System.err.println("good exception: " + e.getMessage() );
+ } else {
+ System.err.println("bad exception");
+ e.printStackTrace();
+ throw new RuntimeException(e.getMessage());
+ }
+ } finally {
+ ++iProblem;
+ }
+ }
+ }
+
+ /**
+ * as the hotspot enters a platform dependent drop site
+ */
+
+ public void dragEnter(DragSourceDragEvent dsde) {
+ System.out.println("[Source] dragEnter");
+ changeCursor(
+ dsde.getDragSourceContext(),
+ dsde.getUserAction() & dsde.getDropAction()
+ );
+ }
+
+ /**
+ * as the hotspot moves over a platform dependent drop site
+ */
+ public void dragOver(DragSourceDragEvent dsde) {
+ System.out.println("[Source] dragOver");
+ changeCursor(
+ dsde.getDragSourceContext(),
+ dsde.getUserAction() & dsde.getDropAction()
+ );
+ dropAction = dsde.getUserAction() & dsde.getDropAction();
+ System.out.println("dropAction = " + dropAction);
+ }
+
+ /**
+ * as the hotspot exits a platform dependent drop site
+ */
+ public void dragExit(DragSourceEvent dse) {
+ System.out.println("[Source] dragExit");
+ changeCursor(
+ dse.getDragSourceContext(),
+ DnDConstants.ACTION_NONE
+ );
+ }
+
+ /**
+ * as the operation changes
+ */
+ public void dragGestureChanged(DragSourceDragEvent dsde) {
+ System.out.println("[Source] dragGestureChanged");
+ changeCursor(
+ dsde.getDragSourceContext(),
+ dsde.getUserAction() & dsde.getDropAction()
+ );
+ dropAction = dsde.getUserAction() & dsde.getDropAction();
+ System.out.println("dropAction = " + dropAction);
+ }
+
+
+ /**
+ * as the operation completes
+ */
+ public void dragDropEnd(DragSourceDropEvent dsde) {
+ System.out.println("[Source] dragDropEnd");
+ }
+
+ public void dropActionChanged(DragSourceDragEvent dsde) {
+ System.out.println("[Source] dropActionChanged");
+ dropAction = dsde.getUserAction() & dsde.getDropAction();
+ System.out.println("dropAction = " + dropAction);
+ }
+
+ public DataFlavor[] getTransferDataFlavors() {
+ return new DataFlavor[]{df};
+ }
+
+ public boolean isDataFlavorSupported(DataFlavor sdf) {
+ return df.equals(sdf);
+ }
+
+ public Object getTransferData(DataFlavor tdf) throws UnsupportedFlavorException, IOException {
+ Object copy = null;
+ if( !df.equals(tdf) ){
+ throw new UnsupportedFlavorException(tdf);
+ }
+ Container parent = getParent();
+ switch (dropAction) {
+ case DnDConstants.ACTION_COPY:
+ try {
+ copy = this.clone();
+ } catch (CloneNotSupportedException e) {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream oos = new ObjectOutputStream(baos);
+
+ oos.writeObject(this);
+ ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+ ObjectInputStream ois = new ObjectInputStream(bais);
+ try {
+ copy = ois.readObject();
+ } catch (ClassNotFoundException cnfe) {
+ // do nothing
+ }
+ }
+ parent.add(this);
+ return copy;
+
+ case DnDConstants.ACTION_MOVE:
+ synchronized (this) {
+ if (parent != null) {
+ parent.remove(this);
+ Label label = new Label("[empty]");
+ label.setBackground(Color.cyan);
+ label.setBounds(this.getBounds());
+ parent.add(label);
+ }
+ }
+ return this;
+
+ case DnDConstants.ACTION_LINK:
+ return this;
+
+ default:
+ return null;
+ }
+
+ }
+}
+
diff --git a/jdk/test/java/awt/dnd/ImageDecoratedDnDNegative/DnDTarget.java b/jdk/test/java/awt/dnd/ImageDecoratedDnDNegative/DnDTarget.java
new file mode 100644
index 00000000000..52d39c4928a
--- /dev/null
+++ b/jdk/test/java/awt/dnd/ImageDecoratedDnDNegative/DnDTarget.java
@@ -0,0 +1,113 @@
+/*
+ * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+* Panel is a DropTarget
+*
+*/
+
+import java.awt.*;
+import java.awt.datatransfer.*;
+import java.awt.dnd.*;
+import java.io.*;
+
+
+class DnDTarget extends Panel implements DropTargetListener {
+ private int dragOperation = DnDConstants.ACTION_COPY | DnDConstants.ACTION_MOVE;
+ Color bgColor;
+ Color htColor;
+
+ DnDTarget(Color bgColor, Color htColor) {
+ super();
+ this.bgColor = bgColor;
+ this.htColor = htColor;
+ setBackground(bgColor);
+ setDropTarget(new DropTarget(this, this));
+ }
+
+
+ public void dragEnter(DropTargetDragEvent e) {
+ System.out.println("[Target] dragEnter");
+ setBackground(htColor);
+ repaint();
+ }
+
+ public void dragOver(DropTargetDragEvent e) {
+ System.out.println("[Target] dragOver");
+ }
+
+ public void dragExit(DropTargetEvent e) {
+ System.out.println("[Target] dragExit");
+ setBackground(bgColor);
+ repaint();
+ }
+
+ public void dragScroll(DropTargetDragEvent e) {
+ System.out.println("[Target] dragScroll");
+ }
+
+ public void dropActionChanged(DropTargetDragEvent e) {
+ System.out.println("[Target] dropActionChanged");
+ }
+
+ public void drop(DropTargetDropEvent dtde) {
+ System.out.println("[Target] drop");
+ boolean success = false;
+ if ((dtde.getDropAction() & dragOperation) == 0) {
+ dtde.rejectDrop();
+ Label label = new Label("[no links here :) ]");
+ label.setBackground(Color.cyan);
+ add(label);
+ } else {
+ dtde.acceptDrop(dragOperation);
+ DataFlavor[] dfs = dtde.getCurrentDataFlavors();
+ if (dfs != null && dfs.length >= 1){
+ Transferable transfer = dtde.getTransferable();
+ try {
+ Button button = (Button)transfer.getTransferData(dfs[0]);
+ if( button != null ){
+ add(button);
+ success = true;
+ }
+ } catch (IOException ioe) {
+ System.out.println(ioe.getMessage());
+ return;
+ } catch (UnsupportedFlavorException ufe) {
+ System.out.println(ufe.getMessage());
+ return;
+ } catch (Exception e) {
+ System.out.println(e.getMessage());
+ return;
+ }
+ }
+ }
+ setBackground(bgColor);
+ dtde.dropComplete(success);
+
+ invalidate();
+ validate();
+ repaint();
+ }
+}
diff --git a/jdk/test/java/awt/dnd/ImageDecoratedDnDNegative/ImageDecoratedDnDNegative.html b/jdk/test/java/awt/dnd/ImageDecoratedDnDNegative/ImageDecoratedDnDNegative.html
new file mode 100644
index 00000000000..e51c99aad77
--- /dev/null
+++ b/jdk/test/java/awt/dnd/ImageDecoratedDnDNegative/ImageDecoratedDnDNegative.html
@@ -0,0 +1,20 @@
+
+
+
+ ImageDecoratedDnDNegative
+
+
+
+ImageDecoratedDnDInOut
Bug ID: 4874070
+
+ See the dialog box (usually in upper left corner) for the test description
+
+
+
+
diff --git a/jdk/test/java/awt/dnd/ImageDecoratedDnDNegative/ImageDecoratedDnDNegative.java b/jdk/test/java/awt/dnd/ImageDecoratedDnDNegative/ImageDecoratedDnDNegative.java
new file mode 100644
index 00000000000..f542a6837fd
--- /dev/null
+++ b/jdk/test/java/awt/dnd/ImageDecoratedDnDNegative/ImageDecoratedDnDNegative.java
@@ -0,0 +1,268 @@
+/*
+ * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ test %W% %E%
+ @bug 4874070
+ @summary Tests basic DnD functionality
+ @author Your Name: Alexey Utkin area=dnd
+ @run applet ImageDecoratedDnDNegative.html
+*/
+
+import java.applet.Applet;
+import java.awt.*;
+import java.awt.Robot;
+import java.awt.event.InputEvent;
+import java.awt.event.KeyEvent;
+import java.awt.geom.Point2D;
+
+
+import java.awt.dnd.DragSource;
+
+
+public class ImageDecoratedDnDNegative extends Applet {
+ //Declare things used in the test, like buttons and labels here
+
+ public void init() {
+ //Create instructions for the user here, as well as set up
+ // the environment -- set the layout manager, add buttons,
+ // etc.
+ this.setLayout(new BorderLayout());
+
+ String[] instructions =
+ {
+ "Automatic test.",
+ "A Frame, which contains a yellow button labeled \"Drag ME!\" and ",
+ "a red panel, will appear below. ",
+ "1. The button would be clicked and dragged to the red panel. ",
+ "2. When the mouse enters the red panel during the drag, the panel ",
+ "should turn yellow. On the systems that supports pictured drag, ",
+ "the image under the drag-cursor should appear (ancor is shifted ",
+ "from top-left corner of the picture inside the picture to 10pt in both dimensions ). ",
+ "In WIN32 systems the image under cursor would be visible ONLY over ",
+ "the drop targets with activated extended OLE D\'n\'D support (that are ",
+ "the desktop and IE ).",
+ "3. The mouse would be released.",
+ "The panel should turn red again and a yellow button labeled ",
+ "\"Drag ME!\" should appear inside the panel. You should be able ",
+ "to repeat this operation multiple times."
+ };
+ Sysout.createDialogWithInstructions(instructions);
+
+ }//End init()
+
+ public void moveTo(
+ Robot r,
+ Point b,
+ Point e)
+ {
+ Point2D.Double ee = new Point2D.Double(e.getX(), e.getY());
+ Point2D.Double bb = new Point2D.Double(b.getX(), b.getY());
+ final int count = (int)(ee.distance(bb));
+ Point2D.Double c = new Point2D.Double(bb.getX(), bb.getY());
+ for(int i=0; i 0) {
+ //if longer than max then chop off first max chars to print
+ if (remainingStr.length() >= maxStringLength) {
+ //Try to chop on a word boundary
+ int posOfSpace = remainingStr.
+ lastIndexOf(' ', maxStringLength - 1);
+
+ if (posOfSpace <= 0) posOfSpace = maxStringLength - 1;
+
+ printStr = remainingStr.substring(0, posOfSpace + 1);
+ remainingStr = remainingStr.substring(posOfSpace + 1);
+ }
+ //else just print
+ else {
+ printStr = remainingStr;
+ remainingStr = "";
+ }
+
+ instructionsText.append(printStr + "\n");
+
+ }// while
+
+ }// for
+
+ }//printInstructions()
+
+ //DO NOT call this directly, go through Sysout
+ public void displayMessage(String messageIn) {
+ messageText.append(messageIn + "\n");
+ }
+
+}// TestDialog class
+
diff --git a/jdk/test/java/awt/dnd/ImageDecoratedDnDNegative/ImageGenerator.java b/jdk/test/java/awt/dnd/ImageDecoratedDnDNegative/ImageGenerator.java
new file mode 100644
index 00000000000..da6484a2d15
--- /dev/null
+++ b/jdk/test/java/awt/dnd/ImageDecoratedDnDNegative/ImageGenerator.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * Image generator for cursor and drag
+ */
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.Image;
+import java.awt.image.BufferedImage;
+
+public abstract class ImageGenerator
+{
+ public int width;
+ public int height;
+ private final BufferedImage bi;
+ public ImageGenerator(int _width, int _height, Color bgColor)
+ {
+ width = _width;
+ height = _height;
+ bi = new BufferedImage(
+ width,
+ height,
+ BufferedImage.TYPE_INT_ARGB);
+ Graphics gr = bi.getGraphics();
+ if(null==bgColor){
+ bgColor = Color.WHITE;
+ }
+ gr.setColor(bgColor);
+ gr.fillRect(0, 0, width, height);
+ paint(gr);
+ gr.dispose();
+ }
+ public Image getImage() { return bi; }
+
+ public abstract void paint(Graphics gr);
+}
diff --git a/jdk/test/java/awt/dnd/ImageDecoratedDnDNegative/MyCursor.java b/jdk/test/java/awt/dnd/ImageDecoratedDnDNegative/MyCursor.java
new file mode 100644
index 00000000000..a9d2b6d5750
--- /dev/null
+++ b/jdk/test/java/awt/dnd/ImageDecoratedDnDNegative/MyCursor.java
@@ -0,0 +1,86 @@
+/*
+ * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+import java.awt.BasicStroke;
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.Graphics2D;
+import java.awt.Toolkit;
+import java.awt.Point;
+
+/**
+ * An interface provides a set of custom cursors
+ */
+
+public interface MyCursor {
+ public static final java.awt.Cursor NO_DROP = Toolkit.getDefaultToolkit().createCustomCursor(
+ new ImageGenerator(32, 32, new Color(0xff, 0xff, 0xff, 0x00) ) {
+ @Override public void paint(Graphics gr) {
+ gr.setColor(Color.GREEN);
+ ((Graphics2D)gr).setStroke(new BasicStroke(3));
+
+ gr.translate(width/2, height/2);
+ int R = width/4;
+ gr.drawOval(-R, -R, 2*R, 2*R);
+ gr.drawLine(-R, R, R, -R);
+ }
+ }.getImage(),
+ new Point(0, 0),
+ "My NoDrop Cursor"
+ );
+ public static final java.awt.Cursor MOVE = Toolkit.getDefaultToolkit().createCustomCursor(
+ new ImageGenerator(32, 32, new Color(0xff, 0xff, 0xff, 0x00) ) {
+ @Override public void paint(Graphics gr) {
+ gr.setColor(Color.GREEN);
+ ((Graphics2D)gr).setStroke(new BasicStroke(3));
+
+ gr.drawLine(0, 0, width, height);
+ gr.drawLine(0, 0, width/2, 0);
+ gr.drawLine(0, 0, 0, height/2);
+ }
+ }.getImage(),
+ new Point(0, 0),
+ "My Move Cursor"
+ );
+ public static final java.awt.Cursor COPY = Toolkit.getDefaultToolkit().createCustomCursor(
+ new ImageGenerator(32, 32, new Color(0xff, 0xff, 0xff, 0x00) ) {
+ @Override public void paint(Graphics gr) {
+ gr.setColor(Color.GREEN);
+ ((Graphics2D)gr).setStroke(new BasicStroke(3));
+ //arrow
+ gr.drawLine(0, 0, width/2, height/2);
+ gr.drawLine(0, 0, width/2, 0);
+ gr.drawLine(0, 0, 0, height/2);
+ //plus
+ gr.drawRect(width/2 - 1, height/2 -1, width/2 - 1, height/2 - 1);
+ gr.drawLine(width*3/4 - 1, height/2 - 1, width*3/4 - 1, height);
+ gr.drawLine(width/2 - 1, height*3/4 - 1, width, height*3/4 - 1);
+ }
+ }.getImage(),
+ new Point(0, 0),
+ "My Copy Cursor"
+ );
+}
+