Skip to content

Commit

Permalink
Merge PR #609: Tree: hide default closed/opened/leaf icons by default
Browse files Browse the repository at this point in the history
  • Loading branch information
DevCharly committed Nov 16, 2022
2 parents 2be2dae + b736502 commit afdaf7a
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ FlatLaf Change Log
- List: Support rounded selection. (PR #547)
- Menus: Support rounded selection. (PR #536)
- Tree: Support rounded selection. (PR #546)
- Tree: Hide default closed/opened/leaf icons by default. Set UI value
`Tree.showDefaultIcons` to `true` to show them.
- Icons: New modern rounded outlined icons for `JFileChooser`, `JOptionPane`,
`JPasswordField` and `JTree`. (PR #577)

Expand Down
16 changes: 16 additions & 0 deletions flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTreeUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
* @uiDefault Tree.selectionArc int
* @uiDefault Tree.wideSelection boolean
* @uiDefault Tree.showCellFocusIndicator boolean
* @uiDefault Tree.showDefaultIcons boolean
*
* <!-- FlatTreeExpandedIcon -->
*
Expand Down Expand Up @@ -143,6 +144,7 @@ public class FlatTreeUI
/** @since 3 */ @Styleable protected int selectionArc;
@Styleable protected boolean wideSelection;
@Styleable protected boolean showCellFocusIndicator;
/** @since 3 */ protected boolean showDefaultIcons;

// for icons
// (needs to be public because icon classes are in another package)
Expand Down Expand Up @@ -189,6 +191,7 @@ protected void installDefaults() {
selectionArc = UIManager.getInt( "Tree.selectionArc" );
wideSelection = UIManager.getBoolean( "Tree.wideSelection" );
showCellFocusIndicator = UIManager.getBoolean( "Tree.showCellFocusIndicator" );
showDefaultIcons = UIManager.getBoolean( "Tree.showDefaultIcons" );

paintLines = UIManager.getBoolean( "Tree.paintLines" );
defaultCellNonSelectionBackground = UIManager.getColor( "Tree.textBackground" );
Expand Down Expand Up @@ -223,6 +226,19 @@ protected void uninstallDefaults() {
oldStyleValues = null;
}

@Override
protected void updateRenderer() {
super.updateRenderer();

// remove default leaf/closed/opened icons
if( !showDefaultIcons && currentCellRenderer instanceof DefaultTreeCellRenderer ) {
DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) currentCellRenderer;
renderer.setLeafIcon( null );
renderer.setClosedIcon( null );
renderer.setOpenIcon( null );
}
}

@Override
protected MouseListener createMouseListener() {
return new BasicTreeUI.MouseHandler() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -901,6 +901,7 @@ Tree.wideSelection = true
Tree.repaintWholeRow = true
Tree.paintLines = false
Tree.showCellFocusIndicator = false
Tree.showDefaultIcons = false
Tree.leftChildIndent = 7
Tree.rightChildIndent = 11
Tree.rowHeight = 0
Expand Down
1 change: 1 addition & 0 deletions flatlaf-testing/dumps/uidefaults/FlatDarkLaf_1.8.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1399,6 +1399,7 @@ Tree.selectionInactiveBackground #0f2a3d HSL 205 61 15 javax.swing.plaf.Co
Tree.selectionInactiveForeground #bbbbbb HSL 0 0 73 javax.swing.plaf.ColorUIResource [UI]
Tree.selectionInsets 0,0,0,0 javax.swing.plaf.InsetsUIResource [UI]
Tree.showCellFocusIndicator false
Tree.showDefaultIcons false
Tree.textBackground #46494b HSL 204 3 28 javax.swing.plaf.ColorUIResource [UI]
Tree.textForeground #bbbbbb HSL 0 0 73 javax.swing.plaf.ColorUIResource [UI]
Tree.timeFactor 1000
Expand Down
1 change: 1 addition & 0 deletions flatlaf-testing/dumps/uidefaults/FlatLightLaf_1.8.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1404,6 +1404,7 @@ Tree.selectionInactiveBackground #d3d3d3 HSL 0 0 83 javax.swing.plaf.Co
Tree.selectionInactiveForeground #000000 HSL 0 0 0 javax.swing.plaf.ColorUIResource [UI]
Tree.selectionInsets 0,0,0,0 javax.swing.plaf.InsetsUIResource [UI]
Tree.showCellFocusIndicator false
Tree.showDefaultIcons false
Tree.textBackground #ffffff HSL 0 0 100 javax.swing.plaf.ColorUIResource [UI]
Tree.textForeground #000000 HSL 0 0 0 javax.swing.plaf.ColorUIResource [UI]
Tree.timeFactor 1000
Expand Down
1 change: 1 addition & 0 deletions flatlaf-testing/dumps/uidefaults/FlatMacDarkLaf_1.8.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1409,6 +1409,7 @@ Tree.selectionInactiveBackground #464646 HSL 0 0 27 javax.swing.plaf.Co
Tree.selectionInactiveForeground #dddddd HSL 0 0 87 javax.swing.plaf.ColorUIResource [UI]
Tree.selectionInsets 0,0,0,0 javax.swing.plaf.InsetsUIResource [UI]
Tree.showCellFocusIndicator false
Tree.showDefaultIcons false
Tree.textBackground #282828 HSL 0 0 16 javax.swing.plaf.ColorUIResource [UI]
Tree.textForeground #dddddd HSL 0 0 87 javax.swing.plaf.ColorUIResource [UI]
Tree.timeFactor 1000
Expand Down
1 change: 1 addition & 0 deletions flatlaf-testing/dumps/uidefaults/FlatMacLightLaf_1.8.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1413,6 +1413,7 @@ Tree.selectionInactiveBackground #dcdcdc HSL 0 0 86 javax.swing.plaf.Co
Tree.selectionInactiveForeground #262626 HSL 0 0 15 javax.swing.plaf.ColorUIResource [UI]
Tree.selectionInsets 0,0,0,0 javax.swing.plaf.InsetsUIResource [UI]
Tree.showCellFocusIndicator false
Tree.showDefaultIcons false
Tree.textBackground #ffffff HSL 0 0 100 javax.swing.plaf.ColorUIResource [UI]
Tree.textForeground #262626 HSL 0 0 15 javax.swing.plaf.ColorUIResource [UI]
Tree.timeFactor 1000
Expand Down
1 change: 1 addition & 0 deletions flatlaf-testing/dumps/uidefaults/FlatTestLaf_1.8.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1450,6 +1450,7 @@ Tree.selectionInactiveBackground #888888 HSL 0 0 53 javax.swing.plaf.Co
Tree.selectionInactiveForeground #ffffff HSL 0 0 100 javax.swing.plaf.ColorUIResource [UI]
Tree.selectionInsets 0,0,0,0 javax.swing.plaf.InsetsUIResource [UI]
Tree.showCellFocusIndicator false
Tree.showDefaultIcons false
Tree.textBackground #fff0ff HSL 300 100 97 javax.swing.plaf.ColorUIResource [UI]
Tree.textForeground #ff0000 HSL 0 100 50 javax.swing.plaf.ColorUIResource [UI]
Tree.timeFactor 1000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,13 @@ private void treeEditableChanged() {
tree.setEditable( editable );
}

private void showDefaultIcons() {
boolean showDefaultIcons = showDefaultIconsCheckBox.isSelected();
UIManager.put( "Tree.showDefaultIcons", showDefaultIcons ? true : null );
for( JTree tree : allTrees )
tree.updateUI();
}

private void treeMouseClicked( MouseEvent e ) {
JTree tree = (JTree) e.getSource();
int x = e.getX();
Expand Down Expand Up @@ -594,6 +601,7 @@ private void initComponents() {
treePaintLinesCheckBox = new JCheckBox();
treeRedLinesCheckBox = new JCheckBox();
treeEditableCheckBox = new JCheckBox();
showDefaultIconsCheckBox = new JCheckBox();
JPanel tableOptionsPanel = new JPanel();
JLabel autoResizeModeLabel = new JLabel();
autoResizeModeField = new JComboBox<>();
Expand Down Expand Up @@ -754,7 +762,6 @@ private void initComponents() {

//---- tree1 ----
tree1.setShowsRootHandles(true);
tree1.setEditable(true);
tree1.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
Expand Down Expand Up @@ -980,6 +987,11 @@ public void mouseClicked(MouseEvent e) {
treeEditableCheckBox.setText("editable");
treeEditableCheckBox.addActionListener(e -> treeEditableChanged());
treeOptionsPanel.add(treeEditableCheckBox, "cell 0 4");

//---- showDefaultIconsCheckBox ----
showDefaultIconsCheckBox.setText("show default icons");
showDefaultIconsCheckBox.addActionListener(e -> showDefaultIcons());
treeOptionsPanel.add(showDefaultIconsCheckBox, "cell 0 4");
}
add(treeOptionsPanel, "cell 0 4 4 1");

Expand Down Expand Up @@ -1116,6 +1128,7 @@ public void mouseClicked(MouseEvent e) {
private JCheckBox treePaintLinesCheckBox;
private JCheckBox treeRedLinesCheckBox;
private JCheckBox treeEditableCheckBox;
private JCheckBox showDefaultIconsCheckBox;
private JComboBox<String> autoResizeModeField;
private JComboBox<String> sortIconPositionComboBox;
private JCheckBox showHorizontalLinesCheckBox;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ new FormModel {
add( new FormComponent( "javax.swing.JTree" ) {
name: "tree1"
"showsRootHandles": true
"editable": true
auxiliary() {
"JavaCodeGenerator.variableLocal": false
}
Expand Down Expand Up @@ -476,6 +475,16 @@ new FormModel {
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 0 4"
} )
add( new FormComponent( "javax.swing.JCheckBox" ) {
name: "showDefaultIconsCheckBox"
"text": "show default icons"
auxiliary() {
"JavaCodeGenerator.variableLocal": false
}
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "showDefaultIcons", false ) )
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 0 4"
} )
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 0 4 4 1"
} )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1150,6 +1150,7 @@ Tree.selectionInactiveBackground
Tree.selectionInactiveForeground
Tree.selectionInsets
Tree.showCellFocusIndicator
Tree.showDefaultIcons
Tree.textBackground
Tree.textForeground
Tree.timeFactor
Expand Down

0 comments on commit afdaf7a

Please sign in to comment.