KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > fractal > gui > status > view > BasicStatusView


1 /***
2  * FractalGUI: a graphical tool to edit Fractal component configurations.
3  * Copyright (C) 2003 France Telecom R&D
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Contact: fractal@objectweb.org
20  *
21  * Authors: Eric Bruneton, Patrice Fauvel
22  */

23
24 package org.objectweb.fractal.gui.status.view;
25
26 import org.objectweb.fractal.gui.graph.view.ComponentPart;
27 import org.objectweb.fractal.gui.graph.view.GraphViewListener;
28 import org.objectweb.fractal.gui.model.Component;
29 import org.objectweb.fractal.gui.model.Interface;
30 import org.objectweb.fractal.swing.JPanelImpl;
31 import org.objectweb.fractal.gui.Constants;
32
33 import java.awt.Color JavaDoc;
34 import java.awt.Dimension JavaDoc;
35 import java.awt.Font JavaDoc;
36 import java.awt.event.MouseEvent JavaDoc;
37
38 import javax.swing.BorderFactory JavaDoc;
39 import javax.swing.JLabel JavaDoc;
40
41 /**
42  * A configuration view that displays the status of the current component or
43  * interface. The "current" component or interface is the component or interface
44  * above which the cursor is. In order to know this component or interface, this
45  * component listens to a graph view.
46  */

