mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-13 15:27:16 -06:00
client property "JComponent.focusOwner" added to allow customizing detection of focused state (issue #185)
This commit is contained in:
@@ -172,6 +172,25 @@ public interface FlatClientProperties
|
|||||||
*/
|
*/
|
||||||
String OUTLINE_WARNING = "warning";
|
String OUTLINE_WARNING = "warning";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specifies a callback that is invoked to check whether a component is permanent focus owner.
|
||||||
|
* Used to paint focus indicators.
|
||||||
|
* <p>
|
||||||
|
* May be useful in special cases for custom components.
|
||||||
|
* <p>
|
||||||
|
* Use a {@link java.util.function.Predicate} that receives the component as parameter:
|
||||||
|
* <pre>{@code
|
||||||
|
* myComponent.putClientProperty( "JComponent.focusOwner",
|
||||||
|
* (Predicate) c -> {
|
||||||
|
* return ...; // check here
|
||||||
|
* } );
|
||||||
|
* }</pre>
|
||||||
|
* <p>
|
||||||
|
* <strong>Component</strong> {@link javax.swing.JComponent}<br>
|
||||||
|
* <strong>Value type</strong> {@link java.util.function.Predicate<javax.swing.JComponent>
|
||||||
|
*/
|
||||||
|
String COMPONENT_FOCUS_OWNER = "JComponent.focusOwner";
|
||||||
|
|
||||||
//---- Popup --------------------------------------------------------------
|
//---- Popup --------------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ import java.awt.geom.Rectangle2D;
|
|||||||
import java.awt.geom.RoundRectangle2D;
|
import java.awt.geom.RoundRectangle2D;
|
||||||
import java.util.IdentityHashMap;
|
import java.util.IdentityHashMap;
|
||||||
import java.util.WeakHashMap;
|
import java.util.WeakHashMap;
|
||||||
|
import java.util.function.Predicate;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
import javax.swing.JComponent;
|
import javax.swing.JComponent;
|
||||||
import javax.swing.JTable;
|
import javax.swing.JTable;
|
||||||
@@ -175,8 +176,18 @@ public class FlatUIUtils
|
|||||||
* Returns whether the given component is the permanent focus owner and
|
* Returns whether the given component is the permanent focus owner and
|
||||||
* is in the active window. Used to paint focus indicators.
|
* is in the active window. Used to paint focus indicators.
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings( "unchecked" )
|
||||||
public static boolean isPermanentFocusOwner( Component c ) {
|
public static boolean isPermanentFocusOwner( Component c ) {
|
||||||
KeyboardFocusManager keyboardFocusManager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
|
KeyboardFocusManager keyboardFocusManager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
|
||||||
|
|
||||||
|
if( c instanceof JComponent ) {
|
||||||
|
Object value = ((JComponent)c).getClientProperty( FlatClientProperties.COMPONENT_FOCUS_OWNER );
|
||||||
|
if( value instanceof Predicate ) {
|
||||||
|
return ((Predicate<JComponent>)value).test( (JComponent) c ) &&
|
||||||
|
keyboardFocusManager.getActiveWindow() == SwingUtilities.windowForComponent( c );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return keyboardFocusManager.getPermanentFocusOwner() == c &&
|
return keyboardFocusManager.getPermanentFocusOwner() == c &&
|
||||||
keyboardFocusManager.getActiveWindow() == SwingUtilities.windowForComponent( c );
|
keyboardFocusManager.getActiveWindow() == SwingUtilities.windowForComponent( c );
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user