Fixed playlist row selection behaviour on playback stop.
This commit is contained in:
parent
e1507efe44
commit
8619678023
@ -125,7 +125,7 @@ public class GStreamerPlayer implements IPlayer{
|
|||||||
internalThread.stop();
|
internalThread.stop();
|
||||||
thread = null;
|
thread = null;
|
||||||
resetSeek();
|
resetSeek();
|
||||||
playlist.setPlayingSong(currentSong);
|
playlist.setStopped();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,5 +20,6 @@ public interface IPlaylist {
|
|||||||
void deleteAll();
|
void deleteAll();
|
||||||
boolean isEmpty();
|
boolean isEmpty();
|
||||||
void setPlayingSong(Song song);
|
void setPlayingSong(Song song);
|
||||||
|
void setStopped();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,10 +4,7 @@ import musicplayer.model.Song;
|
|||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import javax.swing.table.AbstractTableModel;
|
import javax.swing.table.AbstractTableModel;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.IntStream;
|
import java.util.stream.IntStream;
|
||||||
|
|
||||||
@ -117,10 +114,21 @@ public class JTablePlaylist extends JScrollPane implements IPlaylist {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setPlayingSong(Song song){
|
public void setPlayingSong(Song song){
|
||||||
int index = playlistTableModel.getSongIndex(song);
|
final int index = getIndex(song);
|
||||||
|
playlistTableModel.setPlayingRow(index);
|
||||||
if(index >= 0)
|
if(index >= 0)
|
||||||
SwingUtilities.invokeLater(() -> playList.setRowSelectionInterval(index, index));
|
SwingUtilities.invokeLater(() -> playList.setRowSelectionInterval(index, index));
|
||||||
playlistTableModel.setPlayingRow(index);
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setStopped(){
|
||||||
|
if(getActive().isPresent()) {
|
||||||
|
int index = getIndex(getActive().get());
|
||||||
|
playlistTableModel.setPlayingRow(-1);
|
||||||
|
SwingUtilities.invokeLater(() -> playList.setRowSelectionInterval(index, index));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
playlistTableModel.setPlayingRow(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class PlaylistTableModel extends AbstractTableModel {
|
private class PlaylistTableModel extends AbstractTableModel {
|
||||||
|
@ -6,15 +6,23 @@ import musicplayer.model.Song;
|
|||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
public class JTablePlaylistTest {
|
public class JTablePlaylistTest {
|
||||||
|
|
||||||
JTablePlaylist playlist;
|
JTablePlaylist playlist;
|
||||||
|
JTable innerTable;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
playlist = new JTablePlaylist();
|
playlist = new JTablePlaylist();
|
||||||
|
Field jTable = JTablePlaylist.class.getDeclaredField("playList");
|
||||||
|
jTable.setAccessible(true);
|
||||||
|
innerTable = (JTable)jTable.get(playlist);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -109,6 +117,8 @@ public class JTablePlaylistTest {
|
|||||||
playlist.addSong(testSong);
|
playlist.addSong(testSong);
|
||||||
playlist.setPlayingSong(testSong);
|
playlist.setPlayingSong(testSong);
|
||||||
assertEquals(testSong, playlist.getActive().get());
|
assertEquals(testSong, playlist.getActive().get());
|
||||||
|
Thread.sleep(10); // Wait for Swing thread update propagation
|
||||||
|
assertEquals(playlist.getIndex(testSong), innerTable.getSelectedRow());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -116,6 +126,17 @@ public class JTablePlaylistTest {
|
|||||||
Song testSong = new Song("1", "1", "test 1", new Artist("test artist"), new Album("test album"), "test genre", "");
|
Song testSong = new Song("1", "1", "test 1", new Artist("test artist"), new Album("test album"), "test genre", "");
|
||||||
playlist.setPlayingSong(testSong);
|
playlist.setPlayingSong(testSong);
|
||||||
assertFalse(playlist.getActive().isPresent());
|
assertFalse(playlist.getActive().isPresent());
|
||||||
|
assertEquals(-1, innerTable.getSelectedRow());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSetStopped() throws Exception {
|
||||||
|
Song testSong = new Song("1", "1", "test 1", new Artist("test artist"), new Album("test album"), "test genre", "");
|
||||||
|
playlist.addSong(testSong);
|
||||||
|
playlist.setPlayingSong(testSong);
|
||||||
|
playlist.setStopped();
|
||||||
|
assertEquals(testSong, playlist.getActive().get());
|
||||||
|
assertEquals(playlist.getIndex(testSong), innerTable.getSelectedRow());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Loading…
Reference in New Issue
Block a user