JDK-4101794 : Retreive from Drag&drop failing on a Java Frame win95 only
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.2.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_95
  • CPU: x86
  • Submitted: 1998-01-05
  • Updated: 2000-08-03
  • Resolved: 2000-08-03
Related Reports
Duplicate :  
Description

Name: rm29839			Date: 01/05/98


This examples code work correctly on Windows NT,
but fails on Window95. When working, a Java frame
comes up with a text area inside. I can drag some
text from the Wordpad app onto the textarea and 
the dragged text replaces the orginal text when I
drop it. Under Window95 the the step where I 
retrieve the dropped text fails.

This is my debug ouput under Window95:

dropped transferable: java.awt.dnd.DropTargetContext$TransferableProxy@c6fdaa0a
class java.io.InputStream
java.io.ByteArrayInputStream@c7d1aa0a
Bytes Avail: 0
Bytes Read: -1

Obviously, I didn't try to drag a null string 
onto the frame...
_____________________________________________
import java.awt.*;
import java.awt.dnd.*;
import java.awt.datatransfer.*;
import java.awt.event.*;
import java.io.*;

public class DndTest extends Frame implements DropTargetListener {

    DropTarget target;
    TextArea text;

    public DndTest () 
	{
		super("Drop Site");
		text = new TextArea("Grab some text and \npull it over here!");
		target = new DropTarget(text, DnDConstants.ACTION_COPY, this);
		target.setActive (true);
		add ("Center", text);
		enableEvents(AWTEvent.WINDOW_EVENT_MASK);
    }

    public static void main (String args[]) 
	{
		DndTest f = new DndTest();
		f.setSize (400, 200);
		f.setVisible (true);
    }

    ////////////////////////////////////////////////////////// methods in Interface DropTargetListener

    public  void dragEnter (DropTargetDragEvent dtde) 
	{
		// System.out.println ("dragEnter");
		DataFlavor df[] = dtde.getCurrentDataFlavors();
		for (int i = 0; i < df.length; i++)   
		{
		    if (df[i].equals (DataFlavor.plainTextFlavor)) 
			{
				dtde.acceptDrag (DnDConstants.ACTION_COPY);
				return;
			}
		}
		dtde.rejectDrag ();
    }

    public  void dragOver (DropTargetDragEvent dtde) 
	{  /*System.out.println ("dragOver");*/ }

    public  void dragScroll (DropTargetDragEvent dtde) 
	{  /*System.out.println ("dragScroll");*/ }

    public  void dragExit (DropTargetEvent dte) 
	{  System.out.println ("dragExit"); }

    public  void drop (DropTargetDropEvent dtde) 
	{
		dtde.acceptDrop (DnDConstants.ACTION_COPY);

		Transferable trans = dtde.getTransferable();
		DataFlavor df[] = trans.getTransferDataFlavors();
		Object obj = null;
		System.out.println ("dropped transferable: "+trans);

		try 
		{
			for (int i = 0; i < df.length; i++)   
			{
				System.out.println(df[i].getRepresentationClass());
				if (df[i].isRepresentationClassInputStream())
					obj = trans.getTransferData(df[i]);
			}
			//if (trans.isDataFlavorSupported(DataFlavor.plainTextFlavor))
			//	obj = trans.getTransferData(DataFlavor.plainTextFlavor);
			System.out.println (obj);
			if (obj != null) 
			{
				InputStream input = (InputStream) obj;
				System.out.println("Bytes Avail: "+Integer.toString(input.available()));
				StringBuffer str = new StringBuffer();
				byte[] buffer = new byte[64];
				int count = input.read(buffer);
				System.out.println("Bytes Read: "+Integer.toString(count));
				while (count != -1) 
				{
					str.append (new String (buffer, 0, count));
					count = input.read(buffer);
					System.out.println("Bytes: "+Integer.toString(count)+". "+buffer);
				}
				input.close();
				text.setText (str.toString());
			}
		} catch (Exception e) 
		{ e.printStackTrace(); } 
		finally 
		{
			try { target.getDropTargetContext().dropComplete(true); } 
			catch (Exception ignore) {}
		}
    }

    //////////////////////////////////////////////////////////////// other methods

    protected void processWindowEvent (WindowEvent e) 
	{
		if (e.getID() == WindowEvent.WINDOW_CLOSING)
		    System.exit(0);
		super.processWindowEvent (e);
    }

}
(Review ID: 22349)
======================================================================

Comments
EVALUATION Name: rrT76497 Date: 06/25/98 (K. Suresh, SIPTech, June 26, 1998) On Win95 - Bug is reproducible. Tested with JDK-1.2beta4-F On WinNT - Bug is not reproducible. Tested with JDK-1.2beta4-F On Solaris/Intel, Solaris/SPARC - Bug is not reproducible. Tested with JDK-1.2beta3-N ======================================================================
11-06-2004