JDK-4286750 : cannot drag text from a Java application to drop into an external application
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.2.0,1.3.0
  • Priority: P1
  • Status: Closed
  • Resolution: Fixed
  • OS:
    generic,solaris_7,windows_95,windows_98,windows_nt generic,solaris_7,windows_95,windows_98,windows_nt
  • CPU: generic,x86,sparc
  • Submitted: 1999-11-01
  • Updated: 2012-10-10
  • Resolved: 2000-10-31
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
1.3.0 kestrelFixed
Related Reports
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Relates :  
Description
jdk1.3-M Drag-N-Drop works for dragging text from an external application
such as Solaris TextEditor or Window's WordPad and dropping it into the
Java application, but not the other way around.


The following sample code demonstrate the problem.

Roger 11/2/99


import java.io.*;
import java.awt.*;
import java.awt.dnd.*;
import java.awt.event.*;
import java.awt.datatransfer.*;

public class dnd extends Frame {

    public static void main(String argv[]) {
        dnd test = new dnd();
    }

    dnd () {


        String textToBeDropped =
	    "\n" +
	    "\tJava, Java, Java.\n\n";

	Panel workPanel = new Panel(new BorderLayout());

        Label dragComponent =
	    new Label(" Drag Me and drop an editor      ", Label.CENTER);
	dragComponent.setBackground(Color.pink);
        dragComponent.setFont(new Font("Courier", Font.BOLD, 32));

	workPanel.add(dragComponent, BorderLayout.NORTH);
    
        TextArea droppedText = 
	    new TextArea(textToBeDropped, 4, 42, TextArea.SCROLLBARS_NONE);
        droppedText.setEditable(false);
        droppedText.setBackground(Color.white);
        droppedText.setFont(new Font("Courier", Font.PLAIN, 14));

        workPanel.add(droppedText, BorderLayout.CENTER);
    
        add(workPanel);      // Add test panel to frame
    
        DnDTest3 dnd =
	    new DnDTest3(dragComponent, textToBeDropped);
        DragGestureRecognizer recognizer=DragSource.getDefaultDragSource().
        createDefaultDragGestureRecognizer(dragComponent,
					   DnDConstants.ACTION_COPY, dnd);
    
        setSize(600, 400);
	setVisible(true);
    }
}

class ComponentTransferable3 implements Transferable  {
    String text = "";
    DataFlavor possibleFlavors[] = {
	new DataFlavor 
	("text/plain; class=java.io.InputStream; charset=iso8859-1",
	 "Latin based language"),
	new DataFlavor 
	("text/plain; class=java.io.InputStream; charset=ascii",
	 "plain ASCII"),
	new DataFlavor 
	("text/enhanced; class=java.io.InputStream; charset=ascii",
	 "enhanced ASCII"),
	new DataFlavor 
	("text/plain; class=java.io.InputStream; charset=unknown",
	 "other ISO standards"),
	// new DataFlavor 
	// ("text/plain; class=java.io.InputStream; charset=unicode",
	//  "Java Unicode")
    };

    ByteArrayInputStream inputS = null;

    public ComponentTransferable3 (String text) {
        this.text = text;
	byte[] bytes = text.getBytes();

	inputS = new ByteArrayInputStream(bytes);

    }

    public DataFlavor[] getTransferDataFlavors() {
        return possibleFlavors;
    }

    public boolean isDataFlavorSupported(DataFlavor flavor) {
        return true;
    }

    public Object getTransferData(DataFlavor flavor) {
        return inputS; 
    }
}


class DnDTest3 implements DragGestureListener {
    String textToBeDropped = "The text to be dragged";
    public Label dragComponent;

    public DnDTest3(Label dragComponent,
		    String textToBeDropped) {
        this.dragComponent = dragComponent;
        this.textToBeDropped = textToBeDropped;
    }


    public void dragGestureRecognized(DragGestureEvent e) {

        ComponentTransferable3 myTransferable = 
	    new ComponentTransferable3(textToBeDropped);
    
        e.startDrag(DragSource.DefaultCopyDrop, myTransferable, 
		    new DragSourceListener() {
	    public void dragEnter(DragSourceDragEvent dsde) {}
	    public void dragOver(DragSourceDragEvent dsde) {}
	    public void dropActionChanged(DragSourceDragEvent dsde) {}
	    public void dragExit(DragSourceEvent dse) {}
	    public void dragDropEnd(DragSourceDropEvent dsde) {}
	});
    }
}

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: generic FIXED IN: kestrel INTEGRATED IN: kestrel VERIFIED IN: kestrel
14-06-2004

EVALUATION DataFlavor.equals(Object) appears to be broken. It does not properly take the charset into account when evaluating equality. As a result, when the SystemFlavorMap builds a flavors to natives map, later entries overwrite previous ones. For example, in the test case, the DataFlavor with charset "ascii" is mapped to TEXT on Win32, but this is overwritten by the DataFlavor with charset "unknown". See Comments for a new test case which lays out the problem very clearly. david.mendenhall@eng 1999-11-02 Reimplemented DataFlavor.equals(Object) and DataFlavor.hashCode() to take the charset into account if the primary type of the DataFlavor is "text". This corrects the bug. david.mendenhall@eng 1999-11-02
02-11-1999