亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? renderer.java

?? jfreechart標簽庫
?? JAVA
字號:
/* ================================================================
 * Cewolf : Chart enabling Web Objects Framework
 * ================================================================
 *
 * Project Info:  http://cewolf.sourceforge.net
 * Project Lead:  Guido Laures (guido@laures.de);
 *
 * (C) Copyright 2002, by Guido Laures
 *
 * This library 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 library 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
 * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
 * Boston, MA 02111-1307, USA.
 */

package de.laures.cewolf.util;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.Iterator;
import java.util.List;

import org.apache.batik.dom.GenericDOMImplementation;
import org.apache.batik.svggen.SVGGeneratorContext;
import org.apache.batik.svggen.SVGGraphics2D;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jfree.chart.ChartRenderingInfo;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.block.RectangleConstraint;
import org.jfree.chart.entity.StandardEntityCollection;
import org.jfree.chart.title.LegendTitle;
import org.jfree.ui.RectangleEdge;
import org.w3c.dom.DOMImplementation;
import org.w3c.dom.Document;

import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGEncodeParam;
import com.sun.image.codec.jpeg.JPEGImageEncoder;

import de.laures.cewolf.CewolfException;
import de.laures.cewolf.ChartImage;
import de.laures.cewolf.ChartRenderingException;
import de.laures.cewolf.ConfigurationException;
import de.laures.cewolf.WebConstants;

/**
 * Renderer for ChartImageDefinitions.
 *
 * @author glaures
 * @author tbardzil
 * @see    de.laures.cewolf.ChartImage
 */
public class Renderer implements WebConstants {
	
	private final static Log log = LogFactory.getLog(Renderer.class);

	/** Creates a new instance of Renderer */
	private Renderer() {
	};

	/**
	 * Renders a chart image
	 *
	 * @param  cd                  the chart to render
	 * @return                     the rendered image
	 * @throws CewolfException
	 */
	public static RenderedImage render(ChartImage cd, Object chart) throws CewolfException {
		log.debug("rendering " + cd);
		switch (cd.getType()) {
			case ChartImage.IMG_TYPE_CHART :
				return renderChart(cd, chart);
			case ChartImage.IMG_TYPE_LEGEND :
				return renderLegend(cd, chart);
			default :
				throw new ConfigurationException(cd.getType() + " is not a supported image type");
		}
	}

	/**
	 * Renders a chart
	 * @param cd the chart image to be rendered
	 * @return the rendered image
	 * @throws CewolfException
	 */
	private static RenderedImage renderChart(ChartImage cd, Object chart) throws CewolfException {
		try {
			final ByteArrayOutputStream baos = new ByteArrayOutputStream();
			final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
			final String mimeType = cd.getMimeType();
			if (MIME_PNG.equals(mimeType)) {
				handlePNG(baos, (JFreeChart)chart, cd.getWidth(), cd.getHeight(), info);
			} else if (MIME_JPEG.equals(mimeType)) {
			    handleJPEG(baos, (JFreeChart)chart, cd.getWidth(), cd.getHeight(), info);
			} else if (MIME_SVG.equals(mimeType)) {
				handleSVG(baos, (JFreeChart)chart, cd.getWidth(), cd.getHeight());
			} else {
				throw new RenderingException("Mime type " + mimeType + " is unsupported.");
			}
			baos.close();
			return new RenderedImage(baos.toByteArray(), mimeType, info);
		} catch (IOException ioe) {
			log.error(ioe);
			throw new ChartRenderingException(ioe.getMessage(),ioe);
		}
	}

	/**
	 * Handles rendering a chart as a PNG. Currently this method is synchronized
	 * because of concurrency issues with JFreeChart.
	 *
	 * @param  baos
	 * @param  chart
	 * @param  width
	 * @param  height
	 * @param  info
	 * @throws IOException
	 */
	private static synchronized void handlePNG(
		ByteArrayOutputStream baos,
		JFreeChart chart,
		int width,
		int height,
		ChartRenderingInfo info)
		throws IOException {
		ChartUtilities.writeChartAsPNG(baos, chart, width, height, info);
	}
	
	/**
	 * Handles rendering a chart as a JPEG. Currently this method is synchronized
	 * because of concurrency issues with JFreeChart.
	 *
	 * @param  baos
	 * @param  chart
	 * @param  width
	 * @param  height
	 * @param  info
	 * @throws IOException
	 */
	private static synchronized void handleJPEG(
		ByteArrayOutputStream baos,
		JFreeChart chart,
		int width,
		int height,
		ChartRenderingInfo info)
		throws IOException {
		ChartUtilities.writeChartAsJPEG(baos, chart, width, height, info);
	}			

