Java 类java.awt.dnd.DragSourceAdapter 实例源码

项目:jdk8u-jdk    文件:ImageTransferTest.java   
ImageDragSource() {
    formats = retrieveFormatsToTest();
    passedArray = new boolean[formats.length];
    final DragSourceListener dsl = new DragSourceAdapter() {
        public void dragDropEnd(DragSourceDropEvent e) {
            System.err.println("Drop was successful=" + e.getDropSuccess());
            notifyTransferSuccess(e.getDropSuccess());
            if (++fi < formats.length) {
                leaveFormat(formats[fi]);
            }
        }
    };

    new DragSource().createDefaultDragGestureRecognizer(frame,
            DnDConstants.ACTION_COPY,
            dge -> dge.startDrag(null, new ImageSelection(image), dsl));
    leaveFormat(formats[fi]);
}
项目:openjdk-jdk10    文件:ImageTransferTest.java   
ImageDragSource() {
    formats = retrieveFormatsToTest();
    passedArray = new boolean[formats.length];
    final DragSourceListener dsl = new DragSourceAdapter() {
        public void dragDropEnd(DragSourceDropEvent e) {
            System.err.println("Drop was successful=" + e.getDropSuccess());
            notifyTransferSuccess(e.getDropSuccess());
            if (++fi < formats.length) {
                leaveFormat(formats[fi]);
            }
        }
    };

    new DragSource().createDefaultDragGestureRecognizer(frame,
            DnDConstants.ACTION_COPY,
            dge -> dge.startDrag(null, new ImageSelection(image), dsl));
    leaveFormat(formats[fi]);
}
项目:openjdk9    文件:ImageTransferTest.java   
ImageDragSource() {
    formats = retrieveFormatsToTest();
    passedArray = new boolean[formats.length];
    final DragSourceListener dsl = new DragSourceAdapter() {
        public void dragDropEnd(DragSourceDropEvent e) {
            System.err.println("Drop was successful=" + e.getDropSuccess());
            notifyTransferSuccess(e.getDropSuccess());
            if (++fi < formats.length) {
                leaveFormat(formats[fi]);
            }
        }
    };

    new DragSource().createDefaultDragGestureRecognizer(frame,
            DnDConstants.ACTION_COPY,
            dge -> dge.startDrag(null, new ImageSelection(image), dsl));
    leaveFormat(formats[fi]);
}
项目:jdk8u_jdk    文件:ImageTransferTest.java   
ImageDragSource() {
    formats = retrieveFormatsToTest();
    passedArray = new boolean[formats.length];
    final DragSourceListener dsl = new DragSourceAdapter() {
        public void dragDropEnd(DragSourceDropEvent e) {
            System.err.println("Drop was successful=" + e.getDropSuccess());
            notifyTransferSuccess(e.getDropSuccess());
            if (++fi < formats.length) {
                leaveFormat(formats[fi]);
            }
        }
    };

    new DragSource().createDefaultDragGestureRecognizer(frame,
            DnDConstants.ACTION_COPY,
            dge -> dge.startDrag(null, new ImageSelection(image), dsl));
    leaveFormat(formats[fi]);
}
项目:lookaside_java-1.8.0-openjdk    文件:ImageTransferTest.java   
ImageDragSource() {
    formats = retrieveFormatsToTest();
    passedArray = new boolean[formats.length];
    final DragSourceListener dsl = new DragSourceAdapter() {
        public void dragDropEnd(DragSourceDropEvent e) {
            System.err.println("Drop was successful=" + e.getDropSuccess());
            notifyTransferSuccess(e.getDropSuccess());
            if (++fi < formats.length) {
                leaveFormat(formats[fi]);
            }
        }
    };

    new DragSource().createDefaultDragGestureRecognizer(frame,
            DnDConstants.ACTION_COPY,
            dge -> dge.startDrag(null, new ImageSelection(image), dsl));
    leaveFormat(formats[fi]);
}
项目:Tarski    文件:mxGraphHandler.java   
/**
 * 
 */
