diff --git a/core/src/processing/core/PApplet.java b/core/src/processing/core/PApplet.java index 20b8ab97d..2cf4df079 100644 --- a/core/src/processing/core/PApplet.java +++ b/core/src/processing/core/PApplet.java @@ -6009,24 +6009,25 @@ public class PApplet extends Applet // DATA I/O - /** - * @webref input:files - * @brief Creates a new XML object - * @param name the name to be given to the root element of the new XML object - * @return an XML object, or null - * @see XML - * @see PApplet#loadXML(String) - * @see PApplet#parseXML(String) - * @see PApplet#saveXML(XML, String) - */ - public XML createXML(String name) { - try { - return new XML(name); - } catch (Exception e) { - e.printStackTrace(); - return null; - } - } + +// /** +// * @webref input:files +// * @brief Creates a new XML object +// * @param name the name to be given to the root element of the new XML object +// * @return an XML object, or null +// * @see XML +// * @see PApplet#loadXML(String) +// * @see PApplet#parseXML(String) +// * @see PApplet#saveXML(XML, String) +// */ +// public XML createXML(String name) { +// try { +// return new XML(name); +// } catch (Exception e) { +// e.printStackTrace(); +// return null; +// } +// } /** @@ -6103,6 +6104,11 @@ public class PApplet extends Applet } + public JSONObject parseJSONObject(String input) { + return new JSONObject(new StringReader(input)); + } + + public JSONObject loadJSONObject(String filename) { //JSONTokener tokener = new JSONTokener(createReader(filename)); //return new JSONObject(tokener); @@ -6120,6 +6126,11 @@ public class PApplet extends Applet } + public JSONArray parseJSONArray(String input) { + return new JSONArray(new StringReader(input)); + } + + public JSONArray loadJSONArray(String filename) { // JSONTokener tokener = new JSONTokener(createReader(filename)); // return new JSONArray(tokener); @@ -6138,15 +6149,15 @@ public class PApplet extends Applet - /** - * @webref input:files - * @see Table - * @see PApplet#loadTable(String) - * @see PApplet#saveTable(Table, String) - */ - public Table createTable() { - return new Table(); - } +// /** +// * @webref input:files +// * @see Table +// * @see PApplet#loadTable(String) +// * @see PApplet#saveTable(Table, String) +// */ +// public Table createTable() { +// return new Table(); +// } /** diff --git a/core/src/processing/data/JSONObject.java b/core/src/processing/data/JSONObject.java index e934fbdbe..02d18b77b 100644 --- a/core/src/processing/data/JSONObject.java +++ b/core/src/processing/data/JSONObject.java @@ -129,7 +129,6 @@ public class JSONObject { * undefined. */ private static final class Null { - /** * There is only intended to be a single instance of the NULL object, * so the clone method returns itself. diff --git a/core/src/processing/data/Table.java b/core/src/processing/data/Table.java index 15ca6c838..f8e229f64 100644 --- a/core/src/processing/data/Table.java +++ b/core/src/processing/data/Table.java @@ -200,7 +200,9 @@ public class Table { if (dotIndex != -1) { extension = filename.substring(dotIndex + 1).toLowerCase(); if (!extension.equals("csv") && - !extension.equals("tsv")) { + !extension.equals("tsv") && + !extension.equals("html") && + !extension.equals("bin")) { // ignore extension extension = null; } @@ -628,29 +630,37 @@ public class Table { public boolean save(OutputStream output, String options) { PrintWriter writer = PApplet.createWriter(output); + String opt = null; if (options != null) { String[] opts = PApplet.splitTokens(options, ", "); - for (String opt : opts) { - if (opt.equals("csv")) { - writeCSV(writer); - } else if (opt.equals("tsv")) { - writeTSV(writer); - } else if (opt.equals("html")) { - writeHTML(writer); - } else if (opt.equals("bin")) { - try { - saveBinary(output); - } catch (IOException e) { - e.printStackTrace(); - return false; - } - } else { - throw new IllegalArgumentException("'" + opt + "' not understood. " + - "Only csv, tsv, bin, and html are " + - "accepted as save parameters"); - } + opt = opts[opts.length - 1]; + if (!opt.equals("csv") && + !opt.equals("tsv") && + !opt.equals("html") && + !opt.equals("bin")) { + throw new IllegalArgumentException("'" + opt + "' not understood. " + + "Only csv, tsv, bin, and html are " + + "accepted as save parameters"); + } + } else { + opt = "tsv"; // fall back to saving as TSV + } + + if (opt.equals("csv")) { + writeCSV(writer); + } else if (opt.equals("tsv")) { + writeTSV(writer); + } else if (opt.equals("html")) { + writeHTML(writer); + } else if (opt.equals("bin")) { + try { + saveBinary(output); + } catch (IOException e) { + e.printStackTrace(); + return false; } } + writer.flush(); writer.close(); return true; } diff --git a/core/src/processing/data/XML.java b/core/src/processing/data/XML.java index f9e65fd93..bc1fd7fac 100644 --- a/core/src/processing/data/XML.java +++ b/core/src/processing/data/XML.java @@ -167,14 +167,18 @@ public class XML implements Serializable { /** * @param name description TBD */ - // TODO is there a more efficient way of doing this? wow. - public XML(String name) throws ParserConfigurationException { - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - DocumentBuilder builder = factory.newDocumentBuilder(); - Document document = builder.newDocument(); - node = document.createElement(name); -// this.name = name; - this.parent = null; + public XML(String name) { + try { + // TODO is there a more efficient way of doing this? wow. + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder = factory.newDocumentBuilder(); + Document document = builder.newDocument(); + node = document.createElement(name); + this.parent = null; + + } catch (ParserConfigurationException pce) { + throw new RuntimeException(pce); + } } diff --git a/core/todo.txt b/core/todo.txt index be83dc7fe..65f9d7dce 100644 --- a/core/todo.txt +++ b/core/todo.txt @@ -11,86 +11,101 @@ X getIntContent() X getFloatContent() X getContent() or getStringContent()? X switch to CATEGORY instead of CATEGORICAL +X removed createXML() and createTable()... just use 'new' for these https://blogs.oracle.com/CoreJavaTechTips/entry/using_enhanced_for_loops_with -table -X do we need getColumnType() inside TableRow? -X also inside Table -X also do we make the constants public? - - -// function that will convert awful CSV to TSV.. or something else? -// maybe to write binary instead? then read the binary file once it's ok? - -// if loading from a File object (or PApplet is passed in and we can check online) -// then check the (probable) size of the file before loading - -// implement binary tables - -// no column max/min functions since it needs to be per-datatype -// better to use float mx = max(float(getColumn(3))); -// *** but what to do with null entries? - -// todo: need a method to reset the row/column indices after add/remove -// or just make sure that it's covered for all cases - -// no longer the case, ja? -//
By default, empty rows are skipped and so are lines that start with the -// # character. Using # at the beginning of a line indicates a comment.
- -// attempt at a CSV spec: - _ draw() called again before finishing on OS X (retina issue) _ https://github.com/processing/processing/issues/1709 _ tint() with JAVA2D does not automatically refresh (with possible fix) _ https://github.com/processing/processing/issues/1730 -_ include Instant and Interval? (or just Time and TimeSpan) +table +X do we need getColumnType() inside TableRow? +X also inside Table +X also do we make the constants public? +X table writing twice when .csv is added +X https://github.com/processing/processing/issues/1734 +_ checkOptions() is a mess.. need to use different options for load/save +_ rewrite it as necessary +_ function that will convert awful CSV to TSV.. or something else? +_ maybe to write binary instead? then read the binary file once it's ok? +_ if loading from a File object +_ (or PApplet is passed in and we can check online) +_ then check the (probable) size of the file before loading +_ implement binary tables +_ these might be partially set +_ add .gz as option for writing (and bz2?) +_ no column max/min functions since it needs to be per-datatype +_ better to use float mx = max(float(getColumn(3))); +_ but what to do with null entries? +_ need a method to reset the row/column indices after add/remove +_ or just make sure that it's covered for all cases +_ prefixes like # as comments? easy to remove? +data +X "hash.toJSONObject()" or "new JSONObject(hash)" +X opted to use "new JSONObject" version, appears less awkward +o match? find? on StringList? +_ can we use String... for options? or does it screw up the method signature? +_ and would we have to always concatenate arrays to prepend extensions, etc +_ include Instant and Interval? (or just Time and TimeSpan) _ naming for descending sort _ rsort(), sortReverse(), sortKeysReverse, _ sortDescend, sortDescending, sortKeysDescending, _ sortHighLow, sortHigh, sortHighest, sortDown +_ it's going to be File or Reader (mostly BufferedReader) everywhere +_ though TableODS needs an InputStream... +_ and XML could use InputStream if we hope to be able to reflect doc encoding +_ ok, so File, Reader, and InputStream (where needed) +_ setMissingXxxx() -> should this live in PApplet? be static? +_ cons: static stinks, diff tables might use diff values +_ will also need an iterator for the Dict class ala Map.Entry -it's going to be File or Reader (mostly BufferedReader) everywhere - though TableODS needs an InputStream... - and XML could use InputStream if we hope to be able to reflect doc encoding +json +X getIntArray() for JSONArray +X misc bugs with last release +X https://github.com/processing/processing/issues/1660 +X https://github.com/processing/processing/issues/1680 +X Dan having trouble with JSON +X keys() vs keySet() in JSON.. +X keys() doesn't iterate, keySet() introduces 'Set' type +X parseJSONObject(x) and parseJSONArray(x) -setMissingXxxx() -> should this live in PApplet? be static? - cons: static stinks, diff tables might use diff values - -"hash.toJSONObject()" or "new JSONObject(hash)" - -no save/load in hash and list classes - no native format -removeIndex() vs removeValue() vs remove() - remove() refers to an index (with array) or key (with hash) - more consistent with other APIs (Java) - replaceValue[s]() the same, though more on the line - should we not have remove() and removeIndex() - and instead always specify? removeKey(), removeIndex(), removeValue()? - would mean that hash would only have removeKey - downside: remove() takes whatever get() takes as arg - -hash/dict/etc -_ need to sort out the final version of these and their names +data / document +X no save/load for hash and list classes +X because no native format +X write() and constructor are enough for advanced users +o add() to add things to lists, inc/dec for the math +o inc/dec/sum is used less, after all +X or append()? since that's what JSON is currently using +X append() nicer, inc/dec felt arcane (and forced) +o Lookup instead of Hash or Dict? +o increment, decrement, increase, decrease instead of add/subtract +o does double duty for incrementing/decrementing easily +o inc(), inc(amount), dec(), dec(amount) +X replace (especially for null and NaN) +X make note that these work, and are special cases +_ removeIndex() vs removeValue() vs remove() +_ remove() refers to an index (with array) or key (with hash) +_ more consistent with other APIs (Java) +_ replaceValue[s]() the same, though more on the line +_ should we not have remove() and removeIndex() +_ and instead always specify? removeKey(), removeIndex(), removeValue()? +_ would mean that hash would only have removeKey +_ downside: remove() takes whatever get() takes as arg +_ need to sort out the final version of hash/dict/etc and their names _ JSONObject.has(key) vs XML.hasAttribute(attr) vs HashMap.containsKey() _ and how it should be handled with hash/dict _ right now using hasKey().. in JSONObject _ contains() as default, then containsValue() as the alternate _ instead of containsKey() and containsValue() -_ add() to add things to lists, inc/dec for the math -_ inc/dec/sum is used less, after all -_ or append()? since that's what JSON is currently using -_ will also need an iterator for the Dict class ala Map.Entry -_ Lookup instead of Hash or Dict? -inc(), inc(amount) -dec(), dec(amount) -increment, decrement, increase, decrease instead of add/subtract -does double duty for incrementing/decrementing easily -X getIntArray() for JSONArray +_ hasAttribute in XML, containsKey in java's Map, hasKey in JSON +_ hasChildren() is another precedent +o contains() is nice, but containsKey() is weird, often not 'containing' +X hasKey/hasValue is best; fewest changes and most descriptive + _ add indent= as option for XML, JSON save _ not doing print() methods, since alternatives are more descriptive _ println(obj) and obj.write(System.out) are both better @@ -98,9 +113,6 @@ _ using Iterable for rows(), keys(), etc _ generally more efficient for Table, but slower for FloatHash and IntHash _ could use an int array instead, but a bit hokey in places -replace? (especially for NaN) -match? find? on StringList? - decide on TableODS, TableHTML Iterable, Iterator, or [] returned for keys(), rows(), etc. @@ -119,11 +131,6 @@ what should they all return? with removeValue(), add removeValues() for all values that match? also support NaN here -hasAttribute in XML, containsKey in java's Map, hasKey in JSON - hasChildren() is another precedent - -> hasKey/hasValue is better; fewest changes and most descriptive - -> contains() is nicer, but containsKey() is weird, often not 'containing' - listAttributes() in XML is like array from keys() etc in our data classes List: remove(), append(), index(), etc all use values @@ -133,8 +140,6 @@ List: remove(), append(), index(), etc all use values and removeValue(value) is probably used less table -_ table writing twice when .csv is added -_ https://github.com/processing/processing/issues/1734 _ add 'gz' as one of the loadXxx() options _ helps .svgz case from being weird, also generally dealing w/ compressed data _ naming for these (or whether to include hash) @@ -164,14 +169,6 @@ _ CATEGORICAL -> CATEGORY? ORDINAL? _ getInt() on categorial to return index? _ getCategories() and getCategory() methods to query names? -json -_ https://github.com/processing/processing/issues/1660 -_ https://github.com/processing/processing/issues/1680 -_ Dan having trouble with JSON -_ keys() vs keySet() in JSON.. -_ keys() doesn't iterate, keySet() introduces 'Set' type -_ add parseXML() and parseJSONObject(x) - andres A lines not properly renderered in P3D when using ortographic projection A https://github.com/processing/processing/issues/1661 diff --git a/todo.txt b/todo.txt index 84f6dd048..701dbe413 100644 --- a/todo.txt +++ b/todo.txt @@ -30,6 +30,8 @@ X seems to be working fine X move Android mode out to its own repo X fix line endings in revisions.txt for windows X was modifying the wrong file (the source dir, not the work dir) +X change line endings on Windows to only be replaced during dist +X otherwise marks revisions.txt as changed manager X "New version available" mesage is showing html tags around it @@ -51,16 +53,11 @@ _ only send for items that are part of the public list _ otherwise we're sending private libraries/installs _ although this won't pick up old libraries not on the new system -_ change line endings on Windows to only be replaced during dist -_ otherwise marks revisions.txt as changed - _ remove sketch.properties when moving back to the default? _ or can we not do this, because it's used to set the 'next' mode _ Linux sometimes not responding correctly w/ the size() command _ https://github.com/processing/processing/issues/1672 -_ processing-java output as UTF-8 makes Windows unhappy -_ https://github.com/processing/processing/issues/1633 2.0 FINAL / new interface @@ -77,9 +74,9 @@ _ needs to be reset for this release, maybe others 2.0 FINAL / more open/save/etc _ blank sketch opened even if another opened by double-click -_ http://code.google.com/p/processing/issues/detail?id=179 _ add a 150 ms or more lag before opening the untitled window (on os x) -_ osx not opening a sketch at all on pde double-click? (though opening the app) +_ https://github.com/processing/processing/issues/218 +_ OS X not opening a sketch at all on pde double-click? (though opening the app) _ active editor not being set null _ in Base.nextEditorLocation(), changed to "editors.size() == 0" _ instead of (activeEditor == null), but that's papering over a problem @@ -89,8 +86,10 @@ o don't use tmp folder for sketches? _ restrict more things like "show sketch folder" _ don't allow adding files w/o saving _ others? -_ when creating a sketch within non-java mode, should write the settings file +_ when creating a sketch within non-Java mode, should write the settings file _ so that it re-loads in the proper environment +_ processing-java output as UTF-8 makes Windows unhappy +_ https://github.com/processing/processing/issues/1633 2.0 FINAL / libraries & classpaths @@ -149,9 +148,7 @@ _ library installation should use the sketchbook folder, not the p5 folder _ actually enforce this, give users a warning about other libs _ java.extension.dirs has the library/extn stuff _ can probably set this blank -_ the jar from which a class file has been loaded -_ getClass().getProtectionDomain().getCodeSource().getLocation().getFile() -_ example from jsyn +_ example from jsyn JSyn Installer build 011 java.vm.version = 1.5.0_07-87 java.library.path = .:/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java @@ -190,14 +187,15 @@ _ check if libraries folder does not exist _ check to see if other libraries are installed _ warn user about moving libraries and restarting _ support the reference folder of contributed libraries -_ http://code.google.com/p/processing/issues/detail?id=905 +_ add reference for contributed libraries to the Help menu +_ https://github.com/processing/processing/issues/943 2.0 FINAL / misc pde cleanups _ 'recent' menu doesn't respect examples folder of other p5 versions +_ could write that into the file, that it's an example +_ or write the path as shown in the PDE to the file as simpler _ 'recent' menu paths can get enormous -_ add reference for contributed libraries to the Help menu -_ http://code.google.com/p/processing/issues/detail?id=905 _ temporary files (for sketches and logs) are not deleted _ http://code.google.com/p/processing/issues/detail?id=562