Skip to content

Commit

Permalink
Added biome color profile folder and shortcut support.
Browse files Browse the repository at this point in the history
  • Loading branch information
crbednarz committed Dec 5, 2013
1 parent 201441d commit 555ca7f
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/amidst/Amidst.java
Expand Up @@ -24,7 +24,7 @@ public static void main(String args[]) {
Google.startTracking();
Google.track("Run");

BiomeColorProfile.scanAndLoad();
BiomeColorProfile.scan();

new VersionSelectWindow();
}
Expand Down
45 changes: 36 additions & 9 deletions src/amidst/gui/AmidstMenu.java
Expand Up @@ -22,6 +22,7 @@
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;
import java.io.File;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
Expand Down Expand Up @@ -347,6 +348,7 @@ private OptionsMenu() {
setMnemonic(KeyEvent.VK_M);
}
private class BiomeColorMenu extends JMenu {
private ArrayList<JCheckBoxMenuItem> profileCheckboxes = new ArrayList<JCheckBoxMenuItem>();;
private class BiomeProfileActionListener implements ActionListener {
private BiomeColorProfile profile;
private ArrayList<JCheckBoxMenuItem> profileCheckboxes;
Expand All @@ -366,18 +368,43 @@ public void actionPerformed(ActionEvent e) {
}
private BiomeColorMenu() {
super("Biome profile");
ArrayList<JCheckBoxMenuItem> profileCheckboxes = new ArrayList<JCheckBoxMenuItem>();
for (int i = 0; i < BiomeColorProfile.profiles.size(); i++) {
BiomeColorProfile profile = BiomeColorProfile.profiles.get(i);
JCheckBoxMenuItem menuItem = new JCheckBoxMenuItem(profile.name);
menuItem.addActionListener(new BiomeProfileActionListener(profile, menuItem, profileCheckboxes));
profileCheckboxes.add(
menuItem);
add(menuItem);
}

Log.i("Checking for additional biome color profiles.");
File colorProfileFolder = new File("./biome");
scanAndLoad(colorProfileFolder, this);
profileCheckboxes.get(0).setSelected(true);
}

private boolean scanAndLoad(File folder, JMenu menu) {
File[] files = folder.listFiles();
BiomeColorProfile profile;
boolean foundProfiles = false;
for (int i = 0; i < files.length; i++) {
if (files[i].isFile()) {
if ((profile = BiomeColorProfile.createFromFile(files[i])) != null) {
JCheckBoxMenuItem menuItem = new JCheckBoxMenuItem(profile.name);
menuItem.addActionListener(new BiomeProfileActionListener(profile, menuItem, profileCheckboxes));
if (profile.shortcut != null) {
KeyStroke accelerator = KeyStroke.getKeyStroke(profile.shortcut);
if (accelerator != null)
menuItem.setAccelerator(accelerator);
else
Log.i("Unable to create keyboard shortcut from: " + profile.shortcut);
}
menu.add(menuItem);
profileCheckboxes.add(menuItem);
foundProfiles = true;
}
} else {
JMenu subMenu = new JMenu(files[i].getName());
if (scanAndLoad(files[i], subMenu)) {
menu.add(subMenu);
}
}
}
return foundProfiles;
}

}
private class MapOptionsMenu extends JMenu {
private MapOptionsMenu() {
Expand Down
20 changes: 17 additions & 3 deletions src/amidst/preferences/BiomeColorProfile.java
Expand Up @@ -37,11 +37,11 @@ public int toColorInt() {
}
};
public static boolean isEnabled = false;
public static ArrayList<BiomeColorProfile> profiles = new ArrayList<BiomeColorProfile>();

public HashMap<String, BiomeColor> colorMap = new HashMap<String, BiomeColor>();
public int colorArray[] = new int[Biome.length << 1];
public String name;
public String shortcut;

public BiomeColorProfile() {
name = "default";
Expand Down Expand Up @@ -113,7 +113,7 @@ public void activate() {
}


public static void scanAndLoad() {
public static void scan() {
Log.i("Searching for biome color profiles.");
File colorProfileFolder = new File("./biome");

Expand All @@ -127,6 +127,7 @@ public static void scanAndLoad() {
if (!Options.instance.biomeColorProfile.save(defaultProfileFile))
Log.i("Attempted to save default biome color profile, but encountered an error.");

/*
File[] colorProfiles = colorProfileFolder.listFiles();
for (int i = 0; i < colorProfiles.length; i++) {
if (colorProfiles[i].exists() && colorProfiles[i].isFile()) {
Expand All @@ -138,7 +139,20 @@ public static void scanAndLoad() {
Log.i("Unable to load file: " + colorProfiles[i]);
}
}
}
}*/
isEnabled = true;
}

public static BiomeColorProfile createFromFile(File file) {
BiomeColorProfile profile = null;
if (file.exists() && file.isFile()) {
try {
profile = Util.readObject(file, BiomeColorProfile.class);
profile.fillColorArray();
} catch (FileNotFoundException e) {
Log.i("Unable to load file: " + file);
}
}
return profile;
}
}

0 comments on commit 555ca7f

Please sign in to comment.