Package jsynoptic.plugins.svg

Source Code of jsynoptic.plugins.svg.SvgImagePreview

/* ========================
* JSynoptic : a free Synoptic editor
* ========================
*
* Project Info:  http://jsynoptic.sourceforge.net/index.html
*
* This program is free software; you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation;
* either version 2.1 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with this
* program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*
* (C) Copyright 2001-2006, by :
*     Corporate:
*         EADS Astrium SAS
*     Individual:
*         Mathias Choquet
*
*
* $$Id$$
*
*/
package jsynoptic.plugins.svg;

import java.awt.Image;
import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import simtools.images.svg.SVGImageFactory;
import simtools.ui.ImagePreview;

/**
* Class . Summary: this class SvgImagePreview is able to drawn a image preview
* of a a svg file in a filechooser using simtools.ui.ImagePreview
*/
public class SvgImagePreview extends ImagePreview implements
    SVGImageFactory.FactoryListener {

  /**
   * Constructor. call the ImagePreview construct
   *
   * @param fc
   *            the filechooser
   */
  public SvgImagePreview(JFileChooser fc) {
    super(fc);
  }

  public void clean() {
    if (file != null) {
      SvgShape.factory.release(file, this);
    }
  }

  /*
   * (non-Javadoc)
   *
   * @see simtools.ui.ImagePreview#loadImage()
   */
  public void loadImage() {
    if (file != null) {
      // the file must have an svg extension
      if (file.getName().endsWith(".svg")) {
        SvgShape.factory.release(file, this);
        SvgShape.factory.load(file, this);
      }
    }
  }

  /*
   * (non-Javadoc)
   *
   * @see simtools.images.svg.SVGImageFactory.FactoryListener#done(java.awt.image.BufferedImage)
   */
  public void done(BufferedImage image) {
    if (image == null) {
      return;
    }
    Image preferedSizeImage = image.getScaledInstance(90, 90, 0);
    thumbnail = new ImageIcon(preferedSizeImage);
    repaint();
  }

  /*
   * (non-Javadoc)
   *
   * @see simtools.images.svg.SVGImageFactory.FactoryListener#failed(java.lang.String)
   */
  public void failed(String msg) {
  }

}
TOP

Related Classes of jsynoptic.plugins.svg.SvgImagePreview

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.