下面列出了java.awt.dnd.DragGestureEvent#getComponent ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* {@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);
}
}
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;
}
}
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);
}
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 );
}
}
}
}
@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);
}
}
}
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);
}
}