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

📄 mxgraph.java

📁 经典的java图像处理程序源码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/** * $Id: mxGraph.java,v 1.228 2009/05/06 07:11:22 gaudenz Exp $ * Copyright (c) 2007, Gaudenz Alder */package com.mxgraph.view;import java.awt.Graphics;import java.awt.Point;import java.awt.Rectangle;import java.awt.Shape;import java.beans.PropertyChangeListener;import java.beans.PropertyChangeSupport;import java.util.ArrayList;import java.util.Arrays;import java.util.Collection;import java.util.HashSet;import java.util.Hashtable;import java.util.Iterator;import java.util.LinkedHashSet;import java.util.List;import java.util.Set;import org.w3c.dom.Element;import com.mxgraph.canvas.mxGraphics2DCanvas;import com.mxgraph.canvas.mxICanvas;import com.mxgraph.canvas.mxImageCanvas;import com.mxgraph.model.mxCell;import com.mxgraph.model.mxGeometry;import com.mxgraph.model.mxGraphModel;import com.mxgraph.model.mxICell;import com.mxgraph.model.mxIGraphModel;import com.mxgraph.model.mxGraphModel.Filter;import com.mxgraph.model.mxGraphModel.mxChildChange;import com.mxgraph.model.mxGraphModel.mxCollapseChange;import com.mxgraph.model.mxGraphModel.mxGeometryChange;import com.mxgraph.model.mxGraphModel.mxRootChange;import com.mxgraph.model.mxGraphModel.mxStyleChange;import com.mxgraph.model.mxGraphModel.mxTerminalChange;import com.mxgraph.model.mxGraphModel.mxValueChange;import com.mxgraph.model.mxGraphModel.mxVisibleChange;import com.mxgraph.util.mxConstants;import com.mxgraph.util.mxEvent;import com.mxgraph.util.mxEventObject;import com.mxgraph.util.mxEventSource;import com.mxgraph.util.mxImage;import com.mxgraph.util.mxPoint;import com.mxgraph.util.mxRectangle;import com.mxgraph.util.mxResources;import com.mxgraph.util.mxUtils;/** * Implements a graph object that allows to create diagrams from a graph model * and stylesheet. *  * <h3>Images</h3> * To create an image from a graph, use the following code for a given * XML document (doc) and File (file): *  * <code> * Image img = mxCellRenderer.createBufferedImage( * 		graph, null, 1, Color.WHITE, false, null); * ImageIO.write(img, "png", file); * </code> *  * If the XML is given as a string rather than a document, the document can * be obtained using mxUtils.parse. */public class mxGraph extends mxEventSource{	/**	 * Adds required resources.	 */	static	{		mxResources.add("com.mxgraph.resources.graph");	}	/**	 * Holds the version number of this release. Current version	 * is 0.99.0.7.	 */	public static final String VERSION = "0.99.0.7";	/**	 * 	 */	public interface mxICellVisitor	{		/**		 * 		 * @param vertex		 * @param edge		 */		boolean visit(Object vertex, Object edge);	}	/**	 * Property change event handling.	 */	protected PropertyChangeSupport changeSupport = new PropertyChangeSupport(			this);	/**	 * Holds the model that contains the cells to be displayed.	 */	protected mxIGraphModel model;	/**	 * Holds the view that caches the cell states.	 */	protected mxGraphView view;	/**	 * Holds the stylesheet that defines the appearance of the cells.	 */	protected mxStylesheet stylesheet;	/**	 * Holds the <mxGraphSelection> that models the current selection.	 */	protected mxGraphSelectionModel selectionModel;	/**	 * Specifies the grid size. Default is 10.	 */	protected int gridSize = 10;	/**	 * Specifies if the grid is enabled. Default is true.	 */	protected boolean gridEnabled = true;	/**	 * Value returned by getOverlap if isAllowOverlapParent returns	 * true for the given cell. getOverlap is used in keepInside if	 * isKeepInsideParentOnMove returns true. The value specifies the	 * portion of the child which is allowed to overlap the parent.	 */	protected double defaultOverlap = 0.5;	/**	 * Specifies the default parent to be used to insert new cells.	 * This is used in getDefaultParent. Default is null.	 */	protected Object defaultParent;	/**	 * Specifies the alternate edge style to be used if the main control point	 * on an edge is being doubleclicked. Default is null.	 */	protected String alternateEdgeStyle;	/**	 * Specifies the return value for isEnabled. Default is true.	 */	protected boolean enabled = true;	/**	 * Specifies the return value for isCell(s)Locked. Default is false.	 */	protected boolean cellsLocked = false;	/**	 * Specifies the return value for isCell(s)Editable. Default is true.	 */	protected boolean cellsEditable = true;	/**	 * Specifies the return value for isCell(s)Sizable. Default is true.	 */	protected boolean cellsResizable = true;	/**	 * Specifies the return value for isCell(s)Movable. Default is true.	 */	protected boolean cellsMovable = true;	/**	 * Specifies the return value for isCell(s)Bendable. Default is true.	 */	protected boolean cellsBendable = true;	/**	 * Specifies the return value for isCell(s)Selectable. Default is true.	 */	protected boolean cellsSelectable = true;	/**	 * Specifies the return value for isCell(s)Deletable. Default is true.	 */	protected boolean cellsDeletable = true;	/**	 * Specifies the return value for isCell(s)Cloneable. Default is true.	 */	protected boolean cellsCloneable = true;	/**	 * Specifies the return value for isCellDisconntableFromTerminal. Default	 * is true.	 */	protected boolean cellsDisconnectable = true;	/**	 * Specifies the return value for isLabel(s)Clipped. Default is false.	 */	protected boolean labelsClipped = false;	/**	 * Specifies the return value for edges in isLabelMovable. Default is true.	 */	protected boolean edgeLabelsMovable = true;	/**	 * Specifies the return value for vertices in isLabelMovable. Default is false.	 */	protected boolean vertexLabelsMovable = false;	/**	 * Specifies the return value for isDropEnabled. Default is true.	 */	protected boolean dropEnabled = true;	/**	 * Specifies if dropping onto edges should be enabled. Default is true.	 */	protected boolean splitEnabled = true;	/**	 * Specifies if the graph should automatically update the cell size	 * after an edit. This is used in isAutoSizeCell. Default is false.	 */	protected boolean autoSizeCells = false;	/**	 * <mxRectangle> that specifies the area in which all cells in the	 * diagram should be placed. Uses in getMaximumGraphBounds. Use a width	 * or height of 0 if you only want to give a upper, left corner.	 */	protected mxRectangle maximumGraphBounds = null;	/**	 * mxRectangle that specifies the minimum size of the graph canvas inside	 * the scrollpane.	 */	protected mxRectangle minimumGraphSize = null;	/**	 * Border to be added to the bottom and right side when the container is	 * being resized after the graph has been changed. Default is 0.	 */	protected int border = 0;	/**	 * Specifies if edges should appear in the foreground regardless of their	 * order in the model. This has precendence over keepEdgeInBackground	 * Default is false.	 */	protected boolean keepEdgesInForeground = false;	/**	 * Specifies if edges should appear in the background regardless of their	 * order in the model. Default is false.	 */	protected boolean keepEdgesInBackground = false;	/**	 * Specifies if the cell size should be changed to the preferred size when	 * a cell is first collapsed. Default is true.	 */	protected boolean collapseToPreferredSize = true;	/**	 * Specifies the return value for isConstrainChildren. Default is true.	 */	protected boolean constrainChildren = true;	/**	 * Specifies if a parent should contain the child bounds after a resize of	 * the child. Default is true.	 */	protected boolean extendParents = true;	/**	 * Specifies if parents should be extended according to the <extendParents>	 * switch if cells are added. Default is true.	 */	protected boolean extendParentsOnAdd = true;	/**	 * Specifies if loops (aka self-references) are allowed.	 * Default is false.	 */	protected boolean resetEdgesOnResize = false;	/**	 * Specifies if edge control points should be reset after	 * the move of a connected cell. Default is false.	 */	protected boolean resetEdgesOnMove = false;	/**	 * Specifies if edge control points should be reset after	 * the the edge has been reconnected. Default is true.	 */	protected boolean resetEdgesOnConnect = true;	/**	 * Specifies if loops (aka self-references) are allowed.	 * Default is false.	 */	protected boolean allowLoops = false;	/**	 * Specifies the multiplicities to be used for validation of the graph.	 */	protected mxMultiplicity[] multiplicities;	/**	 * Specifies the default style for loops.	 */	protected mxEdgeStyle.mxEdgeStyleFunction defaultLoopStyle = mxEdgeStyle.Loop;	/**	 * Specifies if multiple edges in the same direction between	 * the same pair of vertices are allowed. Default is true.	 */	protected boolean multigraph = true;	/**	 * Specifies if edges are connectable. Default is false.	 * This overrides the connectable field in edges.	 */	protected boolean connectableEdges = false;	/**	 * Specifies if edges with disconnected terminals are	 * allowed in the graph. Default is false.	 */	protected boolean allowDanglingEdges = true;	/**	 * Specifies if edges that are cloned should be validated and only inserted	 * if they are valid. Default is true.	 */	protected boolean cloneInvalidEdges = false;	/**	 * Specifies if edges should be disconnected from their terminals when they	 * are moved. Default is true.	 */	protected boolean disconnectOnMove = true;	/**	 * Specifies if labels should be visible. This is used in	 * getLabel. Default is true.	 */	protected boolean labelsVisible = true;	/**	 * Specifies the return value for isHtmlLabel. Default is false.	 */	protected boolean htmlLabels = false;	/**	 * Specifies if nesting of swimlanes is allowed. Default is true.	 */	protected boolean swimlaneNesting = true;	/**	 * Specifies the mxImage to indicate a collapsed state.	 * Default value is mxClient.imageBasePath+'collapsed.gif'	 */	protected mxImage collapsedImage;	/**	 * Specifies the mxImage to indicate a expanded state.	 * Default value is mxClient.imageBasePath+'expanded.gif'	 */	protected mxImage expandedImage;	/**	 * Specifies the mxImage for the image to be used to	 * display a warning overlay. See setWarning. Default value is	 * mxClient.imageBasePath+'warning'	 */	protected mxImage warningImage;	/**	 * Fires repaint events for full repaints.	 */	protected mxIEventListener fullRepaintHandler = new mxIEventListener()	{		public void invoke(Object sender, mxEventObject evt)		{			fireEvent(mxEvent.REPAINT);		}	};	/**	 * Fires repaint events for full repaints.	 */	protected mxIEventListener invalidateAndRepaintHandler = new mxIEventListener()	{		public void invoke(Object sender, mxEventObject evt)		{			view.invalidate();			fireEvent(mxEvent.REPAINT);		}	};	/**	 * Fires repaint events for model changes.	 */	protected mxIEventListener graphModelChangeHandler = new mxIEventListener()	{		public void invoke(Object sender, mxEventObject evt)		{			mxRectangle dirty = graphModelChanged((mxIGraphModel) sender,					(List) evt.getArgAt(0));			fireEvent(mxEvent.REPAINT,					new mxEventObject(new Object[] { dirty }));		}	};	/**	 * Constructs a new graph with an empty	 * {@link com.mxgraph.model.mxGraphModel}.	 */	public mxGraph()	{		this(null, null);	}	/**	 * Constructs a new graph for the specified model. If no model is	 * specified, then a new, empty {@link com.mxgraph.model.mxGraphModel} is	 * used.	 * 	 * @param model Model that contains the graph data	 */	public mxGraph(mxIGraphModel model)	{		this(model, null);	}	/**	 * Constructs a new graph for the specified model. If no model is	 * specified, then a new, empty {@link com.mxgraph.model.mxGraphModel} is	 * used.	 * 	 * @param stylesheet The stylesheet to use for the graph.	 */	public mxGraph(mxStylesheet stylesheet)	{		this(null, stylesheet);	}	/**	 * Constructs a new graph for the specified model. If no model is	 * specified, then a new, empty {@link com.mxgraph.model.mxGraphModel} is	 * used.	 * 	 * @param model Model that contains the graph data	 */	public mxGraph(mxIGraphModel model, mxStylesheet stylesheet)	{		selectionModel = createSelectionModel();		setModel((model != null) ? model : new mxGraphModel());		setStylesheet((stylesheet != null) ? stylesheet : createStylesheet());		setView(createGraphView());	}	/**	 * Constructs a new selection model to be used in this graph.	 */	protected mxGraphSelectionModel createSelectionModel()	{		return new mxGraphSelectionModel(this);	}	/**	 * Constructs a new stylesheet to be used in this graph.	 */	protected mxStylesheet createStylesheet()	{		return new mxStylesheet();	}	/**	 * Constructs a new view to be used in this graph.	 */	protected mxGraphView createGraphView()	{		return new mxGraphView(this);	}	/**	 * Returns the graph model that contains the graph data.	 * 	 * @return Returns the model that contains the graph data	 */	public mxIGraphModel getModel()	{		return model;	}

⌨️ 快捷键说明

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