Switched usage of config in main program.

TODO:
-Server list order.
-"reason" checkbox and dialog.
-"favorite" command buttons + config
This commit is contained in:
StevenLawson 2014-08-19 20:24:58 -04:00
parent 0f00da9dcb
commit 0f25e91082
2 changed files with 10 additions and 46 deletions

View file

@ -77,6 +77,10 @@ public class BTC_ConfigLoader
public boolean save()
{
final HashSet<ServerEntry> uniqueServers = new HashSet<>(this.servers);
this.servers.clear();
this.servers.addAll(uniqueServers);
return generateXML(new File(SETTINGS_FILE));
}
@ -183,7 +187,7 @@ public class BTC_ConfigLoader
while ((line = in.readLine()) != null)
{
line = line.trim();
oldServers.add(new ServerEntry("imported", line));
oldServers.add(new ServerEntry("legacy", line));
}
}

View file

@ -39,13 +39,10 @@ import javax.swing.text.StyledDocument;
public class BTC_MainPanel extends javax.swing.JFrame
{
private static final String SERVERS_FILE_NAME = "btc_servers.cfg";
public static final ByteArrayOutputStream CONSOLE = new ByteArrayOutputStream();
public static final PrintStream CONSOLE_STREAM = new PrintStream(CONSOLE);
private final BTC_ConnectionManager connectionManager = new BTC_ConnectionManager();
private final LinkedList<String> serverList = new LinkedList<>();
public BTC_MainPanel()
{
@ -444,29 +441,11 @@ public class BTC_MainPanel extends javax.swing.JFrame
public final void loadServerList()
{
try
{
serverList.clear();
txtServer.removeAllItems();
txtServer.removeAllItems();
final File file = new File(SERVERS_FILE_NAME);
if (file.exists())
{
try (final BufferedReader in = new BufferedReader(new FileReader(file)))
{
String line;
while ((line = in.readLine()) != null)
{
line = line.trim();
serverList.add(line);
txtServer.addItem(line);
}
}
}
}
catch (IOException ex)
for (BTC_ConfigLoader.ServerEntry serverEntry : BukkitTelnetClient.config.getServers())
{
BukkitTelnetClient.LOGGER.log(Level.SEVERE, null, ex);
txtServer.addItem(serverEntry.getAddress());
}
}
@ -480,28 +459,9 @@ public class BTC_MainPanel extends javax.swing.JFrame
return;
}
try
{
if (serverList.contains(selectedServer))
{
serverList.remove(selectedServer);
}
BukkitTelnetClient.config.getServers().add(new BTC_ConfigLoader.ServerEntry("legacy", selectedServer));
serverList.addFirst(selectedServer);
try (final BufferedWriter out = new BufferedWriter(new FileWriter(new File(SERVERS_FILE_NAME))))
{
for (final String server : serverList)
{
out.write(server + '\n');
}
}
}
catch (IOException ex)
{
BukkitTelnetClient.LOGGER.log(Level.SEVERE, null, ex);
}
loadServerList();
BukkitTelnetClient.config.save();
connectionManager.triggerConnect(selectedServer);
}