List of usage examples for java.awt.dnd DnDConstants ACTION_COPY_OR_MOVE
int ACTION_COPY_OR_MOVE
To view the source code for java.awt.dnd DnDConstants ACTION_COPY_OR_MOVE.
Click Source Link
From source file:FileTreeDropTarget.java
public FileTreeDropTarget(FileTree tree) { this.tree = tree; // Listen for changes in the enabled property tree.addPropertyChangeListener(this); // Create the DropTarget and register // it with the FileTree. dropTarget = new DropTarget(tree, DnDConstants.ACTION_COPY_OR_MOVE, this, tree.isEnabled(), null); }
From source file:net.sf.jabref.gui.entryeditor.SimpleUrlDragDrop.java
@Override public void drop(DropTargetDropEvent event) { Transferable tsf = event.getTransferable(); event.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE); //try with an URL DataFlavor dataFlavor = null; try {//from w ww . ja va 2s . c o m dataFlavor = new DataFlavor("application/x-java-url; class=java.net.URL"); } catch (ClassNotFoundException e) { LOGGER.warn("Could not find DropTargetDropEvent class", e); } try { URL url = (URL) tsf.getTransferData(dataFlavor); //insert URL editor.setText(url.toString()); storeFieldAction.actionPerformed(new ActionEvent(editor, 0, "")); } catch (UnsupportedFlavorException nfe) { // if not an URL JOptionPane.showMessageDialog((Component) editor, Localization.lang("Operation not supported"), Localization.lang("Drag and Drop Error"), JOptionPane.ERROR_MESSAGE); LOGGER.warn("Could not perform drage and drop", nfe); } catch (IOException ioex) { LOGGER.warn("Could not perform drage and drop", ioex); } }
From source file:Main.java
public DragLabel(String s, int alignment) { super(s, alignment); int action = DnDConstants.ACTION_COPY_OR_MOVE; ds.createDefaultDragGestureRecognizer(this, action, this); }
From source file:de.tor.tribes.ui.windows.AbstractDSWorkbenchFrame.java
public AbstractDSWorkbenchFrame() { mFrameListeners = new LinkedList<>(); // getContentPane().setBackground(Constants.DS_BACK); dragSource = DragSource.getDefaultDragSource(); dragSource.createDefaultDragGestureRecognizer(this, DnDConstants.ACTION_COPY_OR_MOVE, this); DropTarget dropTarget = new DropTarget(this, this); this.setDropTarget(dropTarget); }
From source file:com.mirth.connect.client.ui.editors.JavaScriptEditorDialog.java
public void dragEnter(DropTargetDragEvent dtde) { try {//from w w w . j a va 2 s. c om Transferable tr = dtde.getTransferable(); if (tr.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { dtde.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE); java.util.List fileList = (java.util.List) tr.getTransferData(DataFlavor.javaFileListFlavor); Iterator iterator = fileList.iterator(); while (iterator.hasNext()) { iterator.next(); } } else { dtde.rejectDrag(); } } catch (Exception e) { dtde.rejectDrag(); } }
From source file:EditorDropTarget3.java
public void drop(DropTargetDropEvent dtde) { DnDUtils.debugPrintln("DropTarget drop, drop action = " + DnDUtils.showActions(dtde.getDropAction())); // Check the drop action if ((dtde.getDropAction() & DnDConstants.ACTION_COPY_OR_MOVE) != 0) { // Accept the drop and get the transfer data dtde.acceptDrop(dtde.getDropAction()); Transferable transferable = dtde.getTransferable(); try {/*from w w w. java 2 s. c om*/ boolean result = false; if (draggingFile) { result = dropFile(transferable); } else { result = dropContent(transferable, dtde); } dtde.dropComplete(result); DnDUtils.debugPrintln("Drop completed, success: " + result); } catch (Exception e) { DnDUtils.debugPrintln("Exception while handling drop " + e); dtde.dropComplete(false); } } else { DnDUtils.debugPrintln("Drop target rejected drop"); dtde.rejectDrop(); } }
From source file:PanelDropTarget.java
protected boolean acceptOrRejectDrag(DropTargetDragEvent dtde) { int dropAction = dtde.getDropAction(); int sourceActions = dtde.getSourceActions(); boolean acceptedDrag = false; DnDUtils.debugPrintln("\tSource actions are " + DnDUtils.showActions(sourceActions) + ", drop action is " + DnDUtils.showActions(dropAction)); // Reject if the object being transferred // or the operations available are not acceptable. if (!acceptableType || (sourceActions & DnDConstants.ACTION_COPY_OR_MOVE) == 0) { DnDUtils.debugPrintln("Drop target rejecting drag"); dtde.rejectDrag();/*from w w w . j ava 2 s .c om*/ } else if ((dropAction & DnDConstants.ACTION_COPY_OR_MOVE) == 0) { // Not offering copy or move - suggest a copy DnDUtils.debugPrintln("Drop target offering COPY"); dtde.acceptDrag(DnDConstants.ACTION_COPY); acceptedDrag = true; } else { // Offering an acceptable operation: accept DnDUtils.debugPrintln("Drop target accepting drag"); dtde.acceptDrag(dropAction); acceptedDrag = true; } return acceptedDrag; }
From source file:EditorDropTarget4.java
public void drop(DropTargetDropEvent dtde) { DnDUtils.debugPrintln("DropTarget drop, drop action = " + DnDUtils.showActions(dtde.getDropAction())); // Check the drop action if ((dtde.getDropAction() & DnDConstants.ACTION_COPY_OR_MOVE) != 0) { // Accept the drop and get the transfer data dtde.acceptDrop(dtde.getDropAction()); Transferable transferable = dtde.getTransferable(); try {/* w w w . j av a 2 s. c o m*/ boolean result = false; if (draggingFile) { result = dropFile(transferable); } else { result = dropContent(transferable, dtde); } dtde.dropComplete(result); DnDUtils.debugPrintln("Drop completed, success: " + result); } catch (Exception e) { DnDUtils.debugPrintln("Exception while handling drop " + e); dtde.rejectDrop(); } } else { DnDUtils.debugPrintln("Drop target rejected drop"); dtde.dropComplete(false); } }
From source file:ColorSink.java
public void dragEnter(DropTargetDragEvent e) { if (e.isDataFlavorSupported(TransferableColor.colorFlavor) || e.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { e.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE); this.setBorder(dropBorder); }// w w w. j a va 2s.c o m }
From source file:net.sf.jabref.gui.UrlDragDrop.java
@Override public void drop(DropTargetDropEvent dtde) { Transferable tsf = dtde.getTransferable(); dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE); //try with an URL DataFlavor dtURL = null;/* ww w .java 2 s.c o m*/ try { dtURL = new DataFlavor("application/x-java-url; class=java.net.URL"); } catch (ClassNotFoundException e) { LOGGER.warn("Could not find DropTargetDropEvent class.", e); } try { URL url = (URL) tsf.getTransferData(dtURL); JOptionChoice res = (JOptionChoice) JOptionPane.showInputDialog(editor, "", Localization.lang("Select action"), JOptionPane.QUESTION_MESSAGE, null, new JOptionChoice[] { new JOptionChoice(Localization.lang("Insert URL"), 0), new JOptionChoice(Localization.lang("Download file"), 1) }, new JOptionChoice(Localization.lang("Insert URL"), 0)); if (res != null) { switch (res.getId()) { //insert URL case 0: feditor.setText(url.toString()); editor.updateField(feditor); break; //download file case 1: try { //auto filename: File file = new File(new File(Globals.prefs.get("pdfDirectory")), editor.getEntry().getCiteKey() + ".pdf"); frame.output(Localization.lang("Downloading...")); MonitoredURLDownload.buildMonitoredDownload(editor, url).downloadToFile(file); frame.output(Localization.lang("Download completed")); feditor.setText(file.toURI().toURL().toString()); editor.updateField(feditor); } catch (IOException ioex) { LOGGER.error("Error while downloading file.", ioex); JOptionPane.showMessageDialog(editor, Localization.lang("File download"), Localization.lang("Error while downloading file:" + ioex.getMessage()), JOptionPane.ERROR_MESSAGE); } break; default: LOGGER.warn("Unknown selection (should not happen)"); break; } } return; } catch (UnsupportedFlavorException nfe) { // not an URL then... LOGGER.warn("Could not parse URL.", nfe); } catch (IOException ioex) { LOGGER.warn("Could not perform drag and drop.", ioex); } try { //try with a File List @SuppressWarnings("unchecked") List<File> filelist = (List<File>) tsf.getTransferData(DataFlavor.javaFileListFlavor); if (filelist.size() > 1) { JOptionPane.showMessageDialog(editor, Localization.lang("Only one item is supported"), Localization.lang("Drag and Drop Error"), JOptionPane.ERROR_MESSAGE); return; } File fl = filelist.get(0); feditor.setText(fl.toURI().toURL().toString()); editor.updateField(feditor); } catch (UnsupportedFlavorException nfe) { JOptionPane.showMessageDialog(editor, Localization.lang("Operation not supported"), Localization.lang("Drag and Drop Error"), JOptionPane.ERROR_MESSAGE); LOGGER.warn("Could not perform drag and drop.", nfe); } catch (IOException ioex) { LOGGER.warn("Could not perform drag and drop.", ioex); } }