Demo: Alt+UP and Alt+DOWN now switch to previous/next theme

This commit is contained in:
Karl Tauber
2020-11-20 00:40:10 +01:00
parent d923c8df81
commit cd6b55c846
5 changed files with 33 additions and 1 deletions

View File

@@ -136,6 +136,16 @@ class ControlBar
registerSwitchToLookAndFeel( KeyEvent.VK_F12, MetalLookAndFeel.class.getName() );
registerSwitchToLookAndFeel( KeyEvent.VK_F11, NimbusLookAndFeel.class.getName() );
// register Alt+UP and Alt+DOWN to switch to previous/next theme
((JComponent)frame.getContentPane()).registerKeyboardAction(
e -> frame.themesPanel.selectPreviousTheme(),
KeyStroke.getKeyStroke( KeyEvent.VK_UP, KeyEvent.ALT_DOWN_MASK ),
JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT );
((JComponent)frame.getContentPane()).registerKeyboardAction(
e -> frame.themesPanel.selectNextTheme(),
KeyStroke.getKeyStroke( KeyEvent.VK_DOWN, KeyEvent.ALT_DOWN_MASK ),
JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT );
// register ESC key to close frame
((JComponent)frame.getContentPane()).registerKeyboardAction(
e -> {

View File

@@ -749,6 +749,6 @@ class DemoFrame
private JCheckBoxMenuItem animatedLafChangeMenuItem;
private JTabbedPane tabbedPane;
private ControlBar controlBar;
private IJThemesPanel themesPanel;
IJThemesPanel themesPanel;
// JFormDesigner - End of variables declaration //GEN-END:variables
}

View File

@@ -117,6 +117,7 @@ new FormModel {
name: "themesPanel"
auxiliary() {
"JavaCodeGenerator.variableLocal": false
"JavaCodeGenerator.variableModifiers": 0
}
}, new FormLayoutConstraints( class java.lang.String ) {
"value": "East"

View File

@@ -220,6 +220,17 @@ public class IJThemesPanel
}
}
public void selectPreviousTheme() {
int sel = themesList.getSelectedIndex();
if( sel > 0 )
themesList.setSelectedIndex( sel - 1 );
}
public void selectNextTheme() {
int sel = themesList.getSelectedIndex();
themesList.setSelectedIndex( sel + 1 );
}
private void themesListValueChanged( ListSelectionEvent e ) {
IJThemeInfo themeInfo = themesList.getSelectedValue();
boolean bundledTheme = (themeInfo != null && themeInfo.resourceName != null);

View File

@@ -198,6 +198,16 @@ public class FlatTestFrame
KeyStroke.getKeyStroke( KeyEvent.VK_MINUS, menuShortcutKeyMask ),
JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT );
// register Alt+UP and Alt+DOWN to switch to previous/next theme
((JComponent)getContentPane()).registerKeyboardAction(
e -> themesPanel.selectPreviousTheme(),
KeyStroke.getKeyStroke( KeyEvent.VK_UP, KeyEvent.ALT_DOWN_MASK ),
JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT );
((JComponent)getContentPane()).registerKeyboardAction(
e -> themesPanel.selectNextTheme(),
KeyStroke.getKeyStroke( KeyEvent.VK_DOWN, KeyEvent.ALT_DOWN_MASK ),
JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT );
// register ESC key to close frame
((JComponent)getContentPane()).registerKeyboardAction(
e -> {