commit
f3f3b05faf
|
@ -30,21 +30,12 @@ public class FinderWindow extends JFrame {
|
|||
private static final long serialVersionUID = 196896954675968191L;
|
||||
private Container pane;
|
||||
public Project curProject; //TODO
|
||||
public static Preferences pref;
|
||||
public static boolean dataCollect;
|
||||
private final AmidstMenu menuBar;
|
||||
public FinderWindow() throws IOException {
|
||||
//Initialize window
|
||||
super("Amidst v" + Amidst.version());
|
||||
pref = Preferences.userRoot().node(this.getClass().getName());
|
||||
|
||||
boolean first = pref.getBoolean("firstRun", true);
|
||||
if (first) {
|
||||
Google.track("RunFirstTime");
|
||||
} else {
|
||||
Google.track("Run");
|
||||
}
|
||||
pref.putBoolean("firstRun", false);
|
||||
setSize(800,800);
|
||||
//setLookAndFeel();
|
||||
pane = getContentPane();
|
||||
|
@ -113,16 +104,8 @@ public class FinderWindow extends JFrame {
|
|||
Class<?> mc = null;
|
||||
File s = null;
|
||||
|
||||
//Temporary fix -- Should be removed in a few patches.
|
||||
if (pref.getBoolean("osxMistake", true)) {
|
||||
pref.putBoolean("osxMistake", false);
|
||||
pref.remove("jar");
|
||||
}
|
||||
|
||||
try {
|
||||
s = new File(Util.minecraftDirectory, "bin/minecraft.jar");
|
||||
String jar = pref.get("jar", null);
|
||||
ClasspathHacker.addFile((jar != null) ? new File(jar) : s);
|
||||
ClasspathHacker.addFile(Options.instance.jar.get());
|
||||
mc = ClassLoader.getSystemClassLoader().loadClass("net.minecraft.client.Minecraft");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
@ -156,7 +139,8 @@ public class FinderWindow extends JFrame {
|
|||
}
|
||||
|
||||
try {
|
||||
pref.put("jar", s.getCanonicalPath());
|
||||
if (s != null)
|
||||
Options.instance.jar.set(s);
|
||||
|
||||
String typeDump = "";
|
||||
Field fields[] = mc.getDeclaredFields();
|
||||
|
|
|
@ -16,7 +16,6 @@ public class Amidst {
|
|||
Util.setLookAndFeel();
|
||||
Google.startTracking();
|
||||
Google.track("Run");
|
||||
//TODO: load options
|
||||
FinderWindow w = new FinderWindow(); //as long as we design it well, we won’t need a reference to it ;)
|
||||
//TODO: redesign, move to optipns
|
||||
if (args.length > 0) {
|
||||
|
|
|
@ -1,29 +1,42 @@
|
|||
package amidst;
|
||||
|
||||
import javax.swing.JToggleButton.ToggleButtonModel;
|
||||
import amidst.preferences.BooleanPrefModel;
|
||||
import amidst.preferences.FilePrefModel;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.prefs.Preferences;
|
||||
|
||||
/** Currently selected options that change AMIDST’s behavior
|
||||
* TODO: save and load
|
||||
*/
|
||||
public enum Options {
|
||||
instance;
|
||||
|
||||
//per-run preferences. TODO: store elsewhere?
|
||||
public long seed;
|
||||
public String seedText;
|
||||
public ToggleButtonModel showSlimeChunks;
|
||||
public ToggleButtonModel showGrid;
|
||||
public ToggleButtonModel showNetherFortresses;
|
||||
public ToggleButtonModel showIcons;
|
||||
|
||||
//permanent preferences
|
||||
public final FilePrefModel jar;
|
||||
public final BooleanPrefModel showSlimeChunks;
|
||||
public final BooleanPrefModel showGrid;
|
||||
public final BooleanPrefModel showNetherFortresses;
|
||||
public final BooleanPrefModel showIcons;
|
||||
|
||||
//maybe temporary preferences…?
|
||||
public boolean saveEnabled;
|
||||
|
||||
private Options() {
|
||||
seed = 0L;
|
||||
seedText = null;
|
||||
showSlimeChunks = new ToggleButtonModel();
|
||||
showGrid = new ToggleButtonModel();
|
||||
showNetherFortresses = new ToggleButtonModel();
|
||||
showIcons = new ToggleButtonModel();
|
||||
showIcons.setSelected(true);
|
||||
|
||||
Preferences pref = Preferences.userNodeForPackage(Amidst.class);
|
||||
|
||||
jar = new FilePrefModel( pref, "jar", new File(Util.minecraftDirectory, "bin/minecraft.jar"));
|
||||
showSlimeChunks = new BooleanPrefModel(pref, "slimeChunks", false);
|
||||
showGrid = new BooleanPrefModel(pref, "grid", false);
|
||||
showNetherFortresses = new BooleanPrefModel(pref, "netherFortresses", false);
|
||||
showIcons = new BooleanPrefModel(pref, "icons", true);
|
||||
|
||||
saveEnabled = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
package amidst.preferences;
|
||||
|
||||
import javax.swing.JToggleButton.ToggleButtonModel;
|
||||
import java.util.prefs.Preferences;
|
||||
|
||||
/** Autosaving ToggleButtonModel
|
||||
*/
|
||||
public class BooleanPrefModel extends ToggleButtonModel implements PrefModel<Boolean> {
|
||||
private final String key;
|
||||
private final Preferences pref;
|
||||
|
||||
public BooleanPrefModel(Preferences pref, String key, boolean selected) {
|
||||
super();
|
||||
this.pref = pref;
|
||||
this.key = key;
|
||||
//if the preference doesn’t exist, set it,
|
||||
//else sync the ToggleButtonModel’s status
|
||||
set(pref.getBoolean(key, selected));
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public Boolean get() {
|
||||
assert pref.get(key, null) != null && pref.getBoolean(key, false) == super.isSelected();
|
||||
return super.isSelected();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSelected() {
|
||||
return get();
|
||||
}
|
||||
|
||||
public void set(Boolean value) {
|
||||
super.setSelected(value);
|
||||
pref.putBoolean(key, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelected(boolean value) {
|
||||
set(value);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package amidst.preferences;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.prefs.Preferences;
|
||||
|
||||
/** Autosaving File model
|
||||
*/
|
||||
public class FilePrefModel implements PrefModel<File> {
|
||||
private final String key;
|
||||
private final Preferences pref;
|
||||
|
||||
public FilePrefModel(Preferences pref, String key, File init) {
|
||||
super();
|
||||
this.pref = pref;
|
||||
this.key = key;
|
||||
if (pref.get(key, null) == null)
|
||||
set(init);
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public File get() {
|
||||
String path = pref.get(key, null);
|
||||
assert path != null;
|
||||
return new File(path);
|
||||
}
|
||||
|
||||
public void set(File value) {
|
||||
try {
|
||||
pref.put(key, value.getCanonicalPath());
|
||||
} catch (IOException ignored) {
|
||||
pref.put(key, value.getPath());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package amidst.preferences;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/** Backed by a Preferences instance, saves and loads its value from and to it.
|
||||
* TODO: test the fuck out of this
|
||||
*/
|
||||
public interface PrefModel<T> {
|
||||
String getKey();
|
||||
|
||||
public T get();
|
||||
public void set(T value) throws IOException;
|
||||
}
|
Loading…
Reference in New Issue