Theme Editor: find previous/next with UP/DOWN keys

This commit is contained in:
Karl Tauber
2020-12-31 17:34:16 +01:00
parent b3db52b2ed
commit 95ce92fa18

View File

@@ -17,6 +17,9 @@
package com.formdev.flatlaf.themeeditor;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.util.function.Consumer;
import javax.swing.*;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
@@ -45,6 +48,14 @@ class FlatFindReplaceBar
findField.getDocument().addDocumentListener( new MarkAllUpdater() );
// find previous/next with UP/DOWN keys
InputMap inputMap = findField.getInputMap();
inputMap.put( KeyStroke.getKeyStroke( KeyEvent.VK_UP, 0 ), "findPrevious" );
inputMap.put( KeyStroke.getKeyStroke( KeyEvent.VK_DOWN, 0 ), "findNext" );
ActionMap actionMap = findField.getActionMap();
actionMap.put( "findPrevious", new ConsumerAction( e -> findPrevious() ) );
actionMap.put( "findNext", new ConsumerAction( e -> findNext() ) );
findPreviousButton.setIcon( new FlatSVGIcon( "com/formdev/flatlaf/themeeditor/icons/findAndShowPrevMatches.svg" ) );
findNextButton.setIcon( new FlatSVGIcon( "com/formdev/flatlaf/themeeditor/icons/findAndShowNextMatches.svg" ) );
matchCaseToggleButton.setIcon( new FlatSVGIcon( "com/formdev/flatlaf/themeeditor/icons/matchCase.svg" ) );
@@ -268,4 +279,21 @@ class FlatFindReplaceBar
markAll();
}
}
//---- class ConsumerAction -----------------------------------------------
private static class ConsumerAction
extends AbstractAction
{
private final Consumer<ActionEvent> consumer;
ConsumerAction( Consumer<ActionEvent> consumer ) {
this.consumer = consumer;
}
@Override
public void actionPerformed( ActionEvent e ) {
consumer.accept( e );
}
}
}