mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2025-12-07 06:20:53 +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).
|
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
|
- Fixed clipped borders at 125%, 150% and 175% scaling when outer focus width is
|
||||||
zero (default in "Flat Light" and "Flat Dark" themes).
|
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
|
## 0.21
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ public abstract class FlatLaf
|
|||||||
private PropertyChangeListener desktopPropertyListener;
|
private PropertyChangeListener desktopPropertyListener;
|
||||||
|
|
||||||
private KeyEventPostProcessor mnemonicListener;
|
private KeyEventPostProcessor mnemonicListener;
|
||||||
private static boolean altKeyPressed;
|
private static boolean showMnemonics;
|
||||||
|
|
||||||
private Consumer<UIDefaults> postInitialization;
|
private Consumer<UIDefaults> postInitialization;
|
||||||
|
|
||||||
@@ -113,8 +113,7 @@ public abstract class FlatLaf
|
|||||||
|
|
||||||
// add mnemonic listener
|
// add mnemonic listener
|
||||||
mnemonicListener = e -> {
|
mnemonicListener = e -> {
|
||||||
if( e.getKeyCode() == KeyEvent.VK_ALT )
|
checkShowMnemonics( e );
|
||||||
altKeyChanged( e.getID() == KeyEvent.KEY_PRESSED );
|
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventPostProcessor( mnemonicListener );
|
KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventPostProcessor( mnemonicListener );
|
||||||
@@ -357,14 +356,27 @@ public abstract class FlatLaf
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isShowMnemonics() {
|
public static boolean isShowMnemonics() {
|
||||||
return altKeyPressed || !UIManager.getBoolean( "Component.hideMnemonics" );
|
return showMnemonics || !UIManager.getBoolean( "Component.hideMnemonics" );
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void altKeyChanged( boolean pressed ) {
|
private static void checkShowMnemonics( KeyEvent e ) {
|
||||||
if( pressed == altKeyPressed )
|
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;
|
return;
|
||||||
|
|
||||||
altKeyPressed = pressed;
|
showMnemonics = show;
|
||||||
|
|
||||||
// check whether it is necessary to repaint
|
// check whether it is necessary to repaint
|
||||||
if( !UIManager.getBoolean( "Component.hideMnemonics" ) )
|
if( !UIManager.getBoolean( "Component.hideMnemonics" ) )
|
||||||
|
|||||||
Reference in New Issue
Block a user