List of usage examples for java.awt.dnd DropTargetDropEvent getSourceActions
public int getSourceActions()
From source file:javazoom.jlgui.player.amp.skin.DropTargetAdapter.java
public void drop(DropTargetDropEvent e) { // Check DataFlavor DataFlavor[] dfs = e.getCurrentDataFlavors(); DataFlavor tdf = null;/*from w ww . jav a2 s. c o m*/ for (int i = 0; i < dfs.length; i++) { if (DataFlavor.javaFileListFlavor.equals(dfs[i])) { tdf = dfs[i]; break; } else if (DataFlavor.stringFlavor.equals(dfs[i])) { tdf = dfs[i]; break; } } // Data Flavor available ? 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); processDrop(data); } 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:javazoom.jlgui.player.amp.Player.java
/** * DnD : Drop implementation./*from ww w . ja v a2s .co 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); } }