1 18 19 package org.apache.jmeter.ejb.jndi.config.gui; 20 21 import javax.swing.*; 22 import javax.swing.border.*; 23 import java.awt.event.*; 24 import javax.naming.InitialContext ; 25 import java.awt.*; 26 import java.util.*; 27 28 import org.apache.jmeter.gui.ModelSupported; 29 import org.apache.jmeter.gui.NamePanel; 30 import org.apache.jmeter.gui.VerticalLayout; 31 import org.apache.jmeter.config.gui.ArgumentsPanel; 32 import org.apache.jmeter.config.Arguments; 33 import org.apache.jmeter.util.JMeterUtils; 34 import org.apache.jmeter.ejb.jndi.config.JndiConfig; 35 import org.apache.log4j.Category; 36 37 43 public class JndiConfigGui extends JPanel implements ModelSupported, 44 KeyListener 45 { 46 private static Category catClass = Category.getInstance( 47 JndiConfigGui.class.getName()); 48 49 protected JTextField[] jndi_fields = new JTextField[JndiConfig.JNDI_PROPS.length]; 50 51 protected NamePanel namePanel; 52 protected boolean displayName; 53 protected JndiConfig model; 54 55 public JndiConfigGui() 56 { 57 displayName = true; 58 } 59 60 public JndiConfigGui(boolean displayName) 61 { 62 this.displayName = displayName; 63 } 64 65 public void setModel(Object model) 66 { 67 this.model = (JndiConfig)model; 68 init(); 69 } 70 71 public void updateGui() 72 { 73 for(int i = 0; i < JndiConfig.JNDI_PROPS.length; i++) 74 { 75 jndi_fields[i].setText(model.getValue(i)); 76 } 77 } 78 79 protected void init() 80 { 81 for(int i = 0; i < JndiConfig.JNDI_PROPS.length; i++) 82 { 83 jndi_fields[i] = new JTextField(20); 84 } 85 if(displayName) 86 { 87 this.setLayout(new VerticalLayout(5, VerticalLayout.LEFT, 88 VerticalLayout.TOP)); 89 JPanel mainPanel = new JPanel(); 91 Border margin = new EmptyBorder(10, 10, 5, 10); 92 mainPanel.setBorder(margin); 93 mainPanel.setLayout(new VerticalLayout(5, VerticalLayout.LEFT)); 94 95 mainPanel.add(makeTitlePanel()); 96 97 JPanel urlJNDIPanel = new JPanel(); 99 urlJNDIPanel.setLayout(new VerticalLayout(5, VerticalLayout.LEFT)); 100 urlJNDIPanel.setBorder(BorderFactory.createTitledBorder( 101 JMeterUtils.getResString("jndi_url_jndi_props"))); 102 103 for(int i = 0; i < JndiConfig.JNDI_PROPS.length; i++) 104 { 105 urlJNDIPanel.add(getPanel(i)); 106 } 107 108 mainPanel.add(urlJNDIPanel); 109 this.add(mainPanel); 110 } 111 else 112 { 113 this.setLayout(new VerticalLayout(5, VerticalLayout.LEFT)); 114 115 JPanel urlJNDIPanel = new JPanel(); 117 urlJNDIPanel.setLayout(new VerticalLayout(5, VerticalLayout.LEFT)); 118 urlJNDIPanel.setBorder(BorderFactory.createTitledBorder( 119 JMeterUtils.getResString("jndi_url_jndi_props"))); 120 121 for(int i = 0; i < JndiConfig.JNDI_PROPS.length; i++) 122 { 123 urlJNDIPanel.add(getPanel(i)); 124 } 125 126 this.add(urlJNDIPanel); 127 } 128 } 129 130 protected JPanel getPanel(int i) 131 { 132 catClass.info("Start : getPanel1"); 133 if(catClass.isDebugEnabled()) 134 { 135 catClass.debug("getPanel1 : Panel no. - " + i); 136 catClass.debug("getPanel1 : Panel name - " + JndiConfig.JNDI_PROPS[i]); 137 catClass.debug("getPanel1 : Panel value - " + model.getValue(i)); 138 } 139 JPanel panel = new JPanel(); 140 panel.add(new JLabel(JndiConfig.JNDI_PROPS[i])); 141 jndi_fields[i].setText(model.getValue(i)); 142 jndi_fields[i].setName(JndiConfig.JNDI_PROPS[i]); 143 jndi_fields[i].addKeyListener(this); 144 panel.add(jndi_fields[i]); 145 catClass.info("End : getPanel1"); 146 return panel; 147 } 148 149 public void keyPressed(KeyEvent e) 150 { 151 } 152 153 public void keyTyped(KeyEvent e) 154 { 155 } 156 157 public void keyReleased(KeyEvent e) 158 { 159 String name = e.getComponent().getName(); 160 int i = 0; 161 while(i < JndiConfig.JNDI_PROPS.length) 162 { 163 if(name.equals(JndiConfig.JNDI_PROPS[i])) 164 { 165 break; 166 } 167 i++; 168 } 169 if(i < JndiConfig.JNDI_PROPS.length) 170 { 171 model.setValue(i, jndi_fields[i].getText()); 172 } 173 } 174 } 175 | Popular Tags |