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

项目: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]);
}
项目:passage    文件:DefaultDnDCatcher.java   
/**
 * Invoked on dragGestureRecognized in the ComponentDragGestureListener
 * class.
 * 
 */
public void startDragAction(DragGestureEvent dge, DragSourceListener dsl) {

    // create a Transferable object here.

    // Create a location object that can be dropped on a layer.

    // dragSource.startDrag(dge,
    // getCursor(DragSource.DefaultMoveDrop), new
    // DefaultTransferableObject(new BasicLocation()), dsl);

    // SinkGraphic is a singleton object used as sample. No action
    // on a layer will be done at drop.
    dragSource.startDrag(dge,
            getCursor(DragSource.DefaultMoveDrop),
            new DefaultTransferableObject(SinkGraphic.getSharedInstance()),
            dsl);
}
项目:VarJ    文件:DragSourceContext.java   
/**
    * Calls <code>dragEnter</code> on the
    * <code>DragSourceListener</code>s registered with this
    * <code>DragSourceContext</code> and with the associated
    * <code>DragSource</code>, and passes them the specified
    * <code>DragSourceDragEvent</code>.
    *
    * @param dsde the <code>DragSourceDragEvent</code>
    */
   public void dragEnter(DragSourceDragEvent dsde) {
       DragSourceListener dsl = listener;
       if (dsl != null) {
           dsl.dragEnter(dsde);
       }
       getDragSource().processDragEnter(dsde);

updateCurrentCursor(getSourceActions(), dsde.getTargetActions(), ENTER);
   }
项目:VarJ    文件:DragSourceContext.java   
/**
    * Calls <code>dragOver</code> on the
    * <code>DragSourceListener</code>s registered with this
    * <code>DragSourceContext</code> and with the associated
    * <code>DragSource</code>, and passes them the specified
    * <code>DragSourceDragEvent</code>.
    *
    * @param dsde the <code>DragSourceDragEvent</code>
    */
   public void dragOver(DragSourceDragEvent dsde) {
       DragSourceListener dsl = listener;
       if (dsl != null) {
           dsl.dragOver(dsde);
       }
       getDragSource().processDragOver(dsde);

updateCurrentCursor(getSourceActions(), dsde.getTargetActions(), OVER);
   }
项目:VarJ    文件:DragSourceContext.java   
/**
    * Calls <code>dragExit</code> on the
    * <code>DragSourceListener</code>s registered with this
    * <code>DragSourceContext</code> and with the associated
    * <code>DragSource</code>, and passes them the specified
    * <code>DragSourceEvent</code>.
    *
    * @param dse the <code>DragSourceEvent</code>
    */
   public void dragExit(DragSourceEvent dse) {
       DragSourceListener dsl = listener;
       if (dsl != null) {
           dsl.dragExit(dse);
       }
       getDragSource().processDragExit(dse);

updateCurrentCursor(DnDConstants.ACTION_NONE, DnDConstants.ACTION_NONE, DEFAULT);
   }
项目:VarJ    文件:DragSourceContext.java   
/**
    * Calls <code>dropActionChanged</code> on the
    * <code>DragSourceListener</code>s registered with this
    * <code>DragSourceContext</code> and with the associated
    * <code>DragSource</code>, and passes them the specified
    * <code>DragSourceDragEvent</code>.
    *
    * @param dsde the <code>DragSourceDragEvent</code>
    */
   public void dropActionChanged(DragSourceDragEvent dsde) {
       DragSourceListener dsl = listener;
       if (dsl != null) {
           dsl.dropActionChanged(dsde);
       }
       getDragSource().processDropActionChanged(dsde);

updateCurrentCursor(getSourceActions(), dsde.getTargetActions(), CHANGED);
   }
项目:VarJ    文件:DragSourceContext.java   
/**
 * Deserializes this <code>DragSourceContext</code>. This method first
 * performs default deserialization for all non-<code>transient</code>
 * fields. This object's <code>Transferable</code> and
 * <code>DragSourceListener</code> are then deserialized as well by using
 * the next two objects in the stream. If the resulting
 * <code>Transferable</code> is <code>null</code>, this object's
 * <code>Transferable</code> is set to a dummy <code>Transferable</code>
 * which supports no <code>DataFlavor</code>s.
 *
 * @since 1.4
 */
private void readObject(ObjectInputStream s)
    throws ClassNotFoundException, IOException
{
    s.defaultReadObject();

    transferable = (Transferable)s.readObject();
    listener = (DragSourceListener)s.readObject();

    // Implementation assumes 'transferable' is never null.
    if (transferable == null) {
        if (emptyTransferable == null) {
            emptyTransferable = new Transferable() {
                    public DataFlavor[] getTransferDataFlavors() {
                        return new DataFlavor[0];
                    }
                    public boolean isDataFlavorSupported(DataFlavor flavor)
                    {
                        return false;
                    }
                    public Object getTransferData(DataFlavor flavor)
                        throws UnsupportedFlavorException
                    {
                        throw new UnsupportedFlavorException(flavor);
                    }
                };
        }
        transferable = emptyTransferable;
    }
}
项目:passage    文件:ComponentDragGestureListener.java   
/**
 * Note that DefaultDnDCatcher is a DragSourceListener itself, so
 * dndCatcher and dsl can be the same object.
 */

