Java Code Examples for java.awt.dnd.DropTarget

The following are top voted examples for showing how to use java.awt.dnd.DropTarget. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: alevin-svn2   File: PaneledGuiDemo.java   View source code 6 votes vote down vote up
@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;
}
 
Example 2
Project: incubator-netbeans   File: QuietEditorPane.java   View source code 6 votes vote down vote up
@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 );
        }
    }
}
 
Example 3
Project: incubator-netbeans   File: DnDSupport.java   View source code 6 votes vote down vote up
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 );
}
 
Example 4
Project: openjdk-jdk10   File: LWComponentPeer.java   View source code 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) {
                    throw new IllegalStateException("Current drop target is not null");
                }
                // Create a new drop target:
                fDropTarget = LWToolkit.getLWToolkit().createDropTarget(dt, target, this);
            }
        }
    }
}
 
Example 5
Project: incubator-netbeans   File: PluginManagerUI.java   View source code 6 votes vote down vote up
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);
}
 
Example 6
Project: openjdk-jdk10   File: LWComponentPeer.java   View source code 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 7
Project: OpenJSharp   File: CDropTarget.java   View source code 6 votes vote down vote up
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.");
    }
}
 
Example 8
Project: OpenJSharp   File: LWComponentPeer.java   View source code 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 9
Project: OpenJSharp   File: LWComponentPeer.java   View source code 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
Project: jdk8u-jdk   File: MissingDragExitEventTest.java   View source code 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 11
Project: Tarski   File: EditorRuler.java   View source code 6 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 12
Project: jdk8u-jdk   File: CDropTarget.java   View source code 6 votes vote down vote up
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.");
    }
}
 
Example 13
Project: jdk8u-jdk   File: LWComponentPeer.java   View source code 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 14
Project: incubator-netbeans   File: MenuEditLayer.java   View source code 5 votes vote down vote up
private void configureGlassLayer() {
    try {
        glassLayer.setDropTarget(new DropTarget());
        glassLayer.getDropTarget().addDropTargetListener(new GlassLayerDropTargetListener());
    } catch (TooManyListenersException ex) {
        ex.printStackTrace();
    }
}
 
Example 15
Project: incubator-netbeans   File: DnDSupport.java   View source code 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 16
Project: marathonv5   File: DnDHandler.java   View source code 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 17
Project: onprom   File: UMLDiagramPanel.java   View source code 5 votes vote down vote up
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);
}
 
Example 18
Project: VASSAL-src   File: SetupStack.java   View source code 5 votes vote down vote up
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);
}
 
Example 19
Project: VASSAL-src   File: RegionGrid.java   View source code 5 votes vote down vote up
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);
}
 
Example 20
Project: VASSAL-src   File: PieceMover.java   View source code 5 votes vote down vote up
/**
 * 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());
}
 
Example 21
Project: imagetozxspec   File: PopupPreviewFrame.java   View source code 5 votes vote down vote up
/**
 * 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();
}
 
Example 22
Project: OpenJSharp   File: SunDropTargetContextPeer.java   View source code 5 votes vote down vote up
/**
 * 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;
    }

}
 
Example 23
Project: OpenJSharp   File: SwingUtilities.java   View source code 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 24
Project: OpenJSharp   File: CDropTargetContextPeer.java   View source code 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 25
Project: jdk8u-jdk   File: XComponentPeer.java   View source code 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 26
Project: openjdk-jdk10   File: WComponentPeer.java   View source code 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 27
Project: OpenJSharp   File: WComponentPeer.java   View source code 5 votes vote down vote up
/**
 * register a DropTarget with this native peer
 */

@Override
public synchronized void addDropTarget(DropTarget dt) {
    if (nDropTargets == 0) {
        nativeDropTargetContext = addNativeDropTarget();
    }
    nDropTargets++;
}
 
Example 28
Project: OpenJSharp   File: WComponentPeer.java   View source code 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
Project: OpenJSharp   File: XComponentPeer.java   View source code 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 30
Project: openjdk-jdk10   File: MissingEventsOnModalDialogTest.java   View source code 5 votes vote down vote up
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();
}
 
Example 31
Project: Tarski   File: JTableRenderer.java   View source code 5 votes vote down vote up
/**
 * 
 */
public DropTarget getDropTarget()
{
	if (!((mxGraphTransferHandler) graphContainer.getTransferHandler())
			.isLocalDrag())
	{
		return super.getDropTarget();
	}

	return null;
}
 
Example 32
Project: Tarski   File: EditorRuler.java   View source code 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 33
Project: Tarski   File: mxGraphHandler.java   View source code 5 votes vote down vote up
/**
 * 
 */
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
  }
}
 
Example 34
Project: Method_Trace_Tool   File: Trace.java   View source code 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 35
Project: openjdk-jdk10   File: XComponentPeer.java   View source code 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 = AWTAccessor.getComponentAccessor().getPeer(comp);
            if (wpeer != null) {
                wpeer.addDropTarget();
            }
        }
    }
 
Example 36
Project: jdk8u-jdk   File: SunDropTargetContextPeer.java   View source code 5 votes vote down vote up
/**
 * 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;
    }

}
 
Example 37
Project: openjdk-jdk10   File: WComponentPeer.java   View source code 5 votes vote down vote up
/**
 * register a DropTarget with this native peer
 */

@Override
public synchronized void addDropTarget(DropTarget dt) {
    if (nDropTargets == 0) {
        nativeDropTargetContext = addNativeDropTarget();
    }
    nDropTargets++;
}
 
Example 38
Project: openjdk-jdk10   File: XComponentPeer.java   View source code 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 = AWTAccessor.getComponentAccessor()
                                       .getPeer(comp);
        if (wpeer != null) {
            wpeer.removeDropTarget();
        }
    }
}
 
Example 39
Project: jdk8u-jdk   File: CDropTargetContextPeer.java   View source code 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 40
Project: openjdk-jdk10   File: CDropTargetContextPeer.java   View source code 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);
    }
}