List of usage examples for java.awt.dnd DnDConstants ACTION_MOVE
int ACTION_MOVE
To view the source code for java.awt.dnd DnDConstants ACTION_MOVE.
Click Source Link
From source file:com.igormaznitsa.sciareto.ui.editors.MMDEditor.java
@Override public void dragEnter(@Nonnull final DropTargetDragEvent dtde) { this.dragAcceptableType = checkDragType(dtde); if (!this.dragAcceptableType) { dtde.rejectDrag();/*from w w w.j a v a 2s. c o m*/ } else { dtde.acceptDrag(DnDConstants.ACTION_MOVE); } repaint(); }
From source file:com.igormaznitsa.sciareto.ui.editors.MMDEditor.java
@Override public void dragOver(@Nonnull final DropTargetDragEvent dtde) { if (acceptOrRejectDragging(dtde)) { dtde.acceptDrag(DnDConstants.ACTION_MOVE); } else {//from w w w . ja v a2 s . c o m dtde.rejectDrag(); } repaint(); }
From source file:com.igormaznitsa.sciareto.ui.editors.MMDEditor.java
@Override public void drop(@Nonnull final DropTargetDropEvent dtde) { dtde.acceptDrop(DnDConstants.ACTION_MOVE); File detectedFileObject = null; for (final DataFlavor df : dtde.getCurrentDataFlavors()) { final Class<?> representation = df.getRepresentationClass(); if (FileTransferable.class.isAssignableFrom(representation)) { final FileTransferable t = (FileTransferable) dtde.getTransferable(); final List<File> listOfFiles = t.getFiles(); detectedFileObject = listOfFiles.isEmpty() ? null : listOfFiles.get(0); break; } else if (df.isFlavorJavaFileListType()) { try { final List list = (List) dtde.getTransferable().getTransferData(DataFlavor.javaFileListFlavor); if (list != null && !list.isEmpty()) { detectedFileObject = (File) list.get(0); }//from w w w.j av a 2 s . c o m break; } catch (Exception ex) { LOGGER.error("Can't extract file from DnD", ex); } } } if (detectedFileObject != null) { addFileToElement(detectedFileObject, this.mindMapPanel.findTopicUnderPoint(dtde.getLocation())); } }
From source file:FileTreeDropTarget.java
protected void transferDirectory(int action, File srcDir, File targetDirectory, FileTree.FileTreeNode targetNode) { DnDUtils.debugPrintln((action == DnDConstants.ACTION_COPY ? "Copy" : "Move") + " directory " + srcDir.getAbsolutePath() + " to " + targetDirectory.getAbsolutePath()); // Do not copy a directory into itself or // a subdirectory of itself. File parentDir = targetDirectory; while (parentDir != null) { if (parentDir.equals(srcDir)) { DnDUtils.debugPrintln("-- SUPPRESSED"); return; }//w w w . j a va 2s.com parentDir = parentDir.getParentFile(); } // Copy the directory itself, then its contents // Create a File entry for the target String name = srcDir.getName(); File newDir = new File(targetDirectory, name); if (newDir.exists()) { // Already exists - is it the same directory? if (newDir.equals(srcDir)) { // Exactly the same file - ignore return; } } else { // Directory does not exist - create it if (newDir.mkdir() == false) { // Failed to create - abandon this directory JOptionPane.showMessageDialog(tree, "Failed to create target directory\n " + newDir.getAbsolutePath(), "Directory creation Failed", JOptionPane.ERROR_MESSAGE); return; } } // Add a node for the new directory if (targetNode != null) { targetNode = tree.addNode(targetNode, name); } // Now copy the directory content. File[] files = srcDir.listFiles(); for (int i = 0; i < files.length; i++) { File f = files[i]; if (f.isFile()) { transferFile(action, f, newDir, targetNode); } else if (f.isDirectory()) { transferDirectory(action, f, newDir, targetNode); } } // Remove the source directory after moving if (action == DnDConstants.ACTION_MOVE && System.getProperty("DnDExamples.allowRemove") != null) { srcDir.delete(); } }
From source file:net.sf.nmedit.jtheme.component.JTModuleContainer.java
public void copyMoveModules(DropTargetDropEvent dtde) { DataFlavor chosen = PDragDrop.ModuleSelectionFlavor; Transferable transfer = dtde.getTransferable(); Object data = null;/*from w w w . j a va 2s . c o m*/ try { // Get the data data = transfer.getTransferData(chosen); dtde.acceptDrop(dtde.getDropAction() & (DnDConstants.ACTION_MOVE | DnDConstants.ACTION_COPY | DnDConstants.ACTION_LINK)); } catch (Throwable t) { if (log.isWarnEnabled()) { log.warn("copyMoveModules(DropTargetDropEvent=" + dtde + ") failed", t); } dtde.dropComplete(false); return; } if (data != null && data instanceof PModuleTransferData) { // Cast the data and create a nice module. PModuleTransferData tdata = ((PModuleTransferData) data); boolean isSamePatch = false; if (tdata.getSourcePatch() == getModuleContainer().getPatch()) isSamePatch = true; //Point p = dtde.getLocation(); int action = dtde.getDropAction(); if ((action & DnDConstants.ACTION_MOVE) != 0 && isSamePatch) { MoveOperation op = tdata.getSourceModuleContainer().createMoveOperation(); op.setDestination(getModuleContainer()); executeOperationOnSelection(tdata, dtde.getLocation(), op); } else { copyModules(tdata, dtde.getLocation(), ((dtde.getDropAction() & DnDConstants.ACTION_LINK) != 0)); } } dtde.dropComplete(true); }
From source file:DragDropTreeExample.java
protected void transferFile(int action, File srcFile, File targetDirectory, FileTree.FileTreeNode targetNode) { DnDUtils.debugPrintln((action == DnDConstants.ACTION_COPY ? "Copy" : "Move") + " file " + srcFile.getAbsolutePath() + " to " + targetDirectory.getAbsolutePath()); // Create a File entry for the target String name = srcFile.getName(); File newFile = new File(targetDirectory, name); if (newFile.exists()) { // Already exists - is it the same file? if (newFile.equals(srcFile)) { // Exactly the same file - ignore return; }// w w w . j a v a 2s.co m // File of this name exists in this directory if (copyOverExistingFiles == false) { int res = JOptionPane.showOptionDialog(tree, "A file called\n " + name + "\nalready exists in the directory\n " + targetDirectory.getAbsolutePath() + "\nOverwrite it?", "File Exists", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] { "Yes", "Yes to All", "No", "Cancel" }, "No"); switch (res) { case 1: // Yes to all copyOverExistingFiles = true; case 0: // Yes break; case 2: // No return; default: // Cancel throw new IllegalStateException("Cancelled"); } } } else { // New file - create it try { newFile.createNewFile(); } catch (IOException e) { JOptionPane.showMessageDialog(tree, "Failed to create new file\n " + newFile.getAbsolutePath(), "File Creation Failed", JOptionPane.ERROR_MESSAGE); return; } } // Copy the data and close file. BufferedInputStream is = null; BufferedOutputStream os = null; try { is = new BufferedInputStream(new FileInputStream(srcFile)); os = new BufferedOutputStream(new FileOutputStream(newFile)); int size = 4096; byte[] buffer = new byte[size]; int len; while ((len = is.read(buffer, 0, size)) > 0) { os.write(buffer, 0, len); } } catch (IOException e) { JOptionPane.showMessageDialog(tree, "Failed to copy file\n " + name + "\nto directory\n " + targetDirectory.getAbsolutePath(), "File Copy Failed", JOptionPane.ERROR_MESSAGE); return; } finally { try { if (is != null) { is.close(); } if (os != null) { os.close(); } } catch (IOException e) { } } // Remove the source if this is a move operation. if (action == DnDConstants.ACTION_MOVE && System.getProperty("DnDExamples.allowRemove") != null) { srcFile.delete(); } // Update the tree display if (targetNode != null) { tree.addNode(targetNode, name); } }
From source file:org.jets3t.apps.uploader.Uploader.java
/** * Initialise the application's File drop targets for drag and drop copying of local files * to S3./*from w ww.j ava2s. c o m*/ * * @param dropTargetComponents * the components files can be dropped on to transfer them to S3 */ private void initDropTarget(Component[] dropTargetComponents) { DropTargetListener dropTargetListener = new DropTargetListener() { private Border originalBorder = appContentPanel.getBorder(); private Border dragOverBorder = BorderFactory.createBevelBorder(1); private boolean checkValidDrag(DropTargetDragEvent dtde) { if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor) && (DnDConstants.ACTION_COPY == dtde.getDropAction() || DnDConstants.ACTION_MOVE == dtde.getDropAction())) { dtde.acceptDrag(dtde.getDropAction()); return true; } else { dtde.rejectDrag(); return false; } } public void dragEnter(DropTargetDragEvent dtde) { if (checkValidDrag(dtde)) { SwingUtilities.invokeLater(new Runnable() { public void run() { appContentPanel.setBorder(dragOverBorder); }; }); } } public void dragOver(DropTargetDragEvent dtde) { checkValidDrag(dtde); } public void dropActionChanged(DropTargetDragEvent dtde) { checkValidDrag(dtde); } public void dragExit(DropTargetEvent dte) { SwingUtilities.invokeLater(new Runnable() { public void run() { appContentPanel.setBorder(originalBorder); }; }); } public void drop(DropTargetDropEvent dtde) { if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor) && (DnDConstants.ACTION_COPY == dtde.getDropAction() || DnDConstants.ACTION_MOVE == dtde.getDropAction())) { dtde.acceptDrop(dtde.getDropAction()); SwingUtilities.invokeLater(new Runnable() { public void run() { appContentPanel.setBorder(originalBorder); }; }); try { final List fileList = (List) dtde.getTransferable() .getTransferData(DataFlavor.javaFileListFlavor); if (fileList != null && fileList.size() > 0) { if (checkProposedUploadFiles(fileList)) { wizardStepForward(); } } } catch (Exception e) { String errorMessage = "Unable to accept dropped item"; log.error(errorMessage, e); ErrorDialog.showDialog(ownerFrame, null, uploaderProperties.getProperties(), errorMessage, e); } } else { dtde.rejectDrop(); } } }; // Attach drop target listener to each target component. for (int i = 0; i < dropTargetComponents.length; i++) { new DropTarget(dropTargetComponents[i], DnDConstants.ACTION_COPY, dropTargetListener, true); } }
From source file:DragDropTreeExample.java
protected void transferDirectory(int action, File srcDir, File targetDirectory, FileTree.FileTreeNode targetNode) { DnDUtils.debugPrintln((action == DnDConstants.ACTION_COPY ? "Copy" : "Move") + " directory " + srcDir.getAbsolutePath() + " to " + targetDirectory.getAbsolutePath()); // Do not copy a directory into itself or // a subdirectory of itself. File parentDir = targetDirectory; while (parentDir != null) { if (parentDir.equals(srcDir)) { DnDUtils.debugPrintln("-- SUPPRESSED"); return; }//from w ww . java2 s .c o m parentDir = parentDir.getParentFile(); } // Copy the directory itself, then its contents // Create a File entry for the target String name = srcDir.getName(); File newDir = new File(targetDirectory, name); if (newDir.exists()) { // Already exists - is it the same directory? if (newDir.equals(srcDir)) { // Exactly the same file - ignore return; } } else { // Directory does not exist - create it if (newDir.mkdir() == false) { // Failed to create - abandon this directory JOptionPane.showMessageDialog(tree, "Failed to create target directory\n " + newDir.getAbsolutePath(), "Directory creation Failed", JOptionPane.ERROR_MESSAGE); return; } } // Add a node for the new directory if (targetNode != null) { targetNode = tree.addNode(targetNode, name); } // Now copy the directory content. File[] files = srcDir.listFiles(); for (int i = 0; i < files.length; i++) { File f = files[i]; if (f.isFile()) { transferFile(action, f, newDir, targetNode); } else if (f.isDirectory()) { transferDirectory(action, f, newDir, targetNode); } } // Remove the source directory after moving if (action == DnDConstants.ACTION_MOVE && System.getProperty("DnDExamples.allowRemove") != null) { srcDir.delete(); } }
From source file:org.jets3t.apps.cockpit.Cockpit.java
/** * Initialise the application's File drop targets for drag and drop copying of local files * to S3./* w ww . j a v a 2 s. com*/ * * @param dropTargetComponents * the components files can be dropped on to transfer them to S3 */ private void initDropTarget(JComponent[] dropTargetComponents) { DropTargetListener dropTargetListener = new DropTargetListener() { private boolean checkValidDrag(DropTargetDragEvent dtde) { if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor) && (DnDConstants.ACTION_COPY == dtde.getDropAction() || DnDConstants.ACTION_MOVE == dtde.getDropAction())) { dtde.acceptDrag(dtde.getDropAction()); return true; } else { dtde.rejectDrag(); return false; } } public void dragEnter(DropTargetDragEvent dtde) { if (checkValidDrag(dtde)) { SwingUtilities.invokeLater(new Runnable() { public void run() { objectsTable.requestFocusInWindow(); }; }); } } public void dragOver(DropTargetDragEvent dtde) { checkValidDrag(dtde); } public void dropActionChanged(DropTargetDragEvent dtde) { if (checkValidDrag(dtde)) { SwingUtilities.invokeLater(new Runnable() { public void run() { objectsTable.requestFocusInWindow(); }; }); } else { SwingUtilities.invokeLater(new Runnable() { public void run() { ownerFrame.requestFocusInWindow(); }; }); } } public void dragExit(DropTargetEvent dte) { SwingUtilities.invokeLater(new Runnable() { public void run() { ownerFrame.requestFocusInWindow(); }; }); } public void drop(DropTargetDropEvent dtde) { if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor) && (DnDConstants.ACTION_COPY == dtde.getDropAction() || DnDConstants.ACTION_MOVE == dtde.getDropAction())) { dtde.acceptDrop(dtde.getDropAction()); try { final List fileList = (List) dtde.getTransferable() .getTransferData(DataFlavor.javaFileListFlavor); if (fileList != null && fileList.size() > 0) { uploadFiles((File[]) fileList.toArray(new File[fileList.size()])); } } catch (Exception e) { String message = "Unable to start accept dropped items"; log.error(message, e); ErrorDialog.showDialog(ownerFrame, null, message, e); } } else { dtde.rejectDrop(); } } }; // Attach drop target listener to each target component. for (int i = 0; i < dropTargetComponents.length; i++) { new DropTarget(dropTargetComponents[i], DnDConstants.ACTION_COPY, dropTargetListener, true); } }
From source file:org.jets3t.apps.cockpitlite.CockpitLite.java
/** * Initialise the application's File drop targets for drag and drop copying of local files * to S3.//from w w w. j av a2s . c om * * @param dropTargetComponents * the components files can be dropped on to transfer them to S3 */ private void initDropTarget(JComponent[] dropTargetComponents) { DropTargetListener dropTargetListener = new DropTargetListener() { private boolean checkValidDrag(DropTargetDragEvent dtde) { if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor) && (DnDConstants.ACTION_COPY == dtde.getDropAction() || DnDConstants.ACTION_MOVE == dtde.getDropAction())) { dtde.acceptDrag(dtde.getDropAction()); return true; } else { dtde.rejectDrag(); return false; } } public void dragEnter(DropTargetDragEvent dtde) { if (checkValidDrag(dtde)) { SwingUtilities.invokeLater(new Runnable() { public void run() { objectsTable.requestFocusInWindow(); }; }); } } public void dragOver(DropTargetDragEvent dtde) { checkValidDrag(dtde); } public void dropActionChanged(DropTargetDragEvent dtde) { if (checkValidDrag(dtde)) { SwingUtilities.invokeLater(new Runnable() { public void run() { objectsTable.requestFocusInWindow(); }; }); } else { SwingUtilities.invokeLater(new Runnable() { public void run() { ownerFrame.requestFocusInWindow(); }; }); } } public void dragExit(DropTargetEvent dte) { SwingUtilities.invokeLater(new Runnable() { public void run() { ownerFrame.requestFocusInWindow(); }; }); } public void drop(DropTargetDropEvent dtde) { if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor) && (DnDConstants.ACTION_COPY == dtde.getDropAction() || DnDConstants.ACTION_MOVE == dtde.getDropAction())) { dtde.acceptDrop(dtde.getDropAction()); try { final List fileList = (List) dtde.getTransferable() .getTransferData(DataFlavor.javaFileListFlavor); if (fileList != null && fileList.size() > 0) { new Thread() { @Override public void run() { prepareForFilesUpload((File[]) fileList.toArray(new File[fileList.size()])); } }.start(); } } catch (Exception e) { String message = "Unable to start accept dropped item(s)"; log.error(message, e); ErrorDialog.showDialog(ownerFrame, null, cockpitLiteProperties.getProperties(), message, e); } } else { dtde.rejectDrop(); } } }; // Attach drop target listener to each target component. for (int i = 0; i < dropTargetComponents.length; i++) { new DropTarget(dropTargetComponents[i], DnDConstants.ACTION_COPY, dropTargetListener, true); } }