/** * Parse a polyline or polygon from an SVG file. * @param close true if shape is closed (polygon), false if not (polyline) */ protected void parsePoly(boolean close) { family = PATH; this.close = close; String pointsAttr = element.getString("points"); if (pointsAttr != null) { String[] pointsBuffer = PApplet.splitTokens(pointsAttr); vertexCount = pointsBuffer.length; vertices = new float[vertexCount][2]; for (int i = 0; i < vertexCount; i++) { String pb[] = PApplet.split(pointsBuffer[i], ','); vertices[i][X] = Float.valueOf(pb[0]).floatValue(); vertices[i][Y] = Float.valueOf(pb[1]).floatValue(); } } }
/** * Read a set of entries from a Reader that has each key/value pair on * a single line, separated by a tab. * * @nowebref */ public StringDict(BufferedReader reader) { String[] lines = PApplet.loadStrings(reader); keys = new String[lines.length]; values = new String[lines.length]; for (int i = 0; i < lines.length; i++) { String[] pieces = PApplet.split(lines[i], '\t'); if (pieces.length == 2) { keys[count] = pieces[0]; values[count] = pieces[1]; count++; } } }
/** * Read a set of entries from a Reader that has each key/value pair on * a single line, separated by a tab. * * @nowebref */ public StringDict(BufferedReader reader) { String[] lines = PApplet.loadStrings(reader); keys = new String[lines.length]; values = new String[lines.length]; for (int i = 0; i < lines.length; i++) { String[] pieces = PApplet.split(lines[i], '\t'); if (pieces.length == 2) { keys[count] = pieces[0]; values[count] = pieces[1]; indices.put(keys[count], count); count++; } } }
static public String[] packageListFromClassPath(String path, Context context) { Hashtable<String, Object> table = new Hashtable<String, Object>(); String pieces[] = PApplet.split(path, File.pathSeparatorChar); for(int i = 0; i < pieces.length; i++) { if(pieces[i].length() == 0) continue; if(pieces[i].toLowerCase(Locale.US).endsWith(".jar") || pieces[i].toLowerCase(Locale.US).endsWith(".zip")) packageListFromZip(pieces[i], table, context); else { // it's another type of file or directory File dir = new File(pieces[i]); if(dir.exists() && dir.isDirectory()) packageListFromFolder(dir, null, table); } } int tableCount = table.size(); String output[] = new String[tableCount]; int index = 0; Enumeration<String> e = table.keys(); while(e.hasMoreElements()) output[index++] = (e.nextElement()).replace('/', '.'); return output; }
public boolean write(PrintWriter output, String options) { int indentFactor = 2; if (options != null) { String[] opts = PApplet.split(options, ','); for (String opt : opts) { if (opt.equals("compact")) { indentFactor = -1; } else if (opt.startsWith("indent=")) { indentFactor = PApplet.parseInt(opt.substring(7), -2); if (indentFactor == -2) { throw new IllegalArgumentException("Could not read a number from " + opt); } } else { System.err.println("Ignoring " + opt); } } } output.print(format(indentFactor)); output.flush(); return true; }
public boolean write(PrintWriter output, String options) { int indentFactor = 2; if (options != null) { String[] opts = PApplet.split(options, ','); for (String opt : opts) { if (opt.equals("compact")) { indentFactor = -1; } else if (opt.startsWith("indent=")) { indentFactor = PApplet.parseInt(opt.substring(7), -2); if (indentFactor == -2) { throw new IllegalArgumentException("Could not read a number from " + opt); } } else { System.err.println("Ignoring " + opt); } } } output.print(format(indentFactor)); output.flush(); return true; }
extensions = new String[] { opt.substring(10) }; } else if (opt.startsWith("extensions=")) { extensions = split(opt.substring(10), ','); } else if (opt.equals("files")) { directories = false;
/** * Read a set of entries from a Reader that has each key/value pair on * a single line, separated by a tab. * * @nowebref */ public FloatDict(BufferedReader reader) { String[] lines = PApplet.loadStrings(reader); keys = new String[lines.length]; values = new float[lines.length]; for (int i = 0; i < lines.length; i++) { String[] pieces = PApplet.split(lines[i], '\t'); if (pieces.length == 2) { keys[count] = pieces[0]; values[count] = PApplet.parseFloat(pieces[1]); indices.put(pieces[0], count); count++; } } }
/** * Read a set of entries from a Reader that has each key/value pair on * a single line, separated by a tab. * * @nowebref */ public IntDict(BufferedReader reader) { String[] lines = PApplet.loadStrings(reader); keys = new String[lines.length]; values = new int[lines.length]; for (int i = 0; i < lines.length; i++) { String[] pieces = PApplet.split(lines[i], '\t'); if (pieces.length == 2) { keys[count] = pieces[0]; values[count] = PApplet.parseInt(pieces[1]); indices.put(pieces[0], count); count++; } } }
/** * Get a child by its name or path. * * @param name element name or path/to/element * @return the first matching element or null if no match */ public XML getChild(String name) { if (name.length() > 0 && name.charAt(0) == '/') { throw new IllegalArgumentException("getChild() should not begin with a slash"); } if (name.indexOf('/') != -1) { return getChildRecursive(PApplet.split(name, '/'), 0); } int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { XML kid = getChild(i); String kidName = kid.getName(); if (kidName != null && kidName.equals(name)) { return kid; } } return null; }
class AsyncImageLoader extends Thread { String filename; String extension; PImage vessel; public AsyncImageLoader(String filename, String extension, PImage vessel) { // Give these threads distinct name so we can check whether we are loading // on the main/background thread; for now they are all named the same super(ASYNC_IMAGE_LOADER_THREAD_PREFIX); this.filename = filename; this.extension = extension; this.vessel = vessel; } @Override public void run() { while (requestImageCount == requestImageMax) { try { Thread.sleep(10); } catch (InterruptedException e) { } } requestImageCount++; PImage actual = loadImage(filename, extension); // An error message should have already printed if (actual == null) { vessel.width = -1; vessel.height = -1;
/** * Get a child by its name or path. * * @param name element name or path/to/element * @return the first matching element */ public XML getChild(String name) { if (name.length() > 0 && name.charAt(0) == '/') { throw new IllegalArgumentException("getChild() should not begin with a slash"); } if (name.indexOf('/') != -1) { return getChildRecursive(PApplet.split(name, '/'), 0); } int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { XML kid = getChild(i); String kidName = kid.getName(); if (kidName != null && kidName.equals(name)) { return kid; } } return null; }
/** * Read a set of entries from a Reader that has each key/value pair on * a single line, separated by a tab. * * @nowebref */ public IntDict(BufferedReader reader) { // public IntHash(PApplet parent, String filename) { String[] lines = PApplet.loadStrings(reader); keys = new String[lines.length]; values = new int[lines.length]; // boolean csv = (lines[0].indexOf('\t') == -1); for (int i = 0; i < lines.length; i++) { // String[] pieces = csv ? Table.splitLineCSV(lines[i]) : PApplet.split(lines[i], '\t'); String[] pieces = PApplet.split(lines[i], '\t'); if (pieces.length == 2) { keys[count] = pieces[0]; values[count] = PApplet.parseInt(pieces[1]); count++; } } }
/** * Read a set of entries from a Reader that has each key/value pair on * a single line, separated by a tab. * * @nowebref */ public FloatDict(BufferedReader reader) { // public FloatHash(PApplet parent, String filename) { String[] lines = PApplet.loadStrings(reader); keys = new String[lines.length]; values = new float[lines.length]; // boolean csv = (lines[0].indexOf('\t') == -1); for (int i = 0; i < lines.length; i++) { // String[] pieces = csv ? Table.splitLineCSV(lines[i]) : PApplet.split(lines[i], '\t'); String[] pieces = PApplet.split(lines[i], '\t'); if (pieces.length == 2) { keys[count] = pieces[0]; values[count] = PApplet.parseFloat(pieces[1]); count++; } } }
return getChildrenRecursive(PApplet.split(name, '/'), 0);
return getChildrenRecursive(PApplet.split(name, '/'), 0);
String[] opts = PApplet.trim(PApplet.split(options, ','));
try { String optionStr = Table.extensionOptions(true, filename, options); String[] optionList = trim(split(optionStr, ','));