mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-10 22:17:13 -06:00
Merge PR #375: Accent colors
# Conflicts: # flatlaf-core/src/main/java/com/formdev/flatlaf/FlatLaf.java # flatlaf-core/src/main/java/com/formdev/flatlaf/UIDefaultsLoader.java
This commit is contained in:
@@ -405,6 +405,13 @@ class FlatCompletionProvider
|
||||
setParameterizedCompletionParams( '(', ",", ')' );
|
||||
setParameterChoicesProvider( this );
|
||||
|
||||
addFunction( "if",
|
||||
"condition", "evaluates to true if: is not \"null\" and is not \"false\" and is not an integer with zero value",
|
||||
"trueValue", "used if condition is true",
|
||||
"falseValue", "used if condition is false" );
|
||||
addFunction( "lazy",
|
||||
"uiKey", "UI key (without leading '$')" );
|
||||
|
||||
addFunction( "rgb",
|
||||
"red", "0-255 or 0-100%",
|
||||
"green", "0-255 or 0-100%",
|
||||
@@ -471,6 +478,12 @@ class FlatCompletionProvider
|
||||
addFunction( "shade",
|
||||
"color", colorParamDesc,
|
||||
"weight", weightParamDesc );
|
||||
|
||||
addFunction( "contrast",
|
||||
"color", colorParamDesc,
|
||||
"dark", colorParamDesc,
|
||||
"light", colorParamDesc,
|
||||
"threshold", "(optional) 0-100%, default is 43%" );
|
||||
}
|
||||
|
||||
private void addFunction( String name, String... paramNamesAndDescs ) {
|
||||
|
||||
@@ -31,6 +31,7 @@ import org.fife.ui.rsyntaxtextarea.Token;
|
||||
import com.formdev.flatlaf.FlatLaf;
|
||||
import com.formdev.flatlaf.UIDefaultsLoaderAccessor;
|
||||
import com.formdev.flatlaf.ui.FlatUIUtils;
|
||||
import com.formdev.flatlaf.util.ColorFunctions;
|
||||
import com.formdev.flatlaf.util.HSLColor;
|
||||
import com.formdev.flatlaf.util.UIScale;
|
||||
|
||||
@@ -46,6 +47,7 @@ class FlatThemeEditorOverlay
|
||||
|
||||
static boolean showHSL = true;
|
||||
static boolean showRGB;
|
||||
static boolean showLuma;
|
||||
|
||||
private Font font;
|
||||
private Font baseFont;
|
||||
@@ -80,19 +82,21 @@ class FlatThemeEditorOverlay
|
||||
}
|
||||
|
||||
FontMetrics fm = c.getFontMetrics( font );
|
||||
int space = fm.stringWidth( " " );
|
||||
int maxTextWidth = 0;
|
||||
if( showHSL )
|
||||
maxTextWidth += fm.stringWidth( "HSL 360 100 100" );
|
||||
maxTextWidth += fm.stringWidth( "HSL 360 100 100" ) + space;
|
||||
if( showRGB )
|
||||
maxTextWidth += fm.stringWidth( "#ffffff" );
|
||||
if( showHSL && showRGB )
|
||||
maxTextWidth += fm.stringWidth( " " );
|
||||
maxTextWidth += fm.stringWidth( "#ffffff" ) + space;
|
||||
if( showLuma )
|
||||
maxTextWidth += fm.stringWidth( "100" ) + space;
|
||||
maxTextWidth = Math.max( maxTextWidth - space, 0 );
|
||||
int textHeight = fm.getAscent() - fm.getLeading();
|
||||
|
||||
int width = c.getWidth();
|
||||
int previewWidth = UIScale.scale( COLOR_PREVIEW_WIDTH );
|
||||
int gap = UIScale.scale( 4 );
|
||||
int textGap = (showHSL || showRGB) ? UIScale.scale( 6 ) : 0;
|
||||
int textGap = (showHSL || showRGB || showLuma) ? UIScale.scale( 6 ) : 0;
|
||||
|
||||
// check whether preview is outside of clip bounds
|
||||
if( clipBounds.x + clipBounds.width < width - previewWidth - maxTextWidth - gap - textGap )
|
||||
@@ -123,7 +127,7 @@ class FlatThemeEditorOverlay
|
||||
}
|
||||
|
||||
// paint text
|
||||
if( showHSL || showRGB ) {
|
||||
if( showHSL || showRGB || showLuma ) {
|
||||
int textX = px - textGap - maxTextWidth;
|
||||
if( textX > r.x + gap) {
|
||||
String colorStr = null;
|
||||
@@ -141,6 +145,14 @@ class FlatThemeEditorOverlay
|
||||
else
|
||||
colorStr = rgbStr;
|
||||
}
|
||||
if( showLuma ) {
|
||||
String lumaStr = String.format( "%3d",
|
||||
Math.round( ColorFunctions.luma( color ) * 100 ) );
|
||||
if( colorStr != null )
|
||||
colorStr += " " + lumaStr;
|
||||
else
|
||||
colorStr = lumaStr;
|
||||
}
|
||||
|
||||
int textWidth = fm.stringWidth( colorStr );
|
||||
if( textWidth > maxTextWidth )
|
||||
|
||||
@@ -83,8 +83,9 @@ class FlatThemeFileEditor
|
||||
private static final String KEY_PREVIEW = "preview";
|
||||
private static final String KEY_LAF = "laf";
|
||||
private static final String KEY_FONT_SIZE_INCR = "fontSizeIncr";
|
||||
private static final String KEY_HSL_COLORS = "hslColors";
|
||||
private static final String KEY_RGB_COLORS = "rgbColors";
|
||||
private static final String KEY_SHOW_HSL_COLORS = "showHslColors";
|
||||
private static final String KEY_SHOW_RGB_COLORS = "showRgbColors";
|
||||
private static final String KEY_SHOW_COLOR_LUMA = "showColorLuma";
|
||||
|
||||
private File dir;
|
||||
private Preferences state;
|
||||
@@ -708,9 +709,11 @@ class FlatThemeFileEditor
|
||||
private void colorModelChanged() {
|
||||
FlatThemeEditorOverlay.showHSL = showHSLColorsMenuItem.isSelected();
|
||||
FlatThemeEditorOverlay.showRGB = showRGBColorsMenuItem.isSelected();
|
||||
FlatThemeEditorOverlay.showLuma = showColorLumaMenuItem.isSelected();
|
||||
|
||||
putPrefsBoolean( state, KEY_HSL_COLORS, FlatThemeEditorOverlay.showHSL, true );
|
||||
putPrefsBoolean( state, KEY_RGB_COLORS, FlatThemeEditorOverlay.showRGB, false );
|
||||
putPrefsBoolean( state, KEY_SHOW_HSL_COLORS, FlatThemeEditorOverlay.showHSL, true );
|
||||
putPrefsBoolean( state, KEY_SHOW_RGB_COLORS, FlatThemeEditorOverlay.showRGB, false );
|
||||
putPrefsBoolean( state, KEY_SHOW_COLOR_LUMA, FlatThemeEditorOverlay.showLuma, false );
|
||||
|
||||
repaint();
|
||||
}
|
||||
@@ -762,13 +765,15 @@ class FlatThemeFileEditor
|
||||
directoryField.setModel( model );
|
||||
|
||||
// restore overlay color models
|
||||
FlatThemeEditorOverlay.showHSL = state.getBoolean( KEY_HSL_COLORS, true );
|
||||
FlatThemeEditorOverlay.showRGB = state.getBoolean( KEY_RGB_COLORS, false );
|
||||
FlatThemeEditorOverlay.showHSL = state.getBoolean( KEY_SHOW_HSL_COLORS, true );
|
||||
FlatThemeEditorOverlay.showRGB = state.getBoolean( KEY_SHOW_RGB_COLORS, false );
|
||||
FlatThemeEditorOverlay.showLuma = state.getBoolean( KEY_SHOW_COLOR_LUMA, false );
|
||||
|
||||
// restore menu item selection
|
||||
previewMenuItem.setSelected( state.getBoolean( KEY_PREVIEW, true ) );
|
||||
showHSLColorsMenuItem.setSelected( FlatThemeEditorOverlay.showHSL );
|
||||
showRGBColorsMenuItem.setSelected( FlatThemeEditorOverlay.showRGB );
|
||||
showColorLumaMenuItem.setSelected( FlatThemeEditorOverlay.showLuma );
|
||||
}
|
||||
|
||||
private void saveState() {
|
||||
@@ -884,6 +889,7 @@ class FlatThemeFileEditor
|
||||
resetFontSizeMenuItem = new JMenuItem();
|
||||
showHSLColorsMenuItem = new JCheckBoxMenuItem();
|
||||
showRGBColorsMenuItem = new JCheckBoxMenuItem();
|
||||
showColorLumaMenuItem = new JCheckBoxMenuItem();
|
||||
windowMenu = new JMenu();
|
||||
activateEditorMenuItem = new JMenuItem();
|
||||
nextEditorMenuItem = new JMenuItem();
|
||||
@@ -1031,6 +1037,11 @@ class FlatThemeFileEditor
|
||||
showRGBColorsMenuItem.setText("Show RGB colors (hex)");
|
||||
showRGBColorsMenuItem.addActionListener(e -> colorModelChanged());
|
||||
viewMenu.add(showRGBColorsMenuItem);
|
||||
|
||||
//---- showColorLumaMenuItem ----
|
||||
showColorLumaMenuItem.setText("Show color luma");
|
||||
showColorLumaMenuItem.addActionListener(e -> colorModelChanged());
|
||||
viewMenu.add(showColorLumaMenuItem);
|
||||
}
|
||||
menuBar.add(viewMenu);
|
||||
|
||||
@@ -1140,6 +1151,7 @@ class FlatThemeFileEditor
|
||||
private JMenuItem resetFontSizeMenuItem;
|
||||
private JCheckBoxMenuItem showHSLColorsMenuItem;
|
||||
private JCheckBoxMenuItem showRGBColorsMenuItem;
|
||||
private JCheckBoxMenuItem showColorLumaMenuItem;
|
||||
private JMenu windowMenu;
|
||||
private JMenuItem activateEditorMenuItem;
|
||||
private JMenuItem nextEditorMenuItem;
|
||||
|
||||
@@ -177,6 +177,11 @@ new FormModel {
|
||||
"text": "Show RGB colors (hex)"
|
||||
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "colorModelChanged", false ) )
|
||||
} )
|
||||
add( new FormComponent( "javax.swing.JCheckBoxMenuItem" ) {
|
||||
name: "showColorLumaMenuItem"
|
||||
"text": "Show color luma"
|
||||
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "colorModelChanged", false ) )
|
||||
} )
|
||||
} )
|
||||
add( new FormContainer( "javax.swing.JMenu", new FormLayoutManager( class javax.swing.JMenu ) ) {
|
||||
name: "windowMenu"
|
||||
|
||||
@@ -51,7 +51,11 @@ public class FlatThemeTokenMaker
|
||||
tokenMap.put( "false", Token.LITERAL_BOOLEAN );
|
||||
tokenMap.put( "true", Token.LITERAL_BOOLEAN );
|
||||
|
||||
// functions
|
||||
// general functions
|
||||
tokenMap.put( "if", TOKEN_FUNCTION );
|
||||
tokenMap.put( "lazy", TOKEN_FUNCTION );
|
||||
|
||||
// color functions
|
||||
tokenMap.put( "rgb", TOKEN_FUNCTION );
|
||||
tokenMap.put( "rgba", TOKEN_FUNCTION );
|
||||
tokenMap.put( "hsl", TOKEN_FUNCTION );
|
||||
@@ -71,7 +75,7 @@ public class FlatThemeTokenMaker
|
||||
tokenMap.put( "mix", TOKEN_FUNCTION );
|
||||
tokenMap.put( "tint", TOKEN_FUNCTION );
|
||||
tokenMap.put( "shade", TOKEN_FUNCTION );
|
||||
tokenMap.put( "lazy", TOKEN_FUNCTION );
|
||||
tokenMap.put( "contrast", TOKEN_FUNCTION );
|
||||
|
||||
// function options
|
||||
tokenMap.put( "relative", Token.RESERVED_WORD );
|
||||
|
||||
@@ -172,6 +172,7 @@ ComboBox.selectionBackground
|
||||
ComboBox.selectionForeground
|
||||
ComboBox.timeFactor
|
||||
ComboBoxUI
|
||||
Component.accentColor
|
||||
Component.arc
|
||||
Component.arrowType
|
||||
Component.borderColor
|
||||
|
||||
@@ -29,6 +29,24 @@ Prop.true = true
|
||||
Prop.var = @var1
|
||||
Prop.ref = $Prop.string
|
||||
|
||||
Prop.ifNotNull = if(#000,#0f0,#dfd)
|
||||
Prop.ifNull = if(null,#0f0,#dfd)
|
||||
Prop.ifTrue = if(true,#0f0,#dfd)
|
||||
Prop.ifFalse = if(false,#0f0,#dfd)
|
||||
Prop.ifOne = if(1,#0f0,#dfd)
|
||||
Prop.ifZero = if(0,#0f0,#dfd)
|
||||
@varTrue = true
|
||||
@varFalse = false
|
||||
@varTrueValue = #0f0
|
||||
@varFalseValue = #dfd
|
||||
Prop.ifVarTrue = if(@varTrue,@varTrueValue,@varFalseValue)
|
||||
Prop.ifVarFalse = if(@varFalse,@varTrueValue,@varFalseValue)
|
||||
Prop.ifTrueColorFunc = if(true,lighten(#f00,20%),darken(#f00,20%))
|
||||
Prop.ifFalseColorFunc = if(false,lighten(#f00,20%),darken(#f00,20%))
|
||||
Prop.ifUndefinedVar = if(@undefinedVar,#0f0,#dfd)
|
||||
Prop.ifUndefinedProp = if($undefinedProp,#0f0,#dfd)
|
||||
Prop.ifColor = lighten(if(#000,#0f0,#dfd), 10%)
|
||||
Prop.ifColorVar = lighten(if(@varTrue,@varTrueValue,@varFalseValue), 10%)
|
||||
Prop.lazy = lazy(Prop.string)
|
||||
|
||||
Prop.colorFunc1 = rgb(12,34,56)
|
||||
@@ -70,3 +88,32 @@ Prop.colorFunc42 = tint(#f0f,75%)
|
||||
Prop.colorFunc45 = shade(#f0f,25%)
|
||||
Prop.colorFunc46 = shade(#f0f)
|
||||
Prop.colorFunc47 = shade(#f0f,75%)
|
||||
|
||||
Prop.colorFunc50 = contrast(#111,#000,#fff)
|
||||
Prop.colorFunc51 = contrast(#eee,#000,#fff)
|
||||
Prop.colorFunc52 = contrast(#111,$Prop.colorFunc1,$Prop.colorFunc3)
|
||||
Prop.colorFunc53 = contrast(#eee,$Prop.colorFunc1,$Prop.colorFunc3)
|
||||
Prop.colorFunc54 = contrast(lighten(#111,5%),$Prop.colorFunc1,$Prop.colorFunc3)
|
||||
Prop.colorFunc55 = contrast(lighten(#eee,5%),$Prop.colorFunc1,$Prop.colorFunc3)
|
||||
Prop.colorFunc56 = contrast(contrast(#222,#111,#eee),contrast(#eee,#000,#fff),contrast(#111,#000,#fff))
|
||||
|
||||
Prop.1.selectionBackground = #2675BF
|
||||
Prop.1.selectionForeground = contrast($Prop.1.selectionBackground,#000,#fff)
|
||||
|
||||
Prop.2.selectionBackground = #95c0e9
|
||||
Prop.2.selectionForeground = contrast($Prop.2.selectionBackground,#000,#fff)
|
||||
|
||||
Prop.3.selectionBackground = #f00
|
||||
Prop.3.selectionForeground = contrast($Prop.3.selectionBackground,#000,#fff)
|
||||
|
||||
Prop.4.selectionBackground = #0f0
|
||||
Prop.4.selectionForeground = contrast($Prop.4.selectionBackground,#000,#fff)
|
||||
|
||||
Prop.5.selectionBackground = #00f
|
||||
Prop.5.selectionForeground = contrast($Prop.5.selectionBackground,#000,#fff)
|
||||
|
||||
Prop.6.selectionBackground = #FFCC00
|
||||
Prop.6.selectionForeground = contrast($Prop.6.selectionBackground,#000,#fff)
|
||||
|
||||
Prop.7.selectionBackground = #FF9500
|
||||
Prop.7.selectionForeground = contrast($Prop.7.selectionBackground,#000,#fff)
|
||||
|
||||
Reference in New Issue
Block a user