in the gui we have a function to select a file for data import:
public void load_data_button_click(GButton source, GEvent event) { if (event == GEvent.CLICKED) {
selectInput("Select File to import: ", "loadData");
}
}
as next we have the function loadData:
voidloadData(File selection) {
if (selection == null) { // no path
} else { // path selected
String[] paths = {selection.getAbsolutePath()};
println(" User selected "+ selection.getAbsolutePath());
folder = new File(selection.getAbsolutePath());
saveStrings(AppDataPath + "/userPaths.txt", paths);
… other code.
sorry i could not share other code
- is to much
- not allowed by company rules
i have the location and name of last file saved in userPaths.txt
but how can i use this to pass it as preference directory if user want to load new data set .
i have seen Java has a posibility to define preference path but how to use it in my processing code ?
see this link:
code:
Preferences pref = Preferences.userRoot();
// Retrieve the selected path or use
// an empty string if no path has
// previously been selected
String path = pref.get("DEFAULT_PATH", "");
JFileChooser chooser = new JFileChooser();
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
// Set the path that was saved in preferences
chooser.setCurrentDirectory(new File(path));
int returnVal = chooser.showOpenDialog(null);
if (returnVal == JFileChooser.APPROVE_OPTION)
{
File f = chooser.getSelectedFile();
chooser.setCurrentDirectory(f);
// Save the selected path
pref.put("DEFAULT_PATH", f.getAbsolutePath());
}
but i’m unable to integrate this code in processing because functions of java ( setCurrentDirectory) are unknown in processing .
also i found a page which will solve eventually my problem but if i understand it correct it will modify java function - i thing this would not be practicable - because everytime if on the pc the java ist updated (which is done sometimes by IT over nigth) this wouldnt work.
the link to solution by modify PApplet.java.
would it be possible to do something like this in processing without to modify PApplet.java?
best regards,
El Paco