diff --git a/src/main/java/musicplayer/PlayerGUI.form b/src/main/java/musicplayer/PlayerGUI.form
index 693a682..04c97ea 100644
--- a/src/main/java/musicplayer/PlayerGUI.form
+++ b/src/main/java/musicplayer/PlayerGUI.form
@@ -15,26 +15,10 @@
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -50,6 +34,33 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/main/java/musicplayer/PlayerGUI.java b/src/main/java/musicplayer/PlayerGUI.java
index 8e7b335..e9f0909 100644
--- a/src/main/java/musicplayer/PlayerGUI.java
+++ b/src/main/java/musicplayer/PlayerGUI.java
@@ -22,9 +22,12 @@ public class PlayerGUI implements PlayerCallbackInterface, LibraryCallbackInterf
private JSlider seekBar;
private JSlider volumeSlider;
private JMenuBar menuBar;
+ private JComboBox libraryDisplayType;
private Player player = new Player(this);
private PlaylistTableModel playlistTableModel = new PlaylistTableModel(new ArrayList<>());
+ private Map libraryDisplayVariants = createDisplayVariantMap();
+
public static void main(String[] args) {
JFrame frame = new JFrame();
@@ -58,7 +61,7 @@ public class PlayerGUI implements PlayerCallbackInterface, LibraryCallbackInterf
//Action Listeners
playButton.addActionListener(e -> {
- if (playList.getSelectedColumn() == -1) {
+ if (playList.getRowCount() > 0) {
player.playSong(playlistTableModel.getFirst().get());
}
});
@@ -67,8 +70,9 @@ public class PlayerGUI implements PlayerCallbackInterface, LibraryCallbackInterf
stopButton.addActionListener(e -> player.stop());
nextButton.addActionListener(e -> playNextSong());
volumeSlider.addChangeListener(e -> player.setVolume(((JSlider)e.getSource()).getValue()));
-
+ playList.setComponentPopupMenu(createPlaylistPopup());
populateMenuBar();
+ refreshLibrary();
}
/**
@@ -230,4 +234,20 @@ public class PlayerGUI implements PlayerCallbackInterface, LibraryCallbackInterf
menuBar.add(tools);
}
+
+ private JPopupMenu createPlaylistPopup(){
+ JPopupMenu popupMenu = new JPopupMenu();
+ JMenuItem menuItem = new JMenuItem("Remove");
+ menuItem.addActionListener((e) -> playlistTableModel.removeSong(playList.getSelectedRows()));
+
+ popupMenu.add(menuItem);
+ return popupMenu;
+ }
+
+ private Map createDisplayVariantMap(){
+ Map value = new HashMap<>();
+ value.put("Song", () -> Gateway.listAllSongs().get());
+
+ return value;
+ }
}
diff --git a/src/main/java/musicplayer/PlaylistTableModel.java b/src/main/java/musicplayer/PlaylistTableModel.java
index 561a9c9..806e2fe 100644
--- a/src/main/java/musicplayer/PlaylistTableModel.java
+++ b/src/main/java/musicplayer/PlaylistTableModel.java
@@ -3,8 +3,11 @@ package musicplayer;
import musicplayer.model.Song;
import javax.swing.table.AbstractTableModel;
+import java.util.Collections;
import java.util.List;
import java.util.Optional;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
public class PlaylistTableModel extends AbstractTableModel {
@@ -78,4 +81,17 @@ public class PlaylistTableModel extends AbstractTableModel {
public int getSongIndex(Song song){
return songList.indexOf(song);
}
+
+ public void removeSong(int index){
+ if(songList.size() > index && index >= 0){
+ songList.remove(index);
+ fireTableRowsDeleted(index, index);
+ }
+ }
+
+ public void removeSong(int[] index){
+ List indices = IntStream.of(index).boxed().collect(Collectors.toList());
+ Collections.reverse(indices);
+ indices.forEach(this::removeSong);
+ }
}