protected void installDragGestureHandler() {
  DragGestureListener dragGestureListener = new DragGestureListener() {
    public void dragGestureRecognized(DragGestureEvent e) {
      if (graphComponent.isDragEnabled() && first != null) {
        final TransferHandler th = graphComponent.getTransferHandler();

        if (th instanceof mxGraphTransferHandler) {
          final mxGraphTransferable t = (mxGraphTransferable) ((mxGraphTransferHandler) th)
              .createTransferable(graphComponent);

          if (t != null) {
            e.startDrag(null, mxSwingConstants.EMPTY_IMAGE, new Point(), t,
                new DragSourceAdapter() {

                  /**
                   * 
                   */
                  public void dragDropEnd(DragSourceDropEvent dsde) {
                    ((mxGraphTransferHandler) th).exportDone(graphComponent, t,
                        TransferHandler.NONE);
                    first = null;
                  }
                });
          }
        }
      }
    }
  };

  DragSource dragSource = new DragSource();
  dragSource.createDefaultDragGestureRecognizer(graphComponent.getGraphControl(),
      (isCloneEnabled()) ? DnDConstants.ACTION_COPY_OR_MOVE : DnDConstants.ACTION_MOVE,
      dragGestureListener);
}
项目:wabit    文件:OlapQueryPanel.java   
public void dragGestureRecognized(DragGestureEvent dge) {
    dge.getSourceAsDragGestureRecognizer().setSourceActions(DnDConstants.ACTION_COPY);
    JTree t = (JTree) dge.getComponent();
    List<Object> selectedNodes = new ArrayList<Object>();
    if (t.getSelectionPaths() == null) return;
    for (TreePath path : t.getSelectionPaths()) {
        selectedNodes.add(path.getLastPathComponent());
    }
    dge.getDragSource().startDrag(dge, null, 
            new OlapMetadataTransferable(selectedNodes.toArray()), 
            new DragSourceAdapter() {//just need a default adapter
            }
    );
}
项目:WP3    文件:mxGraphHandler.java   
/**
 * 
 */
protected void installDragGestureHandler() {
  DragGestureListener dragGestureListener = new DragGestureListener() {
    public void dragGestureRecognized(DragGestureEvent e) {
      if (graphComponent.isDragEnabled() && first != null) {
        final TransferHandler th = graphComponent.getTransferHandler();

        if (th instanceof mxGraphTransferHandler) {
          final mxGraphTransferable t = (mxGraphTransferable) ((mxGraphTransferHandler) th)
              .createTransferable(graphComponent);

          if (t != null) {
            e.startDrag(null, mxSwingConstants.EMPTY_IMAGE, new Point(), t,
                new DragSourceAdapter() {

                  /**
                   * 
                   */
                  public void dragDropEnd(DragSourceDropEvent dsde) {
                    ((mxGraphTransferHandler) th).exportDone(graphComponent, t,
                        TransferHandler.NONE);
                    first = null;
                  }
                });
          }
        }
      }
    }
  };

  DragSource dragSource = new DragSource();
  dragSource.createDefaultDragGestureRecognizer(graphComponent.getGraphControl(),
      (isCloneEnabled()) ? DnDConstants.ACTION_COPY_OR_MOVE : DnDConstants.ACTION_MOVE,
      dragGestureListener);
}
项目:TrabalhoFinalEDA2    文件:mxGraphHandler.java   
/**
 * 
 */
