Added library display variant selection and application.
This commit is contained in:
parent
427c648e33
commit
e8255c5b32
@ -19,7 +19,7 @@
|
|||||||
</properties>
|
</properties>
|
||||||
<border type="none"/>
|
<border type="none"/>
|
||||||
<children>
|
<children>
|
||||||
<scrollpane id="359a1">
|
<scrollpane id="359a1" binding="playlistScroll">
|
||||||
<constraints>
|
<constraints>
|
||||||
<splitpane position="right"/>
|
<splitpane position="right"/>
|
||||||
</constraints>
|
</constraints>
|
||||||
|
@ -26,6 +26,7 @@ public class PlayerGUI implements PlayerCallbackInterface, LibraryCallbackInterf
|
|||||||
private JMenuBar menuBar;
|
private JMenuBar menuBar;
|
||||||
private JComboBox libraryDisplayType;
|
private JComboBox libraryDisplayType;
|
||||||
private JLabel volumeValue;
|
private JLabel volumeValue;
|
||||||
|
private JScrollPane playlistScroll;
|
||||||
private Player player = new Player(this);
|
private Player player = new Player(this);
|
||||||
private PlaylistTableModel playlistTableModel = new PlaylistTableModel(new ArrayList<>());
|
private PlaylistTableModel playlistTableModel = new PlaylistTableModel(new ArrayList<>());
|
||||||
|
|
||||||
@ -48,6 +49,7 @@ public class PlayerGUI implements PlayerCallbackInterface, LibraryCallbackInterf
|
|||||||
libraryView.setCellRenderer(new LibraryTreeCellRenderer());
|
libraryView.setCellRenderer(new LibraryTreeCellRenderer());
|
||||||
playList.setModel(playlistTableModel);
|
playList.setModel(playlistTableModel);
|
||||||
resetTree();
|
resetTree();
|
||||||
|
libraryDisplayVariants.keySet().forEach(libraryDisplayType::addItem);
|
||||||
volumeSlider.setValue(player.getVolume());
|
volumeSlider.setValue(player.getVolume());
|
||||||
setVolumeValue(player.getVolume());
|
setVolumeValue(player.getVolume());
|
||||||
Thread seekBarUpdater = new Thread(() -> {
|
Thread seekBarUpdater = new Thread(() -> {
|
||||||
@ -64,6 +66,10 @@ public class PlayerGUI implements PlayerCallbackInterface, LibraryCallbackInterf
|
|||||||
seekBarUpdater.start();
|
seekBarUpdater.start();
|
||||||
|
|
||||||
//Action Listeners
|
//Action Listeners
|
||||||
|
libraryDisplayType.addItemListener(e ->{
|
||||||
|
if(e.getStateChange() == ItemEvent.SELECTED)
|
||||||
|
libraryDisplayVariants.get(libraryDisplayType.getSelectedItem().toString()).run();
|
||||||
|
});
|
||||||
playButton.addActionListener(e -> {
|
playButton.addActionListener(e -> {
|
||||||
if (playList.getRowCount() > 0) {
|
if (playList.getRowCount() > 0) {
|
||||||
if(playList.getSelectedRowCount() > 0)
|
if(playList.getSelectedRowCount() > 0)
|
||||||
@ -81,6 +87,7 @@ public class PlayerGUI implements PlayerCallbackInterface, LibraryCallbackInterf
|
|||||||
setVolumeValue(player.getVolume());
|
setVolumeValue(player.getVolume());
|
||||||
});
|
});
|
||||||
playList.setComponentPopupMenu(createPlaylistPopup());
|
playList.setComponentPopupMenu(createPlaylistPopup());
|
||||||
|
playlistScroll.setComponentPopupMenu(createPlaylistEmptyAreaPopup());
|
||||||
populateMenuBar();
|
populateMenuBar();
|
||||||
refreshLibrary();
|
refreshLibrary();
|
||||||
}
|
}
|
||||||
@ -105,9 +112,10 @@ public class PlayerGUI implements PlayerCallbackInterface, LibraryCallbackInterf
|
|||||||
* @param libraryData Map of albums with a lists of associated songs.
|
* @param libraryData Map of albums with a lists of associated songs.
|
||||||
*/
|
*/
|
||||||
private void populateLibrary(Map<Album, List<Song>> libraryData) {
|
private void populateLibrary(Map<Album, List<Song>> libraryData) {
|
||||||
|
TreeMap<Album, List<Song>> sortedData = new TreeMap<>(libraryData);
|
||||||
DefaultTreeModel model = new DefaultTreeModel(new DefaultMutableTreeNode());
|
DefaultTreeModel model = new DefaultTreeModel(new DefaultMutableTreeNode());
|
||||||
DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) model.getRoot();
|
DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) model.getRoot();
|
||||||
libraryData.forEach((k, v) -> {
|
sortedData.forEach((k, v) -> {
|
||||||
DefaultMutableTreeNode albumNode = new DefaultMutableTreeNode(k);
|
DefaultMutableTreeNode albumNode = new DefaultMutableTreeNode(k);
|
||||||
addNodeToTreeModel(model, parentNode, albumNode);
|
addNodeToTreeModel(model, parentNode, albumNode);
|
||||||
new TreeSet<>(v).forEach(x -> addNodeToTreeModel(model, albumNode, new DefaultMutableTreeNode(x)));
|
new TreeSet<>(v).forEach(x -> addNodeToTreeModel(model, albumNode, new DefaultMutableTreeNode(x)));
|
||||||
@ -120,6 +128,7 @@ public class PlayerGUI implements PlayerCallbackInterface, LibraryCallbackInterf
|
|||||||
* @param libraryData List of songs.
|
* @param libraryData List of songs.
|
||||||
*/
|
*/
|
||||||
private void populateLibrary(List<Song> libraryData) {
|
private void populateLibrary(List<Song> libraryData) {
|
||||||
|
Collections.sort(libraryData);
|
||||||
DefaultTreeModel model = new DefaultTreeModel(new DefaultMutableTreeNode());
|
DefaultTreeModel model = new DefaultTreeModel(new DefaultMutableTreeNode());
|
||||||
DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) model.getRoot();
|
DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) model.getRoot();
|
||||||
libraryData.forEach(x -> addNodeToTreeModel(model, parentNode, new DefaultMutableTreeNode(x)));
|
libraryData.forEach(x -> addNodeToTreeModel(model, parentNode, new DefaultMutableTreeNode(x)));
|
||||||
@ -195,9 +204,7 @@ public class PlayerGUI implements PlayerCallbackInterface, LibraryCallbackInterf
|
|||||||
addNodeToTreeModel(model, parentNode, newNode);
|
addNodeToTreeModel(model, parentNode, newNode);
|
||||||
libraryView.setModel(model);
|
libraryView.setModel(model);
|
||||||
Thread populateThread = new Thread(() -> {
|
Thread populateThread = new Thread(() -> {
|
||||||
TreeMap treeMap = new TreeMap<>(Gateway.listAllSongsGroupedByAlbum().get());
|
libraryDisplayVariants.get(libraryDisplayType.getSelectedItem().toString()).run();
|
||||||
//SwingUtilities.invokeLater(() -> populateLibrary(treeMap));
|
|
||||||
populateLibrary(treeMap);
|
|
||||||
});
|
});
|
||||||
populateThread.start();
|
populateThread.start();
|
||||||
}
|
}
|
||||||
@ -259,9 +266,19 @@ public class PlayerGUI implements PlayerCallbackInterface, LibraryCallbackInterf
|
|||||||
return popupMenu;
|
return popupMenu;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private JPopupMenu createPlaylistEmptyAreaPopup(){
|
||||||
|
JPopupMenu popupMenu = new JPopupMenu();
|
||||||
|
JMenuItem menuItem = new JMenuItem("Clear all");
|
||||||
|
menuItem.addActionListener((e) -> playlistTableModel.removeAll());
|
||||||
|
|
||||||
|
popupMenu.add(menuItem);
|
||||||
|
return popupMenu;
|
||||||
|
}
|
||||||
|
|
||||||
private Map<String, Runnable> createDisplayVariantMap(){
|
private Map<String, Runnable> createDisplayVariantMap(){
|
||||||
Map<String, Runnable> value = new HashMap<>();
|
Map<String, Runnable> value = new HashMap<>();
|
||||||
value.put("Song", () -> Gateway.listAllSongs().get());
|
value.put("Song", () -> Gateway.listAllSongs().ifPresent(this::populateLibrary));
|
||||||
|
value.put("Album/Song", () -> Gateway.listAllSongsGroupedByAlbum().ifPresent(this::populateLibrary));
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
@ -100,6 +100,11 @@ public class PlaylistTableModel extends AbstractTableModel {
|
|||||||
fireTableDataChanged();
|
fireTableDataChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void removeAll(){
|
||||||
|
songList.clear();
|
||||||
|
fireTableDataChanged();
|
||||||
|
}
|
||||||
|
|
||||||
public Optional<Song> getSong(int index){
|
public Optional<Song> getSong(int index){
|
||||||
return songList.size() > 0 && index >= 0 && index < songList.size() ? Optional.of(songList.get(index)) : Optional.empty();
|
return songList.size() > 0 && index >= 0 && index < songList.size() ? Optional.of(songList.get(index)) : Optional.empty();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user