1
package figtree.treeviewer.painters;
3
import figtree.treeviewer.TreePane;
4
import jebl.evolution.graphs.Node;
5
import jebl.evolution.trees.RootedTree;
6
import jebl.evolution.trees.Tree;
9
import java.awt.geom.Point2D;
10
import java.awt.geom.Rectangle2D;
14
* @author Andrew Rambaut
15
* @version $Id: NodeShapePainter.java 536 2006-11-21 16:10:24Z rambaut $
17
public class NodeShapePainter extends NodePainter {
19
public static final String AREA_ATTRIBUTE = "area";
20
public static final String RADIUS_ATTRIBUTE = "radius";
22
public static final String WIDTH_ATTRIBUTE = "width";
23
public static final String HEIGHT_ATTRIBUTE = "height";
25
public static final String LOWER_ATTRIBUTE = "lower";
26
public static final String UPPER_ATTRIBUTE = "upper";
28
public enum NodeShape {
30
RECTANGLE("Rectangle");
32
NodeShape(String name) {
36
public String getName() {
40
public String toString() {
44
private final String name;
47
public NodeShapePainter() {
49
setupAttributes(null);
52
public void setupAttributes(Tree tree) {
53
java.util.List<String> attributeNames = new ArrayList<String>();
55
Set<String> nodeAttributes = new TreeSet<String>();
56
for (Node node : tree.getNodes()) {
57
nodeAttributes.addAll(node.getAttributeNames());
59
attributeNames.addAll(nodeAttributes);
62
this.attributes = new String[attributeNames.size()];
63
attributeNames.toArray(this.attributes);
65
firePainterSettingsChanged();
68
public void setTreePane(TreePane treePane) {
69
this.treePane = treePane;
72
public Rectangle2D calibrate(Graphics2D g2, Node item) {
73
RootedTree tree = treePane.getTree();
74
Point2D nodePoint = treePane.getTreeLayoutCache().getNodePoint(item);
79
return new Rectangle2D.Double(nodePoint.getX() - 10, nodePoint.getY() - 10, preferredWidth, preferredHeight);
82
public double getPreferredWidth() {
83
return preferredWidth;
86
public double getPreferredHeight() {
87
return preferredHeight;
90
public double getHeightBound() {
91
return preferredHeight;
95
* The bounds define the shape of the bar so just draw it
98
* @param justification
101
public void paint(Graphics2D g2, Node item, Justification justification, Rectangle2D bounds) {
102
if (getBackground() != null) {
103
g2.setPaint(getBackground());
107
if (getBorderPaint() != null && getBorderStroke() != null) {
108
g2.setPaint(getBorderPaint());
109
g2.setStroke(getBorderStroke());
115
public String[] getAttributeNames() {
119
public void setDisplayAttribute(String display, String attribute) {
120
displayAttributes.put(display, attribute);
121
firePainterChanged();
124
public void setDisplayValues(String display, double value) {
125
displayValues.put(display, new Double(value));
126
firePainterChanged();
129
private double preferredWidth;
130
private double preferredHeight;
132
protected Map<String, String> displayAttributes = new HashMap<String, String>();
133
protected Map<String, Number> displayValues = new HashMap<String, Number>();
134
protected String[] attributes;
136
protected TreePane treePane;