java.awt.dnd.DragGestureEvent Java Examples

The following examples show how to use java.awt.dnd.DragGestureEvent. 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: MainPanel.java    From java-swing-tips with MIT License 6 votes vote down vote up
@Override public void dragGestureRecognized(DragGestureEvent e) {
  Optional.ofNullable(e.getComponent())
      .filter(c -> c instanceof DnDTabbedPane).map(c -> (DnDTabbedPane) c)
      .filter(tabbedPane -> tabbedPane.getTabCount() > 1)
      .ifPresent(tabbedPane -> {
        Point tabPt = e.getDragOrigin();
        int idx = tabbedPane.indexAtLocation(tabPt.x, tabPt.y);
        int selIdx = tabbedPane.getSelectedIndex();
        // When a tab runs rotation occurs, a tab that is not the target is dragged.
        // pointed out by Arjen
        boolean isTabRunsRotated = !(tabbedPane.getUI() instanceof MetalTabbedPaneUI)
            && tabbedPane.getTabLayoutPolicy() == JTabbedPane.WRAP_TAB_LAYOUT
            && idx != selIdx;
        tabbedPane.dragTabIndex = isTabRunsRotated ? selIdx : idx;
        if (tabbedPane.dragTabIndex >= 0 && tabbedPane.isEnabledAt(tabbedPane.dragTabIndex)) {
          tabbedPane.initGlassPane(tabPt);
          try {
            e.startDrag(DragSource.DefaultMoveDrop, new TabTransferable(tabbedPane), new TabDragSourceListener());
          } catch (InvalidDnDOperationException ex) {
            throw new IllegalStateException(ex);
          }
        }
      });
}
 
Example #2
Source File: CustomizedToolbar.java    From pumpernickel with MIT License 6 votes vote down vote up
private boolean triggerDrag(JFrame f, Point p, DragGestureEvent dge,
		JComponent c) {
	Rectangle r = new Rectangle(0, 0, c.getWidth(), c.getHeight());
	r = SwingUtilities.convertRectangle(c, r, f);

	if (r.contains(p)) {
		draggingFromToolbar = true;
		draggingDefaults = false;
		draggingComponent = c.getName();
		MockComponent mc = new MockComponent(c);
		Transferable transferable = new MockComponentTransferable(mc);
		BufferedImage bi = mc.getBufferedImage();
		dge.startDrag(DragSource.DefaultMoveDrop, bi, new Point(r.x
				- p.x, r.y - p.y), transferable, dragSourceListener);
		return true;
	}
	return false;
}
 
Example #3
Source File: TreePanel.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public void dragGestureRecognized(DragGestureEvent event) {
    mDropReceived = false;
    int   dragAction = event.getDragAction();
    Point where      = new Point(event.getDragOrigin());
    switch (checkAndConvertToArea(where)) {
    case CONTENT:
        if (!mIgnoreNextDragGesture && mDragColumnDivider == -1 && !mSelectedRows.isEmpty() && (dragAction & mAllowedRowDragTypes) != 0) {
            TreeRowSelection selection = new TreeRowSelection(getSelectedRows(), mOpenRows);
            if (DragSource.isDragImageSupported()) {
                Img       dragImage = createDragImage(where);
                Point     imageOffset;
                Rectangle dragClip  = getDragClip();
                imageOffset = dragClip != null ? new Point(dragClip.x - where.x, dragClip.y - where.y) : new Point();
                event.startDrag(null, dragImage, imageOffset, selection, this);
            } else {
                event.startDrag(null, selection, this);
            }
        }
        break;
    case HEADER:
        if (mAllowColumnDrag && dragAction == DnDConstants.ACTION_MOVE && mSortColumn != null) {
            setSourceDragColumn(mSortColumn);
            if (DragSource.isDragImageSupported()) {
                event.startDrag(null, createColumnDragImage(mSortColumn), new Point(-(where.x - getColumnStart(mSortColumn)), -where.y), mSortColumn, this);
            } else {
                event.startDrag(null, mSortColumn, this);
            }
        }
        mSortColumn = null;
        break;
    default:
        break;
    }
}
 
Example #4
Source File: Outline.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public void dragGestureRecognized(DragGestureEvent dge) {
    if (mDividerDrag == null && mModel.hasSelection() && allowRowDrag() && hasFocus()) {
        Point        pt        = dge.getDragOrigin();
        RowSelection selection = new RowSelection(mModel, mModel.getSelectionAsList(true).toArray(new Row[0]));
        if (DragSource.isDragImageSupported()) {
            Img   dragImage   = getDragImage(pt.x, pt.y);
            Point imageOffset = new Point(mDragClip.x - pt.x, mDragClip.y - pt.y);
            dge.startDrag(null, dragImage, imageOffset, selection, null);
        } else {
            dge.startDrag(null, selection);
        }
    }
}
 
Example #5
Source File: WToolkit.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * create the peer for a DragSourceContext
 */

