org.jfree.chart.title.PaintScaleLegend Java Examples

The following examples show how to use org.jfree.chart.title.PaintScaleLegend. 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 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 #2
Source File: StandardChartTheme.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Applies the attributes of this theme to the specified title.
 *
 * @param title  the title.
 */
protected void applyToTitle(Title title) {
    if (title instanceof TextTitle) {
        TextTitle tt = (TextTitle) title;
        tt.setFont(this.largeFont);
        tt.setPaint(this.subtitlePaint);
    }
    else if (title instanceof LegendTitle) {
        LegendTitle lt = (LegendTitle) title;
        if (lt.getBackgroundPaint() != null) {
            lt.setBackgroundPaint(this.legendBackgroundPaint);
        }
        lt.setItemFont(this.regularFont);
        lt.setItemPaint(this.legendItemPaint);
        if (lt.getWrapper() != null) {
            applyToBlockContainer(lt.getWrapper());
        }
    }
    else if (title instanceof PaintScaleLegend) {
        PaintScaleLegend psl = (PaintScaleLegend) title;
        psl.setBackgroundPaint(this.legendBackgroundPaint);
        ValueAxis axis = psl.getAxis();
        if (axis != null) {
            applyToValueAxis(axis);
        }
    }
    else if (title instanceof CompositeTitle) {
        CompositeTitle ct = (CompositeTitle) title;
        BlockContainer bc = ct.getContainer();
        List blocks = bc.getBlocks();
        Iterator iterator = blocks.iterator();
        while (iterator.hasNext()) {
            Block b = (Block) iterator.next();
            if (b instanceof Title) {
                applyToTitle((Title) b);
            }
        }
    }
}
 
Example #3
Source File: StandardChartTheme.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Applies the attributes of this theme to the specified title.
 *
 * @param title  the title.
 */
protected void applyToTitle(Title title) {
    if (title instanceof TextTitle) {
        TextTitle tt = (TextTitle) title;
        tt.setFont(this.largeFont);
        tt.setPaint(this.subtitlePaint);
    }
    else if (title instanceof LegendTitle) {
        LegendTitle lt = (LegendTitle) title;
        if (lt.getBackgroundPaint() != null) {
            lt.setBackgroundPaint(this.legendBackgroundPaint);
        }
        lt.setItemFont(this.regularFont);
        lt.setItemPaint(this.legendItemPaint);
        if (lt.getWrapper() != null) {
            applyToBlockContainer(lt.getWrapper());
        }
    }
    else if (title instanceof PaintScaleLegend) {
        PaintScaleLegend psl = (PaintScaleLegend) title;
        psl.setBackgroundPaint(this.legendBackgroundPaint);
        ValueAxis axis = psl.getAxis();
        if (axis != null) {
            applyToValueAxis(axis);
        }
    }
    else if (title instanceof CompositeTitle) {
        CompositeTitle ct = (CompositeTitle) title;
        BlockContainer bc = ct.getContainer();
        List blocks = bc.getBlocks();
        Iterator iterator = blocks.iterator();
        while (iterator.hasNext()) {
            Block b = (Block) iterator.next();
            if (b instanceof Title) {
                applyToTitle((Title) b);
            }
        }
    }
}
 
Example #4
Source File: PaintScaleLegendTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Two objects that are equal are required to return the same hashCode. 
 */
public void testHashcode() {
    PaintScaleLegend l1 = new PaintScaleLegend(new GrayPaintScale(), 
            new NumberAxis("X"));
    PaintScaleLegend l2 = new PaintScaleLegend(new GrayPaintScale(), 
            new NumberAxis("X"));
    assertTrue(l1.equals(l2));
    int h1 = l1.hashCode();
    int h2 = l2.hashCode();
    assertEquals(h1, h2);
}
 
Example #5
Source File: StandardChartTheme.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Applies the attributes of this theme to the specified title.
 *
 * @param title  the title.
 */
