java.awt.dnd.DropTarget Java Examples

The following examples show how to use java.awt.dnd.DropTarget. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MissingDragExitEventTest.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
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);
}
 
Example #2
Source File: LWComponentPeer.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void addDropTarget(DropTarget dt) {
    LWWindowPeer winPeer = getWindowPeerOrSelf();
    if (winPeer != null && winPeer != this) {
        // We need to register the DropTarget in the
        // peer of the window ancestor of the component
        winPeer.addDropTarget(dt);
    } else {
        synchronized (dropTargetLock) {
            // 10-14-02 VL: Windows WComponentPeer would add (or remove) the drop target only
            // if it's the first (or last) one for the component. Otherwise this call is a no-op.
            if (++fNumDropTargets == 1) {
                // Having a non-null drop target would be an error but let's check just in case:
                if (fDropTarget != null)
                    System.err.println("CComponent.addDropTarget(): current drop target is non-null.");

                // Create a new drop target:
                fDropTarget = CDropTarget.createDropTarget(dt, target, this);
            }
        }
    }
}
 
Example #3
Source File: MissingDragExitEventTest.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
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);
}
 
Example #4
Source File: MissingDragExitEventTest.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
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);
}
 
Example #5
Source File: MissingDragExitEventTest.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
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);
}
 
Example #6
Source File: LWComponentPeer.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void addDropTarget(DropTarget dt) {
    LWWindowPeer winPeer = getWindowPeerOrSelf();
    if (winPeer != null && winPeer != this) {
        // We need to register the DropTarget in the
        // peer of the window ancestor of the component
        winPeer.addDropTarget(dt);
    } else {
        synchronized (dropTargetLock) {
            // 10-14-02 VL: Windows WComponentPeer would add (or remove) the drop target only
            // if it's the first (or last) one for the component. Otherwise this call is a no-op.
            if (++fNumDropTargets == 1) {
                // Having a non-null drop target would be an error but let's check just in case:
                if (fDropTarget != null)
                    System.err.println("CComponent.addDropTarget(): current drop target is non-null.");

                // Create a new drop target:
                fDropTarget = CDropTarget.createDropTarget(dt, target, this);
            }
        }
    }
}
 
Example #7
Source File: LWComponentPeer.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void removeDropTarget(DropTarget dt) {
    LWWindowPeer winPeer = getWindowPeerOrSelf();
    if (winPeer != null && winPeer != this) {
        // We need to unregister the DropTarget in the
        // peer of the window ancestor of the component
        winPeer.removeDropTarget(dt);
    } else {
        synchronized (dropTargetLock){
            // 10-14-02 VL: Windows WComponentPeer would add (or remove) the drop target only
            // if it's the first (or last) one for the component. Otherwise this call is a no-op.
            if (--fNumDropTargets == 0) {
                // Having a null drop target would be an error but let's check just in case:
                if (fDropTarget != null) {
                    // Dispose of the drop target:
                    fDropTarget.dispose();
                    fDropTarget = null;
                } else
                    System.err.println("CComponent.removeDropTarget(): current drop target is null.");
            }
        }
    }
}
 
Example #8
Source File: AbstractTreeTransferHandler.java    From TrakEM2 with GNU General Public License v3.0 6 votes vote down vote up
protected AbstractTreeTransferHandler(DNDTree tree, int action, boolean drawIcon) {
    this.tree = tree;
    drawImage = drawIcon;

    if (!GraphicsEnvironment.getLocalGraphicsEnvironment().isHeadlessInstance())
    {
        dragSource = new DragSource();
        dgr = dragSource.createDefaultDragGestureRecognizer(tree, action, this);
        dropTarget = new DropTarget(tree, action, this);
    }
    else
    {
        dragSource = null;
        dgr = null;
        dropTarget = null;
    }
}
 
