⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mxgraphviewimagereader.java

📁 经典的java图像处理程序源码
💻 JAVA
字号:
/** * $Id: mxGraphViewImageReader.java,v 1.4 2009/04/12 09:50:16 gaudenz Exp $ * Copyright (c) 2007, Gaudenz Alder */package com.mxgraph.reader;import java.awt.Color;import java.awt.image.BufferedImage;import java.io.FileInputStream;import java.io.IOException;import java.util.Hashtable;import javax.xml.parsers.ParserConfigurationException;import javax.xml.parsers.SAXParser;import javax.xml.parsers.SAXParserFactory;import org.xml.sax.InputSource;import org.xml.sax.SAXException;import org.xml.sax.XMLReader;import com.mxgraph.canvas.mxGraphics2DCanvas;import com.mxgraph.canvas.mxICanvas;import com.mxgraph.canvas.mxImageCanvas;import com.mxgraph.util.mxRectangle;import com.mxgraph.util.mxUtils;/** * A converter that renders display XML data onto a graphics canvas. */public class mxGraphViewImageReader extends mxGraphViewReader{	/**	 * Specifies the background color. Default is null.	 */	protected Color background;	/**	 * Specifies if the image should be anti-aliased. Default is true.	 */	protected boolean antiAlias;	/**	 * Specifies the border which is added to the size of the graph. Default is	 * 0.	 */	protected int border;	/**	 * Specifies the border which is added to the size of the graph. Default is	 * true.	 */	protected boolean cropping;	/**	 * Defines the clip to be drawn. Default is null.	 */	protected mxRectangle clip;	/**	 * Constructs a new reader with a transparent background.	 */	public mxGraphViewImageReader()	{		this(null);	}	/**	 * Constructs a new reader with the given background color.	 */	public mxGraphViewImageReader(Color background)	{		this(background, 0);	}	/**	 * Constructs a new reader with a transparent background.	 */	public mxGraphViewImageReader(Color background, int border)	{		this(background, border, true);	}	/**	 * Constructs a new reader with a transparent background.	 */	public mxGraphViewImageReader(Color background, int border,			boolean antiAlias)	{		this(background, border, antiAlias, true);	}	/**	 * Constructs a new reader with a transparent background.	 */	public mxGraphViewImageReader(Color background, int border,			boolean antiAlias, boolean cropping)	{		setBackground(background);		setBorder(border);		setAntiAlias(antiAlias);		setCropping(cropping);	}	/**	 * 	 */	public Color getBackground()	{		return background;	}	/**	 * 	 */	public void setBackground(Color background)	{		this.background = background;	}	/**	 * 	 */	public int getBorder()	{		return border;	}	/**	 * 	 */	public void setBorder(int border)	{		this.border = border;	}	/**	 * 	 */	public boolean isAntiAlias()	{		return antiAlias;	}	/**	 * 	 */	public void setAntiAlias(boolean antiAlias)	{		this.antiAlias = antiAlias;	}	/**	 * Specifies the optional clipping rectangle.	 */	public boolean isCropping()	{		return cropping;	}	/**	 * 	 */	public void setCropping(boolean value)	{		this.cropping = value;	}	/**	 * 	 */	public mxRectangle getClip()	{		return clip;	}	/**	 * 	 */	public void setClip(mxRectangle value)	{		this.clip = value;	}	/*	 * (non-Javadoc)	 * 	 * @see	 * com.mxgraph.reader.mxGraphViewReader#createCanvas(java.util.Hashtable)	 */	public mxICanvas createCanvas(Hashtable attrs)	{		int width = 0;		int height = 0;		int dx = 0;		int dy = 0;				mxRectangle tmp = getClip();		if (tmp != null)		{			dx -= (int) tmp.getX();			dy -= (int) tmp.getY();			width = (int) tmp.getWidth();			height = (int) tmp.getHeight();		}		else		{			int x = (int) Math.round(mxUtils.getDouble(attrs, "x"));			int y = (int) Math.round(mxUtils.getDouble(attrs, "y"));			width = (int) (Math.round(mxUtils.getDouble(attrs, "width")))					+ border + 3;			height = (int) (Math.round(mxUtils.getDouble(attrs, "height")))					+ border + 3;			if (isCropping())			{				dx = -x + 3;				dy = -y + 3;			}			else			{				width += x;				height += y;			}		}		mxImageCanvas canvas = new mxImageCanvas(new mxGraphics2DCanvas(),				width, height, getBackground(), isAntiAlias());		canvas.setTranslate(dx, dy);		return canvas;	}	/**	 * Creates the image for the given display XML file. (Note: The XML file is	 * an encoded mxGraphView, not mxGraphModel.)	 * 	 * @param filename	 *            Filename of the display XML file.	 * @return Returns an image representing the display XML file.	 */	public static BufferedImage convert(String filename,			mxGraphViewImageReader viewReader)			throws ParserConfigurationException, SAXException, IOException	{		return convert(new InputSource(new FileInputStream(filename)),				viewReader);	}	/**	 * Creates the image for the given display XML input source. (Note: The XML	 * is an encoded mxGraphView, not mxGraphModel.)	 * 	 * @param inputSource	 *            Input source that contains the display XML.	 * @return Returns an image representing the display XML input source.	 */	public static BufferedImage convert(InputSource inputSource,			mxGraphViewImageReader viewReader)			throws ParserConfigurationException, SAXException, IOException	{		BufferedImage result = null;		SAXParser parser = SAXParserFactory.newInstance().newSAXParser();		XMLReader reader = parser.getXMLReader();		reader.setContentHandler(viewReader);		reader.parse(inputSource);		if (viewReader.getCanvas() instanceof mxImageCanvas)		{			return ((mxImageCanvas) viewReader.getCanvas()).destroy();		}		return null;	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -