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

spec for java.awt.dnd.DragSource.createDragSourceContext unclear

XMLWordPrintable

    • 1.2beta4
    • sparc
    • solaris_2.5
    • Verified



      Name: sdC67446 Date: 03/13/98


      The specification for
      java.awt.dnd.DragSource.createDragSourceContext(DragSourceContextPeer,
      Component,int actions,Cursor,Image,Point,Transferable,DragSourceListener)
      does not specify behavior for argument actions when
      it is invalid. The current behavior is to throw IllegalArgumentException for
      DnDConstants.ACTION_NONE and ignore other invalid values.
      More acceptable behavior for all invalid actions here is to throw
      IllegalArgumentException unless otherwise specified.

      Here is what doc says:
      --------------------------------------------------
      protected DragSourceContext createDragSourceContext(
                    java.awt.dnd.peer.DragSourceContextPeer dscp,
                    Component c,
                    int actions,
                    Cursor dragCursor,
                    Image dragImage,
                    Point imageOffset,
                    Transferable t,
                    DragSourceListener dsl)

            Create the DragSourceContext to handle this Drag. To incorporate a new
            DragSourceContext subclass, subclass DragSource and override this method.
            Parameters:
                  dscp - The DragSourceContextPeer for this operation
                  c - The Component the drag started in
                  actions - The drag "verbs" appropriate
                  dragCursor - The initial cursor
                  dragImage - The image to drag or null
                  imageOffset - The offset of the image origin from the hotspot
                                of the cursor at
                  the instant of the trigger
                  transferable - The subject data of the operation
                  dsl - The DragSourceListener

      Here is the test demonstrating the bug
      -----------------Test.java------------------------
      import java.awt.*;
      import java.awt.image.*;
      import java.awt.dnd.*;
      import java.awt.dnd.peer.*;
      import java.awt.datatransfer.*;

      public class Test extends DragSource {

          public DragSourceContext createDragSourceContext(
              DragSourceContextPeer dscp, Component component,
              int act, Cursor cursors, Image image, Point point,
              Transferable transferable, DragSourceListener dsl) {

              return super.createDragSourceContext(dscp, component, act,
                  cursors, image, point, transferable, dsl);
          }

          // valid actions
          static int actions[] = {
              DnDConstants.ACTION_NONE,
              DnDConstants.ACTION_COPY,
              DnDConstants.ACTION_MOVE,
              DnDConstants.ACTION_COPY_OR_MOVE,
              DnDConstants.ACTION_LINK,
              DnDConstants.ACTION_REFERENCE
          };

          static DragSourceContextPeer dscp = new DragSourceContextPeer() {
              public void startDrag(DragSourceContext ds, AWTEvent trigger, Cursor cursor, int actions) {}
              public Component getComponent() { return null; }
              public void cancelDrag() {}
              public Cursor getCursor() { return null; }
              public void setCursor(Cursor c) {}
              public AWTEvent getTrigger() {return null;}
          };

          static Component component = new Button();

          static Cursor cursor = DragSource.DefaultCopyDrop;

          static Image image = new Image() {
              public int getWidth(ImageObserver observer) {return 0;}
              public int getHeight(ImageObserver observer){return 0;}
              public ImageProducer getSource() {return null;}
              public Graphics getGraphics() {return null;}
              public void flush() {}
              public Object getProperty(String name, ImageObserver observer) {
                  return null;
              }
          };

          static Point point = new Point(0,0);

          static Transferable transferable = new Transferable() {
              public Object getTransferData(DataFlavor df) {
                  return null;
              }
              public DataFlavor[] getTransferDataFlavors() {
                  return null;
              }
              public boolean isDataFlavorSupported(DataFlavor df) {
                  return false;
              }
          };

          static DragSourceListener dsl = new DragSourceListener() {
              public void dragEnter(DragSourceDragEvent dsde) {}
              public void dragOver(DragSourceDragEvent dsde) {}
              public void dropActionChanged(DragSourceDragEvent dsde) {}
              public void dragExit(DragSourceEvent dsde) {}
              public void dragDropEnd(DragSourceDropEvent dsde) {}
          };

          public static void main(String[] args) {
              Test test = new Test();
              int act = 666;

              // make sure act is unsupported
              for (int i=0;i<actions.length;i++) {
                  if (act == actions[i]) {
                      System.out.println("oops!");
                      return;
                  }
              }

              try {
                  DragSourceContext dsc =
                      test.createDragSourceContext(dscp,
                                                   component,
                                                   act,
                                                   cursor,
                                                   image,
                                                   point,
                                                   transferable,
                                                   dsl);
              } catch (Exception e) {
                  System.out.println(e);
              }
              System.out.println("unexpected passage.");
          }
      }
      ---------Output from the test---------------------
      unexpected passage.
      --------------------------------------------------

      ======================================================================

            asommere Alan Sommerer (Inactive)
            sdmitriesunw Sergei Dmitriev (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: