merged zino's code, but attempted to clean it up. Still needs work to be functional.

This commit is contained in:
Andrew Lalis 2017-07-21 11:53:31 +02:00 committed by Andrew Lalis
parent fe5b2a54ef
commit 36605477c1
4 changed files with 65 additions and 39 deletions

4
.gitignore vendored
View File

@ -1,4 +1,4 @@
.idea/ .idea/*
modules/
src/test/ src/test/
target/ target/
modules/

View File

@ -93,7 +93,7 @@ public class HandieBot {
public static void main(String[] args) throws DiscordException, RateLimitException { public static void main(String[] args) throws DiscordException, RateLimitException {
//musicPlayer = new MusicPlayer(); musicPlayer = new MusicPlayer();
List<String> argsList = Arrays.asList(args); List<String> argsList = Arrays.asList(args);

View File

@ -1,23 +1,16 @@
package handiebot.view; package handiebot.view;
import handiebot.HandieBot; import handiebot.HandieBot;
import handiebot.command.SelectionController;
import handiebot.lavaplayer.playlist.Playlist; import handiebot.lavaplayer.playlist.Playlist;
import handiebot.lavaplayer.playlist.UnloadedTrack;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import javax.swing.*; import javax.swing.*;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener; import javax.swing.event.ListSelectionListener;
import java.awt.*; import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter; import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent; import java.awt.event.WindowEvent;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.*;
import java.util.List; import java.util.List;
import static handiebot.HandieBot.resourceBundle; import static handiebot.HandieBot.resourceBundle;
@ -28,8 +21,16 @@ import static handiebot.HandieBot.resourceBundle;
*/ */
public class BotWindow extends JFrame { public class BotWindow extends JFrame {
//Console output panel.
private JTextPane outputArea; private JTextPane outputArea;
//Playlist display variables.
private DefaultListModel<String> playlistNamesModel;
private DefaultListModel<String> currentPlaylistModel;
private JList<String> playlistNamesList;
private JList<String> currentPlaylistList;
private ListSelectionListener playlistListener;
public BotWindow(){ public BotWindow(){
super(HandieBot.APPLICATION_NAME); super(HandieBot.APPLICATION_NAME);
//Setup GUI //Setup GUI
@ -42,19 +43,32 @@ public class BotWindow extends JFrame {
getContentPane().add(scrollPane, BorderLayout.CENTER); getContentPane().add(scrollPane, BorderLayout.CENTER);
//Playlist shower //Playlist shower
JPanel playlistSub = new JPanel(new BorderLayout()); this.playlistNamesModel = new DefaultListModel<>();
JTextPane textPane = new JTextPane(); this.currentPlaylistModel = new DefaultListModel<>();
textPane.setEditable(false); this.playlistNamesList = new JList<>(this.playlistNamesModel);
JScrollPane playlist = new JScrollPane(textPane); this.playlistNamesList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
playlist.setPreferredSize(new Dimension(250, 200)); this.currentPlaylistList = new JList<>(this.currentPlaylistModel);
playlistSub.add(playlist, BorderLayout.PAGE_END); 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 JPanel playlistDisplayPanel = new JPanel(new BorderLayout());
JList<String> list = setPlayListListArea(textPane);
JScrollPane playlistList = new JScrollPane(list); //Song names scroll pane.
playlistList.setPreferredSize(new Dimension(250, 1000)); JScrollPane songNamesScrollPane = new JScrollPane(this.currentPlaylistList);
playlistSub.add(playlistList, BorderLayout.CENTER); songNamesScrollPane.setPreferredSize(new Dimension(250, 200));
getContentPane().add(playlistSub, BorderLayout.EAST); 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. //Command field.
JTextField commandField = new JTextField(); JTextField commandField = new JTextField();
@ -77,31 +91,46 @@ public class BotWindow extends JFrame {
} }
} }
}); });
//Attempt to set the icon of the window.
try { try {
setIconImage(ImageIO.read(getClass().getClassLoader().getResourceAsStream("avatarIcon.png"))); setIconImage(ImageIO.read(getClass().getClassLoader().getResourceAsStream("avatarIcon.png")));
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
setJMenuBar(new MenuBar(this)); setJMenuBar(new MenuBar(this));
SelectionController controller = new SelectionController(); //SelectionController controller = new SelectionController();
setPreferredSize(new Dimension(800, 600)); setPreferredSize(new Dimension(800, 600));
pack(); pack();
setLocationRelativeTo(null); setLocationRelativeTo(null);
setVisible(true); setVisible(true);
} }
/**
private JList<String> setPlayListListArea(JTextPane pane) { * Sets the playlist data in the window.
List<String> playlistList = Playlist.getAvailablePlaylists(); */
String labels[] = new String[playlistList.size()]; private void updatePlaylistData() {
int i=0; List<String> playlistNames = Playlist.getAvailablePlaylists();
for (String playlist : playlistList) { this.playlistNamesList.removeListSelectionListener(this.playlistListener);
labels[i] = playlist; this.playlistNamesModel.clear();
i++; for (String name : playlistNames){
this.playlistNamesModel.addElement(name);
} }
JList<String> list = new JList<>(labels); this.playlistNamesList.addListSelectionListener(this.playlistListener);
list.addListSelectionListener(e -> { String selectedValue = this.playlistNamesList.getSelectedValue();
String name = list.getSelectedValue(); System.out.println("selected value: "+selectedValue);
if (selectedValue != null && Playlist.playlistExists(selectedValue)){
Playlist playlist = new Playlist(selectedValue);
playlist.load();
List<UnloadedTrack> 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"; String path = System.getProperty("user.home") + "/.handiebot/playlist/" + name + ".txt";
File playlistFile = new File(path); File playlistFile = new File(path);
if (playlistFile.exists()) { if (playlistFile.exists()) {
@ -121,8 +150,7 @@ public class BotWindow extends JFrame {
ioe.printStackTrace(); ioe.printStackTrace();
} }
} }
}); });*/
return list;
} }
public JTextPane getOutputArea(){ public JTextPane getOutputArea(){

View File

@ -1,7 +1,6 @@
package handiebot.view; package handiebot.view;
import handiebot.command.Commands; import handiebot.command.Commands;
import handiebot.command.commands.interfaceActions.PlaylistAction;
import handiebot.view.actions.ActionItem; import handiebot.view.actions.ActionItem;
import handiebot.view.actions.CommandAction; import handiebot.view.actions.CommandAction;
@ -22,7 +21,6 @@ public class MenuBar extends JMenuBar {
this.window = window; this.window = window;
JMenu fileMenu = new JMenu(resourceBundle.getString("menu.fileMenu.title")); 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 ActionItem(resourceBundle.getString("menu.fileMenu.quit"), new CommandAction(Commands.get("quit"))));
fileMenu.add(new PlaylistAction());
this.add(fileMenu); this.add(fileMenu);
JMenu viewMenu = new JMenu(resourceBundle.getString("menu.viewMenu.view")); JMenu viewMenu = new JMenu(resourceBundle.getString("menu.viewMenu.view"));
JMenu language = new JMenu(resourceBundle.getString("menu.viewMenu.language")); JMenu language = new JMenu(resourceBundle.getString("menu.viewMenu.language"));