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

项目:VASSAL-src    文件:CounterDetailViewer.java   
public void addTo(Buildable b) {
  map = (Map) b;
  view = map.getView();
  validator = new SingleChildInstance(map, getClass());
  map.addDrawComponent(this);
  String keyDesc = hotkey == null ? "" : "(" + HotKeyConfigurer.getString(hotkey) + ")";
  GameModule.getGameModule().getPrefs().addOption(Resources.getString("Prefs.general_tab"),
      new BooleanConfigurer(USE_KEYBOARD, Resources.getString("CounterDetailViewer.use_prompt", keyDesc), Boolean.FALSE));
  GameModule.getGameModule().getPrefs().addOption(Resources.getString("Prefs.general_tab"),
      new IntConfigurer(PREFERRED_DELAY, Resources.getString("CounterDetailViewer.delay_prompt"), delay));

  view.addMouseMotionListener(this);
  view.addMouseListener(this);
  view.addKeyListener(this);
  DragSource.getDefaultDragSource().addDragSourceMotionListener(this);

  setAttributeTranslatable(VERSION, false);
  setAttributeTranslatable(SUMMARY_REPORT_FORMAT, true);
  setAttributeTranslatable(COUNTER_REPORT_FORMAT, true);
}
项目:OpenJSharp    文件:WToolkit.java   
@Override
public <T extends DragGestureRecognizer> T
    createDragGestureRecognizer(Class<T> abstractRecognizerClass,
                                DragSource ds, Component c, int srcActions,
                                DragGestureListener dgl)
{
    final LightweightFrame f = SunToolkit.getLightweightFrame(c);
    if (f != null) {
        return f.createDragGestureRecognizer(abstractRecognizerClass, ds, c, srcActions, dgl);
    }

    if (MouseDragGestureRecognizer.class.equals(abstractRecognizerClass))
        return (T)new WMouseDragGestureRecognizer(ds, c, srcActions, dgl);
    else
        return null;
}
项目:OpenJSharp    文件:XToolkit.java   
public <T extends DragGestureRecognizer> T
createDragGestureRecognizer(Class<T> recognizerClass,
                DragSource ds,
                Component c,
                int srcActions,
                DragGestureListener dgl)
{
    final LightweightFrame f = SunToolkit.getLightweightFrame(c);
    if (f != null) {
        return f.createDragGestureRecognizer(recognizerClass, ds, c, srcActions, dgl);
    }

    if (MouseDragGestureRecognizer.class.equals(recognizerClass))
        return (T)new XMouseDragGestureRecognizer(ds, c, srcActions, dgl);
    else
        return null;
}
项目:jdk8u-jdk    文件:WToolkit.java   
@Override
public <T extends DragGestureRecognizer> T
    createDragGestureRecognizer(Class<T> abstractRecognizerClass,
                                DragSource ds, Component c, int srcActions,
                                DragGestureListener dgl)
{
    final LightweightFrame f = SunToolkit.getLightweightFrame(c);
    if (f != null) {
        return f.createDragGestureRecognizer(abstractRecognizerClass, ds, c, srcActions, dgl);
    }

    if (MouseDragGestureRecognizer.class.equals(abstractRecognizerClass))
        return (T)new WMouseDragGestureRecognizer(ds, c, srcActions, dgl);
    else
        return null;
}
项目:jdk8u-jdk    文件:XToolkit.java   
public <T extends DragGestureRecognizer> T
createDragGestureRecognizer(Class<T> recognizerClass,
                DragSource ds,
                Component c,
                int srcActions,
                DragGestureListener dgl)
{
    final LightweightFrame f = SunToolkit.getLightweightFrame(c);
    if (f != null) {
        return f.createDragGestureRecognizer(recognizerClass, ds, c, srcActions, dgl);
    }

    if (MouseDragGestureRecognizer.class.equals(recognizerClass))
        return (T)new XMouseDragGestureRecognizer(ds, c, srcActions, dgl);
    else
        return null;
}
项目: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]);
}
项目:jdk8u-jdk    文件:MissingEventsOnModalDialogTest.java   
public static void main(String[] args) throws Exception {
    Frame sourceFrame = createFrame("Source Frame", 0, 0);
    Frame targetFrame = createFrame("Target Frame", 250, 250);

    DragSource defaultDragSource
            = DragSource.getDefaultDragSource();
    defaultDragSource.createDefaultDragGestureRecognizer(sourceFrame,
            DnDConstants.ACTION_COPY_OR_MOVE,
            new TestDragGestureListener());
    new DropTarget(targetFrame, DnDConstants.ACTION_COPY_OR_MOVE,
            new TestDropTargetListener(targetFrame));

    Robot robot = new Robot();
    robot.setAutoDelay(50);

    sourceFrame.toFront();
    robot.waitForIdle();

    Point point = getCenterPoint(sourceFrame);
    robot.mouseMove(point.x, point.y);
    robot.waitForIdle();

    mouseDragAndDrop(robot, point, getCenterPoint(targetFrame));

    long time = System.currentTimeMillis() + 200;

    while (!passed) {
        if (time < System.currentTimeMillis()) {
            sourceFrame.dispose();
            targetFrame.dispose();
            throw new RuntimeException("Mouse clicked event is lost!");
        }
        Thread.sleep(10);
    }
    sourceFrame.dispose();
    targetFrame.dispose();
}
项目:jdk8u-jdk    文件:ImageDecoratedDnD.java   
public void start() {
    Frame f = new Frame("Use keyboard for DnD change");
    Panel mainPanel;
    Component dragSource, dropTarget;

    f.setBounds(0, 400, 200, 200);
    f.setLayout(new BorderLayout());

    mainPanel = new Panel();
    mainPanel.setLayout(new BorderLayout());

    mainPanel.setBackground(Color.blue);

    dropTarget = new DnDTarget(Color.red, Color.yellow);
    dragSource = new DnDSource("Drag ME! (" + (DragSource.isDragImageSupported()?"with ":"without") + " image)" );

    mainPanel.add(dragSource, "North");
    mainPanel.add(dropTarget, "Center");
    f.add(mainPanel, BorderLayout.CENTER);

    f.setVisible(true);
}
项目:openjdk-jdk10    文件:WToolkit.java   
@Override
@SuppressWarnings("unchecked")
public <T extends DragGestureRecognizer> T
    createDragGestureRecognizer(Class<T> abstractRecognizerClass,
                                DragSource ds, Component c, int srcActions,
                                DragGestureListener dgl)
{
    final LightweightFrame f = SunToolkit.getLightweightFrame(c);
    if (f != null) {
        return f.createDragGestureRecognizer(abstractRecognizerClass, ds, c, srcActions, dgl);
    }

    if (MouseDragGestureRecognizer.class.equals(abstractRecognizerClass))
        return (T)new WMouseDragGestureRecognizer(ds, c, srcActions, dgl);
    else
        return null;
}
项目: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]);
}
项目:openjdk-jdk10    文件:ImageDecoratedDnD.java   
public void start() {
    Frame f = new Frame("Use keyboard for DnD change");
    Panel mainPanel;
    Component dragSource, dropTarget;

    f.setBounds(0, 400, 200, 200);
    f.setLayout(new BorderLayout());

    mainPanel = new Panel();
    mainPanel.setLayout(new BorderLayout());

    mainPanel.setBackground(Color.blue);

    dropTarget = new DnDTarget(Color.red, Color.yellow);
    dragSource = new DnDSource("Drag ME! (" + (DragSource.isDragImageSupported()?"with ":"without") + " image)" );

    mainPanel.add(dragSource, "North");
    mainPanel.add(dropTarget, "Center");
    f.add(mainPanel, BorderLayout.CENTER);

    f.setVisible(true);
}
项目:incubator-netbeans    文件:DragManager.java   
/** Creates a new instance of SplashDnDSupport */
DragManager(JComponent component) {
    this.component = component;
    dSource =  new DragSource();
    dRecognizer = dSource.createDefaultDragGestureRecognizer(this.component,DnDConstants.ACTION_MOVE,this);
    dTarget = new DropTarget(this.component,DnDConstants.ACTION_MOVE,this);
    component.addMouseMotionListener(this);
    oCursor = component.getCursor();
}
项目:incubator-netbeans    文件:DnDSupport.java   
void add( CategoryDescriptor descriptor ) {
    CategoryList list = descriptor.getList();
    list.setTransferHandler( null );
    list.setDragEnabled(false);
    recognizers.add( DragSource.getDefaultDragSource().createDefaultDragGestureRecognizer( list, DnDConstants.ACTION_MOVE, this ) );
    dropTargets.add( new DropTarget( list, this ) );

    CategoryButton button = descriptor.getButton();
    button.setTransferHandler( null );
    recognizers.add( DragSource.getDefaultDragSource().createDefaultDragGestureRecognizer( button, DnDConstants.ACTION_MOVE, this ) );
    dropTargets.add( new DropTarget( button, this ) );
}
项目:incubator-netbeans    文件:IndexedCustomizer.java   
/** Creates drag source with asociated list where drag
* will take place.
* Also creates the default gesture and asociates this with
* given component */
IndexedDragSource(JList comp) {
    this.comp = comp;

    // initialize gesture
    DragSource ds = DragSource.getDefaultDragSource();
    ds.createDefaultDragGestureRecognizer(comp, DnDConstants.ACTION_MOVE, this);
}
项目:incubator-netbeans    文件:IndexedCustomizer.java   
/** Initiating the drag */
public void dragGestureRecognized(DragGestureEvent dge) {
    // check allowed actions
    if ((dge.getDragAction() & DnDConstants.ACTION_MOVE) == 0) {
        return;
    }

    // prepare transferable and start the drag
    int index = comp.locationToIndex(dge.getDragOrigin());

    // no index, then no dragging...
    if (index < 0) {
        return;
    }

    //      System.out.println("Starting drag..."); // NOI18N
    // create our flavor for transferring the index
    myFlavor = new DataFlavor(
            String.class, NbBundle.getBundle(IndexedCustomizer.class).getString("IndexedFlavor")
        );

    try {
        dge.startDrag(DragSource.DefaultMoveDrop, new IndexTransferable(myFlavor, index), this);

        // remember the gesture
        this.dge = dge;
    } catch (InvalidDnDOperationException exc) {
        Logger.getLogger(IndexedCustomizer.class.getName()).log(Level.WARNING, null, exc);

        // PENDING notify user - cannot start the drag
    }
}
项目:incubator-netbeans    文件:DnDWarmUpTask.java   
/** Performs DnD pre-heat.
 */
