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

项目:alevin-svn2    文件:PaneledGuiDemo.java   
@Override
protected JComponent createCenterPane() {
    graphpanel = new SampleGraphPanel();
    graphpanel.setPreferredSize(new Dimension(600, 300));
    new DropTarget(graphpanel, new FileDropTargetListener() {
        @Override
        protected void openFile(File file) {
            // insert your own function for loading a file
            JOptionPane.showMessageDialog(graphpanel,
                    "Opened " + file.getName());
        }

        @Override
        protected boolean canOpenFile() {
            // is GUI ready for opening a file?
            return true;
        }
    });
    return graphpanel;
}
项目:incubator-netbeans    文件:QuietEditorPane.java   
@Override
public void setDocument(Document doc) {
    super.setDocument(doc);

    // Setting DelegatingTransferHandler, where CallbackTransferable will
    // be handled in importData method. 
    // For more details, please refer issue #53439        
    if (doc != null){
        TransferHandler thn = getTransferHandler();
        if( !(thn instanceof DelegatingTransferHandler) ) {
            DelegatingTransferHandler dth = new DelegatingTransferHandler(thn);
            setTransferHandler(dth);
        }

        DropTarget currDt = getDropTarget();
        if( !(currDt instanceof DelegatingDropTarget ) ) {
            DropTarget dt = new DelegatingDropTarget( currDt );
            setDropTarget( dt );
        }
    }
}
项目:incubator-netbeans    文件:DnDSupport.java   
void remove( CategoryDescriptor descriptor ) {
    ArrayList<DragGestureRecognizer> recognizersToRemove = new ArrayList<DragGestureRecognizer>( 2 );
    for( Iterator<DragGestureRecognizer> i=recognizers.iterator(); i.hasNext(); ) {
        DragGestureRecognizer dgr = i.next();
        if( dgr.getComponent() == descriptor.getButton()
            || dgr.getComponent() == descriptor.getList() ) {
            recognizersToRemove.add( dgr );
            dgr.removeDragGestureListener( this );
        }
    }
    recognizers.removeAll( recognizersToRemove );

    ArrayList<DropTarget> dropTargetsToRemove = new ArrayList<DropTarget>( 2 );
    for( Iterator<DropTarget> i=dropTargets.iterator(); i.hasNext(); ) {
        DropTarget dt = i.next();
        if( dt.getComponent() == descriptor.getButton()
            || dt.getComponent() == descriptor.getList() ) {
            dropTargetsToRemove.add( dt );
            dt.removeDropTargetListener( this );
        }
    }
    dropTargets.removeAll( dropTargetsToRemove );
}
项目:openjdk-jdk10    文件: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) {
                    throw new IllegalStateException("Current drop target is not null");
                }
                // Create a new drop target:
                fDropTarget = LWToolkit.getLWToolkit().createDropTarget(dt, target, this);
            }
        }
    }
}
项目:incubator-netbeans    文件:PluginManagerUI.java   
private void postInitComponents () {
    Containers.initNotify ();
    updateTable = createTabForModel(new UpdateTableModel(units));
    availableTable = createTabForModel(new AvailableTableModel (units));
    final LocalDownloadSupport localDownloadSupport = new LocalDownloadSupport();
    final LocallyDownloadedTableModel localTM = new LocallyDownloadedTableModel(localDownloadSupport);
    localTable = createTabForModel(localTM);
    installedTable = createTabForModel(new InstalledTableModel(units));

    DropTargetListener l = new LocallDownloadDnD(localDownloadSupport, localTM, this);
    final DropTarget dt = new DropTarget(null, l);
    dt.setActive(true);
    this.setDropTarget(dt);


    final SettingsTab tab = new SettingsTab(this);
    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            tpTabs.add(tab, INDEX_OF_SETTINGS_TAB);
            tpTabs.setTitleAt(INDEX_OF_SETTINGS_TAB, tab.getDisplayName());
        }
    });
    setWaitingState(true);
}
项目:openjdk-jdk10    文件: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.");
            }
        }
    }
}
项目:OpenJSharp    文件:CDropTarget.java   
private CDropTarget(DropTarget dropTarget, Component component, ComponentPeer peer) {
    super();

    fDropTarget = dropTarget;
    fComponent = component;
    fPeer = peer;

    long nativePeer = CPlatformWindow.getNativeViewPtr(((LWComponentPeer) peer).getPlatformWindow());
    if (nativePeer == 0L) return; // Unsupported for a window without a native view (plugin)

    // Create native dragging destination:
    fNativeDropTarget = this.createNativeDropTarget(dropTarget, component, peer, nativePeer);
    if (fNativeDropTarget == 0) {
        throw new IllegalStateException("CDropTarget.createNativeDropTarget() failed.");
    }
}
项目:OpenJSharp    文件: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);
            }
        }
    }
}
项目:OpenJSharp    文件: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.");
            }
        }
    }
}
项目: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);
}
项目:Tarski    文件: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));
}
项目:jdk8u-jdk    文件:CDropTarget.java   
private CDropTarget(DropTarget dropTarget, Component component, ComponentPeer peer) {
    super();

    fDropTarget = dropTarget;
    fComponent = component;
    fPeer = peer;

    long nativePeer = CPlatformWindow.getNativeViewPtr(((LWComponentPeer) peer).getPlatformWindow());
    if (nativePeer == 0L) return; // Unsupported for a window without a native view (plugin)

    // Create native dragging destination:
    fNativeDropTarget = this.createNativeDropTarget(dropTarget, component, peer, nativePeer);
    if (fNativeDropTarget == 0) {
        throw new IllegalStateException("CDropTarget.createNativeDropTarget() failed.");
    }
}
项目:jdk8u-jdk    文件: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);
            }
        }
    }
}
项目:incubator-netbeans    文件:MenuEditLayer.java   
private void configureGlassLayer() {
    try {
        glassLayer.setDropTarget(new DropTarget());
        glassLayer.getDropTarget().addDropTargetListener(new GlassLayerDropTargetListener());
    } catch (TooManyListenersException ex) {
        ex.printStackTrace();
    }
}
项目: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 ) );
}
项目: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;
}
项目:onprom    文件:UMLDiagramPanel.java   
public UMLDiagramPanel(DiagramEditor _editorLoader) {
  diagramEditor = _editorLoader;
  isOpenGLEnabled = Boolean.parseBoolean(System.getProperty("sun.java2d.opengl"));
  if (!isOpenGLEnabled) {
    logger.warn("OpenGL is not enabled, there could be some performance and quality issues. It can be enabled using -Dsun.java2d.opengl=true runtime argument.");
  }
  // we are going to listen mouse clicks and movements for various operations
  this.addMouseListener(this);
  this.addMouseMotionListener(this);
  this.addMouseWheelListener(this);
  this.setDropTarget(new DropTarget(this, DnDConstants.ACTION_COPY_OR_MOVE, new DropTargetAdapter() {
    @Override
    public void drop(DropTargetDropEvent dtde) {
      if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
        try {
          dtde.acceptDrop(dtde.getDropAction());
          Object transferData = dtde.getTransferable().getTransferData(DataFlavor.javaFileListFlavor);
          if (transferData != null && transferData instanceof List) {
            List files = (List) transferData;
            if (files.size() > 0) {
              diagramEditor.open((File) files.get(0));
              dtde.dropComplete(true);
            }
          }
        } catch (Exception e) {
          logger.error(e.getMessage(), e);
          InformationDialog.display(e.getMessage());
        }
      } else {
        dtde.rejectDrop();
      }
    }
  }));
  this.setBackground(Color.WHITE);
}
项目:VASSAL-src    文件:SetupStack.java   
public View(Board b, SetupStack s) {
  myBoard = b;
  myGrid = b.getGrid();
  myStack = s;
  slot = myStack.getTopPiece();
  if (slot != null) {
    myPiece = slot.getPiece();
  }
  new DropTarget(this, DnDConstants.ACTION_MOVE, this);
  ds.createDefaultDragGestureRecognizer(this,
    DnDConstants.ACTION_MOVE, this);
  setFocusTraversalKeysEnabled(false);
}
项目:VASSAL-src    文件:RegionGrid.java   
public View(Board b, RegionGrid grid, Config config) {
  myBoard = b;
  this.grid = grid;
  this.config = config;
  new DropTarget(this, DnDConstants.ACTION_MOVE, this);
  ds.createDefaultDragGestureRecognizer(this,
    DnDConstants.ACTION_MOVE, this);
  setFocusTraversalKeysEnabled(false);
}
项目:VASSAL-src    文件:PieceMover.java   
/**
 * Creates a new DropTarget and hooks us into the beginning of a
 * DropTargetListener chain. DropTarget events are not multicast;
 * there can be only one "true" listener.
 */
