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

drag & drop action negotiation does not honor the targets supported actions

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P2 P2
    • 6
    • 1.4.1, 1.4.2, 5.0, 6
    • client-libs
    • b81
    • generic, x86
    • generic, windows_nt, windows_2000, windows_xp

      Name: jl125535 Date: 05/23/2003


      FULL PRODUCT VERSION :
      java version "1.4.2-rc"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-rc-b24)
      Java HotSpot(TM) Client VM (build 1.4.2-rc-b24, mixed mode)

      and others - see Description

      FULL OPERATING SYSTEM VERSION :
      Microsoft Windows 2000 [Version 5.00.2195]

      ADDITIONAL OPERATING SYSTEMS : linux (i386)



      A DESCRIPTION OF THE PROBLEM :
      When a drop target supports another action than the default
      (which seems to be move), and indicates that by calling the
      DropTargetDragEvents acceptDrag(action) method during
      dragEnter(), dragOver() or dropActionChanged(), that action
      should be made the current action, as long as the source
      supports it and the user has not explicitely selected
      another operation by holding down modidiers.

      This does not work:
      if the target requests another (source supported) action
      than the current one, the source recieves notifications with
      action=0, even though no explicit user action is requested
      by holding down modifiers.

      alternate actions (i.e. ACTION_COPY or ACTION_LINK) only
      work when the user explicitely holds down the respective
      modifier key.

      for some reason, this does work correctly with jre 1.3.0
      on linux (build 1.3.0_04), but the bug appears with
      all windows versions i tested [(build 1.3.0-C), (build
      1.3.1_02-b02), (build 1.4.0-b92)] and the jre 1.4.0 on linux
      (build 1.4.0-b92)...

      This seems to be a problem on the DragSource side. If you
      drag items from a native application (i.e. a file from
      explorer when running on windows) over a java target that
      only accepts ACTION_LINK for example, that target request is
      correctly handed back to the source (as indicated by the
      changing cursors...)

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. run the attached example DndBug
      2. drag the "source" object over the various targets without
      holding down any modifier keys and watch cursor feedback and
      STDOUT
      3. Drag some native applications objects (a file from
      explorer when running windows) over the various targets of
      the DndBug application without holding down any modifier
      keys and watch cursor feedback and STDOUT


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      Expected:
      When dragging the "source" button over other buttons, the console should display lines such as the following:

      DST: drag over: action=LR, src-act=MCLR, force accept: LR
      SRC: drag over: target=LR, user=0, action=LR

      Actual:
      When dragging the "source" button over other buttons, the console displays lines such as the following:

      DST: drag over: action=M, src-act=MCLR, force accept: LR
      SRC: drag over: target=LR, user=M, action=0

      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.* ;
      import java.awt.datatransfer.* ;
      import java.awt.dnd.* ;
      import java.awt.event.* ;
      import javax.swing.* ;
      import javax.swing.border.* ;

      /**
       * Demonstration of the DnD action negotiation bug.
       * Just compile and run DndBug.
       * Try to drag the "source" to the various targets.
       * Observe STDOUT and cursor feedback.
       * Enjoy.
       * to see, how the negotiation should work:
       * Run DndBug.main on Windows (tested on w2k)
       * drag file from the Windows Explorer over the various targets of DndBug.
       * Observe STDOUT and cursor feedback.
       * Enjoy.
       * Creation date: (30.05.2002 21:40:11)
       * @author: Heiko Hellweg (###@###.###)
       */
      class DndBug {

          class TargetLabel extends JLabel implements DropTargetListener {
      Border std = new EtchedBorder() ;
      Border high = new LineBorder(Color.blue, 2) ;
      int accepted = 0 ;

      public TargetLabel(int actions) {
      super() ;
      // setTransferHandler(null) ; // does not improve it...
      accepted = actions ;
      setBorder(std) ;
      new DropTarget (this, accepted, this);
      }
      private void printActions(DropTargetDragEvent dtde) {
      System.out.println("action="
      + formatActions(dtde.getDropAction())
      + ", src-act="
      + formatActions(dtde.getSourceActions())
      + ", force accept: "
      + formatActions(accepted)
      ) ;
      }
      public void dragEnter(DropTargetDragEvent dtde) {
      System.out.print("DST: drag enter: ") ;
      printActions(dtde) ;
      setBorder(high) ;
      //should set action to accepted, if it is supported
      // by the source and no user action is in effect
      dtde.acceptDrag(accepted) ;
      }
      public void dragOver(DropTargetDragEvent dtde) {
      System.out.print("DST: drag over: ") ;
      printActions(dtde) ;
      //should set action to accepted, if it is supported
      //by the source and no user action is in effect
      dtde.acceptDrag(accepted) ;
      }
      public void dropActionChanged(DropTargetDragEvent dtde) {
      System.out.print("DST: drag action changed: ") ;
      printActions(dtde) ;
      //should set action to accepted, if it is supported
      // by the source and no user action is in effect
      dtde.acceptDrag(accepted) ;
      }
      public void dragExit(DropTargetEvent dtde) {
      System.out.println("DST: drag exit") ;
      setBorder(std) ;
      }
      public void drop(DropTargetDropEvent dtde) {
      System.out.println("DST: drop, action="
      + formatActions(dtde.getDropAction())
      + ", rejecting") ;
      setBorder(std) ;
      dtde.rejectDrop() ;
      }
          }

          class SourceLabel extends JLabel implements DragGestureListener,
      DragSourceListener {

      public static final int allActions = DnDConstants.ACTION_COPY_OR_MOVE
      | DnDConstants.ACTION_REFERENCE
      | DnDConstants.ACTION_LINK ;

      public SourceLabel() {
      super() ;
      // setTransferHandler(null) ; // does not improve it...
      setBorder(new EtchedBorder()) ;
      DragSource.getDefaultDragSource().createDefaultDragGestureRecognizer( this,
      allActions, this);
      }

      private void printActions(DragSourceDragEvent dsde) {
      System.out.println("target="+formatActions(dsde.getTargetActions())
      +", user="+formatActions(dsde.getUserAction())
      +", action="+formatActions(dsde.getDropAction())
      ) ;
      }
      public void dragGestureRecognized(DragGestureEvent dge) {
      System.out.println("gesture reckognized.") ;
      StringSelection sel = new StringSelection("i am on my way ...") ;
      dge.getSourceAsDragGestureRecognizer().setSourceActions(allActions) ;
      dge.startDrag(null, sel, this);
      }
      public void dragDropEnd(DragSourceDropEvent dsde) {
      System.err.println("SRC: drag ended (success="
      + dsde.getDropSuccess()
      + ", action="
      + formatActions(dsde.getDropAction()) + ")") ;
      }
      public void dropActionChanged(DragSourceDragEvent dsde) {
      System.err.print("SRC: drop action changed: ") ;
      printActions(dsde) ;
      }
      public void dragEnter(DragSourceDragEvent dsde) {
      System.err.print("SRC: drag enter: ") ;
      printActions(dsde) ;
      }
      public void dragOver(DragSourceDragEvent dsde) {
      System.err.print("SRC: drag over: ") ;
      printActions(dsde) ;
      }
      public void dragExit(DragSourceEvent dse) {
      System.err.println("SRC: drag exit.") ;
      }
          }

       
          public void bug() {
      JFrame frame = new JFrame();
      frame.setTitle("DnD bug demo") ;
      frame.setSize(new Dimension(100, 200));
      frame.getContentPane().setLayout(new FlowLayout()) ;

      JLabel label = new SourceLabel() ;
      label.setText("source") ;
      frame.getContentPane().add(label) ;

      label = new TargetLabel(DnDConstants.ACTION_REFERENCE) ;
      label.setText("ref. target") ;
      frame.getContentPane().add(label) ;

      label = new TargetLabel(DnDConstants.ACTION_LINK) ;
      label.setText("link target") ;
      frame.getContentPane().add(label) ;

      label = new TargetLabel(DnDConstants.ACTION_COPY) ;
      label.setText("copy target") ;
      frame.getContentPane().add(label) ;

      label = new TargetLabel(DnDConstants.ACTION_MOVE) ;
      label.setText("move target") ;
      frame.getContentPane().add(label) ;

      frame.addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent e) {
      System.exit(0);
      };
      });
      frame.show();

      System.out.println("now start dragging the \"source\" over the targets") ;
          }

          public static String formatActions(int actions) {
      StringBuffer buf = new StringBuffer() ;
      if(actions == (actions | DnDConstants.ACTION_MOVE)) {
      buf.append("M") ;
      }
      if(actions == (actions | DnDConstants.ACTION_COPY)) {
      buf.append("C") ;
      }
      if(actions == (actions | DnDConstants.ACTION_LINK)) {
      buf.append("L") ;
      }
      if(actions == (actions | DnDConstants.ACTION_REFERENCE)) {
      buf.append("R") ;
      }
      if(buf.length() == 0) {
      buf.append("0") ;
      }
      return buf.toString() ;
          }


          public static void main(String[] args) {
              // does not improve anything
              // System.setProperty("suppressSwingDropSupport", "true") ;

              new DndBug().bug() ;
          }
      }

      ---------- END SOURCE ----------
      (Review ID: 147281)
      ======================================================================

            agerasimsunw Alexander Gerasimov (Inactive)
            jleesunw Jon Lee (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: