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

📄 svgcanvas.java

📁 svg gwt 监控软件 大的 大 发了佛法ffffffffff发的司法
💻 JAVA
字号:
package com.mc.svg;

import java.io.Writer;
import org.apache.batik.dom.GenericDOMImplementation;
import org.apache.batik.svggen.SVGGraphics2D;
import org.apache.batik.svggen.SVGGraphics2DIOException;
import org.w3c.dom.DOMImplementation;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import com.mc.svg.menu.Defs;
import com.mc.svg.menu.PopupMenu;
import com.mc.svg.script.Function;
import com.mc.svg.script.LoadMenu;
import com.mc.svg.script.LocationURLFunction;
import com.mc.svg.script.OpenURLFunction;
import com.mc.svg.script.Script;
import com.mc.svg.shape.Shape;
import com.mc.svg.shape.basicshape.SVGPanel;

public class SVGCanvas {

	private DOMImplementation domImpl = null;

	public final static String svgNS = "http://www.w3.org/2000/svg";

	private Document document = null;

	private SVGPanel panel = null;

	private Defs defs = null;

	private Script script = null;

	private Function onloadFunction = null;

	//private boolean useCSS = false;

	//private boolean escaped = false;

	private Writer out = null;

	public SVGCanvas() {
		this(0, 0, 0, 0);
	}

	public SVGCanvas(int width, int lenght) {
		this(1, 1, width, lenght);
	}

	public SVGCanvas(int x, int y, int width, int length) {
		domImpl = GenericDOMImplementation.getDOMImplementation();

		document = domImpl.createDocument(svgNS, "svg", null);

		defs = new Defs(document);
		script = new Script(document);

		/*添加url函数*/
		addOpenURlFunction();
		addLocationURlFunction();

		panel = new SVGPanel(document);

		panel.addDefs(defs);

		onload();

		panel.setLocation(x, y);
		panel.setSize(width, length);

	}

	public void addOpenURlFunction() {
		OpenURLFunction url = new OpenURLFunction();
		script.addFuntion(url);
	}
	
	public void addLocationURlFunction() {
		LocationURLFunction url = new LocationURLFunction();
		script.addFuntion(url);
	}

	public void clear() {

	}

	public void removeShape(Shape shape) {
		removeShape(shape.getId());
	}

	public void removeShape(String id) {
		Element a = document.getElementById(id);
		try {
			document.getDocumentElement().removeChild(a);
		} catch (Exception ex) {

		}

	}

	public void addShape(Shape shape) {

		panel.add(shape);
	}

	public void setOutPut(Writer out) {
		this.out = out;
	}

	public void exportSVG() throws SVGGraphics2DIOException {

		panel.addScript(script);
		SVGGraphics2D svgGraphics = new SVGGraphics2D(document);
		if (out != null) {
			svgGraphics.stream(document.getDocumentElement(), out);
		} else {
			//TODO
		}

	}

	public void onload() {
		String functionName = "onload";

		panel.onLoad(functionName);

		if (onloadFunction == null) {
			onloadFunction = new Function(functionName);
			script.addFuntion(onloadFunction);
		}
	}

	public void addPopupMenu(PopupMenu menu) {
		defs.addPopupMenu(menu);
		
		Function loadMenu = script.findFunction("loadMenu");
		if(loadMenu == null){
			loadMenu = new LoadMenu();
			script.addFuntion(loadMenu);
		}
		
	}

	public void loadPopupMenu(String id) {

		String dses = Function.functionDispose("loadMenu", "'" + id + "'");
		onloadFunction.addContent(dses);
	}

	public Document getDocument() {
		return document;
	}

	public void setDocument(Document document) {
		this.document = document;
	}

	public Script getScript() {
		return script;
	}

	public void setScript(Script script) {
		this.script = script;
	}

}

⌨️ 快捷键说明

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