static public DropTarget makeDropTarget(Component theComponent, int dndContants, DropTargetListener dropTargetListener) {
  if (dropTargetListener != null) {
    DragHandler.getTheDragHandler()
               .dropTargetListeners.put(theComponent, dropTargetListener);
  }
  return new DropTarget(theComponent, dndContants,
                        DragHandler.getTheDragHandler());
}
项目:imagetozxspec    文件:PopupPreviewFrame.java   
/**
 * Dither preview frame that locks the resize
 * to the fixed dimensions required for all dithers
 */
PopupPreviewFrame(UiCallback uiCallback) {
    setTitle(getCaption("preview_title"));
    setIconImage(ImageToZxSpec.IMAGE_ICON.getImage());
    createPreviewImagePanel();
    setDropTarget(new DropTarget(this, new CustomDropTargetListener(uiCallback)));
    getContentPane().setLayout(new BorderLayout());
    getContentPane().add(createRefreshButton(uiCallback), BorderLayout.PAGE_START);
    getContentPane().add(createScrollPane(), BorderLayout.CENTER);
    setPreferredSize(new Dimension(calculateWidth(), calculateHeight()));
    setResizable(false);
    pack();
}
项目:OpenJSharp    文件:SunDropTargetContextPeer.java   
/**
 * actual processing on EventQueue Thread
 */

