Java Code Examples for org.jfree.chart.JFreeChart#getBackgroundPaint()

The following examples show how to use org.jfree.chart.JFreeChart#getBackgroundPaint() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ChartExportUtil.java    From mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
public static void writeChartToJPEG(JFreeChart chart, ChartRenderingInfo info, int width,
    int height, File fileName, int resolution) throws IOException {
  // Background color
  Paint saved = chart.getBackgroundPaint();
  if (((Color) saved).getAlpha() == 0) {
    chart.setBackgroundPaint(Color.WHITE);
    chart.setBackgroundImageAlpha(255);
    if (chart.getLegend() != null)
      chart.getLegend().setBackgroundPaint(Color.WHITE);
    // legends and stuff
    for (int i = 0; i < chart.getSubtitleCount(); i++)
      if (PaintScaleLegend.class.isAssignableFrom(chart.getSubtitle(i).getClass()))
        ((PaintScaleLegend) chart.getSubtitle(i)).setBackgroundPaint(Color.WHITE);

    // apply bg
    chart.getPlot().setBackgroundPaint(Color.WHITE);
  }
  //
  if (resolution == 72)
    writeChartToJPEG(chart, width, height, fileName);
  else {
    OutputStream out = new BufferedOutputStream(new FileOutputStream(fileName));
    try {
      BufferedImage image = paintScaledChartToBufferedImage(chart, info, out, width, height,
          resolution, BufferedImage.TYPE_INT_RGB);
      EncoderUtil.writeBufferedImage(image, ImageFormat.JPEG, out, 1.f);
    } finally {
      out.close();
    }
  }
}
 
Example 2
Source File: ChartExportUtil.java    From old-mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
public static void writeChartToJPEG(JFreeChart chart, ChartRenderingInfo info, int width,
    int height, File fileName, int resolution) throws IOException {
  // Background color
  Paint saved = chart.getBackgroundPaint();
  if (((Color) saved).getAlpha() == 0) {
    chart.setBackgroundPaint(Color.WHITE);
    chart.setBackgroundImageAlpha(255);
    if (chart.getLegend() != null)
      chart.getLegend().setBackgroundPaint(Color.WHITE);
    // legends and stuff
    for (int i = 0; i < chart.getSubtitleCount(); i++)
      if (PaintScaleLegend.class.isAssignableFrom(chart.getSubtitle(i).getClass()))
        ((PaintScaleLegend) chart.getSubtitle(i)).setBackgroundPaint(Color.WHITE);

    // apply bg
    chart.getPlot().setBackgroundPaint(Color.WHITE);
  }
  //
  if (resolution == 72)
    writeChartToJPEG(chart, width, height, fileName);
  else {
    OutputStream out = new BufferedOutputStream(new FileOutputStream(fileName));
    try {
      BufferedImage image = paintScaledChartToBufferedImage(chart, info, out, width, height,
          resolution, BufferedImage.TYPE_INT_RGB);
      EncoderUtil.writeBufferedImage(image, ImageFormat.JPEG, out, 1.f);
    } finally {
      out.close();
    }
  }
}
 
Example 3
Source File: ChartExportUtil.java    From mzmine2 with GNU General Public License v2.0 5 votes vote down vote up
public static void writeChartToJPEG(JFreeChart chart, ChartRenderingInfo info, int width,
    int height, File fileName, int resolution) throws IOException {
  // Background color
  Paint saved = chart.getBackgroundPaint();
  if (((Color) saved).getAlpha() == 0) {
    chart.setBackgroundPaint(Color.WHITE);
    chart.setBackgroundImageAlpha(255);
    if (chart.getLegend() != null)
      chart.getLegend().setBackgroundPaint(Color.WHITE);
    // legends and stuff
    for (int i = 0; i < chart.getSubtitleCount(); i++)
      if (PaintScaleLegend.class.isAssignableFrom(chart.getSubtitle(i).getClass()))
        ((PaintScaleLegend) chart.getSubtitle(i)).setBackgroundPaint(Color.WHITE);

    // apply bg
    chart.getPlot().setBackgroundPaint(Color.WHITE);
  }
  //
  if (resolution == 72)
    writeChartToJPEG(chart, width, height, fileName);
  else {
    OutputStream out = new BufferedOutputStream(new FileOutputStream(fileName));
    try {
      BufferedImage image = paintScaledChartToBufferedImage(chart, info, out, width, height,
          resolution, BufferedImage.TYPE_INT_RGB);
      EncoderUtil.writeBufferedImage(image, ImageFormat.JPEG, out, 1.f);
    } finally {
      out.close();
    }
  }
}
 
