1 18 19 package org.apache.jmeter.ejb.jndi.config.gui; 20 21 import java.awt.*; 22 import java.awt.event.*; 23 import java.beans.*; 24 import javax.swing.*; 25 import javax.swing.event.*; 26 27 import org.apache.jmeter.ejb.jndi.config.MethodConfigUserObject; 28 import org.apache.jmeter.ejb.jndi.config.MethodConfigUserObjectException; 29 import org.apache.log4j.Category; 30 31 38 public class MethodConfigDialog extends JDialog 39 { 40 private static Category catClass = Category.getInstance( 41 MethodConfigDialog.class.getName()); 42 43 protected JOptionPane optionPane; 44 protected JTextField textField; 45 protected JLabel classLabel; 46 protected MethodConfigUserObject userObject; 47 48 public MethodConfigDialog(Frame aFrame, final Class type) 49 { 50 super(aFrame, true); 51 classLabel = new JLabel(type.getName()); 52 textField = new JTextField(10); 53 Object [] array = {classLabel, textField}; 54 55 final String btnString1 = "Ok"; 56 final String btnString2 = "Cancel"; 57 Object [] options = {btnString1, btnString2}; 58 59 optionPane = new JOptionPane( 60 array, 61 JOptionPane.QUESTION_MESSAGE, 62 JOptionPane.OK_CANCEL_OPTION, 63 null, 64 options, 65 options[0]); 66 setContentPane(optionPane); 67 setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); 68 addWindowListener(new WindowAdapter() 69 { 70 } 71 ); 72 textField.addActionListener(new ActionListener() 73 { 74 public void actionPerformed(ActionEvent e) 75 { 76 optionPane.setValue(btnString1); 77 } 78 } 79 ); 80 optionPane.addPropertyChangeListener(new PropertyChangeListener() 81 { 82 public void propertyChange(PropertyChangeEvent e) 83 { 84 catClass.debug("Start : propertyChange1"); 85 String prop = e.getPropertyName(); 86 if(catClass.isDebugEnabled()) 87 { 88 catClass.debug("propertyChange1 : property name - " + prop); 89 } 90 catClass.debug("JOptionPane.INPUT_VALUE_PROPERTY - " + JOptionPane.INPUT_VALUE_PROPERTY); 91 catClass.debug("optionPane.getValue() - " + optionPane.getValue()); 92 catClass.debug("optionPane.getInputValue() - " + optionPane.getInputValue()); 93 Object value = null; 94 if(isVisible() 95 && (e.getSource() == optionPane) 96 && prop.equals(JOptionPane.VALUE_PROPERTY)) 97 { 98 value = optionPane.getValue(); 99 if(catClass.isDebugEnabled()) 100 { 101 catClass.debug("propertyChange1 : optionPane value - " + value); 102 } 103 104 optionPane.setValue(JOptionPane.UNINITIALIZED_VALUE); 108 109 String input = null; 110 if(value.equals(btnString1)) 111 { 112 try 113 { 114 input = textField.getText(); 115 if(catClass.isDebugEnabled()) 116 { 117 catClass.debug("MethodConfigDialog1 : input - " + input); 118 } 119 userObject = new MethodConfigUserObject(type, input); 120 setVisible(false); 121 } 122 catch(MethodConfigUserObjectException ex) 123 { 124 catClass.debug( 126 "propertyChange1 : input incompatible with class"); 127 textField.selectAll(); 128 JOptionPane.showMessageDialog( 129 MethodConfigDialog.this, 130 "Sorry, \"" + input + "\" " 131 + "is not valid for Class " 132 + type, 133 "Try again", 134 JOptionPane.ERROR_MESSAGE); 135 input = null; 136 userObject = null; 137 } 138 } 139 else 140 { 141 setVisible(false); 142 } 143 } 144 catClass.debug("End - propertyChange1"); 145 } 146 } 147 ); 148 } 149 150 public MethodConfigUserObject getValidatedInput() 151 { 152 return userObject; 153 } 154 } 155 | Popular Tags |