Search in sources :

Example 16 with Loader

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();
}
Also used : Loader(com.cburch.logisim.file.Loader) Circuit(com.cburch.logisim.circuit.Circuit) ProgressMonitor(javax.swing.ProgressMonitor) JFileChooser(javax.swing.JFileChooser) File(java.io.File)

Aggregations

Loader (com.cburch.logisim.file.Loader)16 LogisimFile (com.cburch.logisim.file.LogisimFile)12 File (java.io.File)10 LoadFailedException (com.cburch.logisim.file.LoadFailedException)6 JFileChooser (javax.swing.JFileChooser)6 IOException (java.io.IOException)5 Library (com.cburch.logisim.tools.Library)3 Circuit (com.cburch.logisim.circuit.Circuit)2 Project (com.cburch.logisim.proj.Project)2 InputStream (java.io.InputStream)2 JarFile (java.util.jar.JarFile)2 CircuitState (com.cburch.logisim.circuit.CircuitState)1 LoadedLibrary (com.cburch.logisim.file.LoadedLibrary)1 Frame (com.cburch.logisim.gui.main.Frame)1 Print (com.cburch.logisim.gui.main.Print)1 LogisimMenuBar (com.cburch.logisim.gui.menu.LogisimMenuBar)1 Instance (com.cburch.logisim.instance.Instance)1 Tool (com.cburch.logisim.tools.Tool)1 FileNotFoundException (java.io.FileNotFoundException)1 MalformedURLException (java.net.MalformedURLException)1