Example #9
Source File: LWComponentPeer.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void removeDropTarget(DropTarget dt) {
    LWWindowPeer winPeer = getWindowPeerOrSelf();
    if (winPeer != null && winPeer != this) {
        // We need to unregister the DropTarget in the
        // peer of the window ancestor of the component
        winPeer.removeDropTarget(dt);
    } else {
        synchronized (dropTargetLock){
            // 10-14-02 VL: Windows WComponentPeer would add (or remove) the drop target only
            // if it's the first (or last) one for the component. Otherwise this call is a no-op.
            if (--fNumDropTargets == 0) {
                // Having a null drop target would be an error but let's check just in case:
                if (fDropTarget != null) {
                    // Dispose of the drop target:
                    fDropTarget.dispose();
                    fDropTarget = null;
                } else
                    System.err.println("CComponent.removeDropTarget(): current drop target is null.");
            }
        }
    }
}
 
Example #10
Source File: LWComponentPeer.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void removeDropTarget(DropTarget dt) {
    LWWindowPeer winPeer = getWindowPeerOrSelf();
    if (winPeer != null && winPeer != this) {
        // We need to unregister the DropTarget in the
        // peer of the window ancestor of the component
        winPeer.removeDropTarget(dt);
    } else {
        synchronized (dropTargetLock){
            // 10-14-02 VL: Windows WComponentPeer would add (or remove) the drop target only
            // if it's the first (or last) one for the component. Otherwise this call is a no-op.
            if (--fNumDropTargets == 0) {
                // Having a null drop target would be an error but let's check just in case:
                if (fDropTarget != null) {
                    // Dispose of the drop target:
                    fDropTarget.dispose();
                    fDropTarget = null;
                } else
                    System.err.println("CComponent.removeDropTarget(): current drop target is null.");
            }
        }
    }
}
 
Example #11
Source File: SwingUtilities.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Installs a {@code DropTarget} on the component as necessary for a
 * {@code TransferHandler} change.
 */
static void installSwingDropTargetAsNecessary(Component c,
                                                     TransferHandler t) {

    if (!getSuppressDropTarget()) {
        DropTarget dropHandler = c.getDropTarget();
        if ((dropHandler == null) || (dropHandler instanceof UIResource)) {
            if (t == null) {
                c.setDropTarget(null);
            } else if (!GraphicsEnvironment.isHeadless()) {
                c.setDropTarget(new TransferHandler.SwingDropTarget(c));
            }
        }
    }
}
 
Example #12
Source File: StyleMapTable.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Instantiates a new style map table.
 *
 * @param model the model
 * @param av the av
 * @param edit the edit
 * @param tmed the tmed
 */
public StyleMapTable(TableModel model, AnnotationFeaturesViewer av, StyleMapEditor edit,
        TableGUIMediator tmed) {
  super(model);
  med = tmed;
  setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
  setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
  setDropTarget(new DropTarget(this, new TableDropAdapter(av, edit)));

  getTableHeader().setReorderingAllowed(false);
  ListSelectionModel lsm = this.getSelectionModel();
  lsm.addListSelectionListener(new TableSelectionListener(med));
}
 
Example #13
Source File: DnDHandler.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
private DropTargetContext createDropTargetContext() throws SecurityException, NoSuchMethodException, IllegalArgumentException,
        InstantiationException, IllegalAccessException, InvocationTargetException {
    Constructor<DropTargetContext> c = DropTargetContext.class.getDeclaredConstructor(DropTarget.class);
    c.setAccessible(true);
    DropTargetContext inst = c.newInstance(dest.getDropTarget());
    inst.addNotify(createDropTargetContextPeer());
    return inst;
}
 
Example #14
Source File: DarkTabbedPaneUI.java    From darklaf with MIT License 5 votes vote down vote up
protected void installDragSupport() {
    tabPane.setTransferHandler(TRANSFER_HANDLER);
    try {
        DropTarget target = tabPane.getDropTarget();
        if (target != null) {
            target.addDropTargetListener(TRANSFER_HANDLER);
            target.setActive(dndEnabled);
        }
    } catch (TooManyListenersException e) {
        e.printStackTrace();
    }
}
 
Example #15
Source File: XComponentPeer.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public void removeDropTarget(DropTarget dt) {
    Component comp = target;
    while(!(comp == null || comp instanceof Window)) {
        comp = comp.getParent();
    }

    if (comp instanceof Window) {
        XWindowPeer wpeer = (XWindowPeer)(comp.getPeer());
        if (wpeer != null) {
            wpeer.removeDropTarget();
        }
    }
}
 
