starting to move syntax coloring out of theme.txt and back into Preferences

This commit is contained in:
benfry
2012-12-10 17:22:48 +00:00
parent d836b3c0c9
commit 30a6a4b408
13 changed files with 150 additions and 229 deletions
-32
View File
@@ -78,35 +78,3 @@ editor.eolmarkers.color = #999999
# bracket/brace highlighting
editor.brackethighlight = true
editor.brackethighlight.color = #006699
# TEXT - KEYWORDS, LITERALS
# For an explanation of these tags, see Token.java
# trunk/processing/app/src/processing/app/syntax/Token.java
editor.function1.style = #006699,plain
editor.function2.style = #006699,plain
editor.function3.style = #669933,plain
editor.keyword1.style = #996633,plain
editor.keyword2.style = #996633,plain
editor.keyword3.style = #669933,plain
editor.keyword4.style = #ff6699,plain
editor.keyword5.style = #cc6633,plain
editor.literal1.style = #7D4793,plain
editor.literal2.style = #666666,plain
editor.function3.style = #627516,plain
editor.keyword4.style = #627516,plain
editor.keyword5.style = #627516,plain
# e.g. + - = /
editor.operator.style = #000000,plain
# ?? maybe this is for words followed by a colon
# like in case statements or goto
editor.label.style = #7e7e7e,bold
#editor.comment1.style = #7e7e7e,plain
#editor.comment2.style = #7e7e7e,plain
editor.comment1.style = #666666,plain
editor.comment2.style = #666666,plain
+3 -1
View File
@@ -275,7 +275,9 @@ public abstract class Editor extends JFrame implements RunnerListener {
// Open the document that was passed in
boolean loaded = handleOpenInternal(path);
if (!loaded) sketch = null;
if (!loaded) {
sketch = null;
}
}
+14 -5
View File
@@ -863,13 +863,22 @@ public abstract class Mode {
public SyntaxStyle getStyle(String attribute) {
SyntaxStyle style = theme.getStyle(attribute);
if (style == null) {
// System.err.println("No style coloring found for " + attribute);
// style = new SyntaxStyle(Color.BLACK, false, false);
String str = Preferences.get("editor.token." + attribute + ".style");
if (str == null) {
throw new IllegalArgumentException("No style found for " + attribute);
}
return style;
StringTokenizer st = new StringTokenizer(str, ",");
String s = st.nextToken();
if (s.indexOf("#") == 0) s = s.substring(1);
Color color = new Color(Integer.parseInt(s, 16));
s = st.nextToken();
boolean bold = (s.indexOf("bold") != -1);
boolean italic = (s.indexOf("italic") != -1);
return new SyntaxStyle(color, italic, bold);
}
-18
View File
@@ -27,7 +27,6 @@ import java.awt.*;
import java.io.*;
import java.util.*;
import processing.app.syntax.*;
import processing.core.*;
@@ -210,21 +209,4 @@ public class Settings {
return font;
}
public SyntaxStyle getStyle(String what) {
String str = get("editor." + what + ".style");
StringTokenizer st = new StringTokenizer(str, ",");
String s = st.nextToken();
if (s.indexOf("#") == 0) s = s.substring(1);
Color color = new Color(Integer.parseInt(s, 16));
s = st.nextToken();
boolean bold = (s.indexOf("bold") != -1);
boolean italic = (s.indexOf("italic") != -1);
return new SyntaxStyle(color, italic, bold);
}
}
@@ -480,7 +480,7 @@ public abstract class InputHandler extends KeyAdapter
else
{
String noWordSep = (String)textArea.getDocument().getProperty("noWordSep");
caret = TextUtilities.findWordStart(lineText,caret,noWordSep);
caret = findWordStart(lineText,caret,noWordSep);
}
try
@@ -563,7 +563,7 @@ public abstract class InputHandler extends KeyAdapter
else
{
String noWordSep = (String)textArea.getDocument().getProperty("noWordSep");
caret = TextUtilities.findWordEnd(lineText,caret,noWordSep);
caret = findWordEnd(lineText,caret,noWordSep);
}
try
@@ -914,7 +914,7 @@ public abstract class InputHandler extends KeyAdapter
else
{
String noWordSep = (String)textArea.getDocument().getProperty("noWordSep");
caret = TextUtilities.findWordEnd(lineText,caret,noWordSep);
caret = findWordEnd(lineText,caret,noWordSep);
}
if(select)
@@ -1075,7 +1075,7 @@ public abstract class InputHandler extends KeyAdapter
else
{
String noWordSep = (String)textArea.getDocument().getProperty("noWordSep");
caret = TextUtilities.findWordStart(lineText,caret,noWordSep);
caret = findWordStart(lineText,caret,noWordSep);
}
if(select)
@@ -1162,4 +1162,64 @@ public abstract class InputHandler extends KeyAdapter
}
}
}
/**
* Locates the start of the word at the specified position.
* Moved from TextUtilities.java [fry 121210].
* @param line The text
* @param pos The position
*/
public static int findWordStart(String line, int pos, String noWordSep)
{
char ch = line.charAt(pos - 1);
if(noWordSep == null)
noWordSep = "";
boolean selectNoLetter = (!Character.isLetterOrDigit(ch)
&& noWordSep.indexOf(ch) == -1);
int wordStart = 0;
for(int i = pos - 1; i >= 0; i--)
{
ch = line.charAt(i);
if(selectNoLetter ^ (!Character.isLetterOrDigit(ch) &&
noWordSep.indexOf(ch) == -1))
{
wordStart = i + 1;
break;
}
}
return wordStart;
}
/**
* Locates the end of the word at the specified position.
* Moved from TextUtilities.java [fry 121210].
* @param line The text
* @param pos The position
*/
public static int findWordEnd(String line, int pos, String noWordSep)
{
char ch = line.charAt(pos);
if(noWordSep == null)
noWordSep = "";
boolean selectNoLetter = (!Character.isLetterOrDigit(ch)
&& noWordSep.indexOf(ch) == -1);
int wordEnd = line.length();
for(int i = pos; i < line.length(); i++)
{
ch = line.charAt(i);
if(selectNoLetter ^ (!Character.isLetterOrDigit(ch) &&
noWordSep.indexOf(ch) == -1))
{
wordEnd = i;
break;
}
}
return wordEnd;
}
}
@@ -29,7 +29,7 @@ import processing.app.*;
public class PdeTextAreaDefaults extends TextAreaDefaults {
public PdeTextAreaDefaults(Mode theme) {
public PdeTextAreaDefaults(Mode mode) {
inputHandler = new DefaultInputHandler();
//inputHandler.addDefaultKeyBindings(); // 0122
@@ -199,38 +199,39 @@ public class PdeTextAreaDefaults extends TextAreaDefaults {
styles = new SyntaxStyle[Token.ID_COUNT];
styles[Token.COMMENT1] = theme.getStyle("comment1");
styles[Token.COMMENT2] = theme.getStyle("comment2");
styles[Token.COMMENT1] = mode.getStyle("comment1");
styles[Token.COMMENT2] = mode.getStyle("comment2");
styles[Token.KEYWORD1] = theme.getStyle("keyword1");
styles[Token.KEYWORD2] = theme.getStyle("keyword2");
styles[Token.KEYWORD3] = theme.getStyle("keyword3");
styles[Token.KEYWORD4] = theme.getStyle("keyword4");
styles[Token.KEYWORD5] = theme.getStyle("keyword5");
styles[Token.KEYWORD1] = mode.getStyle("keyword1");
styles[Token.KEYWORD2] = mode.getStyle("keyword2");
styles[Token.KEYWORD3] = mode.getStyle("keyword3");
styles[Token.KEYWORD4] = mode.getStyle("keyword4");
styles[Token.KEYWORD5] = mode.getStyle("keyword5");
styles[Token.FUNCTION1] = theme.getStyle("function1");
styles[Token.FUNCTION2] = theme.getStyle("function2");
styles[Token.FUNCTION3] = theme.getStyle("function3");
styles[Token.FUNCTION1] = mode.getStyle("function1");
styles[Token.FUNCTION2] = mode.getStyle("function2");
styles[Token.FUNCTION3] = mode.getStyle("function3");
styles[Token.FUNCTION4] = mode.getStyle("function4");
styles[Token.LITERAL1] = theme.getStyle("literal1");
styles[Token.LITERAL2] = theme.getStyle("literal2");
styles[Token.LITERAL1] = mode.getStyle("literal1");
styles[Token.LITERAL2] = mode.getStyle("literal2");
styles[Token.LABEL] = theme.getStyle("label");
styles[Token.OPERATOR] = theme.getStyle("operator");
styles[Token.LABEL] = mode.getStyle("label");
styles[Token.OPERATOR] = mode.getStyle("operator");
// area that's not in use by the text (replaced with tildes)
styles[Token.INVALID] = theme.getStyle("invalid");
styles[Token.INVALID] = mode.getStyle("invalid");
fgcolor = theme.getColor("editor.fgcolor");
bgcolor = theme.getColor("editor.bgcolor");
fgcolor = mode.getColor("editor.fgcolor");
bgcolor = mode.getColor("editor.bgcolor");
caretColor = theme.getColor("editor.caret.color");
selectionColor = theme.getColor("editor.selection.color");
lineHighlight = theme.getBoolean("editor.linehighlight");
lineHighlightColor = theme.getColor("editor.linehighlight.color");
bracketHighlight = theme.getBoolean("editor.brackethighlight");
bracketHighlightColor = theme.getColor("editor.brackethighlight.color");
eolMarkers = theme.getBoolean("editor.eolmarkers");
eolMarkerColor = theme.getColor("editor.eolmarkers.color");
caretColor = mode.getColor("editor.caret.color");
selectionColor = mode.getColor("editor.selection.color");
lineHighlight = mode.getBoolean("editor.linehighlight");
lineHighlightColor = mode.getColor("editor.linehighlight.color");
bracketHighlight = mode.getBoolean("editor.brackethighlight");
bracketHighlightColor = mode.getColor("editor.brackethighlight.color");
eolMarkers = mode.getBoolean("editor.eolmarkers");
eolMarkerColor = mode.getColor("editor.eolmarkers.color");
}
}
@@ -1,76 +0,0 @@
/*
* TextUtilities.java - Utility functions used by the text area classes
* Copyright (C) 1999 Slava Pestov
*
* You may use and modify this package for any purpose. Redistribution is
* permitted, in both source and binary form, provided that this notice
* remains intact in all source distributions of this package.
*/
package processing.app.syntax;
/**
* Class with several utility functions used by the text area component.
* @author Slava Pestov
* @version $Id$
*/
public class TextUtilities
{
/**
* Locates the start of the word at the specified position.
* @param line The text
* @param pos The position
*/
public static int findWordStart(String line, int pos, String noWordSep)
{
char ch = line.charAt(pos - 1);
if(noWordSep == null)
noWordSep = "";
boolean selectNoLetter = (!Character.isLetterOrDigit(ch)
&& noWordSep.indexOf(ch) == -1);
int wordStart = 0;
for(int i = pos - 1; i >= 0; i--)
{
ch = line.charAt(i);
if(selectNoLetter ^ (!Character.isLetterOrDigit(ch) &&
noWordSep.indexOf(ch) == -1))
{
wordStart = i + 1;
break;
}
}
return wordStart;
}
/**
* Locates the end of the word at the specified position.
* @param line The text
* @param pos The position
*/
public static int findWordEnd(String line, int pos, String noWordSep)
{
char ch = line.charAt(pos);
if(noWordSep == null)
noWordSep = "";
boolean selectNoLetter = (!Character.isLetterOrDigit(ch)
&& noWordSep.indexOf(ch) == -1);
int wordEnd = line.length();
for(int i = pos; i < line.length(); i++)
{
ch = line.charAt(i);
if(selectNoLetter ^ (!Character.isLetterOrDigit(ch) &&
noWordSep.indexOf(ch) == -1))
{
wordEnd = i;
break;
}
}
return wordEnd;
}
}
+5 -2
View File
@@ -66,19 +66,22 @@ public class Token {
/** Loop/function-like blocks (for, while, etc.) */
public static final byte FUNCTION3 = 13;
/** Built-in Processing functions (setup, draw, mouseDragged). */
public static final byte FUNCTION4 = 13;
/**
* Operator token id. This can be used to mark an
* operator. (eg, SQL mode marks +, -, etc with this
* token type)
*/
public static final byte OPERATOR = 14;
public static final byte OPERATOR = 15;
/**
* Invalid token id. This can be used to mark invalid
* or incomplete tokens, so the user can easily spot
* syntax errors.
*/
public static final byte INVALID = 15;
public static final byte INVALID = 16;
/** The total number of defined token ids. */
public static final byte ID_COUNT = INVALID + 1;
+31
View File
@@ -227,6 +227,37 @@ editor.laf.linux = com.sun.java.swing.plaf.gtk.GTKLookAndFeel
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# TEXT - KEYWORDS, LITERALS
# For an explanation of these tags, see Token.java:
# processing/app/src/processing/app/syntax/Token.java
editor.token.function1.style = #006699,plain
editor.token.function2.style = #006699,plain
editor.token.function3.style = #669933,plain
editor.token.function4.style = #669933,plain
editor.token.keyword1.style = #996633,plain
editor.token.keyword2.style = #996633,plain
editor.token.keyword3.style = #669933,plain
editor.token.keyword4.style = #ff6699,plain
editor.token.keyword5.style = #cc6633,plain
editor.token.literal1.style = #7D4793,plain
editor.token.literal2.style = #666666,plain
editor.token.operator.style = #006699,plain
editor.token.label.style = #7e7e7e,bold
editor.token.comment1.style = #7e7e7e,plain
editor.token.comment2.style = #7e7e7e,plain
editor.token.invalid.style = #7e7e7e,bold
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#history.recording = true
# for advanced users, enable option to export a library
+4
View File
@@ -166,6 +166,10 @@ _ so that it could avoid quitting if the sketch hasn't been stopped
_ or if the sketch window is foremost
_ maybe a hack where a new menubar is added?
_ when using loadFont(), don't enable native fonts unless hint() in use
_ but on createFont(), we're probably OK
_ might need to make reference notes about the two behaviors
_ splice() throws ClassCastException when used with objects like PVector
_ http://code.google.com/p/processing/issues/detail?id=1407
-39
View File
@@ -72,45 +72,6 @@ editor.brackethighlight = true
editor.brackethighlight.color = #006699
# TEXT - KEYWORDS
# e.g. Functions
editor.function1.style = #006699,plain
# e.g. Methods (functions inside a class)
editor.function2.style = #006699,plain
# e.g. Datatypes and keywords (void, int, boolean, etc.)
editor.keyword1.style = #D86736,plain
# e.g. Processing fields [variables within a class]
editor.keyword2.style = #EE3C96,plain
# e.g. Processing variables (width, height, focused, etc.)
editor.keyword3.style = #EE3C96,plain
# TEXT - LITERALS
# e.g. Strings (text in quotes)
editor.literal1.style = #7D4793,plain
# e.g. Constants (QUARTER_PI, CORNERS, etc.)
editor.literal2.style = #669933,plain
# e.g. + - = /
editor.operator.style = #006699,plain
# ?? maybe this is for words followed by a colon
# like in case statements or goto
editor.label.style = #7e7e7e,bold
# TEXT - COMMENTS
editor.comment1.style = #7e7e7e,plain
editor.comment2.style = #7e7e7e,plain
# LINE STATUS - editor line number status bar at the bottom of the screen
linestatus.font = SansSerif,plain,10
#linestatus.font.macosx = Helvetica,plain,10
-26
View File
@@ -71,32 +71,6 @@ editor.eolmarkers.color = #999999
editor.brackethighlight = true
editor.brackethighlight.color = #006699
# TEXT - KEYWORDS, LITERALS
# For an explanation of these tags, see Token.java
# trunk/processing/app/src/processing/app/syntax/Token.java
editor.function1.style = #006699,plain
editor.function2.style = #006699,plain
editor.function3.style = #669933,plain
editor.keyword1.style = #996633,plain
editor.keyword2.style = #996633,plain
editor.keyword3.style = #669933,plain
editor.keyword4.style = #ff6699,plain
editor.keyword5.style = #cc6633,plain
editor.literal1.style = #7D4793,plain
editor.literal2.style = #666666,plain
# e.g. + - = /
editor.operator.style = #006699,plain
# ?? maybe this is for words followed by a colon
# like in case statements or goto
editor.label.style = #7e7e7e,bold
# TEXT - COMMENTS
editor.comment1.style = #7e7e7e,plain
editor.comment2.style = #7e7e7e,plain
# LINE STATUS - editor line number status bar at the bottom of the screen
linestatus.font = SansSerif,plain,10
#linestatus.font.macosx = Helvetica,plain,10
+2
View File
@@ -17,6 +17,8 @@ X error checker broken in experimental mode (fix from Manindra)
X http://code.google.com/p/processing/issues/detail?id=1449
X Color coding for if/else in Processing IDE doesn't match
X http://code.google.com/p/processing/issues/detail?id=1457
X add ESC and cmd/ctrl-W to the Examples window
X move token/syntax coloring out of theme.txt and back into preferences
earlier
X include debug mode as 'experimental'?