@Override
public void run() {
    if (!GraphicsEnvironment.isHeadless()) {
        DragSource.getDefaultDragSource();
    }
}
项目:KernelHive    文件:RepositoryViewerDragGestureListener.java   
@Override
public void dragGestureRecognized(DragGestureEvent dge) {
    Cursor cursor = null;
    if(dge.getComponent() instanceof RepositoryViewer){
        RepositoryViewer rv = (RepositoryViewer) dge.getComponent();
        KernelRepositoryEntry kre = (KernelRepositoryEntry) rv.getSelectedValue();

        if(dge.getDragAction()==DnDConstants.ACTION_COPY){
            cursor = DragSource.DefaultCopyDrop;
        }

        dge.startDrag(cursor, new TransferableKernelRepositoryEntry(kre));
    }
}
项目:Equella    文件:FileListPanel.java   
private void registerDndHandlers()
{
    new DragSource().createDefaultDragGestureRecognizer(list, DnDConstants.ACTION_COPY, new DragGestureListener()
    {
        @Override
        public void dragGestureRecognized(DragGestureEvent dge)
        {
            Transferable t = new FileInfoTransferable(getSelectedFile());
            dge.startDrag(DragSource.DefaultMoveDrop, t);
        }
    });

    DnDUtils.registerDropHandler(this, dropHandlers, new HoverHandler()
    {
        @Override
        public void hovering(DropTargetDragEvent e)
        {
            FileInfo fi = getFileUnderMouseCursor();
            if( fi == null )
            {
                int i = getListIndexUnderPoint(e.getLocation());
                if( i >= 0 )
                {
                    fi = model.get(i);
                }
            }

            if( fi != null && fi.isDirectory() )
            {
                list.setSelectedValue(fi, true);
            }
            else
            {
                list.getSelectionModel().clearSelection();
            }
        }
    });
}
项目:OpenJSharp    文件:LightweightContent.java   
/**
 * Create a drag gesture recognizer for the lightweight frame.
 */
