From 360779935462f13ef7453ca498d20b59942dde10 Mon Sep 17 00:00:00 2001 From: Dane Date: Fri, 21 Jun 2013 11:36:38 -0400 Subject: [PATCH] Directories Cached + Resized the JScrollPane for the LogArea in the BotUI since it was being cut off and Clispy is too lazy to do it. As well as ticked the vertical bar in the ServerSelector to always be there. --- .../src/org/parabot/core/Directories.java | 121 +++++++++++------- parabotv2/src/org/parabot/core/ui/BotUI.java | 2 +- .../org/parabot/core/ui/ServerSelector.java | 9 +- 3 files changed, 79 insertions(+), 53 deletions(-) diff --git a/parabotv2/src/org/parabot/core/Directories.java b/parabotv2/src/org/parabot/core/Directories.java index aaaf7d4..2a94a51 100644 --- a/parabotv2/src/org/parabot/core/Directories.java +++ b/parabotv2/src/org/parabot/core/Directories.java @@ -1,12 +1,13 @@ package org.parabot.core; import java.io.File; +import java.util.HashMap; import java.util.LinkedList; +import java.util.Map; import java.util.Queue; import java.util.Random; import javax.swing.JFileChooser; -import javax.swing.filechooser.FileSystemView; import org.parabot.environment.OperatingSystem; @@ -18,75 +19,96 @@ import org.parabot.environment.OperatingSystem; */ public class Directories { - /** - * Gets default user directory - * @return default user director - */ - public static File getDefaultDirectory() { + private static Map cached = new HashMap(); + + static { + switch (OperatingSystem.getOS()) { - case WINDOWS: - JFileChooser fr = new JFileChooser(); - FileSystemView fw = fr.getFileSystemView(); - return fw.getDefaultDirectory(); - default: - return new File(System.getProperty("user.home")); + case WINDOWS: + cached.put("Root", new JFileChooser().getFileSystemView().getDefaultDirectory()); + break; + default: + cached.put("Root", new File(System.getProperty("user.home"))); } - } - - /** - * Gets bot workspace - * @return workspace of bot - */ - public static File getWorkspace() { - return new File(getDefaultDirectory(), "/Parabot/"); - } - - /** - * Get script sources path - * @return script sources path - */ - public static File getScriptSourcesPath() { - return new File(getDefaultDirectory(), "/Parabot/scripts/sources/"); + + cached.put("Root", getDefaultDirectory()); + cached.put("Workspace", new File(cached.get("Root"), "/Parabot/")); + cached.put("Sources", new File(cached.get("Root"), "/Parabot/scripts/sources/")); + cached.put("Compiled", new File(cached.get("Root"), "/Parabot/scripts/compiled/")); + cached.put("Resources", new File(cached.get("Root"), "/Parabot/scripts/resources/")); + cached.put("Settings", new File(cached.get("Root"), "/Parabot/settings/")); + cached.put("Servers", new File(cached.get("Root"), "/Parabot/servers/")); } /** - * Get script compiled path - * @return script compiled path + * Returns the root directory outside of the main Parabot folder. + * + * @return + */ + public static File getDefaultDirectory() { + return cached.get("Root"); + } + + /** + * Returns the Parabot folder. + * + * @return + */ + public static File getWorkspace() { + return cached.get("Workspace"); + } + + /** + * Returns the script sources folder. + * + * @return + */ + public static File getScriptSourcesPath() { + return cached.get("Sources"); + } + + /** + * Returns the compiled scripts folder. + * + * @return */ public static File getScriptCompiledPath() { - return new File(getDefaultDirectory(), "/Parabot/scripts/compiled/"); + return cached.get("Compiled"); } - + /** - * Get script compiled path - * @return script compiled path + * Returns the scripts resources folder. + * + * @return */ public static File getResourcesPath() { - return new File(getDefaultDirectory(), "/Parabot/scripts/resources/"); + return cached.get("Resources"); } - + /** - * Gets settings directory - * @return settings directory + * Returns the Parabot settings folder. + * + * @return */ public static File getSettingsPath() { - return new File(getDefaultDirectory(), "/Parabot/settings/"); + return cached.get("Settings"); } - + /** - * Gets servers directory - * @return servers directory + * Returns the Parabot servers folder. + * + * @return */ public static File getServerPath() { - return new File(getDefaultDirectory(), "/Parabot/servers/"); + return cached.get("Servers"); } - + /** * Validates all directories and makes them if necessary */ public static void validate() { final File defaultPath = getDefaultDirectory(); - if(defaultPath == null || !defaultPath.exists()) { + if (defaultPath == null || !defaultPath.exists()) { throw new RuntimeException("Default path not found"); } final Queue files = new LinkedList(); @@ -96,17 +118,18 @@ public class Directories { files.add(getScriptSourcesPath()); files.add(getScriptCompiledPath()); files.add(getResourcesPath()); - while(files.size() > 0) { + while (files.size() > 0) { final File file = files.poll(); - if(!file.exists()) { + if (!file.exists()) { file.mkdirs(); } } } - + private static File temp = null; + public static File getTempDirectory() { - if(temp != null) { + if (temp != null) { return temp; } int randomNum = new Random().nextInt(999999999); diff --git a/parabotv2/src/org/parabot/core/ui/BotUI.java b/parabotv2/src/org/parabot/core/ui/BotUI.java index 534cb7b..ff3ffac 100644 --- a/parabotv2/src/org/parabot/core/ui/BotUI.java +++ b/parabotv2/src/org/parabot/core/ui/BotUI.java @@ -76,7 +76,7 @@ public class BotUI extends JFrame implements ActionListener { y += iGameHeight; JScrollPane scrlConsole = LogArea.getInstance(); - scrlConsole.setPreferredSize(new Dimension(765, iLogHeight)); + scrlConsole.setPreferredSize(new Dimension(765, iLogHeight - 15)); toolbar.setLocation(x, y); panel.add(toolbar); diff --git a/parabotv2/src/org/parabot/core/ui/ServerSelector.java b/parabotv2/src/org/parabot/core/ui/ServerSelector.java index 165e0d6..32abd76 100644 --- a/parabotv2/src/org/parabot/core/ui/ServerSelector.java +++ b/parabotv2/src/org/parabot/core/ui/ServerSelector.java @@ -11,7 +11,6 @@ import javax.swing.JScrollPane; import org.parabot.core.desc.ServerDescription; import org.parabot.core.parsers.ServerManifestParser; -import org.parabot.core.ui.utils.AwtUtil; import org.parabot.core.ui.utils.SwingUtil; import org.parabot.core.ui.widgets.ServerWidget; @@ -58,6 +57,7 @@ public class ServerSelector extends JFrame { JScrollPane scrlInterior = new JScrollPane(interior); scrlInterior.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); + scrlInterior.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); this.panel.add(scrlInterior, BorderLayout.CENTER); this.add(panel); @@ -68,8 +68,11 @@ public class ServerSelector extends JFrame { public Queue getServers() { final Queue widgets = new LinkedList(); - for (ServerDescription desc : new ServerManifestParser().getDescriptions()) { - widgets.add(new ServerWidget(desc)); + ServerDescription[] servers = new ServerManifestParser().getDescriptions(); + if (servers != null) { + for (ServerDescription desc : servers) { + widgets.add(new ServerWidget(desc)); + } } return widgets; }