1 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 ; 34 import java.awt.Dimension ; 35 import java.awt.Font ; 36 import java.awt.event.MouseEvent ; 37 38 import javax.swing.BorderFactory ; 39 import javax.swing.JLabel ; 40 41 47 48 public class BasicStatusView extends JPanelImpl implements GraphViewListener { 49 50 53 54 private final static Font CAPTION_FONT = 55 new Font ("Arial", Font.BOLD, 12); 56 57 60 61 private final static Font STATUS_FONT = 62 new Font ("courier", Font.PLAIN, 12); 63 64 67 68 private JLabel componentName; 69 70 73 74 private JLabel componentType; 75 76 79 80 private JLabel interfaceName; 81 82 85 86 private JLabel interfaceType; 87 88 91 92 private JLabel statusstring; 93 94 97 98 private JLabel jlabexec; 99 100 103 104 private String EMPTY = "<EMPTY> "; 105 private String WHITE = " "; 106 107 private Color color = Color.black; 108 109 112 113 public BasicStatusView () { 114 color = new Color (0, 0, 64); 115 116 118 JLabel labcomponentName = createLabel("Component name:", 119 0, 110, CAPTION_FONT); 120 JLabel labcomponentType = createLabel("component type:", 121 0, 110, CAPTION_FONT); 122 JLabel labinterfaceName = createLabel("Interface name:", 123 0, 110, CAPTION_FONT); 124 JLabel labinterfaceType = createLabel("Interface type:", 125 0, 110, CAPTION_FONT); 126 JLabel 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 (64, 0, 0); 135 jlabexec = createLabel(" ", 0, 550, STATUS_FONT); 136 137 setLayout(null); 138 setPreferredSize (new Dimension (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 157 public void viewChanged () { 158 } 160 161 public void mousePressed (final MouseEvent e, final ComponentPart p) { 162 } 164 165 public void mouseReleased (final MouseEvent e, final ComponentPart p) { 166 } 168 169 public void mouseClicked (final MouseEvent e, final ComponentPart p) { 170 } 172 173 public void mouseEntered (final MouseEvent e) { 174 } 176 177 public void mouseExited (final MouseEvent e) { 178 } 180 181 public void mouseDragged (final MouseEvent e) { 182 } 184 185 public void mouseMoved (final MouseEvent 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 lb) { 211 lb.setForeground(Color.black); 212 if (lb.getText().equals(EMPTY)) { 213 lb.setForeground(Constants.WARNING_COLOR); 214 } else { 215 String st = lb.getText(); 216 if (st.length() < EMPTY.length()) { 217 lb.setText(st+WHITE.substring(st.length())); 218 } 219 } 220 } 221 222 226 232 233 private JLabel createLabel (final String label, int thickness, int minwidth, 234 Font f) { 235 JLabel l = new JLabel (label); 236 l.setFont(f); 237 l.setForeground(color); 238 l.setBorder(BorderFactory.createLineBorder(Color.gray, thickness)); 239 l.setMinimumSize(new Dimension (minwidth, 20)); 240 return l; 241 } 242 243 private void setInLayout (int x, int y, int w, int h, java.awt.Component c) { 244 c.setBounds(x, y, w, h); 245 add(c); 246 } 247 } 248 | Popular Tags |