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

📄 jgraph.java

📁 用JGraph编的软件
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
	 * @see JComponent#updateUI	 *	 */	public void updateUI() {		setUI(new org.jgraph.plaf.basic.BasicGraphUI());		invalidate();	}	/**	 * Returns the name of the L&F class that renders this component.	 * @return the string "GraphUI"	 * @see JComponent#getUIClassID	 *	 */	public String getUIClassID() {		return uiClassID;	}	//	// Content	//	/**	 * Returns all cells that the model contains.	 */	public Object[] getRoots() {		return DefaultGraphModel.getRoots(graphModel);	}	/**	 * Returns all cells that intersect the given rectangle.	 */	public Object[] getRoots(Rectangle clip) {		CellView[] views = graphLayoutCache.getRoots(clip);		Object[] cells = new Object[views.length];		for (int i = 0; i < views.length; i++)			cells[i] = views[i].getCell();		return cells;	}	/**	 * Returns all <code>cells</code> including all descendants.	 * DEPRECATED: Use getDescendantList instead.	 */	public Object[] getDescendants(Object[] cells) {		Set set = DefaultGraphModel.getDescendants(getModel(), cells);		return set.toArray();	}	/**	 * Returns all <code>cells</code> including all descendants.	 */	public Object[] getDescendantList(Object[] cells) {		return DefaultGraphModel.getDescendantList(getModel(), cells).toArray();	}	/**	 * Returns a map of (cell, clone)-pairs for all <code>cells</code>	 * and their children. Special care is taken to replace the anchor	 * references between ports. (Iterative implementation.)	 */	public Map cloneCells(Object[] cells) {		return graphModel.cloneCells(cells);	}	/**	 * Returns the topmost cell at the specified location.	 * @param x an integer giving the number of pixels horizontally from	 * the left edge of the display area, minus any left margin	 * @param y an integer giving the number of pixels vertically from	 * the top of the display area, minus any top margin	 * @return the topmost cell at the specified location	 */	public Object getFirstCellForLocation(int x, int y) {		return getNextCellForLocation(null, x, y);	}	/**	 * Returns the cell at the specified location that is "behind" the	 * <code>current</code> cell. Returns the topmost cell if there are	 * no more cells behind <code>current</code>.	 */	public Object getNextCellForLocation(Object current, int x, int y) {		x /= scale;		y /= scale; // FIX: Consistency with other methods?		CellView cur = graphLayoutCache.getMapping(current, false);		CellView cell = getNextViewAt(cur, x, y);		if (cell != null)			return cell.getCell();		return null;	}	/**	 * Returns the bounding rectangle of the specified cell.	 */	public Rectangle getCellBounds(Object cell) {		CellView view = graphLayoutCache.getMapping(cell, false);		if (view != null)			return view.getBounds();		return null;	}	/**	 * Returns the bounding rectangle of the specified cells.	 */	public Rectangle getCellBounds(Object[] cells) {		if (cells != null && cells.length > 0) {			Rectangle ret = getCellBounds(cells[0]);			if (ret != null) {				ret = new Rectangle(ret);				for (int i = 1; i < cells.length; i++) {					Rectangle r = getCellBounds(cells[i]);					if (r != null)					    SwingUtilities.computeUnion(						r.x,						r.y,						r.width,						r.height,						ret);				}				return ret;			}		}		return null;	}	/**	 * Returns the next view at the specified location wrt. <code>current</code>.	 * This is used to iterate overlapping cells, and cells that are grouped.	 * The current selection affects this method.	 */	public CellView getNextViewAt(CellView current, int x, int y) {		Object[] sel =			graphLayoutCache.order(getSelectionModel().getSelectables());		CellView[] cells = graphLayoutCache.getMapping(sel);		CellView cell = getNextViewAt(cells, current, x, y);		return cell;	}	/**	 * Returns the next view at the specified location wrt. <code>c</code>	 * in the specified array of views. The views must be in order, as	 * returned, for example, by GraphLayoutCache.order(Object[]).	 */	public CellView getNextViewAt(CellView[] cells, CellView c, int x, int y) {		if (cells != null) {			Rectangle r =				new Rectangle(					x - tolerance,					y - tolerance,					2 * tolerance,					2 * tolerance);			// Iterate through cells and switch to active			// if current is traversed. Cache first cell.			CellView first = null;			boolean active = (c == null);			Graphics g = getGraphics();			for (int i = cells.length - 1; i >= 0; i--) {				if (cells[i] != null && cells[i].intersects(g, r)) {					if (active						&& !selectionModel.isChildrenSelected(cells[i].getCell()))						return cells[i];					else if (first == null)						first = cells[i];					active = active | (cells[i] == c);				}			}			return first;		}		return null;	}	/**	 * Convenience method to return the port at the specified location.	 */	public Object getPortForLocation(int x, int y) {		PortView view = getPortViewAt(x, y);		if (view != null)			return view.getCell();		return null;	}	/**	 * Returns the portview at the specified location.	 */	public PortView getPortViewAt(int x, int y) {		Rectangle r =			new Rectangle(				x - tolerance,				y - tolerance,				2 * tolerance,				2 * tolerance);		PortView[] ports = graphLayoutCache.getPorts();		for (int i = ports.length - 1; i >= 0; i--)			if (ports[i] != null && ports[i].intersects(getGraphics(), r))				return ports[i];		return null;	}	/**	 * Converts the specified value to string. If the value is an instance of	 * CellView or the current GraphLayoutCache returns a mapping for value, then	 * then value attribute of that CellView is used. (The value is retrieved using	 * getAllAttributes.) If the value is an instance	 * of DefaultMutableTreeNode (e.g. DefaultGraphCell), then the userobject	 * is returned as a String.	 */	public String convertValueToString(Object value) {		CellView view =			(value instanceof CellView)				? (CellView) value				: getGraphLayoutCache().getMapping(value, false);		if (view != null) {			Object newValue = GraphConstants.getValue(view.getAllAttributes());			if (newValue != null)				value = newValue;			else				value = view.getCell();		}		if (value instanceof DefaultMutableTreeNode			&& ((DefaultMutableTreeNode) value).getUserObject() != null)			return ((DefaultMutableTreeNode) value).getUserObject().toString();		else if (value != null)			return value.toString();		return null;	}	//	// Grid and Scale	//	/**	 * Returns the given point applied to the grid.	 * @param p a point in screen coordinates.	 * @return the same point applied to the grid.	 */	public Point snap(Point p) {		if (gridEnabled && p != null) {			double sgs = (double) gridSize * getScale();			p.x = (int) Math.round(Math.round(p.x / sgs) * sgs);			p.y = (int) Math.round(Math.round(p.y / sgs) * sgs);		}		return p;	}	/**	 * Returns the given point applied to the grid.	 * @param p a point in screen coordinates.	 * @return the same point applied to the grid.	 */	public Dimension snap(Dimension d) {		if (gridEnabled && d != null) {			double sgs = (double) gridSize * getScale();			d.width = 1 + (int) Math.round(Math.round(d.width / sgs) * sgs);			d.height = 1 + (int) Math.round(Math.round(d.height / sgs) * sgs);		}		return d;	}	/**	 * Upscale the given point in place, ie.	 * using the given instance.	 * @param p the point to be upscaled	 * @return the upscaled point instance	 */	public Point toScreen(Point p) {		if (p == null)			return null;		p.x = (int) Math.round(p.x * scale);		p.y = (int) Math.round(p.y * scale);		return p;	}	/**	 * Downscale the given point in place, ie.	 * using the given instance.	 * @param p the point to be downscaled	 * @return the downscaled point instance	 */	public Point fromScreen(Point p) {		if (p == null)			return null;		p.x = (int) Math.round(p.x / scale);		p.y = (int) Math.round(p.y / scale);		return p;	}	/**	 * Upscale the given rectangle in place, ie.	 * using the given instance.	 * @param rect the rectangle to be upscaled	 * @return the upscaled rectangle instance	 */	public Rectangle toScreen(Rectangle rect) {		if (rect == null)			return null;		rect.x *= scale;		rect.y *= scale;		rect.width *= scale;		rect.height *= scale;		return rect;	}	/**	 * Downscale the given rectangle in place, ie.	 * using the given instance.	 * @param rect the rectangle to be downscaled	 * @return the down-scaled rectangle instance	 */	public Rectangle fromScreen(Rectangle rect) {		if (rect == null)			return null;		rect.x /= scale;		rect.y /= scale;		rect.width /= scale;		rect.height /= scale;		return rect;	}	//	// Cell View Factory	//	/**	 * Constructs a view for the specified cell and associates it	 * with the specified object using the specified CellMapper.	 * This calls refresh on the created CellView to create all	 * dependent views.<p>	 * Note: The mapping needs to be available before the views	 * of child cells and ports are created.	 *	 * @param cell reference to the object in the model	 */	public CellView createView(Object cell, CellMapper map) {		CellView view = null;		if (graphModel.isPort(cell))			view = createPortView(cell, map);		else if (graphModel.isEdge(cell))			view = createEdgeView(cell, map);		else			view = createVertexView(cell, map);		map.putMapping(cell, view);		view.refresh(true); // Create Dependent Views		view.update();		return view;	}	/**	 * Computes and updates the size for <code>view</code>.	 */	public void updateAutoSize(CellView view) {		if (view != null && !isEditing()			&& GraphConstants.isAutoSize(view.getAllAttributes())) {			Rectangle bounds = view.getBounds();			if (bounds != null) {				Dimension d = getUI().getPreferredSize(this, view);				bounds.setSize(d);			}		}	}	/**	 * Constructs an EdgeView view for the specified object.	 */	protected EdgeView createEdgeView(Object e, CellMapper cm) {		if (e instanceof Edge)			return createEdgeView((Edge) e, cm);		else			return new EdgeView(e, this, cm);	}	/**	 * Constructs a PortView view for the specified object.	 */	protected PortView createPortView(Object p, CellMapper cm) {		if (p instanceof Port)			return createPortView((Port) p, cm);		else			return new PortView(p, this, cm);	}	/**	 * Constructs an EdgeView view for the specified object.	 *	 * @deprecated	replaced by {@link #createEdgeView(Object,CellMapper)}	 *		since JGraph no longer exposes dependecies on	 * 		GraphCell subclasses (Port, Edge)	 */	protected EdgeView createEdgeView(Edge e, CellMapper cm) {		return new EdgeView(e, this, cm);	}	/**	 * Constructs a PortView view for the specified object.	*	* @deprecated	replaced by {@link #createPortView(Object,CellMapper)}	*		since JGraph no longer exposes dependecies on	* 		GraphCell subclasses (Port, Edge)	 */	protected PortView createPortView(Port p, CellMapper cm) {		return new PortView(p, this, cm);	}	/**	 * Constructs a VertexView view for the specified object.	 */	protected VertexView createVertexView(Object v, CellMapper cm) {		return new VertexView(v, this, cm);	}	//	// Unbound Properties	//	/**	 * Returns the number of clicks for editing to start.	 */	public int getEditClickCount() {		return editClickCount;	}	/**	 * Sets the number of clicks for editing to start.	 */	public void setEditClickCount(int count) {		editClickCount = count;	}	/**	 * Returns true if the graph accepts drops/pastes from external sources.	 */	public boolean isDropEnabled() {		return dropEnabled;	}	/**	 * Sets if the graph accepts drops/pastes from external sources.	 */	public void setDropEnabled(boolean flag) {		dropEnabled = flag;	}	/**	 * Returns true if the graph uses Drag-and-Drop to move cells.	 */	public boolean isDragEnabled() {		return dragEnabled;	}	/**	 * Sets if the graph uses Drag-and-Drop to move cells.	 */	public void setDragEnabled(boolean flag) {		dragEnabled = flag;	}	/*	 * Returns true if the graph allows movement of cells.	 */	public boolean isMoveable() {		return moveable;	}	/**	 * Sets if the graph allows movement of cells.	 */	public void setMoveable(boolean flag) {		moveable = flag;	}	/**	 * Returns true if the graph allows adding/removing/modifying points.	 */	public boolean isBendable() {		return bendable;	}	/**	 * Sets if the graph allows adding/removing/modifying points.	 */	public void setBendable(boolean flag) {		bendable = flag;	}	/**	 * Returns true if the graph allows new connections to be established.	 */	public boolean isConnectable() {		return connectable;	}	/**	 * Setse if the graph allows new connections to be established.	 */	public void setConnectable(boolean flag) {		connectable = flag;	}	/**	 * Returns true if the graph allows existing connections to be removed.	 */	public boolean isDisconnectable() {		return disconnectable;	}	/**	 * Sets if the graph allows existing connections to be removed.	 */	public void setDisconnectable(boolean flag) {		disconnectable = flag;	}	/**	 * Returns true if cells are cloned on CTRL-Drag operations.	 */	public boolean isCloneable() {		return cloneable;

⌨️ 快捷键说明

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