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

Last change on this file since 3128 was 3083, checked in by bastiK, 14 years ago

added svn:eol-style=native to source files

  • 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.Observable;
7
8public class HelpBrowserHistory extends Observable {
9 private HelpBrowser browser;
10 private ArrayList<String> history;
11 private int historyPos = 0;
12
13 public HelpBrowserHistory(HelpBrowser browser) {
14 this.browser = browser;
15 history = new ArrayList<String>();
16 }
17
18 public void clear() {
19 history.clear();
20 historyPos = 0;
21 setChanged();
22 notifyObservers();
23 }
24
25 public boolean canGoBack() {
26 return historyPos > 0;
27 }
28
29 public boolean canGoForward() {
30 return historyPos + 1 < history.size();
31 }
32
33 public void back() {
34 historyPos--;
35 if (historyPos < 0) return;
36 String url = history.get(historyPos);
37 browser.openUrl(url);
38 setChanged();
39 notifyObservers();
40 }
41
42 public void forward() {
43 historyPos++;
44 if (historyPos >= history.size()) return;
45 String url = history.get(historyPos);
46 browser.openUrl(url);
47 setChanged();
48 notifyObservers();
49 }
50
51 public void setCurrentUrl(String url) {
52 boolean add=true;
53
54 if (historyPos >= 0 && historyPos < history.size() && history.get(historyPos).toString().equals(url.toString())) {
55 add = false;
56 } else if (historyPos == history.size() -1) {
57 // do nothing just append
58 } else if (historyPos ==0 && history.size() > 0) {
59 history = new ArrayList<String>(Collections.singletonList(history.get(0)));
60 } else if (historyPos < history.size() -1 && historyPos > 0) {
61 history = new ArrayList<String>(history.subList(0, historyPos));
62 } else {
63 history = new ArrayList<String>();
64 }
65 if(add)
66 {
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.