protected void applyToTitle(Title title) {
    if (title instanceof TextTitle) {
        TextTitle tt = (TextTitle) title;
        tt.setFont(this.largeFont);
        tt.setPaint(this.subtitlePaint);
    }
    else if (title instanceof LegendTitle) {
        LegendTitle lt = (LegendTitle) title;
        if (lt.getBackgroundPaint() != null) {
            lt.setBackgroundPaint(this.legendBackgroundPaint);
        }
        lt.setItemFont(this.regularFont);
        lt.setItemPaint(this.legendItemPaint);
        if (lt.getWrapper() != null) {
            applyToBlockContainer(lt.getWrapper());
        }
    }
    else if (title instanceof PaintScaleLegend) {
        PaintScaleLegend psl = (PaintScaleLegend) title;
        psl.setBackgroundPaint(this.legendBackgroundPaint);
        ValueAxis axis = psl.getAxis();
        if (axis != null) {
            applyToValueAxis(axis);
        }
    }
    else if (title instanceof CompositeTitle) {
        CompositeTitle ct = (CompositeTitle) title;
        BlockContainer bc = ct.getContainer();
        List blocks = bc.getBlocks();
        Iterator iterator = blocks.iterator();
        while (iterator.hasNext()) {
            Block b = (Block) iterator.next();
            if (b instanceof Title) {
                applyToTitle((Title) b);
            }
        }
    }
}
 
Example #6
Source File: PaintScaleLegendTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Two objects that are equal are required to return the same hashCode.
 */
public void testHashcode() {
    PaintScaleLegend l1 = new PaintScaleLegend(new GrayPaintScale(),
            new NumberAxis("X"));
    PaintScaleLegend l2 = new PaintScaleLegend(new GrayPaintScale(),
            new NumberAxis("X"));
    assertTrue(l1.equals(l2));
    int h1 = l1.hashCode();
    int h2 = l2.hashCode();
    assertEquals(h1, h2);
}
 
Example #7
Source File: StandardChartTheme.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Applies the attributes of this theme to the specified title.
 *
 * @param title  the title.
 */
protected void applyToTitle(Title title) {
    if (title instanceof TextTitle) {
        TextTitle tt = (TextTitle) title;
        tt.setFont(this.largeFont);
        tt.setPaint(this.subtitlePaint);
    }
    else if (title instanceof LegendTitle) {
        LegendTitle lt = (LegendTitle) title;
        if (lt.getBackgroundPaint() != null) {
            lt.setBackgroundPaint(this.legendBackgroundPaint);
        }
        lt.setItemFont(this.regularFont);
        lt.setItemPaint(this.legendItemPaint);
        if (lt.getWrapper() != null) {
            applyToBlockContainer(lt.getWrapper());
        }
    }
    else if (title instanceof PaintScaleLegend) {
        PaintScaleLegend psl = (PaintScaleLegend) title;
        psl.setBackgroundPaint(this.legendBackgroundPaint);
        ValueAxis axis = psl.getAxis();
        if (axis != null) {
            applyToValueAxis(axis);
        }
    }
    else if (title instanceof CompositeTitle) {
        CompositeTitle ct = (CompositeTitle) title;
        BlockContainer bc = ct.getContainer();
        List blocks = bc.getBlocks();
        Iterator iterator = blocks.iterator();
        while (iterator.hasNext()) {
            Block b = (Block) iterator.next();
            if (b instanceof Title) {
                applyToTitle((Title) b);
            }
        }
    }
}
 
Example #8
Source File: ChartJFreeChartOutputHeatmap.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void preResetSeries(final IScope scope) {
	this.clearDataSet(scope);
	final ArrayList<PaintScaleLegend> caxe = new ArrayList<>();
	chart.setSubtitles(caxe);

}
 
Example #9
Source File: StandardChartTheme.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Applies the attributes of this theme to the specified title.
 *
 * @param title  the title.
 */
protected void applyToTitle(Title title) {
    if (title instanceof TextTitle) {
        TextTitle tt = (TextTitle) title;
        tt.setFont(this.largeFont);
        tt.setPaint(this.subtitlePaint);
    }
    else if (title instanceof LegendTitle) {
        LegendTitle lt = (LegendTitle) title;
        if (lt.getBackgroundPaint() != null) {
            lt.setBackgroundPaint(this.legendBackgroundPaint);
        }
        lt.setItemFont(this.regularFont);
        lt.setItemPaint(this.legendItemPaint);
        if (lt.getWrapper() != null) {
            applyToBlockContainer(lt.getWrapper());
        }
    }
    else if (title instanceof PaintScaleLegend) {
        PaintScaleLegend psl = (PaintScaleLegend) title;
        psl.setBackgroundPaint(this.legendBackgroundPaint);
        ValueAxis axis = psl.getAxis();
        if (axis != null) {
            applyToValueAxis(axis);
        }
    }
    else if (title instanceof CompositeTitle) {
        CompositeTitle ct = (CompositeTitle) title;
        BlockContainer bc = ct.getContainer();
        List blocks = bc.getBlocks();
        Iterator iterator = blocks.iterator();
        while (iterator.hasNext()) {
            Block b = (Block) iterator.next();
            if (b instanceof Title) {
                applyToTitle((Title) b);
            }
        }
    }
}
 
