From b0c1dd10bc88cdcab08b300711223b92f0bd5f6a Mon Sep 17 00:00:00 2001 From: Nathan Cannon Date: Fri, 11 Mar 2016 16:41:57 +0000 Subject: [PATCH] playingRow now reacts to changes in playlist. Fixed song highlighting not working when stopping playback. --- src/main/java/musicplayer/PlayerGUI.java | 8 ++++++-- .../java/musicplayer/swingmodels/PlaylistTableModel.java | 4 ++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/java/musicplayer/PlayerGUI.java b/src/main/java/musicplayer/PlayerGUI.java index 41fc35d..f038616 100644 --- a/src/main/java/musicplayer/PlayerGUI.java +++ b/src/main/java/musicplayer/PlayerGUI.java @@ -158,7 +158,8 @@ public class PlayerGUI implements PlayerCallbackInterface, LibraryCallbackInterf @Override public void setSongHighlighting(Song playingSong) { int index = playlistTableModel.getSongIndex(playingSong); - SwingUtilities.invokeLater(() -> playList.setRowSelectionInterval(index, index)); + if(index >= 0) + SwingUtilities.invokeLater(() -> playList.setRowSelectionInterval(index, index)); playlistTableModel.setPlayingRow(index); } @@ -201,7 +202,10 @@ public class PlayerGUI implements PlayerCallbackInterface, LibraryCallbackInterf playlistTableModel.removeSong(invalidSong); } - public void playerStopped(){ playlistTableModel.setPlayingRow(-1); } + public void playerStopped(){ + setSongHighlighting(player.getCurrentSong()); + playlistTableModel.setPlayingRow(-1); + } /** * Refresh the library with songs in the currently selected display format. diff --git a/src/main/java/musicplayer/swingmodels/PlaylistTableModel.java b/src/main/java/musicplayer/swingmodels/PlaylistTableModel.java index 1d28f19..dd7867c 100644 --- a/src/main/java/musicplayer/swingmodels/PlaylistTableModel.java +++ b/src/main/java/musicplayer/swingmodels/PlaylistTableModel.java @@ -114,6 +114,10 @@ public class PlaylistTableModel extends AbstractTableModel { if(songList.size() > index && index >= 0){ songList.remove(index); fireTableRowsDeleted(index, index); + if(index < playingRow) + playingRow--; + else if(playingRow == index) + playingRow = -1; } }