mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
starting to move syntax coloring out of theme.txt and back into Preferences
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user