Search in sources :

Example 21 with DropTarget

use of java.awt.dnd.DropTarget in project jdk8u_jdk by JetBrains.

the class MissingDragExitEventTest method initAndShowUI.

private static void initAndShowUI() {
    frame = new JFrame("Test frame");
    frame.setSize(SIZE, SIZE);
    frame.setLocationRelativeTo(null);
    final JTextArea jta = new JTextArea();
    jta.setBackground(Color.RED);
    frame.add(jta);
    jta.setText("1234567890");
    jta.setFont(jta.getFont().deriveFont(150f));
    jta.setDragEnabled(true);
    jta.selectAll();
    jta.setDropTarget(new DropTarget(jta, DnDConstants.ACTION_COPY, new TestdropTargetListener()));
    jta.addMouseListener(new TestMouseAdapter());
    frame.setVisible(true);
}
Also used : JTextArea(javax.swing.JTextArea) JFrame(javax.swing.JFrame) DropTarget(java.awt.dnd.DropTarget)

Example 22 with DropTarget

use of java.awt.dnd.DropTarget in project jdk8u_jdk by JetBrains.

the class MissingEventsOnModalDialogTest method main.

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();
}
Also used : Frame(java.awt.Frame) DragSource(java.awt.dnd.DragSource) DropTarget(java.awt.dnd.DropTarget) Point(java.awt.Point) Robot(java.awt.Robot)

Example 23 with DropTarget

use of java.awt.dnd.DropTarget in project JMRI by JMRI.

the class ControlPanelEditor method makeDataFlavors.

/**
     * ************************** DnD *************************************
     */
protected void makeDataFlavors() {
    //        _targetPanel.setTransferHandler(new DnDIconHandler(this));
    try {
        _positionableDataFlavor = new DataFlavor(POSITIONABLE_FLAVOR);
        _namedIconDataFlavor = new DataFlavor(ImageIndexEditor.IconDataFlavorMime);
        _positionableListDataFlavor = new DataFlavor(List.class, "JComponentList");
    } catch (ClassNotFoundException cnfe) {
        cnfe.printStackTrace();
    }
    new DropTarget(this, DnDConstants.ACTION_COPY_OR_MOVE, this);
}
Also used : List(java.util.List) ArrayList(java.util.ArrayList) DropTarget(java.awt.dnd.DropTarget) DataFlavor(java.awt.datatransfer.DataFlavor)

Example 24 with DropTarget

use of java.awt.dnd.DropTarget in project JMRI by JMRI.

the class DropJLabel method accept.

private void accept(DropTargetDropEvent e, NamedIcon newIcon) {
    e.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
    DropTarget target = (DropTarget) e.getSource();
    DropJLabel label = (DropJLabel) target.getComponent();
    if (log.isDebugEnabled()) {
        log.debug("accept drop for " + label.getName() + ", " + newIcon.getURL());
    }
    if (newIcon == null || newIcon.getIconWidth() < 1 || newIcon.getIconHeight() < 1) {
        label.setText(Bundle.getMessage("invisibleIcon"));
        label.setForeground(Color.lightGray);
    } else {
        newIcon.reduceTo(100, 100, 0.2);
        label.setText(null);
    }
    label.setIcon(newIcon);
    if (newIcon != null) {
        label.setToolTipText(newIcon.getName());
    }
    //        _catalog.setBackground(label);
    _iconMap.put(label.getName(), newIcon);
    if (!_update) {
        // only prompt for save from palette
        ImageIndexEditor.indexChanged(true);
    }
    e.dropComplete(true);
    if (log.isDebugEnabled()) {
        log.debug("DropJLabel.drop COMPLETED for " + label.getName() + ", " + (newIcon != null ? newIcon.getURL() : " newIcon==null "));
    }
}
Also used : DropTarget(java.awt.dnd.DropTarget)

Example 25 with DropTarget

use of java.awt.dnd.DropTarget in project pcgen by PCGen.

the class NotesView method initDnDComponents.

private void initDnDComponents() {
    filesBarDT = new DropTarget(filesBar, new DropBarListener());
    treeDT = new DropTarget(notesTree, new DropTreeListener());
}
Also used : DropTarget(java.awt.dnd.DropTarget)

Aggregations

DropTarget (java.awt.dnd.DropTarget)25 DropTargetDragEvent (java.awt.dnd.DropTargetDragEvent)9 DropTargetDropEvent (java.awt.dnd.DropTargetDropEvent)9 DropTargetAdapter (java.awt.dnd.DropTargetAdapter)6 Component (java.awt.Component)5 Point (java.awt.Point)5 DropTargetContext (java.awt.dnd.DropTargetContext)4 IOException (java.io.IOException)4 EditorFragmentComponent (com.intellij.codeInsight.hint.EditorFragmentComponent)3 JBLayeredPane (com.intellij.ui.components.JBLayeredPane)3 Activatable (com.intellij.util.ui.update.Activatable)3 UiNotifyConnector (com.intellij.util.ui.update.UiNotifyConnector)3 UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)3 DropTargetListener (java.awt.dnd.DropTargetListener)3 InvalidDnDOperationException (java.awt.dnd.InvalidDnDOperationException)3 DropTargetEvent (java.awt.dnd.DropTargetEvent)2 KeyEvent (java.awt.event.KeyEvent)2 MouseEvent (java.awt.event.MouseEvent)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2