Added nay votes; any songs with nay votes are not added when the album
containing those songs is added to the playlist. git-svn-id: https://samskivert.googlecode.com/svn/trunk@1491 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -169,6 +169,9 @@ public abstract class EntryController extends ItemController
|
|||||||
plist = new PlaylistEntry[0];
|
plist = new PlaylistEntry[0];
|
||||||
}
|
}
|
||||||
for (int i = 0; i < songs.length; i++) {
|
for (int i = 0; i < songs.length; i++) {
|
||||||
|
if (songs[i].isHated()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
PlaylistEntry entry = new PlaylistEntry(
|
PlaylistEntry entry = new PlaylistEntry(
|
||||||
songs[i].entryid, songs[i].songid, songs[i].title);
|
songs[i].entryid, songs[i].songid, songs[i].title);
|
||||||
plist = (PlaylistEntry[])ArrayUtil.append(plist, entry);
|
plist = (PlaylistEntry[])ArrayUtil.append(plist, entry);
|
||||||
|
|||||||
@@ -32,23 +32,20 @@ public abstract class ItemController extends Controller
|
|||||||
public boolean handleAction (ActionEvent e)
|
public boolean handleAction (ActionEvent e)
|
||||||
{
|
{
|
||||||
String cmd = e.getActionCommand();
|
String cmd = e.getActionCommand();
|
||||||
if (cmd.equals(SongItem.ADD_VOTE)) {
|
if (cmd.equals(SongItem.TOGGLE_VOTE)) {
|
||||||
JButton button = (JButton)e.getSource();
|
JButton button = (JButton)e.getSource();
|
||||||
SongItem item = (SongItem)button.getParent();
|
SongItem item = (SongItem)button.getParent();
|
||||||
_song = item.getSong();
|
_song = item.getSong();
|
||||||
if (_song.addVote(Chooser.frame.getUser(true))) {
|
|
||||||
item.update();
|
|
||||||
TaskMaster.invokeMethodTask("updateSong", this, this);
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if (cmd.equals(SongItem.CLEAR_VOTE)) {
|
String who = Chooser.frame.getUser(true);
|
||||||
JButton button = (JButton)e.getSource();
|
switch (_song.hasVoted(who)) {
|
||||||
SongItem item = (SongItem)button.getParent();
|
case -1: _song.addVote(who, true); break;
|
||||||
_song = item.getSong();
|
case 1: _song.clearVote(who); break;
|
||||||
if (_song.clearVote(Chooser.frame.getUser(true))) {
|
default:
|
||||||
item.update();
|
case 0: _song.addVote(who, false); break;
|
||||||
TaskMaster.invokeMethodTask("updateSong", this, this);
|
|
||||||
}
|
}
|
||||||
|
item.update();
|
||||||
|
TaskMaster.invokeMethodTask("updateSong", this, this);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
Log.warning("Unknown action event: " + cmd);
|
Log.warning("Unknown action event: " + cmd);
|
||||||
|
|||||||
@@ -33,8 +33,7 @@ public class SongItem extends Item
|
|||||||
public static final String PLAY = "song:play";
|
public static final String PLAY = "song:play";
|
||||||
|
|
||||||
// ubiquitous actions
|
// ubiquitous actions
|
||||||
public static final String ADD_VOTE = "song:add_vote";
|
public static final String TOGGLE_VOTE = "song:toggle_vote";
|
||||||
public static final String CLEAR_VOTE = "song:clear_vote";
|
|
||||||
|
|
||||||
/** Used depending on where this song is being displayed. */
|
/** Used depending on where this song is being displayed. */
|
||||||
public Object extra;
|
public Object extra;
|
||||||
@@ -85,7 +84,7 @@ public class SongItem extends Item
|
|||||||
|
|
||||||
// add a vote button
|
// add a vote button
|
||||||
_voteButton = ButtonUtil.createControlButton(
|
_voteButton = ButtonUtil.createControlButton(
|
||||||
ADD_VOTE_TIP, ADD_VOTE, _addVoteIcon, true);
|
TOGGLE_VOTE_TIP, TOGGLE_VOTE, _noVoteIcon, true);
|
||||||
_voteButton.putClientProperty(SONG_PROP, song);
|
_voteButton.putClientProperty(SONG_PROP, song);
|
||||||
add(_voteButton, HGroupLayout.FIXED);
|
add(_voteButton, HGroupLayout.FIXED);
|
||||||
|
|
||||||
@@ -106,22 +105,22 @@ public class SongItem extends Item
|
|||||||
{
|
{
|
||||||
if (!StringUtil.blank(_song.votes)) {
|
if (!StringUtil.blank(_song.votes)) {
|
||||||
_trackLabel.setFont(_hasVotesFont);
|
_trackLabel.setFont(_hasVotesFont);
|
||||||
_trackLabel.setToolTipText("<html>" + _song.title +
|
_trackLabel.setToolTipText(
|
||||||
"<br>Votes: " + _song.votes);
|
"<html><table><tr><td>" + _song.title + "</td></tr>" +
|
||||||
|
"<tr><td>Votes: " + _song.votes + "</td></tr>" +
|
||||||
|
"</table></html>");
|
||||||
} else {
|
} else {
|
||||||
_trackLabel.setFont(_nameFont);
|
_trackLabel.setFont(_nameFont);
|
||||||
_trackLabel.setToolTipText(_song.title);
|
_trackLabel.setToolTipText(_song.title);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_song.hasVoted(Chooser.frame.getUser(false))) {
|
switch (_song.hasVoted(Chooser.frame.getUser(false))) {
|
||||||
_voteButton.setIcon(_clearVoteIcon);
|
case -1: _voteButton.setIcon(_nayVoteIcon); break;
|
||||||
_voteButton.setActionCommand(CLEAR_VOTE);
|
case 1: _voteButton.setIcon(_yeaVoteIcon); break;
|
||||||
_voteButton.setToolTipText(CLEAR_VOTE_TIP);
|
default:
|
||||||
} else {
|
case 0: _voteButton.setIcon(_noVoteIcon); break;
|
||||||
_voteButton.setIcon(_addVoteIcon);
|
|
||||||
_voteButton.setActionCommand(ADD_VOTE);
|
|
||||||
_voteButton.setToolTipText(ADD_VOTE_TIP);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,18 +148,18 @@ public class SongItem extends Item
|
|||||||
protected static final String PLAY_SONG_TIP =
|
protected static final String PLAY_SONG_TIP =
|
||||||
"Append this song to the playlist";
|
"Append this song to the playlist";
|
||||||
|
|
||||||
protected static final String ADD_VOTE_TIP =
|
protected static final String TOGGLE_VOTE_TIP =
|
||||||
"Add your vote for this song";
|
"Toggle your vote for this song";
|
||||||
protected static final String CLEAR_VOTE_TIP =
|
|
||||||
"Remove your vote for this song";
|
|
||||||
|
|
||||||
protected static ImageIcon _skipToIcon =
|
protected static ImageIcon _skipToIcon =
|
||||||
ButtonUtil.getIcon(ICON_ROOT + "skip.png");
|
ButtonUtil.getIcon(ICON_ROOT + "skip.png");
|
||||||
protected static ImageIcon _removeIcon =
|
protected static ImageIcon _removeIcon =
|
||||||
ButtonUtil.getIcon(ICON_ROOT + "remove_song.png");
|
ButtonUtil.getIcon(ICON_ROOT + "remove_song.png");
|
||||||
|
|
||||||
protected static ImageIcon _addVoteIcon =
|
protected static ImageIcon _yeaVoteIcon =
|
||||||
ButtonUtil.getIcon(ICON_ROOT + "add_vote.png");
|
ButtonUtil.getIcon(ICON_ROOT + "yea_vote.png");
|
||||||
protected static ImageIcon _clearVoteIcon =
|
protected static ImageIcon _nayVoteIcon =
|
||||||
ButtonUtil.getIcon(ICON_ROOT + "clear_vote.png");
|
ButtonUtil.getIcon(ICON_ROOT + "nay_vote.png");
|
||||||
|
protected static ImageIcon _noVoteIcon =
|
||||||
|
ButtonUtil.getIcon(ICON_ROOT + "no_vote.png");
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 792 B |
Binary file not shown.
|
Before Width: | Height: | Size: 797 B |
Binary file not shown.
|
After Width: | Height: | Size: 820 B |
Binary file not shown.
|
After Width: | Height: | Size: 336 B |
Binary file not shown.
|
After Width: | Height: | Size: 681 B |
@@ -49,25 +49,36 @@ public class Song
|
|||||||
* Adds a voter to the votes string for this entry, not including a
|
* Adds a voter to the votes string for this entry, not including a
|
||||||
* voter that already exists in the voter set.
|
* voter that already exists in the voter set.
|
||||||
*
|
*
|
||||||
|
* @param yea true if this is a positive vote, false if it is a
|
||||||
|
* negative vote.
|
||||||
|
*
|
||||||
* @return true if the voter set was changed as a result of this
|
* @return true if the voter set was changed as a result of this
|
||||||
* addition, false if not.
|
* addition, false if not.
|
||||||
*/
|
*/
|
||||||
public boolean addVote (String voter)
|
public boolean addVote (String voter, boolean yea)
|
||||||
{
|
{
|
||||||
// handle our first vote separately
|
if (voter.indexOf("-") != -1) {
|
||||||
if (StringUtil.blank(votes)) {
|
throw new IllegalArgumentException("Voter must not contain '-'.");
|
||||||
votes = voter;
|
|
||||||
_votes = null; // clear our cached votes
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// make sure this voter has not already cast their ballot
|
// make sure this voter has not already cast their ballot
|
||||||
if (hasVoted(voter)) {
|
clearVote(voter);
|
||||||
return false;
|
|
||||||
|
// mark the vote as nay if appropriate
|
||||||
|
if (!yea) {
|
||||||
|
voter = "-" + voter;
|
||||||
|
}
|
||||||
|
|
||||||
|
// clear our cached votes
|
||||||
|
_votes = null;
|
||||||
|
|
||||||
|
// handle our first vote separately
|
||||||
|
if (StringUtil.blank(votes)) {
|
||||||
|
votes = voter;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
votes = (votes + "," + voter);
|
votes = (votes + "," + voter);
|
||||||
_votes = null; // clear our cached votes
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,11 +90,13 @@ public class Song
|
|||||||
*/
|
*/
|
||||||
public boolean clearVote (String voter)
|
public boolean clearVote (String voter)
|
||||||
{
|
{
|
||||||
|
String nvoter = "-" + voter;
|
||||||
String[] votes = getVotes();
|
String[] votes = getVotes();
|
||||||
StringBuffer nvotes = new StringBuffer();
|
StringBuffer nvotes = new StringBuffer();
|
||||||
boolean saw = false;
|
boolean saw = false;
|
||||||
for (int ii = 0; ii < votes.length; ii++) {
|
for (int ii = 0; ii < votes.length; ii++) {
|
||||||
if (votes[ii].equalsIgnoreCase(voter)) {
|
if (votes[ii].equalsIgnoreCase(voter) ||
|
||||||
|
votes[ii].equalsIgnoreCase(nvoter)) {
|
||||||
saw = true;
|
saw = true;
|
||||||
} else {
|
} else {
|
||||||
if (nvotes.length() > 0) {
|
if (nvotes.length() > 0) {
|
||||||
@@ -116,19 +129,51 @@ public class Song
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if the specified user has voted.
|
* Returns true if this song has at least one positive vote.
|
||||||
*/
|
*/
|
||||||
public boolean hasVoted (String voter)
|
public boolean isLoved ()
|
||||||
{
|
{
|
||||||
String[] votes = getVotes();
|
String[] votes = getVotes();
|
||||||
for (int ii = 0; ii < votes.length; ii++) {
|
for (int ii = 0; ii < votes.length; ii++) {
|
||||||
if (votes[ii].equalsIgnoreCase(voter)) {
|
if (!votes[ii].startsWith("-")) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if this song has at least one negative vote.
|
||||||
|
*/
|
||||||
|
public boolean isHated ()
|
||||||
|
{
|
||||||
|
String[] votes = getVotes();
|
||||||
|
for (int ii = 0; ii < votes.length; ii++) {
|
||||||
|
if (votes[ii].startsWith("-")) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns +1, -1, or 0 to indicate whether the specified user has
|
||||||
|
* voted positively, negatively or not at all.
|
||||||
|
*/
|
||||||
|
public int hasVoted (String voter)
|
||||||
|
{
|
||||||
|
String nvoter = "-" + voter;
|
||||||
|
String[] votes = getVotes();
|
||||||
|
for (int ii = 0; ii < votes.length; ii++) {
|
||||||
|
if (votes[ii].equals(voter)) {
|
||||||
|
return 1;
|
||||||
|
} else if (votes[ii].equals(nvoter)) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a string representation of this instance.
|
* Returns a string representation of this instance.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user