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

📄 jawegraphmodel.java

📁 jawe的最新版本,基于Java的图形化工作流编辑器。图形化工作流编辑器 。使用JAVA语言开发
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
					list = roots;			}			return list;		}	}	//	// Static Methods	//	/**	 * Returns a deep clone of the specified cell, including all children.	 */	public static Object cloneCell(GraphModel model, Object cell) {		Map clones = model.cloneCells(getDescendantList(model, new Object[] { cell }).toArray());		return clones.get(cell);	}	/**	 * Returns a deep clone of the specified cells, including all children.	 */	public static Object[] cloneCell(GraphModel model, Object[] cells) {		Map clones = model.cloneCells(getDescendantList(model, cells).toArray());		for (int i = 0; i < cells.length; i++) {			cells[i] = clones.get(cells[i]);		}		return cells;	}	/**	 * Helper methods that connects the source of <code>edge</code> to	 * <code>port</code> in <code>model</model>.	 */	public static void setSourcePort(GraphModel model, Object edge, Object port) {		model.edit(null, new ConnectionSet(edge, port, true), null, null);	}	/**	 * Helper methods that connects the source of <code>edge</code> to	 * <code>port</code> in <code>model</model>.	 */	public static void setTargetPort(GraphModel model, Object edge, Object port) {		model.edit(null, new ConnectionSet(edge, port, false), null, null);	}	/**	 * Returns the source vertex of the edge by calling getParent on	 * getSource on the specified model.	 */	public static Object getSourceVertex(GraphModel model, Object edge) {		if (model != null) return model.getParent(model.getSource(edge));		return null;	}	/**	 * Returns the target vertex of the edge by calling getParent on	 * getTarget on the specified model.	 */	public static Object getTargetVertex(GraphModel model, Object edge) {		if (model != null) return model.getParent(model.getTarget(edge));		return null;	}	/**	 * @return Returns the user object of the given cell. This implementation	 *         checks if the cell is a default mutable tree node and returns	 *         it's user object.	 * 	 * @deprecated Use {@link GraphModel#getValue(Object)} instead.	 */	public static Object getUserObject(Object cell) {		if (cell instanceof DefaultMutableTreeNode) return ((DefaultMutableTreeNode) cell).getUserObject();		return null;	}	/**	 * Checks whether the cell has at least one child which is not a port. This	 * implementation operates on the model, not taking into account visibility	 * of cells. It returns true for groups regardless of their folded state.	 * 	 * @param cell	 *            the cell to check for being a group	 * @return Returns true if the cell contains at least one cell which is not	 *         a port	 */	public static boolean isGroup(GraphModel model, Object cell) {		for (int i = 0; i < model.getChildCount(cell); i++) {			if (!model.isPort(model.getChild(cell, i))) return true;		}		return false;	}	/**	 * Returns all cells of the model in an array.	 * 	 * @return Returns all cells in the model including all descandants.	 */	public static Object[] getAll(GraphModel model) {		return getDescendantList(model, getRoots(model)).toArray();	}	/**	 * Returns the roots of the specified model as an array.	 */	public static Object[] getRoots(GraphModel model) {		if (model instanceof JaWEGraphModel) return ((JaWEGraphModel) model).roots.toArray();		Object[] cells = null;		if (model != null) {			// If model is DefaultGraphModel, we can do a linear time getRoots			if (model instanceof DefaultGraphModel) {				cells = ((DefaultGraphModel) model).getRoots().toArray();			} else {				cells = new Object[model.getRootCount()];				for (int i = 0; i < cells.length; i++) {					cells[i] = model.getRootAt(i);				}			}		}		return cells;	}	/**	 * Returns the root participants of the specified model as a set.	 */	public static Set getRootParticipants(GraphModel model) {		Object[] roots = getRoots(model);		if (roots == null || roots.length == 0) return null;		Set rootDeps = new HashSet();		// extracting only participants (transitions are also roots)		for (int i = 0; i < roots.length; i++) {			if (roots[i] instanceof GraphParticipantInterface) {				rootDeps.add(roots[i]);			}		}		return rootDeps;	}	/**	 * Returns the roots in <code>cells</code> by checking if their parent is	 * <code>null</code>. This implementation only uses the GraphModel	 * interface. This method never returns null.	 */	public static Object[] getRoots(GraphModel model, Object[] cells) {		List roots = new ArrayList();		if (cells != null) {			for (int i = 0; i < cells.length; i++) {				if (model.getParent(cells[i]) == null) {					roots.add(cells[i]);				}			}		}		return roots.toArray();	}	/**	 * @return Returns the roots of cells, eg. an array that contains no cell	 *         having an ancestor in cells.	 */	public static Object[] getTopmostCells(GraphModel model, Object[] cells) {		Set cellSet = new HashSet();		for (int i = 0; i < cells.length; i++)			cellSet.add(cells[i]);		List parents = new ArrayList();		for (int i = 0; i < cells.length; i++) {			if (!hasAncestorIn(model, cellSet, cells[i])) parents.add(cells[i]);		}		return parents.toArray();	}	/**	 * Returns true if the specified child has an ancestor in parents.	 */	public static boolean hasAncestorIn(GraphModel model, Set parents, Object child) {		Object parent = model.getParent(child);		while (parent != null) {			if (parents.contains(parent)) return true;			parent = model.getParent(parent);		}		return false;	}	public static List getDescendantList(GraphModel model, Object[] cells) {		if (cells != null) {			Stack stack = new Stack();			for (int i = cells.length - 1; i >= 0; i--)				stack.add(cells[i]);			LinkedList result = new LinkedList();			while (!stack.isEmpty()) {				Object tmp = stack.pop();				for (int i = model.getChildCount(tmp) - 1; i >= 0; i--)					stack.add(model.getChild(tmp, i));				if (tmp != null) result.add(tmp);			}			return result;		}		return null;	}	/**	 * Gets all existing cells within model.	 */	public static List getAllCellsInModel(GraphModel model) {		List allCellsInModel = getDescendantList(model, getRoots(model));		if (allCellsInModel == null || allCellsInModel.size() == 0) {			return null;		}		return allCellsInModel;	}	/**	 * Gets all existing participants within model.	 */	public static List getAllParticipantsInModel(GraphModel model) {		if (!(model instanceof JaWEGraphModel)) return null;		List allCellsInModel = getAllCellsInModel(model);		if (allCellsInModel == null) {			return null;		}		List participants = new LinkedList();		Iterator it = allCellsInModel.iterator();		while (it.hasNext()) {			Object cell = it.next();			if (cell instanceof GraphParticipantInterface) {				participants.add(cell);			}		}		if (participants.size() == 0) {			return null;		}		return participants;	}	/**	 * Gets all existing activities within model.	 */	public static List getAllActivitiesInModel(GraphModel model) {		if (!(model instanceof JaWEGraphModel)) return null;		List allCellsInModel = getAllCellsInModel(model);		if (allCellsInModel == null) {			return null;		}		List activities = new LinkedList();		Iterator it = allCellsInModel.iterator();		while (it.hasNext()) {			Object cell = it.next();			if (cell instanceof GraphActivityInterface) {				activities.add(cell);			}		}		if (activities.size() == 0) {			return null;		}		return activities;	}   /**    * Gets all existing start/end bubbles within model.     */   public static List getAllBubblesInModel(GraphModel model) {      if (!(model instanceof JaWEGraphModel)) return null;      List allCellsInModel = getAllCellsInModel(model);      if (allCellsInModel == null) {         return null;      }      List bubbles = new LinkedList();      Iterator it = allCellsInModel.iterator();      while (it.hasNext()) {         Object cell = it.next();         if (cell instanceof GraphBubbleActivityInterface) {            bubbles.add(cell);         }      }      if (bubbles.size() == 0) {         return null;      }      return bubbles;   }      	/**	 * Gets all existing transitions within model.	 */	public static List getAllTransitionsInModel(GraphModel model) {		if (!(model instanceof JaWEGraphModel)) return null;		// Transitions are root objects		Object[] roots = getRoots(model);		if (roots == null || roots.length == 0) return null;		List transitions = new LinkedList();		// extracting only transitions (participants are also roots)		for (int i = 0; i < roots.length; i++) {			if (roots[i] instanceof GraphTransitionInterface) {				transitions.add(roots[i]);			}		}		return transitions;	}	/**	 * Orders cells so that they reflect the model order.	 */	public static Object[] order(GraphModel model, Object[] cells) {		if (cells != null) {			Set cellSet = new HashSet();			for (int i = 0; i < cells.length; i++)				cellSet.add(cells[i]);			Stack stack = new Stack();			for (int i = model.getRootCount() - 1; i >= 0; i--)				stack.add(model.getRootAt(i));			LinkedList result = new LinkedList();			while (!stack.isEmpty()) {				Object tmp = stack.pop();				for (int i = model.getChildCount(tmp) - 1; i >= 0; i--)					stack.add(model.getChild(tmp, i));				if (cellSet.remove(tmp)) result.add(tmp);			}			return result.toArray();		}		return null;	}	/**	 * Returns the set of all connected edges to <code>cells</code> or their	 * descendants. The passed-in cells are never returned as part of the result	 * set. This can be used on vertices, edges and ports.	 */	public static List getEdges(GraphModel model, Object[] cells) {		List result = new LinkedList();		if (cells != null) {			// We know the minimum initial capacity of this set is cells.length			// and it's probably going to get a lot bigger			Set allCells = new HashSet((cells.length) * 2 + 8, (float) 0.75);			for (int i = 0; i < cells.length; i++) {				allCells.add(cells[i]);			}			// Include descendants			allCells.addAll(getDescendantList(model, cells));			if (allCells != null) {				Iterator it = allCells.iterator();				while (it.hasNext()) {					Iterator edges = model.edges(it.next());					while (edges.hasNext())						result.add(edges.next());				}				for (int i = 0; i < cells.length; i++)					result.remove(cells[i]);			}		}		return result;	}	/**	 * @return Returns the opposite port or vertex in <code>edge</code>.	 */	public static Object getOpposite(GraphModel model, Object edge, Object cell) {		boolean isPort = model.isPort(cell);		Object source = (isPort) ? model.getSource(edge) : getSourceVertex(model, edge);		if (cell == source)			return (isPort) ? model.getTarget(edge) : getTargetVertex(model, edge);               return source;	}	/**	 * Returns true if the given vertices are conntected by a single edge in	 * this document.	 */	public static boolean containsEdgeBetween(GraphModel model, Object v1, Object v2) {		Object[] edges = getEdgesBetween(model, v1, v2, false);		return (edges != null && edges.length > 0);	}	/**	 * Returns the edges between two specified ports or two specified vertices.	 * If directed is true then <code>cell1</code> must be the source of the	 * returned edges.	 */	public static Object[] getEdgesBetween(GraphModel model, Object cell1, Object cell2, boolean directed) {		boolean isPort1 = model.isPort(cell1);		boolean isPort2 = model.isPort(cell2);		ArrayList result = new ArrayList();		Set edges = DefaultGraphModel.getEdges(model, new Object[] { cell1 });		Iterator it = edges.iterator();		while (it.hasNext()) {			Object edge = it.next();			// TODO: Handle edge groups			Object source = (isPort1) ? model.getSource(edge) : getSourceVertex(model, edge);			Object target = (isPort2) ? model.getTarget(edge) : getTargetVertex(model, edge);			if ((source == cell1 && target == cell2) || (!directed && source == cell2 && target == cell1))				result.add(edge);		}		return result.toArray();	}	/**	 * Returns the outgoing edges for cell. Cell should be a port or a vertex.	 */	public static Object[] getOutgoingEdges(GraphModel model, Object cell) {		return getEdges(model, cell, false);	}	/**	 * Returns the incoming edges for cell. Cell should be a port or a vertex.	 */	public static Object[] getIncomingEdges(GraphModel model, Object cell) {		return getEdges(model, cell, true);	}	/**	 * Returns the incoming or outgoing edges for cell. Cell should be a port or	 * a vertex.	 */	public static Object[] getEdges(GraphModel model, Object cell, boolean incoming) {		ArrayList result = new ArrayList();		Set edges = DefaultGraphModel.getEdges(model, new Object[] { cell });		Iterator it = edges.iterator();		while (it.hasNext()) {			Object edge = it.next();			// TODO: Handle edge groups			Object port = (incoming) ? model.getTarget(edge) : model.getSource(edge);			Object parent = model.getParent(port);			if (port == cell || parent == cell) result.add(edge);		}		return result.toArray();	}	// Serialization support	private void readObject(ObjectInputStream s)			throws IOException, ClassNotFoundException {		s.defaultReadObject();		listenerList = new EventListenerList();		emptyIterator = new EmptyIterator();	}	public static class EmptyIterator implements Iterator, Serializable {		public boolean hasNext() {			return false;		}		public Object next() {			return null;		}		public void remove() {			// nop		}	}}/* PEGraphModel.java */

⌨️ 快捷键说明

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