|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.uci.ics.jung.visualization.AbstractRenderer
edu.uci.ics.jung.visualization.PluggableRenderer
public class PluggableRenderer
A renderer with all sorts of buttons to press and dials to turn. Using the appropriate methods, the user can override the default properties/behaviors for vertex paint, stroke, shape, label, label font, and label centering; and for edge paint, stroke, label, arrows, label font, label positioning, and drawing.
Notes on these decorators:
SettableVertexShapeFunction
,
AbstractVertexShapeFunction
, VertexShapeFactory
, and the
sample samples.graph.PluggableRendererDemo
.
This class provides default Stroke
implementations for dotted and
dashed lines: the DOTTED
and DASHED
static constants,
respectively.
The EdgeArrowPredicate
specifies the edges for which arrows
should be drawn; the EdgeArrowFunction
specifies the shapes of
the arrowheads for those edges that pass the EdgeArrowPredicate
.
If the specified vertex inclusion Predicate
indicates that
vertex v
is not to be drawn, none of its incident edges will be drawn either.
By default, self-loops are drawn as circles.
By default, undirected edges are drawn as straight lines, directed edges are drawn as bent lines, and parallel edges are drawn on top of one another.
Arrowheads are drawn so that the point of the arrow is at the boundary of the vertex shapes. In the current implementation, finding the place where arrows are drawn is fairly slow; for large graphs, this should be turned off.
Setting a stroke width other than 1, or using transparency, may slow down rendering of the visualization.
Field Summary | |
---|---|
protected float |
arrow_placement_tolerance
|
protected boolean |
centerVertexLabel
|
static Stroke |
DASHED
A stroke for a dashed line: 1 pixel width, square caps, beveled joins, and an array of {5.0f}. |
protected static float[] |
dashing
|
static Stroke |
DOTTED
A stroke for a dotted line: 1 pixel width, round caps, round joins, and an array of {1.0f, 3.0f}. |
protected static float[] |
dotting
|
protected EdgeArrowFunction |
edgeArrowFunction
|
protected Predicate |
edgeArrowPredicate
|
protected EdgeFontFunction |
edgeFontFunction
|
protected Predicate |
edgeIncludePredicate
|
protected NumberEdgeValue |
edgeLabelClosenessFunction
|
protected EdgePaintFunction |
edgePaintFunction
|
protected EdgeShapeFunction |
edgeShapeFunction
|
protected EdgeStringer |
edgeStringer
|
protected EdgeStrokeFunction |
edgeStrokeFunction
|
protected GraphLabelRenderer |
graphLabelRenderer
A default GraphLabelRenderer - picked Vertex labels are blue, picked edge labels are cyan |
static int |
LABEL_OFFSET
Specifies the offset for the edge labels. |
protected static int |
MAX_ITERATIONS
Specifies the maximum number of iterations to run the edge subdivision loop in getLastOutsideSegment ; this is done to fix the arrow
orientation problem noted in bug report #1450529. |
protected ParallelEdgeIndexFunction |
parallelEdgeIndexFunction
|
protected CellRendererPane |
rendererPane
The CellRendererPane is used here just as it is in JTree and JTable, to allow a pluggable JLabel-based renderer for Vertex and Edge label strings and icons. |
protected JComponent |
screenDevice
the JComponent that this Renderer will display the graph on |
protected static EdgePredicate |
self_loop
|
protected VertexFontFunction |
vertexFontFunction
|
protected VertexIconFunction |
vertexIconFunction
|
protected Predicate |
vertexIncludePredicate
|
protected VertexPaintFunction |
vertexPaintFunction
|
protected VertexShapeFunction |
vertexShapeFunction
|
protected VertexStringer |
vertexStringer
|
protected VertexStrokeFunction |
vertexStrokeFunction
|
protected MutableTransformer |
viewTransformer
|
Constructor Summary | |
---|---|
PluggableRenderer()
|
Method Summary | |
---|---|
protected void |
drawSimpleEdge(Graphics2D g,
Edge e,
int x1,
int y1,
int x2,
int y2)
Draws the edge e , whose endpoints are at (x1,y1)
and (x2,y2) , on the graphics context g . |
AffineTransform |
getArrowTransform(GeneralPath edgeShape,
Shape vertexShape)
Returns a transform to position the arrowhead on this edge shape at the point where it intersects the passed vertex shape. |
AffineTransform |
getArrowTransform(Line2D edgeShape,
Shape vertexShape)
This is used for the arrow of a directed and for one of the arrows for non-directed edges Get a transform to place the arrow shape on the passed edge at the point where it intersects the passed shape |
EdgeArrowFunction |
getEdgeArrowFunction()
|
Predicate |
getEdgeArrowPredicate()
|
EdgeFontFunction |
getEdgeFontFunction()
|
Predicate |
getEdgeIncludePredicate()
|
NumberEdgeValue |
getEdgeLabelClosenessFunction()
|
EdgePaintFunction |
getEdgePaintFunction()
|
EdgeShapeFunction |
getEdgeShapeFunction()
|
EdgeStringer |
getEdgeStringer()
|
EdgeStrokeFunction |
getEdgeStrokeFunction()
|
protected Line2D |
getFirstOutsideSegment(Line2D line,
Shape shape)
Passed Line's point1 must be inside the passed shape or an IllegalArgumentException is thrown |
GraphLabelRenderer |
getGraphLabelRenderer()
|
protected Line2D |
getLastOutsideSegment(Line2D line,
Shape shape)
Passed Line's point2 must be inside the passed shape or an IllegalArgumentException is thrown |
ParallelEdgeIndexFunction |
getParallelEdgeIndexFunction()
|
CellRendererPane |
getRendererPane()
|
AffineTransform |
getReverseArrowTransform(GeneralPath edgeShape,
Shape vertexShape)
Returns a transform to position the arrowhead on this edge shape at the point where it intersects the passed vertex shape. |
AffineTransform |
getReverseArrowTransform(GeneralPath edgeShape,
Shape vertexShape,
boolean passedGo)
Returns a transform to position the arrowhead on this edge shape at the point where it intersects the passed vertex shape. |
protected AffineTransform |
getReverseArrowTransform(Line2D edgeShape,
Shape vertexShape)
This is used for the reverse-arrow of a non-directed edge get a transform to place the arrow shape on the passed edge at the point where it intersects the passed shape |
JComponent |
getScreenDevice()
|
VertexFontFunction |
getVertexFontFunction()
|
VertexIconFunction |
getVertexIconFunction()
|
Predicate |
getVertexIncludePredicate()
|
boolean |
getVertexLabelCentering()
|
VertexPaintFunction |
getVertexPaintFunction()
|
VertexShapeFunction |
getVertexShapeFunction()
Returns the VertexShapeFunction currently being
used by this instance. |
VertexStringer |
getVertexStringer()
|
VertexStrokeFunction |
getVertexStrokeFunction()
|
boolean |
isPicked(ArchetypeEdge e)
Deprecated. Use an independent PickedInfo instead of this version, which relies on the Renderer to supply an instance. |
boolean |
isPicked(ArchetypeVertex v)
Deprecated. Use an independent PickedInfo instead of this version, which relies on the Renderer to supply an instance. |
protected void |
labelEdge(Graphics2D g2d,
Edge e,
String label,
int x1,
int x2,
int y1,
int y2)
Labels the specified non-self-loop edge with the specified label. |
protected void |
labelVertex(Graphics g,
Vertex v,
String label,
int x,
int y)
Labels the specified vertex with the specified label. |
void |
paintEdge(Graphics g,
Edge e,
int x1,
int y1,
int x2,
int y2)
Paints e , whose endpoints are at (x1,y1)
and (x2,y2) , on the graphics context g . |
void |
paintIconForVertex(Graphics g,
Vertex v,
int x,
int y)
Paint v 's icon on g at (x,y) . |
void |
paintShapeForVertex(Graphics2D g2d,
Vertex v,
Shape shape)
|
void |
paintVertex(Graphics g,
Vertex v,
int x,
int y)
Paints the vertex v at the location (x,y)
on the graphics context g_gen . |
Component |
prepareRenderer(GraphLabelRenderer renderer,
Object value,
boolean isSelected,
Edge edge)
|
Component |
prepareRenderer(GraphLabelRenderer graphLabelRenderer,
Object value,
boolean isSelected,
Vertex vertex)
|
void |
setArrowPlacementTolerance(float tolerance)
Specifies the smallest (squared) distance that an arrowhead must be moved in order for the placement code to decide that it's "close enough". |
void |
setEdgeArrowFunction(EdgeArrowFunction eaf)
Sets the EdgeArrowFunction that specifies the
Shape of the arrowheads for each edge. |
void |
setEdgeArrowPredicate(Predicate p)
Sets the EdgeArrowPredicate that specifies whether
arrowheads should be drawn for each edge. |
void |
setEdgeColorFunction(EdgeColorFunction ecf)
Deprecated. Use setEdgePaintFunction instead |
void |
setEdgeFontFunction(EdgeFontFunction eff)
Sets the EdgeFontFunction that specifies the font
to use for drawing each edge label. |
void |
setEdgeIncludePredicate(Predicate p)
Sets the Predicate that specifies whether each
edge should be drawn; only those edges for which this
predicate returns true will be drawn. |
void |
setEdgeLabelClosenessFunction(NumberEdgeValue nev)
Sets the NumberEdgeValue that specifies where to draw
the label for each edge. |
void |
setEdgePaintFunction(EdgePaintFunction impl)
|
void |
setEdgeShapeFunction(EdgeShapeFunction impl)
setter for the EdgeShapeFunction |
void |
setEdgeStringer(EdgeStringer es)
Sets the EdgeStringer that specifies the label to
draw for each edge. |
void |
setEdgeStrokeFunction(EdgeStrokeFunction esf)
Sets the EdgeStrokeFunction that specifies the
Stroke to use when drawing each edge. |
void |
setGraphLabelRenderer(GraphLabelRenderer graphLabelRenderer)
|
void |
setParallelEdgeIndexFunction(ParallelEdgeIndexFunction parallelEdgeIndexFunction)
|
void |
setRendererPane(CellRendererPane rendererPane)
|
void |
setScreenDevice(JComponent screenDevice)
The screen device is the JComponent on which the renderer will display the graph. |
void |
setVertexColorFunction(VertexColorFunction vcf)
Deprecated. Use setVertexPaintFunction with a VertexPaintFunction if you can |
void |
setVertexFontFunction(VertexFontFunction vff)
Sets the VertexFontFunction that specifies the font
to use for drawing each vertex label. |
void |
setVertexIconFunction(VertexIconFunction vertexIconFunction)
|
void |
setVertexIncludePredicate(Predicate p)
Sets the Predicate that specifies whether each
vertex should be drawn; only those vertices for which this
predicate returns true will be drawn. |
void |
setVertexLabelCentering(boolean b)
Specifies whether vertex labels are drawn centered on the vertex position ( true ) or offset to one side (false ). |
void |
setVertexPaintFunction(VertexPaintFunction vpf)
Sets the VertexPaintFunction which specifies the
draw (border and text) and fill (interior) Paint for each vertex. |
void |
setVertexShapeFunction(VertexShapeFunction vsf)
Sets the VertexShapeFunction ,
which specifies the Shape for each vertex. |
void |
setVertexStringer(VertexStringer vs)
Sets the VertexStringer that specifies the label to
draw for each vertex. |
void |
setVertexStrokeFunction(VertexStrokeFunction vsf)
Sets the VertexStrokeFunction which
specifies the Stroke to use when drawing
each vertex border. |
void |
setViewTransformer(MutableTransformer viewTransformer)
|
protected void |
subdivide(Line2D src,
Line2D left,
Line2D right)
divide a Line2D into 2 new Line2Ds that are returned in the passed left and right instances, if non-null |
Methods inherited from class edu.uci.ics.jung.visualization.AbstractRenderer |
---|
getPickedKey, setPickedKey |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected float arrow_placement_tolerance
protected static final float[] dotting
public static final Stroke DOTTED
protected static final float[] dashing
public static final Stroke DASHED
public static final int LABEL_OFFSET
protected static final int MAX_ITERATIONS
getLastOutsideSegment
; this is done to fix the arrow
orientation problem noted in bug report #1450529.
protected Predicate vertexIncludePredicate
protected VertexStrokeFunction vertexStrokeFunction
protected VertexShapeFunction vertexShapeFunction
protected VertexStringer vertexStringer
protected VertexIconFunction vertexIconFunction
protected VertexFontFunction vertexFontFunction
protected boolean centerVertexLabel
protected VertexPaintFunction vertexPaintFunction
protected EdgeStringer edgeStringer
protected EdgeStrokeFunction edgeStrokeFunction
protected EdgeArrowFunction edgeArrowFunction
protected Predicate edgeArrowPredicate
protected Predicate edgeIncludePredicate
protected EdgeFontFunction edgeFontFunction
protected NumberEdgeValue edgeLabelClosenessFunction
protected EdgeShapeFunction edgeShapeFunction
protected EdgePaintFunction edgePaintFunction
protected ParallelEdgeIndexFunction parallelEdgeIndexFunction
protected MutableTransformer viewTransformer
protected JComponent screenDevice
protected CellRendererPane rendererPane
protected GraphLabelRenderer graphLabelRenderer
protected static final EdgePredicate self_loop
Constructor Detail |
---|
public PluggableRenderer()
Method Detail |
---|
public EdgeArrowFunction getEdgeArrowFunction()
public Predicate getEdgeArrowPredicate()
public EdgeFontFunction getEdgeFontFunction()
public Predicate getEdgeIncludePredicate()
public NumberEdgeValue getEdgeLabelClosenessFunction()
public EdgePaintFunction getEdgePaintFunction()
public EdgeStringer getEdgeStringer()
public EdgeStrokeFunction getEdgeStrokeFunction()
public JComponent getScreenDevice()
public VertexFontFunction getVertexFontFunction()
public Predicate getVertexIncludePredicate()
public VertexPaintFunction getVertexPaintFunction()
public VertexStringer getVertexStringer()
public VertexIconFunction getVertexIconFunction()
public void setVertexIconFunction(VertexIconFunction vertexIconFunction)
vertexIconFunction
- The VertexIconFunction to set.public VertexStrokeFunction getVertexStrokeFunction()
public void setScreenDevice(JComponent screenDevice)
screenDevice
- public void setArrowPlacementTolerance(float tolerance)
public void setEdgeArrowFunction(EdgeArrowFunction eaf)
EdgeArrowFunction
that specifies the
Shape
of the arrowheads for each edge.
The same shape will be used for both ends of an undirected
edge. The default arrow-drawing implementations assume that arrows
are drawn with their base on the y-axis, pointed left (in the negative
x-direction), centered on the x-axis.
Note that the EdgeArrowFunction
must return a valid shape
for any edge for which the edge arrow Predicate
returns true
.
DirectionalEdgeArrowFunction
)
edu.uci.ics.jung.decorators.EdgeArrowFunction
,
ArrowFactory
public GraphLabelRenderer getGraphLabelRenderer()
public void setGraphLabelRenderer(GraphLabelRenderer graphLabelRenderer)
graphLabelRenderer
- The graphLabelRenderer to set.public void setEdgeArrowPredicate(Predicate p)
EdgeArrowPredicate
that specifies whether
arrowheads should be drawn for each edge. If the predicate evaluates
to true
for a specified edge, arrows should be drawn
for that edge.
Graph.DIRECTED_EDGE
instance)
EdgeArrowFunction
public void setEdgeColorFunction(EdgeColorFunction ecf)
EdgeColorFunction
that specifies the paint to
draw each edge.
Color
public void setEdgeFontFunction(EdgeFontFunction eff)
EdgeFontFunction
that specifies the font
to use for drawing each edge label. This can be used (for example) to
emphasize (or to de-emphasize) edges that have a specific property.
EdgeFontFunction
public void setEdgeIncludePredicate(Predicate p)
Predicate
that specifies whether each
edge should be drawn; only those edges for which this
predicate returns true
will be drawn. This can be
used to selectively display only those edges that have a
specific property, such as a particular decoration or value, or
only those edges of a specific type (such as directed edges,
or everything except self-loops).
TruePredicate
instance)
Predicate
public void setEdgeLabelClosenessFunction(NumberEdgeValue nev)
NumberEdgeValue
that specifies where to draw
the label for each edge. A value of 0 draws the label on top of
the edge's first vertex; a value of 1.0 draws the label on top
of the edge's second vertex; values between 0 and 1 split the
difference (i.e., a value of 0.5 draws the label halfway in between
the two vertices). The effect of values outside the range [0,1]
is undefined. This function is not used for self-loops.
ConstantDirectionalEdgeValue
)
NumberEdgeValue
public void setEdgePaintFunction(EdgePaintFunction impl)
impl
- public void setEdgeShapeFunction(EdgeShapeFunction impl)
impl
- public EdgeShapeFunction getEdgeShapeFunction()
getEdgeShapeFunction
in interface HasShapeFunctions
public void setEdgeStringer(EdgeStringer es)
EdgeStringer
that specifies the label to
draw for each edge.
ConstantEdgeStringer
)
EdgeStringer
public void setEdgeStrokeFunction(EdgeStrokeFunction esf)
EdgeStrokeFunction
that specifies the
Stroke
to use when drawing each edge.
ConstantEdgeStrokeFunction
)
Stroke
,
EdgeStrokeFunction
public void setVertexColorFunction(VertexColorFunction vcf)
Sets the VertexPaintFunction
to the parameter
setVertexPaintFunction(VertexPaintFunction)
,
VertexColorFunction
,
VertexColorToVertexPaintConverter
public void setVertexPaintFunction(VertexPaintFunction vpf)
Sets the VertexPaintFunction
which specifies the
draw (border and text) and fill (interior) Paint for each vertex.
If users want the VertexPaintFunction
implementation
to highlight selected vertices, they should take this
PluggableRenderer instance as a constructor parameter, and call
the isPicked
method on it to identify selected vertices.
Default: black borders, red foreground (selected vertex is orange).
public VertexShapeFunction getVertexShapeFunction()
VertexShapeFunction
currently being
used by this instance.
getVertexShapeFunction
in interface HasShapeFunctions
public void setVertexFontFunction(VertexFontFunction vff)
VertexFontFunction
that specifies the font
to use for drawing each vertex label. This can be used (for example) to
emphasize (or to de-emphasize) vertices that have a specific property.
VertexFontFunction
public void setVertexIncludePredicate(Predicate p)
Predicate
that specifies whether each
vertex should be drawn; only those vertices for which this
predicate returns true
will be drawn. This can be
used to selectively display only those vertices that have a
specific property, such as a particular decoration or value.
TruePredicate
instance)
Predicate
public void setVertexLabelCentering(boolean b)
true
) or offset to one side (false
).
public boolean getVertexLabelCentering()
public void setVertexShapeFunction(VertexShapeFunction vsf)
VertexShapeFunction
,
which specifies the Shape
for each vertex.
Users that wish to independently change the size and
aspect ratio of a vertex's shape should take a look
at the SettableVertexShapeFunction
interface and the AbstractVertexShapeFunction
abstract class.
EllipseVertexShapeFunction
)
Shape
,
VertexShapeFunction
public void setVertexStringer(VertexStringer vs)
VertexStringer
that specifies the label to
draw for each vertex.
ConstantVertexStringer
)
VertexStringer
public void setVertexStrokeFunction(VertexStrokeFunction vsf)
VertexStrokeFunction
which
specifies the Stroke
to use when drawing
each vertex border.
Stroke
,
VertexStrokeFunction
public void paintEdge(Graphics g, Edge e, int x1, int y1, int x2, int y2)
e
, whose endpoints are at (x1,y1)
and (x2,y2)
, on the graphics context g
.
Uses the paint and stroke specified by this instance's
EdgeColorFunction
and EdgeStrokeFunction
,
respectively. (If the paint is unspecified, the existing
paint for the graphics context is used; the same applies to stroke.)
The details of the actual rendering are delegated to
drawSelfLoop
or drawSimpleEdge
,
depending on the type of the edge.
Note that (x1, y1)
is the location of
e.getEndpoints.getFirst() and (x2, y2)
is the location of
e.getEndpoints.getSecond().
paintEdge
in interface Renderer
paintEdge
in class AbstractRenderer
protected void drawSimpleEdge(Graphics2D g, Edge e, int x1, int y1, int x2, int y2)
e
, whose endpoints are at (x1,y1)
and (x2,y2)
, on the graphics context g
.
The Shape
provided by the EdgeShapeFunction
instance
is scaled in the x-direction so that its width is equal to the distance between
(x1,y1)
and (x2,y2)
.
public AffineTransform getArrowTransform(GeneralPath edgeShape, Shape vertexShape)
public AffineTransform getReverseArrowTransform(GeneralPath edgeShape, Shape vertexShape)
public AffineTransform getReverseArrowTransform(GeneralPath edgeShape, Shape vertexShape, boolean passedGo)
Returns a transform to position the arrowhead on this edge shape at the point where it intersects the passed vertex shape.
The Loop edge is a special case because its staring point is not inside the vertex. The passedGo flag handles this case.
edgeShape
- vertexShape
- passedGo
- - used only for Loop edgespublic AffineTransform getArrowTransform(Line2D edgeShape, Shape vertexShape)
edgeShape
- vertexShape
-
protected AffineTransform getReverseArrowTransform(Line2D edgeShape, Shape vertexShape)
edgeShape
- vertexShape
-
protected Line2D getLastOutsideSegment(Line2D line, Shape shape)
line
- line to subdivideshape
- shape to compare with line
IllegalArgumentException
- if the passed line's point1 is not inside the shapeprotected Line2D getFirstOutsideSegment(Line2D line, Shape shape)
line
- line to subdivideshape
- shape to compare with line
IllegalArgumentException
- if the passed line's point1 is not inside the shapeprotected void subdivide(Line2D src, Line2D left, Line2D right)
src
- the line to divideleft
- the left side, or nullright
- the right side, or nullpublic Component prepareRenderer(GraphLabelRenderer graphLabelRenderer, Object value, boolean isSelected, Vertex vertex)
public Component prepareRenderer(GraphLabelRenderer renderer, Object value, boolean isSelected, Edge edge)
protected void labelEdge(Graphics2D g2d, Edge e, String label, int x1, int x2, int y1, int y2)
EdgeFontFunction
. (If the font is unspecified, the existing
font for the graphics context is used.) Positions the
label between the endpoints according to the coefficient returned
by this instance's edge label closeness function.
public void paintVertex(Graphics g, Vertex v, int x, int y)
v
at the location (x,y)
on the graphics context g_gen
. The vertex is painted
using the shape returned by this instance's VertexShapeFunction
,
and the foreground and background (border) colors provided by this
instance's VertexColorFunction
. Delegates drawing the
label (if any) for this vertex to labelVertex
.
paintVertex
in interface Renderer
paintVertex
in class AbstractRenderer
public void paintShapeForVertex(Graphics2D g2d, Vertex v, Shape shape)
public void paintIconForVertex(Graphics g, Vertex v, int x, int y)
v
's icon on g
at (x,y)
.
protected void labelVertex(Graphics g, Vertex v, String label, int x, int y)
VertexFontFunction
. (If the font is unspecified, the existing
font for the graphics context is used.) If vertex label centering
is active, the label is centered on the position of the vertex; otherwise
the label is offset slightly.
public boolean isPicked(ArchetypeVertex v)
isPicked
in interface PickedInfo
isPicked
in class AbstractRenderer
AbstractRenderer#isPicked(Vertex)
public boolean isPicked(ArchetypeEdge e)
isPicked
in interface PickedInfo
isPicked
in class AbstractRenderer
AbstractRenderer#isPicked(Edge)
public CellRendererPane getRendererPane()
public void setRendererPane(CellRendererPane rendererPane)
rendererPane
- The rendererPane to set.public ParallelEdgeIndexFunction getParallelEdgeIndexFunction()
public void setParallelEdgeIndexFunction(ParallelEdgeIndexFunction parallelEdgeIndexFunction)
public void setViewTransformer(MutableTransformer viewTransformer)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |