Return-Path: Delivered-To: apmail-xml-batik-dev-archive@xml.apache.org Received: (qmail 98886 invoked by uid 500); 18 Jun 2002 12:27:12 -0000 Mailing-List: contact batik-dev-help@xml.apache.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Reply-To: batik-dev@xml.apache.org Delivered-To: mailing list batik-dev@xml.apache.org Received: (qmail 98875 invoked by uid 500); 18 Jun 2002 12:27:11 -0000 Delivered-To: apmail-xml-batik-cvs@apache.org Date: 18 Jun 2002 12:27:11 -0000 Message-ID: <20020618122711.64689.qmail@icarus.apache.org> From: vhardy@apache.org To: xml-batik-cvs@apache.org Subject: cvs commit: xml-batik/sources/org/apache/batik/apps/svgbrowser Application.java JSVGViewerFrame.java Main.java XMLPreferenceManager.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N vhardy 2002/06/18 05:27:11 Modified: sources/org/apache/batik/apps/svgbrowser Application.java JSVGViewerFrame.java Main.java XMLPreferenceManager.java Log: Implemented RFE #4834 (making last visited files persistent. The most recent visited files are now persistent and kept in the preferences.xml file. There are two entries: - preference.key.visited.uri.list.length which defines the maximum number of uris which will be stored in the preference file. - preference.key.visited.uri.list which is the list of uris, separated by spaces after encoding with URLEncoder (note that the methods used are deprecated in 1.4, but their replacement is not available in 1.3). The history in each of the viewer frame ('Go' menu) is initialized with the current list of last visited uris which is kept current (i.e., it is updated each time a new uri is visited) throughout the life of the Squiggle browser. Then new URIs are appended as before in the local history. Revision Changes Path 1.9 +11 -1 xml-batik/sources/org/apache/batik/apps/svgbrowser/Application.java Index: Application.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/apps/svgbrowser/Application.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- Application.java 14 Jun 2002 13:12:24 -0000 1.8 +++ Application.java 18 Jun 2002 12:27:11 -0000 1.9 @@ -97,4 +97,14 @@ */ int getAllowedExternalResourceOrigin(); + /** + * Notifies Application of recently visited URI + */ + void addVisitedURI(String uri); + + /** + * Asks Application for a list of recently visited URI + */ + String[] getVisitedURIs(); + } 1.81 +9 -1 xml-batik/sources/org/apache/batik/apps/svgbrowser/JSVGViewerFrame.java Index: JSVGViewerFrame.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/apps/svgbrowser/JSVGViewerFrame.java,v retrieving revision 1.80 retrieving revision 1.81 diff -u -r1.80 -r1.81 --- JSVGViewerFrame.java 14 Jun 2002 13:12:24 -0000 1.80 +++ JSVGViewerFrame.java 18 Jun 2002 12:27:11 -0000 1.81 @@ -519,6 +519,12 @@ localHistory = new LocalHistory(mb, svgCanvas); + String uri[] = application.getVisitedURIs(); + for (int i=0; i>\", \"read\";\n};\n\n"; /** + * Entry for the list of recently visited URI + */ + public static final String PREFERENCE_KEY_VISITED_URI_LIST + = "preference.key.visited.uri.list"; + + /** + * Entry for the maximum number of last visited URIs + */ + public static final String PREFERENCE_KEY_VISITED_URI_LIST_LENGTH + = "preference.key.visited.uri.list.length"; + + /** + * List of separators between URI values in the preference + * file + */ + public static final String URI_SEPARATOR = " "; + + /** + * SVG initialization file, used to trigger loading of most of + * the Batik classes + */ + public static final String SVG_INITIALIZATION = "resources/init.svg"; + + /** + * Stores the initialization file URI + */ + protected String svgInitializationURI; + + /** * Creates a viewer frame and shows it.. * @param args The command-line arguments. */ @@ -162,6 +196,21 @@ protected XMLPreferenceManager preferenceManager; /** + * Maximum number of recently visited URIs + */ + public static final int MAX_VISITED_URIS = 10; + + /** + * The array of last visited URIs + */ + protected Vector lastVisited = new Vector(); + + /** + * The actual allowed maximum number of last visited URIs + */ + protected int maxVisitedURIs = MAX_VISITED_URIS; + + /** * The arguments. */ protected String[] arguments; @@ -244,6 +293,10 @@ new Integer(ResourceOrigin.DOCUMENT)); defaults.put(PreferenceDialog.PREFERENCE_KEY_ALLOWED_EXTERNAL_RESOURCE_ORIGIN, new Integer(ResourceOrigin.ANY)); + defaults.put(PREFERENCE_KEY_VISITED_URI_LIST, + ""); + defaults.put(PREFERENCE_KEY_VISITED_URI_LIST_LENGTH, + new Integer(MAX_VISITED_URIS)); securityEnforcer = new ApplicationSecurityEnforcer(this.getClass(), @@ -259,6 +312,7 @@ preferenceManager.setPreferenceDirectory(f.getCanonicalPath()); preferenceManager.load(); setPreferences(); + initializeLastVisited(); } catch (Exception e) { e.printStackTrace(); } @@ -303,9 +357,10 @@ run(); } }); + c.setSize(100, 100); - c.loadSVGDocument(Main.class.getResource("resources/init.svg").toString()); - + svgInitializationURI = Main.class.getResource(SVG_INITIALIZATION).toString(); + c.loadSVGDocument(svgInitializationURI); } /** @@ -722,4 +777,83 @@ return ret; } + /** + * Notifies Application of recently visited URI + */ + public void addVisitedURI(String uri) { + if(svgInitializationURI.equals(uri)) { + return; + } + + int maxVisitedURIs = + preferenceManager.getInteger + (PREFERENCE_KEY_VISITED_URI_LIST_LENGTH); + + if (maxVisitedURIs < 0) { + maxVisitedURIs = 0; + } + + while (lastVisited.size() > maxVisitedURIs) { + lastVisited.removeElementAt(0); + } + + if (lastVisited.contains(uri)) { + lastVisited.removeElement(uri); + } + + lastVisited.addElement(uri); + + // Now, save the list of visited URL into the preferences + StringBuffer lastVisitedBuffer = new StringBuffer(); + + for (int i=0; i maxVisitedURIs) { + n = maxVisitedURIs; + } + + for (int i=0; i