mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-12 15:07:11 -06:00
Tree: support wide cell renderer (issue #922)
This commit is contained in:
@@ -1410,13 +1410,23 @@ public interface FlatClientProperties
|
||||
//---- JTree --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Override if a tree shows a wide selection. Default is {@code true}.
|
||||
* Specifies whether tree shows a wide selection. Default is {@code true}.
|
||||
* <p>
|
||||
* <strong>Component</strong> {@link javax.swing.JTree}<br>
|
||||
* <strong>Value type</strong> {@link java.lang.Boolean}
|
||||
*/
|
||||
String TREE_WIDE_SELECTION = "JTree.wideSelection";
|
||||
|
||||
/**
|
||||
* Specifies whether tree uses a wide cell renderer. Default is {@code false}.
|
||||
* <p>
|
||||
* <strong>Component</strong> {@link javax.swing.JTree}<br>
|
||||
* <strong>Value type</strong> {@link java.lang.Boolean}
|
||||
*
|
||||
* @since 3.6
|
||||
*/
|
||||
String TREE_WIDE_CELL_RENDERER = "JTree.wideCellRenderer";
|
||||
|
||||
/**
|
||||
* Specifies whether tree item selection is painted. Default is {@code true}.
|
||||
* If set to {@code false}, then the tree cell renderer is responsible for painting selection.
|
||||
|
||||
@@ -106,6 +106,7 @@ import com.formdev.flatlaf.util.UIScale;
|
||||
* @uiDefault Tree.selectionInsets Insets
|
||||
* @uiDefault Tree.selectionArc int
|
||||
* @uiDefault Tree.wideSelection boolean
|
||||
* @uiDefault Tree.wideCellRenderer boolean
|
||||
* @uiDefault Tree.showCellFocusIndicator boolean
|
||||
* @uiDefault Tree.showDefaultIcons boolean
|
||||
*
|
||||
@@ -146,6 +147,7 @@ public class FlatTreeUI
|
||||
/** @since 3 */ @Styleable protected Insets selectionInsets;
|
||||
/** @since 3 */ @Styleable protected int selectionArc;
|
||||
@Styleable protected boolean wideSelection;
|
||||
/** @since 3.6 */ @Styleable protected boolean wideCellRenderer;
|
||||
@Styleable protected boolean showCellFocusIndicator;
|
||||
/** @since 3 */ protected boolean showDefaultIcons;
|
||||
|
||||
@@ -198,6 +200,7 @@ public class FlatTreeUI
|
||||
selectionInsets = UIManager.getInsets( "Tree.selectionInsets" );
|
||||
selectionArc = UIManager.getInt( "Tree.selectionArc" );
|
||||
wideSelection = UIManager.getBoolean( "Tree.wideSelection" );
|
||||
wideCellRenderer = UIManager.getBoolean( "Tree.wideCellRenderer" );
|
||||
showCellFocusIndicator = UIManager.getBoolean( "Tree.showCellFocusIndicator" );
|
||||
showDefaultIcons = UIManager.getBoolean( "Tree.showDefaultIcons" );
|
||||
|
||||
@@ -314,6 +317,7 @@ public class FlatTreeUI
|
||||
if( e.getSource() == tree ) {
|
||||
switch( e.getPropertyName() ) {
|
||||
case TREE_WIDE_SELECTION:
|
||||
case TREE_WIDE_CELL_RENDERER:
|
||||
case TREE_PAINT_SELECTION:
|
||||
HiDPIUtils.repaint( tree );
|
||||
break;
|
||||
@@ -584,6 +588,18 @@ public class FlatTreeUI
|
||||
UIScale.scale( selectionInsets ), arc, arc, arc, arc, 0 );
|
||||
}
|
||||
|
||||
// update bounds for wide cell renderer
|
||||
if( isWideSelection() && isWideCellRenderer() ) {
|
||||
Rectangle wideBounds = new Rectangle( bounds );
|
||||
if( tree.getComponentOrientation().isLeftToRight() )
|
||||
wideBounds.width = tree.getWidth() - bounds.x - insets.right;
|
||||
else {
|
||||
wideBounds.x = insets.left;
|
||||
wideBounds.width = bounds.x + bounds.width - insets.left;
|
||||
}
|
||||
bounds = wideBounds;
|
||||
}
|
||||
|
||||
// do not paint row if editing
|
||||
if( isEditing ) {
|
||||
// paint wide selection
|
||||
@@ -808,6 +824,11 @@ public class FlatTreeUI
|
||||
return clientPropertyBoolean( tree, TREE_WIDE_SELECTION, wideSelection );
|
||||
}
|
||||
|
||||
/** @since 3.6 */
|
||||
protected boolean isWideCellRenderer() {
|
||||
return clientPropertyBoolean( tree, TREE_WIDE_CELL_RENDERER, wideCellRenderer );
|
||||
}
|
||||
|
||||
protected boolean isPaintSelection() {
|
||||
return clientPropertyBoolean( tree, TREE_PAINT_SELECTION, paintSelection );
|
||||
}
|
||||
|
||||
@@ -934,6 +934,7 @@ Tree.rendererMargins = 1,2,1,2
|
||||
Tree.selectionInsets = 0,0,0,0
|
||||
Tree.selectionArc = 0
|
||||
Tree.wideSelection = true
|
||||
Tree.wideCellRenderer = false
|
||||
Tree.repaintWholeRow = true
|
||||
Tree.paintLines = false
|
||||
Tree.showCellFocusIndicator = false
|
||||
|
||||
@@ -969,6 +969,7 @@ public class TestFlatStyleableInfo
|
||||
"selectionInsets", Insets.class,
|
||||
"selectionArc", int.class,
|
||||
"wideSelection", boolean.class,
|
||||
"wideCellRenderer", boolean.class,
|
||||
"showCellFocusIndicator", boolean.class,
|
||||
|
||||
"paintSelection", boolean.class,
|
||||
|
||||
@@ -942,6 +942,7 @@ public class TestFlatStyleableValue
|
||||
testInsets( c, ui, "selectionInsets", 1,2,3,4 );
|
||||
testInteger( c, ui, "selectionArc", 123 );
|
||||
testBoolean( c, ui, "wideSelection", true );
|
||||
testBoolean( c, ui, "wideCellRenderer", true );
|
||||
testBoolean( c, ui, "showCellFocusIndicator", true );
|
||||
|
||||
testBoolean( c, ui, "paintSelection", false );
|
||||
|
||||
@@ -1191,6 +1191,7 @@ public class TestFlatStyling
|
||||
ui.applyStyle( "selectionInsets: 1,2,3,4" );
|
||||
ui.applyStyle( "selectionArc: 8" );
|
||||
ui.applyStyle( "wideSelection: true" );
|
||||
ui.applyStyle( "wideCellRenderer: true" );
|
||||
ui.applyStyle( "showCellFocusIndicator: true" );
|
||||
|
||||
ui.applyStyle( "paintSelection: false" );
|
||||
|
||||
Reference in New Issue
Block a user