GUI now uses generated code rather than binary files.
This commit is contained in:
parent
4414e0b51c
commit
69c9e442fb
38
pom.xml
38
pom.xml
@ -23,6 +23,39 @@
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>2.4</version>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifest>
|
||||
<addClasspath>true</addClasspath>
|
||||
<classpathPrefix>lib/</classpathPrefix>
|
||||
<mainClass>musicplayer.PlayerGUI</mainClass>
|
||||
</manifest>
|
||||
</archive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>copy-dependencies</id>
|
||||
<phase>prepare-package</phase>
|
||||
<goals>
|
||||
<goal>copy-dependencies</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<outputDirectory>${project.build.directory}/lib</outputDirectory>
|
||||
<overWriteReleases>false</overWriteReleases>
|
||||
<overWriteSnapshots>false</overWriteSnapshots>
|
||||
<overWriteIfNewer>true</overWriteIfNewer>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
@ -47,6 +80,11 @@
|
||||
<artifactId>gstreamer-java</artifactId>
|
||||
<version>1.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.intellij</groupId>
|
||||
<artifactId>forms_rt</artifactId>
|
||||
<version>7.0.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
|
@ -1,7 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="musicplayer.PlayerGUI">
|
||||
<grid id="27dc6" binding="mainPanel" layout-manager="GridLayoutManager" row-count="4" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<grid id="27dc6" binding="mainPanel" layout-manager="GridBagLayout">
|
||||
<constraints>
|
||||
<xy x="20" y="20" width="537" height="400"/>
|
||||
</constraints>
|
||||
@ -13,6 +12,7 @@
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="760" height="500"/>
|
||||
</grid>
|
||||
<gridbag weightx="1.0" weighty="1.0"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<dividerLocation value="240"/>
|
||||
@ -68,6 +68,7 @@
|
||||
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="-1" height="20"/>
|
||||
</grid>
|
||||
<gridbag weightx="1.0" weighty="0.0"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<floatable value="false"/>
|
||||
@ -126,12 +127,14 @@
|
||||
<component id="e1626" class="javax.swing.JMenuBar" binding="menuBar">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
<gridbag weightx="1.0" weighty="0.0"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<component id="98c55" class="javax.swing.JSlider" binding="seekBar">
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
|
||||
<gridbag weightx="1.0" weighty="0.0"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<inverted value="false"/>
|
||||
|
@ -1,5 +1,7 @@
|
||||
package musicplayer;
|
||||
|
||||
import com.intellij.uiDesigner.core.GridConstraints;
|
||||
import com.intellij.uiDesigner.core.GridLayoutManager;
|
||||
import musicplayer.callbacks.LibraryCallbackInterface;
|
||||
import musicplayer.callbacks.PlayerCallbackInterface;
|
||||
import musicplayer.db.DatabaseManager;
|
||||
@ -11,8 +13,10 @@ import javax.swing.*;
|
||||
import javax.swing.tree.DefaultMutableTreeNode;
|
||||
import javax.swing.tree.DefaultTreeModel;
|
||||
import javax.swing.tree.TreeNode;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
|
||||
public class PlayerGUI implements PlayerCallbackInterface, LibraryCallbackInterface {
|
||||
private JTree libraryView;
|
||||
@ -66,13 +70,13 @@ public class PlayerGUI implements PlayerCallbackInterface, LibraryCallbackInterf
|
||||
seekBarUpdater.start();
|
||||
|
||||
//Action Listeners
|
||||
libraryDisplayType.addItemListener(e ->{
|
||||
if(e.getStateChange() == ItemEvent.SELECTED)
|
||||
libraryDisplayType.addItemListener(e -> {
|
||||
if (e.getStateChange() == ItemEvent.SELECTED)
|
||||
libraryDisplayVariants.get(libraryDisplayType.getSelectedItem().toString()).run();
|
||||
});
|
||||
playButton.addActionListener(e -> {
|
||||
if (playList.getRowCount() > 0) {
|
||||
if(playList.getSelectedRowCount() > 0)
|
||||
if (playList.getSelectedRowCount() > 0)
|
||||
player.playSong(playlistTableModel.getSong(playList.getSelectedRow()));
|
||||
else
|
||||
player.playSong(playlistTableModel.getFirst());
|
||||
@ -82,8 +86,8 @@ public class PlayerGUI implements PlayerCallbackInterface, LibraryCallbackInterf
|
||||
libraryView.addMouseListener(mouseListener);
|
||||
stopButton.addActionListener(e -> player.stop());
|
||||
nextButton.addActionListener(e -> playNextSong());
|
||||
volumeSlider.addChangeListener(e ->{
|
||||
player.setVolume(((JSlider)e.getSource()).getValue());
|
||||
volumeSlider.addChangeListener(e -> {
|
||||
player.setVolume(((JSlider) e.getSource()).getValue());
|
||||
setVolumeValue(player.getVolume());
|
||||
});
|
||||
playList.setComponentPopupMenu(createPlaylistPopup());
|
||||
@ -94,9 +98,10 @@ public class PlayerGUI implements PlayerCallbackInterface, LibraryCallbackInterf
|
||||
|
||||
/**
|
||||
* Set the value of seekBar.
|
||||
*
|
||||
* @param position New seekBar value.
|
||||
*/
|
||||
public void setSeekBarPosition(int position){
|
||||
public void setSeekBarPosition(int position) {
|
||||
SwingUtilities.invokeLater(() -> seekBar.setValue(position));
|
||||
}
|
||||
|
||||
@ -109,6 +114,7 @@ public class PlayerGUI implements PlayerCallbackInterface, LibraryCallbackInterf
|
||||
|
||||
/**
|
||||
* Populate the library with songs grouped by album.
|
||||
*
|
||||
* @param libraryData Map of albums with a lists of associated songs.
|
||||
*/
|
||||
private void populateLibrary(Map<Album, List<Song>> libraryData) {
|
||||
@ -125,6 +131,7 @@ public class PlayerGUI implements PlayerCallbackInterface, LibraryCallbackInterf
|
||||
|
||||
/**
|
||||
* Populate the library with all songs.
|
||||
*
|
||||
* @param libraryData List of songs.
|
||||
*/
|
||||
private void populateLibrary(List<Song> libraryData) {
|
||||
@ -137,8 +144,9 @@ public class PlayerGUI implements PlayerCallbackInterface, LibraryCallbackInterf
|
||||
|
||||
/**
|
||||
* Add an item to libraryView.
|
||||
*
|
||||
* @param parentNode Node that should be the parent of this node.
|
||||
* @param node This node.
|
||||
* @param node This node.
|
||||
*/
|
||||
private void addNodeToTreeModel(DefaultTreeModel model, DefaultMutableTreeNode parentNode, DefaultMutableTreeNode node) {
|
||||
model.insertNodeInto(node, parentNode, parentNode.getChildCount());
|
||||
@ -149,15 +157,17 @@ public class PlayerGUI implements PlayerCallbackInterface, LibraryCallbackInterf
|
||||
|
||||
/**
|
||||
* Add a song to the current playlist.
|
||||
*
|
||||
* @param song Song to be added to the playlist.
|
||||
*/
|
||||
private void addToPlaylist(Song song){
|
||||
private void addToPlaylist(Song song) {
|
||||
playlistTableModel.addSong(song);
|
||||
playList.revalidate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the next song in the playlist.
|
||||
*
|
||||
* @param currentSong The song that is currently selected.
|
||||
* @return The next song to be selected.
|
||||
*/
|
||||
@ -168,6 +178,7 @@ public class PlayerGUI implements PlayerCallbackInterface, LibraryCallbackInterf
|
||||
|
||||
/**
|
||||
* Set the highlighted song in the playlist to this song.
|
||||
*
|
||||
* @param playingSong Song to be highlighted in the playlist.
|
||||
*/
|
||||
@Override
|
||||
@ -179,16 +190,17 @@ public class PlayerGUI implements PlayerCallbackInterface, LibraryCallbackInterf
|
||||
/**
|
||||
* Get the next song in the playlist and dispatch it to the Player to be played.
|
||||
*/
|
||||
public void playNextSong(){
|
||||
public void playNextSong() {
|
||||
SwingUtilities.invokeLater(() -> seekBar.setValue(0));
|
||||
player.playSong(getNextSong(player.getCurrentSong()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the maximum value of the seekBar.
|
||||
*
|
||||
* @param seconds New length of seekBar.
|
||||
*/
|
||||
public void setSeekBarDuration(int seconds){
|
||||
public void setSeekBarDuration(int seconds) {
|
||||
SwingUtilities.invokeLater(() -> seekBar.setMaximum(seconds));
|
||||
}
|
||||
|
||||
@ -197,7 +209,7 @@ public class PlayerGUI implements PlayerCallbackInterface, LibraryCallbackInterf
|
||||
playlistTableModel.removeSong(invalidSong);
|
||||
}
|
||||
|
||||
public void refreshLibrary(){
|
||||
public void refreshLibrary() {
|
||||
DefaultTreeModel model = new DefaultTreeModel(new DefaultMutableTreeNode());
|
||||
DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) model.getRoot();
|
||||
DefaultMutableTreeNode newNode = new DefaultMutableTreeNode("Refreshing Library...");
|
||||
@ -211,10 +223,120 @@ public class PlayerGUI implements PlayerCallbackInterface, LibraryCallbackInterf
|
||||
|
||||
@Override
|
||||
public void libraryUpdated(boolean successful) {
|
||||
if(successful)
|
||||
if (successful)
|
||||
populateLibrary(new TreeMap<>(Gateway.listAllSongsGroupedByAlbum().get()));
|
||||
}
|
||||
|
||||
{
|
||||
// GUI initializer generated by IntelliJ IDEA GUI Designer
|
||||
// >>> IMPORTANT!! <<<
|
||||
// DO NOT EDIT OR ADD ANY CODE HERE!
|
||||
$$$setupUI$$$();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method generated by IntelliJ IDEA GUI Designer
|
||||
* >>> IMPORTANT!! <<<
|
||||
* DO NOT edit this method OR call it in your code!
|
||||
*
|
||||
* @noinspection ALL
|
||||
*/
|
||||
private void $$$setupUI$$$() {
|
||||
mainPanel = new JPanel();
|
||||
mainPanel.setLayout(new GridBagLayout());
|
||||
final JSplitPane splitPane1 = new JSplitPane();
|
||||
splitPane1.setDividerLocation(240);
|
||||
GridBagConstraints gbc;
|
||||
gbc = new GridBagConstraints();
|
||||
gbc.gridx = 0;
|
||||
gbc.gridy = 1;
|
||||
gbc.weightx = 1.0;
|
||||
gbc.weighty = 1.0;
|
||||
gbc.fill = GridBagConstraints.BOTH;
|
||||
mainPanel.add(splitPane1, gbc);
|
||||
playlistScroll = new JScrollPane();
|
||||
splitPane1.setRightComponent(playlistScroll);
|
||||
playList = new JTable();
|
||||
playList.setRowSelectionAllowed(true);
|
||||
playlistScroll.setViewportView(playList);
|
||||
final JPanel panel1 = new JPanel();
|
||||
panel1.setLayout(new BorderLayout(0, 0));
|
||||
splitPane1.setLeftComponent(panel1);
|
||||
libraryDisplayType = new JComboBox();
|
||||
panel1.add(libraryDisplayType, BorderLayout.NORTH);
|
||||
final JScrollPane scrollPane1 = new JScrollPane();
|
||||
panel1.add(scrollPane1, BorderLayout.CENTER);
|
||||
libraryView = new JTree();
|
||||
libraryView.setRootVisible(true);
|
||||
libraryView.setShowsRootHandles(false);
|
||||
scrollPane1.setViewportView(libraryView);
|
||||
final JToolBar toolBar1 = new JToolBar();
|
||||
toolBar1.setFloatable(false);
|
||||
gbc = new GridBagConstraints();
|
||||
gbc.gridx = 0;
|
||||
gbc.gridy = 3;
|
||||
gbc.weightx = 1.0;
|
||||
gbc.fill = GridBagConstraints.HORIZONTAL;
|
||||
mainPanel.add(toolBar1, gbc);
|
||||
playButton = new JButton();
|
||||
playButton.setLabel("Play");
|
||||
playButton.setText("Play");
|
||||
playButton.setMnemonic('P');
|
||||
playButton.setDisplayedMnemonicIndex(0);
|
||||
toolBar1.add(playButton);
|
||||
stopButton = new JButton();
|
||||
stopButton.setLabel("Stop");
|
||||
stopButton.setText("Stop");
|
||||
stopButton.setMnemonic('S');
|
||||
stopButton.setDisplayedMnemonicIndex(0);
|
||||
toolBar1.add(stopButton);
|
||||
nextButton = new JButton();
|
||||
nextButton.setText("Next");
|
||||
nextButton.setMnemonic('N');
|
||||
nextButton.setDisplayedMnemonicIndex(0);
|
||||
toolBar1.add(nextButton);
|
||||
final JPanel panel2 = new JPanel();
|
||||
panel2.setLayout(new GridLayoutManager(1, 2, new Insets(0, 0, 0, 0), -1, -1));
|
||||
toolBar1.add(panel2);
|
||||
volumeSlider = new JSlider();
|
||||
volumeSlider.setMajorTickSpacing(20);
|
||||
volumeSlider.setMinorTickSpacing(10);
|
||||
volumeSlider.setPaintTicks(true);
|
||||
volumeSlider.setValue(100);
|
||||
panel2.add(volumeSlider, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_EAST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
|
||||
volumeValue = new JLabel();
|
||||
volumeValue.setText("100%");
|
||||
panel2.add(volumeValue, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
|
||||
menuBar = new JMenuBar();
|
||||
gbc = new GridBagConstraints();
|
||||
gbc.gridx = 0;
|
||||
gbc.gridy = 0;
|
||||
gbc.weightx = 1.0;
|
||||
gbc.fill = GridBagConstraints.BOTH;
|
||||
mainPanel.add(menuBar, gbc);
|
||||
seekBar = new JSlider();
|
||||
seekBar.setInverted(false);
|
||||
seekBar.setMinorTickSpacing(1);
|
||||
seekBar.setPaintTicks(false);
|
||||
seekBar.setSnapToTicks(false);
|
||||
seekBar.setValue(0);
|
||||
seekBar.setValueIsAdjusting(false);
|
||||
gbc = new GridBagConstraints();
|
||||
gbc.gridx = 0;
|
||||
gbc.gridy = 2;
|
||||
gbc.weightx = 1.0;
|
||||
gbc.anchor = GridBagConstraints.WEST;
|
||||
gbc.fill = GridBagConstraints.HORIZONTAL;
|
||||
mainPanel.add(seekBar, gbc);
|
||||
}
|
||||
|
||||
/**
|
||||
* @noinspection ALL
|
||||
*/
|
||||
public JComponent $$$getRootComponent$$$() {
|
||||
return mainPanel;
|
||||
}
|
||||
|
||||
private class libraryMouseAdapter extends MouseAdapter {
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e) {
|
||||
@ -232,14 +354,15 @@ public class PlayerGUI implements PlayerCallbackInterface, LibraryCallbackInterf
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (NullPointerException ignored) {}
|
||||
} catch (NullPointerException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Populate the top menu bar with items.
|
||||
*/
|
||||
private void populateMenuBar(){
|
||||
private void populateMenuBar() {
|
||||
|
||||
// Tools menu
|
||||
JMenu tools = new JMenu("Tools");
|
||||
@ -257,7 +380,7 @@ public class PlayerGUI implements PlayerCallbackInterface, LibraryCallbackInterf
|
||||
|
||||
}
|
||||
|
||||
private JPopupMenu createPlaylistPopup(){
|
||||
private JPopupMenu createPlaylistPopup() {
|
||||
JPopupMenu popupMenu = new JPopupMenu();
|
||||
JMenuItem menuItem = new JMenuItem("Remove");
|
||||
menuItem.addActionListener((e) -> playlistTableModel.removeSong(playList.getSelectedRows()));
|
||||
@ -266,7 +389,7 @@ public class PlayerGUI implements PlayerCallbackInterface, LibraryCallbackInterf
|
||||
return popupMenu;
|
||||
}
|
||||
|
||||
private JPopupMenu createPlaylistEmptyAreaPopup(){
|
||||
private JPopupMenu createPlaylistEmptyAreaPopup() {
|
||||
JPopupMenu popupMenu = new JPopupMenu();
|
||||
JMenuItem menuItem = new JMenuItem("Clear all");
|
||||
menuItem.addActionListener((e) -> playlistTableModel.removeAll());
|
||||
@ -275,7 +398,7 @@ public class PlayerGUI implements PlayerCallbackInterface, LibraryCallbackInterf
|
||||
return popupMenu;
|
||||
}
|
||||
|
||||
private Map<String, Runnable> createDisplayVariantMap(){
|
||||
private Map<String, Runnable> createDisplayVariantMap() {
|
||||
Map<String, Runnable> value = new HashMap<>();
|
||||
value.put("Song", () -> Gateway.listAllSongs().ifPresent(this::populateLibrary));
|
||||
value.put("Album/Song", () -> Gateway.listAllSongsGroupedByAlbum().ifPresent(this::populateLibrary));
|
||||
@ -283,8 +406,9 @@ public class PlayerGUI implements PlayerCallbackInterface, LibraryCallbackInterf
|
||||
return value;
|
||||
}
|
||||
|
||||
private void setVolumeValue(int value){
|
||||
private void setVolumeValue(int value) {
|
||||
volumeValue.setText(String.format("%d%%", value));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user