source: josm/trunk/src/org/openstreetmap/josm/gui/help/HelpBrowserHistory.java@ 9078

Last change on this file since 9078 was 9078, checked in by Don-vip, 8 years ago

sonar - Immutable Field

  • Property svn:eol-style set to native
File size: 2.0 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.help;
3
4import java.util.ArrayList;
5import java.util.Collections;
6import java.util.List;
7import java.util.Observable;
8
9public class HelpBrowserHistory extends Observable {
10 private final HelpBrowser browser;
11 private List<String> history;
12 private int historyPos;
13
14 public HelpBrowserHistory(HelpBrowser browser) {
15 this.browser = browser;
16 history = new ArrayList<>();
17 }
18
19 public void clear() {
20 history.clear();
21 historyPos = 0;
22 setChanged();
23 notifyObservers();
24 }
25
26 public boolean canGoBack() {
27 return historyPos > 0;
28 }
29
30 public boolean canGoForward() {
31 return historyPos + 1 < history.size();
32 }
33
34 public void back() {
35 historyPos--;
36 if (historyPos < 0) return;
37 String url = history.get(historyPos);
38 browser.openUrl(url);
39 setChanged();
40 notifyObservers();
41 }
42
43 public void forward() {
44 historyPos++;
45 if (historyPos >= history.size()) return;
46 String url = history.get(historyPos);
47 browser.openUrl(url);
48 setChanged();
49 notifyObservers();
50 }
51
52 public void setCurrentUrl(String url) {
53 boolean add = true;
54
55 if (historyPos >= 0 && historyPos < history.size() && history.get(historyPos).equals(url)) {
56 add = false;
57 } else if (historyPos == history.size() -1) {
58 // do nothing just append
59 } else if (historyPos == 0 && !history.isEmpty()) {
60 history = new ArrayList<>(Collections.singletonList(history.get(0)));
61 } else if (historyPos < history.size() -1 && historyPos > 0) {
62 history = new ArrayList<>(history.subList(0, historyPos));
63 } else {
64 history = new ArrayList<>();
65 }
66 if (add) {
67 history.add(url);
68 historyPos = history.size()-1;
69 }
70 setChanged();
71 notifyObservers();
72 }
73}
Note: See TracBrowser for help on using the repository browser.