1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
package com.c2kernel.collection.gui.view;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import com.c2kernel.collection.Aggregation;
import com.c2kernel.collection.AggregationMember;
import com.c2kernel.graph.model.GraphPoint;
import com.c2kernel.graph.model.Vertex;
import com.c2kernel.graph.view.VertexRenderer;
import com.c2kernel.utils.Logger;
/**
* @version $Revision: 1.24 $ $Date: 2005/12/01 14:23:15 $
* @author $Author: abranson $
*/
public class AggregationMemberRenderer implements VertexRenderer
{
private Aggregation mAggregation = null;
public AggregationMemberRenderer()
{
}
public void setAggregation(Aggregation agg)
{
mAggregation = agg;
}
public void draw(Graphics2D g2d, Vertex vertex)
{
GraphPoint centre = vertex.getCentrePoint();
GraphPoint[] outline = vertex.getOutlinePoints();
FontMetrics metrics = g2d.getFontMetrics();
AggregationMember memberPair = mAggregation.getMemberPair(vertex.getID());
try
{
String name = memberPair.getEntityName();
g2d.drawString( name,
centre.x-metrics.stringWidth(name)/2,
topYOfOutline(outline) );
g2d.drawImage
(
memberPair.getImage(),
centre.x - 8,
centre.y - 8,
null
);
// Draw the outline of the vertex
if(outline.length > 1)
{
for(int i=0; i<outline.length-1; i++)
{
g2d.drawLine
(
outline[i].x,
outline[i].y,
outline[i+1].x,
outline[i+1].y
);
}
g2d.drawLine
(
outline[outline.length-1].x,
outline[outline.length-1].y,
outline[0].x,
outline[0].y
);
}
}
catch (Exception ex)
{
Logger.error("AggregationMemberRenderer::draw() " + ex);
}
}
int topYOfOutline(GraphPoint[] outline)
{
int topY = outline[0].y;
int i = 0;
for(i=1; i<outline.length; i++)
{
if(outline[i].y < topY)
{
topY = outline[i].y;
}
}
return topY;
}
int bottomYOfOutline(GraphPoint[] outline)
{
int bottomY = outline[0].y;
int i = 0;
for(i=1; i<outline.length; i++)
{
if(outline[i].y > bottomY)
{
bottomY = outline[i].y;
}
}
return bottomY;
}
}
|