mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2025-12-06 22:10:54 +03:00
Tree: Fixed editing cell issue with custom cell renderer and cell editor that use same component for rendering and editing (fixes #385)
This commit is contained in:
@@ -1,6 +1,14 @@
|
|||||||
FlatLaf Change Log
|
FlatLaf Change Log
|
||||||
==================
|
==================
|
||||||
|
|
||||||
|
## 2.0-SNAPSHOT
|
||||||
|
|
||||||
|
#### Fixed bugs
|
||||||
|
|
||||||
|
- Tree: Fixed editing cell issue with custom cell renderer and cell editor that
|
||||||
|
use same component for rendering and editing. (issue #385)
|
||||||
|
|
||||||
|
|
||||||
## 1.6
|
## 1.6
|
||||||
|
|
||||||
#### New features and improvements
|
#### New features and improvements
|
||||||
|
|||||||
@@ -263,9 +263,19 @@ public class FlatTreeUI
|
|||||||
boolean isDropRow = isDropRow( row );
|
boolean isDropRow = isDropRow( row );
|
||||||
boolean needsSelectionPainting = (isSelected || isDropRow) && isPaintSelection();
|
boolean needsSelectionPainting = (isSelected || isDropRow) && isPaintSelection();
|
||||||
|
|
||||||
// do not paint row if editing, except if selection needs painted
|
// do not paint row if editing
|
||||||
if( isEditing && !needsSelectionPainting )
|
if( isEditing ) {
|
||||||
|
// paint wide selection
|
||||||
|
// (do not access cell renderer here to avoid side effect
|
||||||
|
// if renderer component is also used as editor component)
|
||||||
|
if( isSelected && isWideSelection() ) {
|
||||||
|
Color oldColor = g.getColor();
|
||||||
|
g.setColor( selectionInactiveBackground );
|
||||||
|
paintWideSelection( g, clipBounds, insets, bounds, path, row, isExpanded, hasBeenExpanded, isLeaf );
|
||||||
|
g.setColor( oldColor );
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
boolean hasFocus = FlatUIUtils.isPermanentFocusOwner( tree );
|
boolean hasFocus = FlatUIUtils.isPermanentFocusOwner( tree );
|
||||||
boolean cellHasFocus = hasFocus && (row == getLeadSelectionRow());
|
boolean cellHasFocus = hasFocus && (row == getLeadSelectionRow());
|
||||||
@@ -322,14 +332,7 @@ public class FlatTreeUI
|
|||||||
|
|
||||||
if( isWideSelection() ) {
|
if( isWideSelection() ) {
|
||||||
// wide selection
|
// wide selection
|
||||||
g.fillRect( 0, bounds.y, tree.getWidth(), bounds.height );
|
paintWideSelection( g, clipBounds, insets, bounds, path, row, isExpanded, hasBeenExpanded, isLeaf );
|
||||||
|
|
||||||
// paint expand/collapse icon
|
|
||||||
// (was already painted before, but painted over with wide selection)
|
|
||||||
if( shouldPaintExpandControl( path, row, isExpanded, hasBeenExpanded, isLeaf ) ) {
|
|
||||||
paintExpandControl( g, clipBounds, insets, bounds,
|
|
||||||
path, row, isExpanded, hasBeenExpanded, isLeaf );
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// non-wide selection
|
// non-wide selection
|
||||||
paintCellBackground( g, rendererComponent, bounds );
|
paintCellBackground( g, rendererComponent, bounds );
|
||||||
@@ -353,7 +356,6 @@ public class FlatTreeUI
|
|||||||
}
|
}
|
||||||
|
|
||||||
// paint renderer
|
// paint renderer
|
||||||
if( !isEditing )
|
|
||||||
rendererPane.paintComponent( g, rendererComponent, tree, bounds.x, bounds.y, bounds.width, bounds.height, true );
|
rendererPane.paintComponent( g, rendererComponent, tree, bounds.x, bounds.y, bounds.width, bounds.height, true );
|
||||||
|
|
||||||
// restore background selection color and border selection color
|
// restore background selection color and border selection color
|
||||||
@@ -363,6 +365,19 @@ public class FlatTreeUI
|
|||||||
((DefaultTreeCellRenderer)rendererComponent).setBorderSelectionColor( oldBorderSelectionColor );
|
((DefaultTreeCellRenderer)rendererComponent).setBorderSelectionColor( oldBorderSelectionColor );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void paintWideSelection( Graphics g, Rectangle clipBounds, Insets insets, Rectangle bounds,
|
||||||
|
TreePath path, int row, boolean isExpanded, boolean hasBeenExpanded, boolean isLeaf )
|
||||||
|
{
|
||||||
|
g.fillRect( 0, bounds.y, tree.getWidth(), bounds.height );
|
||||||
|
|
||||||
|
// paint expand/collapse icon
|
||||||
|
// (was already painted before, but painted over with wide selection)
|
||||||
|
if( shouldPaintExpandControl( path, row, isExpanded, hasBeenExpanded, isLeaf ) ) {
|
||||||
|
paintExpandControl( g, clipBounds, insets, bounds,
|
||||||
|
path, row, isExpanded, hasBeenExpanded, isLeaf );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void paintCellBackground( Graphics g, Component rendererComponent, Rectangle bounds ) {
|
private void paintCellBackground( Graphics g, Component rendererComponent, Rectangle bounds ) {
|
||||||
int xOffset = 0;
|
int xOffset = 0;
|
||||||
int imageOffset = 0;
|
int imageOffset = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user