Example #10
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 #11
Source File: StandardChartTheme.java    From SIMVA-SoS with Apache License 2.0 5 votes vote down vote up
/**
 * Applies the attributes of this theme to the specified title.
 *
 * @param title  the title.
 */
protected void applyToTitle(Title title) {
    if (title instanceof TextTitle) {
        TextTitle tt = (TextTitle) title;
        tt.setFont(this.largeFont);
        tt.setPaint(this.subtitlePaint);
    }
    else if (title instanceof LegendTitle) {
        LegendTitle lt = (LegendTitle) title;
        if (lt.getBackgroundPaint() != null) {
            lt.setBackgroundPaint(this.legendBackgroundPaint);
        }
        lt.setItemFont(this.regularFont);
        lt.setItemPaint(this.legendItemPaint);
        if (lt.getWrapper() != null) {
            applyToBlockContainer(lt.getWrapper());
        }
    }
    else if (title instanceof PaintScaleLegend) {
        PaintScaleLegend psl = (PaintScaleLegend) title;
        psl.setBackgroundPaint(this.legendBackgroundPaint);
        ValueAxis axis = psl.getAxis();
        if (axis != null) {
            applyToValueAxis(axis);
        }
    }
    else if (title instanceof CompositeTitle) {
        CompositeTitle ct = (CompositeTitle) title;
        BlockContainer bc = ct.getContainer();
        List blocks = bc.getBlocks();
        Iterator iterator = blocks.iterator();
        while (iterator.hasNext()) {
            Block b = (Block) iterator.next();
            if (b instanceof Title) {
                applyToTitle((Title) b);
            }
        }
    }
}
 
Example #12
Source File: StandardChartTheme.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Applies the attributes of this theme to the specified title.
 *
 * @param title  the title.
 */
protected void applyToTitle(Title title) {
    if (title instanceof TextTitle) {
        TextTitle tt = (TextTitle) title;
        tt.setFont(this.largeFont);
        tt.setPaint(this.subtitlePaint);
    }
    else if (title instanceof LegendTitle) {
        LegendTitle lt = (LegendTitle) title;
        if (lt.getBackgroundPaint() != null) {
            lt.setBackgroundPaint(this.legendBackgroundPaint);
        }
        lt.setItemFont(this.regularFont);
        lt.setItemPaint(this.legendItemPaint);
        if (lt.getWrapper() != null) {
            applyToBlockContainer(lt.getWrapper());
        }
    }
    else if (title instanceof PaintScaleLegend) {
        PaintScaleLegend psl = (PaintScaleLegend) title;
        psl.setBackgroundPaint(this.legendBackgroundPaint);
        ValueAxis axis = psl.getAxis();
        if (axis != null) {
            applyToValueAxis(axis);
        }
    }
    else if (title instanceof CompositeTitle) {
        CompositeTitle ct = (CompositeTitle) title;
        BlockContainer bc = ct.getContainer();
        List blocks = bc.getBlocks();
        Iterator iterator = blocks.iterator();
        while (iterator.hasNext()) {
            Block b = (Block) iterator.next();
            if (b instanceof Title) {
                applyToTitle((Title) b);
            }
        }
    }
}
 