@Override
public DragSourceContextPeer createDragSourceContextPeer(DragGestureEvent dge) throws InvalidDnDOperationException {
    final LightweightFrame f = SunToolkit.getLightweightFrame(dge.getComponent());
    if (f != null) {
        return f.createDragSourceContextPeer(dge);
    }

    return WDragSourceContextPeer.createDragSourceContextPeer(dge);
}
 
Example #6
Source File: XToolkit.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public DragSourceContextPeer createDragSourceContextPeer(DragGestureEvent dge) throws InvalidDnDOperationException {
    final LightweightFrame f = SunToolkit.getLightweightFrame(dge.getComponent());
    if (f != null) {
        return f.createDragSourceContextPeer(dge);
    }

    return XDragSourceContextPeer.createDragSourceContextPeer(dge);
}
 
Example #7
Source File: SourceFileListFrame.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public void dragGestureRecognized(DragGestureEvent dge) {
    java.util.List<URI> uriList = Stream.of(list.getItems())
                                            .map(File::new)
                                            .map(File::toURI)
                                            .collect(Collectors.toList());

    dge.startDrag(null, new URIListTransferable(uriList));
}
 
Example #8
Source File: PaletteButton.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void dragGestureRecognized( final DragGestureEvent anEvent ) {
  final ElementMetaData elementMetaData = ElementTypeRegistry.getInstance().getElementType( elementName );
  final ElementMetaDataTransferable transferable = new ElementMetaDataTransferable( elementMetaData );
  anEvent.startDrag( DragSource.DefaultCopyNoDrop, EMPTY_DRAG_IMAGE, new Point(), transferable, null );

  final ButtonModel model = getModel();
  model.setArmed( false );
  model.setPressed( false );
}
 
Example #9
Source File: SunDragSourceContextPeer.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * construct a new SunDragSourceContextPeer
 */

public SunDragSourceContextPeer(DragGestureEvent dge) {
    trigger = dge;
    if (trigger != null) {
        component = trigger.getComponent();
    } else {
        component = null;
    }
}
 
Example #10
Source File: XToolkit.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public DragSourceContextPeer createDragSourceContextPeer(DragGestureEvent dge) throws InvalidDnDOperationException {
    final LightweightFrame f = SunToolkit.getLightweightFrame(dge.getComponent());
    if (f != null) {
        return f.createDragSourceContextPeer(dge);
    }

    return XDragSourceContextPeer.createDragSourceContextPeer(dge);
}
 
Example #11
Source File: SourceFileListFrame.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public void dragGestureRecognized(DragGestureEvent dge) {
    String [] filesAsStringArray = list.getItems();
    File [] files = new File[filesAsStringArray.length];
    for (int fileNumber=0; fileNumber<filesAsStringArray.length ; fileNumber++ ) {
        files[fileNumber]=new File(filesAsStringArray[fileNumber]);
    }
    dge.startDrag(null, new FileListTransferable(Arrays.asList(files)));
}
 
Example #12
Source File: XToolkit.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public DragSourceContextPeer createDragSourceContextPeer(DragGestureEvent dge) throws InvalidDnDOperationException {
    final LightweightFrame f = SunToolkit.getLightweightFrame(dge.getComponent());
    if (f != null) {
        return f.createDragSourceContextPeer(dge);
    }

    return XDragSourceContextPeer.createDragSourceContextPeer(dge);
}
 
Example #13
Source File: SourceFileListFrame.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public void dragGestureRecognized(DragGestureEvent dge) {
    java.util.List<URI> uriList = Stream.of(list.getItems())
                                            .map(File::new)
                                            .map(File::toURI)
                                            .collect(Collectors.toList());

    dge.startDrag(null, new URIListTransferable(uriList));
}
 
Example #14
Source File: WToolkit.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * create the peer for a DragSourceContext
 */

@Override
public DragSourceContextPeer createDragSourceContextPeer(DragGestureEvent dge) throws InvalidDnDOperationException {
    final LightweightFrame f = SunToolkit.getLightweightFrame(dge.getComponent());
    if (f != null) {
        return f.createDragSourceContextPeer(dge);
    }

    return WDragSourceContextPeer.createDragSourceContextPeer(dge);
}
 
Example #15
Source File: SourceFileListFrame.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void dragGestureRecognized(DragGestureEvent dge) {
    String [] filesAsStringArray = list.getItems();
    File [] files = new File[filesAsStringArray.length];
    for (int fileNumber=0; fileNumber<filesAsStringArray.length ; fileNumber++ ) {
        files[fileNumber]=new File(filesAsStringArray[fileNumber]);
    }
    dge.startDrag(null, new FileListTransferable(Arrays.asList(files)));
}
 
Example #16
Source File: SunDragSourceContextPeer.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * construct a new SunDragSourceContextPeer
 */

public SunDragSourceContextPeer(DragGestureEvent dge) {
    trigger = dge;
    if (trigger != null) {
        component = trigger.getComponent();
    } else {
        component = null;
    }
}
 
