List of usage examples for java.awt.dnd DropTargetDropEvent dropComplete
public void dropComplete(boolean success)
From source file:org.pmedv.blackboard.EditorUtils.java
/** * Configures the drop target for new symbols to be dragged from the symbol * table to the editor./*from w ww .j ava2s .c o m*/ */ public static DropTarget configureDropTarget(final BoardEditor editor, final int raster) { DropTarget dt = new DropTarget(editor, new DropTargetAdapter() { final DataFlavor flavors[] = { DataFlavor.imageFlavor }; @Override public void drop(DropTargetDropEvent e) { int xloc = BoardUtil.snap((int) e.getLocation().getX(), raster); int yloc = BoardUtil.snap((int) e.getLocation().getY(), raster); SymbolBean symbol = null; try { symbol = (SymbolBean) e.getTransferable().getTransferData(flavors[0]); } catch (Exception e1) { e1.printStackTrace(); } Symbol sym = new Symbol(symbol); sym.setXLoc(xloc); sym.setYLoc(yloc); for (Item subItem : sym.getItems()) { if (subItem instanceof Line) { Line line = (Line) subItem; line.setStart(new Point((int) line.getStart().getX() + xloc, (int) line.getStart().getY() + yloc)); line.setEnd( new Point((int) line.getEnd().getX() + +xloc, (int) line.getEnd().getY() + yloc)); line.setOldstart(new Point(line.getStart())); line.setOldEnd(new Point(line.getEnd())); } else { subItem.setXLoc(subItem.getXLoc() + xloc); subItem.setYLoc(subItem.getYLoc() + yloc); subItem.setOldXLoc(subItem.getXLoc()); subItem.setOldYLoc(subItem.getYLoc()); subItem.setOldWidth(subItem.getWidth()); subItem.setOldHeight(subItem.getHeight()); } } editor.getModel().getCurrentLayer().getItems().add(sym); sym.setLayer(editor.getModel().getCurrentLayer().getIndex()); editor.refresh(); e.dropComplete(true); e.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE); // Switch to select mode after drop ctx.getBean(SetSelectModeCommand.class).execute(null); if (!editor.getUndoManager().addEdit(new AddItemEdit(sym))) { log.info("Could not add edit " + this.getClass()); } editor.setFileState(FileState.DIRTY); ctx.getBean(RedoCommand.class).setEnabled(editor.getUndoManager().canRedo()); ctx.getBean(UndoCommand.class).setEnabled(editor.getUndoManager().canUndo()); } }); return dt; }
From source file:org.rdv.datapanel.AbstractDataPanel.java
@SuppressWarnings("unchecked") public void drop(DropTargetDropEvent e) { try {/*ww w . j a va2 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//from ww w. ja va2 s . c om * * @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(); } }
From source file:tk.tomby.tedit.core.Workspace.java
/** * Creates a new WorkSpace object./*from ww w.ja v a 2 s.c o m*/ */ public Workspace() { super(); setLayout(new BorderLayout()); setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); MessageManager.addMessageListener(MessageManager.BUFFER_GROUP_NAME, new IMessageListener<BufferMessage>() { public void receiveMessage(BufferMessage message) { Workspace.this.receiveMessage(message); } }); MessageManager.addMessageListener(MessageManager.PREFERENCE_GROUP_NAME, new IMessageListener<PreferenceMessage>() { public void receiveMessage(PreferenceMessage message) { Workspace.this.receiveMessage(message); } }); bufferPane = new JTabbedPane(); bufferPane.setMinimumSize(new Dimension(600, 400)); bufferPane.setPreferredSize(new Dimension(800, 600)); bufferPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT); bottomPort = createDockingPort(0, 80); rightPort = createDockingPort(80, 0); leftPort = createDockingPort(80, 0); splitPaneRight = createSplitPane(JSplitPane.HORIZONTAL_SPLIT, bufferPane, rightPort); splitPaneLeft = createSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftPort, splitPaneRight); splitPaneBottom = createSplitPane(JSplitPane.VERTICAL_SPLIT, splitPaneLeft, bottomPort); bufferPane.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { MessageManager .sendMessage(new WorkspaceMessage(evt.getSource(), bufferPane.getSelectedComponent())); } }); bufferPane.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { if (evt.getClickCount() == 2) { splitPaneLeft.setDividerLocation(0.0d); splitPaneBottom.setDividerLocation(1.0d); splitPaneRight.setDividerLocation(1.0d); } } }); DropTarget dropTarget = new DropTarget(bufferPane, new DropTargetAdapter() { public void drop(DropTargetDropEvent dtde) { if (log.isDebugEnabled()) { log.debug("drop start"); } try { if (log.isDebugEnabled()) { log.debug(dtde.getSource()); } Transferable tr = dtde.getTransferable(); DataFlavor[] flavors = tr.getTransferDataFlavors(); for (int i = 0; i < flavors.length; i++) { DataFlavor flavor = flavors[i]; if (log.isDebugEnabled()) { log.debug("mime-type:" + flavor.getMimeType()); } if (flavor.isMimeTypeEqual("text/plain")) { final Object obj = tr.getTransferData(flavor); if (log.isDebugEnabled()) { log.debug(obj); } if (obj instanceof String) { TaskManager.execute(new Runnable() { public void run() { BufferFactory factory = new BufferFactory(); IBuffer buffer = factory.createBuffer(); buffer.open((String) obj); addBuffer(buffer); } }); } dtde.dropComplete(true); return; } } } catch (UnsupportedFlavorException e) { log.warn(e.getMessage(), e); } catch (IOException e) { log.warn(e.getMessage(), e); } dtde.rejectDrop(); if (log.isDebugEnabled()) { log.debug("drop end"); } } }); bufferPane.setDropTarget(dropTarget); this.add(BorderLayout.CENTER, splitPaneBottom); }
From source file:tvbrowser.ui.mainframe.MainFrame.java
@Override public void drop(DropTargetDropEvent dtde) { dtde.acceptDrop(dtde.getDropAction()); File[] files = getDragDropPlugins(dtde.getCurrentDataFlavors(), dtde.getTransferable()); try {//ww w .j ava 2s . c o m File tmpFile = File.createTempFile("plugins", ".txt"); StringBuilder alreadyInstalled = new StringBuilder(); StringBuilder notCompatiblePlugins = new StringBuilder(); for (File jarFile : files) { ClassLoader classLoader = null; try { URL[] urls = new URL[] { jarFile.toURI().toURL() }; classLoader = URLClassLoader.newInstance(urls, ClassLoader.getSystemClassLoader()); } catch (MalformedURLException exc) { } if (classLoader != null) { // Get the plugin name String pluginName = jarFile.getName(); pluginName = pluginName.substring(0, pluginName.length() - 4); try { String pluginId = "java." + pluginName.toLowerCase() + "." + pluginName; PluginProxy installedPlugin = PluginProxyManager.getInstance().getPluginForId(pluginId); TvDataServiceProxy service = TvDataServiceProxyManager.getInstance() .findDataServiceById(pluginName.toLowerCase() + '.' + pluginName); Class<?> pluginClass = classLoader.loadClass(pluginName.toLowerCase() + '.' + pluginName); Method getVersion = pluginClass.getMethod("getVersion", new Class[0]); Version version1 = null; try { version1 = (Version) getVersion.invoke(pluginClass, new Object[0]); } catch (Throwable t1) { t1.printStackTrace(); } if (installedPlugin != null && (installedPlugin.getInfo().getVersion().compareTo(version1) > 0 || (installedPlugin.getInfo().getVersion().compareTo(version1) == 0 && version1.isStable()))) { alreadyInstalled.append(installedPlugin.getInfo().getName()).append('\n'); } else if (service != null && (service.getInfo().getVersion().compareTo(version1) > 0 || (service.getInfo().getVersion().compareTo(version1) == 0 && version1.isStable()))) { alreadyInstalled.append(service.getInfo().getName()).append('\n'); } else { RandomAccessFile write = new RandomAccessFile(tmpFile, "rw"); String versionString = Integer.toString(version1.getMajor()) + '.' + (version1.getMinor() / 10) + (version1.getMinor() % 10) + '.' + version1.getSubMinor(); write.seek(write.length()); write.writeBytes("[plugin:" + pluginName + "]\n"); write.writeBytes("name_en=" + pluginName + "\n"); write.writeBytes("filename=" + jarFile.getName() + "\n"); write.writeBytes("version=" + versionString + "\n"); write.writeBytes("stable=" + version1.isStable() + "\n"); write.writeBytes("download=" + jarFile.toURI().toURL() + "\n"); write.writeBytes("category=unknown\n"); write.close(); } } catch (Exception e) { notCompatiblePlugins.append(jarFile.getName()).append("\n"); } } } if (alreadyInstalled.length() > 0) { showInfoTextMessage( mLocalizer.msg("update.alreadyInstalled", "The following Plugin in current version are already installed:"), alreadyInstalled.toString(), 400); } if (notCompatiblePlugins.length() > 0) { showInfoTextMessage( mLocalizer.msg("update.noTVBPlugin", "This following files are not TV-Browser Plugins:"), notCompatiblePlugins.toString(), 400); } if (tmpFile.length() > 0) { java.net.URL url = tmpFile.toURI().toURL(); SoftwareUpdater softwareUpdater = new SoftwareUpdater(url, false, true); mSoftwareUpdateItems = softwareUpdater.getAvailableSoftwareUpdateItems(); dtde.dropComplete(true); SoftwareUpdateDlg updateDlg = new SoftwareUpdateDlg(this, false, mSoftwareUpdateItems); updateDlg.setVisible(true); } else { dtde.rejectDrop(); dtde.dropComplete(false); } if (!tmpFile.delete()) { tmpFile.deleteOnExit(); } } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:unikn.dbis.univis.visualization.pivottable.VPivotTable.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./*from w w w.j a v a 2 s.co m*/ * <p/> * 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(DropTargetDropEvent dtde) { Object o = null; try { if (dtde.getTransferable().isDataFlavorSupported(VDataReferenceFlavor.COMBINATION_FLAVOR)) { o = dtde.getTransferable().getTransferData(VDataReferenceFlavor.COMBINATION_FLAVOR); } if (o == null) { dtde.rejectDrop(); dtde.dropComplete(false); } } catch (UnsupportedFlavorException ufe) { dtde.rejectDrop(); dtde.dropComplete(false); /*if (LOG.isErrorEnabled()) { LOG.error(ufe.getMessage(), ufe); } */ } catch (IOException ioe) { dtde.rejectDrop(); dtde.dropComplete(false); /*if (LOG.isErrorEnabled()) { LOG.error(ioe.getMessage(), ioe); } */ } if (o instanceof VCombination) { VCombination combination = (VCombination) o; VDimension dimension = combination.getDimension(); if (cube == null) { Set<VCube> supportedCubes = dimension.getSupportedCubes(); if (supportedCubes.size() > 1) { cube = CubeChooser.showCubeChooser(VPivotTable.this, supportedCubes); } else { cube = supportedCubes.iterator().next(); } // Check whether a cube exists or a cube has been selected on the // cube chooser. The chooser maybe interrupted with window close // and then return null. if (cube == null) { return; } } if (measure == null) { measure = combination.getMeasure(); } if (function == null) { function = combination.getFunction(); } addDimension(dimension, dtde); setAncestorsDropped(dimension, true); dtde.dropComplete(true); } }
From source file:zsk.JFCMainClient.java
/** * processing event of dropping a HTTP URL, YT-Video Image or plain text (URL) onto the frame * /*ww w. j av a 2s . co m*/ * seems not to work with M$-IE (8,9) - what a pity! */ public void drop(DropTargetDropEvent dtde) { Transferable tr = dtde.getTransferable(); DataFlavor[] flavors = tr.getTransferDataFlavors(); DataFlavor fl = null; String str = ""; debugoutput("DataFlavors found: ".concat(Integer.toString(flavors.length))); for (int i = 0; i < flavors.length; i++) { fl = flavors[i]; if (fl.isFlavorTextType() /* || fl.isMimeTypeEqual("text/html") || fl.isMimeTypeEqual("application/x-java-url") || fl.isMimeTypeEqual("text/uri-list")*/) { try { dtde.acceptDrop(dtde.getDropAction()); } catch (Throwable t) { } try { if (tr.getTransferData(fl) instanceof InputStreamReader) { debugoutput("Text-InputStream"); BufferedReader textreader = new BufferedReader((Reader) tr.getTransferData(fl)); String sline = ""; try { while (sline != null) { sline = textreader.readLine(); if (sline != null) str += sline; } } catch (Exception e) { } finally { textreader.close(); } str = str.replaceAll("<[^>]*>", ""); // remove HTML tags, especially a hrefs - ignore HTML characters like ß (which are no tags) } else if (tr.getTransferData(fl) instanceof InputStream) { debugoutput("Byte-InputStream"); InputStream input = new BufferedInputStream((InputStream) tr.getTransferData(fl)); int idata = input.read(); String sresult = ""; while (idata != -1) { if (idata != 0) sresult += new Character((char) idata).toString(); idata = input.read(); } // while debugoutput("sresult: ".concat(sresult)); } else { str = tr.getTransferData(fl).toString(); } } catch (IOException ioe) { } catch (UnsupportedFlavorException ufe) { } debugoutput("drop event text: ".concat(str).concat(" (").concat(fl.getMimeType()).concat(") ")); // insert text into textfield - almost the same as user drops text/url into this field // except special characaters -> from http://de.wikipedia.org/wiki/GNU-Projekt (GNU is not Unix)(„GNU is not Unix“) // two drops from same source .. one time in textfield and elsewhere - maybe we change that later?! if (str.matches(szYTREGEX.concat("(.*)"))) { synchronized (JFCMainClient.frame.textinputfield) { JFCMainClient.frame.textinputfield .setText(str.concat(JFCMainClient.frame.textinputfield.getText())); } debugoutput("breaking for-loop with str: ".concat(str)); break; } } else { String sv = "drop event unknown type: ".concat(fl.getHumanPresentableName()); //output(sv); debugoutput(sv); } } // for dtde.dropComplete(true); }