1 package net.sf.mmapps.applications.developer.modules.appview;
2
3 import java.awt.*;
4 import java.awt.font.*;
5 import java.awt.geom.Rectangle2D;
6
7 import net.sf.mmapps.modules.config.*;
8
9 import com.touchgraph.graphlayout.*;
10 import org.apache.commons.logging.*;
11
12 /***
13 * @author Kees Jongenburger
14 * @version $Id: MMBaseEdge.java,v 1.2 2004/07/16 20:55:47 keesj Exp $
15 */
16 public class MMBaseEdge extends Edge {
17 private static Log log = LogFactory.getLog(MMBaseEdge.class);
18 int textWidth = -1;
19 int textHeight = -1;
20 int lineheight = -1;
21 int ascent = -1;
22 RelationManagerConfigurations relmans;
23
24 public MMBaseEdge(RelationManagerConfiguration relman, Node firstNode, Node secondNode) {
25 super(firstNode, secondNode);
26 relmans = new RelationManagerConfigurations();
27 relmans.add(relman);
28 setColor(javax.swing.plaf.metal.MetalLookAndFeel.getPrimaryControl());
29 };
30
31 public MMBaseEdge(RelationManagerConfiguration relman, Node firstNode, Node secondNode, int strength) {
32 super(firstNode, secondNode, strength);
33 relmans = new RelationManagerConfigurations();
34 relmans.add(relman);
35 setColor(javax.swing.plaf.metal.MetalLookAndFeel.getPrimaryControl());
36 };
37
38 public void addRelationManagerConfiguration(RelationManagerConfiguration c) {
39 relmans.add(c);
40 }
41
42 public void paint(Graphics graphics, TGPanel tgPanel) {
43 Graphics2D g = (Graphics2D) graphics;
44 Color c = javax.swing.plaf.metal.MetalLookAndFeel.getPrimaryControl();
45 g.setColor(c);
46 double x1 = from.drawx;
47 double y1 = from.drawy;
48 double x2 = to.drawx;
49 double y2 = to.drawy;
50 String data = null;
51 if (relmans.size() == 1) {
52 data = relmans.getRelationManagerConfiguration(0).getRelationTypeName();
53 } else {
54 data = "";
55 for (int x = 0; x < relmans.size(); x++) {
56 RelationManagerConfiguration relman = relmans.getRelationManagerConfiguration(x);
57 data += relman.getRelationTypeName();
58 if (x < relmans.size() - 1) {
59 data += ".";
60 }
61 }
62 }
63
64
65
66
67 Font f = g.getFont();
68 FontRenderContext frc = g.getFontRenderContext();
69 Rectangle2D rect = f.getStringBounds(data, frc);
70 textWidth = (int) rect.getWidth();
71 textHeight = (int) rect.getHeight();
72 LineMetrics metrics = f.getLineMetrics(data, frc);
73 lineheight = (int) metrics.getHeight();
74 ascent = (int) metrics.getAscent();
75
76 int x = (int) ((x1 + x2) / 2) - (textWidth / 2);
77 int y = (int) (y1 + y2) / 2 - (textHeight / 2);
78 if (from == to) {
79 log.debug("self relation from to type" + relmans);
80 g.drawOval((int) from.drawx - 50, (int) from.drawy -25 , 50, 50);
81 g.setColor(new Color(253, 255, 255));
82 g.fillRect(x - 25, y - textHeight - 25, textWidth, textHeight);
83 g.setColor(c);
84 g.drawString(data, x - 25, y - 25);
85 } else {
86 super.paint(g, tgPanel);
87 /***
88
89 double dy = y2 - y1;
90 double dx = x2 - x1;
91 double ctrl1x = x1;
92 double ctrl1y = y1 + dy /3;
93 double ctrl2x = x2;
94 double ctrl2y = y2 - dy/3;
95 //GeneralPath p = new GeneralPath(GeneralPath.WIND_EVEN_ODD);
96 GeneralPath p = new GeneralPath(GeneralPath.WIND_EVEN_ODD);
97 CubicCurve2D curve = new CubicCurve2D.Double(x1, y1, ctrl1x,ctrl1y, ctrl2x, ctrl2y, x2,y2);
98
99 p.append(curve,true);
100
101 CubicCurve2D curve2 = new CubicCurve2D.Double(x2, y2, ctrl2x, ctrl2y, ctrl1x + 10,ctrl1y, x1 + 10,y1);
102 p.append(curve2,true);
103 //p.moveTo(x1, y1);
104 p.lineTo((float)x1,(float) y1);
105 g.fill(p);
106 g.setColor(Color.black);
107 g.draw(p);
108 **/
109
110 if (!data.equals("related")) {
111 g.setColor(new Color(253, 253, 255));
112 g.fillRect(x, y - ascent, textWidth, textHeight);
113 g.setColor(c);
114 g.drawString(data, x, y);
115 }
116 }
117 g.setColor(c);
118 }
119 }