Example #13
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 #14
Source File: RTMZPlot.java    From mzmine2 with GNU General Public License v2.0 4 votes vote down vote up
public RTMZPlot(RTMZAnalyzerWindow masterFrame, AbstractXYZDataset dataset,
    InterpolatingLookupPaintScale paintScale) {
  super(null);

  this.paintScale = paintScale;

  chart = ChartFactory.createXYAreaChart("", "Retention time", "m/z", dataset,
      PlotOrientation.VERTICAL, false, false, false);
  chart.setBackgroundPaint(Color.white);
  setChart(chart);

  // title

  TextTitle chartTitle = chart.getTitle();
  chartTitle.setMargin(5, 0, 0, 0);
  chartTitle.setFont(titleFont);
  chart.removeSubtitle(chartTitle);

  // disable maximum size (we don't want scaling)
  setMaximumDrawWidth(Integer.MAX_VALUE);
  setMaximumDrawHeight(Integer.MAX_VALUE);

  // set the plot properties
  plot = chart.getXYPlot();
  plot.setBackgroundPaint(Color.white);
  plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));

  // set grid properties
  plot.setDomainGridlinePaint(gridColor);
  plot.setRangeGridlinePaint(gridColor);

  // set crosshair (selection) properties
  plot.setDomainCrosshairVisible(true);
  plot.setRangeCrosshairVisible(true);
  plot.setDomainCrosshairPaint(crossHairColor);
  plot.setRangeCrosshairPaint(crossHairColor);
  plot.setDomainCrosshairStroke(crossHairStroke);
  plot.setRangeCrosshairStroke(crossHairStroke);

  NumberFormat rtFormat = MZmineCore.getConfiguration().getRTFormat();
  NumberFormat mzFormat = MZmineCore.getConfiguration().getMZFormat();

  // set the X axis (retention time) properties
  NumberAxis xAxis = (NumberAxis) plot.getDomainAxis();
  xAxis.setNumberFormatOverride(rtFormat);
  xAxis.setUpperMargin(0.001);
  xAxis.setLowerMargin(0.001);

  // set the Y axis (intensity) properties
  NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
  yAxis.setAutoRangeIncludesZero(false);
  yAxis.setNumberFormatOverride(mzFormat);

  plot.setDataset(dataset);
  spotRenderer = new RTMZRenderer(dataset, paintScale);
  plot.setRenderer(spotRenderer);
  spotRenderer.setDefaultToolTipGenerator(new RTMZToolTipGenerator());

  // Add a paintScaleLegend to chart

  paintScaleAxis = new NumberAxis("Logratio");
  paintScaleAxis.setRange(paintScale.getLowerBound(), paintScale.getUpperBound());

  paintScaleLegend = new PaintScaleLegend(paintScale, paintScaleAxis);
  paintScaleLegend.setPosition(plot.getDomainAxisEdge());
  paintScaleLegend.setMargin(5, 25, 5, 25);

  chart.addSubtitle(paintScaleLegend);


  // reset zoom history
  ZoomHistory history = getZoomHistory();
  if (history != null)
    history.clear();
}
 
Example #15
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);
}
 
