Handle playing display more efficiently.

git-svn-id: https://samskivert.googlecode.com/svn/trunk@180 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
mdb
2001-07-13 00:35:42 +00:00
parent a8272baf6e
commit 13f9e12325
@@ -1,5 +1,5 @@
// //
// $Id: PlaylistPanel.java,v 1.2 2001/07/13 00:11:05 mdb Exp $ // $Id: PlaylistPanel.java,v 1.3 2001/07/13 00:35:42 mdb Exp $
package robodj.chooser; package robodj.chooser;
@@ -68,13 +68,13 @@ public class PlaylistPanel
public void actionPerformed (ActionEvent e) public void actionPerformed (ActionEvent e)
{ {
String cmd = e.getActionCommand(); String cmd = e.getActionCommand();
if (cmd.equals("...")) { if (cmd.equals("clear")) {
} else if (cmd.equals("clear")) {
Chooser.scontrol.clear(); Chooser.scontrol.clear();
refreshPlaylist();
} else if (cmd.equals("skip")) { } else if (cmd.equals("skip")) {
Chooser.scontrol.skip(); Chooser.scontrol.skip();
refreshPlaying();
} else if (cmd.equals("refresh")) { } else if (cmd.equals("refresh")) {
refreshPlaylist(); refreshPlaylist();
@@ -84,14 +84,21 @@ public class PlaylistPanel
PlaylistEntry entry = PlaylistEntry entry =
(PlaylistEntry)src.getClientProperty("entry"); (PlaylistEntry)src.getClientProperty("entry");
Chooser.scontrol.skipto(entry.song.songid); Chooser.scontrol.skipto(entry.song.songid);
refreshPlaylist(); refreshPlaying();
} else if (cmd.equals("remove")) { } else if (cmd.equals("remove")) {
JButton src = (JButton)e.getSource(); JButton src = (JButton)e.getSource();
PlaylistEntry entry = PlaylistEntry entry =
(PlaylistEntry)src.getClientProperty("entry"); (PlaylistEntry)src.getClientProperty("entry");
Chooser.scontrol.remove(entry.song.songid); Chooser.scontrol.remove(entry.song.songid);
refreshPlaylist();
// remove the entry UI elements
JPanel epanel = (JPanel)entry.label.getParent();
epanel.getParent().remove(epanel);
// update the playing indicator because we may have removed
// the playing entry
refreshPlaying();
} }
} }
@@ -106,6 +113,18 @@ public class PlaylistPanel
TaskMaster.invokeMethodTask("readPlaylist", this, this); TaskMaster.invokeMethodTask("readPlaylist", this, this);
} }
protected void refreshPlaying ()
{
// unhighlight whoever is playing now
PlaylistEntry pentry = getPlayingEntry();
if (pentry != null) {
pentry.label.setForeground(Color.black);
}
// figure out who's playing
TaskMaster.invokeMethodTask("readPlaying", this, this);
}
public void readPlaylist () public void readPlaylist ()
throws SQLException throws SQLException
{ {
@@ -113,17 +132,7 @@ public class PlaylistPanel
_plist.clear(); _plist.clear();
// find out what's currently playing // find out what's currently playing
String playing = Chooser.scontrol.getPlaying(); readPlaying();
playing = StringUtil.split(playing, ":")[1].trim();
_playid = -1;
if (!playing.equals("<none>")) {
try {
_playid = Integer.parseInt(playing);
} catch (NumberFormatException nfe) {
Log.warning("Unable to parse currently playing id '" +
playing + "'.");
}
}
// get the playlist from the music daemon // get the playlist from the music daemon
String[] plist = Chooser.scontrol.getPlaylist(); String[] plist = Chooser.scontrol.getPlaylist();
@@ -145,10 +154,28 @@ public class PlaylistPanel
} }
} }
public void readPlaying ()
{
String playing = Chooser.scontrol.getPlaying();
playing = StringUtil.split(playing, ":")[1].trim();
_playid = -1;
if (!playing.equals("<none>")) {
try {
_playid = Integer.parseInt(playing);
} catch (NumberFormatException nfe) {
Log.warning("Unable to parse currently playing id '" +
playing + "'.");
}
}
}
public void taskCompleted (String name, Object result) public void taskCompleted (String name, Object result)
{ {
if (name.equals("readPlaylist")) { if (name.equals("readPlaylist")) {
populatePlaylist(); populatePlaylist();
} else if (name.equals("readPlaying")) {
highlightPlaying();
} }
} }
@@ -197,9 +224,8 @@ public class PlaylistPanel
hpanel.setLayout(gl); hpanel.setLayout(gl);
entry.label = new JLabel(entry.song.title); entry.label = new JLabel(entry.song.title);
if (entry.song.songid == _playid) { entry.label.setForeground((entry.song.songid == _playid) ?
entry.label.setForeground(Color.red); Color.red : Color.black);
}
entry.label.setFont(_nameFont); entry.label.setFont(_nameFont);
hpanel.add(entry.label); hpanel.add(entry.label);
@@ -227,6 +253,27 @@ public class PlaylistPanel
} }
} }
protected void highlightPlaying ()
{
for (int i = 0; i < _plist.size(); i++) {
PlaylistEntry entry = (PlaylistEntry)_plist.get(i);
if (entry.song.songid == _playid) {
entry.label.setForeground(Color.red);
}
}
}
protected PlaylistEntry getPlayingEntry ()
{
for (int i = 0; i < _plist.size(); i++) {
PlaylistEntry entry = (PlaylistEntry)_plist.get(i);
if (entry.song.songid == _playid) {
return entry;
}
}
return null;
}
protected static class PlaylistEntry protected static class PlaylistEntry
{ {
public Entry entry; public Entry entry;
@@ -247,6 +294,7 @@ public class PlaylistPanel
protected ArrayList _plist = new ArrayList(); protected ArrayList _plist = new ArrayList();
protected int _playid; protected int _playid;
protected int _oldid = -1;
protected Font _nameFont; protected Font _nameFont;
} }