Theme Editor: enabled mark occurrences

This commit is contained in:
Karl Tauber
2020-04-05 14:37:25 +02:00
parent 54c14d0dc8
commit 266e9d92d5
3 changed files with 33 additions and 9 deletions

View File

@@ -17,12 +17,14 @@
package com.formdev.flatlaf.themeeditor; package com.formdev.flatlaf.themeeditor;
import java.awt.BorderLayout; import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font; import java.awt.Font;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import javax.swing.JPanel; import javax.swing.JPanel;
import org.fife.ui.rsyntaxtextarea.AbstractTokenMakerFactory; import org.fife.ui.rsyntaxtextarea.AbstractTokenMakerFactory;
import org.fife.ui.rsyntaxtextarea.FileLocation; import org.fife.ui.rsyntaxtextarea.FileLocation;
import org.fife.ui.rsyntaxtextarea.SyntaxScheme;
import org.fife.ui.rsyntaxtextarea.Theme; import org.fife.ui.rsyntaxtextarea.Theme;
import org.fife.ui.rsyntaxtextarea.TokenMakerFactory; import org.fife.ui.rsyntaxtextarea.TokenMakerFactory;
import org.fife.ui.rtextarea.RTextScrollPane; import org.fife.ui.rtextarea.RTextScrollPane;
@@ -51,6 +53,7 @@ class FlatThemeEditorPane
// create text area // create text area
textArea = new FlatSyntaxTextArea(); textArea = new FlatSyntaxTextArea();
textArea.setSyntaxEditingStyle( FLATLAF_STYLE ); textArea.setSyntaxEditingStyle( FLATLAF_STYLE );
textArea.setMarkOccurrences( true );
// theme // theme
try { try {
@@ -60,6 +63,12 @@ class FlatThemeEditorPane
ex.printStackTrace(); ex.printStackTrace();
} }
// use semitransparent token background because token background
// is painted over mark occurrences background
SyntaxScheme scheme = textArea.getSyntaxScheme();
scheme.getStyle( FlatThemeTokenMaker.TOKEN_COLOR ).background = new Color( 0x0a000000, true );
scheme.getStyle( FlatThemeTokenMaker.TOKEN_VARIABLE ).background = new Color( 0x1800cc00, true );
// create scroll pane // create scroll pane
scrollPane = new RTextScrollPane( textArea ); scrollPane = new RTextScrollPane( textArea );
scrollPane.setLineNumbersEnabled( true ); scrollPane.setLineNumbersEnabled( true );

View File

@@ -34,13 +34,13 @@ import org.fife.ui.rsyntaxtextarea.modes.PropertiesFileTokenMaker;
public class FlatThemeTokenMaker public class FlatThemeTokenMaker
extends PropertiesFileTokenMaker extends PropertiesFileTokenMaker
{ {
private static final int TOKEN_PROPERTY = Token.IDENTIFIER; static final int TOKEN_PROPERTY = Token.IDENTIFIER;
private static final int TOKEN_VARIABLE = Token.VARIABLE; static final int TOKEN_VARIABLE = Token.VARIABLE;
private static final int TOKEN_NUMBER = Token.LITERAL_NUMBER_DECIMAL_INT; static final int TOKEN_NUMBER = Token.LITERAL_NUMBER_DECIMAL_INT;
private static final int TOKEN_COLOR = Token.LITERAL_NUMBER_HEXADECIMAL; static final int TOKEN_COLOR = Token.LITERAL_NUMBER_HEXADECIMAL;
private static final int TOKEN_STRING = Token.LITERAL_STRING_DOUBLE_QUOTE; static final int TOKEN_STRING = Token.LITERAL_STRING_DOUBLE_QUOTE;
private static final int TOKEN_FUNCTION = Token.FUNCTION; static final int TOKEN_FUNCTION = Token.FUNCTION;
private static final int TOKEN_TYPE = Token.DATA_TYPE; static final int TOKEN_TYPE = Token.DATA_TYPE;
private final TokenMap tokenMap = new TokenMap(); private final TokenMap tokenMap = new TokenMap();
@@ -143,6 +143,21 @@ public class FlatThemeTokenMaker
return RSyntaxUtilities.isLetterOrDigit( ch ) || ch == '.' || ch == '_' || ch == '-'; return RSyntaxUtilities.isLetterOrDigit( ch ) || ch == '.' || ch == '_' || ch == '-';
} }
@Override
public boolean getMarkOccurrencesOfTokenType( int type ) {
switch( type ) {
case TOKEN_PROPERTY:
case TOKEN_VARIABLE:
case TOKEN_COLOR:
case TOKEN_FUNCTION:
case TOKEN_TYPE:
return true;
default:
return false;
}
}
/*debug /*debug
private java.util.HashMap<Integer, String> tokenTypeStrMap; private java.util.HashMap<Integer, String> tokenTypeStrMap;

View File

@@ -48,7 +48,7 @@
<style token="LITERAL_BOOLEAN" fg="871094"/> <style token="LITERAL_BOOLEAN" fg="871094"/>
<style token="LITERAL_NUMBER_DECIMAL_INT" fg="1750EB"/> <style token="LITERAL_NUMBER_DECIMAL_INT" fg="1750EB"/>
<style token="LITERAL_NUMBER_FLOAT" fg="1750EB"/> <style token="LITERAL_NUMBER_FLOAT" fg="1750EB"/>
<style token="LITERAL_NUMBER_HEXADECIMAL" fg="1750EB" bg="f2f2f2"/> <style token="LITERAL_NUMBER_HEXADECIMAL" fg="1750EB"/>
<style token="LITERAL_STRING_DOUBLE_QUOTE" fg="008000"/> <style token="LITERAL_STRING_DOUBLE_QUOTE" fg="008000"/>
<style token="LITERAL_CHAR" fg="DC009C"/> <style token="LITERAL_CHAR" fg="DC009C"/>
<style token="LITERAL_BACKQUOTE" fg="DC009C"/> <style token="LITERAL_BACKQUOTE" fg="DC009C"/>
@@ -66,7 +66,7 @@
<style token="PREPROCESSOR" fg="808080"/> <style token="PREPROCESSOR" fg="808080"/>
<style token="REGEX" fg="008040"/> <style token="REGEX" fg="008040"/>
<style token="SEPARATOR" fg="ff0000"/> <style token="SEPARATOR" fg="ff0000"/>
<style token="VARIABLE" fg="000000" bg="EDFCED"/> <style token="VARIABLE" fg="000000"/>
<style token="WHITESPACE" fg="000000"/> <style token="WHITESPACE" fg="000000"/>
<style token="ERROR_IDENTIFIER" fg="000000" bg="ffcccc"/> <style token="ERROR_IDENTIFIER" fg="000000" bg="ffcccc"/>