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

Please make Dragging and Dropping arrays (Like TreePath[]) work.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 1.2.2
    • client-libs
    • generic
    • generic



      Name: krT82822 Date: 09/29/99


      (see revised/expanded test case below)

      This is the Transferable I used to create a generic
      way to drag and drop objects within a single application.
      I tried passing a TreePath[] to the constructor, but
      there is an exception, and the message says "failed to parse."
      I think there is a problem with the MimeType parsing
      for arrays.

      class ObjectTransferable implements Transferable {
              Object obj;
              DataFlavor flavor;
              DataFlavor [] flavors = new DataFlavor[1];

              public ObjectTransferable(Object o) throws ClassNotFoundException {
                      obj = o;
                      flavor = new DataFlavor(DataFlavor.javaJVMLocalObjectMimeType+"; class="+obj.getClass().getName());
                      flavors[0] = flavor;
              }
              public Object getTransferData(DataFlavor df) {
                      return obj;
              }
              public DataFlavor[] getTransferDataFlavors() {
                      return flavors;
              }
              public boolean isDataFlavorSupported(DataFlavor df) {
                      for (int i = 0; i < flavors.length; i++) {
                              if (df.equals(flavors[i])) {
                                      return true;
                              }
                      }
                      return false;
              }
      }
      java version "1.2.2"
      Classic VM (build JDK-1.2.2-W, native threads, sunwjit)
      java full version "JDK-1.2.2-W"

      ----------------------

      9/29/99 add'l feedback from user:

      Well, I can't spare the time either, but in order to improve YOUR
      product, I have included a full test case. See attachment.

      I have a work around. Simply convert your array to a Vector or
      other List. I haven't actually tried this, but I am fairly confident
      that it would work.

      I guess I'm not even sure that passing an array around in a Transferable
      is even possible...

      -------------------

      9/29/99 REVISED TEST CASE:

      import java.awt.datatransfer.*;

      class ObjectTransferable implements Transferable {
              Object obj;
              DataFlavor flavor;
              DataFlavor [] flavors = new DataFlavor[1];

              public ObjectTransferable(Object o) throws ClassNotFoundException {
                      obj = o;
                      flavor = new DataFlavor(DataFlavor.javaJVMLocalObjectMimeType+"; class="+obj.getClass().getName());
                      flavors[0] = flavor;
              }
              public Object getTransferData(DataFlavor df) {
                      return obj;
              }
              public DataFlavor[] getTransferDataFlavors() {
                      return flavors;
              }
              public boolean isDataFlavorSupported(DataFlavor df) {
                      for (int i = 0; i < flavors.length; i++) {
                              if (df.equals(flavors[i])) {
                                      return true;
                              }
                      }
                      return false;
              }
              static public void main (String [] args) {
                      try {
                              System.err.println("This works");
                              new ObjectTransferable(new String());
                              System.err.println("This doesnt");
                              new ObjectTransferable(new String[5]);
                      } catch (Exception e) {
                              e.printStackTrace();
                      }
              }
      }


      (Review ID: 95871)
      ======================================================================

            agerasimsunw Alexander Gerasimov (Inactive)
            kryansunw Kevin Ryan (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: