Skip to content

Commit 5e2a088

Browse files
committed
cleanups
1 parent 992d6d5 commit 5e2a088

File tree

2 files changed

+55
-62
lines changed

2 files changed

+55
-62
lines changed

java/src/processing/mode/java/JavaEditor.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2562,13 +2562,13 @@ protected void applyPreferences() {
25622562
UDPTweakClient tweakClient;
25632563

25642564

2565-
public void startInteractiveMode() {
2565+
protected void startInteractiveMode() {
25662566
getJavaTextArea().startInteractiveMode();
25672567
}
25682568

25692569

25702570
//public void stopInteractiveMode(ArrayList<Handle> handles[]) {
2571-
public void stopInteractiveMode(List<List<Handle>> handles) {
2571+
protected void stopInteractiveMode(List<List<Handle>> handles) {
25722572
tweakClient.shutdown();
25732573
getJavaTextArea().stopInteractiveMode();
25742574

@@ -2639,7 +2639,7 @@ public void stopInteractiveMode(List<List<Handle>> handles) {
26392639
}
26402640

26412641

2642-
public void updateInterface(List<List<Handle>> handles,
2642+
protected void updateInterface(List<List<Handle>> handles,
26432643
List<List<ColorControlBox>> colorBoxes) {
26442644
getJavaTextArea().updateInterface(handles, colorBoxes);
26452645
}
@@ -2659,7 +2659,7 @@ static private boolean[] getModifiedTabs(List<List<Handle>> handles) {
26592659
}
26602660

26612661

2662-
public void initBaseCode() {
2662+
protected void initBaseCode() {
26632663
SketchCode[] code = sketch.getCode();
26642664

26652665
baseCode = new String[code.length];
@@ -2669,7 +2669,7 @@ public void initBaseCode() {
26692669
}
26702670

26712671

2672-
public void initEditorCode(List<List<Handle>> handles, boolean withSpaces) {
2672+
protected void initEditorCode(List<List<Handle>> handles, boolean withSpaces) {
26732673
SketchCode[] sketchCode = sketch.getCode();
26742674
for (int tab=0; tab<baseCode.length; tab++) {
26752675
// beautify the numbers
@@ -2740,7 +2740,7 @@ private void removeSpacesFromCode() {
27402740
* these variables and handle update messages.
27412741
*/
27422742
//public boolean automateSketch(Sketch sketch, ArrayList<Handle> handles[])
2743-
public boolean automateSketch(Sketch sketch, List<List<Handle>> handles) {
2743+
protected boolean automateSketch(Sketch sketch, List<List<Handle>> handles) {
27442744
SketchCode[] code = sketch.getCode();
27452745

27462746
if (code.length < 1) {

java/src/processing/mode/java/tweak/SketchParser.java

Lines changed: 49 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public class SketchParser {
3939

4040
List<List<Range>> scientificNotations;
4141

42-
42+
4343
public SketchParser(String[] codeTabs, boolean requiresComment) {
4444
this.codeTabs = codeTabs;
4545
this.requiresComment = requiresComment;
@@ -57,15 +57,13 @@ public SketchParser(String[] codeTabs, boolean requiresComment) {
5757
createColorBoxes();
5858
createColorBoxesForLights();
5959

60-
/* If there is more than one color mode per context,
61-
* allow only hex and webcolors in this context.
62-
* Currently there is no notion of order of execution so we
63-
* cannot know which color mode relate to a color.
64-
*/
60+
// If there is more than one color mode per context, allow only hex and
61+
// webcolors in this context. Currently there is no notion of order of
62+
// execution so we cannot know which color mode relate to a color.
6563
handleMultipleColorModes();
6664
}
6765

68-
66+
6967
public void addAllNumbers() {
7068
//allHandles = new ArrayList[codeTabs.length]; // moved inside addAllDecimalNumbers
7169
addAllDecimalNumbers();
@@ -78,7 +76,7 @@ public void addAllNumbers() {
7876
}
7977
}
8078

81-
79+
8280
/**
8381
* Get a list of all the numbers in this sketch
8482
* @return
@@ -89,13 +87,13 @@ private void addAllDecimalNumbers() {
8987

9088
// for every number found:
9189
// save its type (int/float), name, value and position in code.
92-
90+
9391
Pattern p = Pattern.compile("[\\[\\{<>(),\\t\\s\\+\\-\\/\\*^%!|&=?:~]\\d+\\.?\\d*");
9492
for (int i = 0; i < codeTabs.length; i++) {
9593
//allHandles[i] = new ArrayList<Handle>();
9694
List<Handle> handles = new ArrayList<Handle>();
9795
allHandles.add(handles);
98-
96+
9997
String c = codeTabs[i];
10098
Matcher m = p.matcher(c);
10199

@@ -157,41 +155,37 @@ private void addAllDecimalNumbers() {
157155

158156
int line = countLines(c.substring(0, start)) - 1; // zero based
159157
String value = c.substring(start, end);
160-
//value
161-
if (value.contains(".") || forceFloat) {
162-
// consider this as a float
163-
String name = varPrefix + "_float[" + floatVarCount +"]";
164-
int decimalDigits = getNumDigitsAfterPoint(value);
165-
handles.add(new Handle("float", name, floatVarCount, value, i, line, start, end, decimalDigits));
166-
floatVarCount++;
167-
} else {
168-
// consider this as an int
169-
String name = varPrefix + "_int[" + intVarCount +"]";
170-
handles.add(new Handle("int", name, intVarCount, value, i, line, start, end, 0));
171-
intVarCount++;
172-
}
173-
}
174-
}
175-
}
158+
if (value.contains(".") || forceFloat) {
159+
// consider this as a float
160+
String name = varPrefix + "_float[" + floatVarCount +"]";
161+
int decimalDigits = getNumDigitsAfterPoint(value);
162+
handles.add(new Handle("float", name, floatVarCount, value, i, line, start, end, decimalDigits));
163+
floatVarCount++;
164+
} else {
165+
// consider this as an int
166+
String name = varPrefix + "_int[" + intVarCount +"]";
167+
handles.add(new Handle("int", name, intVarCount, value, i, line, start, end, 0));
168+
intVarCount++;
169+
}
170+
}
171+
}
172+
}
173+
176174

177175
/**
178176
* Get a list of all the hexadecimal numbers in the code
179177
* @return
180178
* list of all hexadecimal numbers in the sketch
181179
*/
182-
private void addAllHexNumbers()
183-
{
184-
/* for every number found:
185-
* save its type (int/float), name, value and position in code.
186-
*/
180+
private void addAllHexNumbers() {
181+
// for every number found:
182+
// save its type (int/float), name, value and position in code.
187183
Pattern p = Pattern.compile("[\\[\\{<>(),\\t\\s\\+\\-\\/\\*^%!|&=?:~]0x[A-Fa-f0-9]+");
188-
for (int i=0; i<codeTabs.length; i++)
189-
{
184+
for (int i = 0; i < codeTabs.length; i++) {
190185
String c = codeTabs[i];
191186
Matcher m = p.matcher(c);
192187

193-
while (m.find())
194-
{
188+
while (m.find()) {
195189
int start = m.start()+1;
196190
int end = m.end();
197191

@@ -230,17 +224,16 @@ private void addAllHexNumbers()
230224
}
231225
allHandles.get(i).add(handle);
232226
intVarCount++;
233-
}
234-
}
235-
}
227+
}
228+
}
229+
}
230+
236231

237232
/**
238233
* Get a list of all the webcolors (#) numbers in the code
239-
* @return
240234
* list of all hexadecimal numbers in the sketch
241235
*/
242-
private void addAllWebColorNumbers()
243-
{
236+
private void addAllWebColorNumbers() {
244237
Pattern p = Pattern.compile("#[A-Fa-f0-9]{6}");
245238
for (int i=0; i<codeTabs.length; i++)
246239
{
@@ -325,17 +318,17 @@ private ArrayList<ColorMode> findAllColorModes() {
325318
return modes;
326319
}
327320

328-
321+
329322
private void createColorBoxes() {
330323
colorBoxes = new ArrayList<>();
331324
// search tab for the functions: 'color', 'fill', 'stroke', 'background', 'tint'
332325
Pattern p = Pattern.compile("color\\(|color\\s\\(|fill[\\(\\s]|stroke[\\(\\s]|background[\\(\\s]|tint[\\(\\s]");
333-
326+
334327
for (int i = 0; i < codeTabs.length; i++) {
335328
//colorBoxes[i] = new ArrayList<ColorControlBox>();
336329
List<ColorControlBox> colorBox = new ArrayList<ColorControlBox>();
337330
colorBoxes.add(colorBox);
338-
331+
339332
String tab = codeTabs[i];
340333
Matcher m = p.matcher(tab);
341334

@@ -412,7 +405,7 @@ private void createColorBoxesForLights() {
412405
Pattern p = Pattern.compile("ambientLight[\\(\\s]|directionalLight[\\(\\s]"+
413406
"|pointLight[\\(\\s]|spotLight[\\(\\s]|lightSpecular[\\(\\s]"+
414407
"|specular[\\(\\s]|ambient[\\(\\s]|emissive[\\(\\s]");
415-
408+
416409
for (int i=0; i<codeTabs.length; i++) {
417410
String tab = codeTabs[i];
418411
Matcher m = p.matcher(tab);
@@ -548,7 +541,7 @@ private void handleMultipleColorModes()
548541
}
549542
}
550543

551-
544+
552545
public List<List<Range>> getAllScientificNotations() {
553546
//ArrayList<Range> notations[] = new ArrayList[codeTabs.length];
554547
List<List<Range>> notations = new ArrayList<>();
@@ -578,7 +571,7 @@ public static boolean containsTweakComment(String[] codeTabs) {
578571
}
579572
return false;
580573
}
581-
574+
582575

583576
static public boolean lineHasTweakComment(int pos, String code) {
584577
int lineEnd = getEndOfLine(pos, code);
@@ -589,7 +582,7 @@ static public boolean lineHasTweakComment(int pos, String code) {
589582
String line = code.substring(pos, lineEnd);
590583
return hasTweakComment(line);
591584
}
592-
585+
593586

594587
static private boolean hasTweakComment(String code) {
595588
Pattern p = Pattern.compile("\\/\\/.*tweak", Pattern.CASE_INSENSITIVE);
@@ -613,7 +606,7 @@ static private boolean isNegativeSign(int pos, String code) {
613606
return false;
614607
}
615608

616-
609+
617610
static private int getNumDigitsAfterPoint(String number) {
618611
Pattern p = Pattern.compile("\\.[0-9]+");
619612
Matcher m = p.matcher(number);
@@ -624,13 +617,13 @@ static private int getNumDigitsAfterPoint(String number) {
624617
return 0;
625618
}
626619

627-
620+
628621
static private int countLines(String str) {
629622
String[] lines = str.split("\r\n|\n\r|\n|\r");
630623
return lines.length;
631624
}
632625

633-
626+
634627
/**
635628
* Are we inside a string? (TODO: ignore comments in the code)
636629
* @param pos
@@ -721,12 +714,12 @@ static private boolean isInComment(int pos, String code) {
721714
return false;
722715
}
723716

724-
717+
725718
static private int getEndOfLine(int pos, String code) {
726719
return code.indexOf("\n", pos);
727720
}
728721

729-
722+
730723
static private int getStartOfLine(int pos, String code) {
731724
while (pos >= 0) {
732725
if (code.charAt(pos) == '\n') {
@@ -738,7 +731,7 @@ static private int getStartOfLine(int pos, String code) {
738731
return 0;
739732
}
740733

741-
734+
742735
/** returns the object of the function starting at 'pos'
743736
*
744737
* @param pos
@@ -769,7 +762,7 @@ else if (readObject) {
769762
return obj;
770763
}
771764

772-
765+
773766
static public int getSetupStart(String code) {
774767
Pattern p = Pattern.compile("void[\\s\\t\\r\\n]*setup[\\s\\t]*\\(\\)[\\s\\t\\r\\n]*\\{");
775768
Matcher m = p.matcher(code);
@@ -786,7 +779,7 @@ static public int getSetupStart(String code) {
786779
// return str.substring(0, start) + put + str.substring(end, str.length());
787780
// }
788781

789-
782+
790783
class Range {
791784
int start;
792785
int end;

0 commit comments

Comments
 (0)