Example #16
Source File: WComponentPeer.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * unregister a DropTarget with this native peer
 */

@Override
public synchronized void removeDropTarget(DropTarget dt) {
    nDropTargets--;
    if (nDropTargets == 0) {
        removeNativeDropTarget();
        nativeDropTargetContext = 0;
    }
}
 
Example #17
Source File: JPanel_FileManager.java    From MobyDroid with Apache License 2.0 5 votes vote down vote up
/**
 *
 */
private void dropHandle() {
    // Handle drag & drop files into jPanel
    jPanel_Device.setDropTarget(new DropTarget() {
        @Override
        public synchronized void drop(DropTargetDropEvent dtde) {
            // disable UI
            try {
                // set accepted drop action
                dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
                // Just going to grab the expected DataFlavor to make sure
                // we know what is being dropped
                // Grab expected flavor
                DataFlavor dragAndDropPanelFlavor = DataFlavor.javaFileListFlavor;
                // What does the Transferable support
                if (dtde.getTransferable().isDataFlavorSupported(dragAndDropPanelFlavor)) {
                    Object transferableArrayListObj = dtde.getTransferable().getTransferData(dragAndDropPanelFlavor);
                    if (transferableArrayListObj != null) {
                        if (transferableArrayListObj instanceof ArrayList) {
                            // copyHandle
                            List<MyFile> src = new ArrayList<>();
                            ((ArrayList) transferableArrayListObj).forEach(file -> {
                                String srcFile = ((File) file).getAbsolutePath();
                                src.add(new MyFile(srcFile, 0, 0, 0));
                            });
                            // copy from local
                            fileBrowserLocal.onCopy(src);
                            // paste to device
                            fileBrowserDevice.onPaste();
                        }
                    }
                }
            } catch (UnsupportedFlavorException | IOException ex) {
                Log.log(Level.SEVERE, "DropItHandle", ex);
            }
            // handle drop inside current panel
            //super.drop(dtde);*/
        }
    });
}
 
Example #18
Source File: XComponentPeer.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/****** DropTargetPeer implementation ********************/

    public void addDropTarget(DropTarget dt) {
        Component comp = target;
        while(!(comp == null || comp instanceof Window)) {
            comp = comp.getParent();
        }

        if (comp instanceof Window) {
            XWindowPeer wpeer = (XWindowPeer)(comp.getPeer());
            if (wpeer != null) {
                wpeer.addDropTarget();
            }
        }
    }
 
Example #19
Source File: EditorRuler.java    From blog-codes with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a new ruler for the specified graph and orientation.
 * 
 * @param graph
 *            The graph to create the ruler for.
 * @param orientation
 *            The orientation to use for the ruler.
 */
public EditorRuler(mxGraphComponent graphComponent, int orientation)
{
	this.orientation = orientation;
	this.graphComponent = graphComponent;
	updateIncrementAndUnits();

	graphComponent.getGraph().getView().addListener(
			mxEvent.SCALE, repaintHandler);
	graphComponent.getGraph().getView().addListener(
			mxEvent.TRANSLATE, repaintHandler);
	graphComponent.getGraph().getView().addListener(
			mxEvent.SCALE_AND_TRANSLATE, repaintHandler);

	graphComponent.getGraphControl().addMouseMotionListener(this);

	DropTarget dropTarget = graphComponent.getDropTarget();

	try
	{
		if (dropTarget != null)
		{
			dropTarget.addDropTargetListener(this);
		}
	}
	catch (TooManyListenersException tmle)
	{
		// should not happen... swing drop target is multicast
	}

	setBorder(BorderFactory.createLineBorder(Color.black));
}
 
Example #20
Source File: WComponentPeer.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * unregister a DropTarget with this native peer
 */

@Override
public synchronized void removeDropTarget(DropTarget dt) {
    nDropTargets--;
    if (nDropTargets == 0) {
        removeNativeDropTarget();
        nativeDropTargetContext = 0;
    }
}
 
Example #21
Source File: WComponentPeer.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * unregister a DropTarget with this native peer
 */

