Theme Editor:

- F12 now activates editor if focus is in preview or in find/replace
- changed accelerators for light/dark themes from F11/F12 to Alt+F1/F2
This commit is contained in:
Karl Tauber
2021-08-22 00:33:34 +02:00
parent 6e8443473b
commit 31cadc532b
3 changed files with 27 additions and 9 deletions

View File

@@ -60,13 +60,11 @@ class FlatFindReplaceBar
inputMap.put( KeyStroke.getKeyStroke( KeyEvent.VK_DOWN, 0 ), "findNext" );
inputMap.put( KeyStroke.getKeyStroke( KeyEvent.VK_PAGE_UP, 0 ), "editorPageUp" );
inputMap.put( KeyStroke.getKeyStroke( KeyEvent.VK_PAGE_DOWN, 0 ), "editorPageDown" );
inputMap.put( KeyStroke.getKeyStroke( KeyEvent.VK_F12, 0 ), "focusEditor" );
ActionMap actionMap = getActionMap();
actionMap.put( "findPrevious", new ConsumerAction( e -> findPrevious() ) );
actionMap.put( "findNext", new ConsumerAction( e -> findNext() ) );
actionMap.put( "editorPageUp", new ConsumerAction( e -> notifyEditorAction( "page-up" ) ) );
actionMap.put( "editorPageDown", new ConsumerAction( e -> notifyEditorAction( "page-down" ) ) );
actionMap.put( "focusEditor", new ConsumerAction( e -> textArea.requestFocusInWindow() ) );
findPreviousButton.setIcon( new FlatSVGIcon( "com/formdev/flatlaf/themeeditor/icons/findAndShowPrevMatches.svg" ) );
findNextButton.setIcon( new FlatSVGIcon( "com/formdev/flatlaf/themeeditor/icons/findAndShowNextMatches.svg" ) );

View File

@@ -212,9 +212,7 @@ public class FlatThemeFileEditor
for( File file : getPropertiesFiles( dir ) )
openFile( file, file.getName().equals( recentFile ) );
FlatThemeEditorPane themeEditorPane = (FlatThemeEditorPane) tabbedPane.getSelectedComponent();
if( themeEditorPane != null )
themeEditorPane.requestFocusInWindow();
activateEditor();
saveState();
@@ -350,6 +348,12 @@ public class FlatThemeFileEditor
return result;
}
private void activateEditor() {
FlatThemeEditorPane themeEditorPane = (FlatThemeEditorPane) tabbedPane.getSelectedComponent();
if( themeEditorPane != null )
themeEditorPane.requestFocusInWindow();
}
private void nextEditor() {
notifyTabbedPaneAction( tabbedPane.getActionMap().get( "navigatePageDown" ) );
}
@@ -540,6 +544,7 @@ public class FlatThemeFileEditor
decrFontSizeMenuItem = new JMenuItem();
resetFontSizeMenuItem = new JMenuItem();
windowMenu = new JMenu();
activateEditorMenuItem = new JMenuItem();
nextEditorMenuItem = new JMenuItem();
previousEditorMenuItem = new JMenuItem();
controlPanel = new JPanel();
@@ -629,14 +634,14 @@ public class FlatThemeFileEditor
lightLafMenuItem.setText("Light Laf");
lightLafMenuItem.setMnemonic('L');
lightLafMenuItem.setSelected(true);
lightLafMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F11, 0));
lightLafMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F1, KeyEvent.ALT_DOWN_MASK));
lightLafMenuItem.addActionListener(e -> lightLaf());
viewMenu.add(lightLafMenuItem);
//---- darkLafMenuItem ----
darkLafMenuItem.setText("Dark Laf");
darkLafMenuItem.setMnemonic('D');
darkLafMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F12, 0));
darkLafMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F2, KeyEvent.ALT_DOWN_MASK));
darkLafMenuItem.addActionListener(e -> darkLaf());
viewMenu.add(darkLafMenuItem);
viewMenu.addSeparator();
@@ -666,6 +671,13 @@ public class FlatThemeFileEditor
windowMenu.setText("Window");
windowMenu.setMnemonic('W');
//---- activateEditorMenuItem ----
activateEditorMenuItem.setText("Activate Editor");
activateEditorMenuItem.setMnemonic('A');
activateEditorMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F12, 0));
activateEditorMenuItem.addActionListener(e -> activateEditor());
windowMenu.add(activateEditorMenuItem);
//---- nextEditorMenuItem ----
nextEditorMenuItem.setText("Next Editor");
nextEditorMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_DOWN, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
@@ -743,6 +755,7 @@ public class FlatThemeFileEditor
private JMenuItem decrFontSizeMenuItem;
private JMenuItem resetFontSizeMenuItem;
private JMenu windowMenu;
private JMenuItem activateEditorMenuItem;
private JMenuItem nextEditorMenuItem;
private JMenuItem previousEditorMenuItem;
private JPanel controlPanel;

View File

@@ -114,7 +114,7 @@ new FormModel {
"$buttonGroup": new FormReference( "lafButtonGroup" )
"mnemonic": 76
"selected": true
"accelerator": static javax.swing.KeyStroke getKeyStroke( 122, 0, false )
"accelerator": static javax.swing.KeyStroke getKeyStroke( 112, 520, false )
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "lightLaf", false ) )
} )
add( new FormComponent( "javax.swing.JRadioButtonMenuItem" ) {
@@ -122,7 +122,7 @@ new FormModel {
"text": "Dark Laf"
"$buttonGroup": new FormReference( "lafButtonGroup" )
"mnemonic": 68
"accelerator": static javax.swing.KeyStroke getKeyStroke( 123, 0, false )
"accelerator": static javax.swing.KeyStroke getKeyStroke( 113, 520, false )
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "darkLaf", false ) )
} )
add( new FormComponent( "javax.swing.JPopupMenu$Separator" ) {
@@ -151,6 +151,13 @@ new FormModel {
name: "windowMenu"
"text": "Window"
"mnemonic": 87
add( new FormComponent( "javax.swing.JMenuItem" ) {
name: "activateEditorMenuItem"
"text": "Activate Editor"
"mnemonic": 65
"accelerator": static javax.swing.KeyStroke getKeyStroke( 123, 0, false )
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "activateEditor", false ) )
} )
add( new FormComponent( "javax.swing.JMenuItem" ) {
name: "nextEditorMenuItem"
"text": "Next Editor"