use of com.cburch.logisim.file.Loader in project logisim-evolution by reds-heig.
the class ExportImage method doExport.
static void doExport(Project proj) {
// First display circuit/parameter selection dialog
Frame frame = proj.getFrame();
CircuitJList list = new CircuitJList(proj, true);
if (list.getModel().getSize() == 0) {
JOptionPane.showMessageDialog(proj.getFrame(), Strings.get("exportEmptyCircuitsMessage"), Strings.get("exportEmptyCircuitsTitle"), JOptionPane.YES_NO_OPTION);
return;
}
OptionsPanel options = new OptionsPanel(list);
int action = JOptionPane.showConfirmDialog(frame, options, Strings.get("exportImageSelect"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
if (action != JOptionPane.OK_OPTION)
return;
List<Circuit> circuits = list.getSelectedCircuits();
double scale = options.getScale();
boolean printerView = options.getPrinterView();
if (circuits.isEmpty())
return;
ImageFileFilter filter;
int fmt = options.getImageFormat();
switch(options.getImageFormat()) {
case FORMAT_GIF:
filter = new ImageFileFilter(fmt, Strings.getter("exportGifFilter"), new String[] { "gif" });
break;
case FORMAT_PNG:
filter = new ImageFileFilter(fmt, Strings.getter("exportPngFilter"), new String[] { "png" });
break;
case FORMAT_JPG:
filter = new ImageFileFilter(fmt, Strings.getter("exportJpgFilter"), new String[] { "jpg", "jpeg", "jpe", "jfi", "jfif", "jfi" });
break;
default:
logger.error("Unexpected image format; aborted!");
return;
}
// Then display file chooser
Loader loader = proj.getLogisimFile().getLoader();
JFileChooser chooser = loader.createChooser();
if (circuits.size() > 1) {
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
chooser.setDialogTitle(Strings.get("exportImageDirectorySelect"));
} else {
chooser.setFileFilter(filter);
chooser.setDialogTitle(Strings.get("exportImageFileSelect"));
}
int returnVal = chooser.showDialog(frame, Strings.get("exportImageButton"));
if (returnVal != JFileChooser.APPROVE_OPTION)
return;
// Determine whether destination is valid
File dest = chooser.getSelectedFile();
chooser.setCurrentDirectory(dest.isDirectory() ? dest : dest.getParentFile());
if (dest.exists()) {
if (!dest.isDirectory()) {
int confirm = JOptionPane.showConfirmDialog(proj.getFrame(), Strings.get("confirmOverwriteMessage"), Strings.get("confirmOverwriteTitle"), JOptionPane.YES_NO_OPTION);
if (confirm != JOptionPane.YES_OPTION)
return;
}
} else {
if (circuits.size() > 1) {
boolean created = dest.mkdir();
if (!created) {
JOptionPane.showMessageDialog(proj.getFrame(), Strings.get("exportNewDirectoryErrorMessage"), Strings.get("exportNewDirectoryErrorTitle"), JOptionPane.YES_NO_OPTION);
return;
}
}
}
// Create the progress monitor
ProgressMonitor monitor = new ProgressMonitor(frame, Strings.get("exportImageProgress"), null, 0, 10000);
monitor.setMillisToDecideToPopup(100);
monitor.setMillisToPopup(200);
monitor.setProgress(0);
// And start a thread to actually perform the operation
// (This is run in a thread so that Swing will update the
// monitor.)
new ExportThread(frame, frame.getCanvas(), dest, filter, circuits, scale, printerView, monitor).start();
}
Aggregations