SelectFolder() and selectInput() in Processing 2.0 vs 1.6
in
Programming Questions
•
11 months ago
Hi,
In 1.6,
- String selectedFolder = selectFolder(String);
- String selectedInput = selectInput(String);
would prompt the user to select the folder / file with the output being the folder path or file path respectively.
(e.g. Users/adilapapaya/Desktop/myFolder);
In 2.0, selectFolder(String) and selectInput(String) no longer exists. Instead, the closest is requires a callback function which you have to add to your sketch telling it what to do with the selected folder or file. The javadoc/reference gives a nice example of this but I was wondering if it would be possible to keep the previous version of 'selectFolder(String)' and selectInput(String) in there too in v2.0.x.
Not sure if this is helpful, but here's the source code for the previous versions of selectFolder and selectInput. (Both refer to a bunch of other functions though and I haven't checked if those still exist in 2.0).
selectFolder:
- /*
- * Opens a platform-specific file chooser dialog to select a folder for
- * input. This function returns the full path to the selected folder as a
- * <b>String</b>, or <b>null</b> if no selection.
- */
- public String selectFolder(final String prompt) {
- checkParentFrame();
- try {
- SwingUtilities.invokeAndWait(new Runnable() {
- public void run() {
- if (platform == MACOSX) {
- FileDialog fileDialog =
- new FileDialog(parentFrame, prompt, FileDialog.LOAD);
- System.setProperty("apple.awt.fileDialogForDirectories", "true");
- fileDialog.setVisible(true);
- System.setProperty("apple.awt.fileDialogForDirectories", "false");
- String filename = fileDialog.getFile();
- selectedFile = (filename == null) ? null :
- new File(fileDialog.getDirectory(), fileDialog.getFile());
- } else {
- JFileChooser fileChooser = new JFileChooser();
- fileChooser.setDialogTitle(prompt);
- fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
- int returned = fileChooser.showOpenDialog(parentFrame);
- System.out.println(returned);
- if (returned == JFileChooser.CANCEL_OPTION) {
- selectedFile = null;
- } else {
- selectedFile = fileChooser.getSelectedFile();
- }
- }
- }
- });
- return (selectedFile == null) ? null : selectedFile.getAbsolutePath();
- } catch (Exception e) {
- e.printStackTrace();
- return null;
- }
- }
selectInput:
- /** Open a platform-specific file chooser dialog to select a file for input.
- * @return full path to the selected file, or null if no selection.*/
- public String selectInput(String prompt) {
- return selectFileImpl(prompt, FileDialog.LOAD);
- }
Many thanks,adila
1