From 842f977c6e582494b575ba6fef3e2b3d6d9dda37 Mon Sep 17 00:00:00 2001 From: Scott Murray Date: Sat, 1 Jun 2013 16:07:01 -0700 Subject: [PATCH 01/10] Added reference for JSONObject methods getJSONObject(), setJSONObject(), setJSONArray() --- core/src/processing/data/JSONObject.java | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/core/src/processing/data/JSONObject.java b/core/src/processing/data/JSONObject.java index 50fd5525c..52e82066e 100644 --- a/core/src/processing/data/JSONObject.java +++ b/core/src/processing/data/JSONObject.java @@ -666,11 +666,11 @@ public class JSONObject { /** * Get the JSONArray value associated with a key. * - * @brief Gets the JSONArray value associated with a key * @webref jsonobject:method - * @param key A key string - * @return A JSONArray which is the value. - * @throws JSONException if the key is not found or if the value is not a JSONArray. + * @brief Gets the JSONArray value associated with a key + * @param key a key string + * @return A JSONArray which is the value. + * @throws JSONException if the key is not found or if the value is not a JSONArray. */ public JSONArray getJSONArray(String key) { Object object = this.get(key); @@ -684,11 +684,11 @@ public class JSONObject { /** * Get the JSONObject value associated with a key. * - * @param key A key string. - * @return A JSONObject which is the value. - * @throws JSONException if the key is not found or if the value is not a JSONObject. * @webref jsonobject:method * @brief Gets the JSONObject value associated with a key + * @param key a key string + * @return A JSONObject which is the value. + * @throws JSONException if the key is not found or if the value is not a JSONObject. */ public JSONObject getJSONObject(String key) { Object object = this.get(key); @@ -1190,7 +1190,9 @@ public class JSONObject { /** * @webref jsonobject:method - * @brief To come... + * @brief Sets the JSONObject value associated with a key + * @param key a key string + * @param value value to assign */ public JSONObject setJSONObject(String key, JSONObject value) { return put(key, value); @@ -1198,7 +1200,9 @@ public class JSONObject { /** * @webref jsonobject:method - * @brief To come... + * @brief Sets the JSONArray value associated with a key + * @param key a key string + * @param value value to assign */ public JSONObject setJSONArray(String key, JSONArray value) { return put(key, value); From d16d1db42d38d7f11470d310215080d8554f08d2 Mon Sep 17 00:00:00 2001 From: Scott Murray Date: Sat, 1 Jun 2013 16:42:03 -0700 Subject: [PATCH 02/10] Added reference for JSONObject methods getInt(), getFloat(), getString(), and getBoolean() --- core/src/processing/data/JSONObject.java | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/core/src/processing/data/JSONObject.java b/core/src/processing/data/JSONObject.java index 52e82066e..d80a33b27 100644 --- a/core/src/processing/data/JSONObject.java +++ b/core/src/processing/data/JSONObject.java @@ -555,11 +555,11 @@ public class JSONObject { /** * Gets the String associated with a key * - * @param key A key string. - * @return A string which is the value. - * @throws JSONException if there is no string value for the key. * @webref jsonobject:method * @brief Gets the string associated with a key + * @param key a key string + * @return A string which is the value. + * @throws JSONException if there is no string value for the key. */ public String getString(String key) { Object object = this.get(key); @@ -573,12 +573,12 @@ public class JSONObject { /** * Gets the int value associated with a key * - * @param key A key string. - * @return The integer value. - * @throws JSONException if the key is not found or if the value cannot - * be converted to an integer. * @webref jsonobject:method * @brief Gets the int value associated with a key + * @param key a key string + * @return The integer value. + * @throws JSONException if the key is not found or if the value cannot + * be converted to an integer. */ public int getInt(String key) { Object object = this.get(key); @@ -613,7 +613,8 @@ public class JSONObject { /** * @webref jsonobject:method - * @brief To come... + * @brief Gets the float value associated with a key + * @param key a key string */ public float getFloat(String key) { return (float) getDouble(key); @@ -642,11 +643,11 @@ public class JSONObject { /** * Get the boolean value associated with a key. * - * @param key A key string. - * @return The truth. - * @throws JSONException if the value is not a Boolean or the String "true" or "false". * @webref jsonobject:method * @brief Gets the boolean value associated with a key + * @param key a key string + * @return The truth. + * @throws JSONException if the value is not a Boolean or the String "true" or "false". */ public boolean getBoolean(String key) { Object object = this.get(key); From 6496f3376044e0739896344b495d884638c770e2 Mon Sep 17 00:00:00 2001 From: Scott Murray Date: Sat, 1 Jun 2013 17:23:02 -0700 Subject: [PATCH 03/10] Added reference for JSONObject methods setInt(), setFloat(), setString(), and setBoolean() --- core/src/processing/data/JSONObject.java | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/core/src/processing/data/JSONObject.java b/core/src/processing/data/JSONObject.java index d80a33b27..c155a20e3 100644 --- a/core/src/processing/data/JSONObject.java +++ b/core/src/processing/data/JSONObject.java @@ -1114,7 +1114,9 @@ public class JSONObject { /** * @webref jsonobject:method - * @brief To come... + * @brief Put a key/String pair in the JSONObject + * @param key a key string + * @param value the value to assign */ public JSONObject setString(String key, String value) { return put(key, value); @@ -1124,12 +1126,12 @@ public class JSONObject { /** * Put a key/int pair in the JSONObject. * - * @param key A key string. - * @param value An int which is the value. - * @return this. - * @throws JSONException If the key is null. * @webref jsonobject:method * @brief Put a key/int pair in the JSONObject + * @param key a key string + * @param value the value to assign + * @return this. + * @throws JSONException If the key is null. */ public JSONObject setInt(String key, int value) { this.put(key, new Integer(value)); @@ -1152,7 +1154,9 @@ public class JSONObject { /** * @webref jsonobject:method - * @brief To come... + * @brief Put a key/float pair in the JSONObject + * @param key a key string + * @param value the value to assign */ public JSONObject setFloat(String key, float value) { this.put(key, new Double(value)); @@ -1177,12 +1181,12 @@ 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. * @webref jsonobject:method * @brief Put a key/boolean pair in the JSONObject + * @param key a key string + * @param value the value to assign + * @return this. + * @throws JSONException If the key is null. */ public JSONObject setBoolean(String key, boolean value) { this.put(key, value ? Boolean.TRUE : Boolean.FALSE); From 5c7c627a2ba056542b558334786e61a7b9a873ce Mon Sep 17 00:00:00 2001 From: Scott Murray Date: Sat, 1 Jun 2013 17:53:11 -0700 Subject: [PATCH 04/10] Added reference for JSONArray methods size() and remove() --- core/src/processing/data/JSONArray.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/src/processing/data/JSONArray.java b/core/src/processing/data/JSONArray.java index a12d7d197..9deebdba8 100644 --- a/core/src/processing/data/JSONArray.java +++ b/core/src/processing/data/JSONArray.java @@ -978,7 +978,7 @@ public class JSONArray { * Get the number of elements in the JSONArray, included nulls. * * @webref jsonarray:method - * @brief Gets the number of elements in the JSONArray, included nulls + * @brief Gets the number of elements in the JSONArray * @return The length (or size). */ public int size() { @@ -1001,8 +1001,8 @@ public class JSONArray { * Remove an index and close the hole. * * @webref jsonarray:method - * @brief Remove an index and close the hole - * @param index The index of the element to be removed. + * @brief Removes an element + * @param index the index value of the element to be removed * @return The value that was associated with the index, or null if there was no value. */ public Object remove(int index) { From 9c4437f33a42869c2491a346527a594c6300868c Mon Sep 17 00:00:00 2001 From: Daniel Shiffman Date: Sat, 1 Jun 2013 22:28:43 -0400 Subject: [PATCH 05/10] new IntList example --- .../IntListLottery/IntListLottery.pde | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 java/examples/Topics/Advanced Data/IntListLottery/IntListLottery.pde diff --git a/java/examples/Topics/Advanced Data/IntListLottery/IntListLottery.pde b/java/examples/Topics/Advanced Data/IntListLottery/IntListLottery.pde new file mode 100644 index 000000000..b4387a877 --- /dev/null +++ b/java/examples/Topics/Advanced Data/IntListLottery/IntListLottery.pde @@ -0,0 +1,66 @@ + +IntList lottery; +IntList results; +IntList ticket; + +void setup() { + size(640, 360); + frameRate(30); + lottery = new IntList(); + results = new IntList(); + ticket = new IntList(); + // Let's add some numbers to our list + for (int i = 0; i < 20; i++) { + lottery.append(i); + } + + for (int i = 0; i < 5; i++) { + int index = int(random(lottery.size())); + ticket.append(lottery.get(index)); + } +} + +void draw() { + background(51); + + lottery.shuffle(); + + showList(lottery,16,48); + showList(results,16,100); + showList(ticket,16,140); + + for (int i = 0; i < results.size(); i++) { + if (results.get(i) == ticket.get(i)) { + fill(0,255,0,100); + } else { + fill(255,0,0,100); + } + ellipse(16+i*32, 140, 24, 24); + } + + if (frameCount % 30 == 0) { + if (results.size() < 5) { + int val = lottery.get(0); + lottery.remove(0); + results.append(val); + } else { + for (int i = 0; i < results.size(); i++) { + lottery.append(results.get(i)); + } + results.clear(); + } + } +} + +void showList(IntList list, float x, float y) { + for (int i = 0; i < list.size(); i++) { + int val = list.get(i); + stroke(255); + noFill(); + ellipse(x+i*32, y, 24, 24); + textAlign(CENTER); + fill(255); + text(val, x+i*32, y+6); + } +} + From 0339b77d714532c11802c610882fdb0a566c4e4c Mon Sep 17 00:00:00 2001 From: Daniel Shiffman Date: Sat, 1 Jun 2013 22:34:37 -0400 Subject: [PATCH 06/10] small fixes to lottery example --- .../IntListLottery/IntListLottery.pde | 33 ++++++++++--------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/java/examples/Topics/Advanced Data/IntListLottery/IntListLottery.pde b/java/examples/Topics/Advanced Data/IntListLottery/IntListLottery.pde index b4387a877..1a12c58af 100644 --- a/java/examples/Topics/Advanced Data/IntListLottery/IntListLottery.pde +++ b/java/examples/Topics/Advanced Data/IntListLottery/IntListLottery.pde @@ -24,30 +24,33 @@ void draw() { background(51); lottery.shuffle(); - - showList(lottery,16,48); - showList(results,16,100); - showList(ticket,16,140); - + + showList(lottery, 16, 48); + showList(results, 16, 100); + showList(ticket, 16, 140); + for (int i = 0; i < results.size(); i++) { if (results.get(i) == ticket.get(i)) { - fill(0,255,0,100); - } else { - fill(255,0,0,100); + fill(0, 255, 0, 100); + } + else { + fill(255, 0, 0, 100); } ellipse(16+i*32, 140, 24, 24); } if (frameCount % 30 == 0) { + // Pick a new lottery number! if (results.size() < 5) { - int val = lottery.get(0); - lottery.remove(0); - results.append(val); + int val = lottery.get(0); + lottery.remove(0); + results.append(val); } else { - for (int i = 0; i < results.size(); i++) { - lottery.append(results.get(i)); - } - results.clear(); + // Ok we picked five numbers, let's reset + for (int i = 0; i < results.size(); i++) { + lottery.append(results.get(i)); + } + results.clear(); } } } From 9d7026c2bf1be29c6706377d4d4c14e179ca2127 Mon Sep 17 00:00:00 2001 From: REAS Date: Sat, 1 Jun 2013 20:23:23 -0700 Subject: [PATCH 07/10] Arrows for GUI, new keywords and reference --- app/src/processing/app/EditorToolbar.java | 2 +- java/keywords.txt | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/app/src/processing/app/EditorToolbar.java b/app/src/processing/app/EditorToolbar.java index 1e902a713..7981cb27e 100644 --- a/app/src/processing/app/EditorToolbar.java +++ b/app/src/processing/app/EditorToolbar.java @@ -78,7 +78,7 @@ public abstract class EditorToolbar extends JComponent implements MouseInputList protected ArrayList