List of usage examples for java.awt.dnd DropTargetDropEvent isDataFlavorSupported
public boolean isDataFlavorSupported(DataFlavor df)
From source file:Main.java
public void drop(DropTargetDropEvent e) { System.out.println("Dropping"); try {//w w w . j av a 2 s. c o m Transferable t = e.getTransferable(); if (e.isDataFlavorSupported(DataFlavor.stringFlavor)) { e.acceptDrop(e.getDropAction()); String s; s = (String) t.getTransferData(DataFlavor.stringFlavor); target.setText(s); e.dropComplete(true); } else e.rejectDrop(); } catch (java.io.IOException e2) { } catch (UnsupportedFlavorException e2) { } }
From source file:de.tor.tribes.ui.windows.AbstractDSWorkbenchFrame.java
@Override public void drop(DropTargetDropEvent dtde) { if (dtde.isDataFlavorSupported(VillageTransferable.villageDataFlavor) || dtde.isDataFlavorSupported(DataFlavor.stringFlavor)) { dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE); } else {//from ww w . j a v a 2 s. co m dtde.rejectDrop(); return; } Transferable t = dtde.getTransferable(); List<Village> v; MapPanel.getSingleton().setCurrentCursor(MapPanel.getSingleton().getCurrentCursor()); try { v = (List<Village>) t.getTransferData(VillageTransferable.villageDataFlavor); fireVillagesDraggedEvent(v, dtde.getLocation()); } catch (Exception ignored) { } }
From source file:ScribbleDragAndDrop.java
/** * This is the key method of DropTargetListener. It is invoked when the user * drops something on us.//from www.ja v a 2 s. c o m */ public void drop(DropTargetDropEvent e) { this.setBorder(normalBorder); // Restore the default border // First, check whether we understand the data that was dropped. // If we supports our data flavors, accept the drop, otherwise reject. if (e.isDataFlavorSupported(Scribble.scribbleDataFlavor) || e.isDataFlavorSupported(DataFlavor.stringFlavor)) { e.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE); } else { e.rejectDrop(); return; } // We've accepted the drop, so now we attempt to get the dropped data // from the Transferable object. Transferable t = e.getTransferable(); // Holds the dropped data Scribble droppedScribble; // This will hold the Scribble object // First, try to get the data directly as a scribble object try { droppedScribble = (Scribble) t.getTransferData(Scribble.scribbleDataFlavor); } catch (Exception ex) { // unsupported flavor, IO exception, etc. // If that doesn't work, try to get it as a String and parse it try { String s = (String) t.getTransferData(DataFlavor.stringFlavor); droppedScribble = Scribble.parse(s); } catch (Exception ex2) { // If we still couldn't get the data, tell the system we failed e.dropComplete(false); return; } } // If we get here, we've got the Scribble object Point p = e.getLocation(); // Where did the drop happen? droppedScribble.translate(p.getX(), p.getY()); // Move it there scribbles.add(droppedScribble); // add to display list repaint(); // ask for redraw e.dropComplete(true); // signal success! }
From source file:com.SE.myPlayer.MusicPlayerGUI.java
public void tableReferesh(JTable songData_Table, String tableName, String columName) { int emptyResultSet = 0; try {/* w ww. j a v a2 s .c om*/ 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: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) { }// w ww . j a v a 2 s .c o m } 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.rdv.datapanel.AbstractDataPanel.java
@SuppressWarnings("unchecked") public void drop(DropTargetDropEvent e) { try {//from w ww . ja va2s. com 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 . j a v a 2s .c o 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(); } }