From 69c9e442fb1b6ce18d2629d1a6b598e50f897673 Mon Sep 17 00:00:00 2001 From: Nathan Cannon Date: Wed, 24 Feb 2016 20:06:30 +0000 Subject: [PATCH] GUI now uses generated code rather than binary files. --- pom.xml | 38 ++++++ src/main/java/musicplayer/PlayerGUI.form | 7 +- src/main/java/musicplayer/PlayerGUI.java | 160 ++++++++++++++++++++--- 3 files changed, 185 insertions(+), 20 deletions(-) diff --git a/pom.xml b/pom.xml index 6cb3ac9..af4785a 100644 --- a/pom.xml +++ b/pom.xml @@ -23,6 +23,39 @@ 1.8 + + org.apache.maven.plugins + maven-jar-plugin + 2.4 + + + + true + lib/ + musicplayer.PlayerGUI + + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + copy-dependencies + prepare-package + + copy-dependencies + + + ${project.build.directory}/lib + false + false + true + + + + @@ -47,6 +80,11 @@ 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 index e2d11ee..febef88 100644 --- a/src/main/java/musicplayer/PlayerGUI.form +++ b/src/main/java/musicplayer/PlayerGUI.form @@ -1,7 +1,6 @@
- - + @@ -13,6 +12,7 @@ + @@ -68,6 +68,7 @@ + @@ -126,12 +127,14 @@ + + diff --git a/src/main/java/musicplayer/PlayerGUI.java b/src/main/java/musicplayer/PlayerGUI.java index baf15ac..c56c0bc 100644 --- a/src/main/java/musicplayer/PlayerGUI.java +++ b/src/main/java/musicplayer/PlayerGUI.java @@ -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> 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 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 createDisplayVariantMap(){ + private Map createDisplayVariantMap() { Map 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)); } + }