protected void installDragGestureHandler()
{
    DragGestureListener dragGestureListener = new DragGestureListener()
    {
        public void dragGestureRecognized(DragGestureEvent e)
        {
            if (graphComponent.isDragEnabled() && first != null)
            {
                final TransferHandler th = graphComponent
                        .getTransferHandler();

                if (th instanceof mxGraphTransferHandler)
                {
                    final mxGraphTransferable t = (mxGraphTransferable) ((mxGraphTransferHandler) th)
                            .createTransferable(graphComponent);

                    if (t != null)
                    {
                        e.startDrag(null, mxSwingConstants.EMPTY_IMAGE,
                                new Point(), t, new DragSourceAdapter()
                                {

                                    /**
                                     * 
                                     */
                                    public void dragDropEnd(
                                            DragSourceDropEvent dsde)
                                    {
                                        ((mxGraphTransferHandler) th)
                                                .exportDone(
                                                        graphComponent,
                                                        t,
                                                        TransferHandler.NONE);
                                        first = null;
                                    }
                                });
                    }
                }
            }
        }
    };

    DragSource dragSource = new DragSource();
    dragSource.createDefaultDragGestureRecognizer(graphComponent
            .getGraphControl(),
            (isCloneEnabled()) ? DnDConstants.ACTION_COPY_OR_MOVE
                    : DnDConstants.ACTION_MOVE, dragGestureListener);
}
项目:openjdk-jdk10    文件:Button2DragTest.java   
public void run() {
    frame = new Frame();

    final DragSourceListener dragSourceListener = new DragSourceAdapter() {
        public void dragDropEnd(DragSourceDropEvent e) {
            dropSuccess = e.getDropSuccess();
            System.err.println("Drop was successful: " + dropSuccess);
        }
    };
    DragGestureListener dragGestureListener = new DragGestureListener() {
        public void dragGestureRecognized(DragGestureEvent dge) {
            dge.startDrag(null, new StringSelection("OK"), dragSourceListener);
        }
    };
    new DragSource().createDefaultDragGestureRecognizer(frame, DnDConstants.ACTION_MOVE,
                                                        dragGestureListener);

    DropTargetAdapter dropTargetListener = new DropTargetAdapter() {
        public void drop(DropTargetDropEvent dtde) {
            dtde.acceptDrop(DnDConstants.ACTION_MOVE);
            dtde.dropComplete(true);
            System.err.println("Drop");
        }
    };
    new DropTarget(frame, dropTargetListener);

    //What would normally go into main() will probably go here.
    //Use System.out.println for diagnostic messages that you want
    //to read after the test is done.
    frame.setUndecorated(true);
    frame.setBounds(100, 100, 200, 200);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);

    Robot robot = Util.createRobot();

    Util.waitForIdle(robot);

    Point startPoint = frame.getLocationOnScreen();
    Point endPoint = new Point(startPoint);
    startPoint.translate(50, 50);
    endPoint.translate(150, 150);

    Util.drag(robot, startPoint, endPoint, InputEvent.BUTTON2_MASK);

    Util.waitForIdle(robot);
    robot.delay(500);

    if (dropSuccess) {
        System.err.println("test passed");
    } else {
        throw new RuntimeException("test failed: drop was not successful");
    }
}
项目:openjdk9    文件:Button2DragTest.java   
public void run() {
    frame = new Frame();

    final DragSourceListener dragSourceListener = new DragSourceAdapter() {
        public void dragDropEnd(DragSourceDropEvent e) {
            dropSuccess = e.getDropSuccess();
            System.err.println("Drop was successful: " + dropSuccess);
        }
    };
    DragGestureListener dragGestureListener = new DragGestureListener() {
        public void dragGestureRecognized(DragGestureEvent dge) {
            dge.startDrag(null, new StringSelection("OK"), dragSourceListener);
        }
    };
    new DragSource().createDefaultDragGestureRecognizer(frame, DnDConstants.ACTION_MOVE,
                                                        dragGestureListener);

    DropTargetAdapter dropTargetListener = new DropTargetAdapter() {
        public void drop(DropTargetDropEvent dtde) {
            dtde.acceptDrop(DnDConstants.ACTION_MOVE);
            dtde.dropComplete(true);
            System.err.println("Drop");
        }
    };
    new DropTarget(frame, dropTargetListener);

    //What would normally go into main() will probably go here.
    //Use System.out.println for diagnostic messages that you want
    //to read after the test is done.
    frame.setUndecorated(true);
    frame.setBounds(100, 100, 200, 200);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);

    Robot robot = Util.createRobot();

    Util.waitForIdle(robot);

    Point startPoint = frame.getLocationOnScreen();
    Point endPoint = new Point(startPoint);
    startPoint.translate(50, 50);
    endPoint.translate(150, 150);

    Util.drag(robot, startPoint, endPoint, InputEvent.BUTTON2_MASK);

    Util.waitForIdle(robot);
    robot.delay(500);

    if (dropSuccess) {
        System.err.println("test passed");
    } else {
        throw new RuntimeException("test failed: drop was not successful");
    }
}
项目:OWLAx    文件:mxGraphHandler.java   
/**
 * 
 */
