Skip to content

Commit 8c69ea5

Browse files
committed
starting to move syntax coloring out of theme.txt and back into Preferences
1 parent 03da36e commit 8c69ea5

File tree

13 files changed

+152
-231
lines changed

13 files changed

+152
-231
lines changed

android/theme/theme.txt

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -78,35 +78,3 @@ editor.eolmarkers.color = #999999
7878
# bracket/brace highlighting
7979
editor.brackethighlight = true
8080
editor.brackethighlight.color = #006699
81-
82-
83-
# TEXT - KEYWORDS, LITERALS
84-
# For an explanation of these tags, see Token.java
85-
# trunk/processing/app/src/processing/app/syntax/Token.java
86-
87-
editor.function1.style = #006699,plain
88-
editor.function2.style = #006699,plain
89-
editor.function3.style = #669933,plain
90-
editor.keyword1.style = #996633,plain
91-
editor.keyword2.style = #996633,plain
92-
editor.keyword3.style = #669933,plain
93-
editor.keyword4.style = #ff6699,plain
94-
editor.keyword5.style = #cc6633,plain
95-
editor.literal1.style = #7D4793,plain
96-
editor.literal2.style = #666666,plain
97-
editor.function3.style = #627516,plain
98-
99-
editor.keyword4.style = #627516,plain
100-
editor.keyword5.style = #627516,plain
101-
102-
# e.g. + - = /
103-
editor.operator.style = #000000,plain
104-
105-
# ?? maybe this is for words followed by a colon
106-
# like in case statements or goto
107-
editor.label.style = #7e7e7e,bold
108-
109-
#editor.comment1.style = #7e7e7e,plain
110-
#editor.comment2.style = #7e7e7e,plain
111-
editor.comment1.style = #666666,plain
112-
editor.comment2.style = #666666,plain

app/src/processing/app/Editor.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,9 @@ public void windowGainedFocus(WindowEvent e) {
275275

276276
// Open the document that was passed in
277277
boolean loaded = handleOpenInternal(path);
278-
if (!loaded) sketch = null;
278+
if (!loaded) {
279+
sketch = null;
280+
}
279281
}
280282

281283

