mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2025-12-08 23:08:42 +03:00
Styling:
- check for duplicate keys in StyleableInfos to find "overlapping" fields/properties (e.g. `borderColor` in `FlatBorder` and in `FlatComboBoxUI`) - Button and ToggleButton: fixed styling `toolbar.spacingInsets`
This commit is contained in:
@@ -133,7 +133,6 @@ public class FlatButtonUI
|
||||
@Styleable protected Color shadowColor;
|
||||
@Styleable(dot=true) protected Color defaultShadowColor;
|
||||
|
||||
@Styleable(dot=true) protected Insets toolbarSpacingInsets;
|
||||
@Styleable(dot=true) protected Color toolbarHoverBackground;
|
||||
@Styleable(dot=true) protected Color toolbarPressedBackground;
|
||||
@Styleable(dot=true) protected Color toolbarSelectedBackground;
|
||||
@@ -202,7 +201,6 @@ public class FlatButtonUI
|
||||
shadowColor = UIManager.getColor( "Button.shadowColor" );
|
||||
defaultShadowColor = UIManager.getColor( "Button.default.shadowColor" );
|
||||
|
||||
toolbarSpacingInsets = UIManager.getInsets( "Button.toolbar.spacingInsets" );
|
||||
toolbarHoverBackground = UIManager.getColor( prefix + "toolbar.hoverBackground" );
|
||||
toolbarPressedBackground = UIManager.getColor( prefix + "toolbar.pressedBackground" );
|
||||
toolbarSelectedBackground = UIManager.getColor( prefix + "toolbar.selectedBackground" );
|
||||
@@ -416,8 +414,8 @@ public class FlatButtonUI
|
||||
int width = c.getWidth();
|
||||
int height = c.getHeight();
|
||||
|
||||
if( isToolBarButton ) {
|
||||
Insets spacing = UIScale.scale( toolbarSpacingInsets );
|
||||
if( isToolBarButton && c.getBorder() instanceof FlatButtonBorder ) {
|
||||
Insets spacing = UIScale.scale( ((FlatButtonBorder)c.getBorder()).toolbarSpacingInsets );
|
||||
x += spacing.left;
|
||||
y += spacing.top;
|
||||
width -= spacing.left + spacing.right;
|
||||
|
||||
@@ -42,7 +42,6 @@ import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import javax.swing.AbstractAction;
|
||||
@@ -495,7 +494,7 @@ public class FlatComboBoxUI
|
||||
/** @since 2 */
|
||||
@Override
|
||||
public Map<String, Class<?>> getStyleableInfos( JComponent c ) {
|
||||
Map<String, Class<?>> infos = new LinkedHashMap<>();
|
||||
Map<String, Class<?>> infos = new FlatStylingSupport.StyleableInfosMap<>();
|
||||
infos.put( "padding", Insets.class );
|
||||
FlatStylingSupport.collectAnnotatedStyleableInfos( this, infos );
|
||||
FlatStylingSupport.collectStyleableInfos( comboBox.getBorder(), infos );
|
||||
|
||||
@@ -25,7 +25,6 @@ import java.awt.Insets;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import javax.swing.JComponent;
|
||||
@@ -222,7 +221,7 @@ public class FlatInternalFrameUI
|
||||
|
||||
@Override
|
||||
public Map<String, Class<?>> getStyleableInfos() {
|
||||
Map<String, Class<?>> infos = new LinkedHashMap<>();
|
||||
Map<String, Class<?>> infos = new FlatStylingSupport.StyleableInfosMap<>();
|
||||
FlatStylingSupport.collectAnnotatedStyleableInfos( this, infos );
|
||||
infos.put( "borderMargins", Insets.class );
|
||||
infos.put( "activeDropShadowColor", Color.class );
|
||||
|
||||
@@ -153,6 +153,7 @@ public class FlatMenuItemRenderer
|
||||
Map<String, Class<?>> infos = FlatStylingSupport.getAnnotatedStyleableInfos( this );
|
||||
if( checkIcon instanceof FlatCheckBoxMenuItemIcon )
|
||||
FlatStylingSupport.putAllPrefixKey( infos, "icon.", ((FlatCheckBoxMenuItemIcon)checkIcon).getStyleableInfos() );
|
||||
infos.remove( "icon.selectionForeground" );
|
||||
if( arrowIcon instanceof FlatMenuArrowIcon )
|
||||
FlatStylingSupport.putAllPrefixKey( infos, "icon.", ((FlatMenuArrowIcon)arrowIcon).getStyleableInfos() );
|
||||
infos.remove( "icon.selectionForeground" );
|
||||
|
||||
@@ -20,7 +20,6 @@ import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.JComponent;
|
||||
@@ -145,7 +144,7 @@ public class FlatMenuItemUI
|
||||
}
|
||||
|
||||
static Map<String, Class<?>> getStyleableInfos( FlatMenuItemRenderer renderer ) {
|
||||
Map<String, Class<?>> infos = new LinkedHashMap<>();
|
||||
Map<String, Class<?>> infos = new FlatStylingSupport.StyleableInfosMap<>();
|
||||
infos.put( "selectionBackground", Color.class );
|
||||
infos.put( "selectionForeground", Color.class );
|
||||
infos.put( "disabledForeground", Color.class );
|
||||
|
||||
@@ -20,7 +20,6 @@ import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.Container;
|
||||
import java.awt.Insets;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.UIManager;
|
||||
@@ -61,7 +60,7 @@ public class FlatPopupMenuBorder
|
||||
/** @since 2 */
|
||||
@Override
|
||||
public Map<String, Class<?>> getStyleableInfos() {
|
||||
Map<String, Class<?>> infos = new LinkedHashMap<>();
|
||||
Map<String, Class<?>> infos = new FlatStylingSupport.StyleableInfosMap<>();
|
||||
infos.put( "borderInsets", Insets.class );
|
||||
infos.put( "borderColor", Color.class );
|
||||
return infos;
|
||||
|
||||
@@ -24,7 +24,6 @@ import java.awt.Rectangle;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import javax.swing.InputMap;
|
||||
@@ -259,7 +258,7 @@ public class FlatScrollBarUI
|
||||
/** @since 2 */
|
||||
@Override
|
||||
public Map<String, Class<?>> getStyleableInfos( JComponent c ) {
|
||||
Map<String, Class<?>> infos = new LinkedHashMap<>();
|
||||
Map<String, Class<?>> infos = new FlatStylingSupport.StyleableInfosMap<>();
|
||||
infos.put( "track", Color.class );
|
||||
infos.put( "thumb", Color.class );
|
||||
infos.put( "width", int.class );
|
||||
|
||||
@@ -25,6 +25,7 @@ import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -612,7 +613,7 @@ public class FlatStylingSupport
|
||||
}
|
||||
|
||||
public static Map<String, Class<?>> getAnnotatedStyleableInfos( Object obj, Border border ) {
|
||||
Map<String, Class<?>> infos = new LinkedHashMap<>();
|
||||
Map<String, Class<?>> infos = new StyleableInfosMap<>();
|
||||
collectAnnotatedStyleableInfos( obj, infos );
|
||||
collectStyleableInfos( border, infos );
|
||||
return infos;
|
||||
@@ -623,6 +624,7 @@ public class FlatStylingSupport
|
||||
* The key is the name of the field and the value the type of the field.
|
||||
*/
|
||||
public static void collectAnnotatedStyleableInfos( Object obj, Map<String, Class<?>> infos ) {
|
||||
HashSet<String> processedFields = new HashSet<>();
|
||||
Class<?> cls = obj.getClass();
|
||||
|
||||
for(;;) {
|
||||
@@ -637,6 +639,13 @@ public class FlatStylingSupport
|
||||
String name = f.getName();
|
||||
Class<?> type = f.getType();
|
||||
|
||||
// for the case that the same field name is used in a class and in
|
||||
// one of its superclasses (e.g. field 'borderColor' in FlatButtonBorder
|
||||
// and in FlatBorder), do not process field in superclass
|
||||
if( processedFields.contains( name ) )
|
||||
continue;
|
||||
processedFields.add( name );
|
||||
|
||||
// handle "dot" keys (e.g. change field name "iconArrowType" to style key "icon.arrowType")
|
||||
if( styleable.dot() ) {
|
||||
int len = name.length();
|
||||
@@ -691,4 +700,24 @@ public class FlatStylingSupport
|
||||
return "unknown style '" + super.getMessage() + "'";
|
||||
}
|
||||
}
|
||||
|
||||
//---- class StyleableInfosMap --------------------------------------------
|
||||
|
||||
static class StyleableInfosMap<K,V>
|
||||
extends LinkedHashMap<K,V>
|
||||
{
|
||||
@Override
|
||||
public V put( K key, V value ) {
|
||||
V oldValue = super.put( key, value );
|
||||
if( oldValue != null )
|
||||
throw new IllegalArgumentException( "duplicate key '" + key + "'" );
|
||||
return oldValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putAll( Map<? extends K, ? extends V> m ) {
|
||||
for( Map.Entry<? extends K, ? extends V> e : m.entrySet() )
|
||||
put( e.getKey(), e.getValue() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,7 +52,6 @@ import java.awt.geom.Rectangle2D;
|
||||
import java.beans.PropertyChangeEvent;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@@ -638,7 +637,7 @@ public class FlatTabbedPaneUI
|
||||
/** @since 2 */
|
||||
@Override
|
||||
public Map<String, Class<?>> getStyleableInfos( JComponent c ) {
|
||||
Map<String, Class<?>> infos = new LinkedHashMap<>();
|
||||
Map<String, Class<?>> infos = new FlatStylingSupport.StyleableInfosMap<>();
|
||||
infos.put( "tabInsets", Insets.class );
|
||||
infos.put( "tabAreaInsets", Insets.class );
|
||||
infos.put( "textIconGap", int.class );
|
||||
|
||||
Reference in New Issue
Block a user