■ ■ ■ ■ ■ ■
src/main/java/com/nccgroup/loggerplusplus/filter/logfilter/LogFilterController.java
| skipped 10 lines |
11 | 11 | | import com.nccgroup.loggerplusplus.util.Globals; |
12 | 12 | | |
13 | 13 | | import javax.swing.*; |
| 14 | + | import javax.swing.text.Document; |
| 15 | + | import javax.swing.undo.UndoManager; |
14 | 16 | | import java.awt.*; |
15 | 17 | | import java.awt.event.*; |
16 | 18 | | import java.util.HashMap; |
| skipped 36 lines |
53 | 55 | | } |
54 | 56 | | } |
55 | 57 | | }); |
| 58 | + | |
| 59 | + | Document filterFieldDoc = ((JTextField) filterField.getEditor().getEditorComponent()).getDocument(); |
| 60 | + | final UndoManager undoManager = new UndoManager(); |
| 61 | + | filterFieldDoc.addUndoableEditListener(undoableEditEvent -> undoManager.addEdit(undoableEditEvent.getEdit())); |
| 62 | + | filterField.getActionMap().put("Undo", new AbstractAction("Undo") { |
| 63 | + | @Override |
| 64 | + | public void actionPerformed(ActionEvent actionEvent) { |
| 65 | + | if (undoManager.canUndo()) undoManager.undo(); |
| 66 | + | } |
| 67 | + | }); |
| 68 | + | |
| 69 | + | filterField.getActionMap().put("Redo", new AbstractAction("Redo") { |
| 70 | + | @Override |
| 71 | + | public void actionPerformed(ActionEvent actionEvent) { |
| 72 | + | if (undoManager.canRedo()) undoManager.redo(); |
| 73 | + | } |
| 74 | + | }); |
| 75 | + | |
| 76 | + | filterField.getInputMap().put(KeyStroke.getKeyStroke("control Z"), "Undo"); |
| 77 | + | filterField.getInputMap().put(KeyStroke.getKeyStroke("control Y"), "Redo"); |
56 | 78 | | |
57 | 79 | | //Update when clicking an item in the list, but not when using arrow keys to move |
58 | 80 | | filterField.addActionListener(e -> { |
| skipped 101 lines |