@Override
public synchronized void removeDropTarget(DropTarget dt) {
    nDropTargets--;
    if (nDropTargets == 0) {
        removeNativeDropTarget();
        nativeDropTargetContext = 0;
    }
}
 
Example #22
Source File: IndexedCustomizer.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Creates the instance, makes given component active for
* drop operation. */
IndexedDropTarget(IndexedCustomizer dialog, IndexedDragSource ids) {
    this.dialog = dialog;
    this.comp = dialog.control;
    this.cellRenderer = (IndexedListCellRenderer) this.comp.getCellRenderer();
    this.ids = ids;
    new DropTarget(comp, DnDConstants.ACTION_MOVE, this, true);
}
 
Example #23
Source File: Trace.java    From Method_Trace_Tool with Apache License 2.0 5 votes vote down vote up
public static void drag()//定义的拖拽方法
{
    //panel表示要接受拖拽的控件
    new DropTarget(JlPath, DnDConstants.ACTION_COPY_OR_MOVE, new DropTargetAdapter() {
        public void drop(DropTargetDropEvent dtde)//重写适配器的drop方法
        {
            try {
                if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor))//如果拖入的文件格式受支持
                {
                    dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);//接收拖拽来的数据
                    List<File> list = (List<File>) (dtde.getTransferable().getTransferData(DataFlavor.javaFileListFlavor));
                    String temp = "";
                    for (File file : list) {
                        temp = file.getAbsolutePath();
                        JlPath.setText(temp);
                        break;
                    }
                    //JOptionPane.showMessageDialog(null, temp);
                    dtde.dropComplete(true);//指示拖拽操作已完成
                } else {
                    dtde.rejectDrop();//否则拒绝拖拽来的数据
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}
 
Example #24
Source File: WComponentPeer.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * unregister a DropTarget with this native peer
 */

@Override
public synchronized void removeDropTarget(DropTarget dt) {
    nDropTargets--;
    if (nDropTargets == 0) {
        removeNativeDropTarget();
        nativeDropTargetContext = 0;
    }
}
 
Example #25
Source File: WComponentPeer.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * unregister a DropTarget with this native peer
 */

@Override
public synchronized void removeDropTarget(DropTarget dt) {
    nDropTargets--;
    if (nDropTargets == 0) {
        removeNativeDropTarget();
        nativeDropTargetContext = 0;
    }
}
 
Example #26
Source File: CDropTargetContextPeer.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Could be called when DnD enters a heavyweight or synthesized in processMotionMessage
 */
@Override
protected void processEnterMessage(SunDropTargetEvent event) {
    Component c = event.getComponent();
    DropTarget dt = event.getComponent().getDropTarget();
    if (isEventInsideTarget(event)
            && dt != insideTarget
            && c.isShowing()
            && dt != null
            && dt.isActive()) {
        insideTarget = dt;
        super.processEnterMessage(event);
    }
}
 
Example #27
Source File: DnDSupport.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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 ) );
}
 
Example #28
Source File: WComponentPeer.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * unregister a DropTarget with this native peer
 */

@Override
public synchronized void removeDropTarget(DropTarget dt) {
    nDropTargets--;
    if (nDropTargets == 0) {
        removeNativeDropTarget();
        nativeDropTargetContext = 0;
    }
}
 
Example #29
Source File: WComponentPeer.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * unregister a DropTarget with this native peer
 */

public synchronized void removeDropTarget(DropTarget dt) {
    nDropTargets--;
    if (nDropTargets == 0) {
        removeNativeDropTarget();
        nativeDropTargetContext = 0;
    }
}
 
Example #30
Source File: MainPanel.java    From java-swing-tips with MIT License 5 votes vote down vote up
private MainPanel() {
  super(new BorderLayout());
  JTabbedPane tabs = new JTabbedPane();
  tabs.addTab("00000000", new JScrollPane(makeList(0)));
  tabs.addTab("11111111", new JScrollPane(makeList(1)));
  tabs.addTab("22222222", new JScrollPane(makeList(2)));
  add(tabs);

  new DropTarget(tabs, DnDConstants.ACTION_MOVE, new TabTitleDropTargetListener(), true);
  setPreferredSize(new Dimension(320, 240));
}