1 package jimm.datavision.gui; 2 import jimm.datavision.ErrorHandler; 3 import jimm.util.I18N; 4 import java.io.IOException ; 5 import java.net.URL ; 6 import java.net.MalformedURLException ; 7 import java.util.Stack ; 8 import javax.swing.JTextField ; 9 import javax.swing.JEditorPane ; 10 11 18 class HelpURLStack { 19 20 protected Stack back; 21 protected URL home; 22 protected URL current; 23 protected Stack forward; 24 protected JEditorPane contentField; 25 protected JTextField urlField; 26 27 HelpURLStack(JEditorPane htmlField, JTextField textField) { 28 contentField = htmlField; 29 urlField = textField; 30 back = new Stack (); 31 current = null; 32 forward = new Stack (); 33 } 34 35 boolean hasPrevious() { 36 return !back.empty(); 37 } 38 boolean hasNext() { 39 return !forward.empty(); 40 } 41 42 void goTo(String urlString) { 43 try { 44 URL url = new URL (urlString); 45 goTo(url); 46 } 47 catch (MalformedURLException e) { 48 ErrorHandler.error(I18N.get("HelpURLStack.error_parsing") 49 + ' ' + urlString, e); 50 } 51 } 52 53 void goTo(URL url) { 54 if (current != null) 55 back.push(current); 56 if (home == null) 57 home = url; 58 current = url; 59 forward.clear(); 60 updateGUI(); 61 } 62 63 64 void goToHomePage() { 65 goTo(home); 66 } 67 68 void goToPreviousPage() { 69 if (hasPrevious()) { 70 if (current != null) 71 forward.push(current); 72 current = (URL )back.pop(); 73 } 74 updateGUI(); 75 } 76 77 void goToNextPage() { 78 if (hasNext()) { 79 if (current != null) 80 back.push(current); 81 current = (URL )forward.pop(); 82 } 83 updateGUI(); 84 } 85 86 protected void updateGUI() { 87 urlField.setText(current == null ? "" : current.toString()); 88 try { 89 contentField.setPage(current); 90 } 91 catch (IOException e) { 92 ErrorHandler.error(I18N.get("HelpURLStack.error_loading") 93 + ' ' + current, e); 94 } 95 96 } 97 98 } 99 | Popular Tags |