Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into classx
Browse files Browse the repository at this point in the history
  • Loading branch information
dar-dev committed Dec 23, 2024
2 parents 13a9b4d + 80ba75f commit 70e0bd0
Show file tree
Hide file tree
Showing 14 changed files with 435 additions and 71 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ FlatLaf Change Log

#### New features and improvements

- CheckBox: Support styling indeterminate state of
[tri-state check boxes](https://www.javadoc.io/doc/com.formdev/flatlaf-extras/latest/com/formdev/flatlaf/extras/components/FlatTriStateCheckBox.html).
(PR #936; issue #919)
- List: Support for alternate row highlighting. (PR #939)
- Tree: Support for alternate row highlighting. (PR #903)
- Tree: Support wide cell renderer. (issue #922)
- Extras: `FlatSVGIcon` color filters now can access painting component to
Expand Down

Large diffs are not rendered by default.

15 changes: 13 additions & 2 deletions flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatListUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -304,13 +304,24 @@ protected void paintCell( Graphics g, int row, Rectangle rowBounds, ListCellRend
{
boolean isSelected = selModel.isSelectedIndex( row );

// paint alternating rows
if( alternateRowColor != null && row % 2 != 0 &&
!"ComboBox.list".equals( list.getName() ) ) // combobox does not support alternate row color
{
g.setColor( alternateRowColor );

float arc = UIScale.scale( selectionArc / 2f );
FlatUIUtils.paintSelection( (Graphics2D) g, rowBounds.x, rowBounds.y, rowBounds.width, rowBounds.height,
UIScale.scale( selectionInsets ), arc, arc, arc, arc, 0 );
}

// get renderer component
@SuppressWarnings( "unchecked" )
Component rendererComponent = cellRenderer.getListCellRendererComponent( list,
dataModel.getElementAt( row ), row, isSelected,
FlatUIUtils.isPermanentFocusOwner( list ) && (row == leadIndex) );
//

// use smaller cell width if list is used in JFileChooser
boolean isFileList = Boolean.TRUE.equals( list.getClientProperty( "List.isFileList" ) );
int cx, cw;
if( isFileList ) {
Expand Down
14 changes: 14 additions & 0 deletions flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatUIUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,20 @@ public static boolean isInsetsEmpty( Insets insets ) {
return insets.top == 0 && insets.left == 0 && insets.bottom == 0 && insets.right == 0;
}

/** @since 3.6 */
public static Color stateColor( boolean state, Color stateColor, Color defaultColor ) {
return (state && stateColor != null) ? stateColor : defaultColor;
}

/** @since 3.6 */
public static Color stateColor( boolean state1, Color state1Color,
boolean state2, Color state2Color, Color defaultColor )
{
return (state1 && state1Color != null)
? state1Color
: ((state2 && state2Color != null) ? state2Color : defaultColor);
}

public static Color getUIColor( String key, int defaultColorRGB ) {
Color color = UIManager.getColor( key );
return (color != null) ? color : new Color( defaultColorRGB );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,8 @@ private void radioButton( Map<String, Class<?>> expected ) {
"icon.borderWidth", float.class,
"icon.selectedBorderWidth", float.class,
"icon.disabledSelectedBorderWidth", float.class,
"icon.indeterminateBorderWidth", float.class,
"icon.disabledIndeterminateBorderWidth", float.class,
"icon.arc", int.class,

// enabled
Expand All @@ -526,34 +528,49 @@ private void radioButton( Map<String, Class<?>> expected ) {
"icon.selectedBorderColor", Color.class,
"icon.selectedBackground", Color.class,
"icon.checkmarkColor", Color.class,
"icon.indeterminateBorderColor", Color.class,
"icon.indeterminateBackground", Color.class,
"icon.indeterminateCheckmarkColor", Color.class,

// disabled
"icon.disabledBorderColor", Color.class,
"icon.disabledBackground", Color.class,
"icon.disabledSelectedBorderColor", Color.class,
"icon.disabledSelectedBackground", Color.class,
"icon.disabledCheckmarkColor", Color.class,
"icon.disabledIndeterminateBorderColor", Color.class,
"icon.disabledIndeterminateBackground", Color.class,
"icon.disabledIndeterminateCheckmarkColor", Color.class,

// focused
"icon.focusedBorderColor", Color.class,
"icon.focusedBackground", Color.class,
"icon.focusedSelectedBorderColor", Color.class,
"icon.focusedSelectedBackground", Color.class,
"icon.focusedCheckmarkColor", Color.class,
"icon.focusedIndeterminateBorderColor", Color.class,
"icon.focusedIndeterminateBackground", Color.class,
"icon.focusedIndeterminateCheckmarkColor", Color.class,

// hover
"icon.hoverBorderColor", Color.class,
"icon.hoverBackground", Color.class,
"icon.hoverSelectedBorderColor", Color.class,
"icon.hoverSelectedBackground", Color.class,
"icon.hoverCheckmarkColor", Color.class,
"icon.hoverIndeterminateBorderColor", Color.class,
"icon.hoverIndeterminateBackground", Color.class,
"icon.hoverIndeterminateCheckmarkColor", Color.class,

// pressed
"icon.pressedBorderColor", Color.class,
"icon.pressedBackground", Color.class,
"icon.pressedSelectedBorderColor", Color.class,
"icon.pressedSelectedBackground", Color.class,
"icon.pressedCheckmarkColor", Color.class
"icon.pressedCheckmarkColor", Color.class,
"icon.pressedIndeterminateBorderColor", Color.class,
"icon.pressedIndeterminateBackground", Color.class,
"icon.pressedIndeterminateCheckmarkColor", Color.class
);
}

Expand Down Expand Up @@ -1147,6 +1164,8 @@ private void flatCheckBoxIcon( Map<String, Class<?>> expected ) {
"borderWidth", float.class,
"selectedBorderWidth", float.class,
"disabledSelectedBorderWidth", float.class,
"indeterminateBorderWidth", float.class,
"disabledIndeterminateBorderWidth", float.class,
"arc", int.class,

// enabled
Expand All @@ -1155,34 +1174,49 @@ private void flatCheckBoxIcon( Map<String, Class<?>> expected ) {
"selectedBorderColor", Color.class,
"selectedBackground", Color.class,
"checkmarkColor", Color.class,
"indeterminateBorderColor", Color.class,
"indeterminateBackground", Color.class,
"indeterminateCheckmarkColor", Color.class,

// disabled
"disabledBorderColor", Color.class,
"disabledBackground", Color.class,
"disabledSelectedBorderColor", Color.class,
"disabledSelectedBackground", Color.class,
"disabledCheckmarkColor", Color.class,
"disabledIndeterminateBorderColor", Color.class,
"disabledIndeterminateBackground", Color.class,
"disabledIndeterminateCheckmarkColor", Color.class,

// focused
"focusedBorderColor", Color.class,
"focusedBackground", Color.class,
"focusedSelectedBorderColor", Color.class,
"focusedSelectedBackground", Color.class,
"focusedCheckmarkColor", Color.class,
"focusedIndeterminateBorderColor", Color.class,
"focusedIndeterminateBackground", Color.class,
"focusedIndeterminateCheckmarkColor", Color.class,

// hover
"hoverBorderColor", Color.class,
"hoverBackground", Color.class,
"hoverSelectedBorderColor", Color.class,
"hoverSelectedBackground", Color.class,
"hoverCheckmarkColor", Color.class,
"hoverIndeterminateBorderColor", Color.class,
"hoverIndeterminateBackground", Color.class,
"hoverIndeterminateCheckmarkColor", Color.class,

// pressed
"pressedBorderColor", Color.class,
"pressedBackground", Color.class,
"pressedSelectedBorderColor", Color.class,
"pressedSelectedBackground", Color.class,
"pressedCheckmarkColor", Color.class
"pressedCheckmarkColor", Color.class,
"pressedIndeterminateBorderColor", Color.class,
"pressedIndeterminateBackground", Color.class,
"pressedIndeterminateCheckmarkColor", Color.class
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1149,6 +1149,8 @@ private void flatCheckBoxIcon( FlatCheckBoxIcon icon ) {
testValue( icon, "borderWidth", 1.5f );
testValue( icon, "selectedBorderWidth", 1.5f );
testValue( icon, "disabledSelectedBorderWidth", 1.5f );
testValue( icon, "indeterminateBorderWidth", 1.5f );
testValue( icon, "disabledIndeterminateBorderWidth", 1.5f );
testValue( icon, "arc", 5 );

// enabled
Expand All @@ -1157,34 +1159,49 @@ private void flatCheckBoxIcon( FlatCheckBoxIcon icon ) {
testValue( icon, "selectedBorderColor", Color.WHITE );
testValue( icon, "selectedBackground", Color.WHITE );
testValue( icon, "checkmarkColor", Color.WHITE );
testValue( icon, "indeterminateBorderColor", Color.WHITE );
testValue( icon, "indeterminateBackground", Color.WHITE );
testValue( icon, "indeterminateCheckmarkColor", Color.WHITE );

// disabled
testValue( icon, "disabledBorderColor", Color.WHITE );
testValue( icon, "disabledBackground", Color.WHITE );
testValue( icon, "disabledSelectedBorderColor", Color.WHITE );
testValue( icon, "disabledSelectedBackground", Color.WHITE );
testValue( icon, "disabledCheckmarkColor", Color.WHITE );
testValue( icon, "disabledIndeterminateBorderColor", Color.WHITE );
testValue( icon, "disabledIndeterminateBackground", Color.WHITE );
testValue( icon, "disabledIndeterminateCheckmarkColor", Color.WHITE );

// focused
testValue( icon, "focusedBorderColor", Color.WHITE );
testValue( icon, "focusedBackground", Color.WHITE );
testValue( icon, "focusedSelectedBorderColor", Color.WHITE );
testValue( icon, "focusedSelectedBackground", Color.WHITE );
testValue( icon, "focusedCheckmarkColor", Color.WHITE );
testValue( icon, "focusedIndeterminateBorderColor", Color.WHITE );
testValue( icon, "focusedIndeterminateBackground", Color.WHITE );
testValue( icon, "focusedIndeterminateCheckmarkColor", Color.WHITE );

// hover
testValue( icon, "hoverBorderColor", Color.WHITE );
testValue( icon, "hoverBackground", Color.WHITE );
testValue( icon, "hoverSelectedBorderColor", Color.WHITE );
testValue( icon, "hoverSelectedBackground", Color.WHITE );
testValue( icon, "hoverCheckmarkColor", Color.WHITE );
testValue( icon, "hoverIndeterminateBorderColor", Color.WHITE );
testValue( icon, "hoverIndeterminateBackground", Color.WHITE );
testValue( icon, "hoverIndeterminateCheckmarkColor", Color.WHITE );

// pressed
testValue( icon, "pressedBorderColor", Color.WHITE );
testValue( icon, "pressedBackground", Color.WHITE );
testValue( icon, "pressedSelectedBorderColor", Color.WHITE );
testValue( icon, "pressedSelectedBackground", Color.WHITE );
testValue( icon, "pressedCheckmarkColor", Color.WHITE );
testValue( icon, "pressedIndeterminateBorderColor", Color.WHITE );
testValue( icon, "pressedIndeterminateBackground", Color.WHITE );
testValue( icon, "pressedIndeterminateCheckmarkColor", Color.WHITE );
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1391,6 +1391,8 @@ private void flatCheckBoxIcon( FlatCheckBoxIcon icon ) {
icon.applyStyleProperty( "borderWidth", 1.5f );
icon.applyStyleProperty( "selectedBorderWidth", 1.5f );
icon.applyStyleProperty( "disabledSelectedBorderWidth", 1.5f );
icon.applyStyleProperty( "indeterminateBorderWidth", 1.5f );
icon.applyStyleProperty( "disabledIndeterminateBorderWidth", 1.5f );
icon.applyStyleProperty( "arc", 5 );

// enabled
Expand All @@ -1399,34 +1401,49 @@ private void flatCheckBoxIcon( FlatCheckBoxIcon icon ) {
icon.applyStyleProperty( "selectedBorderColor", Color.WHITE );
icon.applyStyleProperty( "selectedBackground", Color.WHITE );
icon.applyStyleProperty( "checkmarkColor", Color.WHITE );
icon.applyStyleProperty( "indeterminateBorderColor", Color.WHITE );
icon.applyStyleProperty( "indeterminateBackground", Color.WHITE );
icon.applyStyleProperty( "indeterminateCheckmarkColor", Color.WHITE );

// disabled
icon.applyStyleProperty( "disabledBorderColor", Color.WHITE );
icon.applyStyleProperty( "disabledBackground", Color.WHITE );
icon.applyStyleProperty( "disabledSelectedBorderColor", Color.WHITE );
icon.applyStyleProperty( "disabledSelectedBackground", Color.WHITE );
icon.applyStyleProperty( "disabledCheckmarkColor", Color.WHITE );
icon.applyStyleProperty( "disabledIndeterminateBorderColor", Color.WHITE );
icon.applyStyleProperty( "disabledIndeterminateBackground", Color.WHITE );
icon.applyStyleProperty( "disabledIndeterminateCheckmarkColor", Color.WHITE );

// focused
icon.applyStyleProperty( "focusedBorderColor", Color.WHITE );
icon.applyStyleProperty( "focusedBackground", Color.WHITE );
icon.applyStyleProperty( "focusedSelectedBorderColor", Color.WHITE );
icon.applyStyleProperty( "focusedSelectedBackground", Color.WHITE );
icon.applyStyleProperty( "focusedCheckmarkColor", Color.WHITE );
icon.applyStyleProperty( "focusedIndeterminateBorderColor", Color.WHITE );
icon.applyStyleProperty( "focusedIndeterminateBackground", Color.WHITE );
icon.applyStyleProperty( "focusedIndeterminateCheckmarkColor", Color.WHITE );

// hover
icon.applyStyleProperty( "hoverBorderColor", Color.WHITE );
icon.applyStyleProperty( "hoverBackground", Color.WHITE );
icon.applyStyleProperty( "hoverSelectedBorderColor", Color.WHITE );
icon.applyStyleProperty( "hoverSelectedBackground", Color.WHITE );
icon.applyStyleProperty( "hoverCheckmarkColor", Color.WHITE );
icon.applyStyleProperty( "hoverIndeterminateBorderColor", Color.WHITE );
icon.applyStyleProperty( "hoverIndeterminateBackground", Color.WHITE );
icon.applyStyleProperty( "hoverIndeterminateCheckmarkColor", Color.WHITE );

// pressed
icon.applyStyleProperty( "pressedBorderColor", Color.WHITE );
icon.applyStyleProperty( "pressedBackground", Color.WHITE );
icon.applyStyleProperty( "pressedSelectedBorderColor", Color.WHITE );
icon.applyStyleProperty( "pressedSelectedBackground", Color.WHITE );
icon.applyStyleProperty( "pressedCheckmarkColor", Color.WHITE );
icon.applyStyleProperty( "pressedIndeterminateBorderColor", Color.WHITE );
icon.applyStyleProperty( "pressedIndeterminateBackground", Color.WHITE );
icon.applyStyleProperty( "pressedIndeterminateCheckmarkColor", Color.WHITE );
}

@Test
Expand Down
Loading

0 comments on commit 70e0bd0

Please sign in to comment.