JLabel outputDirLabel = new JLabel(resourceCollection.getRequiredString("wizard.result.outputdirlabel"));
outputDirLabel.setBorder(new EmptyBorder(0, 0, 0, 5));
panel.add(outputDirLabel, BorderLayout.WEST);
// Text field
final JPopupField outputDirField = new JPopupField()
{
public boolean isPopupVisible()
{
return false;
}
public void setPopupVisible(boolean popupVisible)
{
if (popupVisible)
{
// Prepare file chooser
JFileChooser fileChooser = new JFileChooser();
fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
// Set the dir of the file chooser to the current path value
File f = new File(getText());
if (f.exists())
{
fileChooser.setCurrentDirectory(f);
}
// Show the file chooser
int retVal = fileChooser.showOpenDialog(null);
// If a file has been choosen, set the new value.
if (retVal == JFileChooser.APPROVE_OPTION)
{
setText(fileChooser.getSelectedFile().getPath());
}
}
}
};
outputDirField.getTextField().getDocument().addDocumentListener(new DocumentListener()
{
/**
* @see javax.swing.event.DocumentListener#changedUpdate(DocumentEvent)
*/
public void changedUpdate(DocumentEvent e)
{
getContext().setOutputRootDir(outputDirField.getText());
}
/**
* @see javax.swing.event.DocumentListener#insertUpdate(DocumentEvent)
*/
public void insertUpdate(DocumentEvent e)
{
getContext().setOutputRootDir(outputDirField.getText());
}
/**
* @see javax.swing.event.DocumentListener#removeUpdate(DocumentEvent)
*/
public void removeUpdate(DocumentEvent e)
{
getContext().setOutputRootDir(outputDirField.getText());
}
});
panel.add(outputDirField, BorderLayout.CENTER);
outputDirField.setText(getContext().getOutputRootDir());
return panel;
}