mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2025-12-06 14:00:55 +03:00
Compare commits
5 Commits
02636b260a
...
03b7a1c29e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
03b7a1c29e | ||
|
|
60968f77eb | ||
|
|
8bafa37b4a | ||
|
|
04602ac227 | ||
|
|
7ebc1b27c1 |
@@ -11,6 +11,8 @@ FlatLaf Change Log
|
|||||||
|
|
||||||
#### Fixed bugs
|
#### Fixed bugs
|
||||||
|
|
||||||
|
- CheckBox and RadioButton: Fixed styling of custom icon. Also fixed focus width
|
||||||
|
(and preferred size) if using custom icon. (PR #1060)
|
||||||
- TextField: Fixed wrong leading/trailing icon placement if border is set to
|
- TextField: Fixed wrong leading/trailing icon placement if border is set to
|
||||||
`null`. (issue #1047)
|
`null`. (issue #1047)
|
||||||
- Extras: UI defaults inspector: Exclude inspector window from being blocked by
|
- Extras: UI defaults inspector: Exclude inspector window from being blocked by
|
||||||
|
|||||||
@@ -25,6 +25,8 @@ import java.awt.geom.Area;
|
|||||||
import java.awt.geom.Path2D;
|
import java.awt.geom.Path2D;
|
||||||
import java.awt.geom.Rectangle2D;
|
import java.awt.geom.Rectangle2D;
|
||||||
import java.awt.geom.RoundRectangle2D;
|
import java.awt.geom.RoundRectangle2D;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Map;
|
||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
import com.formdev.flatlaf.ui.FlatStylingSupport.UnknownStyleException;
|
import com.formdev.flatlaf.ui.FlatStylingSupport.UnknownStyleException;
|
||||||
import com.formdev.flatlaf.ui.FlatUIUtils;
|
import com.formdev.flatlaf.ui.FlatUIUtils;
|
||||||
@@ -54,6 +56,11 @@ public class FlatCapsLockIcon
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @since 3.7 */
|
||||||
|
public Map<String, Class<?>> getStyleableInfos() throws IllegalArgumentException {
|
||||||
|
return Collections.singletonMap( "capsLockIconColor", Color.class );
|
||||||
|
}
|
||||||
|
|
||||||
/** @since 2.5 */
|
/** @since 2.5 */
|
||||||
public Object getStyleableValue( String key ) {
|
public Object getStyleableValue( String key ) {
|
||||||
switch( key ) {
|
switch( key ) {
|
||||||
|
|||||||
@@ -370,7 +370,7 @@ public class FlatButtonUI
|
|||||||
protected Object applyStyleProperty( AbstractButton b, String key, Object value ) {
|
protected Object applyStyleProperty( AbstractButton b, String key, Object value ) {
|
||||||
if( key.startsWith( "help." ) ) {
|
if( key.startsWith( "help." ) ) {
|
||||||
if( !(helpButtonIcon instanceof FlatHelpButtonIcon) )
|
if( !(helpButtonIcon instanceof FlatHelpButtonIcon) )
|
||||||
return new UnknownStyleException( key );
|
throw new UnknownStyleException( key );
|
||||||
|
|
||||||
if( helpButtonIconShared ) {
|
if( helpButtonIconShared ) {
|
||||||
helpButtonIcon = FlatStylingSupport.cloneIcon( helpButtonIcon );
|
helpButtonIcon = FlatStylingSupport.cloneIcon( helpButtonIcon );
|
||||||
|
|||||||
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package com.formdev.flatlaf.ui;
|
package com.formdev.flatlaf.ui;
|
||||||
|
|
||||||
import java.awt.Color;
|
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.awt.Rectangle;
|
import java.awt.Rectangle;
|
||||||
import java.awt.Toolkit;
|
import java.awt.Toolkit;
|
||||||
@@ -230,7 +229,8 @@ public class FlatPasswordFieldUI
|
|||||||
@Override
|
@Override
|
||||||
public Map<String, Class<?>> getStyleableInfos( JComponent c ) {
|
public Map<String, Class<?>> getStyleableInfos( JComponent c ) {
|
||||||
Map<String, Class<?>> infos = super.getStyleableInfos( c );
|
Map<String, Class<?>> infos = super.getStyleableInfos( c );
|
||||||
infos.put( "capsLockIconColor", Color.class );
|
if( capsLockIcon instanceof FlatCapsLockIcon )
|
||||||
|
infos.putAll( ((FlatCapsLockIcon)capsLockIcon).getStyleableInfos() );
|
||||||
return infos;
|
return infos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -203,11 +203,12 @@ public class FlatRadioButtonUI
|
|||||||
protected Object applyStyleProperty( AbstractButton b, String key, Object value ) {
|
protected Object applyStyleProperty( AbstractButton b, String key, Object value ) {
|
||||||
// style icon
|
// style icon
|
||||||
if( key.startsWith( "icon." ) ) {
|
if( key.startsWith( "icon." ) ) {
|
||||||
|
Icon icon = getRealIcon( b );
|
||||||
if( !(icon instanceof FlatCheckBoxIcon) )
|
if( !(icon instanceof FlatCheckBoxIcon) )
|
||||||
return new UnknownStyleException( key );
|
throw new UnknownStyleException( key );
|
||||||
|
|
||||||
if( iconShared ) {
|
if( icon == this.icon && iconShared ) {
|
||||||
icon = FlatStylingSupport.cloneIcon( icon );
|
this.icon = icon = FlatStylingSupport.cloneIcon( icon );
|
||||||
iconShared = false;
|
iconShared = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -225,6 +226,7 @@ public class FlatRadioButtonUI
|
|||||||
@Override
|
@Override
|
||||||
public Map<String, Class<?>> getStyleableInfos( JComponent c ) {
|
public Map<String, Class<?>> getStyleableInfos( JComponent c ) {
|
||||||
Map<String, Class<?>> infos = FlatStylingSupport.getAnnotatedStyleableInfos( this );
|
Map<String, Class<?>> infos = FlatStylingSupport.getAnnotatedStyleableInfos( this );
|
||||||
|
Icon icon = getRealIcon( c );
|
||||||
if( icon instanceof FlatCheckBoxIcon ) {
|
if( icon instanceof FlatCheckBoxIcon ) {
|
||||||
for( Map.Entry<String, Class<?>> e : ((FlatCheckBoxIcon)icon).getStyleableInfos().entrySet() )
|
for( Map.Entry<String, Class<?>> e : ((FlatCheckBoxIcon)icon).getStyleableInfos().entrySet() )
|
||||||
infos.put( "icon.".concat( e.getKey() ), e.getValue() );
|
infos.put( "icon.".concat( e.getKey() ), e.getValue() );
|
||||||
@@ -237,6 +239,7 @@ public class FlatRadioButtonUI
|
|||||||
public Object getStyleableValue( JComponent c, String key ) {
|
public Object getStyleableValue( JComponent c, String key ) {
|
||||||
// style icon
|
// style icon
|
||||||
if( key.startsWith( "icon." ) ) {
|
if( key.startsWith( "icon." ) ) {
|
||||||
|
Icon icon = getRealIcon( c );
|
||||||
return (icon instanceof FlatCheckBoxIcon)
|
return (icon instanceof FlatCheckBoxIcon)
|
||||||
? ((FlatCheckBoxIcon)icon).getStyleableValue( key.substring( "icon.".length() ) )
|
? ((FlatCheckBoxIcon)icon).getStyleableValue( key.substring( "icon.".length() ) )
|
||||||
: null;
|
: null;
|
||||||
@@ -332,16 +335,18 @@ public class FlatRadioButtonUI
|
|||||||
}
|
}
|
||||||
|
|
||||||
private int getIconFocusWidth( JComponent c ) {
|
private int getIconFocusWidth( JComponent c ) {
|
||||||
AbstractButton b = (AbstractButton) c;
|
Icon icon = getRealIcon( c );
|
||||||
Icon icon = b.getIcon();
|
|
||||||
if( icon == null )
|
|
||||||
icon = getDefaultIcon();
|
|
||||||
|
|
||||||
return (icon instanceof FlatCheckBoxIcon)
|
return (icon instanceof FlatCheckBoxIcon)
|
||||||
? Math.round( UIScale.scale( ((FlatCheckBoxIcon)icon).getFocusWidth() ) )
|
? Math.round( UIScale.scale( ((FlatCheckBoxIcon)icon).getFocusWidth() ) )
|
||||||
: 0;
|
: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Icon getRealIcon( JComponent c ) {
|
||||||
|
AbstractButton b = (AbstractButton) c;
|
||||||
|
Icon icon = b.getIcon();
|
||||||
|
return (icon != null) ? icon : getDefaultIcon();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getBaseline( JComponent c, int width, int height ) {
|
public int getBaseline( JComponent c, int width, int height ) {
|
||||||
return FlatButtonUI.getBaselineImpl( c, width, height );
|
return FlatButtonUI.getBaselineImpl( c, width, height );
|
||||||
|
|||||||
@@ -671,7 +671,7 @@ public class FlatTabbedPaneUI
|
|||||||
// close icon
|
// close icon
|
||||||
if( key.startsWith( "close" ) ) {
|
if( key.startsWith( "close" ) ) {
|
||||||
if( !(closeIcon instanceof FlatTabbedPaneCloseIcon) )
|
if( !(closeIcon instanceof FlatTabbedPaneCloseIcon) )
|
||||||
return new UnknownStyleException( key );
|
throw new UnknownStyleException( key );
|
||||||
|
|
||||||
if( closeIconShared ) {
|
if( closeIconShared ) {
|
||||||
closeIcon = FlatStylingSupport.cloneIcon( closeIcon );
|
closeIcon = FlatStylingSupport.cloneIcon( closeIcon );
|
||||||
|
|||||||
@@ -30,6 +30,9 @@ import org.junit.jupiter.api.AfterAll;
|
|||||||
import org.junit.jupiter.api.BeforeAll;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import com.formdev.flatlaf.icons.*;
|
import com.formdev.flatlaf.icons.*;
|
||||||
|
import com.formdev.flatlaf.ui.TestFlatStyling.CustomCheckBoxIcon;
|
||||||
|
import com.formdev.flatlaf.ui.TestFlatStyling.CustomIcon;
|
||||||
|
import com.formdev.flatlaf.ui.TestFlatStyling.CustomRadioButtonIcon;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Karl Tauber
|
* @author Karl Tauber
|
||||||
@@ -144,7 +147,12 @@ public class TestFlatStyleableInfo
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void checkBox() {
|
void checkBox() {
|
||||||
JCheckBox c = new JCheckBox();
|
checkBox( new JCheckBox() );
|
||||||
|
checkBox( new JCheckBox( new CustomIcon() ) );
|
||||||
|
checkBox( new JCheckBox( new CustomCheckBoxIcon() ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkBox( JCheckBox c ) {
|
||||||
FlatCheckBoxUI ui = (FlatCheckBoxUI) c.getUI();
|
FlatCheckBoxUI ui = (FlatCheckBoxUI) c.getUI();
|
||||||
|
|
||||||
assertTrue( ui.getDefaultIcon() instanceof FlatCheckBoxIcon );
|
assertTrue( ui.getDefaultIcon() instanceof FlatCheckBoxIcon );
|
||||||
@@ -153,6 +161,11 @@ public class TestFlatStyleableInfo
|
|||||||
Map<String, Class<?>> expected = new LinkedHashMap<>();
|
Map<String, Class<?>> expected = new LinkedHashMap<>();
|
||||||
radioButton( expected );
|
radioButton( expected );
|
||||||
|
|
||||||
|
// remove "icon." keys if check box has custom icon
|
||||||
|
Icon icon = c.getIcon();
|
||||||
|
if( icon != null && !(icon instanceof FlatCheckBoxIcon) )
|
||||||
|
expected.keySet().removeIf( key -> key.startsWith( "icon." ) );
|
||||||
|
|
||||||
assertMapEquals( expected, ui.getStyleableInfos( c ) );
|
assertMapEquals( expected, ui.getStyleableInfos( c ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -492,7 +505,12 @@ public class TestFlatStyleableInfo
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void radioButton() {
|
void radioButton() {
|
||||||
JRadioButton c = new JRadioButton();
|
radioButton( new JRadioButton() );
|
||||||
|
radioButton( new JRadioButton( new CustomIcon() ) );
|
||||||
|
radioButton( new JRadioButton( new CustomRadioButtonIcon() ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
private void radioButton( JRadioButton c ) {
|
||||||
FlatRadioButtonUI ui = (FlatRadioButtonUI) c.getUI();
|
FlatRadioButtonUI ui = (FlatRadioButtonUI) c.getUI();
|
||||||
|
|
||||||
assertTrue( ui.getDefaultIcon() instanceof FlatRadioButtonIcon );
|
assertTrue( ui.getDefaultIcon() instanceof FlatRadioButtonIcon );
|
||||||
@@ -504,6 +522,11 @@ public class TestFlatStyleableInfo
|
|||||||
"icon.centerDiameter", float.class
|
"icon.centerDiameter", float.class
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// remove "icon." keys if radio button has custom icon
|
||||||
|
Icon icon = c.getIcon();
|
||||||
|
if( icon != null && !(icon instanceof FlatRadioButtonIcon) )
|
||||||
|
expected.keySet().removeIf( key -> key.startsWith( "icon." ) );
|
||||||
|
|
||||||
assertMapEquals( expected, ui.getStyleableInfos( c ) );
|
assertMapEquals( expected, ui.getStyleableInfos( c ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1112,6 +1135,16 @@ public class TestFlatStyleableInfo
|
|||||||
assertMapEquals( expected, border.getStyleableInfos() );
|
assertMapEquals( expected, border.getStyleableInfos() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void flatScrollPaneBorder() {
|
||||||
|
FlatScrollPaneBorder border = new FlatScrollPaneBorder();
|
||||||
|
|
||||||
|
Map<String, Class<?>> expected = new LinkedHashMap<>();
|
||||||
|
flatScrollPaneBorder( expected );
|
||||||
|
|
||||||
|
assertMapEquals( expected, border.getStyleableInfos() );
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void flatTextBorder() {
|
void flatTextBorder() {
|
||||||
FlatTextBorder border = new FlatTextBorder();
|
FlatTextBorder border = new FlatTextBorder();
|
||||||
@@ -1295,4 +1328,56 @@ public class TestFlatStyleableInfo
|
|||||||
|
|
||||||
assertMapEquals( expected, icon.getStyleableInfos() );
|
assertMapEquals( expected, icon.getStyleableInfos() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void flatClearIcon() {
|
||||||
|
FlatClearIcon icon = new FlatClearIcon();
|
||||||
|
|
||||||
|
Map<String, Class<?>> expected = expectedMap(
|
||||||
|
"clearIconColor", Color.class,
|
||||||
|
"clearIconHoverColor", Color.class,
|
||||||
|
"clearIconPressedColor", Color.class
|
||||||
|
);
|
||||||
|
|
||||||
|
assertMapEquals( expected, icon.getStyleableInfos() );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void flatSearchIcon() {
|
||||||
|
FlatSearchIcon icon = new FlatSearchIcon();
|
||||||
|
|
||||||
|
Map<String, Class<?>> expected = new LinkedHashMap<>();
|
||||||
|
flatSearchIcon( expected );
|
||||||
|
|
||||||
|
assertMapEquals( expected, icon.getStyleableInfos() );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void flatSearchWithHistoryIcon() {
|
||||||
|
FlatSearchWithHistoryIcon icon = new FlatSearchWithHistoryIcon();
|
||||||
|
|
||||||
|
Map<String, Class<?>> expected = new LinkedHashMap<>();
|
||||||
|
flatSearchIcon( expected );
|
||||||
|
|
||||||
|
assertMapEquals( expected, icon.getStyleableInfos() );
|
||||||
|
}
|
||||||
|
|
||||||
|
private void flatSearchIcon( Map<String, Class<?>> expected ) {
|
||||||
|
expectedMap( expected,
|
||||||
|
"searchIconColor", Color.class,
|
||||||
|
"searchIconHoverColor", Color.class,
|
||||||
|
"searchIconPressedColor", Color.class
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void flatCapsLockIcon() {
|
||||||
|
FlatCapsLockIcon icon = new FlatCapsLockIcon();
|
||||||
|
|
||||||
|
Map<String, Class<?>> expected = expectedMap(
|
||||||
|
"capsLockIconColor", Color.class
|
||||||
|
);
|
||||||
|
|
||||||
|
assertMapEquals( expected, icon.getStyleableInfos() );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,6 +67,7 @@ import org.junit.jupiter.api.AfterAll;
|
|||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.BeforeAll;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import com.formdev.flatlaf.icons.FlatCapsLockIcon;
|
||||||
import com.formdev.flatlaf.icons.FlatCheckBoxIcon;
|
import com.formdev.flatlaf.icons.FlatCheckBoxIcon;
|
||||||
import com.formdev.flatlaf.icons.FlatCheckBoxMenuItemIcon;
|
import com.formdev.flatlaf.icons.FlatCheckBoxMenuItemIcon;
|
||||||
import com.formdev.flatlaf.icons.FlatClearIcon;
|
import com.formdev.flatlaf.icons.FlatClearIcon;
|
||||||
@@ -77,6 +78,10 @@ import com.formdev.flatlaf.icons.FlatRadioButtonMenuItemIcon;
|
|||||||
import com.formdev.flatlaf.icons.FlatSearchIcon;
|
import com.formdev.flatlaf.icons.FlatSearchIcon;
|
||||||
import com.formdev.flatlaf.icons.FlatSearchWithHistoryIcon;
|
import com.formdev.flatlaf.icons.FlatSearchWithHistoryIcon;
|
||||||
import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableUI;
|
import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableUI;
|
||||||
|
import com.formdev.flatlaf.ui.FlatStylingSupport.UnknownStyleException;
|
||||||
|
import com.formdev.flatlaf.ui.TestFlatStyling.CustomCheckBoxIcon;
|
||||||
|
import com.formdev.flatlaf.ui.TestFlatStyling.CustomIcon;
|
||||||
|
import com.formdev.flatlaf.ui.TestFlatStyling.CustomRadioButtonIcon;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Karl Tauber
|
* @author Karl Tauber
|
||||||
@@ -269,11 +274,20 @@ public class TestFlatStyleableValue
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void checkBox() {
|
void checkBox() {
|
||||||
JCheckBox c = new JCheckBox();
|
checkBox( new JCheckBox() );
|
||||||
|
checkBox( new JCheckBox( new CustomCheckBoxIcon() ) );
|
||||||
|
checkBox( new JCheckBox( new CustomIcon() ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkBox( JCheckBox c ) {
|
||||||
FlatCheckBoxUI ui = (FlatCheckBoxUI) c.getUI();
|
FlatCheckBoxUI ui = (FlatCheckBoxUI) c.getUI();
|
||||||
|
|
||||||
// FlatCheckBoxUI extends FlatRadioButtonUI
|
// FlatCheckBoxUI extends FlatRadioButtonUI
|
||||||
radioButton( ui, c );
|
radioButton( ui, c );
|
||||||
|
|
||||||
|
// necessary to clear FlatRadioButtonUI.oldStyleValues because
|
||||||
|
// ui.applyStyle(...) operates on shared instance
|
||||||
|
ui.uninstallUI( c );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -536,14 +550,24 @@ public class TestFlatStyleableValue
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void radioButton() {
|
void radioButton() {
|
||||||
JRadioButton c = new JRadioButton();
|
radioButton( new JRadioButton() );
|
||||||
|
radioButton( new JRadioButton( new CustomRadioButtonIcon() ) );
|
||||||
|
radioButton( new JRadioButton( new CustomIcon() ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
private void radioButton( JRadioButton c ) {
|
||||||
FlatRadioButtonUI ui = (FlatRadioButtonUI) c.getUI();
|
FlatRadioButtonUI ui = (FlatRadioButtonUI) c.getUI();
|
||||||
|
|
||||||
assertTrue( ui.getDefaultIcon() instanceof FlatRadioButtonIcon );
|
assertTrue( ui.getDefaultIcon() instanceof FlatRadioButtonIcon );
|
||||||
|
|
||||||
radioButton( ui, c );
|
radioButton( ui, c );
|
||||||
|
|
||||||
testFloat( c, ui, "icon.centerDiameter", 1.23f );
|
if( !(c.getIcon() instanceof CustomIcon) )
|
||||||
|
testFloat( c, ui, "icon.centerDiameter", 1.23f );
|
||||||
|
|
||||||
|
// necessary to clear FlatRadioButtonUI.oldStyleValues because
|
||||||
|
// ui.applyStyle(...) operates on shared instance
|
||||||
|
ui.uninstallUI( c );
|
||||||
}
|
}
|
||||||
|
|
||||||
private void radioButton( FlatRadioButtonUI ui, AbstractButton b ) {
|
private void radioButton( FlatRadioButtonUI ui, AbstractButton b ) {
|
||||||
@@ -551,6 +575,17 @@ public class TestFlatStyleableValue
|
|||||||
|
|
||||||
//---- icon ----
|
//---- icon ----
|
||||||
|
|
||||||
|
if( b.getIcon() instanceof CustomIcon ) {
|
||||||
|
try {
|
||||||
|
ui.applyStyle( b, "icon.focusWidth: 1.23" );
|
||||||
|
assertTrue( false );
|
||||||
|
} catch( UnknownStyleException ex ) {
|
||||||
|
assertEquals( new UnknownStyleException( "icon.focusWidth" ).getMessage(), ex.getMessage() );
|
||||||
|
}
|
||||||
|
assertEquals( null, ui.getStyleableValue( b, "icon.focusWidth" ) );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
testFloat( b, ui, "icon.focusWidth", 1.23f );
|
testFloat( b, ui, "icon.focusWidth", 1.23f );
|
||||||
testColor( b, ui, "icon.focusColor", 0x123456 );
|
testColor( b, ui, "icon.focusColor", 0x123456 );
|
||||||
testFloat( b, ui, "icon.borderWidth", 1.23f );
|
testFloat( b, ui, "icon.borderWidth", 1.23f );
|
||||||
@@ -1290,6 +1325,13 @@ public class TestFlatStyleableValue
|
|||||||
testValue( icon, "searchIconPressedColor", Color.WHITE );
|
testValue( icon, "searchIconPressedColor", Color.WHITE );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void flatCapsLockIcon() {
|
||||||
|
FlatCapsLockIcon icon = new FlatCapsLockIcon();
|
||||||
|
|
||||||
|
testValue( icon, "capsLockIconColor", Color.WHITE );
|
||||||
|
}
|
||||||
|
|
||||||
//---- class TestIcon -----------------------------------------------------
|
//---- class TestIcon -----------------------------------------------------
|
||||||
|
|
||||||
@SuppressWarnings( "EqualsHashCode" ) // Error Prone
|
@SuppressWarnings( "EqualsHashCode" ) // Error Prone
|
||||||
|
|||||||
@@ -19,10 +19,15 @@ package com.formdev.flatlaf.ui;
|
|||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
|
import java.awt.Component;
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
|
import java.awt.Graphics;
|
||||||
import java.awt.Insets;
|
import java.awt.Insets;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import javax.swing.table.JTableHeader;
|
import javax.swing.table.JTableHeader;
|
||||||
@@ -31,6 +36,7 @@ import org.junit.jupiter.api.BeforeAll;
|
|||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import com.formdev.flatlaf.FlatLaf;
|
import com.formdev.flatlaf.FlatLaf;
|
||||||
import com.formdev.flatlaf.icons.*;
|
import com.formdev.flatlaf.icons.*;
|
||||||
|
import com.formdev.flatlaf.ui.FlatStylingSupport.UnknownStyleException;
|
||||||
import com.formdev.flatlaf.util.ColorFunctions;
|
import com.formdev.flatlaf.util.ColorFunctions;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -47,6 +53,14 @@ public class TestFlatStyling
|
|||||||
FlatLaf.setGlobalExtraDefaults( globalExtraDefaults );
|
FlatLaf.setGlobalExtraDefaults( globalExtraDefaults );
|
||||||
|
|
||||||
TestUtils.setup( false );
|
TestUtils.setup( false );
|
||||||
|
|
||||||
|
Set<String> excludes = new HashSet<>();
|
||||||
|
Collections.addAll( excludes,
|
||||||
|
"parse", "parseIfFunction", "parseColorFunctions",
|
||||||
|
"parseReferences", "parseVariables", "parseRecursiveVariables",
|
||||||
|
"enumField", "enumProperty", "enumUIDefaults" );
|
||||||
|
TestUtils.checkImplementedTests( excludes, TestFlatStyling.class,
|
||||||
|
TestFlatStyleableValue.class, TestFlatStyleableInfo.class );
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterAll
|
@AfterAll
|
||||||
@@ -294,13 +308,22 @@ public class TestFlatStyling
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void checkBox() {
|
void checkBox() {
|
||||||
JCheckBox c = new JCheckBox();
|
checkBox( new JCheckBox() );
|
||||||
|
checkBox( new JCheckBox( new CustomIcon() ) );
|
||||||
|
checkBox( new JCheckBox( new CustomCheckBoxIcon() ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkBox( JCheckBox c ) {
|
||||||
FlatCheckBoxUI ui = (FlatCheckBoxUI) c.getUI();
|
FlatCheckBoxUI ui = (FlatCheckBoxUI) c.getUI();
|
||||||
|
|
||||||
assertTrue( ui.getDefaultIcon() instanceof FlatCheckBoxIcon );
|
assertTrue( ui.getDefaultIcon() instanceof FlatCheckBoxIcon );
|
||||||
|
|
||||||
// FlatCheckBoxUI extends FlatRadioButtonUI
|
// FlatCheckBoxUI extends FlatRadioButtonUI
|
||||||
radioButton( ui, c );
|
radioButton( ui, c );
|
||||||
|
|
||||||
|
// necessary to clear FlatRadioButtonUI.oldStyleValues because
|
||||||
|
// ui.applyStyle(...) operates on shared instance
|
||||||
|
ui.uninstallUI( c );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -651,14 +674,24 @@ public class TestFlatStyling
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void radioButton() {
|
void radioButton() {
|
||||||
JRadioButton c = new JRadioButton();
|
radioButton( new JRadioButton() );
|
||||||
|
radioButton( new JRadioButton( new CustomIcon() ) );
|
||||||
|
radioButton( new JRadioButton( new CustomRadioButtonIcon() ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
private void radioButton( JRadioButton c ) {
|
||||||
FlatRadioButtonUI ui = (FlatRadioButtonUI) c.getUI();
|
FlatRadioButtonUI ui = (FlatRadioButtonUI) c.getUI();
|
||||||
|
|
||||||
assertTrue( ui.getDefaultIcon() instanceof FlatRadioButtonIcon );
|
assertTrue( ui.getDefaultIcon() instanceof FlatRadioButtonIcon );
|
||||||
|
|
||||||
radioButton( ui, c );
|
radioButton( ui, c );
|
||||||
|
|
||||||
ui.applyStyle( c, "icon.centerDiameter: 8" );
|
if( !(c.getIcon() instanceof CustomIcon) )
|
||||||
|
ui.applyStyle( c, "icon.centerDiameter: 8" );
|
||||||
|
|
||||||
|
// necessary to clear FlatRadioButtonUI.oldStyleValues because
|
||||||
|
// ui.applyStyle(...) operates on shared instance
|
||||||
|
ui.uninstallUI( c );
|
||||||
}
|
}
|
||||||
|
|
||||||
private void radioButton( FlatRadioButtonUI ui, AbstractButton b ) {
|
private void radioButton( FlatRadioButtonUI ui, AbstractButton b ) {
|
||||||
@@ -676,6 +709,16 @@ public class TestFlatStyling
|
|||||||
|
|
||||||
//---- icon ----
|
//---- icon ----
|
||||||
|
|
||||||
|
if( b.getIcon() instanceof CustomIcon ) {
|
||||||
|
try {
|
||||||
|
ui.applyStyle( b, "icon.focusWidth: 1.5" );
|
||||||
|
assertTrue( false );
|
||||||
|
} catch( UnknownStyleException ex ) {
|
||||||
|
assertEquals( new UnknownStyleException( "icon.focusWidth" ).getMessage(), ex.getMessage() );
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
ui.applyStyle( b, "icon.focusWidth: 1.5" );
|
ui.applyStyle( b, "icon.focusWidth: 1.5" );
|
||||||
ui.applyStyle( b, "icon.focusColor: #fff" );
|
ui.applyStyle( b, "icon.focusColor: #fff" );
|
||||||
ui.applyStyle( b, "icon.borderWidth: 1.5" );
|
ui.applyStyle( b, "icon.borderWidth: 1.5" );
|
||||||
@@ -1333,6 +1376,16 @@ public class TestFlatStyling
|
|||||||
border.applyStyleProperty( "arc", 6 );
|
border.applyStyleProperty( "arc", 6 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void flatScrollPaneBorder() {
|
||||||
|
FlatScrollPaneBorder border = new FlatScrollPaneBorder();
|
||||||
|
|
||||||
|
// FlatScrollPaneBorder extends FlatBorder
|
||||||
|
flatBorder( border );
|
||||||
|
|
||||||
|
border.applyStyleProperty( "arc", 6 );
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void flatTextBorder() {
|
void flatTextBorder() {
|
||||||
FlatTextBorder border = new FlatTextBorder();
|
FlatTextBorder border = new FlatTextBorder();
|
||||||
@@ -1532,6 +1585,13 @@ public class TestFlatStyling
|
|||||||
icon.applyStyleProperty( "searchIconPressedColor", Color.WHITE );
|
icon.applyStyleProperty( "searchIconPressedColor", Color.WHITE );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void flatCapsLockIcon() {
|
||||||
|
FlatCapsLockIcon icon = new FlatCapsLockIcon();
|
||||||
|
|
||||||
|
icon.applyStyleProperty( "capsLockIconColor", Color.WHITE );
|
||||||
|
}
|
||||||
|
|
||||||
//---- enums --------------------------------------------------------------
|
//---- enums --------------------------------------------------------------
|
||||||
|
|
||||||
enum SomeEnum { enumValue1, enumValue2 }
|
enum SomeEnum { enumValue1, enumValue2 }
|
||||||
@@ -1565,4 +1625,34 @@ public class TestFlatStyling
|
|||||||
UIManager.put( "test.enum", null );
|
UIManager.put( "test.enum", null );
|
||||||
assertEquals( SomeEnum.enumValue1, FlatUIUtils.getUIEnum( "test.enum", SomeEnum.class, SomeEnum.enumValue1 ) );
|
assertEquals( SomeEnum.enumValue1, FlatUIUtils.getUIEnum( "test.enum", SomeEnum.class, SomeEnum.enumValue1 ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---- class CustomIcon ---------------------------------------------------
|
||||||
|
|
||||||
|
static class CustomIcon
|
||||||
|
implements Icon
|
||||||
|
{
|
||||||
|
@Override public void paintIcon( Component c, Graphics g, int x, int y ) {}
|
||||||
|
@Override public int getIconWidth() { return 1; }
|
||||||
|
@Override public int getIconHeight() { return 1; }
|
||||||
|
}
|
||||||
|
|
||||||
|
//---- class CustomCheckBoxIcon ----------------------------------------
|
||||||
|
|
||||||
|
static class CustomCheckBoxIcon
|
||||||
|
extends FlatCheckBoxIcon
|
||||||
|
{
|
||||||
|
CustomCheckBoxIcon() {
|
||||||
|
background = Color.green;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//---- class CustomRadioButtonIcon ----------------------------------------
|
||||||
|
|
||||||
|
static class CustomRadioButtonIcon
|
||||||
|
extends FlatRadioButtonIcon
|
||||||
|
{
|
||||||
|
CustomRadioButtonIcon() {
|
||||||
|
background = Color.green;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,9 +17,14 @@
|
|||||||
package com.formdev.flatlaf.ui;
|
package com.formdev.flatlaf.ui;
|
||||||
|
|
||||||
import java.awt.Font;
|
import java.awt.Font;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.TreeMap;
|
||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
import org.opentest4j.AssertionFailedError;
|
import org.opentest4j.AssertionFailedError;
|
||||||
import com.formdev.flatlaf.FlatIntelliJLaf;
|
import com.formdev.flatlaf.FlatIntelliJLaf;
|
||||||
import com.formdev.flatlaf.FlatLightLaf;
|
import com.formdev.flatlaf.FlatLightLaf;
|
||||||
@@ -57,12 +62,44 @@ public class TestUtils
|
|||||||
|
|
||||||
public static void assertMapEquals( Map<?, ?> expected, Map<?, ?> actual ) {
|
public static void assertMapEquals( Map<?, ?> expected, Map<?, ?> actual ) {
|
||||||
if( !Objects.equals( expected, actual ) ) {
|
if( !Objects.equals( expected, actual ) ) {
|
||||||
String expectedStr = String.valueOf( expected ).replace( ", ", ",\n" );
|
String expectedStr = String.valueOf( new TreeMap<>( expected ) ).replace( ", ", ",\n" );
|
||||||
String actualStr = String.valueOf( actual ).replace( ", ", ",\n" );
|
String actualStr = String.valueOf( new TreeMap<>( actual ) ).replace( ", ", ",\n" );
|
||||||
String msg = String.format( "expected: <%s> but was: <%s>", expectedStr, actualStr );
|
String msg = String.format( "expected: <%s> but was: <%s>", expectedStr, actualStr );
|
||||||
|
|
||||||
// pass expected/actual strings to exception for nice diff in IDE
|
// pass expected/actual strings to exception for nice diff in IDE
|
||||||
throw new AssertionFailedError( msg, expectedStr, actualStr );
|
throw new AssertionFailedError( msg, expectedStr, actualStr );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void checkImplementedTests( Set<String> excludes, Class<?> baseClass, Class<?>... classes ) {
|
||||||
|
Set<String> expected = getTestMethods( baseClass );
|
||||||
|
|
||||||
|
for( Class<?> cls : classes ) {
|
||||||
|
Set<String> actual = getTestMethods( cls );
|
||||||
|
|
||||||
|
for( String methodName : expected ) {
|
||||||
|
if( !actual.contains( methodName ) && !excludes.contains( methodName ) ) {
|
||||||
|
throw new AssertionFailedError( "missing " + cls.getSimpleName() + '.' + methodName
|
||||||
|
+ "() for " + baseClass.getSimpleName() + '.' + methodName + "()" );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for( String methodName : actual ) {
|
||||||
|
if( !expected.contains( methodName ) && !excludes.contains( methodName ) ) {
|
||||||
|
throw new AssertionFailedError( "missing " + baseClass.getSimpleName() + '.' + methodName
|
||||||
|
+ "() for " + cls.getSimpleName() + '.' + methodName + "()" );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Set<String> getTestMethods( Class<?> cls ) {
|
||||||
|
HashSet<String> tests = new HashSet<>();
|
||||||
|
Method[] methods = cls.getDeclaredMethods();
|
||||||
|
for( Method m : methods ) {
|
||||||
|
if( m.isAnnotationPresent( Test.class ) )
|
||||||
|
tests.add( m.getName() );
|
||||||
|
}
|
||||||
|
return tests;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user