diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..e96534f --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/HandieBot.iml b/HandieBot.iml new file mode 100644 index 0000000..65ab8e4 --- /dev/null +++ b/HandieBot.iml @@ -0,0 +1,64 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/java/handiebot/command/MouseListener.java b/src/main/java/handiebot/command/MouseListener.java deleted file mode 100644 index 377f52a..0000000 --- a/src/main/java/handiebot/command/MouseListener.java +++ /dev/null @@ -1,8 +0,0 @@ -package handiebot.command; - -/** - * Author: Zino - * Date: 7/13/2017. - */ -public class MouseListener { -} diff --git a/src/main/java/handiebot/command/SelectionController.java b/src/main/java/handiebot/command/SelectionController.java new file mode 100644 index 0000000..4deec07 --- /dev/null +++ b/src/main/java/handiebot/command/SelectionController.java @@ -0,0 +1,39 @@ +package handiebot.command; + +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; + +/** + * Author: Zino Holwerda + * Date: 7/13/2017. + */ +public class SelectionController implements MouseListener { + + + public SelectionController() { + } + + @Override + public void mouseClicked(MouseEvent e) { + } + + @Override + public void mousePressed(MouseEvent e) { + + } + + @Override + public void mouseReleased(MouseEvent e) { + + } + + @Override + public void mouseEntered(MouseEvent e) { + + } + + @Override + public void mouseExited(MouseEvent e) { + + } +} diff --git a/src/main/java/handiebot/view/BotWindow.java b/src/main/java/handiebot/view/BotWindow.java index b5ffc92..109b87c 100644 --- a/src/main/java/handiebot/view/BotWindow.java +++ b/src/main/java/handiebot/view/BotWindow.java @@ -1,6 +1,7 @@ package handiebot.view; import handiebot.HandieBot; +import handiebot.command.SelectionController; import handiebot.lavaplayer.playlist.Playlist; import javax.imageio.ImageIO; @@ -8,15 +9,21 @@ 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; /** - * @author Andrew Lalis + * @author Andrew Lalis & Zino Holwerda * This class inherits JFrame and simplifies the creation of a window. */ public class BotWindow extends JFrame { @@ -36,23 +43,18 @@ public class BotWindow extends JFrame { getContentPane().add(scrollPane, BorderLayout.CENTER); //Playlist shower - java.util.List playlists = Playlist.getAvailablePlaylists(); - String labels[] = new String[playlists.size()]; - int i=0; - for (String playlist : playlists) { - labels[i] = playlist; - i++; - } - JList list = new JList<>(labels); - /*list.addListSelectionListener(new ListSelectionListener() { - @Override - public void valueChanged(ListSelectionEvent e) { + JPanel playlistSub = new JPanel(new BorderLayout()); + JTextPane textPane = new JTextPane(); + JScrollPane playlist = new JScrollPane(textPane); + playlist.setPreferredSize(new Dimension(200, 200)); + playlistSub.add(playlist, BorderLayout.PAGE_END); + getContentPane().add(playlistSub, BorderLayout.EAST); - } - });*/ - JScrollPane jScrollPane = new JScrollPane(list); - jScrollPane.setPreferredSize(new Dimension(100, 200)); - getContentPane().add(jScrollPane, BorderLayout.EAST); + //PlaylistList maker + JList list = setPlayListListArea(textPane); + JScrollPane playlistList = new JScrollPane(list); + playlistList.setPreferredSize(new Dimension(200, 1000)); + playlistSub.add(playlistList, BorderLayout.CENTER); //Command field. JTextField commandField = new JTextField(); @@ -62,6 +64,7 @@ public class BotWindow extends JFrame { //Standard JFrame setup code. setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); + //Add a listener to override the user attempting to close the program. addWindowListener(new WindowAdapter() { @Override @@ -80,12 +83,46 @@ public class BotWindow extends JFrame { e.printStackTrace(); } setJMenuBar(new MenuBar()); + SelectionController controller = new SelectionController(); setPreferredSize(new Dimension(800, 600)); pack(); setVisible(true); } - //private void selected + + 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++; + } + JList list = new JList<>(labels); + list.addListSelectionListener(e -> { + String name = list.getSelectedValue(); + String path = System.getProperty("user.home") + "/.handiebot/playlist/" + name + ".txt"; + File playlistFile = new File(path); + if (playlistFile.exists()) { + try { + List lines = Files.readAllLines(Paths.get(playlistFile.toURI())); + int trackCount = Integer.parseInt(lines.remove(0)); + String[] words = {"A"}; + StringBuilder sb = new StringBuilder(); + for (int i1 = 0; i1 < trackCount; i1++) { + words = lines.remove(0).split(" / "); + sb.append(i1 +1).append(". ").append(words[0]).append("\n"); + } + if(!words[0].equals("A")) { + pane.setText(sb.toString()); + } + } catch (IOException ioe) { + ioe.printStackTrace(); + } + } + }); + return list; + } public JTextPane getOutputArea(){ return this.outputArea;