From 2c8785e9dcab832475d46edfbec0a2ab3d79b3df Mon Sep 17 00:00:00 2001
From: StevenLawson <steven@smlawson.com>
Date: Wed, 27 Aug 2014 22:06:27 -0400
Subject: [PATCH] Finished implementing new config.

---
 .../BukkitTelnetClient/BTC_ConfigLoader.java  | 19 ++++-
 .../BTC_FavoriteButtonsPanel.java             |  6 +-
 .../BukkitTelnetClient/BTC_MainPanel.java     | 27 +------
 .../FavoriteButtonData.java                   | 41 ----------
 .../FavoriteButtonEntry.java                  | 81 +++++++++++++++++++
 .../PlayerCommandEntry.java                   |  4 +-
 src/main/resources/settings.xml               | 80 +++++++++++++++++-
 7 files changed, 184 insertions(+), 74 deletions(-)
 delete mode 100644 src/main/java/me/StevenLawson/BukkitTelnetClient/FavoriteButtonData.java
 create mode 100644 src/main/java/me/StevenLawson/BukkitTelnetClient/FavoriteButtonEntry.java

diff --git a/src/main/java/me/StevenLawson/BukkitTelnetClient/BTC_ConfigLoader.java b/src/main/java/me/StevenLawson/BukkitTelnetClient/BTC_ConfigLoader.java
index 1202e4e..fa5f7ab 100644
--- a/src/main/java/me/StevenLawson/BukkitTelnetClient/BTC_ConfigLoader.java
+++ b/src/main/java/me/StevenLawson/BukkitTelnetClient/BTC_ConfigLoader.java
@@ -36,6 +36,7 @@ public class BTC_ConfigLoader
 
     private final ServerEntry.ServerEntryList servers = new ServerEntry.ServerEntryList();
     private final PlayerCommandEntry.PlayerCommandEntryList playerCommands = new PlayerCommandEntry.PlayerCommandEntryList();
+    private final FavoriteButtonEntry.FavoriteButtonEntryList favoriteButtons = new FavoriteButtonEntry.FavoriteButtonEntryList();
 
     public BTC_ConfigLoader()
     {
@@ -102,6 +103,11 @@ public class BTC_ConfigLoader
         return this.servers.getList();
     }
 
+    public Collection<FavoriteButtonEntry> getFavoriteButtons()
+    {
+        return favoriteButtons.getList();
+    }
+
     private boolean generateXML(final File file)
     {
         try
@@ -111,8 +117,9 @@ public class BTC_ConfigLoader
             final Element rootElement = doc.createElement("configuration");
             doc.appendChild(rootElement);
 
-            rootElement.appendChild(this.playerCommands.toXML(doc));
             rootElement.appendChild(this.servers.toXML(doc));
+            rootElement.appendChild(this.playerCommands.toXML(doc));
+            rootElement.appendChild(this.favoriteButtons.toXML(doc));
 
             final Transformer transformer = TransformerFactory.newInstance().newTransformer();
             transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
@@ -139,15 +146,21 @@ public class BTC_ConfigLoader
             final Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(file);
             doc.getDocumentElement().normalize();
 
+            if (!this.servers.fromXML(doc))
+            {
+                System.out.println("Error loading servers.");
+                hadErrors = true;
+            }
+
             if (!this.playerCommands.fromXML(doc))
             {
                 System.out.println("Error loading playerCommands.");
                 hadErrors = true;
             }
 
-            if (!this.servers.fromXML(doc))
+            if (!this.favoriteButtons.fromXML(doc))
             {
-                System.out.println("Error loading servers.");
+                System.out.println("Error favorite buttons.");
                 hadErrors = true;
             }
         }
diff --git a/src/main/java/me/StevenLawson/BukkitTelnetClient/BTC_FavoriteButtonsPanel.java b/src/main/java/me/StevenLawson/BukkitTelnetClient/BTC_FavoriteButtonsPanel.java
index 375559f..f0bb8cb 100644
--- a/src/main/java/me/StevenLawson/BukkitTelnetClient/BTC_FavoriteButtonsPanel.java
+++ b/src/main/java/me/StevenLawson/BukkitTelnetClient/BTC_FavoriteButtonsPanel.java
@@ -21,13 +21,13 @@ package me.StevenLawson.BukkitTelnetClient;
 import java.awt.*;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
