Java Code Examples for java.awt.dnd.DragGestureEvent

The following examples show how to use java.awt.dnd.DragGestureEvent. These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: pumpernickel   Source File: CustomizedToolbar.java    License: 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 2
Source Project: java-swing-tips   Source File: MainPanel.java    License: 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 3
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 4
Source Project: openjdk-jdk9   Source File: XToolkit.java    License: 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 5
Source Project: jdk8u_jdk   Source File: WToolkit.java    License: 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 Project: jdk8u_jdk   Source File: XToolkit.java    License: 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 7
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 8
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 9
/**
 * construct a new SunDragSourceContextPeer
 */

public SunDragSourceContextPeer(DragGestureEvent dge) {
    trigger = dge;
    if (trigger != null) {
        component = trigger.getComponent();
    } else {
        component = null;
    }
}
 
Example 10
Source Project: jaamsim   Source File: EntityPallet.java    License: 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 11
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 12
Source Project: gcs   Source File: TreePanel.java    License: 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 13
/**
 * construct a new SunDragSourceContextPeer
 */

public SunDragSourceContextPeer(DragGestureEvent dge) {
    trigger = dge;
    if (trigger != null) {
        component = trigger.getComponent();
    } else {
        component = null;
    }
}
 
Example 14
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 15
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
protected synchronized void setTrigger(DragGestureEvent dge) {
    trigger = dge;
    if (trigger != null) {
        component = trigger.getComponent();
    } else {
        component = null;
    }
}
 
Example 17
protected synchronized void setTrigger(DragGestureEvent dge) {
    trigger = dge;
    if (trigger != null) {
        component = trigger.getComponent();
    } else {
        component = null;
    }
}
 
Example 18
Source Project: jdk8u60   Source File: WToolkit.java    License: 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 19
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 Project: gcs   Source File: Outline.java    License: 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 21
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 22
/**
 * construct a new SunDragSourceContextPeer
 */

public SunDragSourceContextPeer(DragGestureEvent dge) {
    trigger = dge;
    if (trigger != null) {
        component = trigger.getComponent();
    } else {
        component = null;
    }
}
 
Example 23
Source Project: jdk8u-jdk   Source File: XToolkit.java    License: 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 24
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 Project: constellation   Source File: DragAction.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void dragGestureRecognized(DragGestureEvent dge) {
    final Point offset = new Point(DRAG_DROP_ICON.getWidth(null), DRAG_DROP_ICON.getHeight(null));
    source.startDrag(dge, DragSource.DefaultCopyDrop, DRAG_DROP_ICON, offset, this, null);
}
 
Example 26
/**
 * construct a new WDragSourceContextPeer. package private
 */

private WDragSourceContextPeer(DragGestureEvent dge) {
    super(dge);
}
 
Example 27
static XDragSourceContextPeer createDragSourceContextPeer(DragGestureEvent dge)
  throws InvalidDnDOperationException {
theInstance.setTrigger(dge);
    return theInstance;
}
 
Example 28
static WDragSourceContextPeer createDragSourceContextPeer(DragGestureEvent dge) throws InvalidDnDOperationException {
    theInstance.setTrigger(dge);
    return theInstance;
}
 
Example 29
protected DragGestureEvent getTrigger() {
    return trigger;
}
 
Example 30
private XDragSourceContextPeer(DragGestureEvent dge) {
    super(dge);
}
 
Example 31
private XDragSourceContextPeer(DragGestureEvent dge) {
    super(dge);
}
 
Example 32
static XDragSourceContextPeer createDragSourceContextPeer(DragGestureEvent dge)
  throws InvalidDnDOperationException {
theInstance.setTrigger(dge);
    return theInstance;
}
 
Example 33
/**
 * construct a new WDragSourceContextPeer. package private
 */

private WDragSourceContextPeer(DragGestureEvent dge) {
    super(dge);
}
 
Example 34
Source Project: jdk8u-jdk   Source File: bug7172833.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Override
public DragSourceContextPeer createDragSourceContextPeer(
        final DragGestureEvent dge) throws InvalidDnDOperationException {
    return null;
}
 
Example 35
@Override
public void dragGestureRecognized(DragGestureEvent dge) {
    dge.startDrag(Cursor.getDefaultCursor(), new StringSelection("test"));
}
 
Example 36
static XDragSourceContextPeer createDragSourceContextPeer(DragGestureEvent dge)
  throws InvalidDnDOperationException {
theInstance.setTrigger(dge);
    return theInstance;
}
 
Example 37
Source Project: netbeans   Source File: IndexedCustomizer.java    License: Apache License 2.0 4 votes vote down vote up
/** Utility accessor */
DragGestureEvent getDragGestureEvent() {
    return dge;
}
 
Example 38
public void dragGestureRecognized(DragGestureEvent dge) {
    dge.startDrag(null, new StringTransferable());
}
 
Example 39
/**
 * construct a new WDragSourceContextPeer. package private
 */

private WDragSourceContextPeer(DragGestureEvent dge) {
    super(dge);
}
 
Example 40
static WDragSourceContextPeer createDragSourceContextPeer(DragGestureEvent dge) throws InvalidDnDOperationException {
    theInstance.setTrigger(dge);
    return theInstance;
}