mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2025-12-06 05:50:53 +03:00
focus indication border (or background) no longer hidden when temporary loosing focus (e.g. showing a popup menu)
This commit is contained in:
@@ -3,6 +3,8 @@ FlatLaf Change Log
|
||||
|
||||
## Unreleased
|
||||
|
||||
- Focus indication border (or background) no longer hidden when temporary
|
||||
loosing focus (e.g. showing a popup menu).
|
||||
- List, Table and Tree: Item selection color of focused components no longer
|
||||
change from blue to gray when temporary loosing focus (e.g. showing a popup
|
||||
menu).
|
||||
|
||||
@@ -96,7 +96,7 @@ public class FlatCheckBoxIcon
|
||||
boolean selected = indeterminate || (c instanceof AbstractButton && ((AbstractButton)c).isSelected());
|
||||
|
||||
// paint focused border
|
||||
if( c.hasFocus() && focusWidth > 0 ) {
|
||||
if( FlatUIUtils.isPermanentFocusOwner( c ) && focusWidth > 0 ) {
|
||||
g2.setColor( focusColor );
|
||||
paintFocusBorder( g2 );
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ public class FlatHelpButtonIcon
|
||||
*/
|
||||
|
||||
boolean enabled = c.isEnabled();
|
||||
boolean focused = c.hasFocus();
|
||||
boolean focused = FlatUIUtils.isPermanentFocusOwner( c );
|
||||
|
||||
// paint focused border
|
||||
if( focused ) {
|
||||
|
||||
@@ -119,7 +119,7 @@ public class FlatBorder
|
||||
JViewport viewport = ((JScrollPane)c).getViewport();
|
||||
Component view = (viewport != null) ? viewport.getView() : null;
|
||||
if( view != null ) {
|
||||
if( view.hasFocus() )
|
||||
if( FlatUIUtils.isPermanentFocusOwner( view ) )
|
||||
return true;
|
||||
|
||||
if( (view instanceof JTable && ((JTable)view).isEditing()) ||
|
||||
@@ -133,17 +133,17 @@ public class FlatBorder
|
||||
return false;
|
||||
} else if( c instanceof JComboBox && ((JComboBox<?>)c).isEditable() ) {
|
||||
Component editorComponent = ((JComboBox<?>)c).getEditor().getEditorComponent();
|
||||
return (editorComponent != null) ? editorComponent.hasFocus() : false;
|
||||
return (editorComponent != null) ? FlatUIUtils.isPermanentFocusOwner( editorComponent ) : false;
|
||||
} else if( c instanceof JSpinner ) {
|
||||
JComponent editor = ((JSpinner)c).getEditor();
|
||||
if( editor instanceof JSpinner.DefaultEditor ) {
|
||||
JTextField textField = ((JSpinner.DefaultEditor)editor).getTextField();
|
||||
if( textField != null )
|
||||
return textField.hasFocus();
|
||||
return FlatUIUtils.isPermanentFocusOwner( textField );
|
||||
}
|
||||
return false;
|
||||
} else
|
||||
return c.hasFocus();
|
||||
return FlatUIUtils.isPermanentFocusOwner( c );
|
||||
}
|
||||
|
||||
protected boolean isTableCellEditor( Component c ) {
|
||||
|
||||
@@ -294,7 +294,9 @@ public class FlatButtonUI
|
||||
|
||||
// paint shadow
|
||||
Color shadowColor = def ? defaultShadowColor : this.shadowColor;
|
||||
if( !isToolBarButton && shadowColor != null && shadowWidth > 0 && focusWidth > 0 && !c.hasFocus() && c.isEnabled() ) {
|
||||
if( !isToolBarButton && shadowColor != null && shadowWidth > 0 && focusWidth > 0 &&
|
||||
!FlatUIUtils.isPermanentFocusOwner( c ) && c.isEnabled() )
|
||||
{
|
||||
g2.setColor( shadowColor );
|
||||
g2.fill( new RoundRectangle2D.Float( focusWidth, focusWidth + UIScale.scale( (float) shadowWidth ),
|
||||
width - focusWidth * 2, height - focusWidth * 2, arc, arc ) );
|
||||
@@ -382,7 +384,7 @@ public class FlatButtonUI
|
||||
if( hoverColor != null && b != null && b.getModel().isRollover() )
|
||||
return hoverColor;
|
||||
|
||||
if( focusedColor != null && c.hasFocus() )
|
||||
if( focusedColor != null && FlatUIUtils.isPermanentFocusOwner( c ) )
|
||||
return focusedColor;
|
||||
|
||||
return enabledColor;
|
||||
|
||||
@@ -81,7 +81,7 @@ public class FlatListUI
|
||||
selectionInactiveBackground = UIManager.getColor( "List.selectionInactiveBackground" );
|
||||
selectionInactiveForeground = UIManager.getColor( "List.selectionInactiveForeground" );
|
||||
|
||||
toggleSelectionColors( list.hasFocus() );
|
||||
toggleSelectionColors();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -100,13 +100,13 @@ public class FlatListUI
|
||||
@Override
|
||||
public void focusGained( FocusEvent e ) {
|
||||
super.focusGained( e );
|
||||
toggleSelectionColors( true );
|
||||
toggleSelectionColors();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void focusLost( FocusEvent e ) {
|
||||
super.focusLost( e );
|
||||
toggleSelectionColors( e.isTemporary() );
|
||||
toggleSelectionColors();
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -120,8 +120,8 @@ public class FlatListUI
|
||||
* already used in applications. Then either the inactive colors are not used,
|
||||
* or the application has to be changed to extend a FlatLaf renderer.
|
||||
*/
|
||||
private void toggleSelectionColors( boolean focused ) {
|
||||
if( focused ) {
|
||||
private void toggleSelectionColors() {
|
||||
if( FlatUIUtils.isPermanentFocusOwner( list ) ) {
|
||||
if( list.getSelectionBackground() == selectionInactiveBackground )
|
||||
list.setSelectionBackground( selectionBackground );
|
||||
if( list.getSelectionForeground() == selectionInactiveForeground )
|
||||
|
||||
@@ -168,7 +168,7 @@ public class FlatPasswordFieldUI
|
||||
|
||||
protected void paintCapsLock( Graphics g ) {
|
||||
JTextComponent c = getComponent();
|
||||
if( !c.isFocusOwner() ||
|
||||
if( !FlatUIUtils.isPermanentFocusOwner( c ) ||
|
||||
!Toolkit.getDefaultToolkit().getLockingKeyState( KeyEvent.VK_CAPS_LOCK ) )
|
||||
return;
|
||||
|
||||
|
||||
@@ -201,7 +201,7 @@ public class FlatSliderUI
|
||||
}
|
||||
|
||||
if( coloredTrack != null ) {
|
||||
FlatUIUtils.setColor( g, slider.hasFocus() ? focusColor : (hover ? hoverColor : thumbColor), thumbColor );
|
||||
FlatUIUtils.setColor( g, FlatUIUtils.isPermanentFocusOwner( slider ) ? focusColor : (hover ? hoverColor : thumbColor), thumbColor );
|
||||
((Graphics2D)g).fill( coloredTrack );
|
||||
}
|
||||
|
||||
@@ -212,7 +212,7 @@ public class FlatSliderUI
|
||||
@Override
|
||||
public void paintThumb( Graphics g ) {
|
||||
FlatUIUtils.setColor( g, slider.isEnabled()
|
||||
? (slider.hasFocus() ? focusColor : (hover ? hoverColor : thumbColor))
|
||||
? (FlatUIUtils.isPermanentFocusOwner( slider ) ? focusColor : (hover ? hoverColor : thumbColor))
|
||||
: disabledForeground,
|
||||
thumbColor );
|
||||
|
||||
|
||||
@@ -318,7 +318,7 @@ public class FlatTabbedPaneUI
|
||||
boolean enabled = tabPane.isEnabled();
|
||||
g.setColor( enabled && tabPane.isEnabledAt( tabIndex ) && getRolloverTab() == tabIndex
|
||||
? hoverColor
|
||||
: (enabled && isSelected && tabPane.hasFocus()
|
||||
: (enabled && isSelected && FlatUIUtils.isPermanentFocusOwner( tabPane )
|
||||
? focusColor
|
||||
: (selectedBackground != null && enabled && isSelected
|
||||
? selectedBackground
|
||||
|
||||
@@ -113,7 +113,7 @@ public class FlatTableUI
|
||||
selectionInactiveBackground = UIManager.getColor( "Table.selectionInactiveBackground" );
|
||||
selectionInactiveForeground = UIManager.getColor( "Table.selectionInactiveForeground" );
|
||||
|
||||
toggleSelectionColors( table.hasFocus() );
|
||||
toggleSelectionColors();
|
||||
|
||||
int rowHeight = FlatUIUtils.getUIInt( "Table.rowHeight", 16 );
|
||||
if( rowHeight > 0 )
|
||||
@@ -160,13 +160,13 @@ public class FlatTableUI
|
||||
@Override
|
||||
public void focusGained( FocusEvent e ) {
|
||||
super.focusGained( e );
|
||||
toggleSelectionColors( true );
|
||||
toggleSelectionColors();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void focusLost( FocusEvent e ) {
|
||||
super.focusLost( e );
|
||||
toggleSelectionColors( e.isTemporary() );
|
||||
toggleSelectionColors();
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -180,8 +180,8 @@ public class FlatTableUI
|
||||
* already used in applications. Then either the inactive colors are not used,
|
||||
* or the application has to be changed to extend a FlatLaf renderer.
|
||||
*/
|
||||
private void toggleSelectionColors( boolean focused ) {
|
||||
if( focused ) {
|
||||
private void toggleSelectionColors() {
|
||||
if( FlatUIUtils.isPermanentFocusOwner( table ) ) {
|
||||
if( table.getSelectionBackground() == selectionInactiveBackground )
|
||||
table.setSelectionBackground( selectionBackground );
|
||||
if( table.getSelectionForeground() == selectionInactiveForeground )
|
||||
|
||||
@@ -20,7 +20,6 @@ import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Insets;
|
||||
import java.awt.KeyboardFocusManager;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
@@ -222,7 +221,7 @@ public class FlatTreeUI
|
||||
TreePath path, int row, boolean isExpanded, boolean hasBeenExpanded, boolean isLeaf )
|
||||
{
|
||||
boolean isEditing = (editingComponent != null && editingRow == row);
|
||||
boolean hasFocus = (KeyboardFocusManager.getCurrentKeyboardFocusManager().getPermanentFocusOwner() == tree);
|
||||
boolean hasFocus = FlatUIUtils.isPermanentFocusOwner( tree );
|
||||
boolean cellHasFocus = hasFocus && (row == getLeadSelectionRow());
|
||||
boolean isSelected = tree.isRowSelected( row );
|
||||
boolean isDropRow = isDropRow( row );
|
||||
|
||||
@@ -24,6 +24,7 @@ import java.awt.Font;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Insets;
|
||||
import java.awt.KeyboardFocusManager;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.Shape;
|
||||
@@ -136,6 +137,10 @@ public class FlatUIUtils
|
||||
return c instanceof JComponent && Boolean.TRUE.equals( ((JComponent)c).getClientProperty( "JComboBox.isTableCellEditor" ) );
|
||||
}
|
||||
|
||||
public static boolean isPermanentFocusOwner( Component c ) {
|
||||
return (KeyboardFocusManager.getCurrentKeyboardFocusManager().getPermanentFocusOwner() == c);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets rendering hints used for painting.
|
||||
*/
|
||||
|
||||
@@ -216,7 +216,7 @@ public class FlatJideTabbedPaneUI
|
||||
g.setColor( enabled && _tabPane.isEnabledAt( tabIndex ) &&
|
||||
(_indexMouseOver == tabIndex || (_closeButtons != null && ((JideTabbedPane.NoFocusButton)_closeButtons[tabIndex]).isMouseOver()))
|
||||
? hoverColor
|
||||
: (enabled && isSelected && _tabPane.hasFocus()
|
||||
: (enabled && isSelected && FlatUIUtils.isPermanentFocusOwner( _tabPane )
|
||||
? focusColor
|
||||
: _tabPane.getBackgroundAt( tabIndex )) );
|
||||
g.fillRect( x, y, w, h );
|
||||
|
||||
@@ -20,6 +20,7 @@ import java.awt.Component;
|
||||
import javax.swing.JTable;
|
||||
import org.jdesktop.swingx.JXDatePicker;
|
||||
import com.formdev.flatlaf.ui.FlatRoundBorder;
|
||||
import com.formdev.flatlaf.ui.FlatUIUtils;
|
||||
|
||||
/**
|
||||
* Border for {@link org.jdesktop.swingx.JXDatePicker}.
|
||||
@@ -32,7 +33,7 @@ public class FlatDatePickerBorder
|
||||
@Override
|
||||
protected boolean isFocused( Component c ) {
|
||||
if( c instanceof JXDatePicker )
|
||||
return ((JXDatePicker)c).getEditor().hasFocus();
|
||||
return FlatUIUtils.isPermanentFocusOwner( ((JXDatePicker)c).getEditor() );
|
||||
|
||||
return super.isFocused( c );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user