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

📄 defaultgraphmodel.java

📁 用JGraph编的软件
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
		 */		protected void handleEmptyGroups(Object[] groups) {			if (groups != null && groups.length > 0) {				if (remove == null)					remove = new Object[] {				};				Object[] tmp = new Object[remove.length + groups.length];				System.arraycopy(remove, 0, tmp, 0, remove.length);				System.arraycopy(groups, 0, tmp, remove.length, groups.length);				remove = tmp;			}		}		public boolean isSignificant() {			return true;		}		/**		 * Returns the source of this change. This can either be a		 * view or a model, if this change is a GraphModelChange.		 */		public Object getSource() {			return DefaultGraphModel.this;		}		/**		 * Returns the cells that have changed. This includes the cells		 * that have been changed through a call to getAttributes and the		 * edges that have been changed with the ConnectionSet.		 */		public Object[] getChanged() {			return changed;		}		/**		 * Returns the objects that have not changed explicitly, but		 * implicitly because one of their dependent cells has changed.		 */		public Object[] getContext() {			return context;		}		/**		 * Returns the cells that were inserted.		 */		public Object[] getInserted() {			return inserted;		}		/**		 * Returns the cells that were inserted.		 */		public Object[] getRemoved() {			return removed;		}		/**		 * Returns a map that contains (object, map) pairs		 * of the attributes that have been stored in the model.		 */		public Map getPreviousAttributes() {			return previousAttributes;		}		/**		 * Returns a map of (object, view attributes). The objects		 * are model objects which need to be mapped to views.		 */		public Map getAttributes() {			return attributes;		}		/**		 * Returns the connectionSet.		 * @return ConnectionSet		 */		public ConnectionSet getConnectionSet() {			return connectionSet;		}		public ConnectionSet getPreviousConnectionSet() {			return previousConnectionSet;		}		/**		 * Returns the parentMap.		 * @return ParentMap		 */		public ParentMap getParentMap() {			return parentMap;		}		public ParentMap getPreviousParentMap() {			return previousParentMap;		}		/**		 * Redoes a change.		 *		 * @exception CannotRedoException if the change cannot be redone		 */		public void redo() throws CannotRedoException {			super.redo();			execute();		}		/**		 * Undoes a change.		 *		 * @exception CannotUndoException if the change cannot be undone		 */		public void undo() throws CannotUndoException {			super.undo();			execute();		}		/**		 * Execute this edit such that the next invocation to this		 * method will invert the last execution.		 */		public void execute() {			// Compute Changed Cells			Set tmp = new HashSet();			if (attributes != null)				tmp.addAll(attributes.keySet());			if (parentMap != null)				tmp.addAll(parentMap.getChangedNodes());			// Note: One must also include the previous parents!			if (connectionSet != null)				tmp.addAll(connectionSet.getChangedEdges());			if (remove != null) {				for (int i = 0; i < remove.length; i++)					tmp.remove(remove[i]);			}			changed = tmp.toArray();			// Context cells			Set ctx = getEdges(DefaultGraphModel.this, changed);			context = ctx.toArray();			// Do Execute			inserted = insert;			removed = remove;			remove = handleInsert(inserted);			previousParentMap = parentMap;			parentMap = handleParentMap(parentMap);			// Adds previous parents			if (parentMap != null)				tmp.addAll(parentMap.getChangedNodes());			previousConnectionSet = connectionSet;			connectionSet = handleConnectionSet(connectionSet);			insert = handleRemove(removed);			previousAttributes = attributes;			attributes = handleAttributes(attributes);			changed = tmp.toArray();			// Fire Event	  			fireGraphChanged(DefaultGraphModel.this, this);		}		public void putViews(GraphLayoutCache view, CellView[] views) {			if (view != null && views != null)				cellViews.put(view, views);		}		public CellView[] getViews(GraphLayoutCache view) {			return (CellView[]) cellViews.get(view);		}		public String toString() {			String s = new String();			if (inserted != null) {				s += "Inserted:\n";				for (int i = 0; i < inserted.length; i++)					s += "  " + inserted[i] + "\n";			} else				s += "None inserted\n";			if (removed != null) {				s += "Removed:\n";				for (int i = 0; i < removed.length; i++)					s += "  " + removed[i] + "\n";			} else				s += "None removed\n";			if (changed != null && changed.length > 0) {				s += "Changed:\n";				for (int i = 0; i < changed.length; i++)					s += "  " + changed[i] + "\n";			} else				s += "None changed\n";			if (parentMap != null)				s += parentMap.toString();			else				s += "No parent map\n";			return s;		}	}	/**	 * An implementation of GraphViewChange.	 */	public class GraphModelLayerEdit		extends GraphLayoutCache.GraphViewLayerEdit		implements GraphModelEvent.GraphModelChange {		// The cell that change are the parents, because they need to		// reload their childs for reordering!		protected Object[] parents;		/**		 * Constructs a GraphModelEdit. This modifies the order of the cells		     * in the model.		 */		public GraphModelLayerEdit(Object[] cells, int layer) {			super(DefaultGraphModel.this, cells, layer);			// Construct Parent Array			Set par = new HashSet();			for (int i = 0; i < cells.length; i++) {				if (cells[i] instanceof TreeNode)					par.add(((TreeNode) cells[i]).getParent());			}			parents = par.toArray();		}		/**		 * Returns the source of this change. This can either be a		 * view or a model, if this change is a GraphModelChange.		 */		public Object getSource() {			return DefaultGraphModel.this;		}		/**		 * Returns the cells that have changed.		 */		public Object[] getChanged() {			return parents;		}		/**		 * Returns the cells that have changed.		 */		public Object[] getInserted() {			return null;		}		/**		 * Returns the cells that have changed.		 */		public Object[] getRemoved() {			return null;		}		/**		 * Returns null.		 */		public Map getPreviousAttributes() {			return null;		}				public ConnectionSet getPreviousConnectionSet() {			return null;		}		public ParentMap getPreviousParentMap() {			return null;		}		/**		 * Allows a <code>GraphLayoutCache</code> to add and execute and		 * UndoableEdit in this change. This does also work if the		 * parent edit has already been executed, in which case the		 * to be added edit will be executed immediately, after		 * addition.		 * This is used to handle changes to the view that are 		 * triggered by certain changes of the model. Such implicit		 * edits may be associated with the view so that they may be		 * undone and redone correctly, and are stored in the model's		 * global history together with the parent event as one unit.		 */		public void addImplicitEdit(UndoableEdit edit) {			// ignore			}		/**		 * Returns the views that have not changed explicitly, but		 * implicitly because one of their dependent cells has changed.		 */		public CellView[] getViews(GraphLayoutCache view) {			return null;		}		/**		 * Returns the views that have not changed explicitly, but		 * implicitly because one of their dependent cells has changed.		 */		public void putViews(GraphLayoutCache view, CellView[] cellViews) {			// ignore		}		protected void updateListeners() {			fireGraphChanged(DefaultGraphModel.this, this);		}		/**		 * Returns the list that exclusively contains <code>view</code>.		 */		protected List getParentList(Object cell) {			List list = null;			if (cell instanceof DefaultMutableTreeNode) {				Object parent = ((DefaultMutableTreeNode) cell).getParent();				if (parent instanceof DefaultGraphCell)					list = ((DefaultGraphCell) parent).getChildren();				else					list = roots;			}			return list;		}	}	//	// Static Methods	//	/**	 * 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;	}	/**	 * Returns the roots of the specified model as an array.	 * This implementation only uses the GraphModel interface.	 */	public static Object[] getRoots(GraphModel model) {		Object[] cells = null;		if (model != null) {			cells = new Object[model.getRootCount()];			for (int i = 0; i < cells.length; i++)				cells[i] = model.getRootAt(i);		}		return cells;	}	/**	 * Return the set of edges that are connected to the	 * specified cells. The array is flattened and then	 * all attached edges that are not part of the cells	 * array are returned.	 */	public static Set getEdges(GraphModel model, Object[] cells) {		Set result = new HashSet();		Set allCells = getDescendants(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());			}			result.removeAll(allCells);		}		return result;	}	/**	 * Flattens the given array of root cells by adding the roots	 * and their descandants. The resulting set contains all cells,	 * which means it contains branches <strong>and</strong> leafs.	 * Note: This is an iterative implementation. No recursion used.	 * DEPRECATED: Use getDescendantList	 */	public static Set getDescendants(GraphModel model, Object[] cells) {		if (cells != null) {			Stack stack = new Stack();			for (int i = 0; i < cells.length; i++)				stack.add(cells[i]);			HashSet result = new HashSet();			while (!stack.isEmpty()) {				Object tmp = stack.pop();				for (int i = 0; i < model.getChildCount(tmp); i++)					stack.add(model.getChild(tmp, i));				if (tmp != null)					result.add(tmp);			}			return result;		}		return null;	}	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;	}	// 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		}	}}

⌨️ 快捷键说明

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