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

📄 mxgraph.java

📁 经典的java图像处理程序源码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
	 * 	 * @param cells Array of cells to be inserted.	 * @param parent Object that represents the new parent. If no parent is	 * given then the default parent is used.	 * @return Returns the cell that was added.	 */	public Object addCell(Object cell, Object parent)	{		return addCell(cell, parent, null, null, null);	}	/**	 * Adds the cell to the parent and connects it to the given source and	 * target terminals. This is a shortcut method.	 * 	 * @param cell Cell to be inserted into the given parent.	 * @param parent Object that represents the new parent. If no parent is	 * given then the default parent is used.	 * @param index Optional index to insert the cells at. Default is to append.	 * @param source Optional cell that represents the source terminal.	 * @param target Optional cell that represents the target terminal.	 * @return Returns the cell that was added.	 */	public Object addCell(Object cell, Object parent, Integer index,			Object source, Object target)	{		return addCells(new Object[] { cell }, parent, index, source, target)[0];	}	/**	 * Adds the cells to the default parent. This is a shortcut method.	 * 	 * @param cells Array of cells to be inserted.	 * @return Returns the cells that were added.	 */	public Object[] addCells(Object[] cells)	{		return addCells(cells, null);	}	/**	 * Adds the cells to the parent. This is a shortcut method.	 * 	 * @param cells Array of cells to be inserted.	 * @param parent Optional cell that represents the new parent. If no parent	 * is specified then the default parent is used.	 * @return Returns the cells that were added.	 */	public Object[] addCells(Object[] cells, Object parent)	{		return addCells(cells, parent, null);	}	/**	 * Adds the cells to the parent at the given index. This is a shortcut method.	 * 	 * @param cells Array of cells to be inserted.	 * @param parent Optional cell that represents the new parent. If no parent	 * is specified then the default parent is used.	 * @param index Optional index to insert the cells at. Default is to append.	 * @return Returns the cells that were added.	 */	public Object[] addCells(Object[] cells, Object parent, Integer index)	{		return addCells(cells, parent, index, null, null);	}	/**	 * Adds the cells to the parent at the given index, connecting each cell to	 * the optional source and target terminal. The change is carried out using	 * cellsAdded. This method fires mxEvent.ADD_CELLS while the transaction	 * is in progress.	 * 	 * @param cells Array of cells to be added.	 * @param parent Optional cell that represents the new parent. If no parent	 * is specified then the default parent is used.	 * @param index Optional index to insert the cells at. Default is to append.	 * @param source Optional source terminal for all inserted cells.	 * @param target Optional target terminal for all inserted cells.	 * @return Returns the cells that were added.	 */	public Object[] addCells(Object[] cells, Object parent, Integer index,			Object source, Object target)	{		if (parent == null)		{			parent = getDefaultParent();		}		if (index == null)		{			index = model.getChildCount(parent);		}		model.beginUpdate();		try		{			cellsAdded(cells, parent, index, source, target, false);			fireEvent(mxEvent.ADD_CELLS, new mxEventObject(new Object[] {					cells, parent, index, source, target }));		}		finally		{			model.endUpdate();		}		return cells;	}	/**	 * Adds the specified cells to the given parent. This method fires	 * mxEvent.CELLS_ADDED while the transaction is in progress.	 */	public void cellsAdded(Object[] cells, Object parent, Integer index,			Object source, Object target, boolean absolute)	{		if (cells != null && parent != null && index != null)		{			model.beginUpdate();			try			{				mxCellState parentState = (absolute) ? view.getState(parent)						: null;				mxPoint o1 = (parentState != null) ? parentState.getOrigin()						: null;				mxPoint zero = new mxPoint(0, 0);				for (int i = 0; i < cells.length; i++)				{					Object previous = model.getParent(cells[i]);					// Keeps the cell at its absolute location					if (o1 != null && cells[i] != parent && parent != previous)					{						mxCellState oldState = view.getState(previous);						mxPoint o2 = (oldState != null) ? oldState.getOrigin()								: zero;						mxGeometry geo = model.getGeometry(cells[i]);						if (geo != null)						{							double dx = o2.getX() - o1.getX();							double dy = o2.getY() - o1.getY();							model.setGeometry(cells[i], geo.translate(dx, dy));						}					}					// Decrements all following indices					// if cell is already in parent					if (parent == previous)					{						index--;					}					model.add(parent, cells[i], index + i);					// Extends the parent					if (isExtendParentsOnAdd() && isExtendParent(cells[i]))					{						extendParent(cells[i]);					}					// Constrains the child					constrainChild(cells[i]);					// Sets the source terminal					if (source != null)					{						model.setTerminal(cells[i], source, true);					}					// Sets the target terminal					if (target != null)					{						model.setTerminal(cells[i], target, false);					}				}				fireEvent(mxEvent.CELLS_ADDED, new mxEventObject(new Object[] {						cells, parent, index, source, target, absolute }));			}			finally			{				model.endUpdate();			}		}	}	/**	 * Removes the selection cells from the graph.	 * 	 * @return Returns the cells that have been removed.	 */	public Object[] removeCells()	{		return removeCells(null);	}	/**	 * Removes the given cells from the graph.	 * 	 * @param cells Array of cells to remove.	 * @return Returns the cells that have been removed.	 */	public Object[] removeCells(Object[] cells)	{		return removeCells(cells, true);	}	/**	 * Removes the given cells from the graph including all connected edges if	 * includeEdges is true. The change is carried out using cellsRemoved. This	 * method fires mxEvent.REMOVE_CELLS while the transaction is in progress.	 * 	 * @param cells Array of cells to remove. If null is specified then the	 * selection cells which are deletable are used.	 * @param includeEdges Specifies if all connected edges should be removed as	 * well.	 */	public Object[] removeCells(Object[] cells, boolean includeEdges)	{		if (cells == null)		{			cells = getDeletableCells(getSelectionCells());		}		// Adds all edges to the cells		if (includeEdges)		{			cells = getDeletableCells(addAllEdges(cells));		}		model.beginUpdate();		try		{			cellsRemoved(cells);			fireEvent(mxEvent.REMOVE_CELLS, new mxEventObject(new Object[] {					cells, includeEdges }));		}		finally		{			model.endUpdate();		}		return cells;	}	/**	 * Removes the given cells from the model. This method fires	 * mxEvent.CELLS_REMOVED while the transaction is in progress.	 * 	 * @param cells Array of cells to remove.	 */	public void cellsRemoved(Object[] cells)	{		if (cells != null && cells.length > 0)		{			double scale = view.getScale();			mxPoint tr = view.getTranslate();			model.beginUpdate();			try			{				for (int i = 0; i < cells.length; i++)				{					// Disconnects edges which are not in cells					Collection cellSet = new HashSet();					cellSet.addAll(Arrays.asList(cells));					Object[] edges = getConnections(cells[i]);					for (int j = 0; j < edges.length; j++)					{						if (!cellSet.contains(edges[j]))						{							mxGeometry geo = model.getGeometry(edges[j]);							if (geo != null)							{								mxCellState state = view.getState(edges[j]);								if (state != null)								{									geo = (mxGeometry) geo.clone();									boolean source = view.getVisibleTerminal(											edges[j], true) == cells[i];									int n = (source) ? 0 : state											.getAbsolutePointCount() - 1;									mxPoint pt = state.getAbsolutePoint(n);									geo.setTerminalPoint(new mxPoint(pt.getX()											/ scale - tr.getX(), pt.getY()											/ scale - tr.getY()), source);									model.setTerminal(edges[j], null, source);									model.setGeometry(edges[j], geo);								}							}						}					}					model.remove(cells[i]);				}				fireEvent(mxEvent.CELLS_REMOVED, new mxEventObject(						new Object[] { cells }));			}			finally			{				model.endUpdate();			}		}	}	/**	 * 	 */	public Object splitEdge(Object edge, Object[] cells)	{		return splitEdge(edge, cells, null, 0, 0);	}	/**	 * 	 */	public Object splitEdge(Object edge, Object[] cells, double dx, double dy)	{		return splitEdge(edge, cells, null, dx, dy);	}	/**	 * Splits the given edge by adding a newEdge between the previous source	 * and the given cell and reconnecting the source of the given edge to the	 * given cell. Fires mxEvent.SPLIT_EDGE while the transaction is in	 * progress.	 * 	 * @param edge Object that represents the edge to be splitted.	 * @param cell Object that represents the cell to insert into the edge.	 * @param newEdge Object that represents the edge to be inserted.	 * @return Returns the new edge that has been inserted.	 */	public Object splitEdge(Object edge, Object[] cells, Object newEdge,			double dx, double dy)	{		if (newEdge == null)		{			newEdge = cloneCells(new Object[] { edge })[0];		}		Object parent = model.getParent(edge);		Object source = model.getTerminal(edge, true);		model.beginUpdate();		try		{			cellsMoved(cells, dx, dy, false, false);			cellsAdded(cells, parent, model.getChildCount(parent), null, null,					true);			cellsAdded(new Object[] { newEdge }, parent, model					.getChildCount(parent), source, cells[0], false);			cellConnected(edge, cells[0], true);			fireEvent(mxEvent.SPLIT_EDGE, new mxEventObject(new Object[] {					edge, cells, newEdge, dx, dy }));		}		finally		{			model.endUpdate();		}		return newEdge;	}	//	// Cell visibility	//	/**	 * Sets the visible state of the selection cells. This is a shortcut	 * method.	 * 	 * @param show Boolean that specifies the visible state to be assigned.	 * @return Returns the cells whose visible state was changed.	 */	public Object[] toggleCells(boolean show)	{		return toggleCells(show, null);	}	/**	 * Sets the visible state of the specified cells. This is a shortcut	 * method.	 *	 * @param show Boolean that specifies the visible state to be assigned.	 * @param cells Array of cells whose visible state should be changed.	 * @return Returns the cells whose visible state was changed.	 */	public Object[] toggleCells(boolean show, Object[] cells)	{		return toggleCells(show, cells, true);	}	/**	 * Sets the visible state of the specified cells and all connected edges	 * if includeEdges is true. The change is carried out using cellsToggled.	 * This method fires mxEvent.TOGGLE_CELLS while the transaction is in	 * progress.	 *	 * @param show Boolean that specifies the visible state to be assigned.	 * @param cells Array of cells whose visible state should be changed. If	 * null is specified then the selection cells are used.	 * @return Returns the cells whose visible state was changed.	 */	public Object[] toggleCells(boolean show, Object[] cells,			boolean includeEdges)	{		if (cells == null)		{			cells = getSelectionCells();		}		// Adds all connected edges recursively		if (includeEdges)		{			cells = addAllEdges(cells);		}		model.beginUpdate();		try		{			cellsToggled(cells, show);			fireEvent(mxEvent.TOGGLE_CELLS, new mxEventObject(new Object[] {					show, cells, includeEdges }));		}		finally		{			model.endUpdate();		}		return cells;	}	/**	 * Sets the visible state of the specified cells.	 * 	 * @param cells Array of cells whose visible state should be changed.	 * @param show Boolean that specifies the visible state to be assigned.	 */	public void cellsToggled(Object[] cells, boolean show)	{		if (cells != null && cells.length > 0)		{			model.beginUpdate();			try			{				for (int i = 0; i < cells.length; i++)				{					model.setVisible(cells[i], show);				}			}			finally			{				model.endUpdate();			}		}	}	//	// Folding	//	/**	 * Sets the collapsed state of the selection cells without recursion.	 * This is a shortcut method.	 * 	 * @param collapse Boolean that specifies the collapsed state to be	 * assigned.	 * @return Returns the cells whose collapsed state was changed.	 */	public Object[] foldCells(boolean collapse)	{		return foldCells(collapse, false);	}	/**	 * Sets the collapsed state of the selection cells. This is a shortcut	 * method.	 * 	 * @param collapse Boolean that specifies the collapsed state to be	 * assigned.	 * @param recurse Boolean that specifies if the collapsed state should	 * be assigned to all descendants.	 * @return Returns the cells whose collapsed state was changed.	 */	public Object[] foldCells(boolean collapse, boolean recurse)	{		return foldCells(collapse, recurse, null);	}	/**	 * Sets the collapsed state of the specified cells and all descendants	 * if recurse is true. The change is carried out using cellsFolded.	 * This method fires mxEvent.FOLD_CELLS while the transaction is in	 * progress. Returns the cells whose collapsed state was changed.	 * 	 * @param collapse Boolean indicating the collapsed state to be assigned.	 * @param recurse Boolean indicating if the collapsed state of all	 * descendants should be set.	 * @param cells Array of cells whose collapsed state should be set. If	 * null is specified then the foldable selection cells

⌨️ 快捷键说明

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