	/**
	 * Handles rendering a chart as a SVG. Currently this method is synchronized
	 * because of concurrency issues with JFreeChart.
	 *
	 * @param  baos
	 * @param  chart
	 * @param  width
	 * @param  height
	 * @throws IOException
	 */
	private static synchronized void handleSVG(ByteArrayOutputStream baos, JFreeChart chart, int width, int height)
		throws IOException {
		OutputStreamWriter writer = new OutputStreamWriter(baos, "UTF-8");
		DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation();
		Document document = domImpl.createDocument("cewolf-svg", "svg", null);
		SVGGeneratorContext ctx = SVGGeneratorContext.createDefault(document);
		ctx.setComment("Generated by Cewolf using JFreeChart and Apache Batik SVG Generator");
		SVGGraphics2D svgGenerator = new SVGGraphics2D(ctx, false);
		svgGenerator.setSVGCanvasSize(new Dimension(width, height));
		chart.draw(svgGenerator, new Rectangle2D.Double(0, 0, width, height), null);
		svgGenerator.stream(writer, false);
		writer.close();
	}

  //gets first legend in the list
  public static LegendTitle getLegend(JFreeChart chart)
  {
    //i need to find the legend now.
    LegendTitle legend = null;
    List subTitles = chart.getSubtitles();
    Iterator iter = subTitles.iterator();
    while (iter.hasNext())
    {
      Object o = iter.next();
      if (o instanceof LegendTitle)
      {
        legend = (LegendTitle) o;
        break;
      }
    }
    return legend;
  }
  
  //removes first legend in the list
  public static void removeLegend(JFreeChart chart)
  {
    List subTitles = chart.getSubtitles();
    Iterator iter = subTitles.iterator();
    while (iter.hasNext())
    {
      Object o = iter.next();
      if (o instanceof LegendTitle)
      {
        iter.remove();
        break;
      }
    }
  }
  