protected void processEnterMessage(SunDropTargetEvent event) {
    Component  c    = (Component)event.getSource();
    DropTarget dt   = c.getDropTarget();
    Point      hots = event.getPoint();

    local = getJVMLocalSourceTransferable();

    if (currentDTC != null) { // some wreckage from last time
        currentDTC.removeNotify();
        currentDTC = null;
    }

    if (c.isShowing() && dt != null && dt.isActive()) {
        currentDT  = dt;
        currentDTC = currentDT.getDropTargetContext();

        currentDTC.addNotify(this);

        currentA   = dt.getDefaultActions();

        try {
            ((DropTargetListener)dt).dragEnter(new DropTargetDragEvent(currentDTC,
                                                                       hots,
                                                                       currentDA,
                                                                       currentSA));
        } catch (Exception e) {
            e.printStackTrace();
            currentDA = DnDConstants.ACTION_NONE;
        }
    } else {
        currentDT  = null;
        currentDTC = null;
        currentDA   = DnDConstants.ACTION_NONE;
        currentSA   = DnDConstants.ACTION_NONE;
        currentA   = DnDConstants.ACTION_NONE;
    }

}
项目:OpenJSharp    文件: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));
            }
        }
    }
}
项目:OpenJSharp    文件: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);
    }
}
项目:jdk8u-jdk    文件: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();
        }
    }
}
项目:openjdk-jdk10    文件:WComponentPeer.java   
/**
 * unregister a DropTarget with this native peer
 */

@Override
public synchronized void removeDropTarget(DropTarget dt) {
    nDropTargets--;
    if (nDropTargets == 0) {
        removeNativeDropTarget();
        nativeDropTargetContext = 0;
    }
}
项目:OpenJSharp    文件:WComponentPeer.java   
/**
 * register a DropTarget with this native peer
 */

