1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
public class PathSelectionPanel extends JPanel implements ActionListener
{
private JTextField textField;
private JButton browseButton;
public PathSelectionPanel()
{
super();
createLayout();
}
protected void createLayout()
{
GridBagLayout layout = new GridBagLayout();
setLayout(layout);
textField = new JTextField(idata.getInstallPath(), 30);
textField.addActionListener(this);
parent.setInitialFocus(textField);
GridBagConstraints gbConstraints = new GridBagConstraints();
parent.getInstallerFrame().buildConstraints(gbConstraints, 0, 1,
GridBagConstraints.RELATIVE, 1, 1.0, 0.0);
gbConstraints.fill = GridBagConstraints.HORIZONTAL;
gbConstraints.anchor = GridBagConstraints.WEST;
gbConstraints.insets = new Insets(0, 0, 0, 10);
layout.addLayoutComponent(textField, gbConstraints);
add(textField);
browseButton = ButtonFactory.createButton();
browseButton.addActionListener(this);
gbConstraints.insets = new Insets(0, 0, 0, 5);
layout.addLayoutComponent(browseButton, gbConstraints);
add(browseButton);
}
public void actionPerformed(ActionEvent e)
{
Object source = e.getSource();
if (source == browseButton)
{
JFileChooser fc = new JFileChooser();
fc.setLocale(new Locale(idata.localeISO3));
fc.setCurrentDirectory(new File(textField.getText()));
fc.setMultiSelectionEnabled(false);
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
fc.addChoosableFileFilter(fc.getAcceptAllFileFilter());
if (fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION)
{
String path = fc.getSelectedFile().getAbsolutePath();
textField.setText(path);
}
}
else
{
if (parent instanceof ActionListener) ((ActionListener) parent).actionPerformed(e);
}
}
public String getPath()
{
return (textField.getText());
}
public void setPath(String path)
{
textField.setText(path);
}
public JTextField getPathInputField()
{
return textField;
}
public JButton getBrowseButton()
{
return browseButton;
}
} |
Partager