Example 4
Source File: ChartExportUtil.java    From mzmine3 with GNU General Public License v2.0 4 votes vote down vote up
/**
   * This method is used to save all image formats. it uses the specific methods for each file
   * format
   *
   * @param chart
   * @param sett
   * @param info
   */
  private static void writeChartToImage(JFreeChart chart, GraphicsExportParameters sett,
      ChartRenderingInfo info) throws Exception {
    // Background color
    Paint saved = chart.getBackgroundPaint();
//    Color awtColor = FxColorUtil.fxColorToAWT(sett.getColorWithAlpha());
//    chart.setBackgroundPaint(awtColor);
//    chart.setBackgroundImageAlpha((float) sett.getTransparency());
//    if (chart.getLegend() != null)
//      chart.getLegend().setBackgroundPaint(awtColor);
    // legends and stuff
//    for (int i = 0; i < chart.getSubtitleCount(); i++)
//      if (PaintScaleLegend.class.isAssignableFrom(chart.getSubtitle(i).getClass()))
//        ((PaintScaleLegend) chart.getSubtitle(i)).setBackgroundPaint(awtColor);

    // apply bg
//    chart.getPlot().setBackgroundPaint(awtColor);

    // create folder
    File f = sett.getFullpath();
    if (!f.exists()) {
      if (f.getParentFile() != null) {
        f.getParentFile().mkdirs();
      }
      // f.createNewFile();
    }

    Dimension size = sett.getPixelSize();
    // Format
    switch (sett.getFormat()) {
      case "PDF":
        writeChartToPDF(chart, size.width, size.height, f);
        break;
      case "PNG":
        writeChartToPNG(chart, info, size.width, size.height, f, (int) sett.getDPI());
        break;
      case "JPG":
        writeChartToJPEG(chart, info, size.width, size.height, f, (int) sett.getDPI());
        break;
      case "EPS":
        writeChartToEPS(chart, size.width, size.height, f);
        break;
      case "SVG":
        writeChartToSVG(chart, size.width, size.height, f);
        break;
      case "EMF":
        writeChartToEMF(chart, size.width, size.height, f);
        break;
    }
    //
    chart.setBackgroundPaint(saved);
    chart.setBackgroundImageAlpha(255);
    if (chart.getLegend() != null)
      chart.getLegend().setBackgroundPaint(saved);
    // legends and stuff
    for (int i = 0; i < chart.getSubtitleCount(); i++)
      if (PaintScaleLegend.class.isAssignableFrom(chart.getSubtitle(i).getClass()))
        ((PaintScaleLegend) chart.getSubtitle(i)).setBackgroundPaint(saved);

    // apply bg
    chart.getPlot().setBackgroundPaint(saved);
  }
 
Example 5
Source File: ChartExportUtil.java    From old-mzmine3 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * This method is used to save all image formats. it uses the specific methods for each file
 * format
 * 
 * @param chart
 * @param sett
 * @param chartRenderingInfo
 */
