From aae98d9481ce75c259dea5387da46a38374ded98 Mon Sep 17 00:00:00 2001 From: Ben Fry Date: Fri, 24 Apr 2015 00:05:57 -0400 Subject: [PATCH] cleanups --- java/src/processing/mode/java/JavaEditor.java | 12 +- .../mode/java/tweak/SketchParser.java | 105 ++++++++---------- 2 files changed, 55 insertions(+), 62 deletions(-) diff --git a/java/src/processing/mode/java/JavaEditor.java b/java/src/processing/mode/java/JavaEditor.java index 99867fc0a..e7d01835f 100644 --- a/java/src/processing/mode/java/JavaEditor.java +++ b/java/src/processing/mode/java/JavaEditor.java @@ -2562,13 +2562,13 @@ public class JavaEditor extends Editor { UDPTweakClient tweakClient; - public void startInteractiveMode() { + protected void startInteractiveMode() { getJavaTextArea().startInteractiveMode(); } //public void stopInteractiveMode(ArrayList handles[]) { - public void stopInteractiveMode(List> handles) { + protected void stopInteractiveMode(List> handles) { tweakClient.shutdown(); getJavaTextArea().stopInteractiveMode(); @@ -2639,7 +2639,7 @@ public class JavaEditor extends Editor { } - public void updateInterface(List> handles, + protected void updateInterface(List> handles, List> colorBoxes) { getJavaTextArea().updateInterface(handles, colorBoxes); } @@ -2659,7 +2659,7 @@ public class JavaEditor extends Editor { } - public void initBaseCode() { + protected void initBaseCode() { SketchCode[] code = sketch.getCode(); baseCode = new String[code.length]; @@ -2669,7 +2669,7 @@ public class JavaEditor extends Editor { } - public void initEditorCode(List> handles, boolean withSpaces) { + protected void initEditorCode(List> handles, boolean withSpaces) { SketchCode[] sketchCode = sketch.getCode(); for (int tab=0; tab handles[]) - public boolean automateSketch(Sketch sketch, List> handles) { + protected boolean automateSketch(Sketch sketch, List> handles) { SketchCode[] code = sketch.getCode(); if (code.length < 1) { diff --git a/java/src/processing/mode/java/tweak/SketchParser.java b/java/src/processing/mode/java/tweak/SketchParser.java index b296a9cbd..dbfc88bb5 100644 --- a/java/src/processing/mode/java/tweak/SketchParser.java +++ b/java/src/processing/mode/java/tweak/SketchParser.java @@ -39,7 +39,7 @@ public class SketchParser { List> scientificNotations; - + public SketchParser(String[] codeTabs, boolean requiresComment) { this.codeTabs = codeTabs; this.requiresComment = requiresComment; @@ -57,15 +57,13 @@ public class SketchParser { createColorBoxes(); createColorBoxesForLights(); - /* If there is more than one color mode per context, - * allow only hex and webcolors in this context. - * Currently there is no notion of order of execution so we - * cannot know which color mode relate to a color. - */ + // If there is more than one color mode per context, allow only hex and + // webcolors in this context. Currently there is no notion of order of + // execution so we cannot know which color mode relate to a color. handleMultipleColorModes(); } - + public void addAllNumbers() { //allHandles = new ArrayList[codeTabs.length]; // moved inside addAllDecimalNumbers addAllDecimalNumbers(); @@ -78,7 +76,7 @@ public class SketchParser { } } - + /** * Get a list of all the numbers in this sketch * @return @@ -89,13 +87,13 @@ public class SketchParser { // for every number found: // save its type (int/float), name, value and position in code. - + Pattern p = Pattern.compile("[\\[\\{<>(),\\t\\s\\+\\-\\/\\*^%!|&=?:~]\\d+\\.?\\d*"); for (int i = 0; i < codeTabs.length; i++) { //allHandles[i] = new ArrayList(); List handles = new ArrayList(); allHandles.add(handles); - + String c = codeTabs[i]; Matcher m = p.matcher(c); @@ -157,41 +155,37 @@ public class SketchParser { int line = countLines(c.substring(0, start)) - 1; // zero based String value = c.substring(start, end); - //value - if (value.contains(".") || forceFloat) { - // consider this as a float - String name = varPrefix + "_float[" + floatVarCount +"]"; - int decimalDigits = getNumDigitsAfterPoint(value); - handles.add(new Handle("float", name, floatVarCount, value, i, line, start, end, decimalDigits)); - floatVarCount++; - } else { - // consider this as an int - String name = varPrefix + "_int[" + intVarCount +"]"; - handles.add(new Handle("int", name, intVarCount, value, i, line, start, end, 0)); - intVarCount++; - } - } - } - } + if (value.contains(".") || forceFloat) { + // consider this as a float + String name = varPrefix + "_float[" + floatVarCount +"]"; + int decimalDigits = getNumDigitsAfterPoint(value); + handles.add(new Handle("float", name, floatVarCount, value, i, line, start, end, decimalDigits)); + floatVarCount++; + } else { + // consider this as an int + String name = varPrefix + "_int[" + intVarCount +"]"; + handles.add(new Handle("int", name, intVarCount, value, i, line, start, end, 0)); + intVarCount++; + } + } + } + } + /** * Get a list of all the hexadecimal numbers in the code * @return * list of all hexadecimal numbers in the sketch */ - private void addAllHexNumbers() - { - /* for every number found: - * save its type (int/float), name, value and position in code. - */ + private void addAllHexNumbers() { + // for every number found: + // save its type (int/float), name, value and position in code. Pattern p = Pattern.compile("[\\[\\{<>(),\\t\\s\\+\\-\\/\\*^%!|&=?:~]0x[A-Fa-f0-9]+"); - for (int i=0; i(); // search tab for the functions: 'color', 'fill', 'stroke', 'background', 'tint' Pattern p = Pattern.compile("color\\(|color\\s\\(|fill[\\(\\s]|stroke[\\(\\s]|background[\\(\\s]|tint[\\(\\s]"); - + for (int i = 0; i < codeTabs.length; i++) { //colorBoxes[i] = new ArrayList(); List colorBox = new ArrayList(); colorBoxes.add(colorBox); - + String tab = codeTabs[i]; Matcher m = p.matcher(tab); @@ -412,7 +405,7 @@ public class SketchParser { Pattern p = Pattern.compile("ambientLight[\\(\\s]|directionalLight[\\(\\s]"+ "|pointLight[\\(\\s]|spotLight[\\(\\s]|lightSpecular[\\(\\s]"+ "|specular[\\(\\s]|ambient[\\(\\s]|emissive[\\(\\s]"); - + for (int i=0; i> getAllScientificNotations() { //ArrayList notations[] = new ArrayList[codeTabs.length]; List> notations = new ArrayList<>(); @@ -578,7 +571,7 @@ public class SketchParser { } return false; } - + static public boolean lineHasTweakComment(int pos, String code) { int lineEnd = getEndOfLine(pos, code); @@ -589,7 +582,7 @@ public class SketchParser { String line = code.substring(pos, lineEnd); return hasTweakComment(line); } - + static private boolean hasTweakComment(String code) { Pattern p = Pattern.compile("\\/\\/.*tweak", Pattern.CASE_INSENSITIVE); @@ -613,7 +606,7 @@ public class SketchParser { return false; } - + static private int getNumDigitsAfterPoint(String number) { Pattern p = Pattern.compile("\\.[0-9]+"); Matcher m = p.matcher(number); @@ -624,13 +617,13 @@ public class SketchParser { return 0; } - + static private int countLines(String str) { String[] lines = str.split("\r\n|\n\r|\n|\r"); return lines.length; } - + /** * Are we inside a string? (TODO: ignore comments in the code) * @param pos @@ -721,12 +714,12 @@ public class SketchParser { return false; } - + static private int getEndOfLine(int pos, String code) { return code.indexOf("\n", pos); } - + static private int getStartOfLine(int pos, String code) { while (pos >= 0) { if (code.charAt(pos) == '\n') { @@ -738,7 +731,7 @@ public class SketchParser { return 0; } - + /** returns the object of the function starting at 'pos' * * @param pos @@ -769,7 +762,7 @@ public class SketchParser { return obj; } - + static public int getSetupStart(String code) { Pattern p = Pattern.compile("void[\\s\\t\\r\\n]*setup[\\s\\t]*\\(\\)[\\s\\t\\r\\n]*\\{"); Matcher m = p.matcher(code); @@ -786,7 +779,7 @@ public class SketchParser { // return str.substring(0, start) + put + str.substring(end, str.length()); // } - + class Range { int start; int end;