protected void installDragGestureHandler()
{
    DragGestureListener dragGestureListener = new DragGestureListener()
    {
        public void dragGestureRecognized(DragGestureEvent e)
        {
            if (graphComponent.isDragEnabled() && first != null)
            {
                final TransferHandler th = graphComponent
                        .getTransferHandler();

                if (th instanceof mxGraphTransferHandler)
                {
                    final mxGraphTransferable t = (mxGraphTransferable) ((mxGraphTransferHandler) th)
                            .createTransferable(graphComponent);

                    if (t != null)
                    {
                        e.startDrag(null, mxSwingConstants.EMPTY_IMAGE,
                                new Point(), t, new DragSourceAdapter()
                                {

                                    /**
                                     * 
                                     */
                                    public void dragDropEnd(
                                            DragSourceDropEvent dsde)
                                    {
                                        ((mxGraphTransferHandler) th)
                                                .exportDone(
                                                        graphComponent,
                                                        t,
                                                        TransferHandler.NONE);
                                        first = null;
                                    }
                                });
                    }
                }
            }
        }
    };

    DragSource dragSource = new DragSource();
    dragSource.createDefaultDragGestureRecognizer(graphComponent
            .getGraphControl(),
            (isCloneEnabled()) ? DnDConstants.ACTION_COPY_OR_MOVE
                    : DnDConstants.ACTION_MOVE, dragGestureListener);
}
项目:CodenameOne    文件:UserInterfaceEditor.java   
private void makeDraggable(final JButton b, final Class codenameOneClass, final String namePrefix, final CustomComponent custom) {
    DragSource.getDefaultDragSource().createDefaultDragGestureRecognizer(b,
            TransferHandler.MOVE, new DragGestureListener() {
        public void dragGestureRecognized(DragGestureEvent dge) {
            lockForDragging = true;
            try {
                com.codename1.ui.Component cmp;
                if(custom != null && custom.isUiResource()) {
                    UIBuilderOverride u = new UIBuilderOverride();
                    cmp = u.createContainer(res, custom.getType());
                    if(b.getIcon() != null) {
                        DragSource.getDefaultDragSource().startDrag(dge, DragSource.DefaultMoveDrop,
                                ((ImageIcon)b.getIcon()).getImage(), new Point(0, 0),
                                new CodenameOneComponentTransferable(cmp), new DragSourceAdapter() {
                            });
                    } else {
                        DragSource.getDefaultDragSource().startDrag(dge, DragSource.DefaultMoveDrop,
                            new CodenameOneComponentTransferable(cmp), new DragSourceAdapter() {
                            });
                    }
                    return;
                }
                if(codenameOneClass == com.codename1.ui.Component.class) {
                    // special case for custom component which has a protected constructor
                    cmp = new com.codename1.ui.Component() {};
                } else {
                    cmp = (com.codename1.ui.Component)codenameOneClass.newInstance();
                }
                cmp.putClientProperty(TYPE_KEY, namePrefix);
                cmp.setName(findUniqueName(namePrefix));
                initializeComponentText(cmp);
                if(custom != null) {
                    cmp.putClientProperty("CustomComponent", custom);
                    cmp.putClientProperty(TYPE_KEY, custom.getType());
                }
                DragSource.getDefaultDragSource().startDrag(dge, DragSource.DefaultMoveDrop,
                        new CodenameOneComponentTransferable(cmp), new DragSourceAdapter() {
                        });
            } catch(Exception e) {
                e.printStackTrace();
            }
        }
    });
}
项目:cn1    文件:UserInterfaceEditor.java   
private void makeDraggable(final JButton b, final Class codenameOneClass, final String namePrefix, final CustomComponent custom) {
    DragSource.getDefaultDragSource().createDefaultDragGestureRecognizer(b,
            TransferHandler.MOVE, new DragGestureListener() {
        public void dragGestureRecognized(DragGestureEvent dge) {
            lockForDragging = true;
            try {
                com.codename1.ui.Component cmp;
                if(custom != null && custom.isUiResource()) {
                    UIBuilderOverride u = new UIBuilderOverride();
                    cmp = u.createContainer(res, custom.getType());
                    if(b.getIcon() != null) {
                        DragSource.getDefaultDragSource().startDrag(dge, DragSource.DefaultMoveDrop,
                                ((ImageIcon)b.getIcon()).getImage(), new Point(0, 0),
                                new CodenameOneComponentTransferable(cmp), new DragSourceAdapter() {
                            });
                    } else {
                        DragSource.getDefaultDragSource().startDrag(dge, DragSource.DefaultMoveDrop,
                            new CodenameOneComponentTransferable(cmp), new DragSourceAdapter() {
                            });
                    }
                    return;
                }
                if(codenameOneClass == com.codename1.ui.Component.class) {
                    // special case for custom component which has a protected constructor
                    cmp = new com.codename1.ui.Component() {};
                } else {
                    cmp = (com.codename1.ui.Component)codenameOneClass.newInstance();
                }
                cmp.putClientProperty(TYPE_KEY, namePrefix);
                cmp.setName(findUniqueName(namePrefix));
                initializeComponentText(cmp);
                if(custom != null) {
                    cmp.putClientProperty("CustomComponent", custom);
                    cmp.putClientProperty(TYPE_KEY, custom.getType());
                }
                DragSource.getDefaultDragSource().startDrag(dge, DragSource.DefaultMoveDrop,
                        new CodenameOneComponentTransferable(cmp), new DragSourceAdapter() {
                        });
            } catch(Exception e) {
                e.printStackTrace();
            }
        }
    });
}
项目:GKA1    文件:mxGraphHandler.java   
/**
 * 
 */
