| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -23,7 +23,6 @@ | |||
| 23 | 23 | ||
| 24 | 24 | import java.io.File; | |
| 25 | 25 | import java.io.FileNotFoundException; | |
| 26 | - import java.io.FileReader; | ||
| 27 | 26 | import java.io.IOException; | |
| 28 | 27 | import java.io.PrintWriter; | |
| 29 | 28 | ||
@@ -201,7 +200,7 @@ protected void writeBuild(File file, String className, | |||
| 201 | 200 | // load the copy from the build location and start messing with it | |
| 202 | 201 | XML mf = null; | |
| 203 | 202 | try { | |
| 204 | - mf = new XML(new FileReader(file)); | ||
| 203 | + mf = new XML(file); | ||
| 205 | 204 | ||
| 206 | 205 | // package name, or default | |
| 207 | 206 | String p = mf.getString("package").trim(); | |
@@ -241,7 +240,7 @@ protected void load() { | |||
| 241 | 240 | File manifestFile = getManifestFile(); | |
| 242 | 241 | if (manifestFile.exists()) { | |
| 243 | 242 | try { | |
| 244 | - xml = new XML(new FileReader(manifestFile)); | ||
| 243 | + xml = new XML(manifestFile); | ||
| 245 | 244 | } catch (Exception e) { | |
| 246 | 245 | e.printStackTrace(); | |
| 247 | 246 | System.err.println("Problem reading AndroidManifest.xml, creating a new version"); | |
@@ -261,7 +260,7 @@ protected void load() { | |||
| 261 | 260 | if (xml == null) { | |
| 262 | 261 | writeBlankManifest(manifestFile); | |
| 263 | 262 | try { | |
| 264 | - xml = new XML(new FileReader(manifestFile)); | ||
| 263 | + xml = new XML(manifestFile); | ||
| 265 | 264 | } catch (FileNotFoundException e) { | |
| 266 | 265 | System.err.println("Could not read " + manifestFile.getAbsolutePath()); | |
| 267 | 266 | e.printStackTrace(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5822,15 +5822,46 @@ header[17] image descriptor (packed bits) | |||
| 5822 | 5822 | * @see PApplet#loadTable(String) | |
| 5823 | 5823 | */ | |
| 5824 | 5824 | public XML loadXML(String filename) { | |
| 5825 | + return loadXML(filename, null); | ||
| 5826 | + } | ||
| 5827 | + | ||
| 5828 | + | ||
| 5829 | + // version that uses 'options' though there are currently no supported options | ||
| 5830 | + public XML loadXML(String filename, String options) { | ||
| 5825 | 5831 | try { | |
| 5826 | - return new XML(this, filename); | ||
| 5832 | + return new XML(createInput(filename), options); | ||
| 5827 | 5833 | } catch (Exception e) { | |
| 5828 | 5834 | e.printStackTrace(); | |
| 5829 | 5835 | return null; | |
| 5830 | 5836 | } | |
| 5831 | 5837 | } | |
| 5832 | 5838 | ||
| 5833 | 5839 | ||
| 5840 | + public XML parseXML(String xmlString) { | ||
| 5841 | + return parseXML(xmlString, null); | ||
| 5842 | + } | ||
| 5843 | + | ||
| 5844 | + | ||
| 5845 | + public XML parseXML(String xmlString, String options) { | ||
| 5846 | + try { | ||
| 5847 | + return XML.parse(xmlString, options); | ||
| 5848 | + } catch (Exception e) { | ||
| 5849 | + e.printStackTrace(); | ||
| 5850 | + return null; | ||
| 5851 | + } | ||
| 5852 | + } | ||
| 5853 | + | ||
| 5854 | + | ||
| 5855 | + public boolean saveXML(XML xml, String filename) { | ||
| 5856 | + return saveXML(xml, filename, null); | ||
| 5857 | + } | ||
| 5858 | + | ||
| 5859 | + | ||
| 5860 | + public boolean saveXML(XML xml, String filename, String options) { | ||
| 5861 | + return xml.save(saveFile(filename), options); | ||
| 5862 | + } | ||
| 5863 | + | ||
| 5864 | + | ||
| 5834 | 5865 | public Table createTable() { | |
| 5835 | 5866 | return new Table(); | |
| 5836 | 5867 | } | |
@@ -5869,17 +5900,19 @@ public Table loadTable(String filename, String options) { | |||
| 5869 | 5900 | } | |
| 5870 | 5901 | ||
| 5871 | 5902 | ||
| 5872 | - public void saveTable(Table table, String filename) { | ||
| 5873 | - saveTable(table, filename, null); | ||
| 5903 | + public boolean saveTable(Table table, String filename) { | ||
| 5904 | + return saveTable(table, filename, null); | ||
| 5874 | 5905 | } | |
| 5875 | 5906 | ||
| 5876 | 5907 | ||
| 5877 | - public void saveTable(Table table, String filename, String options) { | ||
| 5908 | + public boolean saveTable(Table table, String filename, String options) { | ||
| 5878 | 5909 | try { | |
| 5879 | 5910 | table.save(saveFile(filename), options); | |
| 5911 | + return true; | ||
| 5880 | 5912 | } catch (IOException e) { | |
| 5881 | 5913 | e.printStackTrace(); | |
| 5882 | 5914 | } | |
| 5915 | + return false; | ||
| 5883 | 5916 | } | |
| 5884 | 5917 | ||
| 5885 | 5918 | ||
@@ -10847,6 +10880,11 @@ public PShape loadShape(String filename) { | |||
| 10847 | 10880 | } | |
| 10848 | 10881 | ||
| 10849 | 10882 | ||
| 10883 | + public PShape loadShape(String filename, String options) { | ||
| 10884 | + return g.loadShape(filename, options); | ||
| 10885 | + } | ||
| 10886 | + | ||
| 10887 | + | ||
| 10850 | 10888 | /** | |
| 10851 | 10889 | * @webref shape | |
| 10852 | 10890 | * @see PShape | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1604,6 +1604,11 @@ public void endShape(int mode) { | |||
| 1604 | 1604 | * @see PApplet#createShape() | |
| 1605 | 1605 | */ | |
| 1606 | 1606 | public PShape loadShape(String filename) { | |
| 1607 | + return loadShape(filename, null); | ||
| 1608 | + } | ||
| 1609 | + | ||
| 1610 | + | ||
| 1611 | + public PShape loadShape(String filename, String options) { | ||
| 1607 | 1612 | showMissingWarning("loadShape"); | |
| 1608 | 1613 | return null; | |
| 1609 | 1614 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1380,17 +1380,23 @@ public void update(boolean tint, int tintColor) { | |||
| 1380 | 1380 | ||
| 1381 | 1381 | @Override | |
| 1382 | 1382 | public PShape loadShape(String filename) { | |
| 1383 | + return loadShape(filename, null); | ||
| 1384 | + } | ||
| 1385 | + | ||
| 1386 | + | ||
| 1387 | + @Override | ||
| 1388 | + public PShape loadShape(String filename, String options) { | ||
| 1383 | 1389 | String extension = PApplet.getExtension(filename); | |
| 1384 | 1390 | ||
| 1385 | 1391 | PShapeSVG svg = null; | |
| 1386 | 1392 | ||
| 1387 | 1393 | if (extension.equals("svg")) { | |
| 1388 | - svg = new PShapeSVG(parent, filename); | ||
| 1394 | + svg = new PShapeSVG(parent.loadXML(filename)); | ||
| 1389 | 1395 | ||
| 1390 | 1396 | } else if (extension.equals("svgz")) { | |
| 1391 | 1397 | try { | |
| 1392 | 1398 | InputStream input = new GZIPInputStream(parent.createInput(filename)); | |
| 1393 | - XML xml = new XML(PApplet.createReader(input)); | ||
| 1399 | + XML xml = new XML(input, options); | ||
| 1394 | 1400 | svg = new PShapeSVG(xml); | |
| 1395 | 1401 | } catch (Exception e) { | |
| 1396 | 1402 | e.printStackTrace(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -159,14 +159,14 @@ public class PShapeSVG extends PShape { | |||
| 159 | 159 | String fillName; // id of another object | |
| 160 | 160 | ||
| 161 | 161 | ||
| 162 | - /** | ||
| 163 | - * Initializes a new SVG Object with the given filename. | ||
| 164 | - */ | ||
| 165 | - public PShapeSVG(PApplet parent, String filename) { | ||
| 166 | - // this will grab the root document, starting <svg ...> | ||
| 167 | - // the xml version and initial comments are ignored | ||
| 168 | - this(parent.loadXML(filename)); | ||
| 169 | - } | ||
| 162 | + // /** | ||
| 163 | + // * Initializes a new SVG Object with the given filename. | ||
| 164 | + // */ | ||
| 165 | + // public PShapeSVG(PApplet parent, String filename) { | ||
| 166 | + // // this will grab the root document, starting <svg ...> | ||
| 167 | + // // the xml version and initial comments are ignored | ||
| 168 | + // this(parent.loadXML(filename)); | ||
| 169 | + // } | ||
| 170 | 170 | ||
| 171 | 171 | ||
| 172 | 172 | /** | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -119,6 +119,11 @@ public Table(File file, String options) throws IOException { | |||
| 119 | 119 | } | |
| 120 | 120 | ||
| 121 | 121 | ||
| 122 | + public Table(InputStream input) throws IOException { | ||
| 123 | + this(input, null); | ||
| 124 | + } | ||
| 125 | + | ||
| 126 | + | ||
| 122 | 127 | /** | |
| 123 | 128 | * Read the table from a stream. Possible options include: | |
| 124 | 129 | * <ul> | |
@@ -479,7 +484,6 @@ static protected int nextComma(char[] c, int index) { | |||
| 479 | 484 | // compiler) of an inner class by the runtime. | |
| 480 | 485 | ||
| 481 | 486 | /** incomplete, do not use */ | |
| 482 | - // public void parseInto(PApplet sketch, String fieldName) { | ||
| 483 | 487 | public void parseInto(Object enclosingObject, String fieldName) { | |
| 484 | 488 | Class<?> target = null; | |
| 485 | 489 | Object outgoing = null; | |
@@ -1043,14 +1047,23 @@ public void setTableType(String type) { | |||
| 1043 | 1047 | ||
| 1044 | 1048 | /** | |
| 1045 | 1049 | * Set the titles (and if a second column is present) the data types for | |
| 1046 | - * this table based on a file loaded separately. | ||
| 1050 | + * this table based on a file loaded separately. This will look for the | ||
| 1051 | + * title in column 0, and the type in column 1. Better yet, specify a | ||
| 1052 | + * column named "title" and another named "type" in the dictionary table | ||
| 1053 | + * to future-proof the code. | ||
| 1047 | 1054 | * @param dictionary | |
| 1048 | 1055 | */ | |
| 1049 | 1056 | public void setColumnTypes(Table dictionary) { | |
| 1050 | - setColumnTitles(dictionary.getStringColumn(0)); | ||
| 1057 | + int titleCol = 0; | ||
| 1058 | + int typeCol = 1; | ||
| 1059 | + if (dictionary.hasColumnTitles()) { | ||
| 1060 | + titleCol = dictionary.getColumnIndex("title", true); | ||
| 1061 | + typeCol = dictionary.getColumnIndex("type", true); | ||
| 1062 | + } | ||
| 1063 | + setColumnTitles(dictionary.getStringColumn(titleCol)); | ||
| 1051 | 1064 | if (dictionary.getColumnCount() > 1) { | |
| 1052 | 1065 | for (int i = 0; i < dictionary.getRowCount(); i++) { | |
| 1053 | - setColumnType(i, dictionary.getString(i, 1)); | ||
| 1066 | + setColumnType(i, dictionary.getString(i, typeCol)); | ||
| 1054 | 1067 | } | |
| 1055 | 1068 | } | |
| 1056 | 1069 | } | |
@@ -1061,7 +1074,9 @@ public void setColumnTypes(Table dictionary) { | |||
| 1061 | 1074 | ||
| 1062 | 1075 | /** | |
| 1063 | 1076 | * Remove the first row from the data set, and use it as the column titles. | |
| 1077 | + * Use loadTable("table.csv", "header") instead. | ||
| 1064 | 1078 | */ | |
| 1079 | + @Deprecated | ||
| 1065 | 1080 | public String[] removeTitleRow() { | |
| 1066 | 1081 | String[] titles = getStringRow(0); | |
| 1067 | 1082 | removeRow(0); | |
@@ -1089,6 +1104,11 @@ public void setColumnTitle(int column, String title) { | |||
| 1089 | 1104 | } | |
| 1090 | 1105 | ||
| 1091 | 1106 | ||
| 1107 | + public boolean hasColumnTitles() { | ||
| 1108 | + return columnTitles != null; | ||
| 1109 | + } | ||
| 1110 | + | ||
| 1111 | + | ||
| 1092 | 1112 | public String[] getColumnTitles() { | |
| 1093 | 1113 | return columnTitles; | |
| 1094 | 1114 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -43,9 +43,10 @@ public TableODS(PApplet parent, String filename, String worksheet, boolean actua | |||
| 43 | 43 | */ | |
| 44 | 44 | protected TableODS(InputStream input, String worksheet, boolean actual) { | |
| 45 | 45 | try { | |
| 46 | - InputStreamReader isr = new InputStreamReader(input, "UTF-8"); | ||
| 47 | - BufferedReader reader = new BufferedReader(isr); | ||
| 48 | - read(reader, worksheet, actual); | ||
| 46 | + // InputStreamReader isr = new InputStreamReader(input, "UTF-8"); | ||
| 47 | + // BufferedReader reader = new BufferedReader(isr); | ||
| 48 | + // read(reader, worksheet, actual); | ||
| 49 | + read(input, worksheet, actual); | ||
| 49 | 50 | ||
| 50 | 51 | } catch (UnsupportedEncodingException uee) { | |
| 51 | 52 | uee.printStackTrace(); | |
@@ -59,8 +60,11 @@ protected TableODS(InputStream input, String worksheet, boolean actual) { | |||
| 59 | 60 | } | |
| 60 | 61 | ||
| 61 | 62 | ||
| 62 | - protected void read(BufferedReader reader, String worksheet, boolean actual) throws IOException, ParserConfigurationException, SAXException { | ||
| 63 | - XML xml = new XML(reader); | ||
| 63 | + // protected void read(BufferedReader reader, String worksheet, boolean actual) throws IOException, ParserConfigurationException, SAXException { | ||
| 64 | + // XML xml = new XML(reader); | ||
| 65 | + protected void read(InputStream input, String worksheet, boolean actual) throws IOException, ParserConfigurationException, SAXException { | ||
| 66 | + XML xml = new XML(input); | ||
| 67 | + | ||
| 64 | 68 | // XML x = new XML(reader); | |
| 65 | 69 | // PApplet.saveStrings(new File("/Users/fry/Desktop/namespacefix.xml"), new String[] { xml.toString() }); | |
| 66 | 70 | // PApplet.saveStrings(new File("/Users/fry/Desktop/newparser.xml"), new String[] { x.toString() }); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments