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.
This commit is contained in:
Dane
2013-06-21 11:36:38 -04:00
parent 9e99eea72c
commit 3607799354
3 changed files with 79 additions and 53 deletions
+72 -49
View File
@@ -1,12 +1,13 @@
package org.parabot.core; package org.parabot.core;
import java.io.File; import java.io.File;
import java.util.HashMap;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.Map;
import java.util.Queue; import java.util.Queue;
import java.util.Random; import java.util.Random;
import javax.swing.JFileChooser; import javax.swing.JFileChooser;
import javax.swing.filechooser.FileSystemView;
import org.parabot.environment.OperatingSystem; import org.parabot.environment.OperatingSystem;
@@ -18,75 +19,96 @@ import org.parabot.environment.OperatingSystem;
*/ */
public class Directories { public class Directories {
/** private static Map<String, File> cached = new HashMap<String, File>();
* Gets default user directory
* @return default user director static {
*/
public static File getDefaultDirectory() {
switch (OperatingSystem.getOS()) { switch (OperatingSystem.getOS()) {
case WINDOWS: case WINDOWS:
JFileChooser fr = new JFileChooser(); cached.put("Root", new JFileChooser().getFileSystemView().getDefaultDirectory());
FileSystemView fw = fr.getFileSystemView(); break;
return fw.getDefaultDirectory(); default:
default: cached.put("Root", new File(System.getProperty("user.home")));
return new File(System.getProperty("user.home"));
} }
}
cached.put("Root", getDefaultDirectory());
/** cached.put("Workspace", new File(cached.get("Root"), "/Parabot/"));
* Gets bot workspace cached.put("Sources", new File(cached.get("Root"), "/Parabot/scripts/sources/"));
* @return workspace of bot cached.put("Compiled", new File(cached.get("Root"), "/Parabot/scripts/compiled/"));
*/ cached.put("Resources", new File(cached.get("Root"), "/Parabot/scripts/resources/"));
public static File getWorkspace() { cached.put("Settings", new File(cached.get("Root"), "/Parabot/settings/"));
return new File(getDefaultDirectory(), "/Parabot/"); cached.put("Servers", new File(cached.get("Root"), "/Parabot/servers/"));
}
/**
* Get script sources path
* @return script sources path
*/
public static File getScriptSourcesPath() {
return new File(getDefaultDirectory(), "/Parabot/scripts/sources/");
} }
/** /**
* Get script compiled path * Returns the root directory outside of the main Parabot folder.
* @return script compiled path *
* @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() { public static File getScriptCompiledPath() {
return new File(getDefaultDirectory(), "/Parabot/scripts/compiled/"); return cached.get("Compiled");
} }
/** /**
* Get script compiled path * Returns the scripts resources folder.
* @return script compiled path *
* @return
*/ */
public static File getResourcesPath() { public static File getResourcesPath() {
return new File(getDefaultDirectory(), "/Parabot/scripts/resources/"); return cached.get("Resources");
} }
/** /**
* Gets settings directory * Returns the Parabot settings folder.
* @return settings directory *
* @return
*/ */
public static File getSettingsPath() { public static File getSettingsPath() {
return new File(getDefaultDirectory(), "/Parabot/settings/"); return cached.get("Settings");
} }
/** /**
* Gets servers directory * Returns the Parabot servers folder.
* @return servers directory *
* @return
*/ */
public static File getServerPath() { public static File getServerPath() {
return new File(getDefaultDirectory(), "/Parabot/servers/"); return cached.get("Servers");
} }
/** /**
* Validates all directories and makes them if necessary * Validates all directories and makes them if necessary
*/ */
public static void validate() { public static void validate() {
final File defaultPath = getDefaultDirectory(); final File defaultPath = getDefaultDirectory();
if(defaultPath == null || !defaultPath.exists()) { if (defaultPath == null || !defaultPath.exists()) {
throw new RuntimeException("Default path not found"); throw new RuntimeException("Default path not found");
} }
final Queue<File> files = new LinkedList<File>(); final Queue<File> files = new LinkedList<File>();
@@ -96,17 +118,18 @@ public class Directories {
files.add(getScriptSourcesPath()); files.add(getScriptSourcesPath());
files.add(getScriptCompiledPath()); files.add(getScriptCompiledPath());
files.add(getResourcesPath()); files.add(getResourcesPath());
while(files.size() > 0) { while (files.size() > 0) {
final File file = files.poll(); final File file = files.poll();
if(!file.exists()) { if (!file.exists()) {
file.mkdirs(); file.mkdirs();
} }
} }
} }
private static File temp = null; private static File temp = null;
public static File getTempDirectory() { public static File getTempDirectory() {
if(temp != null) { if (temp != null) {
return temp; return temp;
} }
int randomNum = new Random().nextInt(999999999); int randomNum = new Random().nextInt(999999999);
+1 -1
View File
@@ -76,7 +76,7 @@ public class BotUI extends JFrame implements ActionListener {
y += iGameHeight; y += iGameHeight;
JScrollPane scrlConsole = LogArea.getInstance(); JScrollPane scrlConsole = LogArea.getInstance();
scrlConsole.setPreferredSize(new Dimension(765, iLogHeight)); scrlConsole.setPreferredSize(new Dimension(765, iLogHeight - 15));
toolbar.setLocation(x, y); toolbar.setLocation(x, y);
panel.add(toolbar); panel.add(toolbar);
@@ -11,7 +11,6 @@ import javax.swing.JScrollPane;
import org.parabot.core.desc.ServerDescription; import org.parabot.core.desc.ServerDescription;
import org.parabot.core.parsers.ServerManifestParser; 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.utils.SwingUtil;
import org.parabot.core.ui.widgets.ServerWidget; import org.parabot.core.ui.widgets.ServerWidget;
@@ -58,6 +57,7 @@ public class ServerSelector extends JFrame {
JScrollPane scrlInterior = new JScrollPane(interior); JScrollPane scrlInterior = new JScrollPane(interior);
scrlInterior.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); scrlInterior.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
scrlInterior.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
this.panel.add(scrlInterior, BorderLayout.CENTER); this.panel.add(scrlInterior, BorderLayout.CENTER);
this.add(panel); this.add(panel);
@@ -68,8 +68,11 @@ public class ServerSelector extends JFrame {
public Queue<ServerWidget> getServers() { public Queue<ServerWidget> getServers() {
final Queue<ServerWidget> widgets = new LinkedList<ServerWidget>(); final Queue<ServerWidget> widgets = new LinkedList<ServerWidget>();
for (ServerDescription desc : new ServerManifestParser().getDescriptions()) { ServerDescription[] servers = new ServerManifestParser().getDescriptions();
widgets.add(new ServerWidget(desc)); if (servers != null) {
for (ServerDescription desc : servers) {
widgets.add(new ServerWidget(desc));
}
} }
return widgets; return widgets;
} }