Example #17
Source File: SourceFileListFrame.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public void dragGestureRecognized(DragGestureEvent dge) {
    String [] filesAsStringArray = list.getItems();
    File [] files = new File[filesAsStringArray.length];
    for (int fileNumber=0; fileNumber<filesAsStringArray.length ; fileNumber++ ) {
        files[fileNumber]=new File(filesAsStringArray[fileNumber]);
    }
    dge.startDrag(null, new FileListTransferable(Arrays.asList(files)));
}
 
Example #18
Source File: SourceFileListFrame.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public void dragGestureRecognized(DragGestureEvent dge) {
    String [] filesAsStringArray = list.getItems();
    File [] files = new File[filesAsStringArray.length];
    for (int fileNumber=0; fileNumber<filesAsStringArray.length ; fileNumber++ ) {
        files[fileNumber]=new File(filesAsStringArray[fileNumber]);
    }
    dge.startDrag(null, new FileListTransferable(Arrays.asList(files)));
}
 
Example #19
Source File: SourceFileListFrame.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public void dragGestureRecognized(DragGestureEvent dge) {
    java.util.List<URI> uriList = Stream.of(list.getItems())
                                            .map(File::new)
                                            .map(File::toURI)
                                            .collect(Collectors.toList());

    dge.startDrag(null, new URIListTransferable(uriList));
}
 
Example #20
Source File: SunDragSourceContextPeer.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
protected synchronized void setTrigger(DragGestureEvent dge) {
    trigger = dge;
    if (trigger != null) {
        component = trigger.getComponent();
    } else {
        component = null;
    }
}
 
Example #21
Source File: EntityPallet.java    From jaamsim with Apache License 2.0 5 votes vote down vote up
@Override
public void dragGestureRecognized(DragGestureEvent event) {

	TreePath path = tree.getSelectionPath();
	if (path != null) {

		// Dragged node is a DefaultMutableTreeNode
		if(path.getLastPathComponent() instanceof DefaultMutableTreeNode) {
			DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) path.getLastPathComponent();

			// This is an ObjectType node
			if(treeNode.getUserObject() instanceof ObjectType) {
				ObjectType type = (ObjectType) treeNode.getUserObject();
				Cursor cursor = null;

				if (event.getDragAction() == DnDConstants.ACTION_COPY) {
					cursor = DragSource.DefaultCopyDrop;
				}
				if (RenderManager.isGood()) {
					// The new renderer is initialized
					RenderManager.inst().startDragAndDrop(type);
					event.startDrag(cursor,new TransferableObjectType(type), RenderManager.inst());

				} else {
					event.startDrag(cursor,new TransferableObjectType(type));
				}
			}
		}
	}
}
 
Example #22
Source File: SunDragSourceContextPeer.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
protected synchronized void setTrigger(DragGestureEvent dge) {
    trigger = dge;
    if (trigger != null) {
        component = trigger.getComponent();
    } else {
        component = null;
    }
}
 
Example #23
Source File: SunDragSourceContextPeer.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * construct a new SunDragSourceContextPeer
 */

public SunDragSourceContextPeer(DragGestureEvent dge) {
    trigger = dge;
    if (trigger != null) {
        component = trigger.getComponent();
    } else {
        component = null;
    }
}
 
Example #24
Source File: SourceFileListFrame.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public void dragGestureRecognized(DragGestureEvent dge) {
    String [] filesAsStringArray = list.getItems();
    File [] files = new File[filesAsStringArray.length];
    for (int fileNumber=0; fileNumber<filesAsStringArray.length ; fileNumber++ ) {
        files[fileNumber]=new File(filesAsStringArray[fileNumber]);
    }
    dge.startDrag(null, new FileListTransferable(Arrays.asList(files)));
}
 
Example #25
Source File: MissingEventsOnModalDialogTest.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public void dragGestureRecognized(DragGestureEvent dge) {
    dge.startDrag(null, new StringTransferable());
}
 
Example #26
Source File: bug7172833.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Override
public DragSourceContextPeer createDragSourceContextPeer(
        final DragGestureEvent dge) throws InvalidDnDOperationException {
    return null;
}
 
Example #27
Source File: SourcePanel.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public void dragGestureRecognized(DragGestureEvent dge) {
    dge.startDrag(null, new MyTransferable());
}
 
Example #28
Source File: SourcePanel.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public void dragGestureRecognized(DragGestureEvent dge) {
    dge.startDrag(null, new MyTransferable());
}
 
Example #29
Source File: LightweightContent.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Create a drag source context peer for the lightweight frame.
 */
default public DragSourceContextPeer createDragSourceContextPeer(DragGestureEvent dge) throws InvalidDnDOperationException
{
    return null;
}
 
Example #30
Source File: ExtraDragEnterTest.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void dragGestureRecognized(DragGestureEvent dge) {
    dge.startDrag(Cursor.getDefaultCursor(), new StringSelection("test"));
}