private static void writeChartToImage(JFreeChart chart, GraphicsExportParameters sett,
    ChartRenderingInfo info) throws Exception {
  // Background color
  Paint saved = chart.getBackgroundPaint();
  chart.setBackgroundPaint(sett.getColorWithAlpha());
  chart.setBackgroundImageAlpha((float) sett.getTransparency());
  if (chart.getLegend() != null)
    chart.getLegend().setBackgroundPaint(sett.getColorWithAlpha());
  // legends and stuff
  for (int i = 0; i < chart.getSubtitleCount(); i++)
    if (PaintScaleLegend.class.isAssignableFrom(chart.getSubtitle(i).getClass()))
      ((PaintScaleLegend) chart.getSubtitle(i)).setBackgroundPaint(sett.getColorWithAlpha());

  // apply bg
  chart.getPlot().setBackgroundPaint(sett.getColorWithAlpha());

  // create folder
  File f = sett.getFullpath();
  if (!f.exists()) {
    if (f.getParentFile() != null)
      f.getParentFile().mkdirs();
    // f.createNewFile();
  }

  Dimension size = sett.getPixelSize();
  // Format
  switch (sett.getFormat()) {
    case "PDF":
      writeChartToPDF(chart, size.width, size.height, f);
      break;
    case "PNG":
      writeChartToPNG(chart, info, size.width, size.height, f, (int) sett.getDPI());
      break;
    case "JPG":
      writeChartToJPEG(chart, info, size.width, size.height, f, (int) sett.getDPI());
      break;
    case "EPS":
      writeChartToEPS(chart, size.width, size.height, f);
      break;
    case "SVG":
      writeChartToSVG(chart, size.width, size.height, f);
      break;
    case "EMF":
      writeChartToEMF(chart, size.width, size.height, f);
      break;
  }
  //
  chart.setBackgroundPaint(saved);
  chart.setBackgroundImageAlpha(255);
  if (chart.getLegend() != null)
    chart.getLegend().setBackgroundPaint(saved);
  // legends and stuff
  for (int i = 0; i < chart.getSubtitleCount(); i++)
    if (PaintScaleLegend.class.isAssignableFrom(chart.getSubtitle(i).getClass()))
      ((PaintScaleLegend) chart.getSubtitle(i)).setBackgroundPaint(saved);

  // apply bg
  chart.getPlot().setBackgroundPaint(saved);
}
 
Example 6
Source File: ChartExportUtil.java    From mzmine2 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * This method is used to save all image formats. it uses the specific methods for each file
 * format
 * 
 * @param chart
 * @param sett
 * @param chartRenderingInfo
 */
private static void writeChartToImage(JFreeChart chart, GraphicsExportParameters sett,
    ChartRenderingInfo info) throws Exception {
  // Background color
  Paint saved = chart.getBackgroundPaint();
  chart.setBackgroundPaint(sett.getColorWithAlpha());
  chart.setBackgroundImageAlpha((float) sett.getTransparency());
  if (chart.getLegend() != null)
    chart.getLegend().setBackgroundPaint(sett.getColorWithAlpha());
  // legends and stuff
  for (int i = 0; i < chart.getSubtitleCount(); i++)
    if (PaintScaleLegend.class.isAssignableFrom(chart.getSubtitle(i).getClass()))
      ((PaintScaleLegend) chart.getSubtitle(i)).setBackgroundPaint(sett.getColorWithAlpha());

  // apply bg
  chart.getPlot().setBackgroundPaint(sett.getColorWithAlpha());

  // create folder
  File f = sett.getFullpath();
  if (!f.exists()) {
    if (f.getParentFile() != null)
      f.getParentFile().mkdirs();
    // f.createNewFile();
  }

  Dimension size = sett.getPixelSize();
  // Format
  switch (sett.getFormat()) {
    case "PDF":
      writeChartToPDF(chart, size.width, size.height, f);
      break;
    case "PNG":
      writeChartToPNG(chart, info, size.width, size.height, f, (int) sett.getDPI());
      break;
    case "JPG":
      writeChartToJPEG(chart, info, size.width, size.height, f, (int) sett.getDPI());
      break;
    case "EPS":
      writeChartToEPS(chart, size.width, size.height, f);
      break;
    case "SVG":
      writeChartToSVG(chart, size.width, size.height, f);
      break;
    case "EMF":
      writeChartToEMF(chart, size.width, size.height, f);
      break;
  }
  //
  chart.setBackgroundPaint(saved);
  chart.setBackgroundImageAlpha(255);
  if (chart.getLegend() != null)
    chart.getLegend().setBackgroundPaint(saved);
  // legends and stuff
  for (int i = 0; i < chart.getSubtitleCount(); i++)
    if (PaintScaleLegend.class.isAssignableFrom(chart.getSubtitle(i).getClass()))
      ((PaintScaleLegend) chart.getSubtitle(i)).setBackgroundPaint(saved);

  // apply bg
  chart.getPlot().setBackgroundPaint(saved);
}