47
48 public class BasicStatusView extends JPanelImpl implements GraphViewListener {
49
50   /**
51    * Font used to draw the captions.
52    */

53
54   private final static Font JavaDoc CAPTION_FONT =
55     new Font JavaDoc("Arial", Font.BOLD, 12);
56
57   /**
58    * Font used to draw the status of components and interfaces.
59    */

60
61   private final static Font JavaDoc STATUS_FONT =
62     new Font JavaDoc("courier", Font.PLAIN, 12);
63
64   /**
65    * The label that displays the current component's name.
66    */

67
68   private JLabel JavaDoc componentName;
69
70   /**
71    * The label that displays the current component's type.
72    */

73
74   private JLabel JavaDoc componentType;
75
76   /**
77    * The label that displays the current interface's name.
78    */

79
80   private JLabel JavaDoc interfaceName;
81
82   /**
83    * The label that displays the current interface's type.
84    */

85
86   private JLabel JavaDoc interfaceType;
87
88   /**
89    * The configuration status to be dispayed, if any
90    */

91
92   private JLabel JavaDoc statusstring;
93
94   /**
95    * The execution directory to be dispayed, if any
96    */

97
98   private JLabel JavaDoc jlabexec;
99
100   /**
101    * "Empty" strings for display in order to keep a minimum size.
102    */

103
104   private String JavaDoc EMPTY = "<EMPTY> ";
105   private String JavaDoc WHITE = " ";
106
107   private Color JavaDoc color = Color.black;
108
109   /**
110    * Constructs a new {@link BasicStatusView} component.
111    */

112
113   public BasicStatusView () {
114     color = new Color JavaDoc (0, 0, 64);
115
116     // TODO remove all hardcoded coordinates, font sizes, ...
117

118     JLabel JavaDoc labcomponentName = createLabel("Component name:",
119       0, 110, CAPTION_FONT);
120     JLabel JavaDoc labcomponentType = createLabel("component type:",
121       0, 110, CAPTION_FONT);
122     JLabel JavaDoc labinterfaceName = createLabel("Interface name:",
123       0, 110, CAPTION_FONT);
124     JLabel JavaDoc labinterfaceType = createLabel("Interface type:",
125       0, 110, CAPTION_FONT);
126     JLabel JavaDoc labstatusstring = createLabel("Status:",
127       0, 110, CAPTION_FONT);
128
129     color = Color.black;
130     componentName = createLabel(EMPTY, 0, 170, STATUS_FONT);
131     componentType = createLabel(EMPTY, 0, 400, STATUS_FONT);
132     interfaceName = createLabel(EMPTY, 0, 170, STATUS_FONT);
133     interfaceType = createLabel(EMPTY, 0, 400, STATUS_FONT);
134     color = new Color JavaDoc (64, 0, 0);
135     jlabexec = createLabel(" ", 0, 550, STATUS_FONT);
136
137     setLayout(null);
138     setPreferredSize (new Dimension JavaDoc (800, 40));
139     setInLayout (10, 0, 120, 20, labcomponentName);
140     setInLayout (10, 20, 120, 20, labinterfaceName);
141
142     setInLayout (135, 0, 200, 20, componentName);
143     setInLayout (135, 20, 200, 20, interfaceName);
144     setInLayout (135, 40, 560, 20, jlabexec);
145
146     setInLayout (310, 0, 120, 20, labcomponentType);
147     setInLayout (310, 20, 120, 20, labinterfaceType);
148
149     setInLayout (435, 0, 460, 20, componentType);
150     setInLayout (435, 20, 460, 20, interfaceType);
151   }
152
153   // -------------------------------------------------------------------------
154
// Implementation of the GraphViewListener interface
155
// -------------------------------------------------------------------------
156

157   public void viewChanged () {
158     // does nothing
159
}
160
161   public void mousePressed (final MouseEvent JavaDoc e, final ComponentPart p) {
162     // does nothing
163
}
164
165   public void mouseReleased (final MouseEvent JavaDoc e, final ComponentPart p) {
166     // does nothing
167
}
168
169   public void mouseClicked (final MouseEvent JavaDoc e, final ComponentPart p) {
170     // does nothing
171
}
172
173   public void mouseEntered (final MouseEvent JavaDoc e) {
174     // does nothing
175
}
176
177   public void mouseExited (final MouseEvent JavaDoc e) {
178     // does nothing
179
}
180
181   public void mouseDragged (final MouseEvent JavaDoc e) {
182     // does nothing
183
}
184
185   public void mouseMoved (final MouseEvent JavaDoc e, final ComponentPart p) {
186     if (p == null) {
187       componentName.setText(EMPTY);
188       componentType.setText(EMPTY);
189       interfaceName.setText(EMPTY);
190       interfaceType.setText(EMPTY);
191     } else {
192       Component c = p.getComponent();
193       componentName.setText(
194         c == null || c.getName().length() == 0 ? EMPTY : c.getName());
195       componentType.setText(
196         c == null || c.getType().length() == 0 ? EMPTY : c.getType());
197
198       Interface i = p.getInterface();
199       interfaceName.setText(
200         i == null || i.getName().length() == 0? EMPTY : i.getName());
201       interfaceType.setText(
202         i == null || i.getSignature().length() == 0 ? EMPTY : i.getSignature());
203     }
204     ajuste (componentName);
205     ajuste (interfaceName);
206     ajuste (componentType);
207     ajuste (interfaceType);
208   }
209
210   private void ajuste (JLabel JavaDoc lb) {
211     lb.setForeground(Color.black);
212     if (lb.getText().equals(EMPTY)) {
213       lb.setForeground(Constants.WARNING_COLOR);
214     } else {
215       String JavaDoc st = lb.getText();
216       if (st.length() < EMPTY.length()) {
217         lb.setText(st+WHITE.substring(st.length()));
218       }
219     }
220   }
221
222   // -------------------------------------------------------------------------
223
// Other methods
224
// -------------------------------------------------------------------------
225

226   /**
227    * Creates a new Swing label for this view component.
228    *
229    * @param label the value of the label to be created.
230    * @return the newly created label.
231    */

232
233   private JLabel JavaDoc createLabel (final String JavaDoc label, int thickness, int minwidth,
234     Font JavaDoc f) {
235     JLabel JavaDoc l = new JLabel JavaDoc(label);
236     l.setFont(f);
237     l.setForeground(color);
238     l.setBorder(BorderFactory.createLineBorder(Color.gray, thickness));
239     l.setMinimumSize(new Dimension JavaDoc (minwidth, 20));
240     return l;
241   }
242
243     private void setInLayout (int x, int y, int w, int h, java.awt.Component JavaDoc c) {
244         c.setBounds(x, y, w, h);
245         add(c);
246     }
247 }
248
Popular Tags