diff --git a/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatSyntaxTextArea.java b/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatSyntaxTextArea.java index 4f629012..05f7f8b3 100644 --- a/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatSyntaxTextArea.java +++ b/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatSyntaxTextArea.java @@ -17,6 +17,8 @@ package com.formdev.flatlaf.themeeditor; import java.awt.Color; +import java.awt.KeyboardFocusManager; +import java.util.Collections; import java.util.HashMap; import java.util.Map; import javax.swing.text.BadLocationException; @@ -38,6 +40,9 @@ class FlatSyntaxTextArea private final Map parsedColorsMap = new HashMap<>(); FlatSyntaxTextArea() { + // remove Ctrl+Tab and Ctrl+Shift+Tab focus traversal keys to allow tabbed pane to process them + setFocusTraversalKeys( KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, Collections.emptySet() ); + setFocusTraversalKeys( KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, Collections.emptySet() ); } boolean isUseColorOfColorTokens() { diff --git a/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatThemeFileEditor.java b/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatThemeFileEditor.java index b868eba2..5643c4fa 100644 --- a/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatThemeFileEditor.java +++ b/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatThemeFileEditor.java @@ -165,12 +165,29 @@ public class FlatThemeFileEditor return result; } + private void nextEditor() { + int index = tabbedPane.getSelectedIndex() + 1; + if( index >= tabbedPane.getTabCount() ) + index = 0; + tabbedPane.setSelectedIndex( index ); + } + + private void previousEditor() { + int index = tabbedPane.getSelectedIndex() - 1; + if( index < 0 ) + index = tabbedPane.getTabCount() - 1; + tabbedPane.setSelectedIndex( index ); + } + private void initComponents() { // JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents menuBar = new JMenuBar(); fileMenu = new JMenu(); saveAllMenuItem = new JMenuItem(); exitMenuItem = new JMenuItem(); + windowMenu = new JMenu(); + nextEditorMenuItem = new JMenuItem(); + previousEditorMenuItem = new JMenuItem(); controlPanel = new JPanel(); directoryLabel = new JLabel(); directoryField = new JTextField(); @@ -219,6 +236,27 @@ public class FlatThemeFileEditor fileMenu.add(exitMenuItem); } menuBar.add(fileMenu); + + //======== windowMenu ======== + { + windowMenu.setText("Window"); + windowMenu.setMnemonic('W'); + + //---- nextEditorMenuItem ---- + nextEditorMenuItem.setText("Next Editor"); + nextEditorMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); + nextEditorMenuItem.setMnemonic('N'); + nextEditorMenuItem.addActionListener(e -> nextEditor()); + windowMenu.add(nextEditorMenuItem); + + //---- previousEditorMenuItem ---- + previousEditorMenuItem.setText("Previous Editor"); + previousEditorMenuItem.setMnemonic('P'); + previousEditorMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()|KeyEvent.SHIFT_MASK)); + previousEditorMenuItem.addActionListener(e -> previousEditor()); + windowMenu.add(previousEditorMenuItem); + } + menuBar.add(windowMenu); } setJMenuBar(menuBar); @@ -238,6 +276,7 @@ public class FlatThemeFileEditor //---- directoryField ---- directoryField.setEditable(false); + directoryField.setFocusable(false); controlPanel.add(directoryField, "cell 1 0"); } contentPane.add(controlPanel, BorderLayout.NORTH); @@ -255,6 +294,9 @@ public class FlatThemeFileEditor private JMenu fileMenu; private JMenuItem saveAllMenuItem; private JMenuItem exitMenuItem; + private JMenu windowMenu; + private JMenuItem nextEditorMenuItem; + private JMenuItem previousEditorMenuItem; private JPanel controlPanel; private JLabel directoryLabel; private JTextField directoryField; diff --git a/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatThemeFileEditor.jfd b/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatThemeFileEditor.jfd index 98c68d40..5dad47f3 100644 --- a/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatThemeFileEditor.jfd +++ b/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatThemeFileEditor.jfd @@ -27,6 +27,7 @@ new FormModel { add( new FormComponent( "javax.swing.JTextField" ) { name: "directoryField" "editable": false + "focusable": false }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { "value": "cell 1 0" } ) @@ -62,6 +63,25 @@ new FormModel { addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "exit", false ) ) } ) } ) + add( new FormContainer( "javax.swing.JMenu", new FormLayoutManager( class javax.swing.JMenu ) ) { + name: "windowMenu" + "text": "Window" + "mnemonic": 87 + add( new FormComponent( "javax.swing.JMenuItem" ) { + name: "nextEditorMenuItem" + "text": "Next Editor" + "accelerator": static javax.swing.KeyStroke getKeyStroke( 9, 4226, false ) + "mnemonic": 78 + addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "nextEditor", false ) ) + } ) + add( new FormComponent( "javax.swing.JMenuItem" ) { + name: "previousEditorMenuItem" + "text": "Previous Editor" + "mnemonic": 80 + "accelerator": static javax.swing.KeyStroke getKeyStroke( 9, 4291, false ) + addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "previousEditor", false ) ) + } ) + } ) } }, new FormLayoutConstraints( null ) { "location": new java.awt.Point( 0, 0 )