-
Bug
-
Resolution: Fixed
-
P3
-
1.2.1, 1.3.0, 1.4.0
-
beta2
-
x86, sparc
-
linux, solaris_2.6, windows_nt
-
Verified
Dnd of a button on Solaris causes button be always pressed. When the button is pressed to initiate dnd, and dropped onto the target, the button still remains pressed. The button returns to the released state when button is pressed again.
Tested with JDK1.2.1-I build
Sample code is given below to simulate the same.
Steps to reproduce the problem,
1. Run the application.
2. Drag and drop the button onto the target panel. Button remains pressed.
import java.awt.*;
import java.awt.event.*;
import java.awt.datatransfer.*;
import java.awt.dnd.*;
import java.io.*;
class DnDTarget extends Panel implements DropTargetListener {
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.err.println("[Target] dragEnter");
e.acceptDrag(DnDConstants.ACTION_COPY);
setBackground(htColor);
repaint();
}
public void dragOver(DropTargetDragEvent e) {
System.err.println("[Target] dragOver");
e.acceptDrag(DnDConstants.ACTION_COPY);
}
public void dragExit(DropTargetEvent e) {
System.err.println("[Target] dragExit");
setBackground(bgColor);
repaint();
}
public void drop(DropTargetDropEvent dtde) {
System.err.println("[Target] drop");
DropTargetContext dtc = dtde.getDropTargetContext();
if ((dtde.getSourceActions() & DnDConstants.ACTION_COPY) != 0)
dtde.acceptDrop(DnDConstants.ACTION_COPY);
else {
dtde.rejectDrop();
return;
}
DataFlavor[] dfs = dtde.getCurrentDataFlavors();
if (dfs != null && dfs.length >= 1) {
Transferable transfer = dtde.getTransferable();
Object obj = null;
try {
obj = transfer.getTransferData(dfs[0]);
} catch (IOException ioe) {
System.err.println(ioe.getMessage());
dtc.dropComplete(false);
return;
} catch (UnsupportedFlavorException ufe) {
System.err.println(ufe.getMessage());
dtc.dropComplete(false);
return;
}
if (obj != null) {
Button button = null;
try {
button = (Button)obj;
} catch (Exception e) {
System.err.println(e.getMessage());
dtc.dropComplete(false);
return;
}
add(button);
repaint();
}
}
setBackground(bgColor);
invalidate();
validate();
repaint();
dtc.dropComplete(true);
}
public void dragScroll(DropTargetDragEvent e) {
System.err.println("[Target] dragScroll");
}
public void dropActionChanged(DropTargetDragEvent e) {
System.err.println("[Target] dropActionChanged");
}
Color bgColor;
Color htColor;
}
import java.awt.*;
import java.awt.event.*;
import java.awt.datatransfer.*;
import java.awt.dnd.*;
import java.io.*;
class DnDSource extends Button implements Serializable, Transferable,
DragGestureListener,
DragSourceListener
{
DnDSource(String label) {
super(label);
DragSource ds = DragSource.getDefaultDragSource();
ds.createDefaultDragGestureRecognizer(this, DnDConstants.ACTION_COPY,
this);
setBackground(Color.yellow);
setForeground(Color.blue);
df = new DataFlavor(DnDSource.class, "DnDSource");
}
public void dragGestureRecognized(DragGestureEvent dge) {
System.err.println("starting Drag");
dge.startDrag(null, this, this);
}
public void dragEnter(DragSourceDragEvent dsde) {
System.err.println("[Source] dragEnter");
dsde.getDragSourceContext().setCursor(DragSource.DefaultCopyDrop);
}
public void dragOver(DragSourceDragEvent dsde) {
System.err.println("[Source] dragOver");
dropAction = dsde.getDropAction();
System.out.println("dropAction = " + dropAction);
}
public void dragGestureChanged(DragSourceDragEvent dsde) {
System.err.println("[Source] dragGestureChanged");
dropAction = dsde.getDropAction();
System.out.println("dropAction = " + dropAction);
}
public void dragExit(DragSourceEvent dsde) {
System.err.println("[Source] dragExit");
dsde.getDragSourceContext().setCursor(null);
}
public void dragDropEnd(DragSourceDropEvent dsde) {
System.err.println("[Source] dragDropEnd");
}
public void dropActionChanged(DragSourceDragEvent dsde) {
System.err.println("[Source] dropActionChanged");
dropAction = 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
}
}
return copy;
case DnDConstants.ACTION_MOVE:
synchronized(this) {
if (parent != null) parent.remove(this);
}
return this;
case DnDConstants.ACTION_LINK:
return this;
default:
//throw new IOException("bad operation");
return this; // workaround for: 4135456 getDropAction() always return 0
}
}
private transient DataFlavor df ;
private transient int dropAction;
}
import java.awt.*;
import java.awt.event.*;
import java.awt.datatransfer.*;
import java.awt.dnd.*;
public class ButtonPanel extends Frame {
public ButtonPanel() {
Panel mainPanel;
Component dragSource, dropTarget;
setTitle("ButtonPanel");
setSize(200,200);
setLayout(new BorderLayout());
mainPanel = new Panel();
mainPanel.setLayout(new BorderLayout());
mainPanel.setBackground(Color.black);
dropTarget= new DnDTarget(Color.red, Color.yellow);
dragSource= new DnDSource("Drag ME!");
mainPanel.add(dragSource, "North");
mainPanel.add(dropTarget, "Center");
add(mainPanel, BorderLayout.CENTER);
}
public static void main(String[] args) {
ButtonPanel buttonPanel = new ButtonPanel();
buttonPanel.show();
}
}
Tested with JDK1.2.1-I build
Sample code is given below to simulate the same.
Steps to reproduce the problem,
1. Run the application.
2. Drag and drop the button onto the target panel. Button remains pressed.
import java.awt.*;
import java.awt.event.*;
import java.awt.datatransfer.*;
import java.awt.dnd.*;
import java.io.*;
class DnDTarget extends Panel implements DropTargetListener {
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.err.println("[Target] dragEnter");
e.acceptDrag(DnDConstants.ACTION_COPY);
setBackground(htColor);
repaint();
}
public void dragOver(DropTargetDragEvent e) {
System.err.println("[Target] dragOver");
e.acceptDrag(DnDConstants.ACTION_COPY);
}
public void dragExit(DropTargetEvent e) {
System.err.println("[Target] dragExit");
setBackground(bgColor);
repaint();
}
public void drop(DropTargetDropEvent dtde) {
System.err.println("[Target] drop");
DropTargetContext dtc = dtde.getDropTargetContext();
if ((dtde.getSourceActions() & DnDConstants.ACTION_COPY) != 0)
dtde.acceptDrop(DnDConstants.ACTION_COPY);
else {
dtde.rejectDrop();
return;
}
DataFlavor[] dfs = dtde.getCurrentDataFlavors();
if (dfs != null && dfs.length >= 1) {
Transferable transfer = dtde.getTransferable();
Object obj = null;
try {
obj = transfer.getTransferData(dfs[0]);
} catch (IOException ioe) {
System.err.println(ioe.getMessage());
dtc.dropComplete(false);
return;
} catch (UnsupportedFlavorException ufe) {
System.err.println(ufe.getMessage());
dtc.dropComplete(false);
return;
}
if (obj != null) {
Button button = null;
try {
button = (Button)obj;
} catch (Exception e) {
System.err.println(e.getMessage());
dtc.dropComplete(false);
return;
}
add(button);
repaint();
}
}
setBackground(bgColor);
invalidate();
validate();
repaint();
dtc.dropComplete(true);
}
public void dragScroll(DropTargetDragEvent e) {
System.err.println("[Target] dragScroll");
}
public void dropActionChanged(DropTargetDragEvent e) {
System.err.println("[Target] dropActionChanged");
}
Color bgColor;
Color htColor;
}
import java.awt.*;
import java.awt.event.*;
import java.awt.datatransfer.*;
import java.awt.dnd.*;
import java.io.*;
class DnDSource extends Button implements Serializable, Transferable,
DragGestureListener,
DragSourceListener
{
DnDSource(String label) {
super(label);
DragSource ds = DragSource.getDefaultDragSource();
ds.createDefaultDragGestureRecognizer(this, DnDConstants.ACTION_COPY,
this);
setBackground(Color.yellow);
setForeground(Color.blue);
df = new DataFlavor(DnDSource.class, "DnDSource");
}
public void dragGestureRecognized(DragGestureEvent dge) {
System.err.println("starting Drag");
dge.startDrag(null, this, this);
}
public void dragEnter(DragSourceDragEvent dsde) {
System.err.println("[Source] dragEnter");
dsde.getDragSourceContext().setCursor(DragSource.DefaultCopyDrop);
}
public void dragOver(DragSourceDragEvent dsde) {
System.err.println("[Source] dragOver");
dropAction = dsde.getDropAction();
System.out.println("dropAction = " + dropAction);
}
public void dragGestureChanged(DragSourceDragEvent dsde) {
System.err.println("[Source] dragGestureChanged");
dropAction = dsde.getDropAction();
System.out.println("dropAction = " + dropAction);
}
public void dragExit(DragSourceEvent dsde) {
System.err.println("[Source] dragExit");
dsde.getDragSourceContext().setCursor(null);
}
public void dragDropEnd(DragSourceDropEvent dsde) {
System.err.println("[Source] dragDropEnd");
}
public void dropActionChanged(DragSourceDragEvent dsde) {
System.err.println("[Source] dropActionChanged");
dropAction = 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
}
}
return copy;
case DnDConstants.ACTION_MOVE:
synchronized(this) {
if (parent != null) parent.remove(this);
}
return this;
case DnDConstants.ACTION_LINK:
return this;
default:
//throw new IOException("bad operation");
return this; // workaround for: 4135456 getDropAction() always return 0
}
}
private transient DataFlavor df ;
private transient int dropAction;
}
import java.awt.*;
import java.awt.event.*;
import java.awt.datatransfer.*;
import java.awt.dnd.*;
public class ButtonPanel extends Frame {
public ButtonPanel() {
Panel mainPanel;
Component dragSource, dropTarget;
setTitle("ButtonPanel");
setSize(200,200);
setLayout(new BorderLayout());
mainPanel = new Panel();
mainPanel.setLayout(new BorderLayout());
mainPanel.setBackground(Color.black);
dropTarget= new DnDTarget(Color.red, Color.yellow);
dragSource= new DnDSource("Drag ME!");
mainPanel.add(dragSource, "North");
mainPanel.add(dropTarget, "Center");
add(mainPanel, BorderLayout.CENTER);
}
public static void main(String[] args) {
ButtonPanel buttonPanel = new ButtonPanel();
buttonPanel.show();
}
}
- duplicates
-
JDK-4341903 unix: jck1.3 test api/java_awt/interactive/DnDTests.html#DnDTests fails
-
- Closed
-
- relates to
-
JDK-6295043 Drag source button remains pressed state after dnd
-
- Open
-
-
JDK-4508273 Solaris DnD should not send mouseReleased after DnD
-
- Closed
-
-
JDK-4940356 Focus on wrong list item after DnD operation
-
- Closed
-