diff --git a/pom.xml b/pom.xml
index af4785a..b061566 100644
--- a/pom.xml
+++ b/pom.xml
@@ -80,11 +80,6 @@
gstreamer-java
1.5
-
- com.intellij
- forms_rt
- 7.0.3
-
junit
junit
diff --git a/src/main/java/musicplayer/PlayerGUI.form b/src/main/java/musicplayer/PlayerGUI.form
deleted file mode 100644
index febef88..0000000
--- a/src/main/java/musicplayer/PlayerGUI.form
+++ /dev/null
@@ -1,150 +0,0 @@
-
-
diff --git a/src/main/java/musicplayer/PlayerGUI.java b/src/main/java/musicplayer/PlayerGUI.java
index c56c0bc..2f39c03 100644
--- a/src/main/java/musicplayer/PlayerGUI.java
+++ b/src/main/java/musicplayer/PlayerGUI.java
@@ -1,7 +1,5 @@
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;
@@ -14,48 +12,28 @@ import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreeNode;
import java.awt.*;
-import java.awt.event.*;
+import java.awt.event.ItemEvent;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
import java.util.*;
import java.util.List;
public class PlayerGUI implements PlayerCallbackInterface, LibraryCallbackInterface {
+ public JPanel mainPanel;
private JTree libraryView;
- private JTable playList;
- private JPanel mainPanel;
- private JButton playButton;
- private JButton stopButton;
- private JButton nextButton;
+ private JTable playList = new JTable();
private JSlider seekBar;
- private JSlider volumeSlider;
- private JMenuBar menuBar;
- private JComboBox libraryDisplayType;
- private JLabel volumeValue;
- private JScrollPane playlistScroll;
+ private JComboBox libraryDisplayType = new JComboBox();
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();
- frame.setContentPane(new PlayerGUI().mainPanel);
- frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
- frame.pack();
- frame.setVisible(true);
- }
-
-
public PlayerGUI() {
+ createUI();
DatabaseManager.init();
- libraryView.setRootVisible(false);
- libraryView.setToggleClickCount(1);
- libraryView.setCellRenderer(new LibraryTreeCellRenderer());
- playList.setModel(playlistTableModel);
resetTree();
libraryDisplayVariants.keySet().forEach(libraryDisplayType::addItem);
- volumeSlider.setValue(player.getVolume());
- setVolumeValue(player.getVolume());
Thread seekBarUpdater = new Thread(() -> {
boolean running = true;
while (running) {
@@ -68,34 +46,19 @@ public class PlayerGUI implements PlayerCallbackInterface, LibraryCallbackInterf
}
});
seekBarUpdater.start();
-
- //Action Listeners
- 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)
- player.playSong(playlistTableModel.getSong(playList.getSelectedRow()));
- else
- player.playSong(playlistTableModel.getFirst());
- }
- });
- MouseListener mouseListener = new libraryMouseAdapter();
- libraryView.addMouseListener(mouseListener);
- stopButton.addActionListener(e -> player.stop());
- nextButton.addActionListener(e -> playNextSong());
- volumeSlider.addChangeListener(e -> {
- player.setVolume(((JSlider) e.getSource()).getValue());
- setVolumeValue(player.getVolume());
- });
- playList.setComponentPopupMenu(createPlaylistPopup());
- playlistScroll.setComponentPopupMenu(createPlaylistEmptyAreaPopup());
- populateMenuBar();
+ createMenuBar();
refreshLibrary();
}
+ public static void main(String[] args) {
+ PlayerGUI playerGUI = new PlayerGUI();
+ JFrame frame = new JFrame();
+ frame.setContentPane(playerGUI.mainPanel);
+ frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
+ frame.pack();
+ frame.setVisible(true);
+ }
+
/**
* Set the value of seekBar.
*
@@ -224,120 +187,159 @@ public class PlayerGUI implements PlayerCallbackInterface, LibraryCallbackInterf
@Override
public void libraryUpdated(boolean successful) {
if (successful)
- populateLibrary(new TreeMap<>(Gateway.listAllSongsGroupedByAlbum().get()));
+ libraryDisplayVariants.get(libraryDisplayType.getSelectedItem().toString()).run();
}
- {
-// GUI initializer generated by IntelliJ IDEA GUI Designer
-// >>> IMPORTANT!! <<<
-// DO NOT EDIT OR ADD ANY CODE HERE!
- $$$setupUI$$$();
+ private Map createDisplayVariantMap() {
+ Map value = new HashMap<>();
+ value.put("Song", () -> Gateway.listAllSongs().ifPresent(this::populateLibrary));
+ value.put("Album/Song", () -> Gateway.listAllSongsGroupedByAlbum().ifPresent(this::populateLibrary));
+
+ return value;
}
- /**
- * Method generated by IntelliJ IDEA GUI Designer
- * >>> IMPORTANT!! <<<
- * DO NOT edit this method OR call it in your code!
- *
- * @noinspection ALL
+ /*
+ mainPanel
+ +--------------------+
+ |menuBar |
+ +---------+----------+
+ |comboBox |playlist |
+ +---------+ |
+ |library | |
+ | | |
+ +---------+----------+
+ |controlPane |
+ +--------------------+
*/
- private void $$$setupUI$$$() {
+ private void createUI() {
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);
+ mainPanel.setLayout(new BorderLayout(0, 0));
+ final JSplitPane libraryAndPlaylistPane = new JSplitPane();
+ libraryAndPlaylistPane.setDividerLocation(240);
+ libraryAndPlaylistPane.setRightComponent(createPlaylistArea());
+ mainPanel.add(libraryAndPlaylistPane, BorderLayout.CENTER);
+ final JPanel libraryAndComboboxPane = new JPanel();
+ libraryAndComboboxPane.setLayout(new BorderLayout(0, 0));
+ libraryAndPlaylistPane.setLeftComponent(libraryAndComboboxPane);
+ libraryDisplayType.addItemListener(e -> {
+ if (e.getStateChange() == ItemEvent.SELECTED)
+ libraryDisplayVariants.get(libraryDisplayType.getSelectedItem().toString()).run();
+ });
+ libraryAndComboboxPane.add(libraryDisplayType, BorderLayout.NORTH);
+ final JScrollPane libraryPane = new JScrollPane();
+ libraryAndComboboxPane.add(libraryPane, BorderLayout.CENTER);
+ libraryPane.setViewportView(createLibraryArea());
+ final JPanel controlPane = new JPanel();
+ controlPane.setLayout(new BorderLayout(0, 0));
+ mainPanel.add(controlPane, BorderLayout.SOUTH);
+ seekBar = new JSlider();
+ seekBar.setMinorTickSpacing(1);
+ seekBar.setValue(0);
+ controlPane.add(seekBar, BorderLayout.NORTH);
+ controlPane.add(createControlButtons(), BorderLayout.SOUTH);
+ mainPanel.add(createMenuBar(), BorderLayout.NORTH);
+ }
+
+ private JTree createLibraryArea() {
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");
+ libraryView.setRootVisible(false);
+ libraryView.setToggleClickCount(1);
+ libraryView.setCellRenderer(new LibraryTreeCellRenderer());
+ libraryView.addMouseListener(new LibraryMouseAdapter());
+ return libraryView;
+ }
+
+ private JScrollPane createPlaylistArea() {
+ JScrollPane playlistScroll = new JScrollPane();
+ playList.setRowSelectionAllowed(true);
+ playList.setModel(playlistTableModel);
+ JPopupMenu popupMenu = new JPopupMenu();
+ JMenuItem menuItem = new JMenuItem("Remove");
+ menuItem.addActionListener((e) -> playlistTableModel.removeSong(playList.getSelectedRows()));
+ popupMenu.add(menuItem);
+ playList.setComponentPopupMenu(popupMenu);
+ popupMenu = new JPopupMenu();
+ menuItem = new JMenuItem("Clear all");
+ menuItem.addActionListener((e) -> playlistTableModel.removeAll());
+ popupMenu.add(menuItem);
+ playlistScroll.setComponentPopupMenu(popupMenu);
+ playlistScroll.setViewportView(playList);
+ return playlistScroll;
+ }
+
+ private JToolBar createControlButtons() {
+ JToolBar toolBar = new JToolBar();
+ toolBar.setFloatable(false);
+ JButton playButton = new JButton();
playButton.setText("Play");
playButton.setMnemonic('P');
playButton.setDisplayedMnemonicIndex(0);
- toolBar1.add(playButton);
- stopButton = new JButton();
- stopButton.setLabel("Stop");
+ playButton.addActionListener(e -> {
+ if (playList.getRowCount() > 0) {
+ if (playList.getSelectedRowCount() > 0)
+ player.playSong(playlistTableModel.getSong(playList.getSelectedRow()));
+ else
+ player.playSong(playlistTableModel.getFirst());
+ }
+ });
+ toolBar.add(playButton);
+ JButton stopButton = new JButton();
stopButton.setText("Stop");
stopButton.setMnemonic('S');
stopButton.setDisplayedMnemonicIndex(0);
- toolBar1.add(stopButton);
- nextButton = new JButton();
+ stopButton.addActionListener(e -> player.stop());
+ toolBar.add(stopButton);
+ JButton 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();
+ nextButton.addActionListener(e -> playNextSong());
+ toolBar.add(nextButton);
+ toolBar.add(createVolumeControls());
+ return toolBar;
+ }
+
+ private JPanel createVolumeControls() {
+ JPanel panel = new JPanel();
+ panel.setLayout(new FlowLayout());
+ JSlider 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);
+ volumeSlider.setValue(player.getVolume());
+ panel.add(volumeSlider);
+ JLabel volumeValue = new JLabel();
+ volumeValue.setText(String.format("%d%%", player.getVolume()));
+ volumeSlider.addChangeListener(e -> {
+ player.setVolume(((JSlider) e.getSource()).getValue());
+ volumeValue.setText(String.format("%d%%", player.getVolume()));
+ });
+ panel.add(volumeValue);
+ return panel;
}
/**
- * @noinspection ALL
+ * Populate the top menu bar with items.
*/
- public JComponent $$$getRootComponent$$$() {
- return mainPanel;
+ private JMenuBar createMenuBar() {
+ JMenuBar menuBar = new JMenuBar();
+ // Tools menu
+ JMenu tools = new JMenu("Tools");
+ JMenuItem menuItem = new JMenuItem("Refresh Library");
+ menuItem.addActionListener(e -> refreshLibrary());
+ tools.add(menuItem);
+
+ menuItem = new JMenuItem("Update Library");
+ menuItem.setToolTipText("Reindex and refresh library.");
+
+ tools.add(menuItem);
+
+ // Add everything to the menu bar itself
+ menuBar.add(tools);
+ return menuBar;
}
- private class libraryMouseAdapter extends MouseAdapter {
+ private class LibraryMouseAdapter extends MouseAdapter {
@Override
public void mousePressed(MouseEvent e) {
int selRow = libraryView.getRowForLocation(e.getX(), e.getY());
@@ -358,57 +360,4 @@ public class PlayerGUI implements PlayerCallbackInterface, LibraryCallbackInterf
}
}
}
-
- /**
- * Populate the top menu bar with items.
- */
- private void populateMenuBar() {
-
- // Tools menu
- JMenu tools = new JMenu("Tools");
- JMenuItem menuItem = new JMenuItem("Refresh Library");
- menuItem.addActionListener(e -> refreshLibrary());
- tools.add(menuItem);
-
- menuItem = new JMenuItem("Update Library");
- menuItem.setToolTipText("Reindex and refresh library.");
-
- tools.add(menuItem);
-
- // Add everything to the menu bar itself
- 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 JPopupMenu createPlaylistEmptyAreaPopup() {
- JPopupMenu popupMenu = new JPopupMenu();
- JMenuItem menuItem = new JMenuItem("Clear all");
- menuItem.addActionListener((e) -> playlistTableModel.removeAll());
-
- popupMenu.add(menuItem);
- return popupMenu;
- }
-
- private Map createDisplayVariantMap() {
- Map value = new HashMap<>();
- value.put("Song", () -> Gateway.listAllSongs().ifPresent(this::populateLibrary));
- value.put("Album/Song", () -> Gateway.listAllSongsGroupedByAlbum().ifPresent(this::populateLibrary));
-
- return value;
- }
-
- private void setVolumeValue(int value) {
- volumeValue.setText(String.format("%d%%", value));
- }
-
-
}