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

📄 mxvmlcanvas.java

📁 经典的java图像处理程序源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/** * $Id: mxVmlCanvas.java,v 1.38 2008/11/25 17:32:52 gaudenz Exp $ * Copyright (c) 2007, Gaudenz Alder */package com.mxgraph.canvas;import java.awt.Rectangle;import java.util.Hashtable;import java.util.List;import org.w3c.dom.Document;import org.w3c.dom.Element;import org.w3c.dom.Node;import com.mxgraph.util.mxConstants;import com.mxgraph.util.mxPoint;import com.mxgraph.util.mxUtils;/** * An implementation of a canvas that uses VML for painting. */public class mxVmlCanvas extends mxBasicCanvas{	/**	 * Holds the HTML document that represents the canvas.	 */	protected Document document;	/**	 * Constructs a new VML canvas for the specified dimension and scale.	 * 	 * @param width Width of the canvas to be constructed.	 * @param height Height of the canvas to be constructed.	 * @param scale Scale of the canvas to be constructed.	 */	public mxVmlCanvas()	{		this(null);	}	/**	 * Constructs a new VML canvas for the specified bounds, scale and	 * background color.	 * 	 * @param x X-coordinate of the origin of the canvas.	 * @param y Y-coordinate of the origin of the canvas.	 * @param width Width of the canvas to be constructed.	 * @param height Height of the canvas to be constructed.	 * @param scale Scale of the canvas to be constructed.	 * @param backgroundColor Color of the background. Default is null	 * (transparent).	 */	public mxVmlCanvas(Document document)	{		setDocument(document);	}	/**	 * 	 */	public void setDocument(Document document)	{		this.document = document;	}		/**	 * Returns a reference to the document that represents the canvas.	 * 	 * @return Returns the document.	 */	public Document getDocument()	{		return document;	}		/**	 * 	 */	public void appendVmlElement(Element node)	{		if (document != null)		{			Node body = document.getDocumentElement().getFirstChild().getNextSibling();						if (body != null)			{				body.appendChild(node);			}		}			}	/* (non-Javadoc)	 * @see com.mxgraph.canvas.mxICanvas#drawVertex(java.lang.String, int, int, int, int, mxPoint, java.util.Hashtable)	 */	public Object drawVertex(int x, int y, int w, int h, Hashtable style)	{		Element elem = null;		int start = mxUtils.getInt(style, mxConstants.STYLE_STARTSIZE);		x += translate.x;		y += translate.y;		if (start == 0)		{			elem = drawShape(x, y, w, h, style);		}		else		{			start = (int) Math.round(start * scale);			// Removes some styles to draw the content area			Hashtable cloned = new Hashtable(style);			cloned.remove(mxConstants.STYLE_FILLCOLOR);			cloned.remove(mxConstants.STYLE_ROUNDED);			if (mxUtils.isTrue(style, mxConstants.STYLE_HORIZONTAL, true))			{				elem = drawShape(x, y, w, start, style);				drawShape(x, y + start, w, h - start, cloned);			}			else			{				elem = drawShape(x, y, start, h, style);				drawShape(x + start, y, w - start, h, cloned);			}		}		return elem;	}	/* (non-Javadoc)	 * @see com.mxgraph.canvas.mxICanvas#drawEdge(java.lang.String, java.util.List, com.mxgraph.utils.mxPoint, java.util.Hashtable)	 */	public Object drawEdge(List pts, Hashtable style)	{		// Transpose all points by cloning into a new array		pts = mxUtils.translatePoints(pts, translate.x, translate.y);		// Draws the line		Element elem = drawLine(pts, style);		// Draws the markers		String start = mxUtils.getString(style, mxConstants.STYLE_STARTARROW);		String end = mxUtils.getString(style, mxConstants.STYLE_ENDARROW);		if (start != null || end != null)		{			Element strokeNode = document.createElement("v:stroke");			if (start != null)			{				strokeNode.setAttribute("startarrow", start);				String startWidth = "medium";				String startLength = "medium";				double startSize = mxUtils.getFloat(style,						mxConstants.STYLE_STARTSIZE,						mxConstants.DEFAULT_MARKERSIZE)						* scale;				if (startSize < 6)				{					startWidth = "narrow";					startLength = "short";				}				else if (startSize > 10)				{					startWidth = "wide";					startLength = "long";				}				strokeNode.setAttribute("startarrowwidth", startWidth);				strokeNode.setAttribute("startarrowlength", startLength);			}			if (end != null)			{				strokeNode.setAttribute("endarrow", end);				String endWidth = "medium";				String endLength = "medium";				double endSize = mxUtils.getFloat(style,						mxConstants.STYLE_ENDSIZE,						mxConstants.DEFAULT_MARKERSIZE)						* scale;				if (endSize < 6)				{					endWidth = "narrow";					endLength = "short";				}				else if (endSize > 10)				{					endWidth = "wide";					endLength = "long";				}				strokeNode.setAttribute("endarrowwidth", endWidth);				strokeNode.setAttribute("endarrowlength", endLength);			}			elem.appendChild(strokeNode);		}		return elem;	}	/*	 * (non-Javadoc)	 * @see com.mxgraph.canvas.mxICanvas#drawLabel(java.lang.String, int, int, int, int, java.util.Hashtable, boolean)	 */	public Object drawLabel(String label, int x, int y, int w, int h,			Hashtable style, boolean isHtml)	{		if (drawLabels)		{			x += translate.x;			y += translate.y;			return drawText(label, x, y, w, h, style);		}		return null;	}	/**	 * Draws the shape specified with the STYLE_SHAPE key in the given style.	 * 	 * @param x X-coordinate of the shape.	 * @param y Y-coordinate of the shape.	 * @param w Width of the shape.	 * @param h Height of the shape.	 * @param style Style of the the shape.	 */	public Element drawShape(int x, int y, int w, int h, Hashtable style)	{		String fillColor = mxUtils				.getString(style, mxConstants.STYLE_FILLCOLOR);		String gradientColor = mxUtils.getString(style,				mxConstants.STYLE_GRADIENTCOLOR);		String strokeColor = mxUtils.getString(style,				mxConstants.STYLE_STROKECOLOR);		float strokeWidth = (float) (mxUtils.getFloat(style,				mxConstants.STYLE_STROKEWIDTH, 1) * scale);		// Draws the shape		String shape = mxUtils.getString(style, mxConstants.STYLE_SHAPE);		Element elem = null;		if (shape.equals(mxConstants.SHAPE_IMAGE))		{			String img = getImageForStyle(style);			if (img != null)			{				elem = document.createElement("v:img");				elem.setAttribute("src", img);			}		}		else if (shape.equals(mxConstants.SHAPE_LINE))		{			String direction = mxUtils.getString(style,					mxConstants.STYLE_DIRECTION, mxConstants.DIRECTION_EAST);			String points = null;			if (direction.equals(mxConstants.DIRECTION_EAST)					|| direction.equals(mxConstants.DIRECTION_WEST))			{				int mid = (int) Math.round(h / 2);				points = "m 0 " + mid + " l " + w + " " + mid;			}			else			{				int mid = (int) Math.round(w / 2);				points = "m " + mid + " 0 L " + mid + " " + h;			}			elem = document.createElement("v:shape");			elem.setAttribute("coordsize", w + " " + h);			elem.setAttribute("path", points + " x e");		}		else if (shape.equals(mxConstants.SHAPE_ELLIPSE))		{			elem = document.createElement("v:oval");		}		else if (shape.equals(mxConstants.SHAPE_DOUBLE_ELLIPSE))		{			elem = document.createElement("v:shape");			elem.setAttribute("coordsize", w + " " + h);

⌨️ 快捷键说明

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