diff --git a/dev/listfix/model/Playlist.java b/dev/listfix/model/Playlist.java index 5197548b..587c064b 100644 --- a/dev/listfix/model/Playlist.java +++ b/dev/listfix/model/Playlist.java @@ -481,7 +481,7 @@ private List getEntriesForFiles(File[] files, IProgressObserver ents = new ArrayList(); for (File file : files) { - if (!observer.getCancelled()) + if (observer == null || !observer.getCancelled()) { if (Playlist.isPlaylist(file)) { diff --git a/dev/listfix/view/GUIScreen.form b/dev/listfix/view/GUIScreen.form index cd15a19a..cd07c43e 100644 --- a/dev/listfix/view/GUIScreen.form +++ b/dev/listfix/view/GUIScreen.form @@ -712,9 +712,6 @@ - - - @@ -754,9 +751,6 @@ - - - diff --git a/dev/listfix/view/GUIScreen.java b/dev/listfix/view/GUIScreen.java index 6e75336f..b6aadf68 100644 --- a/dev/listfix/view/GUIScreen.java +++ b/dev/listfix/view/GUIScreen.java @@ -28,8 +28,15 @@ import java.awt.GraphicsEnvironment; import java.awt.Insets; import java.awt.Rectangle; +import java.awt.datatransfer.DataFlavor; import java.awt.datatransfer.StringSelection; import java.awt.datatransfer.Transferable; +import java.awt.dnd.DnDConstants; +import java.awt.dnd.DropTarget; +import java.awt.dnd.DropTargetDragEvent; +import java.awt.dnd.DropTargetDropEvent; +import java.awt.dnd.DropTargetEvent; +import java.awt.dnd.DropTargetListener; import java.awt.event.ComponentAdapter; import java.awt.event.ComponentEvent; import java.awt.event.KeyEvent; @@ -77,7 +84,6 @@ import listfix.model.BatchRepair; import listfix.model.BatchRepairItem; import listfix.model.Playlist; -import listfix.model.PlaylistEntry; import listfix.model.PlaylistHistory; import listfix.util.ArrayFunctions; @@ -94,13 +100,14 @@ import listfix.view.support.ICloseableTabManager; import listfix.view.support.ProgressWorker; -public final class GUIScreen extends JFrame implements ICloseableTabManager +public final class GUIScreen extends JFrame implements ICloseableTabManager, DropTargetListener { private static final long serialVersionUID = 7691786927987534889L; private final JFileChooser jM3UChooser; private final JFileChooser jMediaDirChooser; private final JFileChooser jSaveFileChooser; private GUIDriver guiDriver = null; + private DropTarget dropTarget = null; /** Creates new form GUIScreen */ public GUIScreen() @@ -167,7 +174,7 @@ public GUIScreen() syncJMenuFonts(); - // drag-n-drop support + // drag-n-drop support for the playlist directory tree _playlistDirectoryTree.setTransferHandler(new TransferHandler() { @Override @@ -176,6 +183,7 @@ public boolean canImport(TransferHandler.TransferSupport info) return false; } + @Override public boolean importData(TransferHandler.TransferSupport info) { return false; @@ -204,6 +212,69 @@ protected Transferable createTransferable(JComponent c) } }); + + dropTarget = new DropTarget(this, this); + } + + public void dragEnter(DropTargetDragEvent dtde) + { + + } + + public void dragExit(DropTargetEvent dte) + { + + } + + public void dragOver(DropTargetDragEvent dtde) + { + + } + + public void dropActionChanged(DropTargetDragEvent dtde) + { + + } + + public void drop(DropTargetDropEvent dtde) + { + try + { + // Ok, get the dropped object and try to figure out what it is + Transferable tr = dtde.getTransferable(); + DataFlavor[] flavors = tr.getTransferDataFlavors(); + for (int i = 0; i < flavors.length; i++) + { + System.out.println("Possible flavor: " + flavors[i].getMimeType()); + // Check for file lists specifically + if (flavors[i].isFlavorJavaFileListType()) + { + // Great! Accept copy drops... + dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE); + + // And add the list of file names to our text area + java.util.List list = (java.util.List) tr.getTransferData(flavors[i]); + for (int j = 0; j < list.size(); j++) + { + if (list.get(j) instanceof File) + { + openPlaylist((File) list.get(j)); + } + } + + // If we made it this far, everything worked. + dtde.dropComplete(true); + return; + } + } + // Hmm, the user must not have dropped a file list + dtde.rejectDrop(); + } + catch (Exception e) + { + e.printStackTrace(); + dtde.rejectDrop(); + } } public AppOptions getOptions() diff --git a/dev/listfix/view/PlaylistEditCtrl.java b/dev/listfix/view/PlaylistEditCtrl.java index 4371bbe5..bafff004 100644 --- a/dev/listfix/view/PlaylistEditCtrl.java +++ b/dev/listfix/view/PlaylistEditCtrl.java @@ -27,6 +27,7 @@ import java.awt.datatransfer.DataFlavor; import java.awt.datatransfer.Transferable; import java.awt.datatransfer.UnsupportedFlavorException; +import java.awt.dnd.DnDConstants; import java.awt.event.ActionEvent; import java.awt.event.KeyEvent; import java.awt.event.MouseAdapter; @@ -1557,7 +1558,9 @@ else if ((isOverItem && _uiTable.getSelectedRowCount() == 0) @Override public boolean canImport(TransferHandler.TransferSupport info) { - if (!info.isDataFlavorSupported(_playlistEntryListFlavor) && !info.isDataFlavorSupported(DataFlavor.stringFlavor)) + if (!info.isDataFlavorSupported(_playlistEntryListFlavor) + && !info.isDataFlavorSupported(DataFlavor.stringFlavor) + && !info.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { return false; } @@ -1579,7 +1582,9 @@ public boolean importData(TransferHandler.TransferSupport info) } // Check for custom PlaylistEntryList flavor - if (!info.isDataFlavorSupported(_playlistEntryListFlavor) && !info.isDataFlavorSupported(DataFlavor.stringFlavor)) + if (!info.isDataFlavorSupported(_playlistEntryListFlavor) + && !info.isDataFlavorSupported(DataFlavor.stringFlavor) + && !info.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { return false; } @@ -1619,16 +1624,114 @@ public boolean importData(TransferHandler.TransferSupport info) return false; } } + else if (info.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) + { + return HandleFileListFlavor(info, dl); + } else + { + return HandleStringFlavor(info, dl); + } + } + + private boolean HandleFileListFlavor(TransferSupport info, final JTable.DropLocation dl) + { + Transferable t = info.getTransferable(); + DataFlavor[] flavors = t.getTransferDataFlavors(); + for (int i = 0; i < flavors.length; i++) { - // Currently we're only dealing w/ a string that represents the path to a playlist - // Get the entries that are being dropped. - Transferable t = info.getTransferable(); - final String data; try { - data = (String) t.getTransferData(DataFlavor.stringFlavor); + int insertAt = dl.getRow(); + final List list; + list = (List)t.getTransferData(flavors[i]); + for (int j = 0; j < list.size(); j++) + { + final File tempFile = (File)list.get(j); + if (tempFile instanceof File) + { + if (Playlist.isPlaylist(tempFile)) + { + final String[] libraryFiles; + if (GUIDriver.getInstance().getAppOptions().getAutoLocateEntriesOnPlaylistLoad()) + { + libraryFiles = GUIDriver.getInstance().getMediaLibraryFileList(); + } + else + { + libraryFiles = null; + } + ProgressWorker worker = new ProgressWorker() + { + @Override + protected Playlist doInBackground() throws Exception + { + Playlist list = new Playlist(tempFile, this); + if (libraryFiles != null) + { + list.repair(libraryFiles, this); + } + return list; + } + + @Override + protected void done() + { + Playlist list; + try + { + list = get(); + _playlist.addAll(dl.getRow(), list.getEntries()); + } + catch (CancellationException ex) + { + return; + } + catch (Exception ex) + { + JOptionPane.showMessageDialog(PlaylistEditCtrl.this.getParentFrame(), ex, "Open Playlist Error", JOptionPane.ERROR_MESSAGE); + return; + } + } + }; + ProgressDialog pd = new ProgressDialog((GUIScreen) getParentFrame(), true, worker, "Loading..."); + int plistSize = _playlist.size(); + pd.setVisible(true); + insertAt += _playlist.size() - plistSize; + } + else + { + // add it to the playlist! + _playlist.add(insertAt, new File[] {tempFile}, null); + insertAt++; + } + } + } + resizeAllColumns(); + return true; + } + catch (UnsupportedFlavorException ex) + { + Logger.getLogger(PlaylistEditCtrl.class.getName()).log(Level.SEVERE, null, ex); + } + catch (IOException ex) + { + Logger.getLogger(PlaylistEditCtrl.class.getName()).log(Level.SEVERE, null, ex); + } + } + return false; + } + private boolean HandleStringFlavor(TransferSupport info, final JTable.DropLocation dl) + { + Transferable t = info.getTransferable(); + DataFlavor[] flavors = t.getTransferDataFlavors(); + for (int i = 0; i < flavors.length; i++) + { + try + { + final String data; + data = (String) t.getTransferData(flavors[i]); final String[] libraryFiles; if (GUIDriver.getInstance().getAppOptions().getAutoLocateEntriesOnPlaylistLoad()) { @@ -1638,7 +1741,6 @@ public boolean importData(TransferHandler.TransferSupport info) { libraryFiles = null; } - ProgressWorker worker = new ProgressWorker() { @Override @@ -1660,7 +1762,6 @@ protected void done() { list = get(); _playlist.addAll(dl.getRow(), list.getEntries()); - if (_playlist.size() == list.size()) { resizeAllColumns(); @@ -1689,9 +1790,10 @@ protected void done() { Logger.getLogger(PlaylistEditCtrl.class.getName()).log(Level.SEVERE, null, ex); } - return false; } - }; + return false; + } +; @Override public int getSourceActions(JComponent c)