List of usage examples for java.awt.dnd DropTargetDropEvent rejectDrop
public void rejectDrop()
From source file:com.mirth.connect.client.ui.components.MirthTree.java
public void drop(DropTargetDropEvent dtde) { if (parent.currentContentPage != parent.channelEditPanel.transformerPane) { return;//from w w w . j a va 2 s .c o m } try { TreeNode selectedNode = (TreeNode) this.getLastSelectedPathComponent(); if (selectedNode == null) { return; } dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE); Transferable tr = dtde.getTransferable(); if (supportedDropFlavor == TreeTransferable.MAPPER_DATA_FLAVOR) { Object transferData = tr.getTransferData(TreeTransferable.MAPPER_DATA_FLAVOR); MapperDropData data = (MapperDropData) transferData; parent.channelEditPanel.transformerPane.addNewStep( constructMessageBuilderStepName(data.getNode(), selectedNode), constructPath(selectedNode, prefix, suffix).toString(), data.getMapping(), TransformerPane.MESSAGE_BUILDER); } else if (supportedDropFlavor == TreeTransferable.MESSAGE_BUILDER_DATA_FLAVOR) { Object transferData = tr.getTransferData(TreeTransferable.MESSAGE_BUILDER_DATA_FLAVOR); MessageBuilderDropData data = (MessageBuilderDropData) transferData; parent.channelEditPanel.transformerPane.addNewStep( constructMessageBuilderStepName(selectedNode, data.getNode()), data.getMessageSegment(), constructPath(selectedNode, prefix, suffix).toString(), TransformerPane.MESSAGE_BUILDER); } else { dtde.rejectDrop(); } } catch (Exception e) { dtde.rejectDrop(); } }
From source file:DropTest2.java
public void drop(DropTargetDropEvent dtde) { try {/*from ww w .j a va 2 s . c o m*/ // Ok, get the dropped object and try to figure out what it is Transferable tr = dtde.getTransferable(); DataFlavor[] flavors = tr.getTransferDataFlavors(); for (int i = 0; i < flavors.length; i++) { System.out.println("Possible flavor: " + flavors[i].getMimeType()); // Check for file lists specifically if (flavors[i].isFlavorJavaFileListType()) { // Great! Accept copy drops... dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE); ta.setText("Successful file list drop.\n\n"); // And add the list of file names to our text area java.util.List list = (java.util.List) tr.getTransferData(flavors[i]); for (int j = 0; j < list.size(); j++) { ta.append(list.get(j) + "\n"); } // If we made it this far, everything worked. dtde.dropComplete(true); return; } // Ok, is it another Java object? else if (flavors[i].isFlavorSerializedObjectType()) { dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE); ta.setText("Successful text drop.\n\n"); Object o = tr.getTransferData(flavors[i]); ta.append("Object: " + o); dtde.dropComplete(true); return; } // How about an input stream? else if (flavors[i].isRepresentationClassInputStream()) { dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE); ta.setText("Successful text drop.\n\n"); ta.read(new InputStreamReader((InputStream) tr.getTransferData(flavors[i])), "from system clipboard"); dtde.dropComplete(true); return; } } // Hmm, the user must not have dropped a file list System.out.println("Drop failed: " + dtde); dtde.rejectDrop(); } catch (Exception e) { e.printStackTrace(); dtde.rejectDrop(); } }
From source file:com.mirth.connect.client.ui.editors.filter.FilterPane.java
public void drop(DropTargetDropEvent dtde) { try {/*from ww w . ja v a 2s. co m*/ dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE); Transferable tr = dtde.getTransferable(); if (tr.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { List<File> fileList = (List<File>) tr.getTransferData(DataFlavor.javaFileListFlavor); Iterator<File> iterator = fileList.iterator(); if (fileList.size() == 1) { File file = (File) iterator.next(); importFilter(parent.readFileToString(file)); } } else if (tr.isDataFlavorSupported(TreeTransferable.RULE_DATA_FLAVOR)) { Object transferData = tr.getTransferData(TreeTransferable.RULE_DATA_FLAVOR); if (transferData instanceof RuleDropData) { RuleDropData data = (RuleDropData) transferData; addNewRule(MirthTree.constructNodeDescription(data.getNode()), data.getMapping()); } } } catch (Exception e) { dtde.rejectDrop(); } }
From source file:com.mirth.connect.client.ui.editors.transformer.TransformerPane.java
public void drop(DropTargetDropEvent dtde) { try {/*from w w w.jav a 2 s . com*/ Transferable tr = dtde.getTransferable(); if (tr.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE); List<File> fileList = (List<File>) tr.getTransferData(DataFlavor.javaFileListFlavor); Iterator<File> iterator = fileList.iterator(); if (fileList.size() == 1) { File file = (File) iterator.next(); importTransformer(parent.readFileToString(file)); } } else if (tr.isDataFlavorSupported(TreeTransferable.MAPPER_DATA_FLAVOR) || tr.isDataFlavorSupported(TreeTransferable.MESSAGE_BUILDER_DATA_FLAVOR)) { dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE); Object mapperTransferData = tr.getTransferData(TreeTransferable.MAPPER_DATA_FLAVOR); Object messageBuilderTransferData = tr .getTransferData(TreeTransferable.MESSAGE_BUILDER_DATA_FLAVOR); if (mapperTransferData != null && !parent.isAcceleratorKeyPressed()) { Object transferData = tr.getTransferData(TreeTransferable.MAPPER_DATA_FLAVOR); MapperDropData data = (MapperDropData) transferData; addNewStep(data.getVariable(), data.getVariable(), data.getMapping(), MAPPER); } else if (mapperTransferData != null && parent.isAcceleratorKeyPressed()) { Object transferData = tr.getTransferData(TreeTransferable.MAPPER_DATA_FLAVOR); MapperDropData data2 = (MapperDropData) transferData; MessageBuilderDropData data = new MessageBuilderDropData(data2.getNode(), MirthTree.constructPath(data2.getNode().getParent(), "msg", "").toString(), ""); addNewStep(MirthTree.constructMessageBuilderStepName(null, data.getNode()), data.getMessageSegment(), data.getMapping(), MESSAGE_BUILDER); } else if (messageBuilderTransferData != null) { Object transferData = tr.getTransferData(TreeTransferable.MESSAGE_BUILDER_DATA_FLAVOR); MessageBuilderDropData data = (MessageBuilderDropData) transferData; addNewStep(MirthTree.constructMessageBuilderStepName(null, data.getNode()), data.getMessageSegment(), data.getMapping(), MESSAGE_BUILDER); } } } catch (Exception e) { dtde.rejectDrop(); } }
From source file:com.declarativa.interprolog.gui.ListenerWindow.java
void handlePrologInputDnD(DropTargetDropEvent dtde) { //System.out.println("drop:"+dtde); try {/*ww w .j av a 2s. c o m*/ Transferable transferable = dtde.getTransferable(); /* DataFlavor[] flavors = transferable.getTransferDataFlavors(); for (int f=0;f<flavors.length;f++) System.out.println("Flavor:"+flavors[f]);*/ int action = dtde.getDropAction(); if (transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { if (engine.isIdle()) { dtde.acceptDrop(action); final java.util.List files = (java.util.List) transferable .getTransferData(DataFlavor.javaFileListFlavor); dtde.getDropTargetContext().dropComplete(true); boolean allPs = true; for (int f = 0; f < files.size(); f++) { String filename = ((File) files.get(f)).getName(); int dot = filename.lastIndexOf('.'); if (!filename.endsWith(".P")) { allPs = false; break; } } if (!allPs) { errorMessage("All dragged files must be Prolog source files (with a .P extension)"); } else { prologOutput.append("\nReconsulting " + ((files.size() > 1 ? files.size() + " files...\n" : files.size() + " file...\n"))); Runnable r = new Runnable() { public void run() { boolean crashed = false; Toolkit.getDefaultToolkit().sync(); for (int f = 0; f < files.size() && !crashed; f++) { File file = (File) files.get(f); if (!processDraggedFile(file)) { crashed = true; } } if (crashed) { prologOutput.append("...terminated with errors.\n"); } else { prologOutput.append("...done.\n"); } } }; SwingUtilities.invokeLater(r); } } else { dtde.rejectDrop(); errorMessage("You can not consult files while Prolog is working"); } } else { dtde.rejectDrop(); } } catch (Exception e) { throw new IPException("Problem dropping:" + e); } }
From source file:de.tor.tribes.ui.windows.TribeTribeAttackFrame.java
@Override public void drop(DropTargetDropEvent dtde) { Transferable t = dtde.getTransferable(); List<Village> villages = new LinkedList<Village>(); if (dtde.getDropTargetContext().getComponent() == jSourcesTable || dtde.getDropTargetContext().getComponent() == jVictimTable) { if (dtde.isDataFlavorSupported(VillageTransferable.villageDataFlavor)) { //village dnd dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE); try { villages = (List<Village>) t.getTransferData(VillageTransferable.villageDataFlavor); } catch (Exception ex) { }//ww w . j av a2 s . c om } else if (dtde.isDataFlavorSupported(DataFlavor.stringFlavor)) { //string dnd try { villages = PluginManager.getSingleton() .executeVillageParser((String) t.getTransferData(DataFlavor.stringFlavor)); } catch (Exception e) { } } else { dtde.rejectDrop(); return; } } else { dtde.rejectDrop(); return; } MapPanel.getSingleton().setCurrentCursor(MapPanel.getSingleton().getCurrentCursor()); if (!villages.isEmpty()) { if (jideTabbedPane1.getSelectedIndex() == 0) { fireAddSourcesEvent(villages); } else if (jideTabbedPane1.getSelectedIndex() == 1) { fireAddTargetsEvent(villages); } } }
From source file:org.kuali.test.ui.dnd.RepositoryDropTargetAdapter.java
@Override public void drop(DropTargetDropEvent dtde) { boolean success = false; try {/*from ww w . j a v a2 s. co m*/ if (canDrop(dtde)) { Transferable t = dtde.getTransferable(); Object data = t.getTransferData(t.getTransferDataFlavors()[0]); DefaultMutableTreeNode dropNode = getNodeAtPoint(dtde.getLocation()); if ((dropNode != null) && (data != null) && (data instanceof RepositoryTransferData)) { repositoryTree.handleDataDrop(t.getTransferDataFlavors()[0], (RepositoryTransferData) data, dropNode); success = true; dtde.dropComplete(true); } } } catch (Exception e) { LOG.error(e.toString(), e); } if (!success) { dtde.rejectDrop(); } }
From source file:org.pentaho.reporting.designer.core.util.dnd.GenericDNDHandler.java
/** * Called when the drag operation has terminated with a drop on the operable part of the drop site for the * <code>DropTarget</code> registered with this listener. * <p/>// w w w . j a va 2 s. c om * This method is responsible for undertaking the transfer of the data associated with the gesture. The * <code>DropTargetDropEvent</code> provides a means to obtain a <code>Transferable</code> object that represents the * data object(s) to be transfered.<P> From this method, the <code>DropTargetListener</code> shall accept or reject * the drop via the acceptDrop(int dropAction) or rejectDrop() methods of the <code>DropTargetDropEvent</code> * parameter. * <p/> * Subsequent to acceptDrop(), but not before, <code>DropTargetDropEvent</code>'s getTransferable() method may be * invoked, and data transfer may be performed via the returned <code>Transferable</code>'s getTransferData() method. * <p/> * At the completion of a drop, an implementation of this method is required to signal the success/failure of the drop * by passing an appropriate <code>boolean</code> to the <code>DropTargetDropEvent</code>'s dropComplete(boolean * success) method. * <p/> * Note: The data transfer should be completed before the call to the <code>DropTargetDropEvent</code>'s * dropComplete(boolean success) method. After that, a call to the getTransferData() method of the * <code>Transferable</code> returned by <code>DropTargetDropEvent.getTransferable()</code> is guaranteed to succeed * only if the data transfer is local; that is, only if <code>DropTargetDropEvent.isLocalTransfer()</code> returns * <code>true</code>. Otherwise, the behavior of the call is implementation-dependent. * <p/> * * @param dtde the <code>DropTargetDropEvent</code> */ public void drop(final DropTargetDropEvent dtde) { dtde.rejectDrop(); transferData = null; position = null; flavor = null; }
From source file:org.rdv.datapanel.AbstractDataPanel.java
@SuppressWarnings("unchecked") public void drop(DropTargetDropEvent e) { try {/*from w ww .j av a2 s .c om*/ int dropAction = e.getDropAction(); if (dropAction == DnDConstants.ACTION_LINK) { DataFlavor channelListDataFlavor = new ChannelListDataFlavor(); Transferable tr = e.getTransferable(); if (e.isDataFlavorSupported(channelListDataFlavor)) { e.acceptDrop(DnDConstants.ACTION_LINK); e.dropComplete(true); final List<String> channels = (List) tr.getTransferData(channelListDataFlavor); new Thread() { public void run() { for (int i = 0; i < channels.size(); i++) { String channel = channels.get(i); boolean status; if (supportsMultipleChannels()) { status = addChannel(channel); } else { status = setChannel(channel); } if (!status) { // TODO display an error in the UI } } } }.start(); } else { e.rejectDrop(); } } } catch (IOException ioe) { ioe.printStackTrace(); } catch (UnsupportedFlavorException ufe) { ufe.printStackTrace(); } }
From source file:org.rdv.datapanel.DigitalTabularDataPanel.java
/** * an overridden method from/* w ww .j a va2 s . com*/ * * @see org.rdv.datapanel.AbstractDataPanel for the * @see DropTargetListener interface */ @SuppressWarnings("unchecked") public void drop(DropTargetDropEvent e) { try { int dropAction = e.getDropAction(); if (dropAction == DnDConstants.ACTION_LINK) { DataFlavor channelListDataFlavor = new ChannelListDataFlavor(); Transferable tr = e.getTransferable(); if (e.isDataFlavorSupported(channelListDataFlavor)) { e.acceptDrop(DnDConstants.ACTION_LINK); e.dropComplete(true); // calculate which table the x coordinate of the mouse // corresponds to double clickX = e.getLocation().getX(); // get the mouse x // coordinate int compWidth = dataComponent.getWidth(); // gets the // width of this // component final int tableNum = (int) (clickX * columnGroupCount / compWidth); final List<String> channels = (List) tr.getTransferData(channelListDataFlavor); new Thread() { public void run() { for (int i = 0; i < channels.size(); i++) { String channel = channels.get(i); boolean status; if (supportsMultipleChannels()) { status = addChannel(channel, tableNum); } else { status = setChannel(channel); } if (!status) { // TODO display an error in the UI } } } }.start(); } else { e.rejectDrop(); } } } catch (IOException ioe) { ioe.printStackTrace(); } catch (UnsupportedFlavorException ufe) { ufe.printStackTrace(); } }