diff --git a/core/src/processing/data/JSONArray.java b/core/src/processing/data/JSONArray.java index 0a8a1a678..4ce4dbf48 100644 --- a/core/src/processing/data/JSONArray.java +++ b/core/src/processing/data/JSONArray.java @@ -1,5 +1,16 @@ -/* +package processing.data; +// This code has been modified heavily to more closely match the rest of the +// Processing API. In the spirit of the rest of the project, where we try to +// keep the API as simple as possible, we have erred on the side of being +// conservative in choosing which functions to include, since we haven't yet +// decided what's truly necessary. Power users looking for a full-featured +// version can use the original version from json.org, or one of the many +// other APIs that are available. As with all Processing API, if there's a +// function that should be added, please let use know, and have others vote: +// http://code.google.com/p/processing/issues/list + +/* Copyright (c) 2002 JSON.org Permission is hereby granted, free of charge, to any person obtaining a copy @@ -23,8 +34,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package processing.data; - import java.io.IOException; import java.io.StringWriter; import java.io.Writer; diff --git a/core/src/processing/data/JSONObject.java b/core/src/processing/data/JSONObject.java index 8d424594e..cdb970b36 100644 --- a/core/src/processing/data/JSONObject.java +++ b/core/src/processing/data/JSONObject.java @@ -1,7 +1,16 @@ package processing.data; -/* +// This code has been modified heavily to more closely match the rest of the +// Processing API. In the spirit of the rest of the project, where we try to +// keep the API as simple as possible, we have erred on the side of being +// conservative in choosing which functions to include, since we haven't yet +// decided what's truly necessary. Power users looking for a full-featured +// version can use the original version from json.org, or one of the many +// other APIs that are available. As with all Processing API, if there's a +// function that should be added, please let use know, and have others vote: +// http://code.google.com/p/processing/issues/list +/* Copyright (c) 2002 JSON.org Permission is hereby granted, free of charge, to any person obtaining a copy @@ -936,64 +945,64 @@ public class JSONObject { // } - /** - * Get an optional long value associated with a key, - * or zero if there is no such key or if the value is not a number. - * If the value is a string, an attempt will be made to evaluate it as - * a number. - * - * @param key A key string. - * @return An object which is the value. - */ - public long optLong(String key) { - return this.optLong(key, 0); - } +// /** +// * Get an optional long value associated with a key, +// * or zero if there is no such key or if the value is not a number. +// * If the value is a string, an attempt will be made to evaluate it as +// * a number. +// * +// * @param key A key string. +// * @return An object which is the value. +// */ +// public long optLong(String key) { +// return this.optLong(key, 0); +// } - /** - * Get an optional long value associated with a key, - * or the default if there is no such key or if the value is not a number. - * If the value is a string, an attempt will be made to evaluate it as - * a number. - * - * @param key A key string. - * @param defaultValue The default. - * @return An object which is the value. - */ - public long optLong(String key, long defaultValue) { - try { - return this.getLong(key); - } catch (Exception e) { - return defaultValue; - } - } +// /** +// * Get an optional long value associated with a key, +// * or the default if there is no such key or if the value is not a number. +// * If the value is a string, an attempt will be made to evaluate it as +// * a number. +// * +// * @param key A key string. +// * @param defaultValue The default. +// * @return An object which is the value. +// */ +// public long optLong(String key, long defaultValue) { +// try { +// return this.getLong(key); +// } catch (Exception e) { +// return defaultValue; +// } +// } - /** - * Get an optional string associated with a key. - * It returns an empty string if there is no such key. If the value is not - * a string and is not null, then it is converted to a string. - * - * @param key A key string. - * @return A string which is the value. - */ - public String optString(String key) { - return this.optString(key, ""); - } +// /** +// * Get an optional string associated with a key. +// * It returns an empty string if there is no such key. If the value is not +// * a string and is not null, then it is converted to a string. +// * +// * @param key A key string. +// * @return A string which is the value. +// */ +// public String optString(String key) { +// return this.optString(key, ""); +// } - /** - * Get an optional string associated with a key. - * It returns the defaultValue if there is no such key. - * - * @param key A key string. - * @param defaultValue The default. - * @return A string which is the value. - */ - public String optString(String key, String defaultValue) { - Object object = this.opt(key); - return NULL.equals(object) ? defaultValue : object.toString(); - } +// /** +// * Get an optional string associated with a key. +// * It returns the defaultValue if there is no such key. +// * +// * @param key A key string. +// * @param defaultValue The default. +// * @return A string which is the value. +// */ +// public String optString(String key, String defaultValue) { +// Object object = this.opt(key); +// return NULL.equals(object) ? defaultValue : object.toString(); +// } private void populateMap(Object bean) { @@ -1044,45 +1053,8 @@ public class JSONObject { } - /** - * Put a key/boolean pair in the JSONObject. - * - * @param key A key string. - * @param value A boolean which is the value. - * @return this. - * @throws JSONException If the key is null. - */ - public JSONObject put(String key, boolean value) { - this.put(key, value ? Boolean.TRUE : Boolean.FALSE); - return this; - } - - - /** - * Put a key/value pair in the JSONObject, where the value will be a - * JSONArray which is produced from a Collection. - * @param key A key string. - * @param value A Collection value. - * @return this. - * @throws JSONException - */ - public JSONObject put(String key, Collection value) { - this.put(key, new JSONArray(value)); - return this; - } - - - /** - * Put a key/double pair in the JSONObject. - * - * @param key A key string. - * @param value A double which is the value. - * @return this. - * @throws JSONException If the key is null or if the number is invalid. - */ - public JSONObject put(String key, double value) { - this.put(key, new Double(value)); - return this; + public JSONObject setString(String key, String value) { + return put(key, value); } @@ -1094,7 +1066,7 @@ public class JSONObject { * @return this. * @throws JSONException If the key is null. */ - public JSONObject put(String key, int value) { + public JSONObject setInt(String key, int value) { this.put(key, new Integer(value)); return this; } @@ -1108,26 +1080,85 @@ public class JSONObject { * @return this. * @throws JSONException If the key is null. */ - public JSONObject put(String key, long value) { + public JSONObject setLong(String key, long value) { this.put(key, new Long(value)); return this; } - /** - * Put a key/value pair in the JSONObject, where the value will be a - * JSONObject which is produced from a Map. - * @param key A key string. - * @param value A Map value. - * @return this. - * @throws JSONException - */ - public JSONObject put(String key, HashMap value) { - this.put(key, new JSONObject(value)); + public JSONObject setFloat(String key, float value) { + this.put(key, new Double(value)); return this; } + /** + * Put a key/double pair in the JSONObject. + * + * @param key A key string. + * @param value A double which is the value. + * @return this. + * @throws JSONException If the key is null or if the number is invalid. + */ + public JSONObject setDouble(String key, double value) { + this.put(key, new Double(value)); + return this; + } + + + /** + * Put a key/boolean pair in the JSONObject. + * + * @param key A key string. + * @param value A boolean which is the value. + * @return this. + * @throws JSONException If the key is null. + */ + public JSONObject setBoolean(String key, boolean value) { + this.put(key, value ? Boolean.TRUE : Boolean.FALSE); + return this; + } + + + public JSONObject setJSONObject(String key, String value) { + return put(key, value); + } + + + public JSONObject setJSONArray(String key, String value) { + return put(key, value); + } + + +// /** +// * Put a key/value pair in the JSONObject, where the value will be a +// * JSONArray which is produced from a Collection. +// * @param key A key string. +// * @param value A Collection value. +// * @return this. +// * @throws JSONException +// */ +// public JSONObject put(String key, Collection value) { +// this.put(key, new JSONArray(value)); +// return this; +// } + + +// /** +// * Put a key/value pair in the JSONObject, where the value will be a +// * JSONObject which is produced from a Map. +// * @param key A key string. +// * @param value A Map value. +// * @return this. +// * @throws JSONException +// */ +// //public JSONObject put(String key, HashMap value) { +// public JSONObject put(String key, Map value) { +// this.put(key, new JSONObject(value)); +// return this; +// } + + /** * Put a key/value pair in the JSONObject. If the value is null, * then the key will be removed from the JSONObject if it is present. @@ -1139,7 +1170,7 @@ public class JSONObject { * @throws JSONException If the value is non-finite number * or if the key is null. */ - public JSONObject put(String key, Object value) { + private JSONObject put(String key, Object value) { String pooled; if (key == null) { throw new RuntimeException("Null key."); @@ -1172,7 +1203,7 @@ public class JSONObject { * @return his. * @throws JSONException if the key is a duplicate */ - public JSONObject putOnce(String key, Object value) { + private JSONObject putOnce(String key, Object value) { if (key != null && value != null) { if (this.opt(key) != null) { throw new RuntimeException("Duplicate key \"" + key + "\""); @@ -1183,22 +1214,22 @@ public class JSONObject { } - /** - * Put a key/value pair in the JSONObject, but only if the - * key and the value are both non-null. - * @param key A key string. - * @param value An object which is the value. It should be of one of these - * types: Boolean, Double, Integer, JSONArray, JSONObject, Long, String, - * or the JSONObject.NULL object. - * @return this. - * @throws JSONException If the value is a non-finite number. - */ - public JSONObject putOpt(String key, Object value) { - if (key != null && value != null) { - this.put(key, value); - } - return this; - } +// /** +// * Put a key/value pair in the JSONObject, but only if the +// * key and the value are both non-null. +// * @param key A key string. +// * @param value An object which is the value. It should be of one of these +// * types: Boolean, Double, Integer, JSONArray, JSONObject, Long, String, +// * or the JSONObject.NULL object. +// * @return this. +// * @throws JSONException If the value is a non-finite number. +// */ +// public JSONObject putOpt(String key, Object value) { +// if (key != null && value != null) { +// this.put(key, value); +// } +// return this; +// } /** @@ -1209,7 +1240,7 @@ public class JSONObject { * @param string A String * @return A String correctly formatted for insertion in a JSON text. */ - public static String quote(String string) { + static protected String quote(String string) { StringWriter sw = new StringWriter(); synchronized (sw.getBuffer()) { try { @@ -1221,7 +1252,7 @@ public class JSONObject { } } - public static Writer quote(String string, Writer w) throws IOException { + static protected Writer quote(String string, Writer w) throws IOException { if (string == null || string.length() == 0) { w.write("\"\""); return w; @@ -1280,6 +1311,7 @@ public class JSONObject { return w; } + /** * Remove a name and its value, if present. * @param key The name to be removed. @@ -1290,13 +1322,14 @@ public class JSONObject { return this.map.remove(key); } + /** * Try to convert a string into a number, boolean, or null. If the string * can't be converted, return the string. * @param string A String. * @return A simple JSON value. */ - public static Object stringToValue(String string) { + static protected Object stringToValue(String string) { Double d; if (string.equals("")) { return string; @@ -1348,7 +1381,7 @@ public class JSONObject { * @param o The object to test. * @throws JSONException If o is a non-finite number. */ - public static void testValidity(Object o) { + static protected void testValidity(Object o) { if (o != null) { if (o instanceof Double) { if (((Double)o).isInfinite() || ((Double)o).isNaN()) { @@ -1365,24 +1398,25 @@ public class JSONObject { } - /** - * Produce a JSONArray containing the values of the members of this - * JSONObject. - * @param names A JSONArray containing a list of key strings. This - * determines the sequence of the values in the result. - * @return A JSONArray of values. - * @throws JSONException If any of the values are non-finite numbers. - */ - public JSONArray toJSONArray(JSONArray names) { - if (names == null || names.size() == 0) { - return null; - } - JSONArray ja = new JSONArray(); - for (int i = 0; i < names.size(); i += 1) { - ja.append(this.opt(names.getString(i))); - } - return ja; - } +// /** +// * Produce a JSONArray containing the values of the members of this +// * JSONObject. +// * @param names A JSONArray containing a list of key strings. This +// * determines the sequence of the values in the result. +// * @return A JSONArray of values. +// * @throws JSONException If any of the values are non-finite numbers. +// */ +// public JSONArray toJSONArray(JSONArray names) { +// if (names == null || names.size() == 0) { +// return null; +// } +// JSONArray ja = new JSONArray(); +// for (int i = 0; i < names.size(); i += 1) { +// ja.append(this.opt(names.getString(i))); +// } +// return ja; +// } + /** * Make a JSON text of this JSONObject. For compactness, no whitespace @@ -1399,7 +1433,7 @@ public class JSONObject { @Override public String toString() { try { - return this.toString(0); + return this.toString(-1); } catch (Exception e) { return null; } @@ -1446,7 +1480,7 @@ public class JSONObject { * with } (right brace). * @throws JSONException If the value is or contains an invalid number. */ - public static String valueToString(Object value) { + static protected String valueToString(Object value) { if (value == null || value.equals(null)) { return "null"; } @@ -1584,6 +1618,7 @@ public class JSONObject { return writer; } + static final void indent(Writer writer, int indent) throws IOException { for (int i = 0; i < indent; i += 1) { writer.write(' '); @@ -1599,42 +1634,44 @@ public class JSONObject { * @return The writer. * @throws JSONException */ - Writer write(Writer writer, int indentFactor, int indent) { + protected Writer write(Writer writer, int indentFactor, int indent) { try { boolean commanate = false; final int length = this.size(); Iterator keys = this.keys(); writer.write('{'); + int actualFactor = (indentFactor == -1) ? 0 : indentFactor; + if (length == 1) { Object key = keys.next(); writer.write(quote(key.toString())); writer.write(':'); - if (indentFactor > 0) { + if (actualFactor > 0) { writer.write(' '); } - writeValue(writer, this.map.get(key), indentFactor, indent); + writeValue(writer, this.map.get(key), actualFactor, indent); } else if (length != 0) { - final int newindent = indent + indentFactor; + final int newindent = indent + actualFactor; while (keys.hasNext()) { Object key = keys.next(); if (commanate) { writer.write(','); } - if (indentFactor > 0) { + if (indentFactor != -1) { writer.write('\n'); } indent(writer, newindent); writer.write(quote(key.toString())); writer.write(':'); - if (indentFactor > 0) { + if (actualFactor > 0) { writer.write(' '); } - writeValue(writer, this.map.get(key), indentFactor, + writeValue(writer, this.map.get(key), actualFactor, newindent); commanate = true; } - if (indentFactor > 0) { + if (indentFactor != -1) { writer.write('\n'); } indent(writer, indent); @@ -1665,28 +1702,27 @@ public class JSONObject { // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . - /** - * Get the hex value of a character (base16). - * @param c A character between '0' and '9' or between 'A' and 'F' or - * between 'a' and 'f'. - * @return An int between 0 and 15, or -1 if c was not a hex digit. - */ - public static int dehexchar(char c) { - if (c >= '0' && c <= '9') { - return c - '0'; - } - if (c >= 'A' && c <= 'F') { - return c - ('A' - 10); - } - if (c >= 'a' && c <= 'f') { - return c - ('a' - 10); - } - return -1; - } +// /** +// * Get the hex value of a character (base16). +// * @param c A character between '0' and '9' or between 'A' and 'F' or +// * between 'a' and 'f'. +// * @return An int between 0 and 15, or -1 if c was not a hex digit. +// */ +// static protected int dehexchar(char c) { +// if (c >= '0' && c <= '9') { +// return c - '0'; +// } +// if (c >= 'A' && c <= 'F') { +// return c - ('A' - 10); +// } +// if (c >= 'a' && c <= 'f') { +// return c - ('a' - 10); +// } +// return -1; +// } static class JSONTokener { - private long character; private boolean eof; private long index; diff --git a/core/todo.txt b/core/todo.txt index eb4fbd343..fa9d3eee3 100644 --- a/core/todo.txt +++ b/core/todo.txt @@ -14,6 +14,7 @@ X Opting not to do this, because we can't remove the decorations on the X window at this point. And re-opening a new winodw is a lot of mess. X Better all around to just encourage the use of sketchFullScreen() X or cmd/ctrl-shift-R in the PDE. +X make notes about methods removed from JSON to be conservative _ PImage.resize() greater than loaded image size hangs Java App @@ -31,13 +32,18 @@ decisions on data X are we comfortable with setInt/Float/etc instead of just set(int, blah) X yes, better to have parity X too weird to have to explain why getXxx() needs types and set() doesn't -_ get/set with Java's 'Map' class? -_ really useful, but leaning toward not including it -_ or leave it in as an advanced feature? +X get/set with Java's 'Map' class? +X really useful, but leaning toward not including it +X or leave it in as an advanced feature? X createXxx() methods less important X XML.parse() - or new XML("") or new XML("tag") _ add parseXML() and parseJSONObject(x) +_ why not HashMap and ArrayList for JSON? +_ JSONObject.has(key) vs XML.hasAttribute(attr) vs HashMap.containsKey() +_ and how it should be handled with hash/dict + + cleaning/earlier C textureWrap() CLAMP and REPEAT now added C begin/endContour() diff --git a/todo.txt b/todo.txt index c96740a27..bc3d4e631 100644 --- a/todo.txt +++ b/todo.txt @@ -21,6 +21,17 @@ X add ESC and cmd/ctrl-W to the Examples window X move token/syntax coloring out of theme.txt and back into preferences X what order should 'recent' menu use? X most recent is at the top +X check on new JDK and how it works on OS X +X http://jdk7.java.net/macportpreview/ +X add retina support to Info.plist +X NSHighResolutionCapable +X true +X add basics of retina support to the toolbar and header +X getDefaultToolkit().getDesktopProperty("apple.awt.contentScaleFactor"); + +_ deal with underscores and "Find in Reference" +_ http://code.google.com/p/processing/issues/detail?id=1474 + _ unable to open the URL link to reference after updated to 2.0b7 _ http://code.google.com/p/processing/issues/detail?id=1465 @@ -870,18 +881,6 @@ _ otherwise updates are going to require reinstall.. _ or that it's gonna need to parse and say "update command line?" _ look into LCD rendering problems w/ Java (see if Lion still a problem) _ fonts were showing up with very different fatness -_ check on new JDK and how it works on OS X -_ http://jdk7.java.net/macportpreview/ -_ retina support -_ also this? -NSHighResolutionCapable -true -_ someone else: -Have you added an NSPrincipalClass to your Info.plist, and are using a JavaApplicationStub with 64-bit? -NSPrincipalClass -NSApplication -Check out the desktop property. Unfortunately, it won't tell you *which* display is running in HiDPI, but it will stay up-to-date with live display changes (like a Retina-display being plugged and unplugged). If you query the property after each GraphicsEnvironment display change event, you should be able to live switch in and out of HiDPI. -java.awt.Toolkit.getDefaultToolkit().getDesktopProperty("apple.awt.contentScaleFactor"); _ cut/copy/paste while saving a sketch on goes to the editor, not save dialog _ http://code.google.com/p/processing/issues/detail?id=997 _ problem with focus traversal and native windows on OS X