-
Type:
Bug
-
Resolution: Cannot Reproduce
-
Priority:
P3
-
None
-
Affects Version/s: 1.3.0
-
Component/s: client-libs
-
x86
-
windows_nt
Name: boT120536 Date: 02/01/2001
java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)
Bug 4225247 was recently closed. However, in speaking with Sun engineer
David Mendenhall, it appears that the bug fixers ignored the "brad_mann"
and "deep_36" sections of the bug dicussion. Those sections describe how
when using DND in an applet on NS4.75 or IE5.0, a drop does not occur on mouse
release, but rather occurs on mouse release AND subsequent mouse move.
Here are steps to reproduce that bug: (I'm on NT 4.0 sp6, with java 1.3.)
(1) Compile Grid.java. Put the Grid*.class files and an html page that
invokes the Grid applet in a web server directory.
(2) In a browser open the html file. The applet should start,
and you should see two JTables. (Bug happens with lots of objects -
I just use JTable for simplicity.)
(3) Drag a cell with text from the top JTable to the bottom JTable. But before
you drop it in
the bottom JTable, make sure your mouse is absolutely still as you release
the button.
You should see that no drop happens! Now if you move the mouse a bit, the
drop will be registered.
Here is the source code:
import java.util.*;
import javax.swing.*;
import java.awt.dnd.*;
import java.awt.event.*;
import java.awt.*;
import java.awt.datatransfer.*;
public class Grid extends JApplet /*extends JRootPane*/ {
private JTextField m_textField = new JTextField();
private final JTable m_grid = new JTable(10,10);
private final JTable m_grid2 = new JTable(10,10);
public Grid() {
getContentPane().setLayout( new GridLayout(3,0) );
getContentPane().add(m_grid);
getContentPane().add(m_grid2);
getContentPane().add(m_textField);
try {
m_grid.setValueAt( "hello" , 2 , 3 );
}
catch ( Exception e ) {
e.printStackTrace();
}
}
private void initDnd() {
if (m_dragSource == null)
m_dragSource = new DragSource();
m_dragGestureListener = new DragGestureListener() {
final JTable grid = m_grid;
public void dragGestureRecognized( DragGestureEvent e ) {
log( "DragGestureListener: dragGestureRecognized" );
try{
Point p = e.getDragOrigin();
String string = (String)grid.getValueAt( grid.rowAtPoint(p),
grid.columnAtPoint(p) );
Transferable transferable = new StringSelection( string );
m_dragSource.startDrag( e, DragSource.DefaultMoveDrop ,
transferable, m_dragSourceListener );
} catch( Exception ex ) {
ex.printStackTrace();
}
}
};
m_dragGestureRecognizer = m_dragSource.createDragGestureRecognizer(
MouseDragGestureRecognizer.class, m_grid,
DnDConstants.ACTION_COPY_OR_MOVE, m_dragGestureListener);
getContentPane().add(m_grid);
m_grid2.setDropTarget( new DropTarget( m_grid2, m_dropTargetListener )
);
}
private static final void log( String msg ) {
Date time = new Date();
System.out.println( time + ": " + msg );
}
private static DragSource m_dragSource = null; //new DragSource();
private DragGestureListener m_dragGestureListener = null;
private boolean m_dropped = false;
private DragGestureRecognizer m_dragGestureRecognizer = null;
private void dropper(DropTargetDropEvent event) {
boolean success = false;
try {
Transferable transferable = event.getTransferable();
// we accept only Strings
if (transferable.isDataFlavorSupported
(DataFlavor.stringFlavor)){
try{
event.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
String s = (String)transferable.getTransferData (
DataFlavor.stringFlavor);
Point p = event.getLocation();
m_grid2.setValueAt( s , m_grid2.rowAtPoint(p),
m_grid2.columnAtPoint(p) );
event.getDropTargetContext().dropComplete(true);
success = true;
}
catch (Exception e) {
e.printStackTrace();
}
}
}
catch (Exception e) {
e.printStackTrace();
}
if (!success)
event.rejectDrop();
}
DropTargetListener m_dropTargetListener = new DropTargetListener() {
public void dragEnter (DropTargetDragEvent event) {
log( "DropTargetListener: dragEnter");
event.acceptDrag( DnDConstants.ACTION_COPY_OR_MOVE );
}
public void dragExit (DropTargetEvent event) {
log( "DropTargetListener: dragExit");
}
public void dragOver (DropTargetDragEvent event) {
log( "DropTargetListener: dragOver");
event.acceptDrag( DnDConstants.ACTION_COPY_OR_MOVE );
/*if ( m_dropped == true )
dropper(event); */
}
public void dropActionChanged(DropTargetDragEvent event) {
log( "DropTargetListener: dropActionChanged");
}
public void drop(DropTargetDropEvent event) {
log( "DropTargetListener: drop");
dropper(event);
}
};
DragSourceListener m_dragSourceListener = new DragSourceListener() {
MouseEvent e = null;
public void dragEnter (DragSourceDragEvent event) {
m_dropped = false;
log( "DragSourceListener: dragEnter");
}
public void dragExit (DragSourceEvent event) {
log( "DragSourceListener: dragExit");
m_dropped = true;
}
public void dragOver (DragSourceDragEvent event) {
int x = event.getGestureModifiers();
log( "DragSourceListener: dragOver " + x + ":" +
event.getUserAction() );
if ( x == 0 )
m_dropped = true;
}
public void dragDropEnd(DragSourceDropEvent event) {
log( "DragSourceListener: dragDropEnd");
}
public void dropActionChanged(DragSourceDragEvent event) {
log( "DragSourceListener: dropActionChanged");
}
};
public static void main( String[] args ) {
JFrame f = new JFrame();
Grid g = new Grid();
f.getContentPane().add(g);
f.setSize(800,800);
f.addWindowListener(
new WindowAdapter() {
public void windowClosing( WindowEvent e ) {
System.exit(0);
}
}
);
f.setVisible(true);
g.start();
}
private boolean m_startDone = false;
public synchronized void start() {
Thread t = new Thread() {
public void run() {
synchronized(Grid.this) {
while (!m_startDone) {
try{
Grid.this.wait();
}
catch( InterruptedException e ) {
}
}
initDnd();
}
}
};
t.start();
m_startDone = true;
Grid.this.notifyAll();
}
}
(Review ID: 111521)
======================================================================