Java Code Examples for java.awt.dnd.DragGestureEvent#getDragOrigin()

The following examples show how to use java.awt.dnd.DragGestureEvent#getDragOrigin() . 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: DragAndDropFeedbackVisualizer.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void start(final DragGestureEvent e) {
    originalLocationOnScreen = source.getComponent().getLocationOnScreen();
    final Rectangle tabRect = source.getTabBounds(tabIndex);
    if( prefs.getBoolean(WinSysPrefs.DND_SMALLWINDOWS, true) ) {
        originalLocationOnScreen.x += tabRect.x;
    }

    DragWindow tmp = createDragWindow( tabIndex );
    if( null != tmp ) {
        dragOffset = new Point( 0, 0 );
        Point loc = new Point( e.getDragOrigin() );
        SwingUtilities.convertPointToScreen(loc, e.getComponent());
        tmp.setLocation( loc.x-dragOffset.x, loc.y-dragOffset.y );
        //let the JNA transparency stuff to kick in
        try {
            tmp.setVisible( true );
            //make drag window visible, i.e. move to proper location,
            //dragImage.setLocation( startingPoint );
            dragWindow = tmp;
        } catch( UnsatisfiedLinkError ulE ) {
            Logger.getLogger(DragAndDropFeedbackVisualizer.class.getName()).log(Level.INFO, null, ulE);
        } catch( Throwable ex ) {
            Logger.getLogger(DragAndDropFeedbackVisualizer.class.getName()).log(Level.FINE, null, ex);
        }
    }
}
 
Example 2
Source File: CustomizedToolbar.java    From pumpernickel with MIT License 6 votes vote down vote up
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 vote down vote up
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: OutputTree.java    From swing_library with MIT License 6 votes vote down vote up
public void dragGestureRecognized(DragGestureEvent dge) {
	
	Point location = dge.getDragOrigin();

	TreePath path = this.getPathForLocation(location.x, location.y);

	DefaultMutableTreeNode node = (DefaultMutableTreeNode) path
			.getLastPathComponent();

	System.out
			.println("The class of user object node is node.getUserObject() "
					+ node.getUserObject().getClass());

	Output o = (Output) node.getUserObject();

	if (o != null) {
		Transferable transferable = new SimpleTransferable(o);
		dge.startDrag(null, transferable, this);
	}
}
 
Example 5
Source File: OutlineHeader.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public void dragGestureRecognized(DragGestureEvent dge) {
    if (mSortColumn != null && mOwner.allowColumnDrag()) {
        mOwner.setSourceDragColumn(mSortColumn);
        if (DragSource.isDragImageSupported()) {
            Point pt = dge.getDragOrigin();
            dge.startDrag(null, mOwner.getColumnDragImage(mSortColumn), new Point(-(pt.x - mOwner.getColumnStart(mSortColumn)), -pt.y), mSortColumn, this);
        } else {
            dge.startDrag(null, mSortColumn, this);
        }
        mSortColumn = null;
    }
}
 
Example 6
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 7
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 8
Source File: DockTab.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public void dragGestureRecognized(DragGestureEvent dge) {
    DockableTransferable transferable = new DockableTransferable(mDockable);
    if (DragSource.isDragImageSupported()) {
        Point offset = new Point(dge.getDragOrigin());
        offset.x = -offset.x;
        offset.y = -offset.y;
        dge.startDrag(null, DragSource.isDragImageSupported() ? UIUtilities.getImage(this) : null, offset, transferable, null);
    } else {
        dge.startDrag(null, transferable);
    }
}
 
Example 9
Source File: MainPanel.java    From java-swing-tips with MIT License 5 votes vote down vote up
@Override public void dragGestureRecognized(DragGestureEvent dge) {
  // System.out.println("dragGestureRecognized");
  Point pt = dge.getDragOrigin();
  TreePath path = getPathForLocation(pt.x, pt.y);
  if (Objects.isNull(path) || Objects.isNull(path.getParentPath())) {
    return;
  }
  // System.out.println("start " + path.toString());
  draggedNode = (TreeNode) path.getLastPathComponent();
  Transferable trans = new TreeNodeTransferable(draggedNode);
  DragSource.getDefaultDragSource().startDrag(dge, Cursor.getDefaultCursor(), trans, new NodeDragSourceListener());
}
 
Example 10
Source File: DnDSupport.java    From netbeans with Apache License 2.0 4 votes vote down vote up
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);
    }
}