We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › File extension for selectOutput()
Page Index Toggle Pages: 1
File extension for selectOutput() (Read 1156 times)
File extension for selectOutput()
Jan 15th, 2010, 7:27am
 
Is there any way to define the default file extension?  What about a default file name?
Re: File extension for selectOutput()
Reply #1 - Jan 15th, 2010, 12:29pm
 
selectOutput is just a wrapper around FileDialog which is less flexible than a JFileChooser...
Aiming at simplicity, I fear it doesn't offer much customization options.
Re: File extension for selectOutput()
Reply #2 - Jan 15th, 2010, 12:46pm
 
You may use if (filename.endsWith(".jpg")||filename.endsWith(".jpeg")) do stuff; after filename=selectOutput("Please please only .jpg"); to get what you want. I have some code with JFileChooser but I really like the simplicity of selectOutput()

Re: File extension for selectOutput()
Reply #3 - Apr 22nd, 2010, 7:48am
 
Here is what I ended up doing... for anyone else that runs into this.  I added this to my sketch.
Code:
import java.awt.FileDialog;

public String selectOutputPro(String prompt, String filestring) {
return selectFileImplPro(prompt, filestring, FileDialog.SAVE);
}


protected String selectFileImplPro(final String prompt, final String filestring, final int mode) {
this.checkParentFrame();

try {
javax.swing.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;
}
}


I also made a request for the filename to be included in the core... would be relatively simple (even included the code if anyone wants to check it in).  
http://dev.processing.org/bugs/show_bug.cgi?id=1504
Page Index Toggle Pages: 1