1 17 package org.apache.jmeter.testbeans.gui; 18 19 import java.awt.BorderLayout ; 20 import java.awt.Component ; 21 import java.awt.Graphics ; 22 import java.awt.Rectangle ; 23 import java.awt.event.ActionEvent ; 24 import java.awt.event.ActionListener ; 25 import java.beans.PropertyChangeListener ; 26 import java.beans.PropertyEditor ; 27 import java.beans.PropertyEditorSupport ; 28 import java.io.File ; 29 30 import javax.swing.JButton ; 31 import javax.swing.JFileChooser ; 32 import javax.swing.JPanel ; 33 34 import org.apache.jmeter.gui.util.FileDialoger; 35 import org.apache.jorphan.logging.LoggingManager; 36 import org.apache.log.Logger; 37 38 48 public class FileEditor implements PropertyEditor , ActionListener 49 { 50 private static final Logger log= LoggingManager.getLoggerForClass(); 51 52 55 private JPanel panel; 56 57 60 PropertyEditor editor; 61 62 public FileEditor() 63 { 64 JButton button= new JButton ("Browse..."); 66 button.addActionListener(this); 67 68 editor= new WrapperEditor( 71 this, 72 new SimpleFileEditor(), 73 new ComboStringEditor(), 74 true, true, true, null); 75 76 panel= new JPanel (new BorderLayout (5,0)); 78 panel.add(editor.getCustomEditor(), BorderLayout.CENTER); 79 panel.add(button, BorderLayout.EAST); } 81 82 85 public void actionPerformed(ActionEvent e) 86 { 87 JFileChooser chooser = FileDialoger.promptToOpenFile(); 88 89 File file = chooser.getSelectedFile(); 90 91 setValue(file.getPath()); 92 } 93 94 97 public void addPropertyChangeListener(PropertyChangeListener listener) 98 { 99 editor.addPropertyChangeListener(listener); 100 } 101 102 105 public String getAsText() 106 { 107 return editor.getAsText(); 108 } 109 110 113 public Component getCustomEditor() 114 { 115 return panel; 116 } 117 118 121 public String getJavaInitializationString() 122 { 123 return editor.getJavaInitializationString(); 124 } 125 126 129 public String [] getTags() 130 { 131 return editor.getTags(); 132 } 133 134 137 public Object getValue() 138 { 139 return editor.getValue(); 140 } 141 142 145 public boolean isPaintable() 146 { 147 return editor.isPaintable(); 148 } 149 150 154 public void paintValue(Graphics gfx, Rectangle box) 155 { 156 editor.paintValue(gfx, box); 157 } 158 159 162 public void removePropertyChangeListener(PropertyChangeListener listener) 163 { 164 editor.removePropertyChangeListener(listener); 165 } 166 167 171 public void setAsText(String text) throws IllegalArgumentException 172 { 173 editor.setAsText(text); 174 } 175 176 179 public void setValue(Object value) 180 { 181 editor.setValue(value); 182 } 183 184 187 public boolean supportsCustomEditor() 188 { 189 return editor.supportsCustomEditor(); 190 } 191 192 private static class SimpleFileEditor extends PropertyEditorSupport 193 { 194 197 public String getAsText() 198 { 199 return ((File )super.getValue()).getPath(); 200 } 201 202 205 public void setAsText(String text) throws IllegalArgumentException 206 { 207 super.setValue(new File (text)); 208 } 209 210 214 public Object getValue() 215 { 216 return getAsText(); } 218 219 222 public void setValue(Object file) 223 { 224 setAsText((String )file); 225 } 226 } 227 } | Popular Tags |