You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-dev@xmlgraphics.apache.org by tk...@apache.org on 2001/09/06 10:32:28 UTC

cvs commit: xml-batik/sources/org/apache/batik/apps/svgbrowser JSVGViewerFrame.java

tkormann    01/09/06 01:32:28

  Modified:    sources/org/apache/batik/apps/svgbrowser
                        JSVGViewerFrame.java
  Log:
  Add a file filter when exporting as an image (png, jpg, or tiff).
  
  Revision  Changes    Path
  1.47      +47 -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.46
  retrieving revision 1.47
  diff -u -r1.46 -r1.47
  --- JSVGViewerFrame.java	2001/08/03 16:33:42	1.46
  +++ JSVGViewerFrame.java	2001/09/06 08:32:28	1.47
  @@ -73,6 +73,8 @@
   import javax.swing.JTextArea;
   import javax.swing.JToolBar;
   
  +import javax.swing.filechooser.FileFilter;
  +
   import javax.swing.text.Document;
   import javax.swing.text.PlainDocument;
   
  @@ -136,7 +138,7 @@
    * This class represents a SVG viewer swing frame.
    *
    * @author <a href="mailto:stephane@hillion.org">Stephane Hillion</a>
  - * @version $Id: JSVGViewerFrame.java,v 1.46 2001/08/03 16:33:42 vhardy Exp $
  + * @version $Id: JSVGViewerFrame.java,v 1.47 2001/09/06 08:32:28 tkormann Exp $
    */
   public class JSVGViewerFrame
       extends    JFrame
  @@ -858,6 +860,7 @@
               fileChooser.setFileHidingEnabled(false);
               fileChooser.setFileSelectionMode
                   (JFileChooser.FILES_ONLY);
  +            fileChooser.addChoosableFileFilter(new ImageFileFilter(".jpg"));
   
               int choice = fileChooser.showSaveDialog(JSVGViewerFrame.this);
               if (choice == JFileChooser.APPROVE_OPTION) {
  @@ -911,6 +914,7 @@
               fileChooser.setFileHidingEnabled(false);
               fileChooser.setFileSelectionMode
                   (JFileChooser.FILES_ONLY);
  +            fileChooser.addChoosableFileFilter(new ImageFileFilter(".png"));
   
               int choice = fileChooser.showSaveDialog(JSVGViewerFrame.this);
               if (choice == JFileChooser.APPROVE_OPTION) {
  @@ -962,6 +966,7 @@
               fileChooser.setFileHidingEnabled(false);
               fileChooser.setFileSelectionMode
                   (JFileChooser.FILES_ONLY);
  +            fileChooser.addChoosableFileFilter(new ImageFileFilter(".tiff"));
   
               int choice = fileChooser.showSaveDialog(JSVGViewerFrame.this);
               if (choice == JFileChooser.APPROVE_OPTION) {
  @@ -1691,4 +1696,45 @@
           public void handleElement(Element elt, Object data){
           }
       }
  +
  +    /**
  +     * A FileFilter used when exporting the SVG document as an image.
  +     */
  +    protected static class ImageFileFilter extends FileFilter {
  +
  +	/** The extension of the image filename. */
  +	protected String extension;
  +
  +	public ImageFileFilter(String extension) {
  +	    this.extension = extension;
  +	}
  +
  +	/**
  +	 * Returns true if <tt>f</tt> is a file with the correct extension,
  +	 * false otherwise.
  +	 */
  +	public boolean accept(File f) {
  +	    boolean accept = false;
  +	    String fileName = null;
  +	    if (f != null) {
  +		if (f.isDirectory()) {
  +		    accept = true;
  +		} else {
  +		    fileName = f.getPath().toLowerCase();
  +		    if (fileName.endsWith(extension)) {
  +			accept = true;
  +		    }
  +		}
  +	    }
  +	    return accept;
  +	}
  +	
  +	/**
  +	 * Returns the file description
  +	 */
  +	public String getDescription() {
  +	    return extension;
  +	}
  +    }
  +
   }
  
  
  

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