1 package net.sf.mmapps.applications.developer.modules.editor;
2
3 import java.awt.*;
4 import java.awt.geom.Rectangle2D;
5
6 import javax.swing.JPanel;
7
8 import net.sf.mmapps.modules.config.*;
9
10 /***
11 * @author Kees Jongenburger
12 * @version $Id: NodeManagerDrawingPanel.java,v 1.1.1.1 2004/02/06 08:44:07 keesj Exp $
13 **/
14 public class NodeManagerDrawingPanel extends JPanel {
15 NodeManagerConfiguration conf;
16 Configuration configuration;
17 String applicationName;
18
19 public NodeManagerDrawingPanel(
20 Configuration configuration,
21 String applicationName,
22 NodeManagerConfiguration nodeManagerConfiguration) {
23 super();
24 this.conf = nodeManagerConfiguration;
25 this.configuration = configuration;
26 this.applicationName = applicationName;
27 }
28
29 public void paint(Graphics g) {
30 update(g);
31 }
32
33 public static Dimension drawNodeManagerConfiguration(NodeManagerConfiguration conf, int x, int y, Graphics g) {
34 Font font = g.getFont();
35 g.setFont(new Font("Courrier", Font.BOLD, 10));
36 int myWidth = 150;
37
38 String data = conf.getName() + " extends " + conf.getExtends();
39 if (conf.getExtends().equals("object")) {
40 data = conf.getName();
41 }
42
43 Rectangle2D rect = g.getFontMetrics().getStringBounds(data, g);
44 int textWidth = (int) rect.getWidth();
45 if (textWidth > myWidth) {
46 x -= (textWidth - myWidth) / 2;
47 myWidth = textWidth;
48 }
49
50 FontMetrics fm = g.getFontMetrics();
51 int textHeight = fm.getHeight();
52
53 g.setColor(Color.white);
54 g.fillRect(x, y, myWidth, 2 + (textHeight + 2) * (1 + conf.getFieldConfigurations().size()));
55 g.setColor(Color.black);
56 g.drawRect(x, y, myWidth, 2 + (textHeight + 2) * (1 + conf.getFieldConfigurations().size()));
57
58 y += textHeight + 2;
59 g.drawString(data, x, y);
60
61 g.drawLine(x, y + 1, x + myWidth, y + 1);
62 FieldConfigurations fieldConfigurations = conf.getFieldConfigurations();
63 for (int i = 0; i < fieldConfigurations.size(); i++) {
64 FieldConfiguration fieldConfiguration = fieldConfigurations.getFieldConfiguration(i);
65 y += textHeight + 2;
66
67 Rectangle2D ff = g.getFontMetrics().getStringBounds(fieldConfiguration.getName(), g);
68 int fieldTextWidth = (int) ff.getWidth();
69 if (fieldTextWidth > myWidth) {
70 myWidth = fieldTextWidth;
71 }
72
73 String fieldType = fieldConfiguration.getType();
74 if (fieldType.equals("STRING")) {
75 g.setColor(Color.black);
76 } else if (fieldType.equals("INTEGER")) {
77 g.setColor(Color.blue);
78 } else if (fieldType.equals("XML")) {
79 g.setColor(Color.cyan);
80 } else if (fieldType.equals("BYTE")) {
81 g.setColor(Color.orange);
82 } else if (fieldType.equals("NODE")) {
83 g.setColor(Color.magenta);
84 } else {
85 g.setColor(Color.green);
86 }
87 g.drawString(fieldConfiguration.getName(), x , y);
88
89 }
90
91 g.setFont(font);
92 return new Dimension(myWidth, 2 + (textHeight + 2) * (1 + conf.getFieldConfigurations().size()));
93 }
94
95 public void update(Graphics g) {
96 int x = 150;
97 int y = 50;
98 Color color = g.getColor();
99 g.setColor(Color.white);
100 Dimension dim = getSize();
101 g.fillRect(0, 0, dim.width, dim.height);
102 g.setColor(color);
103
104 NodeManagerConfigurations parentConfigurations = new NodeManagerConfigurations();
105
106 NodeManagerConfiguration nmc = conf;
107
108 while (nmc != null && !nmc.getName().equals("object")) {
109
110 String parent = nmc.getExtends();
111 if (parent != null && !parent.trim().equals("")) {
112 nmc = configuration.getNodeManagerConfiguration(parent);
113 if (nmc != null) {
114 parentConfigurations.add(nmc);
115 }
116 }
117 }
118 int yIndent = 50;
119 for (int i = parentConfigurations.size() - 1; i >= 0; i--) {
120 Dimension compsize = drawNodeManagerConfiguration(parentConfigurations.getNodeManagerConfiguration(i), x, y, g);
121
122 y += (int) compsize.getHeight() + yIndent;
123 int midle =(int) (x + compsize.getWidth() /2 );
124
125 g.drawLine(midle, y - yIndent, midle, y);
126 }
127
128 drawNodeManagerConfiguration(conf, x, y, g);
129 paintComponents(g);
130 }
131 }