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

javaJVMLocalObjectMimeType doesn't notify DropTargetListener properly

XMLWordPrintable

    • mantis
    • x86
    • windows_2000, windows_xp
    • Verified


      ###@###.### 2002-06-14

      Bug4251057 does not fix completely.

      J2SE Version (please include all output from java -version flag):
        java version "1.4.1-beta"
        Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-beta-b14)
        Java HotSpot(TM) Client VM (build 1.4.1-beta-b14, mixed mode)

      Does this problem occur on J2SE 1.3 or 1.4? Yes / No (pick one)
        Yes.

      Operating System Configuration Information (be specific):
        Microsoft Windows XP [Version 5.1.2600] and Win2K.

      Hardware Configuration Information (be specific):
        PIII 650MHz, 384 MB RAM

      Bug Description:
        DnD of javaJVMLocalObjectMimeType doesn't notify DropTargetListener properly


      Steps to Reproduce (be specific):

      It seems that this is related to already closed bugs 4251057 and 4473062.
      Though they are declared as fixed, there still remains a problem.
      Please see the following source code. It's a slighly modified version
      of the code posted as part of the evaluation for the bug 4251057.
      "dragEnter" doesn't get called properly.

      To make the transferable serializable will workaround the problem as
      stated in workaround field.

      Test program:
      ===============
      import java.awt.*;
      import java.awt.dnd.*;
      import java.awt.datatransfer.*;
      import java.io.*;

      public class MyTransferable implements Transferable, ClipboardOwner {

      DataFlavor m_df;

      public MyTransferable()
      {

        String mimeType = DataFlavor.javaJVMLocalObjectMimeType +
           "; class=" + this.getClass().getName();

        m_df = new DataFlavor(mimeType, "Davids String");
      }

      public DataFlavor[] getTransferDataFlavors() {
        DataFlavor[] dfs = new DataFlavor[] {m_df};
        return dfs;
      }

      public boolean isDataFlavorSupported( DataFlavor flavor ) {
        return ( flavor.equals(m_df) );
      }

      public Object getTransferData(DataFlavor flavor)
        throws UnsupportedFlavorException, IOException {
        if (flavor.equals(m_df))
        {
          return this;
        }
        else
        {
          throw new UnsupportedFlavorException (flavor);
        }
      }

      public String toString() {
        return "MyTransferable";
      }

      public void lostOwnership(Clipboard clipboard,
        Transferable contents) {
        System.out.println ("StringTransferable lost ownership of " +
                      clipboard.getName());
        System.out.println ("data: " + contents);
      }

          public static void main(String[] args) {
              new Test();
          }
      }

      class Test {
          final Frame frame = new Frame();
          final Label source = new Label("Source");
          final Label target = new Label("Target");
          final MyTransferable t = new MyTransferable();
          final DragSourceListener dsl = new DragSourceAdapter() {};
          final DragGestureListener dgl = new DragGestureListener() {
                  public void dragGestureRecognized(DragGestureEvent dge) {
                      dge.startDrag(null, t, dsl);
                  }
              };
          final DropTargetListener dtl = new DropTargetAdapter() {
                  ////////// Added by DoHyung ////////////////
                  public void dragEnter(DropTargetDragEvent e) {
                      super.dragEnter(e);
                      System.out.println("Check: " + e);
                  }
                  ////////// Added by DoHyung ////////////////
                  public void dragOver(DropTargetDragEvent e) {
                      super.dragEnter(e);
                      System.out.println("Check2: " + e);
                  }
                  public void drop(DropTargetDropEvent dtde) {
                      dtde.acceptDrop(DnDConstants.ACTION_COPY);
                      final Transferable t = dtde.getTransferable();
                      final DataFlavor[] dfs = t.getTransferDataFlavors();
                      if (dfs.length > 0) {
                          try {
                              System.out.println("Supported flavor=" + dfs[0]);
                              Object obj = t.getTransferData(dfs[0]);
                              dtde.dropComplete(true);
                              target.setText("Drop succeded");
                              frame.pack();
                          } catch (IOException ioe) {
                              ioe.printStackTrace();
                              dtde.dropComplete(false);
                          } catch (UnsupportedFlavorException ufe) {
                              ufe.printStackTrace();
                              dtde.dropComplete(false);
                          }
                      } else {
                          dtde.dropComplete(false);
                      }
                  }
              };
          final DragSource ds = DragSource.getDefaultDragSource();
          final DropTarget dt = new DropTarget(target, dtl);
          final DragGestureRecognizer dgr =
              ds.createDefaultDragGestureRecognizer(source,
                                                    DnDConstants.ACTION_COPY_OR_MOVE,
                                                    dgl);

          public Test() {
              frame.setLayout(new FlowLayout());
              frame.add(source);
              frame.add(target);
              frame.pack();
              frame.setVisible(true);
          }
      }





            dassunw Das Das (Inactive)
            tyao Ting-Yun Ingrid Yao (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: