Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4101794

Retreive from Drag&drop failing on a Java Frame win95 only

    XMLWordPrintable

    Details

    • Subcomponent:
    • CPU:
      x86
    • OS:
      windows_95

      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)
      ======================================================================

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              dmendenhsunw David Mendenhall (Inactive)
              Reporter:
              rmandelsunw Ronan Mandel (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: