diff options
| author | 2019-05-12 09:47:41 +0200 | |
|---|---|---|
| committer | 2019-05-12 09:47:41 +0200 | |
| commit | 65a8ff63bae4f6f2e025e3dbf0b7b8eb64193039 (patch) | |
| tree | ae282f190a8e86a3f0be75ca168f2660d89c56f3 /src/main/java/cuchaz/enigma/gui/util | |
| parent | Support navigation to declaration on ctrl+click (diff) | |
| download | enigma-fork-65a8ff63bae4f6f2e025e3dbf0b7b8eb64193039.tar.gz enigma-fork-65a8ff63bae4f6f2e025e3dbf0b7b8eb64193039.tar.xz enigma-fork-65a8ff63bae4f6f2e025e3dbf0b7b8eb64193039.zip | |
Add forward and backward reference history with mouse navigation (#132)
* Add History
* Add forward and backward reference history
* Update PopupMenuBar text for history
* Fix indentation
* Fix more indentation
Diffstat (limited to 'src/main/java/cuchaz/enigma/gui/util')
| -rw-r--r-- | src/main/java/cuchaz/enigma/gui/util/History.java | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/main/java/cuchaz/enigma/gui/util/History.java b/src/main/java/cuchaz/enigma/gui/util/History.java new file mode 100644 index 0000000..94f3105 --- /dev/null +++ b/src/main/java/cuchaz/enigma/gui/util/History.java | |||
| @@ -0,0 +1,49 @@ | |||
| 1 | package cuchaz.enigma.gui.util; | ||
| 2 | |||
| 3 | import com.google.common.collect.Queues; | ||
| 4 | |||
| 5 | import java.util.Deque; | ||
| 6 | |||
| 7 | public class History<T> { | ||
| 8 | private final Deque<T> previous = Queues.newArrayDeque(); | ||
| 9 | private final Deque<T> next = Queues.newArrayDeque(); | ||
| 10 | private T current; | ||
| 11 | |||
| 12 | public History(T initial) { | ||
| 13 | current = initial; | ||
| 14 | } | ||
| 15 | |||
| 16 | public T getCurrent() { | ||
| 17 | return current; | ||
| 18 | } | ||
| 19 | |||
| 20 | public void push(T value) { | ||
| 21 | previous.addLast(current); | ||
| 22 | current = value; | ||
| 23 | next.clear(); | ||
| 24 | } | ||
| 25 | |||
| 26 | public void replace(T value) { | ||
| 27 | current = value; | ||
| 28 | } | ||
| 29 | |||
| 30 | public boolean canGoBack() { | ||
| 31 | return !previous.isEmpty(); | ||
| 32 | } | ||
| 33 | |||
| 34 | public T goBack() { | ||
| 35 | next.addFirst(current); | ||
| 36 | current = previous.removeLast(); | ||
| 37 | return current; | ||
| 38 | } | ||
| 39 | |||
| 40 | public boolean canGoForward() { | ||
| 41 | return !next.isEmpty(); | ||
| 42 | } | ||
| 43 | |||
| 44 | public T goForward() { | ||
| 45 | previous.addLast(current); | ||
| 46 | current = next.removeFirst(); | ||
| 47 | return current; | ||
| 48 | } | ||
| 49 | } | ||