	/**
	 * Renders a legend
	 * @param cd the chart iamge to be rendred
	 * @return the rendered image
	 * @throws CewolfException
	 */
	private static RenderedImage renderLegend(ChartImage cd, Object c) throws CewolfException {
		try {
		    JFreeChart chart = (JFreeChart) c;
			final int width = cd.getWidth();
			final int height = cd.getHeight();
			LegendTitle legend = getLegend(chart);
			boolean haslegend = true;
			
			// with JFreeChart v0.9.20, the only way to get a valid legend,
			// is either to retrieve it from the chart or to assign a new
			// one to the chart. In the case where the chart has no legend,
			// a new one must be assigned, but just for rendering. After, we
			// have to reset the legend to null in the chart.
			if (null == legend) {
				haslegend = false;
				legend = new LegendTitle(chart.getPlot());   
			}
			legend.setPosition(RectangleEdge.BOTTOM);
			BufferedImage bimage = ImageHelper.createImage(width, height);
			Graphics2D g = bimage.createGraphics();
			g.setColor(Color.white);
			g.fillRect(0, 0, width, height);
			legend.arrange(g,new RectangleConstraint(width,height));
 			legend.draw(g, new Rectangle(width, height));
			ByteArrayOutputStream out = new ByteArrayOutputStream();
			JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
			JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(bimage);
			param.setQuality(1.0f, true);
			encoder.encode(bimage, param);
			out.close();

			// if the chart had no legend, reset it to null in order to give back the
			// chart in the state we received it.
			if (!haslegend) {
				removeLegend(chart);
			}
			
			return new RenderedImage(
				out.toByteArray(),
				"image/jpeg",
				new ChartRenderingInfo(new StandardEntityCollection()));
		} catch (IOException ioex) {
			log.error(ioex);
			throw new ChartRenderingException(ioex.getMessage(), ioex);
		}
	}

}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
色婷婷亚洲婷婷| 樱花草国产18久久久久| 国产精品久久久久9999吃药| 午夜天堂影视香蕉久久| 国产夫妻精品视频| 欧美精品自拍偷拍| 18成人在线观看| 国产精品白丝av| 欧美tickling挠脚心丨vk| 亚洲一区二区三区四区不卡| 国产aⅴ精品一区二区三区色成熟| 欧美在线色视频| 亚洲欧美另类图片小说| 国产成人高清视频| 久久综合久久久久88| 午夜精品久久久久久久久久| 99久久免费视频.com| 久久久精品黄色| 国内一区二区视频| 日韩你懂的在线观看| 青青草国产成人av片免费 | 亚洲精品va在线观看| 国产一区二区精品在线观看| 日韩一区二区三区av| 偷拍与自拍一区| 欧美曰成人黄网| 一区二区三区四区不卡在线 | 欧美成人激情免费网| 夜夜爽夜夜爽精品视频| 91视视频在线观看入口直接观看www | 天涯成人国产亚洲精品一区av| 成人精品视频一区| 中文字幕精品三区| 99re这里都是精品| 亚洲精品国产a久久久久久| 91在线观看一区二区| 日韩一区欧美一区| 在线观看欧美日本| 视频一区二区国产| 日韩久久久精品| 国内精品伊人久久久久av一坑| 欧美精品一区二区不卡| 黑人巨大精品欧美黑白配亚洲| 久久综合九色综合97婷婷 | 丁香婷婷综合激情五月色| 国产日韩欧美综合一区| 成人免费视频一区| 亚洲情趣在线观看| 欧美剧情电影在线观看完整版免费励志电影| 樱桃视频在线观看一区| 91麻豆精品国产91久久久久久久久| 视频在线观看一区| 久久婷婷国产综合精品青草| 国产大陆亚洲精品国产| 《视频一区视频二区| 欧美在线色视频| 久久精品国产99久久6| 中文文精品字幕一区二区| 91丨porny丨最新| 爽爽淫人综合网网站| 久久久精品欧美丰满| 色婷婷av久久久久久久| 天天色天天操综合| 中文av字幕一区| 欧美二区三区91| 成人午夜电影久久影院| 亚洲电影一级黄| 久久久久久久综合色一本| 在线欧美小视频| 国产精品99久久久久久久女警 | 日韩电影在线一区二区| 欧美高清一级片在线观看| 欧美系列在线观看| 国产另类ts人妖一区二区| 一区二区三区久久| 国产无遮挡一区二区三区毛片日本| 色综合天天综合狠狠| 另类小说视频一区二区| 日韩一区在线看| 精品国产乱码久久久久久老虎| av电影在线不卡| 欧美aaaaaa午夜精品| 亚洲三级在线看| 国产人成一区二区三区影院| 欧美视频中文字幕| 成人免费视频一区| 国产一区二区在线视频| 日欧美一区二区| 亚洲免费毛片网站| 国产午夜亚洲精品不卡| 欧美日韩dvd在线观看| 成人国产在线观看| 激情欧美一区二区三区在线观看| 亚洲精品成a人| 日韩一区有码在线| 中文av一区二区| 国产性天天综合网| 欧美精品一区二区精品网| 欧美日韩国产一二三| 91网上在线视频| 99精品一区二区三区| 成人激情av网| 国产suv精品一区二区6| 国产剧情一区二区| 久久不见久久见中文字幕免费| 婷婷成人综合网| 亚洲影院免费观看| 一区二区三区中文在线| 亚洲日本一区二区| 中文字幕一区二区5566日韩| 国产日韩综合av| 久久精品一二三| 国产人久久人人人人爽| 欧美激情综合五月色丁香小说| 久久久久亚洲蜜桃| 国产亚洲精久久久久久| 国产精品亲子乱子伦xxxx裸| 亚洲国产精品av| 亚洲欧洲精品天堂一级| 亚洲人成亚洲人成在线观看图片| 国产精品久久久久久久午夜片| 国产精品午夜在线| 亚洲日本韩国一区| 亚洲一区在线电影| 日韩精品一卡二卡三卡四卡无卡| 五月婷婷综合在线| 青娱乐精品在线视频| 另类专区欧美蜜桃臀第一页| 国产一区二区在线看| 成人免费视频播放| 色婷婷综合久色| 欧美人与性动xxxx| 精品久久五月天| 国产欧美一区二区精品仙草咪| 中日韩免费视频中文字幕| 综合婷婷亚洲小说| 日韩精品欧美精品| 国产精品 日产精品 欧美精品| 国产风韵犹存在线视精品| 色综合久久六月婷婷中文字幕| 欧美日韩一区二区在线视频| 91精品久久久久久久久99蜜臂| 久久久噜噜噜久久中文字幕色伊伊| 国产拍欧美日韩视频二区| 亚洲精品国产精华液| 美女视频黄 久久| av福利精品导航| 欧美精品在线一区二区三区| 久久久午夜精品理论片中文字幕| 国产精品国产精品国产专区不片| 亚洲一卡二卡三卡四卡五卡| 秋霞午夜鲁丝一区二区老狼| 不卡的电视剧免费网站有什么| 精品视频在线免费看| 国产色91在线| 日韩经典一区二区| 成人黄色网址在线观看| 在线成人av影院| 国产精品成人网| 免费一级欧美片在线观看| 成人av网站在线| 日韩三级伦理片妻子的秘密按摩| 日韩理论电影院| 国产精品18久久久久| 3d动漫精品啪啪一区二区竹菊| 欧美韩国日本不卡| 久久国产夜色精品鲁鲁99| 91精品1区2区| 国产精品人人做人人爽人人添| 美女在线视频一区| 在线精品视频一区二区| 欧美经典一区二区| 另类中文字幕网| 欧美精品 日韩| 一级女性全黄久久生活片免费| 成人免费福利片| 欧美精品一区二区三区蜜桃视频 | 久久久久久久久岛国免费| 香蕉成人啪国产精品视频综合网| 成熟亚洲日本毛茸茸凸凹| 欧美一区二区美女| 依依成人综合视频| 91网站视频在线观看| 国产午夜亚洲精品理论片色戒| 看电视剧不卡顿的网站| 这里只有精品视频在线观看| 亚洲视频免费观看| 成人高清视频在线观看| 久久亚洲二区三区| 久久99精品一区二区三区三区| 777午夜精品视频在线播放| 亚洲免费大片在线观看| 91亚洲精华国产精华精华液| 国产精品乱码久久久久久| 精品在线一区二区| 日韩久久久久久| 国产一区二区中文字幕| 久久青草欧美一区二区三区| 九一九一国产精品| 久久色在线视频|