Coverage details for edu.uci.ics.jung.graph.decorators.GradientEdgePaintFunction

LineHitsSource
1 /*
2  * Created on Apr 8, 2005
3  *
4  * Copyright (c) 2004, the JUNG Project and the Regents of the University
5  * of California
6  * All rights reserved.
7  *
8  * This software is open-source under the BSD license; see either
9  * "license.txt" or
10  * http://jung.sourceforge.net/license.txt for a description.
11  */
12 package edu.uci.ics.jung.graph.decorators;
13  
14 import java.awt.Color;
15 import java.awt.GradientPaint;
16 import java.awt.Paint;
17 import java.awt.geom.Point2D;
18  
19 import edu.uci.ics.jung.graph.Edge;
20 import edu.uci.ics.jung.graph.UndirectedEdge;
21 import edu.uci.ics.jung.graph.Vertex;
22 import edu.uci.ics.jung.utils.Pair;
23 import edu.uci.ics.jung.visualization.HasGraphLayout;
24 import edu.uci.ics.jung.visualization.Layout;
25 import edu.uci.ics.jung.visualization.transform.LayoutTransformer;
26  
27 /**
28  * Creates <code>GradientPaint</code> instances which can be used
29  * to paint an <code>Edge</code>. For <code>DirectedEdge</code>s,
30  * the color will blend from <code>c1</code> (source) to
31  * <code>c2</code> (destination); for <code>UndirectedEdge</code>s,
32  * the color will be <code>c1</code> at each end and <code>c2</code>
33  * in the middle.
34  *
35  * @author Joshua O'Madadhain
36  */
37 public class GradientEdgePaintFunction extends AbstractEdgePaintFunction
38 {
39     protected Color c1;
40     protected Color c2;
41     HasGraphLayout vv;
42     LayoutTransformer transformer;
43     
44     public GradientEdgePaintFunction(Color c1, Color c2,
45             HasGraphLayout vv, LayoutTransformer transformer)
460    {
470        this.c1 = c1;
480        this.c2 = c2;
490        this.vv = vv;
500        this.transformer = transformer;
510    }
52     
53     public Paint getDrawPaint(Edge e)
54     {
550        Layout layout = vv.getGraphLayout();
560        Pair p = e.getEndpoints();
570        Vertex b = (Vertex)p.getFirst();
580        Vertex f = (Vertex)p.getSecond();
590        Point2D pb = transformer.layoutTransform(layout.getLocation(b));
600        Point2D pf = transformer.layoutTransform(layout.getLocation(f));
610        float xB = (float) pb.getX();
620        float yB = (float) pb.getY();
630        float xF = (float) pf.getX();
640        float yF = (float) pf.getY();
650        if (e instanceof UndirectedEdge )
66         {
670            xF = (xF + xB) / 2;
680            yF = (yF + yB) / 2;
69         }
700        if(xB == xF && yB == yF)
71         {
72             // hack so loop edges don't 'vanish'
730            xB -= 10;
740            yB -= 10;
750            xF += 10;
760            yF += 10;
77         }
78  
790        return new GradientPaint(xB, yB, getColor1(e), xF, yF, getColor2(e), true);
80     }
81     
82     /**
83      * Returns <code>c1</code>. Subclasses may override
84      * this method to enable more complex behavior (e.g., for
85      * picked edges).
86      */
87     protected Color getColor1(Edge e)
88     {
890        return c1;
90     }
91  
92     /**
93      * Returns <code>c2</code>. Subclasses may override
94      * this method to enable more complex behavior (e.g., for
95      * picked edges).
96      */
97     protected Color getColor2(Edge e)
98     {
990        return c2;
100     }
101 }

this report was generated by version 1.0.5 of jcoverage.
visit www.jcoverage.com for updates.

copyright © 2003, jcoverage ltd. all rights reserved.
Java is a trademark of Sun Microsystems, Inc. in the United States and other countries.