From 95ce92fa1854182fd5853721421f5d540e1154ac Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Thu, 31 Dec 2020 17:34:16 +0100 Subject: [PATCH] Theme Editor: find previous/next with UP/DOWN keys --- .../themeeditor/FlatFindReplaceBar.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatFindReplaceBar.java b/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatFindReplaceBar.java index cc2af24a..83cb7ee6 100644 --- a/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatFindReplaceBar.java +++ b/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatFindReplaceBar.java @@ -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 consumer; + + ConsumerAction( Consumer consumer ) { + this.consumer = consumer; + } + + @Override + public void actionPerformed( ActionEvent e ) { + consumer.accept( e ); + } + } }