From e52a400a3fe213620fffeb84f44a4a02d05ba62d Mon Sep 17 00:00:00 2001 From: Walter Korman Date: Sat, 15 Jun 2002 02:13:11 +0000 Subject: [PATCH] Allow specifying the color and stroke with which an edge is to be rendered. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1468 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- src/java/com/threerings/nodemap/Edge.java | 28 ++++++++++++++++++- .../nodemap/direction/DirectionalEdge.java | 24 ++++++++++------ 2 files changed, 42 insertions(+), 10 deletions(-) diff --git a/src/java/com/threerings/nodemap/Edge.java b/src/java/com/threerings/nodemap/Edge.java index 4e7e3db5d..842f92e6c 100644 --- a/src/java/com/threerings/nodemap/Edge.java +++ b/src/java/com/threerings/nodemap/Edge.java @@ -1,9 +1,11 @@ // -// $Id: Edge.java,v 1.2 2002/06/15 01:59:12 shaper Exp $ +// $Id: Edge.java,v 1.3 2002/06/15 02:13:11 shaper Exp $ package com.threerings.nodemap; +import java.awt.Color; import java.awt.Graphics; +import java.awt.Stroke; /** * The edge class represents an edge connecting two nodes. @@ -35,6 +37,24 @@ public abstract class Edge */ public abstract void paint (Graphics g); + /** + * Sets the color used to render the edge, or null (the + * default) to use the current graphics context color. + */ + public void setColor (Color color) + { + _color = color; + } + + /** + * Sets the stroke used to render the edge, or null (the + * default) to use the current graphics context stroke. + */ + public void setStroke (Stroke stroke) + { + _stroke = stroke; + } + /** * Return a string representation of this edge. */ @@ -55,4 +75,10 @@ public abstract class Edge buf.append("src=").append(src); buf.append(", dst=").append(dst); } + + /** The edge color. */ + protected Color _color; + + /** The edge stroke. */ + protected Stroke _stroke; } diff --git a/src/java/com/threerings/nodemap/direction/DirectionalEdge.java b/src/java/com/threerings/nodemap/direction/DirectionalEdge.java index c03dba137..eff4151a0 100644 --- a/src/java/com/threerings/nodemap/direction/DirectionalEdge.java +++ b/src/java/com/threerings/nodemap/direction/DirectionalEdge.java @@ -1,10 +1,11 @@ // -// $Id: DirectionalEdge.java,v 1.4 2001/12/17 03:34:04 mdb Exp $ +// $Id: DirectionalEdge.java,v 1.5 2002/06/15 02:13:11 shaper Exp $ package com.threerings.nodemap.direction; -import java.awt.Color; +import java.awt.Graphics2D; import java.awt.Graphics; +import java.awt.Stroke; import com.threerings.util.DirectionCodes; @@ -35,14 +36,17 @@ public class DirectionalEdge extends Edge this.dir = dir; } - /** - * Render the edge to the given graphics context. - * - * @param g the graphics context. - */ + // documentation inherited public void paint (Graphics g) { - g.setColor(Color.black); + Graphics2D gfx = (Graphics2D)g; + Stroke ostroke = gfx.getStroke(); + if (_stroke != null) { + gfx.setStroke(_stroke); + } + if (_color != null) { + gfx.setColor(_color); + } int sx = src.getX(), sy = src.getY(); int dx = dst.getX(), dy = dst.getY(); @@ -53,9 +57,11 @@ public class DirectionalEdge extends Edge int cdx = dx + (dst.getWidth() / 2); int cdy = dy + (dst.getHeight() / 2); - g.drawLine(csx, csy, cdx, cdy); + gfx.drawLine(csx, csy, cdx, cdy); + gfx.setStroke(ostroke); } + // documentation inherited public void toString (StringBuffer buf) { super.toString(buf);