Package simtools.images.svg.test

Source Code of simtools.images.svg.test.TestSVGImageFactory$TestFileHolder

/* ========================
* 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-2005, by :
*     Corporate:
*         EADS Astrium SAS
*         EADS CRC
*     Individual:
*         Claude Cazenave
*
* $Id: TestSVGImageFactory.java,v 1.4 2007/03/28 16:05:17 ogor Exp $
*
* Changes
* -------
* 20 d�c. 2005 : Initial public release (CC);
*
*/
package simtools.images.svg.test;

import java.awt.image.BufferedImage;
import java.io.File;
import java.util.Iterator;
import java.util.logging.Logger;

import org.apache.batik.transcoder.TranscoderException;
import org.apache.batik.transcoder.TranscoderOutput;
import org.w3c.dom.Document;

import simtools.images.svg.FactoryTranscoder;
import simtools.images.svg.ImageHolder;
import simtools.images.svg.SVGFileHolder;
import simtools.images.svg.SVGImageFactory;

/**
* A factory with time measurement and debug traces
*/
public class TestSVGImageFactory extends SVGImageFactory {

  /**
   * A looger to dump error or warning messages in a soket, an output stream, a file...
   */
  static Logger _logger = simtools.util.LogConfigurator.getLogger(TestSVGImageFactory.class.getName());

  protected FactoryTranscoder createFactoryTranscoder(
      ImageHolder ie) {
    return new TestFactoryTranscoder(ie);
  }

  protected SVGFileHolder createFileHolder(SVGImageFactory factory, File f) {
    return new TestFileHolder(factory, f);
  }

  public void dump(String msg) {
    Iterator it = factoryElements.keySet().iterator();
    while (it.hasNext()) {
      Object k = it.next();
      TestFileHolder fh = (TestFileHolder) factoryElements.get(k);
      fh.dump();
    }
  }

  public class TestFileHolder extends SVGFileHolder implements java.io.Serializable{

    public TestFileHolder(SVGImageFactory factory, File f) {
      super(factory, f);
    }

    public void dump() {
      synchronized (imageElements) {
        Iterator it = imageElements.keySet().iterator();
        while (it.hasNext()) {
          Object o = it.next();
          ImageHolder ih = (ImageHolder) imageElements.get(o);
          SVGFileHolder fh = ih.getFileHolder();
         
          _logger.fine("--" + fh.getFile().getName() + "(" + o
              + ")" + ih.getListenersSize());
        }
      }
    }

  }

  public class TestFactoryTranscoder extends FactoryTranscoder {
    long time;

    /**
     * @param ie the image holder
     */
    public TestFactoryTranscoder(ImageHolder ie) {
      super(ie);
    }

    /*
     * (non-Javadoc)
     *
     * @see org.apache.batik.transcoder.image.ImageTranscoder#transcode(org.w3c.dom.Document,
     *      java.lang.String, org.apache.batik.transcoder.TranscoderOutput)
     */
    protected void transcode(Document document, String uri,
        TranscoderOutput output) throws TranscoderException {
      time = System.currentTimeMillis();
      super.transcode(document, uri, output);
    }

    /*
     * (non-Javadoc)
     *
     * @see simtools.images.svg.FactoryTranscoder#sendImage(java.awt.image.BufferedImage)
     */
    protected void sendImage(BufferedImage arg0) {
      time = System.currentTimeMillis() - time;
     
      _logger.fine("load "
          + imageHolder.getFileHolder().getFile().getName() + "("
          + requestedWidth + "," + requestedHeight + ") in " + time
          + " ms");
      super.sendImage(arg0);
    }
  }
}
TOP

Related Classes of simtools.images.svg.test.TestSVGImageFactory$TestFileHolder

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.