/** * Initializes a drag source context. * * @exception IllegalArgumentException If Component or DragSource of trigger are null, the drag * action for the trigger event is DnDConstants.ACTION_NONE or if the source actions for the * DragGestureRecognizer associated with the trigger event are equal to * DnDConstants.ACTION_NONE. * @exception NullPointerException If peer or trigger is null. */ public DragSourceContext( DragSourceContextPeer peer, DragGestureEvent trigger, Cursor cursor, Image image, Point offset, Transferable trans, DragSourceListener dsl) { if (peer == null || trigger == null) throw new NullPointerException(); if (trigger.getComponent() == null || trigger.getDragSource() == null || trigger.getDragAction() == DnDConstants.ACTION_NONE || trigger.getSourceAsDragGestureRecognizer().getSourceActions() == DnDConstants.ACTION_NONE) throw new IllegalArgumentException(); this.peer = peer; this.trigger = trigger; this.cursor = cursor; this.image = image; this.offset = offset; this.transferable = trans; this.dragSourceListener = dsl; throw new Error("not implemented"); }
/** * Start the drag if the operation is ok. uses java.awt.datatransfer.StringSelection to transfer * the label's data * * @param e the event object */ public void dragGestureRecognized(DragGestureEvent e) { // if the action is ok we go ahead // otherwise we punt System.out.println(e.getDragAction()); if ((e.getDragAction() & DragLabel.this.dragAction) == 0) return; System.out.println("kicking off drag"); // get the label's text and put it inside a Transferable // Transferable transferable = new StringSelection( DragLabel.this.getText() ); Transferable transferable = new StringTransferable(DragLabel.this.getText()); // now kick off the drag try { // initial cursor, transferrable, dsource listener e.startDrag(DragSource.DefaultCopyNoDrop, transferable, DragLabel.this.dsListener); // or if dragSource is a variable // dragSource.startDrag(e, DragSource.DefaultCopyDrop, transferable, dsListener); // or if you'd like to use a drag image if supported /* if(DragSource.isDragImageSupported() ) // cursor, image, point, transferrable, dsource listener e.startDrag(DragSource.DefaultCopyDrop, image, point, transferable, dsListener); */ } catch (InvalidDnDOperationException idoe) { System.err.println(idoe); } }
public void dragGestureRecognized(DragGestureEvent event) { if (folderPanel.getMainFrame().getNoEventsMode()) return; FileTable fileTable = folderPanel.getFileTable(); FileTableModel tableModel = fileTable.getFileTableModel(); // Return (do not initiate drag) if mouse button2 or button3 was used if ((event.getTriggerEvent().getModifiers() & (InputEvent.BUTTON2_MASK | InputEvent.BUTTON3_MASK)) != 0) return; // Do not use that to retrieve the current selected file as it is inaccurate: the selection // could have changed since the // the mouse was clicked. // AbstractFile selectedFile = fileTable.getSelectedFile(false); // // Return if selected file is null (could happen if '..' is selected) // if(selectedFile==null) // return; // Find out which row was clicked int clickedRow = fileTable.rowAtPoint(event.getDragOrigin()); // Return (do not initiate drag) if the selected file is the parent folder '..' if (clickedRow == -1 || fileTable.isParentFolder(clickedRow)) return; // Retrieve the file corresponding to the clicked row AbstractFile selectedFile = tableModel.getFileAtRow(clickedRow); // Find out which files are to be dragged, based on the selected file and currenlty marked // files. // If there are some files marked, drag marked files only if the selected file is one of the // marked files. // In any other case, only drag the selected file. FileSet markedFiles; FileSet draggedFiles; if (tableModel.getNbMarkedFiles() > 0 && (markedFiles = fileTable.getSelectedFiles()).contains(selectedFile)) { draggedFiles = markedFiles; } else { draggedFiles = new FileSet(fileTable.getCurrentFolder(), selectedFile); } // Set initial DnDContext information DnDContext.setDragInitiatedByMucommander(true); DnDContext.setDragInitiator(folderPanel); DnDContext.setDragGestureModifiersEx(event.getTriggerEvent().getModifiersEx()); // Start dragging DragSource.getDefaultDragSource() .startDrag(event, null, new TransferableFileSet(draggedFiles), this); // DragSource.getDefaultDragSource().startDrag(createCustomDragGestureEvent(event, // DnDConstants.ACTION_MOVE), null, new TransferableFileSet(draggedFiles), this); }
@Override public void dragGestureRecognized(DragGestureEvent dge) { Cursor cursor = null; BufferedImage bi = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB); paint(bi.getGraphics()); ImageMover.start(bi, MouseInfo.getPointerInfo().getLocation()); String s = "[ANDITEM]"; if (dge.getDragAction() == DnDConstants.ACTION_COPY) { cursor = DragSource.DefaultCopyDrop; } dge.startDrag( cursor, new SimpleDragObject.TransferableSimpleDragObject(new SimpleDragObject(s))); }
public int getSourceActions() { return trigger.getSourceAsDragGestureRecognizer().getSourceActions(); }
public Component getComponent() { return trigger.getComponent(); }
public DragSource getDragSource() { return trigger.getDragSource(); }