public ComponentDragGestureListener(DefaultDnDCatcher dndCatcher,
        DragSourceListener dsl) {
    this.dndCatcher = dndCatcher;
    this.dsl = dsl;
    Debug.message("draggesturelistener",
            "Created> ComponentDragGestureListener");
    Debug.message("draggesturelistener", "dndCatcher=" + dndCatcher);
}
项目: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");
    }
}
项目:passage    文件:BeanBoxDnDCatcher.java   
/**
 * Invoked on dragGestureRecognized
 */
public void startDragAction(DragGestureEvent dge, DragSourceListener dsl) {
    if (Debug.debugging("beanbox"))
        Debug.output("Enter> startDragAction");

    Object selectedBean = null;
    BeanBox selectedBeanBox = null;
    Layer selectedLayer = null;

    Point srcLocation = dge.getDragOrigin();

    Enumeration keys = layers.keys();
    while (keys.hasMoreElements()) {
        String layerName = keys.nextElement().toString();
        Layer omLayer = (Layer) layers.get(layerName);
        BeanBox beanBox = ((BeanBoxHandler) omLayer).getBeanBox();
        selectedBean = beanBox.getBeanAtLocation(srcLocation);
        if (selectedBean != null) {
            selectedBeanBox = beanBox;
            selectedLayer = omLayer;
            break;
        }
    }

    if (Debug.debugging("beanbox"))
        Debug.output("selectedBean=" + selectedBean);

    if (selectedBean == null || selectedBeanBox == null
            || selectedLayer == null) {
        if (Debug.debugging("beanbox"))
            Debug.output("Exit> startDragAction, selected bean/beanbox/layer is null");
        return;
    }

    Image dragImage = selectedBeanBox.getDragImage(selectedBean);

    super.setCursor(dragImage, DragSource.DefaultMoveDrop);

    BeanInfo beanInfo = selectedBeanBox.getBeanInfoForBean(selectedBean.getClass()
            .getName());

    Vector beanTransferData = new Vector();
    beanTransferData.add(selectedBean);
    beanTransferData.add(beanInfo);
    beanTransferData.add(new Boolean(true));
    beanTransferData.add(selectedLayer.getName());

    dragSource.startDrag(dge,
            super.getCursor(DragSource.DefaultMoveDrop),
            new DefaultTransferableObject(beanTransferData),
            dsl);

    if (Debug.debugging("beanbox"))
        Debug.output("Exit> startDragAction");
}
项目:VarJ    文件:DragSourceContext.java   
/**
    * Add a <code>DragSourceListener</code> to this
    * <code>DragSourceContext</code> if one has not already been added.
    * If a <code>DragSourceListener</code> already exists, 
    * this method throws a <code>TooManyListenersException</code>.
    * <P>
    * @param dsl the <code>DragSourceListener</code> to add.
    * Note that while <code>null</code> is not prohibited,
    * it is not acceptable as a parameter.
    * <P>
    * @throws <code>TooManyListenersException</code> if
    * a <code>DragSourceListener</code> has already been added
    */

   public synchronized void addDragSourceListener(DragSourceListener dsl) throws TooManyListenersException {
if (dsl == null) return;

if (equals(dsl)) throw new IllegalArgumentException("DragSourceContext may not be its own listener");

if (listener != null)
    throw new TooManyListenersException();
else
    listener = dsl;
   }
项目:VarJ    文件:DragSourceContext.java   
/**
    * Removes the specified <code>DragSourceListener</code>
    * from  this <code>DragSourceContext</code>.
    * 
    * @param dsl the <code>DragSourceListener</code> to remove;
    *     note that while <code>null</code> is not prohibited,
    *     it is not acceptable as a parameter
    */

   public synchronized void removeDragSourceListener(DragSourceListener dsl) {
if (listener != null && listener.equals(dsl)) {
    listener = null;
} else
    throw new IllegalArgumentException();
   }
项目:VarJ    文件:DragSourceContext.java   
/**
 * Calls <code>dragDropEnd</code> on the
 * <code>DragSourceListener</code>s registered with this
 * <code>DragSourceContext</code> and with the associated
 * <code>DragSource</code>, and passes them the specified
 * <code>DragSourceDropEvent</code>.
 *
 * @param dsde the <code>DragSourceDropEvent</code>
 */
public void dragDropEnd(DragSourceDropEvent dsde) {
    DragSourceListener dsl = listener;
    if (dsl != null) {
        dsl.dragDropEnd(dsde);
    }
    getDragSource().processDragDropEnd(dsde);
}
项目:caadapter    文件:DragCompatibleComponent.java   
/**
 * Called by the DragGestureAdapter in dragGestureRecognized. This
 * is the listener that is registered with the drag source in the
 * startDrag method.
 *
 * @return usually the DragSourceAdapter
 */
public DragSourceListener getDragSourceListener();
项目:caadapter    文件:TreeDefaultDragTransferHandler.java   
/**
 * Called by the DragGestureAdapter in dragGestureRecognized. This
 * is the listener that is registered with the drag source in the
 * startDrag method.
 *
 * @return usually the DragSourceAdapter
 */
public DragSourceListener getDragSourceListener()
{
    return this.dragSourceAdapter;
}