default public <T extends DragGestureRecognizer> T createDragGestureRecognizer(
        Class<T> abstractRecognizerClass,
        DragSource ds, Component c, int srcActions,
        DragGestureListener dgl)
{
    return null;
}
项目:OpenJSharp    文件:JLightweightFrame.java   
public <T extends DragGestureRecognizer> T createDragGestureRecognizer(
        Class<T> abstractRecognizerClass,
        DragSource ds, Component c, int srcActions,
        DragGestureListener dgl)
{
    return content == null ? null : content.createDragGestureRecognizer(
            abstractRecognizerClass, ds, c, srcActions, dgl);
}
项目:OpenJSharp    文件:DragRecognitionSupport.java   
/**
 * Returns whether or not the event is potentially part of a drag sequence.
 */
private boolean mousePressedImpl(MouseEvent me) {
    component = (JComponent)me.getSource();

    if (mapDragOperationFromModifiers(me, component.getTransferHandler())
            != TransferHandler.NONE) {

        motionThreshold = DragSource.getDragThreshold();
        dndArmedEvent = me;
        return true;
    }

    clearState();
    return false;
}
项目:OpenJSharp    文件:WMouseDragGestureRecognizer.java   
/**
 * Invoked when a mouse button has been pressed on a component.
 */

@Override
public void mousePressed(MouseEvent e) {
    events.clear();

    if (mapDragOperationFromModifiers(e) != DnDConstants.ACTION_NONE) {
        try {
            motionThreshold = DragSource.getDragThreshold();
        } catch (Exception exc) {
            motionThreshold = 5;
        }
        appendEvent(e);
    }
}
项目:OpenJSharp    文件:XMouseDragGestureRecognizer.java   
/**
 * Invoked when a mouse button has been pressed on a component.
 */