Example #16
Source File: ChartJFreeChartOutputHeatmap.java    From gama with GNU General Public License v3.0 4 votes vote down vote up
protected void resetRenderer(final IScope scope, final String serieid) {
	final XYBlockRenderer newr = (XYBlockRenderer) this.getOrCreateRenderer(scope, serieid);

	// newr.setSeriesStroke(0, new BasicStroke(0));
	final ChartDataSeries myserie = this.getChartdataset().getDataSeries(scope, serieid);

	if (myserie.getMycolor() != null) {
		newr.setSeriesPaint(0, myserie.getMycolor());
	}
	if (myserie.getSValues(scope).size() > 0) {
		final double maxval = Collections.max(myserie.getSValues(scope));
		final double minval = Collections.min(myserie.getSValues(scope));
		Color cdeb = new Color(0, 0, 0, 0);
		if (myserie.getMyMincolor() != null) {
			cdeb = myserie.getMyMincolor();
		}
		Color cend = new Color(0.9f, 0.9f, 0.9f, 1.0f);
		if (myserie.getMycolor() != null) {
			cend = myserie.getMycolor();
		}

		LookupPaintScale paintscale = createLUT(100, (float) minval, (float) maxval, cdeb, cend);
		if (myserie.getMyMedcolor() != null) {
			paintscale = createLUT(100, (float) minval, (float) maxval, cdeb, myserie.getMyMedcolor(), cend);
		}

		newr.setPaintScale(paintscale);

		final NumberAxis scaleAxis = new NumberAxis(myserie.getName());
		scaleAxis.setAxisLinePaint(this.axesColor);
		scaleAxis.setTickMarkPaint(this.axesColor);
		scaleAxis.setTickLabelFont(this.getTickFont());
		scaleAxis.setRange(minval, maxval);
		scaleAxis.setAxisLinePaint(axesColor);
		scaleAxis.setLabelFont(getLabelFont());
		if (textColor != null) {
			scaleAxis.setLabelPaint(textColor);
			scaleAxis.setTickLabelPaint(textColor);
		}
		if (!this.getXTickValueVisible(scope)) {
			scaleAxis.setTickMarksVisible(false);
			scaleAxis.setTickLabelsVisible(false);

		}

		final PaintScaleLegend legend = new PaintScaleLegend(paintscale, scaleAxis);
		legend.setAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
		legend.setAxisOffset(5.0);
		// legend.setMargin(new RectangleInsets(5, 5, 5, 5));
		// legend.setFrame(new BlockBorder(Color.red));
		// legend.setPadding(new RectangleInsets(10, 10, 10, 10));
		// legend.setStripWidth(10);
		legend.setPosition(RectangleEdge.RIGHT);
		legend.setBackgroundPaint(this.backgroundColor);
		// ArrayList<PaintScaleLegend> caxe=new
		// ArrayList<PaintScaleLegend>();
		// caxe.add(legend);
		// chart.setSubtitles(caxe);
		if (!this.series_label_position.equals("none")) {
			chart.addSubtitle(legend);
		}

	}
}
 
Example #17
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 #18
Source File: PaintScaleLegendTests.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Test that the equals() method distinguishes all fields.
 */
public void testEquals() {

    // default instances
    PaintScaleLegend l1 = new PaintScaleLegend(new GrayPaintScale(),
            new NumberAxis("X"));
    PaintScaleLegend l2 = new PaintScaleLegend(new GrayPaintScale(),
            new NumberAxis("X"));
    assertTrue(l1.equals(l2));
    assertTrue(l2.equals(l1));

    // paintScale
    l1.setScale(new LookupPaintScale());
    assertFalse(l1.equals(l2));
    l2.setScale(new LookupPaintScale());
    assertTrue(l1.equals(l2));

    // axis
    l1.setAxis(new NumberAxis("Axis 2"));
    assertFalse(l1.equals(l2));
    l2.setAxis(new NumberAxis("Axis 2"));
    assertTrue(l1.equals(l2));

    // axisLocation
    l1.setAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);
    assertFalse(l1.equals(l2));
    l2.setAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);
    assertTrue(l1.equals(l2));

    // axisOffset
    l1.setAxisOffset(99.0);
    assertFalse(l1.equals(l2));
    l2.setAxisOffset(99.0);
    assertTrue(l1.equals(l2));

    // stripWidth
    l1.setStripWidth(99.0);
    assertFalse(l1.equals(l2));
    l2.setStripWidth(99.0);
    assertTrue(l1.equals(l2));

    // stripOutlineVisible
    l1.setStripOutlineVisible(!l1.isStripOutlineVisible());
    assertFalse(l1.equals(l2));
    l2.setStripOutlineVisible(l1.isStripOutlineVisible());
    assertTrue(l1.equals(l2));

    // stripOutlinePaint
    l1.setStripOutlinePaint(new GradientPaint(1.0f, 2.0f, Color.red,
            3.0f, 4.0f, Color.blue));
    assertFalse(l1.equals(l2));
    l2.setStripOutlinePaint(new GradientPaint(1.0f, 2.0f, Color.red,
            3.0f, 4.0f, Color.blue));
    assertTrue(l1.equals(l2));

    // stripOutlineStroke
    l1.setStripOutlineStroke(new BasicStroke(1.1f));
    assertFalse(l1.equals(l2));
    l2.setStripOutlineStroke(new BasicStroke(1.1f));
    assertTrue(l1.equals(l2));

    // backgroundPaint
    l1.setBackgroundPaint(new GradientPaint(1.0f, 2.0f, Color.red,
            3.0f, 4.0f, Color.blue));
    assertFalse(l1.equals(l2));
    l2.setBackgroundPaint(new GradientPaint(1.0f, 2.0f, Color.red,
            3.0f, 4.0f, Color.blue));
    assertTrue(l1.equals(l2));

    l1.setSubdivisionCount(99);
    assertFalse(l1.equals(l2));
    l2.setSubdivisionCount(99);
    assertTrue(l1.equals(l2));

}
 