app/src/processing/app/Mode.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -863,13 +863,22 @@ public Font getFont(String attribute) {
863863

864864

865865
public SyntaxStyle getStyle(String attribute) {
866-
SyntaxStyle style = theme.getStyle(attribute);
867-
if (style == null) {
868-
// System.err.println("No style coloring found for " + attribute);
869-
// style = new SyntaxStyle(Color.BLACK, false, false);
866+
String str = Preferences.get("editor.token." + attribute + ".style");
867+
if (str == null) {
870868
throw new IllegalArgumentException("No style found for " + attribute);
871869
}
872-
return style;
870+
871+
StringTokenizer st = new StringTokenizer(str, ",");
872+
873+
String s = st.nextToken();
874+
if (s.indexOf("#") == 0) s = s.substring(1);
875+
Color color = new Color(Integer.parseInt(s, 16));
876+
877+
s = st.nextToken();
878+
boolean bold = (s.indexOf("bold") != -1);
879+
boolean italic = (s.indexOf("italic") != -1);
880+
881+
return new SyntaxStyle(color, italic, bold);
873882
}
874883

875884

app/src/processing/app/Settings.java

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import java.io.*;
2828
import java.util.*;
2929

30-
import processing.app.syntax.*;
3130
import processing.core.*;
3231

3332

@@ -210,21 +209,4 @@ public Font getFont(String attr) {
210209

211210
return font;
212211
}
213-
214-
215-
public SyntaxStyle getStyle(String what) {
216-
String str = get("editor." + what + ".style");
217-
218-
StringTokenizer st = new StringTokenizer(str, ",");
219-
220-
String s = st.nextToken();
221-
if (s.indexOf("#") == 0) s = s.substring(1);
222-
Color color = new Color(Integer.parseInt(s, 16));
223-
224-
s = st.nextToken();
225-
boolean bold = (s.indexOf("bold") != -1);
226-
boolean italic = (s.indexOf("italic") != -1);
227-
228-
return new SyntaxStyle(color, italic, bold);
229-
}
230212
}

app/src/processing/app/syntax/InputHandler.java

Lines changed: 64 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ public void actionPerformed(ActionEvent evt)
480480
else
481481
{
482482
String noWordSep = (String)textArea.getDocument().getProperty("noWordSep");
483-
caret = TextUtilities.findWordStart(lineText,caret,noWordSep);
483+
caret = findWordStart(lineText,caret,noWordSep);
484484
}
485485

486486
try
@@ -563,7 +563,7 @@ public void actionPerformed(ActionEvent evt)
563563
else
564564
{
565565
String noWordSep = (String)textArea.getDocument().getProperty("noWordSep");
566-
caret = TextUtilities.findWordEnd(lineText,caret,noWordSep);
566+
caret = findWordEnd(lineText,caret,noWordSep);
567567
}
568568

569569
try
@@ -914,7 +914,7 @@ public void actionPerformed(ActionEvent evt)
914914
else
915915
{
916916
String noWordSep = (String)textArea.getDocument().getProperty("noWordSep");
917-
caret = TextUtilities.findWordEnd(lineText,caret,noWordSep);
917+
caret = findWordEnd(lineText,caret,noWordSep);
918918
}
919919

920920
if(select)
@@ -1075,7 +1075,7 @@ public void actionPerformed(ActionEvent evt)
10751075
else
10761076
{
10771077
String noWordSep = (String)textArea.getDocument().getProperty("noWordSep");
1078-
caret = TextUtilities.findWordStart(lineText,caret,noWordSep);
1078+
caret = findWordStart(lineText,caret,noWordSep);
10791079
}
10801080

10811081
if(select)
@@ -1162,4 +1162,64 @@ public void actionPerformed(ActionEvent evt)
11621162
}
11631163
}
11641164
}
1165+
1166+
1167+
/**
1168+
* Locates the start of the word at the specified position.
1169+
* Moved from TextUtilities.java [fry 121210].
1170+
* @param line The text
1171+
* @param pos The position
1172+
*/
1173+
public static int findWordStart(String line, int pos, String noWordSep)
1174+
{
1175+
char ch = line.charAt(pos - 1);
1176+
1177+
if(noWordSep == null)
1178+
noWordSep = "";
1179+
boolean selectNoLetter = (!Character.isLetterOrDigit(ch)
1180+
&& noWordSep.indexOf(ch) == -1);
1181+
1182+
int wordStart = 0;
1183+
for(int i = pos - 1; i >= 0; i--)
1184+
{
1185+
ch = line.charAt(i);
1186+
if(selectNoLetter ^ (!Character.isLetterOrDigit(ch) &&
1187+
noWordSep.indexOf(ch) == -1))
1188+
{
1189+
wordStart = i + 1;
1190+
break;
1191+
}
1192+
}
1193+
1194+
return wordStart;
1195+
}
1196+
1197+
/**
1198+
* Locates the end of the word at the specified position.
1199+
* Moved from TextUtilities.java [fry 121210].
1200+
* @param line The text
1201+
* @param pos The position
1202+
*/
1203+
public static int findWordEnd(String line, int pos, String noWordSep)
1204+
{
1205+
char ch = line.charAt(pos);
1206+
1207+
if(noWordSep == null)
1208+
noWordSep = "";
1209+
boolean selectNoLetter = (!Character.isLetterOrDigit(ch)
1210+
&& noWordSep.indexOf(ch) == -1);
1211+
1212+
int wordEnd = line.length();
1213+
for(int i = pos; i < line.length(); i++)
1214+
{
1215+
ch = line.charAt(i);
1216+
if(selectNoLetter ^ (!Character.isLetterOrDigit(ch) &&
1217+
noWordSep.indexOf(ch) == -1))
1218+
{
1219+
wordEnd = i;
1220+
break;
1221+
}
1222+
}
1223+
return wordEnd;
1224+
}
11651225
}

