use of artisynth.core.util.ExtensionFileFilter in project artisynth_core by artisynth.
the class MenuBarHandler method saveViewerImage.
private void saveViewerImage() {
JFileChooser chooser;
if ((chooser = myViewerImageFileChooser) == null) {
chooser = new JFileChooser();
chooser.setApproveButtonText("Save");
chooser.setCurrentDirectory(ArtisynthPath.getWorkingDir());
for (FileFilter ff : chooser.getChoosableFileFilters()) {
chooser.removeChoosableFileFilter(ff);
}
// create filters
String[] fmts = ImageIO.getWriterFormatNames();
for (String fmt : fmts) {
ExtensionFileFilter filter = new ExtensionFileFilter("." + fmt + " files", fmt);
chooser.addChoosableFileFilter(filter);
}
chooser.setFileFilter(chooser.getChoosableFileFilters()[0]);
myViewerImageFileChooser = chooser;
}
int returnVal = chooser.showSaveDialog(myFrame);
if (returnVal == JFileChooser.APPROVE_OPTION) {
ExtensionFileFilter filter = (ExtensionFileFilter) chooser.getFileFilter();
String ext = filter.getExtensions()[0];
File file = chooser.getSelectedFile();
if (!file.getName().toLowerCase().endsWith(ext.toLowerCase())) {
file = new File(file.getPath() + "." + ext);
}
int confirmation = JOptionPane.YES_OPTION;
if (file.exists()) {
confirmation = JOptionPane.showConfirmDialog(myFrame, "File " + file.getName() + " aleady exists. Proceed?", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
}
if (confirmation == JOptionPane.YES_OPTION) {
GLViewer viewer = myMain.getViewer();
viewer.setupScreenShot(viewer.getScreenWidth(), viewer.getScreenHeight(), file, ext);
viewer.repaint();
// while (viewer.grabPending()) {
// try {
// Thread.sleep (10);
// }
// catch (Exception e){
// }
// }
}
}
}
Aggregations