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

LineHitsSource
1 /*
2  * Copyright (c) 2005, the JUNG Project and the Regents of the University of
3  * California All rights reserved.
4  *
5  * This software is open-source under the BSD license; see either "license.txt"
6  * or http://jung.sourceforge.net/license.txt for a description.
7  *
8  * Created on Aug 1, 2005
9  */
10  
11 package edu.uci.ics.jung.graph.decorators;
12  
13 import java.awt.Image;
14 import java.awt.Shape;
15 import java.awt.geom.AffineTransform;
16 import java.util.HashMap;
17 import java.util.Map;
18  
19 import javax.swing.Icon;
20 import javax.swing.ImageIcon;
21  
22 import edu.uci.ics.jung.graph.Vertex;
23 import edu.uci.ics.jung.visualization.FourPassImageShaper;
24  
25 /**
26  * A default implementation that stores images in a Map keyed on the
27  * vertex. Also applies a shaping function to images to extract the
28  * shape of the opaque part of a transparent image.
29  *
30  * @author Tom Nelson - RABA Technologies
31  *
32  *
33  */public class VertexIconAndShapeFunction extends DefaultVertexIconFunction
34      implements VertexShapeFunction {
35      
360     protected Map shapeMap = new HashMap();
37      protected VertexShapeFunction delegate;
38      /**
39       *
40       *
41       */
420    public VertexIconAndShapeFunction(VertexShapeFunction delegate) {
430        this.delegate = delegate;
440    }
45  
46     /**
47      * @return Returns the delegate.
48      */
49     public VertexShapeFunction getDelegate() {
500        return delegate;
51     }
52  
53     /**
54      * @param delegate The delegate to set.
55      */
56     public void setDelegate(VertexShapeFunction delegate) {
570        this.delegate = delegate;
580    }
59  
60     /**
61      * get the shape from the image. If not available, get
62      * the shape from the delegate VertexShapeFunction
63      */
64     public Shape getShape(Vertex v) {
650        Icon icon = getIcon(v);
660        if (icon != null && icon instanceof ImageIcon) {
670            Image image = ((ImageIcon) icon).getImage();
680            Shape shape = (Shape) shapeMap.get(image);
690            if (shape == null) {
700                shape = FourPassImageShaper.getShape(image, 30);
710                if(shape.getBounds().getWidth() > 0 &&
72                         shape.getBounds().getHeight() > 0) {
73                     // don't cache a zero-sized shape, wait for the image
74                    // to be ready
750                    int width = image.getWidth(null);
760                    int height = image.getHeight(null);
770                    AffineTransform transform = AffineTransform
78                         .getTranslateInstance(-width / 2, -height / 2);
790                    shape = transform.createTransformedShape(shape);
800                    shapeMap.put(image, shape);
81                 }
82             }
830            return shape;
84         } else {
850            return delegate.getShape(v);
86         }
87  
88     }
89 }

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.