diff --git a/.gitignore b/.gitignore index 4713549..f2d9c1b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -.idea/ -modules/ +.idea/* src/test/ target/ +modules/ diff --git a/src/main/java/handiebot/HandieBot.java b/src/main/java/handiebot/HandieBot.java index ebc1448..d973651 100644 --- a/src/main/java/handiebot/HandieBot.java +++ b/src/main/java/handiebot/HandieBot.java @@ -93,7 +93,7 @@ public class HandieBot { public static void main(String[] args) throws DiscordException, RateLimitException { - //musicPlayer = new MusicPlayer(); + musicPlayer = new MusicPlayer(); List argsList = Arrays.asList(args); diff --git a/src/main/java/handiebot/view/BotWindow.java b/src/main/java/handiebot/view/BotWindow.java index 4724a1b..ef06b58 100644 --- a/src/main/java/handiebot/view/BotWindow.java +++ b/src/main/java/handiebot/view/BotWindow.java @@ -1,23 +1,16 @@ package handiebot.view; import handiebot.HandieBot; -import handiebot.command.SelectionController; import handiebot.lavaplayer.playlist.Playlist; +import handiebot.lavaplayer.playlist.UnloadedTrack; import javax.imageio.ImageIO; import javax.swing.*; -import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; import java.awt.*; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; -import java.io.File; import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.*; import java.util.List; import static handiebot.HandieBot.resourceBundle; @@ -28,8 +21,16 @@ import static handiebot.HandieBot.resourceBundle; */ public class BotWindow extends JFrame { + //Console output panel. private JTextPane outputArea; + //Playlist display variables. + private DefaultListModel playlistNamesModel; + private DefaultListModel currentPlaylistModel; + private JList playlistNamesList; + private JList currentPlaylistList; + private ListSelectionListener playlistListener; + public BotWindow(){ super(HandieBot.APPLICATION_NAME); //Setup GUI @@ -42,19 +43,32 @@ public class BotWindow extends JFrame { getContentPane().add(scrollPane, BorderLayout.CENTER); //Playlist shower - JPanel playlistSub = new JPanel(new BorderLayout()); - JTextPane textPane = new JTextPane(); - textPane.setEditable(false); - JScrollPane playlist = new JScrollPane(textPane); - playlist.setPreferredSize(new Dimension(250, 200)); - playlistSub.add(playlist, BorderLayout.PAGE_END); + this.playlistNamesModel = new DefaultListModel<>(); + this.currentPlaylistModel = new DefaultListModel<>(); + this.playlistNamesList = new JList<>(this.playlistNamesModel); + this.playlistNamesList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + this.currentPlaylistList = new JList<>(this.currentPlaylistModel); + this.currentPlaylistList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); + this.playlistListener = e -> { + System.out.println("user updated list."); + updatePlaylistData(); + }; + this.playlistNamesList.addListSelectionListener(this.playlistListener); + updatePlaylistData(); - //PlaylistList maker - JList list = setPlayListListArea(textPane); - JScrollPane playlistList = new JScrollPane(list); - playlistList.setPreferredSize(new Dimension(250, 1000)); - playlistSub.add(playlistList, BorderLayout.CENTER); - getContentPane().add(playlistSub, BorderLayout.EAST); + JPanel playlistDisplayPanel = new JPanel(new BorderLayout()); + + //Song names scroll pane. + JScrollPane songNamesScrollPane = new JScrollPane(this.currentPlaylistList); + songNamesScrollPane.setPreferredSize(new Dimension(250, 200)); + playlistDisplayPanel.add(songNamesScrollPane, BorderLayout.PAGE_END); + + //Playlist name scroll pane. + JScrollPane playlistNamesScrollPane = new JScrollPane(playlistNamesList); + playlistNamesScrollPane.setPreferredSize(new Dimension(250, 1000)); + playlistDisplayPanel.add(playlistNamesScrollPane, BorderLayout.CENTER); + + getContentPane().add(playlistDisplayPanel, BorderLayout.EAST); //Command field. JTextField commandField = new JTextField(); @@ -77,31 +91,46 @@ public class BotWindow extends JFrame { } } }); + + //Attempt to set the icon of the window. try { setIconImage(ImageIO.read(getClass().getClassLoader().getResourceAsStream("avatarIcon.png"))); } catch (IOException e) { e.printStackTrace(); } setJMenuBar(new MenuBar(this)); - SelectionController controller = new SelectionController(); + //SelectionController controller = new SelectionController(); setPreferredSize(new Dimension(800, 600)); pack(); setLocationRelativeTo(null); setVisible(true); } - - private JList setPlayListListArea(JTextPane pane) { - List playlistList = Playlist.getAvailablePlaylists(); - String labels[] = new String[playlistList.size()]; - int i=0; - for (String playlist : playlistList) { - labels[i] = playlist; - i++; + /** + * Sets the playlist data in the window. + */ + private void updatePlaylistData() { + List playlistNames = Playlist.getAvailablePlaylists(); + this.playlistNamesList.removeListSelectionListener(this.playlistListener); + this.playlistNamesModel.clear(); + for (String name : playlistNames){ + this.playlistNamesModel.addElement(name); } - JList list = new JList<>(labels); - list.addListSelectionListener(e -> { - String name = list.getSelectedValue(); + this.playlistNamesList.addListSelectionListener(this.playlistListener); + String selectedValue = this.playlistNamesList.getSelectedValue(); + System.out.println("selected value: "+selectedValue); + if (selectedValue != null && Playlist.playlistExists(selectedValue)){ + Playlist playlist = new Playlist(selectedValue); + playlist.load(); + List tracks = playlist.getTracks(); + this.currentPlaylistModel.clear(); + for (int i = 0; i < playlist.getTrackCount(); i++){ + this.currentPlaylistModel.addElement(tracks.get(i).getTitle()); + } + } + /* + this.playlistNamesList.addListSelectionListener(e -> { + String name = playlistNamesList.getSelectedValue(); String path = System.getProperty("user.home") + "/.handiebot/playlist/" + name + ".txt"; File playlistFile = new File(path); if (playlistFile.exists()) { @@ -121,8 +150,7 @@ public class BotWindow extends JFrame { ioe.printStackTrace(); } } - }); - return list; + });*/ } public JTextPane getOutputArea(){ diff --git a/src/main/java/handiebot/view/MenuBar.java b/src/main/java/handiebot/view/MenuBar.java index 7cd1c05..6440b4a 100644 --- a/src/main/java/handiebot/view/MenuBar.java +++ b/src/main/java/handiebot/view/MenuBar.java @@ -1,7 +1,6 @@ package handiebot.view; import handiebot.command.Commands; -import handiebot.command.commands.interfaceActions.PlaylistAction; import handiebot.view.actions.ActionItem; import handiebot.view.actions.CommandAction; @@ -22,7 +21,6 @@ public class MenuBar extends JMenuBar { this.window = window; JMenu fileMenu = new JMenu(resourceBundle.getString("menu.fileMenu.title")); fileMenu.add(new ActionItem(resourceBundle.getString("menu.fileMenu.quit"), new CommandAction(Commands.get("quit")))); - fileMenu.add(new PlaylistAction()); this.add(fileMenu); JMenu viewMenu = new JMenu(resourceBundle.getString("menu.viewMenu.view")); JMenu language = new JMenu(resourceBundle.getString("menu.viewMenu.language"));