add caret options to prefs, also modernize prefs code a bit (issue #1136)

This commit is contained in:
benfry
2012-10-23 16:22:00 +00:00
parent 48855177ca
commit 4dff288c98
4 changed files with 87 additions and 86 deletions
+67 -46
View File
@@ -133,13 +133,13 @@ public class Preferences {
// data model
static Hashtable defaults;
static Hashtable table = new Hashtable();;
static HashMap<String,String> defaults;
static HashMap<String,String> table = new HashMap<String,String>();
static File preferencesFile;
static public void init(String commandLinePrefs) {
// static public void init(String commandLinePrefs) {
static public void init() {
// start by loading the defaults, in case something
// important was deleted from the user prefs
try {
@@ -152,55 +152,71 @@ public class Preferences {
// check for platform-specific properties in the defaults
String platformExt = "." + PConstants.platformNames[PApplet.platform];
int platformExtLength = platformExt.length();
Enumeration e = table.keys();
while (e.hasMoreElements()) {
String key = (String) e.nextElement();
// Enumeration e = table.keys();
// while (e.hasMoreElements()) {
// String key = (String) e.nextElement();
// if (key.endsWith(platformExt)) {
// // this is a key specific to a particular platform
// String actualKey = key.substring(0, key.length() - platformExtLength);
// String value = get(key);
// table.put(actualKey, value);
// }
// }
// Get a list of keys that are specific to this platform
ArrayList<String> platformKeys = new ArrayList<String>();
for (String key : table.keySet()) {
if (key.endsWith(platformExt)) {
// this is a key specific to a particular platform
String actualKey = key.substring(0, key.length() - platformExtLength);
String value = get(key);
table.put(actualKey, value);
platformKeys.add(key);
}
}
// Use those platform-specific keys to override
for (String key : platformKeys) {
// this is a key specific to a particular platform
String actualKey = key.substring(0, key.length() - platformExtLength);
String value = get(key);
set(actualKey, value);
}
// clone the hash table
defaults = (Hashtable) table.clone();
defaults = (HashMap<String, String>) table.clone();
// other things that have to be set explicitly for the defaults
setColor("run.window.bgcolor", SystemColor.control);
// Load a prefs file if specified on the command line
if (commandLinePrefs != null) {
// if (commandLinePrefs != null) {
// try {
// load(new FileInputStream(commandLinePrefs));
//
// } catch (Exception poe) {
// Base.showError("Error",
// "Could not read preferences from " +
// commandLinePrefs, poe);
// }
// } else if (!Base.isCommandLine()) {
// next load user preferences file
preferencesFile = Base.getSettingsFile(PREFS_FILE);
if (!preferencesFile.exists()) {
// create a new preferences file if none exists
// saves the defaults out to the file
save();
} else {
// load the previous preferences file
try {
load(new FileInputStream(commandLinePrefs));
load(new FileInputStream(preferencesFile));
} catch (Exception poe) {
Base.showError("Error",
"Could not read preferences from " +
commandLinePrefs, poe);
}
} else if (!Base.isCommandLine()) {
// next load user preferences file
preferencesFile = Base.getSettingsFile(PREFS_FILE);
if (!preferencesFile.exists()) {
// create a new preferences file if none exists
// saves the defaults out to the file
save();
} else {
// load the previous preferences file
try {
load(new FileInputStream(preferencesFile));
} catch (Exception ex) {
Base.showError("Error reading preferences",
"Error reading the preferences file. " +
"Please delete (or move)\n" +
preferencesFile.getAbsolutePath() +
" and restart Processing.", ex);
}
} catch (Exception ex) {
Base.showError("Error reading preferences",
"Error reading the preferences file. " +
"Please delete (or move)\n" +
preferencesFile.getAbsolutePath() +
" and restart Processing.", ex);
}
// }
}
PApplet.useNativeSelect = Preferences.getBoolean("chooser.files.native");
@@ -790,10 +806,15 @@ public class Preferences {
// Fix for 0163 to properly use Unicode when writing preferences.txt
PrintWriter writer = PApplet.createWriter(preferencesFile);
Enumeration e = table.keys(); //properties.propertyNames();
while (e.hasMoreElements()) {
String key = (String) e.nextElement();
writer.println(key + "=" + ((String) table.get(key)));
// Enumeration e = table.keys(); //properties.propertyNames();
// while (e.hasMoreElements()) {
// String key = (String) e.nextElement();
// writer.println(key + "=" + ((String) table.get(key)));
// }
String[] keyList = table.keySet().toArray(new String[table.size()]);
keyList = PApplet.sort(keyList);
for (String key : keyList) {
writer.println(key + "=" + table.get(key));
}
writer.flush();
@@ -815,7 +836,7 @@ public class Preferences {
//}
static public String get(String attribute /*, String defaultValue */) {
return (String) table.get(attribute);
return table.get(attribute);
/*
//String value = (properties != null) ?
//properties.getProperty(attribute) : applet.getParameter(attribute);
@@ -828,7 +849,7 @@ public class Preferences {
static public String getDefault(String attribute) {
return (String) defaults.get(attribute);
return defaults.get(attribute);
}
@@ -137,7 +137,8 @@ public class PdeTextAreaDefaults extends TextAreaDefaults {
editable = true;
electricScroll = 3;
caretVisible = true;
caretBlinks = true;
caretBlinks = Preferences.getBoolean("editor.caret.blink");
blockCaret = Preferences.getBoolean("editor.caret.block");
cols = 80;
// Set the number of rows lower to avoid layout badness with large fonts
// http://code.google.com/p/processing/issues/detail?id=1275
@@ -45,38 +45,4 @@ public class TextAreaDefaults {
public Color fgcolor;
public Color bgcolor;
public boolean antialias;
/*
private static final TextAreaDefaults DEFAULTS = new TextAreaDefaults();
static {
DEFAULTS.inputHandler = new DefaultInputHandler();
DEFAULTS.inputHandler.addDefaultKeyBindings();
DEFAULTS.document = new SyntaxDocument();
DEFAULTS.editable = true;
DEFAULTS.caretVisible = true;
DEFAULTS.caretBlinks = true;
DEFAULTS.electricScroll = 3;
DEFAULTS.cols = 80;
DEFAULTS.rows = 25;
DEFAULTS.styles = SyntaxUtilities.getDefaultSyntaxStyles();
DEFAULTS.caretColor = Color.red;
DEFAULTS.selectionColor = new Color(0xccccff);
DEFAULTS.lineHighlightColor = new Color(0xe0e0e0);
DEFAULTS.lineHighlight = true;
DEFAULTS.bracketHighlightColor = Color.black;
DEFAULTS.bracketHighlight = true;
DEFAULTS.eolMarkerColor = new Color(0x009999);
DEFAULTS.eolMarkers = true;
DEFAULTS.paintInvalid = true;
}
/// Returns a new TextAreaDefaults object with the default values filled in.
public static TextAreaDefaults getDefaults()
{
return DEFAULTS;
}
*/
}
+18 -5
View File
@@ -6,10 +6,27 @@ X remove preferences that refer to applets
X remove applet folder from the Java stuff
X remove old 'cmd' folder from the Java build directory
X Import statements are executed within multiline comments
_ http://code.google.com/p/processing/issues/detail?id=911
X http://code.google.com/p/processing/issues/detail?id=911
X write preferences file sorted
X Major change to how lib folder is found, hopefully handles cmd line better
o caretBlinks always true.. just remove the pref?
o blockCaret always false.. remove it?
X report from someone about blinking caret
X http://code.google.com/p/processing/issues/detail?id=1136
_ see if commander is still headless
_ don't use --request on OS X, not available
_ check to see if sketchbook is getting picked up for cmd line
editor.caret.blink = true
editor.caret.block = false
_ processing-java ClassNotFoundException: BatchCompiler (Linux)
_ http://code.google.com/p/processing/issues/detail?id=1334
2.0 FINAL / library/tool/mode manager cleanup
_ a couple notes
@@ -19,10 +36,6 @@ _ http://code.google.com/p/processing/issues/detail?id=1093
_ TextAreaDefaults
_ is editable in use?
_ what's electricScroll?
_ caretBlinks always true.. just remove the pref?
_ blockCaret always false.. remove it?
_ report from someone about blinking caret
_ http://code.google.com/p/processing/issues/detail?id=1136
_ excessive CPU usage of PDE after using library manager
_ http://code.google.com/p/processing/issues/detail?id=1036
_ remove PdeKeyListener, roll it into the Java InputHandler for JEditTextArea