diff --git a/projects/robodj/src/java/robodj/chooser/PlaylistController.java b/projects/robodj/src/java/robodj/chooser/PlaylistController.java index d8043999..575d823f 100644 --- a/projects/robodj/src/java/robodj/chooser/PlaylistController.java +++ b/projects/robodj/src/java/robodj/chooser/PlaylistController.java @@ -1,10 +1,11 @@ // -// $Id: PlaylistController.java,v 1.2 2004/01/28 02:36:44 mdb Exp $ +// $Id: PlaylistController.java,v 1.3 2004/02/24 12:40:24 mdb Exp $ package robodj.chooser; import java.awt.Color; import java.awt.event.ActionEvent; +import java.util.ArrayList; import java.util.Iterator; import javax.swing.JButton; @@ -12,6 +13,7 @@ import javax.swing.JOptionPane; import javax.swing.JPanel; import com.samskivert.io.PersistenceException; +import com.samskivert.util.ArrayUtil; import com.samskivert.util.StringUtil; import com.samskivert.swing.util.SwingUtil; @@ -135,6 +137,31 @@ public class PlaylistController extends ItemController } }, this); + } else if (cmd.equals(PlaylistPanel.SHUFFLE)) { + // put all of the songs in the playlist into a list and + // shuffle them + ArrayList slist = new ArrayList(); + for (Iterator iter = _panel.plist.iterator(); iter.hasNext(); ) { + slist.add(((PlaylistEntry)iter.next()).song); + } + final Song[] songs = (Song[])slist.toArray(new Song[slist.size()]); + ArrayUtil.shuffle(songs); + + // now clear and reload the playlist entirely + TaskMaster.invokeTask("noop", new TaskAdapter() { + public Object invoke () throws Exception { + Chooser.scontrol.clear(); + for (int ii = 0; ii < songs.length; ii++) { + Chooser.scontrol.append( + songs[ii].entryid, songs[ii].songid, + songs[ii].location); + } + // finally queue up a UI refresh + postAction(_panel, PlaylistPanel.REFRESH); + return null; + } + }, this); + } else { return super.handleAction(e); } diff --git a/projects/robodj/src/java/robodj/chooser/PlaylistPanel.java b/projects/robodj/src/java/robodj/chooser/PlaylistPanel.java index 6ac94ec4..ec05a113 100644 --- a/projects/robodj/src/java/robodj/chooser/PlaylistPanel.java +++ b/projects/robodj/src/java/robodj/chooser/PlaylistPanel.java @@ -1,5 +1,5 @@ // -// $Id: PlaylistPanel.java,v 1.17 2004/01/28 02:36:23 mdb Exp $ +// $Id: PlaylistPanel.java,v 1.18 2004/02/24 12:40:24 mdb Exp $ package robodj.chooser; @@ -48,6 +48,8 @@ public class PlaylistPanel extends ControlledPanel public static final String REMOVE_ALL = "remove_all"; + public static final String SHUFFLE = "shuffle"; + public ArrayList plist = new ArrayList(); public PlaylistPanel () @@ -76,10 +78,12 @@ public class PlaylistPanel extends ControlledPanel // add our control buttons _clearbut = ButtonUtil.createControlButton( - CLEAR_TIP, "clear", CLEAR_ICON_PATH); + CLEAR_TIP, CLEAR, CLEAR_ICON_PATH); cbar.add(_clearbut); cbar.add(ButtonUtil.createControlButton( - REFRESH_TIP, "refresh", REFRESH_ICON_PATH)); + REFRESH_TIP, REFRESH, REFRESH_ICON_PATH)); + cbar.add(ButtonUtil.createControlButton( + SHUFFLE_TIP, SHUFFLE, SHUFFLE_ICON_PATH)); add(cbar, GroupLayout.FIXED); // use a special font for our name buttons @@ -227,6 +231,7 @@ public class PlaylistPanel extends ControlledPanel protected static final String ICON_ROOT = "/robodj/chooser/images/"; protected static final String REFRESH_ICON_PATH = ICON_ROOT + "refresh.png"; protected static final String CLEAR_ICON_PATH = ICON_ROOT + "clear.png"; + protected static final String SHUFFLE_ICON_PATH = ICON_ROOT + "shuffle.png"; protected static final String SKIPTO_ICON_PATH = ICON_ROOT + "skip.png"; protected static final String REMOVE_ENTRY_ICON_PATH = ICON_ROOT + "remove_entry.png"; @@ -237,6 +242,8 @@ public class PlaylistPanel extends ControlledPanel protected static final String REFRESH_TIP = "Refresh the playlist"; protected static final String CLEAR_TIP = "Clear all songs from the playlist"; + protected static final String SHUFFLE_TIP = + "Shuffle the songs in the playlist"; protected static final String SKIPTO_TIP = "Skip to this song"; protected static final String REMOVE_ENTRY_TIP = "Remove all songs in this entry from the playlist"; diff --git a/projects/robodj/src/java/robodj/chooser/images/shuffle.png b/projects/robodj/src/java/robodj/chooser/images/shuffle.png new file mode 100644 index 00000000..51406cff Binary files /dev/null and b/projects/robodj/src/java/robodj/chooser/images/shuffle.png differ