use of easik.Easik in project fql by CategoricalData.
the class FileChooser method chooseFileAWT.
/*
* AWT FileDialog implementation of the file chooser. This is because
* JFileChooser doesn't work very well on non-Windows, but FileDialog
* doesn't work on Windows (it doesn't support file filters on Windows).
*/
/**
* @param title
* @param mode
* @param filter
*
* @return
*/
private static File chooseFileAWT(String title, Mode mode, FileFilter filter) {
Easik e = Easik.getInstance();
EasikSettings s = e.getSettings();
FileDialog dialog = new FileDialog(e.getFrame(), title, (mode == Mode.SAVE) ? FileDialog.SAVE : FileDialog.LOAD);
dialog.setDirectory(s.getDefaultFolder());
if ((mode == Mode.DIRECTORY) && EasikConstants.RUNNING_ON_MAC) {
System.setProperty("apple.awt.fileDialogForDirectories", "true");
} else if (filter != null) {
dialog.setFilenameFilter(filter);
}
// Show the dialog (this blocks until the user is done)
dialog.setVisible(true);
if ((mode == Mode.DIRECTORY) && EasikConstants.RUNNING_ON_MAC) {
System.setProperty("apple.awt.fileDialogForDirectories", "false");
}
String filename = dialog.getFile();
if (filename == null) {
return null;
}
File selected = new File(dialog.getDirectory(), filename);
if (mode != Mode.DIRECTORY) {
s.setProperty("folder_last", selected.getParentFile().getAbsolutePath());
}
return selected;
}
use of easik.Easik in project fql by CategoricalData.
the class FileChooser method chooseFileSwing.
/**
* @param title
* @param mode
* @param filter
*
* @return
*/
private static File chooseFileSwing(String title, Mode mode, FileFilter filter, String defaultName) {
Easik e = Easik.getInstance();
EasikSettings s = e.getSettings();
JFileChooser dialog = new JFileChooser(s.getDefaultFolder());
if (filter != null) {
dialog.setFileFilter(filter);
}
int result;
if (mode == Mode.DIRECTORY) {
dialog.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
result = dialog.showDialog(e.getFrame(), "Select folder");
} else if (mode == Mode.SAVE) {
if (defaultName != null) {
dialog.setSelectedFile(new File(defaultName));
}
result = dialog.showSaveDialog(e.getFrame());
} else {
result = dialog.showOpenDialog(e.getFrame());
}
if (result != JFileChooser.APPROVE_OPTION) {
return null;
}
File selFile = dialog.getSelectedFile();
if (mode != Mode.DIRECTORY) {
s.setProperty("folder_last", selFile.getParentFile().getAbsolutePath());
}
return selFile;
}
Aggregations