protected void installDragGestureHandler()
{
    DragGestureListener dragGestureListener = new DragGestureListener()
    {
        public void dragGestureRecognized(DragGestureEvent e)
        {
            if (graphComponent.isDragEnabled() && first != null)
            {
                final TransferHandler th = graphComponent
                        .getTransferHandler();

                if (th instanceof mxGraphTransferHandler)
                {
                    final mxGraphTransferable t = (mxGraphTransferable) ((mxGraphTransferHandler) th)
                            .createTransferable(graphComponent);

                    if (t != null)
                    {
                        e.startDrag(null, mxSwingConstants.EMPTY_IMAGE,
                                new Point(), t, new DragSourceAdapter()
                                {

                                    /**
                                     * 
                                     */
                                    public void dragDropEnd(
                                            DragSourceDropEvent dsde)
                                    {
                                        ((mxGraphTransferHandler) th)
                                                .exportDone(
                                                        graphComponent,
                                                        t,
                                                        TransferHandler.NONE);
                                        first = null;
                                    }
                                });
                    }
                }
            }
        }
    };

    DragSource dragSource = new DragSource();
    dragSource.createDefaultDragGestureRecognizer(graphComponent
            .getGraphControl(),
            (isCloneEnabled()) ? DnDConstants.ACTION_COPY_OR_MOVE
                    : DnDConstants.ACTION_MOVE, dragGestureListener);
}
项目:GKA1    文件:mxGraphHandler.java   
/**
 * 
 */
protected void installDragGestureHandler()
{
    DragGestureListener dragGestureListener = new DragGestureListener()
    {
        public void dragGestureRecognized(DragGestureEvent e)
        {
            if (graphComponent.isDragEnabled() && first != null)
            {
                final TransferHandler th = graphComponent
                        .getTransferHandler();

                if (th instanceof mxGraphTransferHandler)
                {
                    final mxGraphTransferable t = (mxGraphTransferable) ((mxGraphTransferHandler) th)
                            .createTransferable(graphComponent);

                    if (t != null)
                    {
                        e.startDrag(null, mxSwingConstants.EMPTY_IMAGE,
                                new Point(), t, new DragSourceAdapter()
                                {

                                    /**
                                     * 
                                     */
                                    public void dragDropEnd(
                                            DragSourceDropEvent dsde)
                                    {
                                        ((mxGraphTransferHandler) th)
                                                .exportDone(
                                                        graphComponent,
                                                        t,
                                                        TransferHandler.NONE);
                                        first = null;
                                    }
                                });
                    }
                }
            }
        }
    };

    DragSource dragSource = new DragSource();
    dragSource.createDefaultDragGestureRecognizer(graphComponent
            .getGraphControl(),
            (isCloneEnabled()) ? DnDConstants.ACTION_COPY_OR_MOVE
                    : DnDConstants.ACTION_MOVE, dragGestureListener);
}
项目:Puzzledice    文件:mxGraphHandler.java   
/**
 * 
 */
