mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-11 06:27:13 -06:00
List: cellNoFocusBorder, focusCellHighlightBorder and focusSelectedCellHighlightBorder added
This commit is contained in:
@@ -28,6 +28,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.function.Function;
|
||||
import javax.swing.UIDefaults;
|
||||
import javax.swing.UIDefaults.LazyValue;
|
||||
import javax.swing.plaf.ColorUIResource;
|
||||
@@ -36,6 +37,8 @@ import javax.swing.plaf.FontUIResource;
|
||||
import javax.swing.plaf.InsetsUIResource;
|
||||
import javax.swing.plaf.basic.BasicLookAndFeel;
|
||||
import javax.swing.plaf.metal.MetalLookAndFeel;
|
||||
import com.formdev.flatlaf.ui.FlatEmptyBorder;
|
||||
import com.formdev.flatlaf.ui.FlatLineBorder;
|
||||
import com.formdev.flatlaf.util.SystemInfo;
|
||||
|
||||
/**
|
||||
@@ -169,6 +172,10 @@ public abstract class FlatLaf
|
||||
}
|
||||
}
|
||||
|
||||
Function<String, String> resolver = value -> {
|
||||
return resolveValue( properties, value );
|
||||
};
|
||||
|
||||
// get globals, which override all other defaults that end with same suffix
|
||||
HashMap<String, Object> globals = new HashMap<>();
|
||||
for( Map.Entry<Object, Object> e : properties.entrySet() ) {
|
||||
@@ -177,7 +184,7 @@ public abstract class FlatLaf
|
||||
continue;
|
||||
|
||||
String value = resolveValue( properties, (String) e.getValue() );
|
||||
globals.put( key.substring( GLOBAL_PREFIX.length() ), parseValue( key, value ) );
|
||||
globals.put( key.substring( GLOBAL_PREFIX.length() ), parseValue( key, value, resolver ) );
|
||||
}
|
||||
|
||||
// override UI defaults with globals
|
||||
@@ -198,7 +205,7 @@ public abstract class FlatLaf
|
||||
continue;
|
||||
|
||||
String value = resolveValue( properties, (String) e.getValue() );
|
||||
defaults.put( key, parseValue( key, value ) );
|
||||
defaults.put( key, parseValue( key, value, resolver ) );
|
||||
}
|
||||
} catch( IOException ex ) {
|
||||
ex.printStackTrace();
|
||||
@@ -219,7 +226,7 @@ public abstract class FlatLaf
|
||||
return newValue;
|
||||
}
|
||||
|
||||
private Object parseValue( String key, String value ) {
|
||||
private Object parseValue( String key, String value, Function<String, String> resolver ) {
|
||||
value = value.trim();
|
||||
|
||||
// null, false, true
|
||||
@@ -230,8 +237,8 @@ public abstract class FlatLaf
|
||||
}
|
||||
|
||||
// borders
|
||||
if( key.endsWith( ".border" ) )
|
||||
return parseBorder( value );
|
||||
if( key.endsWith( ".border" ) || key.endsWith( "Border" ) )
|
||||
return parseBorder( value, resolver );
|
||||
|
||||
// icons
|
||||
if( key.endsWith( ".icon" ) || key.endsWith( "Icon" ) )
|
||||
@@ -241,16 +248,16 @@ public abstract class FlatLaf
|
||||
if( key.endsWith( ".margin" ) || key.endsWith( ".padding" ) || key.endsWith( "Insets" ) )
|
||||
return parseInsets( value );
|
||||
|
||||
// insets
|
||||
// size
|
||||
if( key.endsWith( "Size" ) && !key.equals( "SplitPane.dividerSize" ))
|
||||
return parseSize( value );
|
||||
|
||||
// insets
|
||||
// width, height
|
||||
if( key.endsWith( "Width" ) || key.endsWith( "Height" ) )
|
||||
return parseInteger( value, true );
|
||||
|
||||
// colors
|
||||
ColorUIResource color = parseColor( value );
|
||||
ColorUIResource color = parseColor( value, false );
|
||||
if( color != null )
|
||||
return color;
|
||||
|
||||
@@ -263,8 +270,22 @@ public abstract class FlatLaf
|
||||
return value;
|
||||
}
|
||||
|
||||
private Object parseBorder( String value ) {
|
||||
return parseInstance( value );
|
||||
private Object parseBorder( String value, Function<String, String> resolver ) {
|
||||
if( value.indexOf( ',' ) >= 0 ) {
|
||||
// top,left,bottom,right[,lineColor]
|
||||
List<String> parts = split( value, ',' );
|
||||
Insets insets = parseInsets( value );
|
||||
ColorUIResource lineColor = (parts.size() == 5)
|
||||
? parseColor( resolver.apply( parts.get( 4 ) ), true )
|
||||
: null;
|
||||
|
||||
return (LazyValue) t -> {
|
||||
return (lineColor != null)
|
||||
? new FlatLineBorder( insets, lineColor )
|
||||
: new FlatEmptyBorder( insets );
|
||||
};
|
||||
} else
|
||||
return parseInstance( value );
|
||||
}
|
||||
|
||||
private Object parseInstance( String value ) {
|
||||
@@ -304,17 +325,21 @@ public abstract class FlatLaf
|
||||
}
|
||||
}
|
||||
|
||||
private ColorUIResource parseColor( String value ) {
|
||||
private ColorUIResource parseColor( String value, boolean reportError ) {
|
||||
try {
|
||||
if( value.length() == 6 ) {
|
||||
int rgb = Integer.parseInt( value, 16 );
|
||||
int rgb = Integer.parseInt( value, 16 );
|
||||
if( value.length() == 6 )
|
||||
return new ColorUIResource( rgb );
|
||||
}
|
||||
if( value.length() == 8 ) {
|
||||
int rgba = Integer.parseInt( value, 16 );
|
||||
return new ColorUIResource( new Color( rgba, true ) );
|
||||
}
|
||||
if( value.length() == 8 )
|
||||
return new ColorUIResource( new Color( rgb, true ) );
|
||||
|
||||
if( reportError )
|
||||
throw new NumberFormatException( value );
|
||||
} catch( NumberFormatException ex ) {
|
||||
if( reportError ) {
|
||||
System.err.println( "invalid color '" + value + "'" );
|
||||
throw ex;
|
||||
}
|
||||
// not a color --> ignore
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -16,11 +16,16 @@
|
||||
|
||||
package com.formdev.flatlaf.ui;
|
||||
|
||||
import static com.formdev.flatlaf.util.UIScale.scale;
|
||||
import java.awt.Component;
|
||||
import java.awt.Insets;
|
||||
import javax.swing.plaf.BorderUIResource;
|
||||
|
||||
/**
|
||||
* Empty border for various components.
|
||||
*
|
||||
* The insets are scaled.
|
||||
*
|
||||
* @author Karl Tauber
|
||||
*/
|
||||
public class FlatEmptyBorder
|
||||
@@ -29,4 +34,26 @@ public class FlatEmptyBorder
|
||||
public FlatEmptyBorder() {
|
||||
super( 0, 0, 0, 0 );
|
||||
}
|
||||
|
||||
public FlatEmptyBorder( int top, int left, int bottom, int right ) {
|
||||
super( top, left, bottom, right );
|
||||
}
|
||||
|
||||
public FlatEmptyBorder( Insets insets ) {
|
||||
super( insets );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Insets getBorderInsets() {
|
||||
return new Insets( scale( top ), scale( left ), scale( bottom ), scale( right ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Insets getBorderInsets( Component c, Insets insets ) {
|
||||
insets.left = scale( left );
|
||||
insets.top = scale( top );
|
||||
insets.right = scale( right );
|
||||
insets.bottom = scale( bottom );
|
||||
return insets;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright 2019 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
|
||||
*
|
||||
* http://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.ui;
|
||||
|
||||
import static com.formdev.flatlaf.util.UIScale.scale;
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Insets;
|
||||
|
||||
/**
|
||||
* Line border for various components.
|
||||
*
|
||||
* Paints a scaled 1px thick line around the component.
|
||||
* The line thickness is not included in the border insets.
|
||||
* The insets should be at least 1,1,1,1.
|
||||
*
|
||||
* @author Karl Tauber
|
||||
*/
|
||||
public class FlatLineBorder
|
||||
extends FlatEmptyBorder
|
||||
{
|
||||
private final Color lineColor;
|
||||
|
||||
public FlatLineBorder( Insets insets, Color lineColor ) {
|
||||
super( insets );
|
||||
this.lineColor = lineColor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paintBorder( Component c, Graphics g, int x, int y, int width, int height ) {
|
||||
Graphics2D g2 = (Graphics2D) g.create();
|
||||
try {
|
||||
FlatUIUtils.setRenderingHints( g2 );
|
||||
g2.setColor( lineColor );
|
||||
FlatUIUtils.drawRoundRectangle( g2, x, y, width, height, 0f, scale( 1f ), 0f );
|
||||
} finally {
|
||||
g2.dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,7 @@
|
||||
|
||||
@background=3c3f41
|
||||
@foreground=bbbbbb
|
||||
@selectionBackground=4B6EAF
|
||||
@disabledText=777777
|
||||
@textComponentBackground=45494A
|
||||
@icon=adadad
|
||||
@@ -36,7 +37,7 @@
|
||||
*.caretForeground=@foreground
|
||||
*.inactiveBackground=@background
|
||||
*.inactiveForeground=@foreground
|
||||
*.selectionBackground=4B6EAF
|
||||
*.selectionBackground=@selectionBackground
|
||||
*.selectionForeground=@foreground
|
||||
*.disabledBackground=@background
|
||||
*.disabledForeground=@disabledText
|
||||
|
||||
@@ -80,6 +80,13 @@ FormattedTextField.background=@textComponentBackground
|
||||
FormattedTextField.margin=@textComponentMargin
|
||||
|
||||
|
||||
#---- List ----
|
||||
|
||||
List.cellNoFocusBorder=1,6,1,6
|
||||
List.focusCellHighlightBorder=1,6,1,6,@selectionBackground
|
||||
List.focusSelectedCellHighlightBorder=1,6,1,6,@selectionBackground
|
||||
|
||||
|
||||
#---- PasswordField ----
|
||||
|
||||
PasswordField.border=com.formdev.flatlaf.ui.FlatBorder
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
|
||||
@background=f2f2f2
|
||||
@foreground=000000
|
||||
@selectionBackground=4A6EB7
|
||||
@disabledText=999999
|
||||
@textComponentBackground=ffffff
|
||||
@icon=afafaf
|
||||
@@ -36,7 +37,7 @@
|
||||
*.caretForeground=@foreground
|
||||
*.inactiveBackground=@background
|
||||
*.inactiveForeground=777777
|
||||
*.selectionBackground=4A6EB7
|
||||
*.selectionBackground=@selectionBackground
|
||||
*.selectionForeground=ffffff
|
||||
*.disabledBackground=@background
|
||||
*.disabledForeground=@disabledText
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#---- variables ----
|
||||
|
||||
@background=ccffcc
|
||||
@selectionBackground=00aa00
|
||||
@textComponentBackground=ffffff
|
||||
@icon=afafaf
|
||||
|
||||
@@ -30,8 +31,8 @@
|
||||
*.caretForeground=0000ff
|
||||
*.inactiveBackground=f0f0f0
|
||||
*.inactiveForeground=000088
|
||||
*.selectionBackground=4B6EAF
|
||||
*.selectionForeground=00ff00
|
||||
*.selectionBackground=@selectionBackground
|
||||
*.selectionForeground=ffff00
|
||||
*.disabledBackground=e0e0e0
|
||||
*.disabledForeground=000088
|
||||
*.disabledText=000088
|
||||
@@ -94,6 +95,13 @@ Label.foreground=008800
|
||||
Label.disabledForeground=000088
|
||||
|
||||
|
||||
#---- List ----
|
||||
|
||||
List.cellNoFocusBorder=1,6,1,6
|
||||
List.focusSelectedCellHighlightBorder=1,6,1,6,880000
|
||||
List.focusCellHighlightBorder=1,6,1,6,880000
|
||||
|
||||
|
||||
#---- ProgressBar ----
|
||||
|
||||
ProgressBar.background=88ff88
|
||||
|
||||
Reference in New Issue
Block a user