Java Code Examples for java.awt.dnd.DragGestureEvent#getComponent()
The following examples show how to use
java.awt.dnd.DragGestureEvent#getComponent() .
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: DefaultTransferHandler.java From freecol with GNU General Public License v2.0 | 6 votes |
/** * {@inheritDoc} */ public void dragGestureRecognized(DragGestureEvent dge) { JComponent c = (JComponent)dge.getComponent(); DefaultTransferHandler th = (DefaultTransferHandler)c.getTransferHandler(); Transferable t = th.createTransferable(c); if (t == null) { logger.warning("Unable to create transferable for: " + dge); th.exportDone(c, null, NONE); return; } this.scrolls = c.getAutoscrolls(); c.setAutoscrolls(false); try { Cursor cursor = getCursor(c); dge.startDrag(cursor, t, this); } catch (RuntimeException re) { c.setAutoscrolls(this.scrolls); } }
Example 2
Source File: CustomizedToolbar.java From pumpernickel with MIT License | 6 votes |
public void dragGestureRecognized(DragGestureEvent dge) { Point p = dge.getDragOrigin(); Component c = dge.getComponent(); JFrame f = (JFrame) SwingUtilities.getWindowAncestor(c); p = SwingUtilities.convertPoint(c, p, f); for (int a = 0; a < componentList.length; a++) { if (triggerDrag(f, p, dge, componentList[a])) return; } // double-check for separators & gaps: for (int a = 0; a < getComponentCount(); a++) { if (triggerDrag(f, p, dge, (JComponent) getComponent(a))) return; } }
Example 3
Source File: CustomizedToolbarOptions.java From pumpernickel with MIT License | 6 votes |
public void dragGestureRecognized(DragGestureEvent dge) { Point p = dge.getDragOrigin(); MockComponent mc = (MockComponent) dge.getComponent(); Transferable transferable = new MockComponentTransferable(mc); BufferedImage bi = mc.getBufferedImage(); if (mc instanceof MockDefaultToolbar) { toolbar.draggingComponent = ""; } else if (mc.getName().equals("-")) { toolbar.draggingComponent = toolbar.getNewSeparatorName(); } else if (mc.getName().equals(" ")) { toolbar.draggingComponent = toolbar.getNewSpaceName(); } else if (mc.getName().equals("\t")) { toolbar.draggingComponent = toolbar.getNewFlexibleSpaceName(); } else { toolbar.draggingComponent = mc.getName(); } toolbar.draggingDefaults = (mc instanceof MockDefaultToolbar); toolbar.draggingFromToolbar = false; dge.startDrag(DragSource.DefaultMoveDrop, bi, new Point(-p.x, -p.y), transferable, dragSourceListener); }
Example 4
Source File: DnDSupport.java From netbeans with Apache License 2.0 | 5 votes |
public void dragGestureRecognized( DragGestureEvent dge ) { Transferable t = null; if( dge.getComponent() instanceof CategoryButton ) { //trying to drag a palette category CategoryButton button = (CategoryButton)dge.getComponent(); draggingCategory = button.getCategory(); t = draggingCategory.getTransferable(); } else if( dge.getComponent() instanceof CategoryList ) { //trying to drag a palette item CategoryList list = (CategoryList)dge.getComponent(); int selIndex = list.locationToIndex( dge.getDragOrigin() ); draggingItem = list.getItemAt( selIndex ); if( null == draggingItem ) { return; } t = draggingItem.drag(); dragSourceCategoryList = list; } if( null != t ) { dge.getDragSource().addDragSourceListener( getDragSourceListener() ); try { dge.startDrag( null, t ); } catch( InvalidDnDOperationException idndE ) { //attempt to fix #110670 try { dge.startDrag( null, t ); } catch( InvalidDnDOperationException e ) { ERR.log( Level.INFO, idndE.getMessage(), e ); } } } }
Example 5
Source File: DnDTree.java From netbeans-mmd-plugin with Apache License 2.0 | 5 votes |
@Override public void dragGestureRecognized(@Nonnull final DragGestureEvent dragGestureEvent) { final JTree tree = (JTree) dragGestureEvent.getComponent(); final TreePath path = tree.getSelectionPath(); if (path != null) { final Object selection = path.getLastPathComponent(); if (selection instanceof NodeFileOrFolder) { FileTransferable node = new FileTransferable(Arrays.asList(((NodeFileOrFolder) selection).makeFileForNode())); dragGestureEvent.startDrag(DragSource.DefaultCopyDrop, node, this); } } }
Example 6
Source File: DnDSupport.java From netbeans with Apache License 2.0 | 4 votes |
public void dragGestureRecognized(DragGestureEvent e) { Component c = e.getComponent(); if( !(c instanceof JComponent) ) return; Transferable t = null; try { final DataObject dob = (DataObject) ((JComponent) c).getClientProperty("file"); if( dob != null && c.getParent() instanceof Toolbar && buttonDndAllowed ) { //dragging a toolbar button sourceToolbar = (Toolbar) c.getParent(); t = new ExTransferable.Single(buttonDataFlavor) { public Object getData() { return dob; } }; isToolbarDrag = false; isButtonDrag = true; dragSourceButtonIndex = sourceToolbar.getComponentIndex(c); } else if( Boolean.TRUE.equals( ((JComponent) c).getClientProperty(ToolbarContainer.PROP_DRAGGER) ) ) { //dragging the whole toolbar final ToolbarContainer container = (ToolbarContainer) c.getParent().getParent(); if( container.isShowing() ) { sourceContainer = container; sourceRow = (ToolbarRow) container.getParent(); t = new ExTransferable.Single(toolbarDataFlavor) { public Object getData() { return container; } }; isToolbarDrag = true; isButtonDrag = false; startingPoint = new Point(e.getDragOrigin()); Rectangle bounds = new Rectangle(sourceContainer.getPreferredSize()); bounds.setLocation(sourceContainer.getLocationOnScreen()); dragImage = createContentImage(sourceContainer, bounds.getSize()); sourceRow.dragStarted( sourceContainer ); dragWindow = createDragWindow( dragImage, bounds ); } } if( c instanceof JButton ) { ((JButton) c).getModel().setArmed(false); ((JButton) c).getModel().setPressed(false); ((JButton) c).getModel().setRollover(true); } if( t != null ) { e.startDrag(dragMoveCursor, t, this); } } catch( InvalidDnDOperationException idoE ) { log.log(Level.INFO, null, idoE); } }