Now using glyphicons for media controls.

This commit is contained in:
neviyn 2016-03-14 22:51:04 +00:00
parent 086f887d20
commit 9e36003152
13 changed files with 66 additions and 13 deletions

View File

@ -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();
}

View File

@ -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;
}

View File

@ -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"));
}

View File

@ -0,0 +1,2 @@
<html><a href="http://glyphicons.com/">GLYPHICONS FREE by Jan Kovarik</a> is licensed under <a href="http://creativecommons.org/licenses/by/3.0/">CC BY 3.0</a>.
</html>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB