mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2025-12-06 14:00:55 +03:00
Theme Editor: support Ctrl+PageDown/PageUp to switch to next/previous editor
This commit is contained in:
@@ -25,10 +25,13 @@ import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.InputMap;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLayer;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.KeyStroke;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.border.MatteBorder;
|
||||
@@ -104,6 +107,11 @@ class FlatThemeEditorPane
|
||||
scrollPane.setBorder( BorderFactory.createEmptyBorder() );
|
||||
scrollPane.setLineNumbersEnabled( true );
|
||||
|
||||
// map Ctrl+PageUp/Down to a not-existing action to avoid that the scrollpane catches them
|
||||
InputMap inputMap = scrollPane.getInputMap( JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT );
|
||||
inputMap.put( KeyStroke.getKeyStroke( "ctrl PAGE_UP" ), "__dummy__" );
|
||||
inputMap.put( KeyStroke.getKeyStroke( "ctrl PAGE_DOWN" ), "__dummy__" );
|
||||
|
||||
// create error strip
|
||||
errorStrip = new ErrorStrip( textArea );
|
||||
|
||||
|
||||
@@ -327,23 +327,16 @@ public class FlatThemeFileEditor
|
||||
}
|
||||
|
||||
private void nextEditor() {
|
||||
if( tabbedPane.getTabCount() == 0 )
|
||||
return;
|
||||
|
||||
int index = tabbedPane.getSelectedIndex() + 1;
|
||||
if( index >= tabbedPane.getTabCount() )
|
||||
index = 0;
|
||||
tabbedPane.setSelectedIndex( index );
|
||||
notifyTabbedPaneAction( tabbedPane.getActionMap().get( "navigatePageDown" ) );
|
||||
}
|
||||
|
||||
private void previousEditor() {
|
||||
if( tabbedPane.getTabCount() == 0 )
|
||||
return;
|
||||
notifyTabbedPaneAction( tabbedPane.getActionMap().get( "navigatePageUp" ) );
|
||||
}
|
||||
|
||||
int index = tabbedPane.getSelectedIndex() - 1;
|
||||
if( index < 0 )
|
||||
index = tabbedPane.getTabCount() - 1;
|
||||
tabbedPane.setSelectedIndex( index );
|
||||
private void notifyTabbedPaneAction( Action action ) {
|
||||
if( action != null && action.isEnabled() )
|
||||
action.actionPerformed( new ActionEvent( tabbedPane, ActionEvent.ACTION_PERFORMED, null ) );
|
||||
}
|
||||
|
||||
private void find() {
|
||||
@@ -634,7 +627,7 @@ public class FlatThemeFileEditor
|
||||
|
||||
//---- nextEditorMenuItem ----
|
||||
nextEditorMenuItem.setText("Next Editor");
|
||||
nextEditorMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
|
||||
nextEditorMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_DOWN, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
|
||||
nextEditorMenuItem.setMnemonic('N');
|
||||
nextEditorMenuItem.addActionListener(e -> nextEditor());
|
||||
windowMenu.add(nextEditorMenuItem);
|
||||
@@ -642,7 +635,7 @@ public class FlatThemeFileEditor
|
||||
//---- previousEditorMenuItem ----
|
||||
previousEditorMenuItem.setText("Previous Editor");
|
||||
previousEditorMenuItem.setMnemonic('P');
|
||||
previousEditorMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()|KeyEvent.SHIFT_DOWN_MASK));
|
||||
previousEditorMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
|
||||
previousEditorMenuItem.addActionListener(e -> previousEditor());
|
||||
windowMenu.add(previousEditorMenuItem);
|
||||
}
|
||||
|
||||
@@ -145,7 +145,7 @@ new FormModel {
|
||||
add( new FormComponent( "javax.swing.JMenuItem" ) {
|
||||
name: "nextEditorMenuItem"
|
||||
"text": "Next Editor"
|
||||
"accelerator": static javax.swing.KeyStroke getKeyStroke( 9, 4226, false )
|
||||
"accelerator": static javax.swing.KeyStroke getKeyStroke( 34, 4226, false )
|
||||
"mnemonic": 78
|
||||
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "nextEditor", false ) )
|
||||
} )
|
||||
@@ -153,7 +153,7 @@ new FormModel {
|
||||
name: "previousEditorMenuItem"
|
||||
"text": "Previous Editor"
|
||||
"mnemonic": 80
|
||||
"accelerator": static javax.swing.KeyStroke getKeyStroke( 9, 4291, false )
|
||||
"accelerator": static javax.swing.KeyStroke getKeyStroke( 33, 4226, false )
|
||||
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "previousEditor", false ) )
|
||||
} )
|
||||
} )
|
||||
|
||||
Reference in New Issue
Block a user