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

📄 graphlayoutcache.java

📁 用JGraph编的软件
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
				return tmp;			} else { // Simply Invert				Object[] tmp = new Object[cells.length];				for (int i = 0; i < cells.length; i++)					tmp[cells.length - i - 1] = cells[i];				return tmp;			}		}		return cells;	}	/**	 * An implementation of GraphViewChange.	 */	public class GraphViewEdit		extends CompoundEdit		implements			GraphModelEvent.GraphViewChange,			GraphModelEvent.ExecutableGraphChange {		protected Object[] cells;		protected CellView[] context, hidden;		protected Map attributes;		protected Object[] visible, invisible;		/**		* Constructs a GraphViewEdit. This modifies the attributes		* of the specified views and may be used to notify UndoListeners.		*		* @param viewAttributes the map that defines the new attributes		*/		public GraphViewEdit(Map nested) {			this(nested, null, null);			attributes = nested;		}		/**		* Constructs a GraphViewEdit. This modifies the attributes		* of the specified views and may be used to notify UndoListeners.		* This should also take an array of removed cell views, but it 		* is not possible to add further UndoableEdits to an already		* executed CompoundEdit, such as a GraphModel change. Thus, 		* to handle implicit changes -- rather than piggybacking on		* the model's event -- the CompoundEdit's addEdit method		* should be extended to accept and instantly execute sub-		* sequent edits (implicit changes to the view, such as		* removing a mapping, hiding a view or the like).		*		* @param viewAttributes the map that defines the new attributes		*/		public GraphViewEdit(			Map attributes,			Object[] visible,			Object[] invisible) {			super();			this.attributes = attributes;			// Context cells			if (attributes != null) {				cells = attributes.keySet().toArray();				Set ctx = DefaultGraphModel.getEdges(getModel(), cells);				context = getMapping(ctx.toArray());			}			// Visibility Operation			this.visible = visible;			this.invisible = invisible;		}		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 GraphLayoutCache.this;		}		/**		 * Returns the views that have changed.		 */		public Object[] getChanged() {			if (attributes != null)				return attributes.keySet().toArray();			return null;		}		/**		 * Returns the views that have not changed explicitly, but		 * implicitly because one of their dependent cells has changed.		 */		public Object[] getContext() {			return context;		}		/**		 * Returns a map of (cell view, attribute) pairs.		 */		public Map getAttributes() {			return attributes;		}		/**		 * 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() {			// Remember or restore hidden cells			if (hidden != null)				for (int i = 0; i < hidden.length; i++)					if (hidden[i] != null)						mapping.put(hidden[i].getCell(), hidden[i]);			if (!rememberCellViews) // already remembered				hidden = getMapping(invisible);			// Handle visibility			boolean updatePorts =				setVisibleImpl(visible, true)					| setVisibleImpl(invisible, false);			// Swap arrays			Object[] tmp = visible;			visible = invisible;			invisible = tmp;			// Handle attributes			//System.out.println("GraphLayoutCache::GraphViewEdit::execute::attributes="+attributes);			if (attributes != null)				attributes = handleAttributes(attributes);			if (updatePorts)				updatePorts();			// Refresh Context			if (context != null)				for (int i = 0; i < context.length; i++)					if (context[i] != null)						context[i].refresh(false);			setChanged();			notifyObservers(this);		}	}	/**	 * Attention: Undo will not work for routing-change if	 * ROUTING and POINTS are stored in different locations.	 * This happens if the model holds the routing attribute	 * and the routing changes from unrouted to routed.	 * In this case the points in the view are already routed	 * according to the new scheme when written to the command	 * history (-> no undo).	 */	protected Map handleAttributes(Map attributes) {		Map undo = new Hashtable();		CellView[] views = new CellView[attributes.size()];		Iterator it = attributes.entrySet().iterator();		int i = 0;		while (it.hasNext()) {			Map.Entry entry = (Map.Entry) it.next();			CellView cv = getMapping(entry.getKey(), false);			views[i] = cv;			i += 1;			if (cv != null) {				Map deltaNew = (Map) entry.getValue();				//System.out.println("state=" + cv.getAttributes());				//System.out.println("change=" + deltaNew);				Map deltaOld = cv.setAttributes(deltaNew);				cv.refresh(false);				//System.out.println("state'=" + cv.getAttributes());				//System.out.println("change'=" + deltaOld);				undo.put(cv.getCell(), deltaOld);				factory.updateAutoSize(cv);			}		}		// Re-route all child edges		update(views);		return undo;	}	//	// GraphViewLayerEdit	//	/**	 * An implementation of GraphViewChange.	 */	public static class GraphViewLayerEdit		extends AbstractUndoableEdit		implements			GraphModelEvent.GraphViewChange,			GraphModelEvent.ExecutableGraphChange {		public static final int FRONT = -1, BACK = -2;		protected Object changeSource;		protected transient Object[] cells;		protected transient int[] next, prev;		protected int layer;		/**		 * Constructs a GraphViewEdit. This modifies the view attributes		 * of the specified cells and may be used to notify UndoListeners.		 *		 * @param source the source of the change (the view)		 * @param changed the cellviews that changed		 * @param viewAttributes the map that defines the new attributes		 */		public GraphViewLayerEdit(Object source, Object[] cells, int layer) {			changeSource = source;			this.cells = cells;			this.layer = layer;			next = new int[cells.length];			prev = new int[cells.length];			updateNext();		}		protected void updateNext() {			for (int i = 0; i < next.length; i++)				next[i] = layer;		}		/**		 * 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 changeSource;		}		/**		 * Returns the cells that have changed.		 */		public Object[] getChanged() {			return cells;		}		/**		 * Returns the views that have not changed explicitly, but		 * implicitly because one of their dependent cells has changed.		 */		public Object[] getContext() {			return null;		}		/**		 * Returns a map of (cell view, attribute) pairs.		 */		public Map getAttributes() {			return null;		}		/**		 * Redoes a change.		 *		 * @exception CannotRedoException if the change cannot be redone		 */		public void redo() throws CannotRedoException {			super.redo();			updateNext();			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() {			for (int i = 0; i < cells.length; i++) {				List list = getParentList(cells[i]);				if (list != null) {					prev[i] = list.indexOf(cells[i]);					if (prev[i] >= 0) {						list.remove(prev[i]);						int n = next[i];						if (n == FRONT)							n = list.size();						else if (n == BACK)							n = 0;						list.add(n, cells[i]);						next[i] = prev[i];					}				}			}			updateListeners();		}		protected void updateListeners() {			((GraphLayoutCache) changeSource).setChanged();			((GraphLayoutCache) changeSource).notifyObservers(this);		}		/**		 * Returns the list that exclusively contains <code>view</code>.		 */		protected List getParentList(Object view) {			if (view instanceof CellView) {				CellView parent = ((CellView) view).getParentView();				List list = null;				if (parent == null)					list = ((GraphLayoutCache) changeSource).roots;				else if (parent instanceof AbstractCellView)					list = ((AbstractCellView) parent).childViews;				return list;			}			return null;		}	}	//	// Static Methods	//	/**	 * Translates the specified views by the given amount.	 */	public static void translateViews(CellView[] views, int dx, int dy) {		views = AbstractCellView.getDescendantViews(views);		for (int i = 0; i < views.length; i++)			if (views[i].isLeaf())				GraphConstants.translate(views[i].getAllAttributes(), dx, dy);	}	/**	 * Returns all views, including descendants that have a parent	 * in <code>views</code>, especially the PortViews.	 * Note: Iterative Implementation using model.getChild and getMapping	 * on this cell mapper.	 */	public CellView[] getAllDescendants(CellView[] views) {		Stack stack = new Stack();		for (int i = 0; i < views.length; i++)			if (views[i] != null)				stack.add(views[i]);		ArrayList result = new ArrayList();		while (!stack.isEmpty()) {			CellView tmp = (CellView) stack.pop();			Object[] children = tmp.getChildViews();			for (int i = 0; i < children.length; i++)				stack.add(children[i]);			result.add(tmp);			// Add Port Views			for (int i = 0; i < graphModel.getChildCount(tmp.getCell()); i++) {				Object child = graphModel.getChild(tmp.getCell(), i);				if (graphModel.isPort(child)) {					CellView view = getMapping(child, false);					if (view != null)						stack.add(view);				}			}		}		CellView[] ret = new CellView[result.size()];		result.toArray(ret);		return ret;	}	/**	 * Returns the hiddenSet.	 * @return Map	 */	public Map getHiddenSet() {		return hiddenSet;	}	/**	 * Returns the hideEdgesOnBecomeInvisible.	 * @return boolean	 */	public boolean isHideEdgesOnBecomeInvisible() {		return hideEdgesOnBecomeInvisible;	}	/**	 * Returns the hideEdgesOnHide.	 * @return boolean	 */	public boolean isHideEdgesOnHide() {		return hideEdgesOnHide;	}	/**	 * Returns the rememberCellViews.	 * @return boolean	 */	public boolean isRememberCellViews() {		return rememberCellViews;	}	/**	 * Returns the showAllEdgesForVisibleVertices.	 * @return boolean	 */	public boolean isShowAllEdgesForVisibleVertices() {		return showAllEdgesForVisibleVertices;	}	/**	 * Returns the showEdgesOnShow.	 * @return boolean	 */	public boolean isShowEdgesOnShow() {		return showEdgesOnShow;	}	/**	 * Sets the hiddenSet.	 * @param hiddenSet The hiddenSet to set	 */	public void setHiddenSet(Map hiddenSet) {		this.hiddenSet = hiddenSet;	}	/**	 * Sets the hideEdgesOnBecomeInvisible.	 * @param hideEdgesOnBecomeInvisible The hideEdgesOnBecomeInvisible to set	 */	public void setHideEdgesOnBecomeInvisible(boolean hideEdgesOnBecomeInvisible) {		this.hideEdgesOnBecomeInvisible = hideEdgesOnBecomeInvisible;	}	/**	 * Sets the hideEdgesOnHide.	 * @param hideEdgesOnHide The hideEdgesOnHide to set	 */	public void setHideEdgesOnHide(boolean hideEdgesOnHide) {		this.hideEdgesOnHide = hideEdgesOnHide;	}	/**	 * Sets the rememberCellViews.	 * @param rememberCellViews The rememberCellViews to set	 */	public void setRememberCellViews(boolean rememberCellViews) {		this.rememberCellViews = rememberCellViews;	}	/**	 * Sets the showAllEdgesForVisibleVertices.	 * @param showAllEdgesForVisibleVertices The showAllEdgesForVisibleVertices to set	 */	public void setShowAllEdgesForVisibleVertices(boolean showAllEdgesForVisibleVertices) {		this.showAllEdgesForVisibleVertices = showAllEdgesForVisibleVertices;	}	/**	 * Sets the showEdgesOnShow.	 * @param showEdgesOnShow The showEdgesOnShow to set	 */	public void setShowEdgesOnShow(boolean showEdgesOnShow) {		this.showEdgesOnShow = showEdgesOnShow;	}}

⌨️ 快捷键说明

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