1 package org.joshy.html.app.browser; 2 3 import org.joshy.u; 4 import java.net.URL ; 5 import org.w3c.dom.Document ; 6 import java.util.ArrayList ; 7 8 18 19 20 public class HistoryManager { 21 protected ArrayList entries = new ArrayList (); 22 protected int index = -1; 23 24 protected class Entry { 25 public Document doc; 26 public URL url; 27 public String toString() { 28 return "HistoryEntry: " + doc; 29 } 30 } 31 32 protected Entry getEntry(int i) { 33 return (Entry)entries.get(i); 34 } 35 36 public Document getCurrentDocument() { 37 return getEntry(index).doc; 38 } 39 40 public URL getCurrentURL() { 41 return getEntry(index).url; 42 } 43 44 public void goPrevious() { 45 index--; 46 } 47 public boolean hasPrevious() { 48 if(index > 0) { 49 return true; 50 } else { 51 return false; 52 } 53 } 54 55 public boolean hasNext() { 56 if(index+1 < entries.size() && index >= 0) { 57 return true; 58 } else { 59 return false; 60 } 61 } 62 public void goNext() { 63 index++; 64 } 65 public void goNewDocument(Document doc) { 66 goNewDocument(doc,null); 67 } 68 public void goNewDocument(Document doc, URL url) { 69 Entry entry = new Entry(); 70 entry.doc = doc; 71 entry.url = url; 72 74 int len = entries.size(); 75 for(int i=index+1; i<len; i++) { 76 entries.remove(index+1); 77 } 78 79 entries.add(entry); 80 index++; 81 } 83 84 public void dumpHistory() { 85 u.p(entries); 86 u.p("current index = " + index); 87 } 88 89 } 90 | Popular Tags |