String path = preferences.get("img-path", "");
JFileChooser chooser = new JFileChooser(path);
chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
chooser.setAcceptAllFileFilterUsed(false);
chooser.setFileFilter(DimStackImageFileFilter.getInstance());
DataVisualization dataVis = owner.getActiveDataVisualization();
int returnVal = chooser.showSaveDialog(dataVis.getTopComponent());
if (returnVal == JFileChooser.APPROVE_OPTION) {
File img = chooser.getSelectedFile();
// save path info for future file operations
if (img.isDirectory()) {
preferences.put("img-path", img.getAbsolutePath());
} else {
preferences.put("img-path", img.getParent());
}
// handle if file already exists
if (img.exists()) {
int answer = JOptionPane.showConfirmDialog(null,
"Overwrite existing file?");
if (answer != JOptionPane.OK_OPTION) {
return;
}
} else {
// If this is a new file, make sure
// it has the necessary file ending
if (FileUtils.getExtension(img) == null) {
javax.swing.filechooser.FileFilter filter = chooser.getFileFilter();
String str = img.getAbsolutePath()
+ filter.getDescription();
img = new File(str);
}
}
writeFile(img);
dataVis.fireSaveStateChange(false);
}
}