app/src/processing/app/syntax/PdeTextAreaDefaults.java

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
public class PdeTextAreaDefaults extends TextAreaDefaults {
3131

32-
public PdeTextAreaDefaults(Mode theme) {
32+
public PdeTextAreaDefaults(Mode mode) {
3333
inputHandler = new DefaultInputHandler();
3434
//inputHandler.addDefaultKeyBindings(); // 0122
3535

@@ -199,38 +199,39 @@ public PdeTextAreaDefaults(Mode theme) {
199199

200200
styles = new SyntaxStyle[Token.ID_COUNT];
201201

202-
styles[Token.COMMENT1] = theme.getStyle("comment1");
203-
styles[Token.COMMENT2] = theme.getStyle("comment2");
202+
styles[Token.COMMENT1] = mode.getStyle("comment1");
203+
styles[Token.COMMENT2] = mode.getStyle("comment2");
204204

205-
styles[Token.KEYWORD1] = theme.getStyle("keyword1");
206-
styles[Token.KEYWORD2] = theme.getStyle("keyword2");
207-
styles[Token.KEYWORD3] = theme.getStyle("keyword3");
208-
styles[Token.KEYWORD4] = theme.getStyle("keyword4");
209-
styles[Token.KEYWORD5] = theme.getStyle("keyword5");
205+
styles[Token.KEYWORD1] = mode.getStyle("keyword1");
206+
styles[Token.KEYWORD2] = mode.getStyle("keyword2");
207+
styles[Token.KEYWORD3] = mode.getStyle("keyword3");
208+
styles[Token.KEYWORD4] = mode.getStyle("keyword4");
209+
styles[Token.KEYWORD5] = mode.getStyle("keyword5");
210210

211-
styles[Token.FUNCTION1] = theme.getStyle("function1");
212-
styles[Token.FUNCTION2] = theme.getStyle("function2");
213-
styles[Token.FUNCTION3] = theme.getStyle("function3");
211+
styles[Token.FUNCTION1] = mode.getStyle("function1");
212+
styles[Token.FUNCTION2] = mode.getStyle("function2");
213+
styles[Token.FUNCTION3] = mode.getStyle("function3");
214+
styles[Token.FUNCTION4] = mode.getStyle("function4");
214215

215-
styles[Token.LITERAL1] = theme.getStyle("literal1");
216-
styles[Token.LITERAL2] = theme.getStyle("literal2");
216+
styles[Token.LITERAL1] = mode.getStyle("literal1");
217+
styles[Token.LITERAL2] = mode.getStyle("literal2");
217218

218-
styles[Token.LABEL] = theme.getStyle("label");
219-
styles[Token.OPERATOR] = theme.getStyle("operator");
219+
styles[Token.LABEL] = mode.getStyle("label");
220+
styles[Token.OPERATOR] = mode.getStyle("operator");
220221

221222
// area that's not in use by the text (replaced with tildes)
222-
styles[Token.INVALID] = theme.getStyle("invalid");
223-
224-
fgcolor = theme.getColor("editor.fgcolor");
225-
bgcolor = theme.getColor("editor.bgcolor");
226-
227-
caretColor = theme.getColor("editor.caret.color");
228-
selectionColor = theme.getColor("editor.selection.color");
229-
lineHighlight = theme.getBoolean("editor.linehighlight");
230-
lineHighlightColor = theme.getColor("editor.linehighlight.color");
231-
bracketHighlight = theme.getBoolean("editor.brackethighlight");
232-
bracketHighlightColor = theme.getColor("editor.brackethighlight.color");
233-
eolMarkers = theme.getBoolean("editor.eolmarkers");
234-
eolMarkerColor = theme.getColor("editor.eolmarkers.color");
223+
styles[Token.INVALID] = mode.getStyle("invalid");
224+
225+
fgcolor = mode.getColor("editor.fgcolor");
226+
bgcolor = mode.getColor("editor.bgcolor");
227+
228+
caretColor = mode.getColor("editor.caret.color");
229+
selectionColor = mode.getColor("editor.selection.color");
230+
lineHighlight = mode.getBoolean("editor.linehighlight");
231+
lineHighlightColor = mode.getColor("editor.linehighlight.color");
232+
bracketHighlight = mode.getBoolean("editor.brackethighlight");
233+
bracketHighlightColor = mode.getColor("editor.brackethighlight.color");
234+
eolMarkers = mode.getBoolean("editor.eolmarkers");
235+
eolMarkerColor = mode.getColor("editor.eolmarkers.color");
235236
}
236237
}

app/src/processing/app/syntax/TextUtilities.java

Lines changed: 0 additions & 76 deletions
This file was deleted.

app/src/processing/app/syntax/Token.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,19 +66,22 @@ public class Token {
6666
/** Loop/function-like blocks (for, while, etc.) */
6767
public static final byte FUNCTION3 = 13;
6868

69+
/** Built-in Processing functions (setup, draw, mouseDragged). */
70+
public static final byte FUNCTION4 = 13;
71+
6972
/**
7073
* Operator token id. This can be used to mark an
7174
* operator. (eg, SQL mode marks +, -, etc with this
7275
* token type)
7376
*/
74-
public static final byte OPERATOR = 14;
77+
public static final byte OPERATOR = 15;
7578

7679
/**
7780
* Invalid token id. This can be used to mark invalid
7881
* or incomplete tokens, so the user can easily spot
7982
* syntax errors.
8083
*/
81-
public static final byte INVALID = 15;
84+
public static final byte INVALID = 16;
8285

8386
/** The total number of defined token ids. */
8487
public static final byte ID_COUNT = INVALID + 1;

0 commit comments

Comments
 (0)