List of usage examples for java.awt.dnd DnDConstants ACTION_COPY
int ACTION_COPY
To view the source code for java.awt.dnd DnDConstants ACTION_COPY.
Click Source Link
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 ww . j a v a 2 s.c o m*/ * * @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); } }
From source file:org.kuali.test.ui.components.repositorytree.RepositoryTree.java
/** * * @param mainframe/*from w ww .jav a2 s .co m*/ */ public RepositoryTree(TestCreator mainframe) { super(mainframe); popupMenu = new RepositoryPopupMenu(mainframe); init(); new RepositoryDropTargetAdapter(this); new DragSource().createDefaultDragGestureRecognizer(this, DnDConstants.ACTION_COPY, this); }
From source file:org.kuali.test.ui.dnd.RepositoryDropTargetAdapter.java
/** * * @param repositoryTree */ public RepositoryDropTargetAdapter(RepositoryTree repositoryTree) { this(repositoryTree, DnDConstants.ACTION_COPY); }
From source file:org.kuali.test.ui.dnd.RepositoryDropTargetAdapter.java
private boolean isTestLinkTransfer(Transferable t, int ops, DataFlavor dataFlavor) { boolean retval = ((t != null) && (ops == DnDConstants.ACTION_COPY) && dataFlavor.equals(DndHelper.getTestDataFlavor())); if (LOG.isDebugEnabled()) { LOG.debug("isTestLinkTransfer: " + retval); }/*from w ww. java2s.c o m*/ return retval; }
From source file:org.kuali.test.ui.dnd.RepositoryDropTargetAdapter.java
private boolean isTestOrderTransfer(Transferable t, int ops, DataFlavor dataFlavor) { boolean retval = ((t != null) && (ops == DnDConstants.ACTION_COPY) && dataFlavor.equals(DndHelper.getTestOrderDataFlavor())); if (LOG.isDebugEnabled()) { LOG.debug("isTestOrderTransfer: " + retval); }//from w ww .j a v a2s . co m return retval; }
From source file:org.openmicroscopy.shoola.agents.treeviewer.browser.BrowserUI.java
/** * Reacts to the D&D properties.//from w w w .ja va 2s. com * @see PropertyChangeListener#propertyChange(PropertyChangeEvent) */ public void propertyChange(PropertyChangeEvent evt) { String name = evt.getPropertyName(); if (DnDTree.DRAGGED_PROPERTY.equals(name)) { ObjectToTransfer transfer = (ObjectToTransfer) evt.getNewValue(); int action = TreeViewer.CUT_AND_PASTE; if (transfer.getDropAction() == DnDConstants.ACTION_COPY) action = TreeViewer.COPY_AND_PASTE; //check the node model.transfer(transfer.getTarget(), transfer.getNodes(), action); } }
From source file:org.pentaho.reporting.designer.core.util.dnd.GenericDNDHandler.java
/** * Called when a drag operation is ongoing, while the mouse pointer is still over the operable part of the drop site * for the <code>DropTarget</code> registered with this listener. * * @param dtde the <code>DropTargetDragEvent</code> *///from w ww. j ava2 s. c om public void dragOver(final DropTargetDragEvent dtde) { final Transferable transferable = dtde.getTransferable(); for (int i = 0; i < acceptedFlavors.length; i++) { final DataFlavor acceptedFlavor = acceptedFlavors[i]; if (transferable.isDataFlavorSupported(acceptedFlavor)) { // a transfer from the palette. try { transferData = transferable.getTransferData(acceptedFlavor); position = dtde.getLocation(); flavor = acceptedFlavor; final int result = updateDragOver(dtde); if (result > 0) { dtde.acceptDrag(DnDConstants.ACTION_COPY); } else { transferData = null; position = null; flavor = null; dtde.rejectDrag(); } break; } catch (Exception e) { if (logger.isDebugEnabled()) { logger.debug("ReportPanel.dragOver ", e); // NON-NLS } transferData = null; position = null; flavor = null; dtde.rejectDrag(); } } } }
From source file:org.pentaho.reporting.designer.core.util.dnd.GenericDNDHandler.java
protected int updateDragOver(final DropTargetDragEvent event) { return DnDConstants.ACTION_COPY; }
From source file:se.trixon.pacoma.ui.MainFrame.java
private void initListeners() { mActionManager.addAppListener(new ActionManager.AppListener() { @Override//from w w w . ja va 2 s. co m public void onCancel(ActionEvent actionEvent) { } @Override public void onMenu(ActionEvent actionEvent) { if (actionEvent.getSource() != menuButton) { menuButtonMousePressed(null); } } @Override public void onOptions(ActionEvent actionEvent) { showOptions(); } @Override public void onQuit(ActionEvent actionEvent) { quit(); } @Override public void onRedo(ActionEvent actionEvent) { mCollage.nextHistory(); updateToolButtons(); } @Override public void onStart(ActionEvent actionEvent) { } @Override public void onUndo(ActionEvent actionEvent) { mCollage.prevHistory(); updateToolButtons(); } }); mActionManager.addProfileListener(new ActionManager.ProfileListener() { @Override public void onAdd(ActionEvent actionEvent) { addImages(); } @Override public void onClear(ActionEvent actionEvent) { mCollage.clearFiles(); } @Override public void onClose(ActionEvent actionEvent) { setTitle("pacoma"); mActionManager.setEnabledDocumentActions(false); canvasPanel.close(); } @Override public void onEdit(ActionEvent actionEvent) { editCollage(mCollage); } @Override public void onRegenerate(ActionEvent actionEvent) { //TODO } @Override public void onNew(ActionEvent actionEvent) { editCollage(null); if (mCollage != null && mCollage.getName() != null) { setTitle(mCollage); canvasPanel.open(mCollage); mActionManager.getAction(ActionManager.CLEAR).setEnabled(false); mActionManager.getAction(ActionManager.REGENERATE).setEnabled(false); } } @Override public void onOpen(ActionEvent actionEvent) { initFileDialog(mCollageFileNameExtensionFilter); if (SimpleDialog.openFile()) { try { open(SimpleDialog.getPath()); } catch (IOException ex) { Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex); } } } @Override public void onSave(ActionEvent actionEvent) { save(); } @Override public void onSaveAs(ActionEvent actionEvent) { saveAs(); } }); mCollagePropertyChangeListener = () -> { if (mCollage != null) { setTitle(mCollage); mActionManager.getAction(ActionManager.SAVE).setEnabled(true); mActionManager.getAction(ActionManager.CLEAR).setEnabled(mCollage.hasImages()); mActionManager.getAction(ActionManager.REGENERATE).setEnabled(mCollage.hasImages()); } }; mDropTarget = new DropTarget() { @Override public synchronized void drop(DropTargetDropEvent evt) { try { evt.acceptDrop(DnDConstants.ACTION_COPY); LinkedList<File> droppedFiles = new LinkedList<>( (List<File>) evt.getTransferable().getTransferData(DataFlavor.javaFileListFlavor)); List<File> invalidFiles = new LinkedList<>(); droppedFiles.forEach((droppedFile) -> { if (droppedFile.isFile() && FilenameUtils.isExtension( droppedFile.getName().toLowerCase(Locale.getDefault()), Collage.FILE_EXT)) { //all ok } else { invalidFiles.add(droppedFile); } }); invalidFiles.forEach((invalidFile) -> { droppedFiles.remove(invalidFile); }); switch (droppedFiles.size()) { case 0: Message.error(MainFrame.this, Dict.Dialog.TITLE_IO_ERROR.toString(), "Not a valid collage file."); break; case 1: open(droppedFiles.getFirst()); break; default: Message.error(MainFrame.this, Dict.Dialog.TITLE_IO_ERROR.toString(), "Too many files dropped."); break; } } catch (UnsupportedFlavorException | IOException ex) { System.err.println(ex.getMessage()); } } }; canvasPanel.setDropTarget(mDropTarget); }
From source file:se.trixon.pacoma.ui.PagePanel.java
private void init() { mDropTarget = new DropTarget() { @Override// w w w.ja v a2s. c o m public synchronized void drop(DropTargetDropEvent evt) { try { evt.acceptDrop(DnDConstants.ACTION_COPY); LinkedList<File> droppedFiles = new LinkedList<>( (List<File>) evt.getTransferable().getTransferData(DataFlavor.javaFileListFlavor)); List<File> invalidFiles = new LinkedList<>(); droppedFiles.forEach((droppedFile) -> { if (droppedFile.isFile() && FilenameUtils.isExtension(droppedFile.getName().toLowerCase(Locale.getDefault()), new String[] { "jpg", "jpeg", "png" })) { //all ok } else { invalidFiles.add(droppedFile); } }); invalidFiles.forEach((invalidFile) -> { droppedFiles.remove(invalidFile); System.out.println("remomve invalid file: " + invalidFile.getAbsolutePath()); }); droppedFiles.forEach((droppedFile) -> { System.out.println("accept: " + droppedFile.getAbsolutePath()); }); mCollage.addFiles(droppedFiles); } catch (UnsupportedFlavorException | IOException ex) { System.err.println(ex.getMessage()); } } }; setDropTarget(mDropTarget); }