List of usage examples for java.awt.dnd DropTargetDragEvent acceptDrag
public void acceptDrag(int dragOperation)
From source file:com.mirth.connect.client.ui.editors.transformer.TransformerPane.java
public void dragEnter(DropTargetDragEvent dtde) { try {// w w w . jav a 2s.co m Transferable tr = dtde.getTransferable(); if (tr.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { dtde.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE); List fileList = (List) tr.getTransferData(DataFlavor.javaFileListFlavor); Iterator iterator = fileList.iterator(); if (iterator.hasNext() && fileList.size() == 1) { String fileName = ((File) iterator.next()).getName(); if (!fileName.substring(fileName.lastIndexOf(".")).equalsIgnoreCase(".xml")) { dtde.rejectDrag(); } } else { dtde.rejectDrag(); } } else if (tr.isDataFlavorSupported(TreeTransferable.MAPPER_DATA_FLAVOR) || tr.isDataFlavorSupported(TreeTransferable.MESSAGE_BUILDER_DATA_FLAVOR)) { dtde.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE); } else { dtde.rejectDrag(); } } catch (Exception e) { dtde.rejectDrag(); } }
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 ww w .ja v a2s.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:FileTreeDropTarget.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)); Point location = dtde.getLocation(); boolean acceptableDropLocation = isAcceptableDropLocation(location); // 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();/* ww w. ja v a 2 s . c o m*/ } else if (!tree.isEditable()) { // Can't drag to a read-only FileTree DnDUtils.debugPrintln("Drop target rejecting drag"); dtde.rejectDrag(); } else if (!acceptableDropLocation) { // Can only drag to writable directory DnDUtils.debugPrintln("Drop target rejecting drag"); dtde.rejectDrag(); } 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:DragDropTreeExample.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)); Point location = dtde.getLocation(); boolean acceptableDropLocation = isAcceptableDropLocation(location); // 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();// w w w . j av a 2 s. co m } else if (!tree.isEditable()) { // Can't drag to a read-only FileTree DnDUtils.debugPrintln("Drop target rejecting drag"); dtde.rejectDrag(); } else if (!acceptableDropLocation) { // Can only drag to writable directory DnDUtils.debugPrintln("Drop target rejecting drag"); dtde.rejectDrag(); } 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:org.jets3t.apps.cockpit.Cockpit.java
/** * Initialise the application's File drop targets for drag and drop copying of local files * to S3./* w w w .j ava2 s. 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) { 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:de.tor.tribes.ui.windows.TribeTribeAttackFrame.java
@Override public void dragEnter(DropTargetDragEvent dtde) { if (dtde.isDataFlavorSupported(VillageTransferable.villageDataFlavor) || dtde.isDataFlavorSupported(DataFlavor.stringFlavor)) { if (dtde.getDropTargetContext().getComponent() == jSourcesTable || dtde.getDropTargetContext().getComponent() == jVictimTable) { dtde.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE); } else {/* w w w . j a v a2s.c o m*/ dtde.rejectDrag(); } } else { dtde.rejectDrag(); } }
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 a v a2 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.dnd.RepositoryDropTargetAdapter.java
@Override public void dragOver(DropTargetDragEvent dtde) { if (canDrop(dtde)) { dtde.acceptDrag(dtde.getDropAction()); } else {//from w w w.j av a2 s . c o m dtde.acceptDrag(DnDConstants.ACTION_NONE); dtde.rejectDrag(); } }
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 av a2 s .c o m 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:tvbrowser.ui.mainframe.MainFrame.java
@Override public void dragEnter(DropTargetDragEvent dtde) { File[] files = getDragDropPlugins(dtde.getCurrentDataFlavors(), dtde.getTransferable()); if (files.length > 0) { dtde.acceptDrag(dtde.getDropAction()); } else {/*from www . ja v a 2 s .c om*/ dtde.rejectDrag(); } }