mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2025-12-07 14:30:56 +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.nio.charset.StandardCharsets;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javax.swing.BorderFactory;
|
import javax.swing.BorderFactory;
|
||||||
|
import javax.swing.InputMap;
|
||||||
|
import javax.swing.JComponent;
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
import javax.swing.JLayer;
|
import javax.swing.JLayer;
|
||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.KeyStroke;
|
||||||
import javax.swing.SwingUtilities;
|
import javax.swing.SwingUtilities;
|
||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
import javax.swing.border.MatteBorder;
|
import javax.swing.border.MatteBorder;
|
||||||
@@ -104,6 +107,11 @@ class FlatThemeEditorPane
|
|||||||
scrollPane.setBorder( BorderFactory.createEmptyBorder() );
|
scrollPane.setBorder( BorderFactory.createEmptyBorder() );
|
||||||
scrollPane.setLineNumbersEnabled( true );
|
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
|
// create error strip
|
||||||
errorStrip = new ErrorStrip( textArea );
|
errorStrip = new ErrorStrip( textArea );
|
||||||
|
|
||||||
|
|||||||
@@ -327,23 +327,16 @@ public class FlatThemeFileEditor
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void nextEditor() {
|
private void nextEditor() {
|
||||||
if( tabbedPane.getTabCount() == 0 )
|
notifyTabbedPaneAction( tabbedPane.getActionMap().get( "navigatePageDown" ) );
|
||||||
return;
|
|
||||||
|
|
||||||
int index = tabbedPane.getSelectedIndex() + 1;
|
|
||||||
if( index >= tabbedPane.getTabCount() )
|
|
||||||
index = 0;
|
|
||||||
tabbedPane.setSelectedIndex( index );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void previousEditor() {
|
private void previousEditor() {
|
||||||
if( tabbedPane.getTabCount() == 0 )
|
notifyTabbedPaneAction( tabbedPane.getActionMap().get( "navigatePageUp" ) );
|
||||||
return;
|
}
|
||||||
|
|
||||||
int index = tabbedPane.getSelectedIndex() - 1;
|
private void notifyTabbedPaneAction( Action action ) {
|
||||||
if( index < 0 )
|
if( action != null && action.isEnabled() )
|
||||||
index = tabbedPane.getTabCount() - 1;
|
action.actionPerformed( new ActionEvent( tabbedPane, ActionEvent.ACTION_PERFORMED, null ) );
|
||||||
tabbedPane.setSelectedIndex( index );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void find() {
|
private void find() {
|
||||||
@@ -634,7 +627,7 @@ public class FlatThemeFileEditor
|
|||||||
|
|
||||||
//---- nextEditorMenuItem ----
|
//---- nextEditorMenuItem ----
|
||||||
nextEditorMenuItem.setText("Next Editor");
|
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.setMnemonic('N');
|
||||||
nextEditorMenuItem.addActionListener(e -> nextEditor());
|
nextEditorMenuItem.addActionListener(e -> nextEditor());
|
||||||
windowMenu.add(nextEditorMenuItem);
|
windowMenu.add(nextEditorMenuItem);
|
||||||
@@ -642,7 +635,7 @@ public class FlatThemeFileEditor
|
|||||||
//---- previousEditorMenuItem ----
|
//---- previousEditorMenuItem ----
|
||||||
previousEditorMenuItem.setText("Previous Editor");
|
previousEditorMenuItem.setText("Previous Editor");
|
||||||
previousEditorMenuItem.setMnemonic('P');
|
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());
|
previousEditorMenuItem.addActionListener(e -> previousEditor());
|
||||||
windowMenu.add(previousEditorMenuItem);
|
windowMenu.add(previousEditorMenuItem);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -145,7 +145,7 @@ new FormModel {
|
|||||||
add( new FormComponent( "javax.swing.JMenuItem" ) {
|
add( new FormComponent( "javax.swing.JMenuItem" ) {
|
||||||
name: "nextEditorMenuItem"
|
name: "nextEditorMenuItem"
|
||||||
"text": "Next Editor"
|
"text": "Next Editor"
|
||||||
"accelerator": static javax.swing.KeyStroke getKeyStroke( 9, 4226, false )
|
"accelerator": static javax.swing.KeyStroke getKeyStroke( 34, 4226, false )
|
||||||
"mnemonic": 78
|
"mnemonic": 78
|
||||||
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "nextEditor", false ) )
|
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "nextEditor", false ) )
|
||||||
} )
|
} )
|
||||||
@@ -153,7 +153,7 @@ new FormModel {
|
|||||||
name: "previousEditorMenuItem"
|
name: "previousEditorMenuItem"
|
||||||
"text": "Previous Editor"
|
"text": "Previous Editor"
|
||||||
"mnemonic": 80
|
"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 ) )
|
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "previousEditor", false ) )
|
||||||
} )
|
} )
|
||||||
} )
|
} )
|
||||||
|
|||||||
Reference in New Issue
Block a user