mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2025-12-06 22:10:54 +03:00
Theme Editor: mark invalid color values with a curly underline
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright 2020 FormDev Software GmbH
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.formdev.flatlaf;
|
||||
|
||||
/**
|
||||
* Enable accessing package private methods of {@link UIDefaultsLoader}.
|
||||
*
|
||||
* @author Karl Tauber
|
||||
*/
|
||||
public class UIDefaultsLoaderAccessor
|
||||
{
|
||||
public static int parseColorRGBA( String value ) {
|
||||
return UIDefaultsLoader.parseColorRGBA( value );
|
||||
}
|
||||
}
|
||||
@@ -54,6 +54,7 @@ class FlatThemeEditorPane
|
||||
textArea = new FlatSyntaxTextArea();
|
||||
textArea.setSyntaxEditingStyle( FLATLAF_STYLE );
|
||||
textArea.setMarkOccurrences( true );
|
||||
textArea.addParser( new FlatThemeParser() );
|
||||
|
||||
// theme
|
||||
try {
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright 2020 FormDev Software GmbH
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.formdev.flatlaf.themeeditor;
|
||||
|
||||
import javax.swing.text.Element;
|
||||
import org.fife.ui.rsyntaxtextarea.RSyntaxDocument;
|
||||
import org.fife.ui.rsyntaxtextarea.Token;
|
||||
import org.fife.ui.rsyntaxtextarea.parser.AbstractParser;
|
||||
import org.fife.ui.rsyntaxtextarea.parser.DefaultParseResult;
|
||||
import org.fife.ui.rsyntaxtextarea.parser.DefaultParserNotice;
|
||||
import org.fife.ui.rsyntaxtextarea.parser.ParseResult;
|
||||
import com.formdev.flatlaf.UIDefaultsLoaderAccessor;
|
||||
|
||||
/**
|
||||
* Parser for FlatLaf properties files that checks for invalid values.
|
||||
*
|
||||
* @author Karl Tauber
|
||||
*/
|
||||
class FlatThemeParser
|
||||
extends AbstractParser
|
||||
{
|
||||
private final DefaultParseResult result;
|
||||
|
||||
FlatThemeParser() {
|
||||
result = new DefaultParseResult( this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ParseResult parse( RSyntaxDocument doc, String style ) {
|
||||
Element root = doc.getDefaultRootElement();
|
||||
|
||||
result.clearNotices();
|
||||
result.setParsedLines( 0, root.getElementCount() - 1 );
|
||||
|
||||
for( Token token : doc ) {
|
||||
if( token.getType() == FlatThemeTokenMaker.TOKEN_COLOR ) {
|
||||
try {
|
||||
UIDefaultsLoaderAccessor.parseColorRGBA( token.getLexeme() );
|
||||
} catch( IllegalArgumentException ex ) {
|
||||
result.addNotice( new DefaultParserNotice( this,
|
||||
"Invalid color.\n\nUse #RRGGBB, #RRGGBBAA, #RGB or #RGBA",
|
||||
root.getElementIndex( token.getOffset() ),
|
||||
token.getOffset(), token.length() ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,8 @@ Prop.color1=#f80
|
||||
Prop.color2=#ff8800
|
||||
Prop.color3=#f804
|
||||
Prop.color4=#ff880044
|
||||
Prop.color5=#12
|
||||
Prop.color6=#12345
|
||||
Prop.border=1,2,3,4
|
||||
|
||||
Prop.scaledInteger={scaledInteger}123
|
||||
|
||||
Reference in New Issue
Block a user