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
This commit is contained in:
Walter Korman
2002-06-15 02:13:11 +00:00
parent 5599b715df
commit e52a400a3f
2 changed files with 42 additions and 10 deletions
+27 -1
View File
@@ -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 <code>null</code> (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 <code>null</code> (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;
}
@@ -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);