-import java.util.List;
+import java.util.Collection;
 import javax.swing.JButton;
 import javax.swing.JPanel;
 
 public class BTC_FavoriteButtonsPanel extends JPanel
 {
-    public BTC_FavoriteButtonsPanel(final List<FavoriteButtonData> buttonList)
+    public BTC_FavoriteButtonsPanel(final Collection<FavoriteButtonEntry> buttonList)
     {
         super.setLayout(new GridLayout(0, 2, 1, 1));
 
@@ -43,7 +43,7 @@ public class BTC_FavoriteButtonsPanel extends JPanel
             }
         };
 
-        for (final FavoriteButtonData buttonData : buttonList)
+        for (final FavoriteButtonEntry buttonData : buttonList)
         {
             final JButton button = new JButton();
             button.setText(buttonData.getLabel());
diff --git a/src/main/java/me/StevenLawson/BukkitTelnetClient/BTC_MainPanel.java b/src/main/java/me/StevenLawson/BukkitTelnetClient/BTC_MainPanel.java
index 94626ce..1db38b0 100644
--- a/src/main/java/me/StevenLawson/BukkitTelnetClient/BTC_MainPanel.java
+++ b/src/main/java/me/StevenLawson/BukkitTelnetClient/BTC_MainPanel.java
@@ -37,31 +37,10 @@ public class BTC_MainPanel extends javax.swing.JFrame
     private final BTC_ConnectionManager connectionManager = new BTC_ConnectionManager();
     private final List<PlayerInfo> playerList = new ArrayList<>();
     private final PlayerListTableModel playerListTableModel = new PlayerListTableModel(playerList);
-
-    private final List<FavoriteButtonData> favButtonList = new ArrayList<>();
+    private final Collection<FavoriteButtonEntry> favButtonList = BukkitTelnetClient.config.getFavoriteButtons();
 
     public BTC_MainPanel()
     {
-        favButtonList.add(new FavoriteButtonData("Op All", "opall"));
-        favButtonList.add(new FavoriteButtonData("Deop All", "deopall"));
-        favButtonList.add(new FavoriteButtonData("Nick Clean", "nickclean"));
-        favButtonList.add(new FavoriteButtonData("Adminmode ON", "adminmode on"));
-        favButtonList.add(new FavoriteButtonData("Adminmode OFF", "adminmode off"));
-        favButtonList.add(new FavoriteButtonData("Cake", "cake"));
-        favButtonList.add(new FavoriteButtonData("Mob Purge", "mp"));
-        favButtonList.add(new FavoriteButtonData("Remove Drops", "rd"));
-        favButtonList.add(new FavoriteButtonData("Purge All", "purgeall"));
-        favButtonList.add(new FavoriteButtonData("Set Limit = 500", "setl"));
-        favButtonList.add(new FavoriteButtonData("Stop Server", "stop"));
-        favButtonList.add(new FavoriteButtonData("Toggle Water Placement", "toggle waterplace"));
-        favButtonList.add(new FavoriteButtonData("Toggle Fire Placement", "toggle fireplace"));
-        favButtonList.add(new FavoriteButtonData("Toggle Lava Placement", "toggle lavaplace"));
-        favButtonList.add(new FavoriteButtonData("Toggle Fluid Spread", "toggle fluidspread"));
-        favButtonList.add(new FavoriteButtonData("Toggle Lava Damage", "toggle lavadmg"));
-        favButtonList.add(new FavoriteButtonData("Toggle Fire Spread", "toggle firespread"));
-        favButtonList.add(new FavoriteButtonData("Toggle Lockdown", "toggle lockdown"));
-        favButtonList.add(new FavoriteButtonData("Toggle Explosives", "toggle explosives"));
-
         initComponents();
     }
 
@@ -521,7 +500,7 @@ public class BTC_MainPanel extends javax.swing.JFrame
         mainOutput = new javax.swing.JTextPane();
         btnDisconnect = new javax.swing.JButton();
         btnSend = new javax.swing.JButton();
-        txtServer = new javax.swing.JComboBox<ServerEntry>();
+        txtServer = new javax.swing.JComboBox<me.StevenLawson.BukkitTelnetClient.ServerEntry>();
         chkAutoScroll = new javax.swing.JCheckBox();
         txtCommand = new javax.swing.JTextField();
         btnConnect = new javax.swing.JButton();
@@ -853,7 +832,7 @@ public class BTC_MainPanel extends javax.swing.JFrame
     private javax.swing.JTable tblPlayers;
     private javax.swing.JTextField txtCommand;
     private javax.swing.JTextField txtNumPlayers;
-    private javax.swing.JComboBox<ServerEntry> txtServer;
+    private javax.swing.JComboBox<me.StevenLawson.BukkitTelnetClient.ServerEntry> txtServer;
     // End of variables declaration//GEN-END:variables
 
     public javax.swing.JButton getBtnConnect()
diff --git a/src/main/java/me/StevenLawson/BukkitTelnetClient/FavoriteButtonData.java b/src/main/java/me/StevenLawson/BukkitTelnetClient/FavoriteButtonData.java
deleted file mode 100644
index 1f72049..0000000
--- a/src/main/java/me/StevenLawson/BukkitTelnetClient/FavoriteButtonData.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/* 
- * Copyright (C) 2012-2014 Steven Lawson
- *
- * This file is part of BukkitTelnetClient.
- *
- * BukkitTelnetClient is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-package me.StevenLawson.BukkitTelnetClient;
-
-public class FavoriteButtonData
-{
-    private final String label;
-    private final String command;
-
-    public FavoriteButtonData(String label, String command)
-    {
-        this.label = label;
-        this.command = command;
-    }
-
-    public String getLabel()
-    {
-        return label;
-    }
-
-    public String getCommand()
-    {
-        return command;
-    }
-}
diff --git a/src/main/java/me/StevenLawson/BukkitTelnetClient/FavoriteButtonEntry.java b/src/main/java/me/StevenLawson/BukkitTelnetClient/FavoriteButtonEntry.java
new file mode 100644
index 0000000..77d676d
--- /dev/null
+++ b/src/main/java/me/StevenLawson/BukkitTelnetClient/FavoriteButtonEntry.java
@@ -0,0 +1,81 @@
+/* 
+ * Copyright (C) 2012-2014 Steven Lawson
+ *
+ * This file is part of BukkitTelnetClient.
+ *
+ * BukkitTelnetClient is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package me.StevenLawson.BukkitTelnetClient;
+
+import java.util.ArrayList;
+
+public class FavoriteButtonEntry implements ConfigEntry
+{
+    private String label;
+    private String command;
+
+    public FavoriteButtonEntry()
+    {
+    }
+
+    public FavoriteButtonEntry(final String label, final String command)
+    {
+        this.label = label;
+        this.command = command;
+    }
+
+    @ConfigEntryList.ParameterGetter(name = "label")
+    public String getLabel()
+    {
+        return label;
+    }
+
+    @ConfigEntryList.ParameterSetter(name = "label")
+    public void setLabel(String label)
+    {
+        this.label = label;
+    }
+
+    @ConfigEntryList.ParameterGetter(name = "command")
+    public String getCommand()
+    {
+        return command;
+    }
+
+    @ConfigEntryList.ParameterSetter(name = "command")
+    public void setCommand(String command)
+    {
+        this.command = command;
+    }
+
+    public static class FavoriteButtonEntryList extends ConfigEntryList<FavoriteButtonEntry>
+    {
+        public FavoriteButtonEntryList()
+        {
+            super(new ArrayList<FavoriteButtonEntry>(), FavoriteButtonEntry.class);
+        }
+
+        @Override
+        public String getParentElementName()
+        {
+            return "favoriteButtons";
+        }
+
+        @Override
+        public String getItemElementName()
+        {
+            return "favoriteButton";
+        }
+    }
+}
diff --git a/src/main/java/me/StevenLawson/BukkitTelnetClient/PlayerCommandEntry.java b/src/main/java/me/StevenLawson/BukkitTelnetClient/PlayerCommandEntry.java
index 1eb115b..5fcda43 100644
--- a/src/main/java/me/StevenLawson/BukkitTelnetClient/PlayerCommandEntry.java
+++ b/src/main/java/me/StevenLawson/BukkitTelnetClient/PlayerCommandEntry.java
@@ -18,7 +18,7 @@
  */
 package me.StevenLawson.BukkitTelnetClient;
 
-import java.util.HashSet;
+import java.util.ArrayList;
 
 public class PlayerCommandEntry implements ConfigEntry
 {
@@ -63,7 +63,7 @@ public class PlayerCommandEntry implements ConfigEntry
     {
         public PlayerCommandEntryList()
         {
-            super(new HashSet<PlayerCommandEntry>(), PlayerCommandEntry.class);
+            super(new ArrayList<PlayerCommandEntry>(), PlayerCommandEntry.class);
         }
 
         @Override
diff --git a/src/main/resources/settings.xml b/src/main/resources/settings.xml
index 3d61696..df3fbad 100644
--- a/src/main/resources/settings.xml
+++ b/src/main/resources/settings.xml
@@ -1,5 +1,6 @@
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
 <configuration>
+    <servers/>
     <playerCommands>
         <playerCommand>
             <name>Ban</name>
@@ -58,5 +59,82 @@
             <format>survival %s</format>
         </playerCommand>
     </playerCommands>
-    <servers/>
+    <favoriteButtons>
+        <favoriteButton>
+            <label>Op All</label>
+            <command>opall</command>
+        </favoriteButton>
+        <favoriteButton>
+            <label>Deop All</label>
+            <command>deopall</command>
+        </favoriteButton>
+        <favoriteButton>
+            <label>Nick Clean</label>
+            <command>nickclean</command>
+        </favoriteButton>
+        <favoriteButton>
+            <label>Adminmode ON</label>
+            <command>adminmode on</command>
+        </favoriteButton>
+        <favoriteButton>
+            <label>Adminmode OFF</label>
+            <command>adminmode off</command>
+        </favoriteButton>
+        <favoriteButton>
+            <label>Cake</label>
+            <command>cake</command>
+        </favoriteButton>
+        <favoriteButton>
+            <label>Mob Purge</label>
+            <command>mp</command>
+        </favoriteButton>
+        <favoriteButton>
+            <label>Remove Drops</label>
+            <command>rd</command>
+        </favoriteButton>
+        <favoriteButton>
+            <label>Purge All</label>
+            <command>purgeall</command>
+        </favoriteButton>
+        <favoriteButton>
+            <label>Set Limit = 500</label>
+            <command>setl</command>
+        </favoriteButton>
+        <favoriteButton>
+            <label>Stop Server</label>
+            <command>stop</command>
+        </favoriteButton>
+        <favoriteButton>
+            <label>Toggle Water Placement</label>
+            <command>toggle waterplace</command>
+        </favoriteButton>
+        <favoriteButton>
+            <label>Toggle Fire Placement</label>
+            <command>toggle fireplace</command>
+        </favoriteButton>
+        <favoriteButton>
+            <label>Toggle Lava Placement</label>
+            <command>toggle lavaplace</command>
+        </favoriteButton>
+        <favoriteButton>
+            <label>Toggle Fluid Spread</label>
+            <command>toggle fluidspread</command>
+        </favoriteButton>
+        <favoriteButton>
+            <label>Toggle Lava Damage</label>
+            <command>toggle lavadmg</command>
+        </favoriteButton>
+        <favoriteButton>
+            <label>Toggle Fire Spread</label>
+            <command>toggle firespread</command>
+        </favoriteButton>
+        <favoriteButton>
+            <label>Toggle Lockdown</label>
+            <command>toggle lockdown</command>
+        </favoriteButton>
+        <favoriteButton>
+            <label>Toggle Explosives</label>
+            <command>toggle explosives</command>
+        </favoriteButton>
+    </favoriteButtons>
 </configuration>