List of usage examples for java.awt.dnd DropTargetDropEvent acceptDrop
public void acceptDrop(int dropAction)
From source file:org.apache.jmeter.gui.MainFrame.java
/** * Handler of Top level Dnd/*w ww. j av a 2 s. co m*/ */ @Override public void drop(DropTargetDropEvent dtde) { try { Transferable tr = dtde.getTransferable(); DataFlavor[] flavors = tr.getTransferDataFlavors(); for (DataFlavor flavor : flavors) { // Check for file lists specifically if (flavor.isFlavorJavaFileListType()) { dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE); try { openJmxFilesFromDragAndDrop(tr); } finally { dtde.dropComplete(true); } return; } } } catch (UnsupportedFlavorException | IOException e) { log.warn("Dnd failed", e); } }
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 www . j a v a2 s . 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 {/*w w w .java2 s.c o m*/ 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 w ww.ja v a 2 s .co m * * @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:pkgrenamer.Main.java
static void onDropFiles(DropTargetDropEvent dtde, FileDropListener onDrop) { try {/*from w ww. j a v a 2s . c om*/ Transferable transferable = dtde.getTransferable(); if (transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { dtde.acceptDrop(DnDConstants.ACTION_MOVE); java.util.List<?> files = (java.util.List<?>) transferable .getTransferData(DataFlavor.javaFileListFlavor); File[] fa = new File[files.size()]; for (int i = 0; i < fa.length; i++) { fa[i] = (File) files.get(i); } onDrop.onDropFile(fa); dtde.getDropTargetContext().dropComplete(true); } else { if (sNixFileDataFlavor == null) { sNixFileDataFlavor = new DataFlavor("text/uri-list;class=java.lang.String"); } dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE); String data = (String) transferable.getTransferData(sNixFileDataFlavor); if (data != null) { ArrayList<File> fs = new ArrayList<>(); for (StringTokenizer st = new StringTokenizer(data, "\r\n"); st.hasMoreTokens();) { String token = st.nextToken().trim(); if (token.startsWith("#") || token.isEmpty()) { continue; } try { fs.add(new File(new URI(token))); } catch (Exception e) { } } onDrop.onDropFile(fs.toArray(new File[0])); dtde.getDropTargetContext().dropComplete(true); } else { dtde.rejectDrop(); } } } catch (Exception e) { e.printStackTrace(); } }
From source file:plugin.notes.gui.NotesTreeNode.java
/** * handles a drop of a java file list/* w w w. j a va 2 s.c o m*/ * * @param dtde * drop target drop even - a java dile list has been dropped on * something that represents this node. * @return returns true if the drop takes place, false if not */ public boolean handleDropJavaFileList(DropTargetDropEvent dtde) { dtde.acceptDrop(dtde.getDropAction()); Transferable t = dtde.getTransferable(); try { List fileList = ((List) t.getTransferData(DataFlavor.javaFileListFlavor)); for (Object aFileList : fileList) { File newFile = (File) aFileList; if (newFile.exists()) { FileUtils.copyFile(newFile, new File(dir.getAbsolutePath() + File.separator + newFile.getName())); } } } catch (Exception e) { Logging.errorPrint(e.getMessage(), e); return false; } return true; }
From source file:se.trixon.pacoma.ui.MainFrame.java
private void initListeners() { mActionManager.addAppListener(new ActionManager.AppListener() { @Override// w ww . j a va 2s. c om 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/*from w ww. j av a2 s. 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); }
From source file:se.trixon.solos.core.panel.NavigatorPanel.java
private void init() { DropTarget dropTarget = new DropTarget() { @Override/* ww w . j av a2 s . c o m*/ public synchronized void drop(DropTargetDropEvent evt) { try { evt.acceptDrop(DnDConstants.ACTION_COPY); List<File> droppedFiles = (List<File>) evt.getTransferable() .getTransferData(DataFlavor.javaFileListFlavor); File file = droppedFiles.get(0); if (droppedFiles.size() == 1) { if (file.isDirectory()) { setPath(file); } else if (file.isFile()) { setPath(file.getParentFile()); } } else { setPath(file.getParentFile()); } directoryChanged(); } catch (UnsupportedFlavorException | IOException ex) { } } }; textField.setDropTarget(dropTarget); }
From source file:se.trixon.toolbox.geotagger.GeotaggerTopComponent.java
private void init() { openButton.setIcon(Pict.Actions.DOCUMENT_OPEN.get(TOOLBAR_ICON_SIZE)); editToggleButton.setIcon(Pict.Actions.DOCUMENT_EDIT.get(TOOLBAR_ICON_SIZE)); closeButton.setIcon(Pict.Actions.WINDOW_CLOSE.get(TOOLBAR_ICON_SIZE)); closeButton.setEnabled(false);/*from w w w . java 2s . co m*/ startButton.setIcon(Pict.Actions.ARROW_RIGHT.get(ICON_SIZE)); startButton.setToolTipText(Dict.START.getString()); startButton.setEnabled(false); saveLogButton.setIcon(Pict.Actions.DOCUMENT_SAVE.get(ICON_SIZE)); saveLogButton.setEnabled(false); helpButton.setIcon(Pict.Actions.HELP_CONTENTS.get(ICON_SIZE)); helpButton.setToolTipText(Dict.HELP.getString()); DropTarget dropTarget = new DropTarget() { @Override public synchronized void drop(DropTargetDropEvent evt) { try { evt.acceptDrop(DnDConstants.ACTION_COPY); List<File> droppedFiles = (List<File>) evt.getTransferable() .getTransferData(DataFlavor.javaFileListFlavor); if (droppedFiles.get(0).isFile()) { openFile(droppedFiles.get(0)); } } catch (UnsupportedFlavorException | IOException ex) { } } }; scrollPane.setDropTarget(dropTarget); mTableModel = new GeotagTableModel(); table.setModel(mTableModel); mTableRowSorter = new TableRowSorter<>(mTableModel); table.setRowSorter(mTableRowSorter); TableColumnModel columnModel = table.getColumnModel(); NumericTableCellRenderer cooNumericTableCellRenderer = new NumericTableCellRenderer(Double.class, 6); NumericTableCellRenderer altNumericTableCellRenderer = new NumericTableCellRenderer(Double.class, 4); columnModel.getColumn(GeotagTableModel.COLUMN_LATITUDE).setCellRenderer(cooNumericTableCellRenderer); columnModel.getColumn(GeotagTableModel.COLUMN_LONGITUDE).setCellRenderer(cooNumericTableCellRenderer); columnModel.getColumn(GeotagTableModel.COLUMN_ALTITUDE).setCellRenderer(altNumericTableCellRenderer); columnModel.getColumn(GeotagTableModel.COLUMN_NAME).setPreferredWidth(200); columnModel.getColumn(GeotagTableModel.COLUMN_LATITUDE).setPreferredWidth(100); columnModel.getColumn(GeotagTableModel.COLUMN_LONGITUDE).setPreferredWidth(100); columnModel.getColumn(GeotagTableModel.COLUMN_ALTITUDE).setPreferredWidth(50); }