diff --git a/src/main/java/musicplayer/LibraryConfigGUI.java b/src/main/java/musicplayer/LibraryConfigGUI.java index 49e4a18..c4c9958 100644 --- a/src/main/java/musicplayer/LibraryConfigGUI.java +++ b/src/main/java/musicplayer/LibraryConfigGUI.java @@ -17,6 +17,7 @@ class LibraryConfigGUI { frame.setContentPane(createUI()); frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); frame.setSize(300, 200); + frame.setMinimumSize(new Dimension(300, 200)); frame.setVisible(true); updateLibraryListContents(); } diff --git a/src/main/java/musicplayer/PlayerGUI.java b/src/main/java/musicplayer/PlayerGUI.java index f038616..0475d53 100644 --- a/src/main/java/musicplayer/PlayerGUI.java +++ b/src/main/java/musicplayer/PlayerGUI.java @@ -12,10 +12,12 @@ import musicplayer.model.Artist; import musicplayer.model.HasSongs; import musicplayer.model.Song; import musicplayer.swingmodels.PlaylistTableModel; +import musicplayer.util.Icons; import musicplayer.util.LibraryUtils; import musicplayer.util.PlaylistUtils; import javax.swing.*; +import javax.swing.event.HyperlinkEvent; import javax.swing.filechooser.FileNameExtensionFilter; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.DefaultTreeModel; @@ -27,7 +29,10 @@ import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.io.File; import java.io.IOException; +import java.net.URISyntaxException; +import java.nio.file.Files; import java.nio.file.Path; +import java.nio.file.Paths; import java.util.*; import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; @@ -77,6 +82,7 @@ public class PlayerGUI implements PlayerCallbackInterface, LibraryCallbackInterf DatabaseManager.init(); PlayerGUI playerGUI = new PlayerGUI(); JFrame frame = new JFrame(); + frame.setMinimumSize(new Dimension(600, 400)); frame.setContentPane(playerGUI.mainPanel); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.pack(); @@ -362,9 +368,10 @@ public class PlayerGUI implements PlayerCallbackInterface, LibraryCallbackInterf private JToolBar createControlButtons() { JToolBar toolBar = new JToolBar(); toolBar.setFloatable(false); - JButton playButton = new JButton("Play"); + JPanel controlBar = new JPanel(new GridLayout(1, 5)); + JButton playButton = new JButton(); + playButton.setIcon(Icons.playIcon); playButton.setMnemonic('P'); - playButton.setDisplayedMnemonicIndex(0); playButton.addActionListener(e -> { if (playList.getRowCount() > 0) { if (playList.getSelectedRowCount() > 0) @@ -373,28 +380,31 @@ public class PlayerGUI implements PlayerCallbackInterface, LibraryCallbackInterf playSong(playlistTableModel.getFirst()); } }); - toolBar.add(playButton); - JButton pauseButton = new JButton("Pause"); + controlBar.add(playButton); + JButton pauseButton = new JButton(); + pauseButton.setIcon(Icons.pauseIcon); pauseButton.setMnemonic('E'); pauseButton.addActionListener(e -> { player.pause(); setSongHighlighting(player.getCurrentSong()); // Resume won't function if a different song is selected. }); - toolBar.add(pauseButton); - JButton stopButton = new JButton("Stop"); + controlBar.add(pauseButton); + JButton stopButton = new JButton(); + stopButton.setIcon(Icons.stopIcon); stopButton.setMnemonic('S'); - stopButton.setDisplayedMnemonicIndex(0); stopButton.addActionListener(e -> player.stop()); - toolBar.add(stopButton); - JButton previousButton = new JButton("Previous"); + controlBar.add(stopButton); + JButton previousButton = new JButton(); + previousButton.setIcon(Icons.prevIcon); previousButton.setMnemonic('R'); previousButton.addActionListener(e -> playPreviousSong()); - toolBar.add(previousButton); - JButton nextButton = new JButton("Next"); + controlBar.add(previousButton); + JButton nextButton = new JButton(); + nextButton.setIcon(Icons.nextIcon); nextButton.setMnemonic('N'); - nextButton.setDisplayedMnemonicIndex(0); nextButton.addActionListener(e -> playNextSong()); - toolBar.add(nextButton); + controlBar.add(nextButton); + toolBar.add(controlBar); toolBar.add(createVolumeControls()); return toolBar; } @@ -489,6 +499,32 @@ public class PlayerGUI implements PlayerCallbackInterface, LibraryCallbackInterf // Add everything to the menu bar itself menuBar.add(playlistTools); + + JMenu helpMenu = new JMenu("Help"); + menuItem = new JMenuItem("About"); + menuItem.addActionListener(e -> { + try { + //noinspection ConstantConditions + JEditorPane messagePane = new JEditorPane("text/html", Files.readAllLines( + Paths.get(PlayerGUI.class.getClassLoader().getResource("LICENSE.txt").toURI())).get(0)); + messagePane.setEditable(false); + messagePane.addHyperlinkListener(hl -> { + if (hl.getEventType() == HyperlinkEvent.EventType.ACTIVATED) + if(Desktop.isDesktopSupported()) + try { + Desktop.getDesktop().browse(hl.getURL().toURI()); + } catch (IOException | URISyntaxException e1) { + e1.printStackTrace(); + } + }); + JOptionPane.showMessageDialog(mainPanel, messagePane, "About", JOptionPane.INFORMATION_MESSAGE); + } catch (IOException | URISyntaxException e1) { + e1.printStackTrace(); + } + }); + helpMenu.add(menuItem); + + menuBar.add(helpMenu); return menuBar; } diff --git a/src/main/java/musicplayer/util/Icons.java b/src/main/java/musicplayer/util/Icons.java new file mode 100644 index 0000000..3784a73 --- /dev/null +++ b/src/main/java/musicplayer/util/Icons.java @@ -0,0 +1,14 @@ +package musicplayer.util; + +import javax.swing.*; + +@SuppressWarnings("ConstantConditions") +public final class Icons { + + private static final ClassLoader classLoader = Icons.class.getClassLoader(); + public static final Icon playIcon = new ImageIcon(classLoader.getResource("glyphicons-174-play.png")); + public static final Icon pauseIcon = new ImageIcon(classLoader.getResource("glyphicons-175-pause.png")); + public static final Icon stopIcon = new ImageIcon(classLoader.getResource("glyphicons-176-stop.png")); + public static final Icon prevIcon = new ImageIcon(classLoader.getResource("glyphicons-171-step-backward.png")); + public static final Icon nextIcon = new ImageIcon(classLoader.getResource("glyphicons-179-step-forward.png")); +} diff --git a/src/main/resources/LICENSE.txt b/src/main/resources/LICENSE.txt new file mode 100644 index 0000000..aa1a7cb --- /dev/null +++ b/src/main/resources/LICENSE.txt @@ -0,0 +1,2 @@ +GLYPHICONS FREE by Jan Kovarik is licensed under CC BY 3.0. + \ No newline at end of file diff --git a/src/main/resources/glyphicons-171-step-backward.png b/src/main/resources/glyphicons-171-step-backward.png new file mode 100644 index 0000000..a3762b6 Binary files /dev/null and b/src/main/resources/glyphicons-171-step-backward.png differ diff --git a/src/main/resources/glyphicons-172-fast-backward.png b/src/main/resources/glyphicons-172-fast-backward.png new file mode 100644 index 0000000..e78871a Binary files /dev/null and b/src/main/resources/glyphicons-172-fast-backward.png differ diff --git a/src/main/resources/glyphicons-173-rewind.png b/src/main/resources/glyphicons-173-rewind.png new file mode 100644 index 0000000..40691a3 Binary files /dev/null and b/src/main/resources/glyphicons-173-rewind.png differ diff --git a/src/main/resources/glyphicons-174-play.png b/src/main/resources/glyphicons-174-play.png new file mode 100644 index 0000000..b67aebd Binary files /dev/null and b/src/main/resources/glyphicons-174-play.png differ diff --git a/src/main/resources/glyphicons-175-pause.png b/src/main/resources/glyphicons-175-pause.png new file mode 100644 index 0000000..4566643 Binary files /dev/null and b/src/main/resources/glyphicons-175-pause.png differ diff --git a/src/main/resources/glyphicons-176-stop.png b/src/main/resources/glyphicons-176-stop.png new file mode 100644 index 0000000..3132434 Binary files /dev/null and b/src/main/resources/glyphicons-176-stop.png differ diff --git a/src/main/resources/glyphicons-177-forward.png b/src/main/resources/glyphicons-177-forward.png new file mode 100644 index 0000000..192e736 Binary files /dev/null and b/src/main/resources/glyphicons-177-forward.png differ diff --git a/src/main/resources/glyphicons-178-fast-forward.png b/src/main/resources/glyphicons-178-fast-forward.png new file mode 100644 index 0000000..d2e23ac Binary files /dev/null and b/src/main/resources/glyphicons-178-fast-forward.png differ diff --git a/src/main/resources/glyphicons-179-step-forward.png b/src/main/resources/glyphicons-179-step-forward.png new file mode 100644 index 0000000..5785c36 Binary files /dev/null and b/src/main/resources/glyphicons-179-step-forward.png differ