示例#1
0
 static {
   // FOP installed?
   if (SVGPlot.hasFOPInstalled()) {
     formats = new String[] {"svg", "png", "jpeg", "jpg", "pdf", "ps", "eps"};
     visibleformats = new String[] {automagic_format, "svg", "png", "jpeg", "pdf", "ps", "eps"};
   } else {
     formats = new String[] {"svg", "png", "jpeg", "jpg"};
     visibleformats = new String[] {automagic_format, "svg", "png", "jpeg"};
   }
 }
示例#2
0
  /**
   * Show a "Save as" dialog.
   *
   * @param plot The plot to be exported.
   * @param width The width of the exported image (when export to JPEG/PNG).
   * @param height The height of the exported image (when export to JPEG/PNG).
   * @return Result from {@link JFileChooser#showSaveDialog}
   */
  public static int showSaveDialog(SVGPlot plot, int width, int height) {
    double quality = 1.0;
    int ret = -1;

    JFileChooser fc = new JFileChooser(new File("."));
    fc.setDialogTitle(DEFAULT_TITLE);
    // fc.setFileFilter(new ImageFilter());
    SaveOptionsPanel optionsPanel = new SaveOptionsPanel(fc, width, height);
    fc.setAccessory(optionsPanel);

    ret = fc.showSaveDialog(null);
    fc.setDialogTitle("Saving... Please wait.");
    if (ret == JFileChooser.APPROVE_OPTION) {
      File file = fc.getSelectedFile();
      String format = optionsPanel.getSelectedFormat();
      if (format == null || automagic_format.equals(format)) {
        format = guessFormat(file.getName());
      }
      try {
        if (format == null) {
          showError(fc, "Error saving image.", "File format not recognized.");
        } else if ("jpeg".equals(format) || "jpg".equals(format)) {
          quality = optionsPanel.getJPEGQuality();
          plot.saveAsJPEG(file, width, height, quality);
        } else if ("png".equals(format)) {
          plot.saveAsPNG(file, width, height);
        } else if ("ps".equals(format)) {
          plot.saveAsPS(file);
        } else if ("eps".equals(format)) {
          plot.saveAsEPS(file);
        } else if ("pdf".equals(format)) {
          plot.saveAsPDF(file);
        } else if ("svg".equals(format)) {
          plot.saveAsSVG(file);
        } else {
          showError(fc, "Error saving image.", "Unsupported format: " + format);
        }
      } catch (java.lang.IncompatibleClassChangeError e) {
        showError(
            fc,
            "Error saving image.",
            "It seems that your Java version is incompatible with this version of Batik and Jpeg writing. Sorry.");
      } catch (ClassNotFoundException e) {
        showError(
            fc,
            "Error saving image.",
            "A class was not found when saving this image. Maybe installing Apache FOP will help (for PDF, PS and EPS output).\n"
                + e.toString());
      } catch (IOException e) {
        LOG.exception(e);
        showError(fc, "Error saving image.", e.toString());
      } catch (TranscoderException e) {
        LOG.exception(e);
        showError(fc, "Error saving image.", e.toString());
      } catch (TransformerFactoryConfigurationError e) {
        LOG.exception(e);
        showError(fc, "Error saving image.", e.toString());
      } catch (TransformerException e) {
        LOG.exception(e);
        showError(fc, "Error saving image.", e.toString());
      } catch (Exception e) {
        LOG.exception(e);
        showError(fc, "Error saving image.", e.toString());
      }
    } else if (ret == JFileChooser.ERROR_OPTION) {
      showError(fc, "Error in file dialog.", "Unknown Error.");
    } else if (ret == JFileChooser.CANCEL_OPTION) {
      // do nothing - except return result
    }
    return ret;
  }