protected void installDragGestureHandler()
{
    DragGestureListener dragGestureListener = new DragGestureListener()
    {
        public void dragGestureRecognized(DragGestureEvent e)
        {
            if (graphComponent.isDragEnabled() && first != null)
            {
                final TransferHandler th = graphComponent
                        .getTransferHandler();

                if (th instanceof mxGraphTransferHandler)
                {
                    final mxGraphTransferable t = (mxGraphTransferable) ((mxGraphTransferHandler) th)
                            .createTransferable(graphComponent);

                    if (t != null)
                    {
                        e.startDrag(null, mxConstants.EMPTY_IMAGE,
                                new Point(), t, new DragSourceAdapter()
                                {

                                    /**
                                     * 
                                     */
                                    public void dragDropEnd(
                                            DragSourceDropEvent dsde)
                                    {
                                        ((mxGraphTransferHandler) th)
                                                .exportDone(
                                                        graphComponent,
                                                        t,
                                                        TransferHandler.NONE);
                                        first = null;
                                    }
                                });
                    }
                }
            }
        }
    };

    DragSource dragSource = new DragSource();
    dragSource.createDefaultDragGestureRecognizer(
            graphComponent.getGraphControl(),
            DnDConstants.ACTION_COPY_OR_MOVE, dragGestureListener);
}
项目:WMA    文件:mxGraphHandler.java   
/**
 * 
 */
protected void installDragGestureHandler()
{
    DragGestureListener dragGestureListener = new DragGestureListener()
    {
        public void dragGestureRecognized(DragGestureEvent e)
        {
            if (graphComponent.isDragEnabled() && first != null)
            {
                final TransferHandler th = graphComponent
                        .getTransferHandler();

                if (th instanceof mxGraphTransferHandler)
                {
                    final mxGraphTransferable t = (mxGraphTransferable) ((mxGraphTransferHandler) th)
                            .createTransferable(graphComponent);

                    if (t != null)
                    {
                        e.startDrag(null, mxSwingConstants.EMPTY_IMAGE,
                                new Point(), t, new DragSourceAdapter()
                                {

                                    /**
                                     * 
                                     */
                                    public void dragDropEnd(
                                            DragSourceDropEvent dsde)
                                    {
                                        ((mxGraphTransferHandler) th)
                                                .exportDone(
                                                        graphComponent,
                                                        t,
                                                        TransferHandler.NONE);
                                        first = null;
                                    }
                                });
                    }
                }
            }
        }
    };

    DragSource dragSource = new DragSource();
    dragSource.createDefaultDragGestureRecognizer(
            graphComponent.getGraphControl(),
            DnDConstants.ACTION_COPY_OR_MOVE, dragGestureListener);
}
项目:OnionUmlVisualization    文件:mxGraphHandler.java   
/**
 * 
 */
protected void installDragGestureHandler()
{
    DragGestureListener dragGestureListener = new DragGestureListener()
    {
        public void dragGestureRecognized(DragGestureEvent e)
        {
            if (graphComponent.isDragEnabled() && first != null)
            {
                final TransferHandler th = graphComponent
                        .getTransferHandler();

                if (th instanceof mxGraphTransferHandler)
                {
                    final mxGraphTransferable t = (mxGraphTransferable) ((mxGraphTransferHandler) th)
                            .createTransferable(graphComponent);

                    if (t != null)
                    {
                        e.startDrag(null, mxSwingConstants.EMPTY_IMAGE,
                                new Point(), t, new DragSourceAdapter()
                                {

                                    /**
                                     * 
                                     */
                                    public void dragDropEnd(
                                            DragSourceDropEvent dsde)
                                    {
                                        ((mxGraphTransferHandler) th)
                                                .exportDone(
                                                        graphComponent,
                                                        t,
                                                        TransferHandler.NONE);
                                        first = null;
                                    }
                                });
                    }
                }
            }
        }
    };

    DragSource dragSource = new DragSource();
    dragSource.createDefaultDragGestureRecognizer(
            graphComponent.getGraphControl(),
            DnDConstants.ACTION_COPY_OR_MOVE, dragGestureListener);
}