From 266e9d92d5d65f20b9a8dce27b14d101d5bac6f6 Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Sun, 5 Apr 2020 14:37:25 +0200 Subject: [PATCH] Theme Editor: enabled mark occurrences --- .../themeeditor/FlatThemeEditorPane.java | 9 ++++++ .../themeeditor/FlatThemeTokenMaker.java | 29 ++++++++++++++----- .../com/formdev/flatlaf/themeeditor/light.xml | 4 +-- 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatThemeEditorPane.java b/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatThemeEditorPane.java index b201452f..4500c18e 100644 --- a/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatThemeEditorPane.java +++ b/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatThemeEditorPane.java @@ -17,12 +17,14 @@ package com.formdev.flatlaf.themeeditor; import java.awt.BorderLayout; +import java.awt.Color; import java.awt.Font; import java.io.IOException; import java.nio.charset.StandardCharsets; import javax.swing.JPanel; import org.fife.ui.rsyntaxtextarea.AbstractTokenMakerFactory; import org.fife.ui.rsyntaxtextarea.FileLocation; +import org.fife.ui.rsyntaxtextarea.SyntaxScheme; import org.fife.ui.rsyntaxtextarea.Theme; import org.fife.ui.rsyntaxtextarea.TokenMakerFactory; import org.fife.ui.rtextarea.RTextScrollPane; @@ -51,6 +53,7 @@ class FlatThemeEditorPane // create text area textArea = new FlatSyntaxTextArea(); textArea.setSyntaxEditingStyle( FLATLAF_STYLE ); + textArea.setMarkOccurrences( true ); // theme try { @@ -60,6 +63,12 @@ class FlatThemeEditorPane 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 scrollPane = new RTextScrollPane( textArea ); scrollPane.setLineNumbersEnabled( true ); diff --git a/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatThemeTokenMaker.java b/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatThemeTokenMaker.java index 47a51831..1d5081dc 100644 --- a/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatThemeTokenMaker.java +++ b/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatThemeTokenMaker.java @@ -34,13 +34,13 @@ import org.fife.ui.rsyntaxtextarea.modes.PropertiesFileTokenMaker; public class FlatThemeTokenMaker extends PropertiesFileTokenMaker { - private static final int TOKEN_PROPERTY = Token.IDENTIFIER; - private static final int TOKEN_VARIABLE = Token.VARIABLE; - private static final int TOKEN_NUMBER = Token.LITERAL_NUMBER_DECIMAL_INT; - private static final int TOKEN_COLOR = Token.LITERAL_NUMBER_HEXADECIMAL; - private static final int TOKEN_STRING = Token.LITERAL_STRING_DOUBLE_QUOTE; - private static final int TOKEN_FUNCTION = Token.FUNCTION; - private static final int TOKEN_TYPE = Token.DATA_TYPE; + static final int TOKEN_PROPERTY = Token.IDENTIFIER; + static final int TOKEN_VARIABLE = Token.VARIABLE; + static final int TOKEN_NUMBER = Token.LITERAL_NUMBER_DECIMAL_INT; + static final int TOKEN_COLOR = Token.LITERAL_NUMBER_HEXADECIMAL; + static final int TOKEN_STRING = Token.LITERAL_STRING_DOUBLE_QUOTE; + static final int TOKEN_FUNCTION = Token.FUNCTION; + static final int TOKEN_TYPE = Token.DATA_TYPE; private final TokenMap tokenMap = new TokenMap(); @@ -143,6 +143,21 @@ public class FlatThemeTokenMaker 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 private java.util.HashMap tokenTypeStrMap; diff --git a/flatlaf-theme-editor/src/main/resources/com/formdev/flatlaf/themeeditor/light.xml b/flatlaf-theme-editor/src/main/resources/com/formdev/flatlaf/themeeditor/light.xml index 9b566345..22d780ec 100644 --- a/flatlaf-theme-editor/src/main/resources/com/formdev/flatlaf/themeeditor/light.xml +++ b/flatlaf-theme-editor/src/main/resources/com/formdev/flatlaf/themeeditor/light.xml @@ -48,7 +48,7 @@