Skip to content

Commit

Permalink
Can now open playlists by dragging files into the app, can insert the…
Browse files Browse the repository at this point in the history
…m, and media files, into an open playlist the same way!
  • Loading branch information
firewyre committed Mar 10, 2011
1 parent 2c4a5ae commit a12401e
Show file tree
Hide file tree
Showing 4 changed files with 188 additions and 21 deletions.
2 changes: 1 addition & 1 deletion dev/listfix/model/Playlist.java
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ private List<PlaylistEntry> getEntriesForFiles(File[] files, IProgressObserver<S
List<PlaylistEntry> ents = new ArrayList<PlaylistEntry>();
for (File file : files)
{
if (!observer.getCancelled())
if (observer == null || !observer.getCancelled())
{
if (Playlist.isPlaylist(file))
{
Expand Down
6 changes: 0 additions & 6 deletions dev/listfix/view/GUIScreen.form
Original file line number Diff line number Diff line change
Expand Up @@ -712,9 +712,6 @@
<Property name="text" type="java.lang.String" value="Open A Playlist"/>
<Property name="toolTipText" type="java.lang.String" value="Open A Playlist"/>
<Property name="alignmentY" type="float" value="0.0"/>
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
<Border info="null"/>
</Property>
<Property name="focusable" type="boolean" value="false"/>
<Property name="horizontalTextPosition" type="int" value="0"/>
<Property name="iconTextGap" type="int" value="-2"/>
Expand Down Expand Up @@ -754,9 +751,6 @@
<Property name="text" type="java.lang.String" value="New Playlist"/>
<Property name="toolTipText" type="java.lang.String" value="New Playlist"/>
<Property name="alignmentY" type="float" value="0.0"/>
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
<Border info="null"/>
</Property>
<Property name="focusable" type="boolean" value="false"/>
<Property name="horizontalTextPosition" type="int" value="0"/>
<Property name="iconTextGap" type="int" value="3"/>
Expand Down
77 changes: 74 additions & 3 deletions dev/listfix/view/GUIScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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()
Expand Down Expand Up @@ -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
Expand All @@ -176,6 +183,7 @@ public boolean canImport(TransferHandler.TransferSupport info)
return false;
}

@Override
public boolean importData(TransferHandler.TransferSupport info)
{
return false;
Expand Down Expand Up @@ -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()
Expand Down
124 changes: 113 additions & 11 deletions dev/listfix/view/PlaylistEditCtrl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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<Playlist, Void> worker = new ProgressWorker<Playlist, Void>()
{
@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())
{
Expand All @@ -1638,7 +1741,6 @@ public boolean importData(TransferHandler.TransferSupport info)
{
libraryFiles = null;
}

ProgressWorker<Playlist, Void> worker = new ProgressWorker<Playlist, Void>()
{
@Override
Expand All @@ -1660,7 +1762,6 @@ protected void done()
{
list = get();
_playlist.addAll(dl.getRow(), list.getEntries());

if (_playlist.size() == list.size())
{
resizeAllColumns();
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit a12401e

Please sign in to comment.