01: /*
02: * soapUI, copyright (C) 2004-2007 eviware.com
03: *
04: * soapUI is free software; you can redistribute it and/or modify it under the
05: * terms of version 2.1 of the GNU Lesser General Public License as published by
06: * the Free Software Foundation.
07: *
08: * soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
09: * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10: * See the GNU Lesser General Public License for more details at gnu.org.
11: */
12:
13: package com.eviware.soapui.support.components;
14:
15: import java.awt.event.ActionEvent;
16: import java.io.File;
17:
18: import javax.swing.AbstractAction;
19: import javax.swing.JButton;
20: import javax.swing.JPanel;
21: import javax.swing.JTextField;
22: import javax.swing.text.JTextComponent;
23:
24: import com.eviware.soapui.support.UISupport;
25: import com.jgoodies.forms.builder.ButtonBarBuilder;
26:
27: public class DirectoryFormComponent extends JPanel implements
28: JFormComponent {
29: private JTextField textField;
30:
31: public DirectoryFormComponent(String tooltip) {
32: ButtonBarBuilder builder = new ButtonBarBuilder(this );
33: textField = new JTextField(30);
34: textField.setToolTipText(tooltip);
35: builder.addGriddedGrowing(textField);
36: builder.addRelatedGap();
37: builder.addFixed(new JButton(new SelectDirectoryAction()));
38: }
39:
40: public void setValue(String value) {
41: textField.setText(value);
42: }
43:
44: public String getValue() {
45: return textField.getText();
46: }
47:
48: public class SelectDirectoryAction extends AbstractAction {
49: public SelectDirectoryAction() {
50: super ("Browse...");
51: }
52:
53: public void actionPerformed(ActionEvent e) {
54: File currentDirectory = null;
55: if (textField.getText().length() > 0)
56: currentDirectory = new File(textField.getText());
57: File file = UISupport.getFileDialogs().openDirectory(this ,
58: "Select directory", currentDirectory);
59: if (file != null) {
60: textField.setText(file.getAbsolutePath());
61: }
62: }
63: }
64:
65: public JTextComponent getTextField() {
66: return textField;
67: }
68: }
|