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

Line | Hits | Source
--- | --- | ---
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 |  | ``
36 | 0 | `protected Map shapeMap = new HashMap();`
37 |  | `protected VertexShapeFunction delegate;`
38 |  | `/**`
39 |  | `*`
40 |  | `*`
41 |  | `*/`
42 | 0 | `public VertexIconAndShapeFunction(VertexShapeFunction delegate) {`
43 | 0 | `this.delegate = delegate;`
44 | 0 | `}`
45 |  | ``
46 |  | `/**`
47 |  | `* @return Returns the delegate.`
48 |  | `*/`
49 |  | `public VertexShapeFunction getDelegate() {`
50 | 0 | `return delegate;`
51 |  | `}`
52 |  | ``
53 |  | `/**`
54 |  | `* @param delegate The delegate to set.`
55 |  | `*/`
56 |  | `public void setDelegate(VertexShapeFunction delegate) {`
57 | 0 | `this.delegate = delegate;`
58 | 0 | `}`
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) {`
65 | 0 | `Icon icon = getIcon(v);`
66 | 0 | `if (icon != null && icon instanceof ImageIcon) {`
67 | 0 | `Image image = ((ImageIcon) icon).getImage();`
68 | 0 | `Shape shape = (Shape) shapeMap.get(image);`
69 | 0 | `if (shape == null) {`
70 | 0 | `shape = FourPassImageShaper.getShape(image, 30);`
71 | 0 | `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`
75 | 0 | `int width = image.getWidth(null);`
76 | 0 | `int height = image.getHeight(null);`
77 | 0 | `AffineTransform transform = AffineTransform`
78 |  | `.getTranslateInstance(-width / 2, -height / 2);`
79 | 0 | `shape = transform.createTransformedShape(shape);`
80 | 0 | `shapeMap.put(image, shape);`
81 |  | `}`
82 |  | `}`
83 | 0 | `return shape;`
84 |  | `} else {`
85 | 0 | `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.