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

📄 edgerenderer.java

📁 用JGraph编的软件
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
			int c = BasicStroke.CAP_BUTT;			int j = BasicStroke.JOIN_MITER;			g2.setStroke(new BasicStroke(lineWidth, c, j));			translateGraphics(g);			g.setColor(getForeground());			if (view.beginShape != null) {				if (beginFill)					g2.fill(view.beginShape);				g2.draw(view.beginShape);			}			if (view.endShape != null) {				if (endFill)					g2.fill(view.endShape);				g2.draw(view.endShape);			}			if (lineDash != null) // Dash For Line Only				g2.setStroke(					new BasicStroke(lineWidth, c, j, 10.0f, lineDash, 0.0f));			if (view.lineShape != null)				g2.draw(view.lineShape);							if (selected) { // Paint Selected				g2.setStroke(GraphConstants.SELECTION_STROKE);				g2.setColor(graph.getHighlightColor());				if (view.beginShape != null)					g2.draw(view.beginShape);				if (view.lineShape != null)					g2.draw(view.lineShape);				if (view.endShape != null)					g2.draw(view.endShape);			}			if (graph.getEditingCell() != view.getCell()) {				Object label = graph.convertValueToString(view);				if (label != null) {					g2.setStroke(new BasicStroke(1));					g.setFont(getFont());					paintLabel(g, label.toString());				}			}		}	}	// This if for subclassers that to not want the graphics	// to be relative to the top, left corner of this component.	// Note: Override this method with an empty implementation 	// if you want absolute positions for your edges	protected void translateGraphics(Graphics g) {		g.translate(-getX(), -getY());	}	/**	 * Paint the specified label for the current edgeview.	 */	protected void paintLabel(Graphics g, String label) {		Point p = getLabelPosition(view);		if (p != null && label != null && label.length() > 0) {			int sw = metrics.stringWidth(label);			int sh = metrics.getHeight();			if (isOpaque()) {				g.setColor(getBackground());				g.fillRect(p.x - sw / 2 - 1, p.y - sh / 2 - 1, sw + 2, sh + 2);			}			if (borderColor != null) {				g.setColor(borderColor);				g.drawRect(p.x - sw / 2 - 1, p.y - sh / 2 - 1, sw + 2, sh + 2);			}			g.setColor(fontColor);			g.drawString(label, p.x - sw / 2, p.y + sh / 4);		}	}	/**	 * Returns the shape that represents the current edge	 * in the context of the current graph.	 * This method sets the global beginShape, lineShape	 * and endShape variables as a side-effect.	 */	protected Shape createShape() {            int n = view.getPointCount();            if (n > 1) {                // Following block may modify global vars as side effect (Flyweight Design)                EdgeView tmp = view;                Point[] p = new Point[n];                for (int i = 0; i < n; i++)                    p[i] = new Point(tmp.getPoint(i));                // End of Side-Effect Block                // Undo Global Side Effects                if (view != tmp) {                    view = tmp;                    installAttributes(view);                }                // End of Undo                if (view.sharedPath == null) {                    view.sharedPath = new GeneralPath(GeneralPath.WIND_NON_ZERO);                } else {                    view.sharedPath.reset();                }                view.beginShape = view.lineShape = view.endShape = null;                Point p0 = p[0];                Point pe = p[n - 1];                Point p1 = p[1];                Point p2 = p[n - 2];                if (beginDeco != GraphConstants.ARROW_NONE) {                    view.beginShape = createLineEnd(beginSize, beginDeco, p1, p0);                }                if (endDeco != GraphConstants.ARROW_NONE) {                    view.endShape = createLineEnd(endSize, endDeco, p2, pe);                }                view.sharedPath.moveTo(p0.x, p0.y);                if (lineStyle == GraphConstants.STYLE_QUADRATIC && n > 2)                    view.sharedPath.quadTo(p1.x, p1.y, pe.x, pe.y);                else if (lineStyle == GraphConstants.STYLE_BEZIER && n > 3)                    view.sharedPath.curveTo(p1.x, p1.y, p2.x, p2.y, pe.x, pe.y);                else {                    for (int i = 1; i < n - 1; i++)                        view.sharedPath.lineTo(p[i].x, p[i].y);                    view.sharedPath.lineTo(pe.x, pe.y);                }                view.sharedPath.moveTo(pe.x, pe.y);                view.lineShape = (GeneralPath) view.sharedPath.clone();                if (view.endShape != null)                    view.sharedPath.append(view.endShape, true);                if (view.beginShape != null)                    view.sharedPath.append(view.beginShape, true);                return view.sharedPath;            }            return null;	}	/**	 * Paint the current view's direction. Sets tmpPoint as a side-effect	 * such that the invoking method can use it to determine the	 * connection point to this decoration.	 */	protected Shape createLineEnd(int size, int style, Point src, Point dst) {		int d = (int) Math.max(1, dst.distance(src));		int ax = - (size * (dst.x - src.x) / d);		int ay = - (size * (dst.y - src.y) / d);		if (style == GraphConstants.ARROW_DIAMOND) {			Polygon poly = new Polygon();			poly.addPoint(dst.x, dst.y);			poly.addPoint(dst.x + ax / 2 + ay / 3, dst.y + ay / 2 - ax / 3);			Point last = new Point(dst);			dst.setLocation(dst.x + ax, dst.y + ay);			poly.addPoint(dst.x, dst.y);			poly.addPoint(last.x + ax / 2 - ay / 3, last.y + ay / 2 + ax / 3);			return poly;		} else if (			style == GraphConstants.ARROW_TECHNICAL				|| style == GraphConstants.ARROW_CLASSIC) {			Polygon poly = new Polygon();			poly.addPoint(dst.x, dst.y);			poly.addPoint(dst.x + ax + ay / 2, dst.y + ay - ax / 2);			Point last = new Point(dst);			if (style == GraphConstants.ARROW_CLASSIC) {				dst.setLocation(dst.x + ax * 2 / 3, dst.y + ay * 2 / 3);				poly.addPoint(dst.x, dst.y);			} else if (style == GraphConstants.ARROW_DIAMOND) {				dst.setLocation(dst.x + 2 * ax, dst.y + 2 * ay);				poly.addPoint(dst.x, dst.y);			} else				dst.setLocation(dst.x + ax, dst.y + ay);			poly.addPoint(last.x + ax - ay / 2, last.y + ay + ax / 2);			return poly;		} else if (style == GraphConstants.ARROW_SIMPLE) {			GeneralPath path = new GeneralPath(GeneralPath.WIND_NON_ZERO, 4);			path.moveTo(dst.x + ax + ay / 2, dst.y + ay - ax / 2);			path.lineTo(dst.x, dst.y);			path.lineTo(dst.x + ax - ay / 2, dst.y + ay + ax / 2);			return path;		} else if (style == GraphConstants.ARROW_CIRCLE) {			Ellipse2D ellipse =				new Ellipse2D.Float(					dst.x + ax / 2 - size / 2,					dst.y + ay / 2 - size / 2,					size,					size);			dst.setLocation(dst.x + ax, dst.y + ay);			return ellipse;		} else if (			style == GraphConstants.ARROW_LINE				|| style == GraphConstants.ARROW_DOUBLELINE) {			GeneralPath path = new GeneralPath(GeneralPath.WIND_NON_ZERO, 4);			path.moveTo(dst.x + ax / 2 + ay / 2, dst.y + ay / 2 - ax / 2);			path.lineTo(dst.x + ax / 2 - ay / 2, dst.y + ay / 2 + ax / 2);			if (style == GraphConstants.ARROW_DOUBLELINE) {				path.moveTo(dst.x + ax / 3 + ay / 2, dst.y + ay / 3 - ax / 2);				path.lineTo(dst.x + ax / 3 - ay / 2, dst.y + ay / 3 + ax / 2);			}			return path;		}		return null;	}	/**	 * Overridden for performance reasons.	 * See the <a href="#override">Implementation Note</a>	 * for more information.	 */	public void validate() {	}	/**	 * Overridden for performance reasons.	 * See the <a href="#override">Implementation Note</a>	 * for more information.	 */	public void revalidate() {	}	/**	 * Overridden for performance reasons.	 * See the <a href="#override">Implementation Note</a>	 * for more information.	 */	public void repaint(long tm, int x, int y, int width, int height) {	}	/**	 * Overridden for performance reasons.	 * See the <a href="#override">Implementation Note</a>	 * for more information.	 */	public void repaint(Rectangle r) {	}	/**	 * Overridden for performance reasons.	 * See the <a href="#override">Implementation Note</a>	 * for more information.	 */	protected void firePropertyChange(		String propertyName,		Object oldValue,		Object newValue) {		// Strings get interned...		if (propertyName == "text")			super.firePropertyChange(propertyName, oldValue, newValue);	}	/**	 * Overridden for performance reasons.	 * See the <a href="#override">Implementation Note</a>	 * for more information.	 */	public void firePropertyChange(		String propertyName,		byte oldValue,		byte newValue) {	}	/**	 * Overridden for performance reasons.	 * See the <a href="#override">Implementation Note</a>	 * for more information.	 */	public void firePropertyChange(		String propertyName,		char oldValue,		char newValue) {	}	/**	 * Overridden for performance reasons.	 * See the <a href="#override">Implementation Note</a>	 * for more information.	 */	public void firePropertyChange(		String propertyName,		short oldValue,		short newValue) {	}	/**	 * Overridden for performance reasons.	 * See the <a href="#override">Implementation Note</a>	 * for more information.	 */	public void firePropertyChange(		String propertyName,		int oldValue,		int newValue) {	}	/**	 * Overridden for performance reasons.	 * See the <a href="#override">Implementation Note</a>	 * for more information.	 */	public void firePropertyChange(		String propertyName,		long oldValue,		long newValue) {	}	/**	 * Overridden for performance reasons.	 * See the <a href="#override">Implementation Note</a>	 * for more information.	 */	public void firePropertyChange(		String propertyName,		float oldValue,		float newValue) {	}	/**	 * Overridden for performance reasons.	 * See the <a href="#override">Implementation Note</a>	 * for more information.	 */	public void firePropertyChange(		String propertyName,		double oldValue,		double newValue) {	}	/**	 * Overridden for performance reasons.	 * See the <a href="#override">Implementation Note</a>	 * for more information.	 */	public void firePropertyChange(		String propertyName,		boolean oldValue,		boolean newValue) {	}}

⌨️ 快捷键说明

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