public void mousePressed(MouseEvent e) {
    events.clear();

    if (mapDragOperationFromModifiers(e) != DnDConstants.ACTION_NONE) {
        try {
            motionThreshold = DragSource.getDragThreshold();
        } catch (Exception exc) {
            motionThreshold = 5;
        }
        appendEvent(e);
    }
}
项目: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);
}
项目:jdk8u-jdk    文件:LightweightContent.java   
/**
 * Create a drag gesture recognizer for the lightweight frame.
 */
default public <T extends DragGestureRecognizer> T createDragGestureRecognizer(
        Class<T> abstractRecognizerClass,
        DragSource ds, Component c, int srcActions,
        DragGestureListener dgl)
{
    return null;
}
项目:jdk8u-jdk    文件:JLightweightFrame.java   
public <T extends DragGestureRecognizer> T createDragGestureRecognizer(
        Class<T> abstractRecognizerClass,
        DragSource ds, Component c, int srcActions,
        DragGestureListener dgl)
{
    return content == null ? null : content.createDragGestureRecognizer(
            abstractRecognizerClass, ds, c, srcActions, dgl);
}
项目:jdk8u-jdk    文件:DragRecognitionSupport.java   
/**
 * Returns whether or not the event is potentially part of a drag sequence.
 */
private boolean mousePressedImpl(MouseEvent me) {
    component = (JComponent)me.getSource();

    if (mapDragOperationFromModifiers(me, component.getTransferHandler())
            != TransferHandler.NONE) {

        motionThreshold = DragSource.getDragThreshold();
        dndArmedEvent = me;
        return true;
    }

    clearState();
    return false;
}
项目:jdk8u-jdk    文件:WMouseDragGestureRecognizer.java   
/**
 * Invoked when a mouse button has been pressed on a component.
 */

@Override
public void mousePressed(MouseEvent e) {
    events.clear();

    if (mapDragOperationFromModifiers(e) != DnDConstants.ACTION_NONE) {
        try {
            motionThreshold = DragSource.getDragThreshold();
        } catch (Exception exc) {
            motionThreshold = 5;
        }
        appendEvent(e);
    }
}
项目:Logisim    文件:JTreeUtil.java   
@Override
public final void dropActionChanged(DragSourceDragEvent dsde) {
    int action = dsde.getDropAction();
    if (action == DnDConstants.ACTION_COPY) {
        dsde.getDragSourceContext().setCursor(DragSource.DefaultCopyDrop);
    } else {
        if (action == DnDConstants.ACTION_MOVE) {
            dsde.getDragSourceContext().setCursor(DragSource.DefaultMoveDrop);
        } else {
            dsde.getDragSourceContext().setCursor(DragSource.DefaultMoveNoDrop);
        }
    }
}
项目:jdk8u-jdk    文件:XMouseDragGestureRecognizer.java   
/**
 * Invoked when a mouse button has been pressed on a component.
 */

