类java.awt.dnd.DropTarget源码实例Demo

下面列出了怎么用java.awt.dnd.DropTarget的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: openjdk-jdk8u   文件: LWComponentPeer.java
@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);
            }
        }
    }
}
 
源代码2 项目: TrakEM2   文件: AbstractTreeTransferHandler.java
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;
    }
}
 
源代码3 项目: hottub   文件: LWComponentPeer.java
@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);
            }
        }
    }
}
 
源代码4 项目: dragonwell8_jdk   文件: LWComponentPeer.java
@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.");
            }
        }
    }
}
 
源代码5 项目: jdk8u-jdk   文件: LWComponentPeer.java
@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.");
            }
        }
    }
}
 
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);
}
 
源代码7 项目: openjdk-8-source   文件: LWComponentPeer.java
@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.");
            }
        }
    }
}
 
源代码8 项目: jdk8u-jdk   文件: MissingDragExitEventTest.java
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);
}
 
源代码9 项目: jdk8u-jdk   文件: MissingDragExitEventTest.java
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);
}
 
源代码10 项目: TencentKona-8   文件: MissingDragExitEventTest.java
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);
}
 
源代码11 项目: openjdk-8-source   文件: CDropTargetContextPeer.java
/**
 * 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);
    }
}
 
源代码12 项目: darklaf   文件: DarkTabbedPaneUI.java
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();
    }
}
 
源代码13 项目: hottub   文件: XComponentPeer.java
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();
        }
    }
}
 
源代码14 项目: blog-codes   文件: EditorRuler.java
/**
 * 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));
}
 
源代码15 项目: openjdk-8-source   文件: XComponentPeer.java
/****** 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();
            }
        }
    }
 
源代码16 项目: openjdk-8-source   文件: SwingUtilities.java
/**
 * 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));
            }
        }
    }
}
 
源代码17 项目: TencentKona-8   文件: XComponentPeer.java
/****** 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();
            }
        }
    }
 
源代码18 项目: MobyDroid   文件: JPanel_FileManager.java
/**
 *
 */
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);*/
        }
    });
}
 
源代码19 项目: TencentKona-8   文件: WComponentPeer.java
/**
 * unregister a DropTarget with this native peer
 */

@Override
public synchronized void removeDropTarget(DropTarget dt) {
    nDropTargets--;
    if (nDropTargets == 0) {
        removeNativeDropTarget();
        nativeDropTargetContext = 0;
    }
}
 
源代码20 项目: marathonv5   文件: DnDHandler.java
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;
}
 
源代码21 项目: jdk8u-jdk   文件: WComponentPeer.java
/**
 * unregister a DropTarget with this native peer
 */

@Override
public synchronized void removeDropTarget(DropTarget dt) {
    nDropTargets--;
    if (nDropTargets == 0) {
        removeNativeDropTarget();
        nativeDropTargetContext = 0;
    }
}
 
源代码22 项目: uima-uimaj   文件: StyleMapTable.java
/**
 * 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));
}
 
源代码23 项目: jdk8u_jdk   文件: WComponentPeer.java
/**
 * unregister a DropTarget with this native peer
 */

@Override
public synchronized void removeDropTarget(DropTarget dt) {
    nDropTargets--;
    if (nDropTargets == 0) {
        removeNativeDropTarget();
        nativeDropTargetContext = 0;
    }
}
 
源代码24 项目: netbeans   文件: IndexedCustomizer.java
/** 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);
}
 
源代码25 项目: Method_Trace_Tool   文件: Trace.java
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();
            }
        }
    });
}
 
源代码26 项目: hottub   文件: WComponentPeer.java
/**
 * unregister a DropTarget with this native peer
 */

@Override
public synchronized void removeDropTarget(DropTarget dt) {
    nDropTargets--;
    if (nDropTargets == 0) {
        removeNativeDropTarget();
        nativeDropTargetContext = 0;
    }
}
 
源代码27 项目: 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 ) );
}
 
源代码28 项目: dragonwell8_jdk   文件: WComponentPeer.java
/**
 * unregister a DropTarget with this native peer
 */

@Override
public synchronized void removeDropTarget(DropTarget dt) {
    nDropTargets--;
    if (nDropTargets == 0) {
        removeNativeDropTarget();
        nativeDropTargetContext = 0;
    }
}
 
源代码29 项目: java-swing-tips   文件: MainPanel.java
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));
}
 
源代码30 项目: openjdk-8   文件: WComponentPeer.java
/**
 * unregister a DropTarget with this native peer
 */

public synchronized void removeDropTarget(DropTarget dt) {
    nDropTargets--;
    if (nDropTargets == 0) {
        removeNativeDropTarget();
        nativeDropTargetContext = 0;
    }
}
 
 类所在包
 同包方法