java.awt.dnd.DragSource Java Examples
The following examples show how to use
java.awt.dnd.DragSource.
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: DragAction.java From constellation with Apache License 2.0 | 6 votes |
public DraggableButton(final Action action) { super(action); addMouseListener(new MouseAdapter() { @Override public void mousePressed(final MouseEvent event) { getTransferHandler().exportAsDrag(DraggableButton.this, event, TransferHandler.COPY); } }); t = new TransferHandler("graph") { @Override public Transferable createTransferable(final JComponent c) { return new StringSelection("graphSelection"); } }; setTransferHandler(t); source = new DragSource(); source.createDefaultDragGestureRecognizer(this, DnDConstants.ACTION_COPY, this); }
Example #2
Source File: WToolkit.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
@Override public <T extends DragGestureRecognizer> T createDragGestureRecognizer(Class<T> abstractRecognizerClass, DragSource ds, Component c, int srcActions, DragGestureListener dgl) { final LightweightFrame f = SunToolkit.getLightweightFrame(c); if (f != null) { return f.createDragGestureRecognizer(abstractRecognizerClass, ds, c, srcActions, dgl); } if (MouseDragGestureRecognizer.class.equals(abstractRecognizerClass)) return (T)new WMouseDragGestureRecognizer(ds, c, srcActions, dgl); else return null; }
Example #3
Source File: ImageTransferTest.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
ImageDragSource() { formats = retrieveFormatsToTest(); passedArray = new boolean[formats.length]; final DragSourceListener dsl = new DragSourceAdapter() { public void dragDropEnd(DragSourceDropEvent e) { System.err.println("Drop was successful=" + e.getDropSuccess()); notifyTransferSuccess(e.getDropSuccess()); if (++fi < formats.length) { leaveFormat(formats[fi]); } } }; new DragSource().createDefaultDragGestureRecognizer(frame, DnDConstants.ACTION_COPY, dge -> dge.startDrag(null, new ImageSelection(image), dsl)); leaveFormat(formats[fi]); }
Example #4
Source File: ImageDecoratedDnD.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
public void start() { Frame f = new Frame("Use keyboard for DnD change"); Panel mainPanel; Component dragSource, dropTarget; f.setBounds(0, 400, 200, 200); f.setLayout(new BorderLayout()); mainPanel = new Panel(); mainPanel.setLayout(new BorderLayout()); mainPanel.setBackground(Color.blue); dropTarget = new DnDTarget(Color.red, Color.yellow); dragSource = new DnDSource("Drag ME! (" + (DragSource.isDragImageSupported()?"with ":"without") + " image)" ); mainPanel.add(dragSource, "North"); mainPanel.add(dropTarget, "Center"); f.add(mainPanel, BorderLayout.CENTER); f.setVisible(true); }
Example #5
Source File: ImageDecoratedDnD.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
public void start() { Frame f = new Frame("Use keyboard for DnD change"); Panel mainPanel; Component dragSource, dropTarget; f.setBounds(0, 400, 200, 200); f.setLayout(new BorderLayout()); mainPanel = new Panel(); mainPanel.setLayout(new BorderLayout()); mainPanel.setBackground(Color.blue); dropTarget = new DnDTarget(Color.red, Color.yellow); dragSource = new DnDSource("Drag ME! (" + (DragSource.isDragImageSupported()?"with ":"without") + " image)" ); mainPanel.add(dragSource, "North"); mainPanel.add(dropTarget, "Center"); f.add(mainPanel, BorderLayout.CENTER); f.setVisible(true); }
Example #6
Source File: RepositoryGlobalSearchGUIProvider.java From rapidminer-studio with GNU Affero General Public License v3.0 | 6 votes |
@Override public void dragGestureRecognized(DragGestureEvent event) { // only allow dragging with left mouse button if (event.getTriggerEvent().getModifiers() != InputEvent.BUTTON1_MASK) { return; } // change cursor to drag move Cursor cursor = null; if (event.getDragAction() == DnDConstants.ACTION_COPY) { cursor = DragSource.DefaultCopyDrop; } // set the repository entry as the Transferable TransferableRepositoryEntry transferable = new TransferableRepositoryEntry(location); if (usageLogger != null) { transferable.setUsageStatsLogger(usageLogger); } else if (usageObject != null) { transferable.setUsageObject(usageObject); } event.startDrag(cursor, transferable); }
Example #7
Source File: CustomizedToolbar.java From pumpernickel with MIT License | 6 votes |
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 #8
Source File: DragAndDropReorderPane.java From runelite with BSD 2-Clause "Simplified" License | 6 votes |
@Override public void mouseDragged(MouseEvent e) { if (SwingUtilities.isLeftMouseButton(e) && dragStartPoint != null) { Point point = e.getPoint(); if (draggingComponent != null) { drag(point); } else if (point.distance(dragStartPoint) > DragSource.getDragThreshold()) { startDragging(point); } } }
Example #9
Source File: ImageDecoratedDnD.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
public void start() { Frame f = new Frame("Use keyboard for DnD change"); Panel mainPanel; Component dragSource, dropTarget; f.setBounds(0, 400, 200, 200); f.setLayout(new BorderLayout()); mainPanel = new Panel(); mainPanel.setLayout(new BorderLayout()); mainPanel.setBackground(Color.blue); dropTarget = new DnDTarget(Color.red, Color.yellow); dragSource = new DnDSource("Drag ME! (" + (DragSource.isDragImageSupported()?"with ":"without") + " image)" ); mainPanel.add(dragSource, "North"); mainPanel.add(dropTarget, "Center"); f.add(mainPanel, BorderLayout.CENTER); f.setVisible(true); }
Example #10
Source File: WToolkit.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
@Override public <T extends DragGestureRecognizer> T createDragGestureRecognizer(Class<T> abstractRecognizerClass, DragSource ds, Component c, int srcActions, DragGestureListener dgl) { final LightweightFrame f = SunToolkit.getLightweightFrame(c); if (f != null) { return f.createDragGestureRecognizer(abstractRecognizerClass, ds, c, srcActions, dgl); } if (MouseDragGestureRecognizer.class.equals(abstractRecognizerClass)) return (T)new WMouseDragGestureRecognizer(ds, c, srcActions, dgl); else return null; }
Example #11
Source File: ImageTransferTest.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
ImageDragSource() { formats = retrieveFormatsToTest(); passedArray = new boolean[formats.length]; final DragSourceListener dsl = new DragSourceAdapter() { public void dragDropEnd(DragSourceDropEvent e) { System.err.println("Drop was successful=" + e.getDropSuccess()); notifyTransferSuccess(e.getDropSuccess()); if (++fi < formats.length) { leaveFormat(formats[fi]); } } }; new DragSource().createDefaultDragGestureRecognizer(frame, DnDConstants.ACTION_COPY, dge -> dge.startDrag(null, new ImageSelection(image), dsl)); leaveFormat(formats[fi]); }
Example #12
Source File: JLightweightFrame.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
public <T extends DragGestureRecognizer> T createDragGestureRecognizer( Class<T> abstractRecognizerClass, DragSource ds, Component c, int srcActions, DragGestureListener dgl) { return content == null ? null : content.createDragGestureRecognizer( abstractRecognizerClass, ds, c, srcActions, dgl); }
Example #13
Source File: TreePanel.java From gcs with Mozilla Public License 2.0 | 5 votes |
@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 #14
Source File: DBBrowserTree.java From nextreports-designer with Apache License 2.0 | 5 votes |
public void dragEnter(DragSourceDragEvent dsde) { if ((dsde.getDropAction() & DnDConstants.ACTION_MOVE) == DnDConstants.ACTION_MOVE) { dsde.getDragSourceContext().setCursor(DragSource.DefaultLinkDrop); } else { dsde.getDragSourceContext().setCursor(DragSource.DefaultLinkNoDrop); } }
Example #15
Source File: MissingEventsOnModalDialogTest.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { Frame sourceFrame = createFrame("Source Frame", 0, 0); Frame targetFrame = createFrame("Target Frame", 250, 250); DragSource defaultDragSource = DragSource.getDefaultDragSource(); defaultDragSource.createDefaultDragGestureRecognizer(sourceFrame, DnDConstants.ACTION_COPY_OR_MOVE, new TestDragGestureListener()); new DropTarget(targetFrame, DnDConstants.ACTION_COPY_OR_MOVE, new TestDropTargetListener(targetFrame)); Robot robot = new Robot(); robot.setAutoDelay(50); sourceFrame.toFront(); robot.waitForIdle(); Point point = getCenterPoint(sourceFrame); robot.mouseMove(point.x, point.y); robot.waitForIdle(); mouseDragAndDrop(robot, point, getCenterPoint(targetFrame)); long time = System.currentTimeMillis() + 200; while (!passed) { if (time < System.currentTimeMillis()) { sourceFrame.dispose(); targetFrame.dispose(); throw new RuntimeException("Mouse clicked event is lost!"); } Thread.sleep(10); } sourceFrame.dispose(); targetFrame.dispose(); }
Example #16
Source File: DragManager.java From netbeans with Apache License 2.0 | 5 votes |
/** Creates a new instance of SplashDnDSupport */ DragManager(JComponent component) { this.component = component; dSource = new DragSource(); dRecognizer = dSource.createDefaultDragGestureRecognizer(this.component,DnDConstants.ACTION_MOVE,this); dTarget = new DropTarget(this.component,DnDConstants.ACTION_MOVE,this); component.addMouseMotionListener(this); oCursor = component.getCursor(); }
Example #17
Source File: SourcePanel.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
public SourcePanel() { setPreferredSize(new Dimension(200, 200)); DragSource defaultDragSource = DragSource.getDefaultDragSource(); defaultDragSource.createDefaultDragGestureRecognizer(this, DnDConstants.ACTION_COPY_OR_MOVE, dragGestureListener); setBackground(Color.RED); }
Example #18
Source File: WMouseDragGestureRecognizer.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
/** * Invoked when a mouse button has been pressed on a component. */ public void mousePressed(MouseEvent e) { events.clear(); if (mapDragOperationFromModifiers(e) != DnDConstants.ACTION_NONE) { try { motionThreshold = DragSource.getDragThreshold(); } catch (Exception exc) { motionThreshold = 5; } appendEvent(e); } }
Example #19
Source File: DragRecognitionSupport.java From hottub with GNU General Public License v2.0 | 5 votes |
/** * Returns whether or not the event is potentially part of a drag sequence. */ private boolean mousePressedImpl(MouseEvent me) { component = (JComponent)me.getSource(); if (mapDragOperationFromModifiers(me, component.getTransferHandler()) != TransferHandler.NONE) { motionThreshold = DragSource.getDragThreshold(); dndArmedEvent = me; return true; } clearState(); return false; }
Example #20
Source File: SourceFileListFrame.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
SourceFileListFrame() { super("Source File List Frame"); extractFilesFromTheWorkingDirectory(); initList(); initGUI(); new DragSource().createDefaultDragGestureRecognizer(list, DnDConstants.ACTION_COPY,this); }
Example #21
Source File: MissingEventsOnModalDialogTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { Frame sourceFrame = createFrame("Source Frame", 0, 0); Frame targetFrame = createFrame("Target Frame", 250, 250); DragSource defaultDragSource = DragSource.getDefaultDragSource(); defaultDragSource.createDefaultDragGestureRecognizer(sourceFrame, DnDConstants.ACTION_COPY_OR_MOVE, new TestDragGestureListener()); new DropTarget(targetFrame, DnDConstants.ACTION_COPY_OR_MOVE, new TestDropTargetListener(targetFrame)); Robot robot = new Robot(); robot.setAutoDelay(50); sourceFrame.toFront(); robot.waitForIdle(); Point point = getCenterPoint(sourceFrame); robot.mouseMove(point.x, point.y); robot.waitForIdle(); mouseDragAndDrop(robot, point, getCenterPoint(targetFrame)); long time = System.currentTimeMillis() + 1000; while (!passed) { if (time < System.currentTimeMillis()) { sourceFrame.dispose(); targetFrame.dispose(); throw new RuntimeException("Mouse clicked event is lost!"); } Thread.sleep(10); } sourceFrame.dispose(); targetFrame.dispose(); }
Example #22
Source File: SourceFileListFrame.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
SourceFileListFrame() { super("Source File List Frame"); extractFilesFromTheWorkingDirectory(); initList(); initGUI(); new DragSource().createDefaultDragGestureRecognizer(list, DnDConstants.ACTION_COPY,this); }
Example #23
Source File: MainPanel.java From java-swing-tips with MIT License | 5 votes |
protected DnDTabbedPane() { super(); glassPane.setName("GlassPane"); new DropTarget(glassPane, DnDConstants.ACTION_COPY_OR_MOVE, new TabDropTargetListener(), true); DragSource.getDefaultDragSource().createDefaultDragGestureRecognizer( this, DnDConstants.ACTION_COPY_OR_MOVE, new TabDragGestureListener()); }
Example #24
Source File: SourceFileListFrame.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
SourceFileListFrame() { super("Source File List Frame"); extractFilesFromTheWorkingDirectory(); initList(); initGUI(); new DragSource().createDefaultDragGestureRecognizer(list, DnDConstants.ACTION_COPY,this); }
Example #25
Source File: HeadlessToolkit.java From Bytecoder with Apache License 2.0 | 5 votes |
@Override public <T extends DragGestureRecognizer> T createDragGestureRecognizer(Class<T> abstractRecognizerClass, DragSource ds, Component c, int srcActions, DragGestureListener dgl) { return null; }
Example #26
Source File: SourcePanel.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
public SourcePanel () { setPreferredSize(new Dimension(200, 200)); DragSource defaultDragSource = DragSource.getDefaultDragSource(); defaultDragSource.createDefaultDragGestureRecognizer(this, DnDConstants.ACTION_COPY_OR_MOVE, dragGestureListener); setBackground(Color.RED); }
Example #27
Source File: XMouseDragGestureRecognizer.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * Invoked when a mouse button has been pressed on a component. */ public void mousePressed(MouseEvent e) { events.clear(); if (mapDragOperationFromModifiers(e) != DnDConstants.ACTION_NONE) { try { motionThreshold = DragSource.getDragThreshold(); } catch (Exception exc) { motionThreshold = 5; } appendEvent(e); } }
Example #28
Source File: LightweightContent.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** * Create a drag gesture recognizer for the lightweight frame. */ default public <T extends DragGestureRecognizer> T createDragGestureRecognizer( Class<T> abstractRecognizerClass, DragSource ds, Component c, int srcActions, DragGestureListener dgl) { return null; }
Example #29
Source File: PaletteButton.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 5 votes |
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 #30
Source File: SourcePanel.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
public SourcePanel() { setPreferredSize(new Dimension(200, 200)); DragSource defaultDragSource = DragSource.getDefaultDragSource(); defaultDragSource.createDefaultDragGestureRecognizer(this, DnDConstants.ACTION_COPY_OR_MOVE, dragGestureListener); setBackground(Color.RED); }