List of usage examples for java.awt.dnd DropTargetDropEvent acceptDrop
public void acceptDrop(int dropAction)
From source file:DragDropTreeExample.java
public void drop(DropTargetDropEvent dtde) { DnDUtils.debugPrintln("DropTarget drop, drop action = " + DnDUtils.showActions(dtde.getDropAction())); // Check the drop action if ((dtde.getDropAction() & DnDConstants.ACTION_COPY_OR_MOVE) != 0) { // Accept the drop and get the transfer data dtde.acceptDrop(dtde.getDropAction()); Transferable transferable = dtde.getTransferable(); boolean dropSucceeded = false; try {/*from ww w. j a va 2s .c o m*/ tree.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); // Save the user's selections saveTreeSelection(); dropSucceeded = dropFile(dtde.getDropAction(), transferable, dtde.getLocation()); DnDUtils.debugPrintln("Drop completed, success: " + dropSucceeded); } catch (Exception e) { DnDUtils.debugPrintln("Exception while handling drop " + e); } finally { tree.setCursor(Cursor.getDefaultCursor()); // Restore the user's selections restoreTreeSelection(); dtde.dropComplete(dropSucceeded); } } else { DnDUtils.debugPrintln("Drop target rejected drop"); dtde.dropComplete(false); } }
From source file:com.mirth.connect.client.ui.editors.filter.FilterPane.java
public void drop(DropTargetDropEvent dtde) { try {/*from ww w.j a va 2 s. com*/ 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 . j a v a 2s .co m 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:at.becast.youploader.gui.FrmMain.java
public void initMainTab() { cmbCategory = new JComboBox<Categories>(); cmbCategory.setModel(new DefaultComboBoxModel<Categories>(Categories.values())); SideBar sideBar = new SideBar(SideBar.SideBarMode.TOP_LEVEL, true, 300, true); ss1 = new SidebarSection(sideBar, LANG.getString("frmMain.Sidebar.Settings"), new EditPanel(this), new ImageIcon(getClass().getResource("/pencil.png"))); ss2 = new SidebarSection(sideBar, LANG.getString("frmMain.Sidebar.Playlists"), new PlaylistPanel(this), new ImageIcon(getClass().getResource("/layers.png"))); ss3 = new SidebarSection(sideBar, LANG.getString("frmMain.Sidebar.Monetisation"), new MonetPanel(), new ImageIcon(getClass().getResource("/money.png"))); sideBar.addSection(ss1, false);//from w ww.j av a 2s . c o m sideBar.addSection(ss2); sideBar.addSection(ss3); JPanel mainTab = new JPanel(); JPanel panel = new JPanel(); GroupLayout mainTabLayout = new GroupLayout(mainTab); mainTabLayout.setHorizontalGroup(mainTabLayout.createParallelGroup(Alignment.TRAILING) .addGroup(mainTabLayout.createSequentialGroup() .addComponent(panel, GroupLayout.DEFAULT_SIZE, 465, Short.MAX_VALUE) .addPreferredGap(ComponentPlacement.RELATED) .addComponent(sideBar, GroupLayout.DEFAULT_SIZE, 408, Short.MAX_VALUE))); mainTabLayout.setVerticalGroup(mainTabLayout.createParallelGroup(Alignment.LEADING) .addComponent(panel, GroupLayout.DEFAULT_SIZE, 492, Short.MAX_VALUE) .addGroup(mainTabLayout.createSequentialGroup() .addComponent(sideBar, GroupLayout.DEFAULT_SIZE, 469, Short.MAX_VALUE).addContainerGap())); panel.setLayout(new FormLayout( new ColumnSpec[] { ColumnSpec.decode("2px"), FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("20px:grow"), FormSpecs.LABEL_COMPONENT_GAP_COLSPEC, ColumnSpec.decode("23px"), ColumnSpec.decode("33px"), FormSpecs.UNRELATED_GAP_COLSPEC, ColumnSpec.decode("61px"), FormSpecs.DEFAULT_COLSPEC, FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("24px"), ColumnSpec.decode("28px"), ColumnSpec.decode("40px"), ColumnSpec.decode("36px"), FormSpecs.LABEL_COMPONENT_GAP_COLSPEC, ColumnSpec.decode("28px"), FormSpecs.LABEL_COMPONENT_GAP_COLSPEC, ColumnSpec.decode("58px"), }, new RowSpec[] { RowSpec.decode("2px"), FormSpecs.RELATED_GAP_ROWSPEC, RowSpec.decode("14px"), RowSpec.decode("25px"), FormSpecs.RELATED_GAP_ROWSPEC, RowSpec.decode("14px"), RowSpec.decode("25px"), FormSpecs.LINE_GAP_ROWSPEC, RowSpec.decode("14px"), RowSpec.decode("25px"), FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, RowSpec.decode("64dlu:grow"), FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, RowSpec.decode("max(64dlu;default)"), FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, RowSpec.decode("25px"), FormSpecs.PARAGRAPH_GAP_ROWSPEC, RowSpec.decode("24px"), RowSpec.decode("23px"), })); lbltitlelenght = new JLabel("(0/100)"); panel.add(lbltitlelenght, "14, 6, 3, 1, right, top"); txtTitle = new JTextField(); contextMenu.add(txtTitle); panel.add(txtTitle, "3, 7, 14, 1, fill, fill"); txtTitle.setColumns(10); txtTitle.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { calcNotifies(); } }); JLabel lblCategory = new JLabel(LANG.getString("frmMain.Category")); panel.add(lblCategory, "3, 9, 4, 1, left, bottom"); panel.add(cmbCategory, "3, 10, 14, 1, fill, fill"); JLabel lblDescription = new JLabel(LANG.getString("frmMain.Description")); panel.add(lblDescription, "3, 12, 4, 1, left, bottom"); lblDesclenght = new JLabel("(0/5000)"); panel.add(lblDesclenght, "14, 12, 3, 1, right, bottom"); JScrollPane DescriptionScrollPane = new JScrollPane(); panel.add(DescriptionScrollPane, "3, 13, 14, 1, fill, fill"); txtDescription = new JTextArea(); contextMenu.add(txtDescription); txtDescription.setFont(new Font("SansSerif", Font.PLAIN, 13)); DescriptionScrollPane.setViewportView(txtDescription); txtDescription.setWrapStyleWord(true); txtDescription.setLineWrap(true); txtDescription.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { calcNotifies(); } }); JLabel lblTags = new JLabel(LANG.getString("frmMain.Tags")); panel.add(lblTags, "3, 15, 4, 1, left, bottom"); lblTagslenght = new JLabel("(0/500)"); panel.add(lblTagslenght, "14, 15, 3, 1, right, top"); JScrollPane TagScrollPane = new JScrollPane(); panel.add(TagScrollPane, "3, 16, 14, 1, fill, fill"); txtTags = new JTextArea(); contextMenu.add(txtTags); txtTags.setFont(new Font("SansSerif", Font.PLAIN, 13)); TagScrollPane.setViewportView(txtTags); txtTags.setWrapStyleWord(true); txtTags.setLineWrap(true); txtTags.setBorder(BorderFactory.createEtchedBorder()); txtTags.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { calcNotifies(); } }); JLabel lblAccount = new JLabel(LANG.getString("frmMain.Account")); panel.add(lblAccount, "3, 18, 4, 1, left, bottom"); cmbAccount = new JComboBox<AccountType>(); panel.add(getCmbAccount(), "3, 19, 14, 1, fill, fill"); cmbAccount.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { changeUser(); } }); btnAddToQueue = new JButton(LANG.getString("frmMain.addtoQueue")); btnAddToQueue.setEnabled(false); panel.add(btnAddToQueue, "3, 21, 6, 1, fill, fill"); btnAddToQueue.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { queueButton(); } }); JLabel lblSelectVideo = new JLabel(); panel.add(lblSelectVideo, "3, 3, 4, 1, left, bottom"); lblSelectVideo.setText(LANG.getString("frmMain.selectVideoFile")); cmbFile = new JComboBox<String>(); cmbFile.setDropTarget(new DropTarget() { private static final long serialVersionUID = 8809983794742040683L; public synchronized void drop(DropTargetDropEvent evt) { try { evt.acceptDrop(DnDConstants.ACTION_COPY); @SuppressWarnings("unchecked") List<File> droppedFiles = (List<File>) evt.getTransferable() .getTransferData(DataFlavor.javaFileListFlavor); for (File file : droppedFiles) { cmbFile.removeAllItems(); cmbFile.addItem(file.getAbsolutePath()); } } catch (Exception ex) { LOG.error("Error dropping video file", ex); } } }); panel.add(cmbFile, "3, 4, 14, 1, fill, fill"); JButton btnSelectMovie = new JButton(); btnSelectMovie.setToolTipText("Select Video File"); panel.add(btnSelectMovie, "18, 4, center, top"); btnSelectMovie.setIcon(new ImageIcon(getClass().getResource("/film_add.png"))); JLabel lblTitle = new JLabel(LANG.getString("frmMain.Title")); panel.add(lblTitle, "3, 6, 4, 1, left, bottom"); JButton btnReset = new JButton(LANG.getString("frmMain.Reset")); btnReset.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { resetEdit(); } }); panel.add(btnReset, "11, 21, 6, 1, fill, fill"); btnSelectMovie.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { EditPanel edit = (EditPanel) ss1.contentPane; NativeJFileChooser chooser; if (edit.getTxtStartDir() != null && !edit.getTxtStartDir().equals("")) { chooser = new NativeJFileChooser(edit.getTxtStartDir().getText().trim()); } else { chooser = new NativeJFileChooser(); } int returnVal = chooser.showOpenDialog((Component) self); if (returnVal == JFileChooser.APPROVE_OPTION) { cmbFile.removeAllItems(); cmbFile.addItem(chooser.getSelectedFile().getAbsolutePath().toString()); } } }); mainTab.setLayout(mainTabLayout); mainTab.revalidate(); mainTab.repaint(); TabbedPane.addTab(LANG.getString("frmMain.Tabs.VideoSettings"), mainTab); }
From source file:com.emental.mindraider.ui.frames.MindRaiderMainWindow.java
public void drop(DropTargetDropEvent evt) { logger.debug("=-> drop"); try {//from w w w . j a v a 2 s . co m Transferable t = evt.getTransferable(); if (t.isDataFlavorSupported(DataFlavor.stringFlavor)) { logger.debug(" Accepting 'string' data flavor..."); evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE); String s = (String) t.getTransferData(DataFlavor.stringFlavor); evt.getDropTargetContext().dropComplete(true); logger.debug("DnD: '" + s + "'"); if (s != null) { int indexOf = s.indexOf("\n"); if (indexOf != -1) { dragAndDropReference = new DragAndDropReference(s.substring(indexOf + 1), s.substring(0, indexOf), DragAndDropReference.BROWSER_LINK); } else { dragAndDropReference = new DragAndDropReference(s, DragAndDropReference.BROWSER_LINK); } } } else { if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { logger.debug(" Accepting 'file list' data flavor..."); evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE); List<Object> list = (List<Object>) t.getTransferData(DataFlavor.javaFileListFlavor); if (list != null) { Iterator<Object> iterator = list.iterator(); while (iterator.hasNext()) { Object next = iterator.next(); if (next instanceof File) { logger.debug(" DnD file: " + next); dragAndDropReference = new DragAndDropReference(((File) next).getAbsolutePath(), DragAndDropReference.EXPLORER_LINK); } } } } else { logger.debug("DnD rejected! "); dragAndDropReference = null; // DataFlavor[] dfs=t.getTransferDataFlavors(); // for (int i = 0; i < dfs.length; i++) { // logger.debug(" "+i+" ... "+dfs[i].getMimeType()); // logger.debug(" "+i+" ... // "+dfs[i].getDefaultRepresentationClassAsString()); // logger.debug(" "+i+" ... // "+dfs[i].getHumanPresentableName()); // } } } } catch (Exception e) { logger.debug("Drag&Drop error:", e); dragAndDropReference = null; } OutlineJPanel.getInstance().enableDisableAttachToolbarButton(); if (dragAndDropReference != null) { JOptionPane.showMessageDialog(this, "Dropped local/web resource reference stored! Use \n'clip' icon from Notebook outline toolbar to attach it.", "Drag&Drop Info", JOptionPane.INFORMATION_MESSAGE); dragAndDropReference.debug(); } logger.debug("<-= drop"); }
From source file:com.SE.myPlayer.MusicPlayerGUI.java
public void tableReferesh(JTable songData_Table, String tableName, String columName) { int emptyResultSet = 0; try {//from w w w . j av a 2s . co m con = db.getCon(); stmt = con.createStatement(); ResultSet rs; switch (tableName) { case "library": rs = stmt.executeQuery("select * from library order by " + columName + ""); break; case "playlist": rs = stmt.executeQuery("select * from library order by " + columName + ""); break; default: rs = stmt.executeQuery( "Select library.id_songs, library.song_location, library.song_name, library.song_album, library.song_artist, library.genre, library.year, library.time, library.comment from playlist INNER JOIN library ON library.id_songs = playlist.id_songs AND playlist.playlist_name = '" + tableName + "' order by " + columName + ""); break; } DefaultTableModel myModel = new DefaultTableModel() { @Override public boolean isCellEditable(int row, int column) { return false; } }; String[] songsColumnsName = { "Location", "Name", "Album", "Artist", "Genre", "Year", "Time", "Comment" }; myModel.setColumnIdentifiers(songsColumnsName); ResultSetMetaData rsmd = rs.getMetaData(); int colNumbers = rsmd.getColumnCount(); Object[] objects = new Object[colNumbers]; while (rs.next()) { emptyResultSet = 1; for (int i = 0; i < colNumbers - 1; i++) { objects[i] = rs.getObject(i + 2); } myModel.addRow(objects); } if (emptyResultSet == 0) { myModel.addRow(objects); } songData_Table.setModel(myModel); rs = stmt.executeQuery("select col_name from col_name where col_status = 0"); while (rs.next()) { songData_Table.removeColumn(songData_Table.getColumn(rs.getString(1))); } songData_Table.getTableHeader().removeMouseListener(ma); songData_Table.getTableHeader().addMouseListener(ma); songData_Table.setDragEnabled(true); songData_Table.setDropTarget(new DropTarget() { @Override public synchronized void drop(DropTargetDropEvent dtde) { dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE); Transferable t = dtde.getTransferable(); try { if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { Object fileList = t.getTransferData(DataFlavor.javaFileListFlavor); String files = fileList.toString(); finalString = convertFileString(files); if (dropControl == 0 && lastOpen.equals("library")) { songAddDB(finalString); } else if (dropControl == 0 && !lastOpen.equals("library")) { songAddPlaylistFromLibrary(lastOpen, finalString); getSongTable(lastOpen); } else { songAddPlaylistFromLibrary(tableName, finalString); } } else if (dtde.isDataFlavorSupported(DataFlavor.stringFlavor)) { Object fileList = t.getTransferData(DataFlavor.stringFlavor); String fileListString = fileList.toString(); fileListString = Arrays.toString(fileListString.split("\\n")); String[] splitLocations = fileListString.split(",\\s"); for (int i = 0; i < splitLocations.length; i++) { if (i == 0) { splitLocations[i] = splitLocations[i].substring(1, splitLocations[i].indexOf(".mp3") + 4); } else { splitLocations[i] = splitLocations[i].substring(0, splitLocations[i].indexOf(".mp3") + 4); } } for (int i = 0; i < splitLocations.length; i++) { splitLocations[i] = sd.getLocations(splitLocations[i]); } finalString = Arrays.asList(splitLocations); if (dropControl == 0 && lastOpen.equals("library")) { songAddDB(finalString); } else if (dropControl == 0 && !lastOpen.equals("library")) { songAddPlaylistFromLibrary(lastOpen, finalString); getSongTable(lastOpen); } else { songAddPlaylistFromLibrary(tableName, finalString); } } } catch (UnsupportedFlavorException | IOException | InvalidDataException | UnsupportedTagException ex) { System.out.println("Error in second drop flavour............" + ex); } } }); if (con != null) { stmt.close(); con.close(); } } catch (SQLException e) { System.out.println("Error in Stmt " + e); } }
From source file:net.sf.nmedit.jtheme.component.JTModuleContainer.java
public void dropNewModule(DropTargetDropEvent dtde) { PModuleContainer mc = getModuleContainer(); PModuleDescriptor md = PDragDrop.getModuleDescriptor(dtde.getTransferable()); if (md == null || mc == null) { dtde.rejectDrop();/* w w w. ja v a2 s.c om*/ return; } Point l = dtde.getLocation(); PModule module; try { module = mc.createModule(md); module.setScreenLocation(l.x, l.y); } catch (InvalidDescriptorException e) { if (log.isErrorEnabled()) { log.error("could not create module: " + md, e); } dtde.rejectDrop(); return; } boolean moduleAdded = mc.add(module); if (!moduleAdded) { dtde.rejectDrop(); return; } // TODO short after dropping a new module and then moving it // causes a NullPointerException in the next line PModuleContainer parent = module.getParentComponent(); if (parent != null) { JTCableManager cm = getCableManager(); try { cm.setAutoRepaintDisabled(); MoveOperation move = parent.createMoveOperation(); move.setScreenOffset(0, 0); move.add(module); move.move(); } finally { cm.clearAutoRepaintDisabled(); } } else { // XXX concurrency problems probably ?! throw new RuntimeException("Drop problem on illegal modules: for example 2 midi globals"); } dtde.acceptDrop(DnDConstants.ACTION_COPY); // compute dimensions of container revalidate(); repaint(); dtde.dropComplete(true); }
From source file:javazoom.jlgui.player.amp.Player.java
/** * DnD : Drop implementation.//from w ww . j a va2 s .c o m * Adds all dropped files to the playlist. */ public void drop(DropTargetDropEvent e) { // Check DataFlavor DataFlavor[] dfs = e.getCurrentDataFlavors(); DataFlavor tdf = null; for (int i = 0; i < dfs.length; i++) { if (DataFlavor.javaFileListFlavor.equals(dfs[i])) { tdf = dfs[i]; break; } } // Is file list ? if (tdf != null) { // Accept COPY DnD only. if ((e.getSourceActions() & DnDConstants.ACTION_COPY) != 0) { e.acceptDrop(DnDConstants.ACTION_COPY); } else return; try { Transferable t = e.getTransferable(); Object data = t.getTransferData(tdf); // How many files ? if (data instanceof java.util.List) { java.util.List al = (java.util.List) data; // Read the first File. if (al.size() > 0) { File file = null; // Stops the player if needed. if ((playerState == PLAY) || (playerState == PAUSE)) { theSoundPlayer.stop(); playerState = STOP; } // Clean the playlist. playlist.removeAllItems(); // Add all dropped files to playlist. ListIterator li = al.listIterator(); while (li.hasNext()) { file = (File) li.next(); PlaylistItem pli = null; if (file != null) { pli = new PlaylistItem(file.getName(), file.getAbsolutePath(), -1, true); if (pli != null) playlist.appendItem(pli); } } // Start the playlist from the top. playlist.nextCursor(); fileList.initPlayList(); this.setCurrentSong(playlist.getCursor()); } } else { log.info("Unknown dropped objects"); } } catch (IOException ioe) { log.info("Drop error", ioe); e.dropComplete(false); return; } catch (UnsupportedFlavorException ufe) { log.info("Drop error", ufe); e.dropComplete(false); return; } catch (Exception ex) { log.info("Drop error", ex); e.dropComplete(false); return; } e.dropComplete(true); } }
From source file:com.declarativa.interprolog.gui.ListenerWindow.java
void handlePrologInputDnD(DropTargetDropEvent dtde) { //System.out.println("drop:"+dtde); try {/*from ww w .j a va 2s . co 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 a 2 s. com*/ } 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); } } }