Bug 1504 : add means of setting a filename/path with selectInput/Output
Last modified: 2010-06-05 03:50




Status:
RESOLVED
Resolution:
DUPLICATE of bug 1475
Priority:
P4
Severity:
enhancement

 

Reporter:
jeffg
Assigned To:
fry

Attachment Type Created Size Actions

Description:   Opened: 2010-03-11 15:14
It would be nice if the select dialogs supported the AWT setFile() option
for the file name.
Perhaps something like selectOutput(String title, String filename);
Additional Comment #1 From fry 2010-03-11 16:17
thanks for the report. i probably won't be adding more features to
these--the idea is to just have a simple means of selecting files. after
that it's best to just use the awt/swing commands directly.
Additional Comment #2 From jeffg 2010-03-13 17:40
Here is a change to the code to add this functionality.

public String selectOutput(String prompt, String filestring) {
return selectFileImpl(prompt, FileDialog.SAVE, filestring);
}

public String selectFileImpl(final String prompt, final int mode) {
return selectFileImpl(prompt, mode, "");
}

protected String selectFileImpl(final String prompt, final int mode,
final String filestring) {
checkParentFrame();

try {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
FileDialog fileDialog =
new FileDialog(parentFrame, prompt, mode);
fileDialog.setFile(filestring);
fileDialog.setVisible(true);
String directory = fileDialog.getDirectory();
String filename = fileDialog.getFile();
selectedFile =
(filename == null) ? null : new File(directory, filename);
}
});
return (selectedFile == null) ? null : selectedFile.getAbsolutePath();

} catch (Exception e) {
e.printStackTrace();
return null;
}
}
Additional Comment #3 From fry 2010-06-05 03:50
well, that's two votes; maybe we're onto something.

*** This bug has been marked as a duplicate of 1475 ***