Example #19
Source File: PlotUtil.java    From dl4j-tutorials with MIT License 4 votes vote down vote up
private static JFreeChart createChart(XYZDataset dataset, double[] mins, double[] maxs, int nPoints, XYDataset xyData) {
    NumberAxis xAxis = new NumberAxis("X");
    xAxis.setRange(mins[0],maxs[0]);


    NumberAxis yAxis = new NumberAxis("Y");
    yAxis.setRange(mins[1], maxs[1]);

    XYBlockRenderer renderer = new XYBlockRenderer();
    renderer.setBlockWidth((maxs[0]-mins[0])/(nPoints-1));
    renderer.setBlockHeight((maxs[1] - mins[1]) / (nPoints - 1));
    PaintScale scale = new GrayPaintScale(0, 1.0);
    renderer.setPaintScale(scale);
    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinesVisible(false);
    plot.setRangeGridlinesVisible(false);
    plot.setAxisOffset(new RectangleInsets(5, 5, 5, 5));
    JFreeChart chart = new JFreeChart("", plot);
    chart.getXYPlot().getRenderer().setSeriesVisibleInLegend(0, false);


    NumberAxis scaleAxis = new NumberAxis("Probability (class 0)");
    scaleAxis.setAxisLinePaint(Color.white);
    scaleAxis.setTickMarkPaint(Color.white);
    scaleAxis.setTickLabelFont(new Font("Dialog", Font.PLAIN, 7));
    PaintScaleLegend legend = new PaintScaleLegend(new GrayPaintScale(),
            scaleAxis);
    legend.setStripOutlineVisible(false);
    legend.setSubdivisionCount(20);
    legend.setAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    legend.setAxisOffset(5.0);
    legend.setMargin(new RectangleInsets(5, 5, 5, 5));
    legend.setFrame(new BlockBorder(Color.red));
    legend.setPadding(new RectangleInsets(10, 10, 10, 10));
    legend.setStripWidth(10);
    legend.setPosition(RectangleEdge.LEFT);
    chart.addSubtitle(legend);

    ChartUtilities.applyCurrentTheme(chart);

    plot.setDataset(1, xyData);
    XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer();
    renderer2.setBaseLinesVisible(false);
    plot.setRenderer(1, renderer2);

    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

    return chart;
}
 
Example #20
Source File: PaintScaleLegendTests.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Test that the equals() method distinguishes all fields.
 */
public void testEquals() {
    
    // default instances
    PaintScaleLegend l1 = new PaintScaleLegend(new GrayPaintScale(), 
            new NumberAxis("X"));
    PaintScaleLegend l2 = new PaintScaleLegend(new GrayPaintScale(), 
            new NumberAxis("X"));
    assertTrue(l1.equals(l2));
    assertTrue(l2.equals(l1));
    
    // paintScale
    l1.setScale(new LookupPaintScale());
    assertFalse(l1.equals(l2));
    l2.setScale(new LookupPaintScale());
    assertTrue(l1.equals(l2));
    
    // axis
    l1.setAxis(new NumberAxis("Axis 2"));
    assertFalse(l1.equals(l2));
    l2.setAxis(new NumberAxis("Axis 2"));
    assertTrue(l1.equals(l2));
    
    // axisLocation
    l1.setAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);
    assertFalse(l1.equals(l2));
    l2.setAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);
    assertTrue(l1.equals(l2));
    
    // axisOffset
    l1.setAxisOffset(99.0);
    assertFalse(l1.equals(l2));
    l2.setAxisOffset(99.0);
    assertTrue(l1.equals(l2));
    
    // stripWidth
    l1.setStripWidth(99.0);
    assertFalse(l1.equals(l2));
    l2.setStripWidth(99.0);
    assertTrue(l1.equals(l2));
    
    // stripOutlineVisible
    l1.setStripOutlineVisible(!l1.isStripOutlineVisible());
    assertFalse(l1.equals(l2));
    l2.setStripOutlineVisible(l1.isStripOutlineVisible());
    assertTrue(l1.equals(l2));
    
    // stripOutlinePaint
    l1.setStripOutlinePaint(new GradientPaint(1.0f, 2.0f, Color.red,
            3.0f, 4.0f, Color.blue));
    assertFalse(l1.equals(l2));
    l2.setStripOutlinePaint(new GradientPaint(1.0f, 2.0f, Color.red,
            3.0f, 4.0f, Color.blue));
    assertTrue(l1.equals(l2));
    
    // stripOutlineStroke
    l1.setStripOutlineStroke(new BasicStroke(1.1f));
    assertFalse(l1.equals(l2));
    l2.setStripOutlineStroke(new BasicStroke(1.1f));
    assertTrue(l1.equals(l2));
    
    // backgroundPaint
    l1.setBackgroundPaint(new GradientPaint(1.0f, 2.0f, Color.red,
            3.0f, 4.0f, Color.blue));
    assertFalse(l1.equals(l2));
    l2.setBackgroundPaint(new GradientPaint(1.0f, 2.0f, Color.red,
            3.0f, 4.0f, Color.blue));
    assertTrue(l1.equals(l2));
        
}
 