@Override
public synchronized void addDropTarget(DropTarget dt) {
    if (nDropTargets == 0) {
        nativeDropTargetContext = addNativeDropTarget();
    }
    nDropTargets++;
}
项目:OpenJSharp    文件:WComponentPeer.java   
/**
 * unregister a DropTarget with this native peer
 */

@Override
public synchronized void removeDropTarget(DropTarget dt) {
    nDropTargets--;
    if (nDropTargets == 0) {
        removeNativeDropTarget();
        nativeDropTargetContext = 0;
    }
}
项目:OpenJSharp    文件: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();
            }
        }
    }
项目:openjdk-jdk10    文件:MissingEventsOnModalDialogTest.java   
private static void runTest() throws Exception {
    Frame sourceFrame = createFrame("Source Frame", 100, 100);
    Frame targetFrame = createFrame("Target Frame", 350, 350);

    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() + 1000;

    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();
}
项目:Tarski    文件:JTableRenderer.java   
/**
 * 
 */
public DropTarget getDropTarget()
{
    if (!((mxGraphTransferHandler) graphContainer.getTransferHandler())
            .isLocalDrag())
    {
        return super.getDropTarget();
    }

    return null;
}
项目:Tarski    文件: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));
}
项目:Tarski    文件:mxGraphHandler.java   
/**
 * 
 */
protected void installDropTargetHandler() {
  DropTarget dropTarget = graphComponent.getDropTarget();

  try {
    if (dropTarget != null) {
      dropTarget.addDropTargetListener(this);
      currentDropTarget = dropTarget;
    }
  } catch (TooManyListenersException tmle) {
    // should not happen... swing drop target is multicast
  }
}
项目: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();
            }
        }
    });
}
项目:openjdk-jdk10    文件: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 = AWTAccessor.getComponentAccessor().getPeer(comp);
            if (wpeer != null) {
                wpeer.addDropTarget();
            }
        }
    }
项目:jdk8u-jdk    文件:SunDropTargetContextPeer.java   
/**
 * actual processing on EventQueue Thread
 */

protected void processEnterMessage(SunDropTargetEvent event) {
    Component  c    = (Component)event.getSource();
    DropTarget dt   = c.getDropTarget();
    Point      hots = event.getPoint();

    local = getJVMLocalSourceTransferable();

    if (currentDTC != null) { // some wreckage from last time
        currentDTC.removeNotify();
        currentDTC = null;
    }

    if (c.isShowing() && dt != null && dt.isActive()) {
        currentDT  = dt;
        currentDTC = currentDT.getDropTargetContext();

        currentDTC.addNotify(this);

        currentA   = dt.getDefaultActions();

        try {
            ((DropTargetListener)dt).dragEnter(new DropTargetDragEvent(currentDTC,
                                                                       hots,
                                                                       currentDA,
                                                                       currentSA));
        } catch (Exception e) {
            e.printStackTrace();
            currentDA = DnDConstants.ACTION_NONE;
        }
    } else {
        currentDT  = null;
        currentDTC = null;
        currentDA   = DnDConstants.ACTION_NONE;
        currentSA   = DnDConstants.ACTION_NONE;
        currentA   = DnDConstants.ACTION_NONE;
    }

}
项目:openjdk-jdk10    文件:WComponentPeer.java   
/**
 * register a DropTarget with this native peer
 */

@Override
public synchronized void addDropTarget(DropTarget dt) {
    if (nDropTargets == 0) {
        nativeDropTargetContext = addNativeDropTarget();
    }
    nDropTargets++;
}
项目:openjdk-jdk10    文件: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 = AWTAccessor.getComponentAccessor()
                                       .getPeer(comp);
        if (wpeer != null) {
            wpeer.removeDropTarget();
        }
    }
}
项目:jdk8u-jdk    文件: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);
    }
}
项目:openjdk-jdk10    文件: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);
    }
}