public void mousePressed(MouseEvent e) {
    events.clear();

    if (mapDragOperationFromModifiers(e) != DnDConstants.ACTION_NONE) {
        try {
            motionThreshold = DragSource.getDragThreshold();
        } catch (Exception exc) {
            motionThreshold = 5;
        }
        appendEvent(e);
    }
}
项目:jdk8u-jdk    文件:SourcePanel.java   
public SourcePanel () {
    setPreferredSize(new Dimension(200, 200));
    DragSource defaultDragSource =
            DragSource.getDefaultDragSource();
    defaultDragSource.createDefaultDragGestureRecognizer(this,
            DnDConstants.ACTION_COPY_OR_MOVE, dragGestureListener);
    setBackground(Color.RED);
}
项目:jdk8u-jdk    文件:SourceFileListFrame.java   
SourceFileListFrame() {
    super("Source File List Frame");
    extractFilesFromTheWorkingDirectory();
    initList();
    initGUI();
    new DragSource().createDefaultDragGestureRecognizer(list,
            DnDConstants.ACTION_COPY,this);
}
项目:jdk8u-jdk    文件:SourceFileListFrame.java   
SourceFileListFrame() {
    super("Source File List Frame");
    extractFilesFromTheWorkingDirectory();
    initList();
    initGUI();
    new DragSource().createDefaultDragGestureRecognizer(list,
            DnDConstants.ACTION_COPY,this);
}
项目:jdk8u-jdk    文件:SourceFileListFrame.java   
SourceFileListFrame() {
    super("Source File List Frame");
    extractFilesFromTheWorkingDirectory();
    initList();
    initGUI();
    new DragSource().createDefaultDragGestureRecognizer(list,
            DnDConstants.ACTION_COPY,this);
}
项目:jdk8u-jdk    文件:SourcePanel.java   
public SourcePanel() {
    setPreferredSize(new Dimension(200, 200));
    DragSource defaultDragSource =
            DragSource.getDefaultDragSource();
    defaultDragSource.createDefaultDragGestureRecognizer(this,
            DnDConstants.ACTION_COPY_OR_MOVE, dragGestureListener);
    setBackground(Color.RED);
}
项目:openjdk-jdk10    文件:HeadlessToolkit.java   
@Override
public <T extends DragGestureRecognizer> T
    createDragGestureRecognizer(Class<T> abstractRecognizerClass,
                                DragSource ds, Component c,
                                int srcActions, DragGestureListener dgl)
{
    return null;
}
项目:openjdk-jdk10    文件:HToolkit.java   
@Override
public <T extends DragGestureRecognizer> T
    createDragGestureRecognizer(Class<T> abstractRecognizerClass,
                                DragSource ds, Component c,
                                int srcActions, DragGestureListener dgl)
{
    return null;
}
项目:openjdk-jdk10    文件:LightweightContent.java   
/**
 * Create a drag gesture recognizer for the lightweight frame.
 */
default public <T extends DragGestureRecognizer> T createDragGestureRecognizer(
        Class<T> abstractRecognizerClass,
        DragSource ds, Component c, int srcActions,
        DragGestureListener dgl)
{
    return null;
}
项目:openjdk-jdk10    文件:JLightweightFrame.java   
public <T extends DragGestureRecognizer> T createDragGestureRecognizer(
        Class<T> abstractRecognizerClass,
        DragSource ds, Component c, int srcActions,
        DragGestureListener dgl)
{
    return content == null ? null : content.createDragGestureRecognizer(
            abstractRecognizerClass, ds, c, srcActions, dgl);
}
项目:openjdk-jdk10    文件:DragRecognitionSupport.java   
/**
 * Returns whether or not the event is potentially part of a drag sequence.
 */
private boolean mousePressedImpl(MouseEvent me) {
    component = (JComponent)me.getSource();

    if (mapDragOperationFromModifiers(me, component.getTransferHandler())
            != TransferHandler.NONE) {

        motionThreshold = DragSource.getDragThreshold();
        dndArmedEvent = me;
        return true;
    }

    clearState();
    return false;
}