Example #21
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 #22
Source File: RTMZPlot.java    From mzmine3 with GNU General Public License v2.0 4 votes vote down vote up
public RTMZPlot(RTMZAnalyzerWindow masterFrame, AbstractXYZDataset dataset,
    InterpolatingLookupPaintScale paintScale) {
  super(null);

  this.paintScale = paintScale;

  chart = ChartFactory.createXYAreaChart("", "Retention time", "m/z", dataset,
      PlotOrientation.VERTICAL, false, false, false);
  chart.setBackgroundPaint(Color.white);
  setChart(chart);

  // title

  TextTitle chartTitle = chart.getTitle();
  chartTitle.setMargin(5, 0, 0, 0);
  chartTitle.setFont(titleFont);
  chart.removeSubtitle(chartTitle);

  // disable maximum size (we don't want scaling)
  // setMaximumDrawWidth(Integer.MAX_VALUE);
  // setMaximumDrawHeight(Integer.MAX_VALUE);

  // set the plot properties
  plot = chart.getXYPlot();
  plot.setBackgroundPaint(Color.white);
  plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));

  // set grid properties
  plot.setDomainGridlinePaint(gridColor);
  plot.setRangeGridlinePaint(gridColor);

  // set crosshair (selection) properties
  plot.setDomainCrosshairVisible(true);
  plot.setRangeCrosshairVisible(true);
  plot.setDomainCrosshairPaint(crossHairColor);
  plot.setRangeCrosshairPaint(crossHairColor);
  plot.setDomainCrosshairStroke(crossHairStroke);
  plot.setRangeCrosshairStroke(crossHairStroke);

  NumberFormat rtFormat = MZmineCore.getConfiguration().getRTFormat();
  NumberFormat mzFormat = MZmineCore.getConfiguration().getMZFormat();

  // set the X axis (retention time) properties
  NumberAxis xAxis = (NumberAxis) plot.getDomainAxis();
  xAxis.setNumberFormatOverride(rtFormat);
  xAxis.setUpperMargin(0.001);
  xAxis.setLowerMargin(0.001);

  // set the Y axis (intensity) properties
  NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
  yAxis.setAutoRangeIncludesZero(false);
  yAxis.setNumberFormatOverride(mzFormat);

  plot.setDataset(dataset);
  spotRenderer = new RTMZRenderer(dataset, paintScale);
  plot.setRenderer(spotRenderer);
  spotRenderer.setDefaultToolTipGenerator(new RTMZToolTipGenerator());

  // Add a paintScaleLegend to chart

  paintScaleAxis = new NumberAxis("Logratio");
  paintScaleAxis.setRange(paintScale.getLowerBound(), paintScale.getUpperBound());

  paintScaleLegend = new PaintScaleLegend(paintScale, paintScaleAxis);
  paintScaleLegend.setPosition(plot.getDomainAxisEdge());
  paintScaleLegend.setMargin(5, 25, 5, 25);

  chart.addSubtitle(paintScaleLegend);

  // reset zoom history
  ZoomHistory history = getZoomHistory();
  if (history != null)
    history.clear();
}