Tree: Fixed missing custom closed/opened/leaf icons of a custom DefaultTreeCellRenderer. (issue #653; regression since implementing PR #609 in FlatLaf 3.0)

This commit is contained in:
Karl Tauber
2023-03-02 23:06:35 +01:00
parent 465798ee3d
commit 2f5c54bb49
4 changed files with 42 additions and 3 deletions

View File

@@ -38,6 +38,9 @@ FlatLaf Change Log
- Updated "Hiberbee Dark" and "Material Theme UI Lite" themes. - Updated "Hiberbee Dark" and "Material Theme UI Lite" themes.
- Styling: Fixed resolving of UI variables in styles that use other variables. - Styling: Fixed resolving of UI variables in styles that use other variables.
- MenuItem: Fixed horizontal alignment of icons. (issue #631) - MenuItem: Fixed horizontal alignment of icons. (issue #631)
- Tree: Fixed missing custom closed/opened/leaf icons of a custom
`DefaultTreeCellRenderer`. (issue #653; regression since implementing PR #609
in FlatLaf 3.0)
- Tree: Fixed truncated node text and too small painted non-wide node background - Tree: Fixed truncated node text and too small painted non-wide node background
if custom cell renderer sets icon, but not disabled icon, and tree is if custom cell renderer sets icon, but not disabled icon, and tree is
disabled. (issue #640) disabled. (issue #640)

View File

@@ -158,6 +158,10 @@ public class FlatTreeUI
// only used via styling (not in UI defaults, but has likewise client properties) // only used via styling (not in UI defaults, but has likewise client properties)
/** @since 2 */ @Styleable protected boolean paintSelection = true; /** @since 2 */ @Styleable protected boolean paintSelection = true;
private Icon defaultLeafIcon;
private Icon defaultClosedIcon;
private Icon defaultOpenIcon;
private boolean paintLines; private boolean paintLines;
private Color defaultCellNonSelectionBackground; private Color defaultCellNonSelectionBackground;
private Color defaultSelectionBackground; private Color defaultSelectionBackground;
@@ -193,6 +197,10 @@ public class FlatTreeUI
showCellFocusIndicator = UIManager.getBoolean( "Tree.showCellFocusIndicator" ); showCellFocusIndicator = UIManager.getBoolean( "Tree.showCellFocusIndicator" );
showDefaultIcons = UIManager.getBoolean( "Tree.showDefaultIcons" ); showDefaultIcons = UIManager.getBoolean( "Tree.showDefaultIcons" );
defaultLeafIcon = UIManager.getIcon( "Tree.leafIcon" );
defaultClosedIcon = UIManager.getIcon( "Tree.closedIcon" );
defaultOpenIcon = UIManager.getIcon( "Tree.openIcon" );
paintLines = UIManager.getBoolean( "Tree.paintLines" ); paintLines = UIManager.getBoolean( "Tree.paintLines" );
defaultCellNonSelectionBackground = UIManager.getColor( "Tree.textBackground" ); defaultCellNonSelectionBackground = UIManager.getColor( "Tree.textBackground" );
defaultSelectionBackground = selectionBackground; defaultSelectionBackground = selectionBackground;
@@ -219,6 +227,10 @@ public class FlatTreeUI
selectionInactiveForeground = null; selectionInactiveForeground = null;
selectionBorderColor = null; selectionBorderColor = null;
defaultLeafIcon = null;
defaultClosedIcon = null;
defaultOpenIcon = null;
defaultCellNonSelectionBackground = null; defaultCellNonSelectionBackground = null;
defaultSelectionBackground = null; defaultSelectionBackground = null;
defaultSelectionForeground = null; defaultSelectionForeground = null;
@@ -233,9 +245,14 @@ public class FlatTreeUI
// remove default leaf/closed/opened icons // remove default leaf/closed/opened icons
if( !showDefaultIcons && currentCellRenderer instanceof DefaultTreeCellRenderer ) { if( !showDefaultIcons && currentCellRenderer instanceof DefaultTreeCellRenderer ) {
DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) currentCellRenderer; DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) currentCellRenderer;
renderer.setLeafIcon( null ); if( renderer.getLeafIcon() == defaultLeafIcon &&
renderer.setClosedIcon( null ); renderer.getClosedIcon() == defaultClosedIcon &&
renderer.setOpenIcon( null ); renderer.getOpenIcon() == defaultOpenIcon )
{
renderer.setLeafIcon( null );
renderer.setClosedIcon( null );
renderer.setOpenIcon( null );
}
} }
} }

View File

@@ -439,6 +439,11 @@ public class FlatComponents2Test
tree.setCellRenderer( new TestDefaultTreeCellRenderer() ); tree.setCellRenderer( new TestDefaultTreeCellRenderer() );
break; break;
case "defaultWithIcons":
for( JTree tree : trees )
tree.setCellRenderer( new TestDefaultWithIconsTreeCellRenderer() );
break;
case "defaultWithIcon": case "defaultWithIcon":
for( JTree tree : trees ) for( JTree tree : trees )
tree.setCellRenderer( new TestDefaultWithIconTreeCellRenderer() ); tree.setCellRenderer( new TestDefaultWithIconTreeCellRenderer() );
@@ -960,6 +965,7 @@ public class FlatComponents2Test
treeRendererComboBox.setModel(new DefaultComboBoxModel<>(new String[] { treeRendererComboBox.setModel(new DefaultComboBoxModel<>(new String[] {
"default", "default",
"defaultSubclass", "defaultSubclass",
"defaultWithIcons",
"defaultWithIcon", "defaultWithIcon",
"label", "label",
"swingxDefault", "swingxDefault",
@@ -1612,6 +1618,18 @@ public class FlatComponents2Test
} }
} }
//---- class TestDefaultWithIconsTreeCellRenderer -------------------------
private static class TestDefaultWithIconsTreeCellRenderer
extends TestDefaultTreeCellRenderer
{
public TestDefaultWithIconsTreeCellRenderer() {
setLeafIcon( UIManager.getIcon( "FileView.floppyDriveIcon" ) );
setClosedIcon( UIManager.getIcon( "FileView.hardDriveIcon" ) );
setOpenIcon( UIManager.getIcon( "FileView.computerIcon" ) );
}
}
//---- class TestDefaultWithIconTreeCellRenderer -------------------------- //---- class TestDefaultWithIconTreeCellRenderer --------------------------
private static class TestDefaultWithIconTreeCellRenderer private static class TestDefaultWithIconTreeCellRenderer

View File

@@ -411,6 +411,7 @@ new FormModel {
selectedItem: "default" selectedItem: "default"
addElement( "default" ) addElement( "default" )
addElement( "defaultSubclass" ) addElement( "defaultSubclass" )
addElement( "defaultWithIcons" )
addElement( "defaultWithIcon" ) addElement( "defaultWithIcon" )
addElement( "label" ) addElement( "label" )
addElement( "swingxDefault" ) addElement( "swingxDefault" )