1 18 19 package org.apache.jmeter.gui; 20 import java.awt.Component ; 21 import java.awt.Container ; 22 import java.awt.Font ; 23 24 import javax.swing.BorderFactory ; 25 import javax.swing.JLabel ; 26 import javax.swing.JPanel ; 27 import javax.swing.JScrollPane ; 28 import javax.swing.border.Border ; 29 30 import org.apache.jmeter.gui.tree.JMeterTreeNode; 31 import org.apache.jmeter.gui.util.VerticalPanel; 32 import org.apache.jmeter.testelement.TestElement; 33 import org.apache.jmeter.testelement.property.BooleanProperty; 34 import org.apache.jmeter.testelement.property.NullProperty; 35 import org.apache.jmeter.testelement.property.StringProperty; 36 import org.apache.jmeter.util.JMeterUtils; 37 import org.apache.jorphan.logging.LoggingManager; 38 import org.apache.log.Logger; 39 40 57 public abstract class AbstractJMeterGuiComponent 58 extends JPanel 59 implements JMeterGUIComponent 60 { 61 62 private static Logger log = LoggingManager.getLoggerForClass(); 63 64 65 private boolean enabled = true; 66 67 68 private JMeterTreeNode node; 69 70 71 private NamePanel namePanel; 72 73 74 79 public AbstractJMeterGuiComponent() 80 { 81 namePanel = new NamePanel(); 82 setName(getStaticLabel()); 83 } 84 85 89 public void setName(String name) 90 { 91 namePanel.setName(name); 92 } 93 94 98 public boolean isEnabled() 99 { 100 return enabled; 101 } 102 103 107 public void setEnabled(boolean e) 108 { 109 log.debug("Setting enabled: " + e); 110 enabled = e; 111 } 112 113 117 public String getName() 118 { 119 if (getNamePanel() != null) { 120 return getNamePanel().getName(); 121 } 122 else return ""; 123 } 124 125 133 protected NamePanel getNamePanel() 134 { 135 return namePanel; 136 } 137 138 148 protected Component createTitleLabel() 149 { 150 JLabel titleLabel = new JLabel (getStaticLabel()); 151 Font curFont = titleLabel.getFont(); 152 titleLabel.setFont(curFont.deriveFont((float) curFont.getSize() + 4)); 153 return titleLabel; 154 } 155 156 169 public void configure(TestElement element) 170 { 171 setName(element.getPropertyAsString(TestElement.NAME)); 172 if (element.getProperty(TestElement.ENABLED) instanceof NullProperty) 173 { 174 enabled = true; 175 } 176 else 177 { 178 enabled = element.getPropertyAsBoolean(TestElement.ENABLED); 179 } 180 } 181 182 188 public void clear() 189 { 190 setName(getStaticLabel()); 191 enabled = true; 192 } 193 194 204 protected void configureTestElement(TestElement mc) 205 { 206 mc.setProperty(new StringProperty(TestElement.NAME, getName())); 207 208 mc.setProperty( 209 new StringProperty( 210 TestElement.GUI_CLASS, 211 this.getClass().getName())); 212 213 mc.setProperty( 214 new StringProperty( 215 TestElement.TEST_CLASS, 216 mc.getClass().getName())); 217 218 log.debug("setting element to enabled: " + enabled); 220 mc.setProperty(new BooleanProperty(TestElement.ENABLED, enabled)); 221 } 222 223 227 public void setNode(JMeterTreeNode node) 228 { 229 this.node = node; 230 getNamePanel().setNode(node); 231 } 232 233 237 protected JMeterTreeNode getNode() 238 { 239 return node; 240 } 241 242 250 protected Container makeTitlePanel() 251 { 252 VerticalPanel titlePanel = new VerticalPanel(); 253 titlePanel.add(createTitleLabel()); 254 titlePanel.add(getNamePanel()); 255 return titlePanel; 256 } 257 258 266 protected Border makeBorder() 267 { 268 return BorderFactory.createEmptyBorder(10, 10, 5, 10); 269 } 270 271 282 protected JScrollPane makeScrollPane(Component comp) 283 { 284 JScrollPane pane = new JScrollPane (comp); 285 pane.setPreferredSize(pane.getMinimumSize()); 286 return pane; 287 } 288 289 304 protected JScrollPane makeScrollPane( 305 Component comp, 306 int verticalPolicy, 307 int horizontalPolicy) 308 { 309 JScrollPane pane = 310 new JScrollPane (comp, verticalPolicy, horizontalPolicy); 311 pane.setPreferredSize(pane.getMinimumSize()); 312 return pane; 313 } 314 315 public String getStaticLabel() 316 { 317 return JMeterUtils.getResString(getLabelResource()); 318 } 319 320 public String getDocAnchor() 321 { 322 return getStaticLabel().replace(' ', '_'); 323 } 324 325 } 340 | Popular Tags |