mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2025-12-06 14:00:55 +03:00
on Mac show mnemonics only when Ctrl and Alt keys are pressed (issue #4)
This commit is contained in:
@@ -18,6 +18,8 @@ FlatLaf Change Log
|
||||
pressing focused button with <kbd>Enter</kbd> key (as in Windows LaF).
|
||||
- Fixed clipped borders at 125%, 150% and 175% scaling when outer focus width is
|
||||
zero (default in "Flat Light" and "Flat Dark" themes).
|
||||
- On Mac show mnemonics only when <kbd>Ctrl</kbd> and <kbd>Alt</kbd> keys are
|
||||
pressed. (issue #4)
|
||||
|
||||
|
||||
## 0.21
|
||||
|
||||
@@ -61,7 +61,7 @@ public abstract class FlatLaf
|
||||
private PropertyChangeListener desktopPropertyListener;
|
||||
|
||||
private KeyEventPostProcessor mnemonicListener;
|
||||
private static boolean altKeyPressed;
|
||||
private static boolean showMnemonics;
|
||||
|
||||
private Consumer<UIDefaults> postInitialization;
|
||||
|
||||
@@ -113,8 +113,7 @@ public abstract class FlatLaf
|
||||
|
||||
// add mnemonic listener
|
||||
mnemonicListener = e -> {
|
||||
if( e.getKeyCode() == KeyEvent.VK_ALT )
|
||||
altKeyChanged( e.getID() == KeyEvent.KEY_PRESSED );
|
||||
checkShowMnemonics( e );
|
||||
return false;
|
||||
};
|
||||
KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventPostProcessor( mnemonicListener );
|
||||
@@ -357,14 +356,27 @@ public abstract class FlatLaf
|
||||
}
|
||||
|
||||
public static boolean isShowMnemonics() {
|
||||
return altKeyPressed || !UIManager.getBoolean( "Component.hideMnemonics" );
|
||||
return showMnemonics || !UIManager.getBoolean( "Component.hideMnemonics" );
|
||||
}
|
||||
|
||||
private static void altKeyChanged( boolean pressed ) {
|
||||
if( pressed == altKeyPressed )
|
||||
private static void checkShowMnemonics( KeyEvent e ) {
|
||||
int keyCode = e.getKeyCode();
|
||||
if( SystemInfo.IS_MAC ) {
|
||||
// Ctrl+Alt keys must be pressed on Mac
|
||||
if( keyCode == KeyEvent.VK_CONTROL || keyCode == KeyEvent.VK_ALT )
|
||||
showMnemonics( e.getID() == KeyEvent.KEY_PRESSED && e.isControlDown() && e.isAltDown() );
|
||||
} else {
|
||||
// Alt key must be pressed on Windows and Linux
|
||||
if( keyCode == KeyEvent.VK_ALT )
|
||||
showMnemonics( e.getID() == KeyEvent.KEY_PRESSED );
|
||||
}
|
||||
}
|
||||
|
||||
private static void showMnemonics( boolean show ) {
|
||||
if( show == showMnemonics )
|
||||
return;
|
||||
|
||||
altKeyPressed = pressed;
|
||||
showMnemonics = show;
|
||||
|
||||
// check whether it is necessary to repaint
|
||||
if( !UIManager.getBoolean( "Component.hideMnemonics" ) )
|
||||
|
||||
Reference in New Issue
Block a user