xmlgraphics-batik-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vha...@apache.org
Subject cvs commit: xml-batik/sources/org/apache/batik/apps/svgbrowser Application.java JSVGViewerFrame.java Main.java XMLPreferenceManager.java
Date Tue, 18 Jun 2002 12:27:11 GMT
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<uri.length; i++) {
  +                if (uri[i] != null && !"".equals(uri[i])) {
  +                    localHistory.update(uri[i]);
  +                }
  +            }
               p = new JPanel(new BorderLayout());
   
               // Create the toolbar
  @@ -1624,6 +1630,7 @@
           }
   
           localHistory.update(s);
  +        application.addVisitedURI(s);
           backAction.update();
           forwardAction.update();
   
  @@ -1877,6 +1884,7 @@
   
               if (s.indexOf("#") != -1) {
                   localHistory.update(s);
  +                application.addVisitedURI(s);
                   backAction.update();
                   forwardAction.update();
   
  
  
  
  1.36      +137 -3    xml-batik/sources/org/apache/batik/apps/svgbrowser/Main.java
  
  Index: Main.java
  ===================================================================
  RCS file: /home/cvs/xml-batik/sources/org/apache/batik/apps/svgbrowser/Main.java,v
  retrieving revision 1.35
  retrieving revision 1.36
  diff -u -r1.35 -r1.36
  --- Main.java	17 Jun 2002 08:07:39 -0000	1.35
  +++ Main.java	18 Jun 2002 12:27:11 -0000	1.36
  @@ -23,6 +23,9 @@
   import java.io.Writer;
   import java.security.Policy;
   
  +import java.net.URLDecoder;
  +import java.net.URLEncoder;
  +
   import java.util.HashMap;
   import java.util.Iterator;
   import java.util.LinkedList;
  @@ -30,6 +33,8 @@
   import java.util.Locale;
   import java.util.Map;
   import java.util.ResourceBundle;
  +import java.util.StringTokenizer;
  +import java.util.Vector;
   
   import javax.swing.AbstractAction;
   import javax.swing.Action;
  @@ -111,6 +116,35 @@
           = "grant {\n  permission java.io.FilePermission \"<<ALL FILES>>\",
\"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<lastVisited.size(); i++) {
  +            lastVisitedBuffer.append(URLEncoder.encode(lastVisited.elementAt(i).toString()));
  +            lastVisitedBuffer.append(URI_SEPARATOR);
  +        }
  +        
  +        preferenceManager.setString
  +            (PREFERENCE_KEY_VISITED_URI_LIST,
  +             lastVisitedBuffer.toString());
  +
  +        try {
  +            preferenceManager.save();
  +        } catch (Exception e) {
  +            // As in other places. But this is ugly...
  +        }
  +    }
  +
  +    /**
  +     * Asks Application for a list of recently visited URI.
  +     */
  +    public String[] getVisitedURIs() {
  +        String[] visitedURIs = new String[lastVisited.size()];
  +        lastVisited.copyInto(visitedURIs);
  +        return visitedURIs;
  +    }
  +
  +    /**
  +     * Initializes the lastVisited array
  +     */
  +    protected void initializeLastVisited(){
  +        String lastVisitedStr 
  +            = preferenceManager.getString(PREFERENCE_KEY_VISITED_URI_LIST);
  +
  +        StringTokenizer st 
  +            = new StringTokenizer(lastVisitedStr,
  +                                  URI_SEPARATOR);
  +
  +        int n = st.countTokens();
  +
  +        int maxVisitedURIs 
  +            = preferenceManager.getInteger
  +            (PREFERENCE_KEY_VISITED_URI_LIST_LENGTH);
  +
  +        if (n > maxVisitedURIs) {
  +            n = maxVisitedURIs;
  +        }
  +
  +        for (int i=0; i<n; i++) {
  +            lastVisited.addElement(URLDecoder.decode(st.nextToken()));
  +        }
  +    }
   }
  
  
  
  1.3       +8 -3      xml-batik/sources/org/apache/batik/apps/svgbrowser/XMLPreferenceManager.java
  
  Index: XMLPreferenceManager.java
  ===================================================================
  RCS file: /home/cvs/xml-batik/sources/org/apache/batik/apps/svgbrowser/XMLPreferenceManager.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- XMLPreferenceManager.java	9 May 2001 22:43:58 -0000	1.2
  +++ XMLPreferenceManager.java	18 Jun 2002 12:27:11 -0000	1.3
  @@ -48,6 +48,11 @@
       protected String xmlParserClassName;
   
       /**
  +     * The XML encoding used to store properties
  +     */
  +    public static final String PREFERENCE_ENCODING = "8859_1";
  +
  +    /**
        * Creates a preference manager.
        * @param prefFileName the name of the preference file.
        */
  @@ -102,7 +107,7 @@
            */
           public synchronized void load(InputStream is) throws IOException {
               BufferedReader r;
  -            r = new BufferedReader(new InputStreamReader(is, "8859_1"));
  +            r = new BufferedReader(new InputStreamReader(is, PREFERENCE_ENCODING));
               DocumentFactory df = new SAXDocumentFactory
                   (GenericDOMImplementation.getDOMImplementation(),
                    xmlParserClassName);
  @@ -143,7 +148,7 @@
           public synchronized void store(OutputStream os, String header)
               throws IOException {
               BufferedWriter w;
  -            w = new BufferedWriter(new OutputStreamWriter(os, "8859_1"));
  +            w = new BufferedWriter(new OutputStreamWriter(os, PREFERENCE_ENCODING));
   
               Map m = new HashMap();
               enumerate(m);
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-dev-help@xml.apache.org


Mime
View raw message