Java Code Examples for org.jfree.chart.LegendItemCollection#add()

The following examples show how to use org.jfree.chart.LegendItemCollection#add() . 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: PolarPlot.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns the legend items for the plot.  Each legend item is generated by
 * the plot's m_Renderer, since the m_Renderer is responsible for the visual
 * representation of the data.
 *
 * @return The legend items.
 */
@Override
public LegendItemCollection getLegendItems() {
    if (this.fixedLegendItems != null) {
        return this.fixedLegendItems;
    }
    LegendItemCollection result = new LegendItemCollection();
    int count = this.datasets.size();
    for (int datasetIndex = 0; datasetIndex < count; datasetIndex++) {
        XYDataset dataset = getDataset(datasetIndex);
        PolarItemRenderer renderer = getRenderer(datasetIndex);
        if (dataset != null && renderer != null) {
            int seriesCount = dataset.getSeriesCount();
            for (int i = 0; i < seriesCount; i++) {
                LegendItem item = renderer.getLegendItem(i);
                result.add(item);
            }
        }
    }
    return result;
}
 
Example 2
Source File: MeterPlot.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns an item for each interval.
 *
 * @return A collection of legend items.
 */
@Override
public LegendItemCollection getLegendItems() {
    LegendItemCollection result = new LegendItemCollection();
    Iterator iterator = this.intervals.iterator();
    while (iterator.hasNext()) {
        MeterInterval mi = (MeterInterval) iterator.next();
        Paint color = mi.getBackgroundPaint();
        if (color == null) {
            color = mi.getOutlinePaint();
        }
        LegendItem item = new LegendItem(mi.getLabel(), mi.getLabel(),
                null, null, new Rectangle2D.Double(-4.0, -4.0, 8.0, 8.0),
                color);
        item.setDataset(getDataset());
        result.add(item);
    }
    return result;
}
 
Example 3
Source File: PolarPlot.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns the legend items for the plot.  Each legend item is generated by
 * the plot's m_Renderer, since the m_Renderer is responsible for the visual
 * representation of the data.
 *
 * @return The legend items.
 */
@Override
public LegendItemCollection getLegendItems() {
    if (this.fixedLegendItems != null) {
        return this.fixedLegendItems;
    }
    LegendItemCollection result = new LegendItemCollection();
    int count = this.datasets.size();
    for (int datasetIndex = 0; datasetIndex < count; datasetIndex++) {
        XYDataset dataset = getDataset(datasetIndex);
        PolarItemRenderer renderer = getRenderer(datasetIndex);
        if (dataset != null && renderer != null) {
            int seriesCount = dataset.getSeriesCount();
            for (int i = 0; i < seriesCount; i++) {
                LegendItem item = renderer.getLegendItem(i);
                result.add(item);
            }
        }
    }
    return result;
}
 
Example 4
Source File: AbstractXYItemRenderer.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns a (possibly empty) collection of legend items for the series
 * that this renderer is responsible for drawing.
 *
 * @return The legend item collection (never <code>null</code>).
 */
@Override
public LegendItemCollection getLegendItems() {
    if (this.plot == null) {
        return new LegendItemCollection();
    }
    LegendItemCollection result = new LegendItemCollection();
    int index = this.plot.getIndexOf(this);
    XYDataset dataset = this.plot.getDataset(index);
    if (dataset != null) {
        int seriesCount = dataset.getSeriesCount();
        for (int i = 0; i < seriesCount; i++) {
            if (isSeriesVisibleInLegend(i)) {
                LegendItem item = getLegendItem(index, i);
                if (item != null) {
                    result.add(item);
                }
            }
        }

    }
    return result;
}
 
Example 5
Source File: XYPlot.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns the legend items for the plot.  Each legend item is generated by
 * the plot's renderer, since the renderer is responsible for the visual
 * representation of the data.
 *
 * @return The legend items.
 */
@Override
public LegendItemCollection getLegendItems() {
    if (this.fixedLegendItems != null) {
        return this.fixedLegendItems;
    }
    LegendItemCollection result = new LegendItemCollection();
    for (XYDataset dataset : this.datasets.values()) {
        if (dataset == null) {
            continue;
        }
        int datasetIndex = indexOf(dataset);
        XYItemRenderer renderer = getRenderer(datasetIndex);
        if (renderer == null) {
            renderer = getRenderer(0);
        }
        if (renderer != null) {
            int seriesCount = dataset.getSeriesCount();
            for (int i = 0; i < seriesCount; i++) {
                if (renderer.isSeriesVisible(i)
                        && renderer.isSeriesVisibleInLegend(i)) {
                    LegendItem item = renderer.getLegendItem(
                            datasetIndex, i);
                    if (item != null) {
                        result.add(item);
                    }
                }
            }
        }
    }
    return result;
}
 
Example 6
Source File: SpiderWebPlot.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a collection of legend items for the radar chart.
 * 
 * @return The legend items.
 */
public LegendItemCollection getLegendItems() {
    LegendItemCollection result = new LegendItemCollection();

    List keys = null;

    if (this.dataExtractOrder == TableOrder.BY_ROW) {
        keys = this.dataset.getRowKeys();
    }
    else if (this.dataExtractOrder == TableOrder.BY_COLUMN) {
        keys = this.dataset.getColumnKeys();
    }

    if (keys != null) {
        int series = 0;
        Iterator iterator = keys.iterator();
        Shape shape = getLegendItemShape();

        while (iterator.hasNext()) {
            String label = iterator.next().toString();
            String description = label;

            Paint paint = getSeriesPaint(series);
            Paint outlinePaint = getSeriesOutlinePaint(series);
            Stroke stroke = getSeriesOutlineStroke(series);
            LegendItem item = new LegendItem(label, description, 
                    null, null, shape, paint, stroke, outlinePaint);
            item.setDataset(getDataset());
            result.add(item);
            series++;
        }
    }

    return result;
}
 
Example 7
Source File: SpiderWebPlot.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns a collection of legend items for the spider web chart.
 *
 * @return The legend items (never <code>null</code>).
 */
@Override
public LegendItemCollection getLegendItems() {
    LegendItemCollection result = new LegendItemCollection();
    if (getDataset() == null) {
        return result;
    }
    List keys = null;
    if (this.dataExtractOrder == TableOrder.BY_ROW) {
        keys = this.dataset.getRowKeys();
    }
    else if (this.dataExtractOrder == TableOrder.BY_COLUMN) {
        keys = this.dataset.getColumnKeys();
    }
    if (keys == null) {
        return result;
    }

    int series = 0;
    Iterator iterator = keys.iterator();
    Shape shape = getLegendItemShape();
    while (iterator.hasNext()) {
        Comparable key = (Comparable) iterator.next();
        String label = key.toString();
        String description = label;
        Paint paint = getSeriesPaint(series);
        Paint outlinePaint = getSeriesOutlinePaint(series);
        Stroke stroke = getSeriesOutlineStroke(series);
        LegendItem item = new LegendItem(label, description,
                null, null, shape, paint, stroke, outlinePaint);
        item.setDataset(getDataset());
        item.setSeriesKey(key);
        item.setSeriesIndex(series);
        result.add(item);
        series++;
    }
    return result;
}
 
Example 8
Source File: XYPlot.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns the legend items for the plot.  Each legend item is generated by
 * the plot's renderer, since the renderer is responsible for the visual
 * representation of the data.
 *
 * @return The legend items.
 */
@Override
public LegendItemCollection getLegendItems() {
    if (this.fixedLegendItems != null) {
        return this.fixedLegendItems;
    }
    LegendItemCollection result = new LegendItemCollection();
    for (XYDataset dataset : this.datasets.values()) {
        if (dataset == null) {
            continue;
        }
        int datasetIndex = indexOf(dataset);
        XYItemRenderer renderer = getRenderer(datasetIndex);
        if (renderer == null) {
            renderer = getRenderer(0);
        }
        if (renderer != null) {
            int seriesCount = dataset.getSeriesCount();
            for (int i = 0; i < seriesCount; i++) {
                if (renderer.isSeriesVisible(i)
                        && renderer.isSeriesVisibleInLegend(i)) {
                    LegendItem item = renderer.getLegendItem(
                            datasetIndex, i);
                    if (item != null) {
                        result.add(item);
                    }
                }
            }
        }
    }
    return result;
}
 
Example 9
Source File: arja3_three_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * Returns a collection of legend items for the pie chart.
 *
 * @return The legend items.
 */
public LegendItemCollection getLegendItems() {

    LegendItemCollection result = new LegendItemCollection();

    if (this.dataset != null) {
        List keys = null;

        prefetchSectionPaints();
        if (this.dataExtractOrder == TableOrder.BY_ROW) {
            keys = this.dataset.getColumnKeys();
        }
        else if (this.dataExtractOrder == TableOrder.BY_COLUMN) {
            keys = this.dataset.getRowKeys();
        }

        if (keys != null) {
            int section = 0;
            Iterator iterator = keys.iterator();
            while (iterator.hasNext()) {
                Comparable key = (Comparable) iterator.next();
                String label = key.toString();
                String description = label;
                Paint paint = (Paint) this.sectionPaints.get(key);
                LegendItem item = new LegendItem(label, description,
                        null, null, Plot.DEFAULT_LEGEND_ITEM_CIRCLE,
                        paint, Plot.DEFAULT_OUTLINE_STROKE, paint);
                item.setDataset(getDataset());
                result.add(item);
                section++;
            }
        }
        if (this.limit > 0.0) {
            result.add(new LegendItem(this.aggregatedItemsKey.toString(),
                    this.aggregatedItemsKey.toString(), null, null,
                    Plot.DEFAULT_LEGEND_ITEM_CIRCLE,
                    this.aggregatedItemsPaint,
                    Plot.DEFAULT_OUTLINE_STROKE,
                    this.aggregatedItemsPaint));
        }
    }
    return result;
}
 
Example 10
Source File: MsMsVisualizerWindow.java    From mzmine2 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
 */
public void actionPerformed(ActionEvent event) {

  String command = event.getActionCommand();

  if (command.equals("SHOW_SPECTRUM")) {
    CursorPosition pos = getCursorPosition();
    if (pos != null) {
      SpectraVisualizerModule.showNewSpectrumWindow(pos.getDataFile(), pos.getScanNumber());
    }
  }

  if (command.equals("SETUP_AXES")) {
    AxesSetupDialog dialog = new AxesSetupDialog(this, IDAPlot.getXYPlot());
    dialog.setVisible(true);
  }

  if (command.equals("SHOW_DATA_POINTS")) {
    IDAPlot.switchDataPointsVisible();
  }

  if (command.equals("SWITCH_TOOLTIPS")) {
    if (tooltipMode) {
      IDAPlot.showPeaksTooltips(false);
      toolBar.setTooltipButton(false);
      tooltipMode = false;
    } else {
      IDAPlot.showPeaksTooltips(true);
      toolBar.setTooltipButton(true);
      tooltipMode = true;
    }
  }

  if (command.equals("FIND_SPECTRA")) {

    // Parameters
    final DoubleParameter inputMZ =
        new DoubleParameter("Ion m/z", "m/z value of ion to search for.");

    final MZToleranceParameter inputMZTolerance = new MZToleranceParameter();

    final DoubleParameter inputIntensity = new DoubleParameter("Min. ion intensity",
        "Only ions with intensities above this value will be searched for.");

    final BooleanParameter inputNL = new BooleanParameter("Neutral Loss",
        "If selected, the ion to be searched for will be a neutral loss ion.\nIn this case, only ions above the min. intensity will be examined.",
        false);

    final ComboParameter<Colors> inputColors = new ComboParameter<Colors>("Color",
        "The color which the data points will be marked with.", Colors.values());

    Parameter<?>[] parameters = new Parameter<?>[5];
    parameters[0] = inputMZ;
    parameters[1] = inputMZTolerance;
    parameters[2] = inputIntensity;
    parameters[3] = inputNL;
    parameters[4] = inputColors;

    final ParameterSet parametersSearch = new SimpleParameterSet(parameters);
    ExitCode exitCode = parametersSearch.showSetupDialog(this, true);

    if (exitCode != ExitCode.OK)
      return;

    double searchMZ = parametersSearch.getParameter(inputMZ).getValue();
    MZTolerance searchMZTolerance = parametersSearch.getParameter(inputMZTolerance).getValue();
    double minIntensity = parametersSearch.getParameter(inputIntensity).getValue();
    boolean neutralLoss = parametersSearch.getParameter(inputNL).getValue();

    Color highligtColor = Color.red;;
    if (parametersSearch.getParameter(inputColors).getValue().equals(Colors.green)) {
      highligtColor = Color.green;
    }
    if (parametersSearch.getParameter(inputColors).getValue().equals(Colors.blue)) {
      highligtColor = Color.blue;
    }

    // Find and highlight spectra with specific ion
    dataset.highlightSpectra(searchMZ, searchMZTolerance, minIntensity, neutralLoss,
        highligtColor);

    // Add legend entry
    LegendItemCollection chartLegend = IDAPlot.getXYPlot().getLegendItems();
    chartLegend.add(new LegendItem("Ion: " + searchMZ, "",
        "MS/MS spectra which contain the " + searchMZ + " ion\nTolerance: "
            + searchMZTolerance.toString() + "\nMin intensity: " + minIntensity,
        "", new Ellipse2D.Double(0, 0, 7, 7), highligtColor));
    IDAPlot.getXYPlot().setFixedLegendItems(chartLegend);
  }

}
 
Example 11
Source File: PolarPlotTest.java    From ECG-Viewer with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Some checks for the equals() method.
 */
@Test
public void testEquals() {
    PolarPlot plot1 = new PolarPlot();
    PolarPlot plot2 = new PolarPlot();
    assertTrue(plot1.equals(plot2));
    assertTrue(plot2.equals(plot1));

    plot1.setAngleGridlinePaint(new GradientPaint(1.0f, 2.0f, Color.red,
            3.0f, 4.0f, Color.blue));
    assertFalse(plot1.equals(plot2));
    plot2.setAngleGridlinePaint(new GradientPaint(1.0f, 2.0f, Color.red,
            3.0f, 4.0f, Color.blue));
    assertTrue(plot1.equals(plot2));

    Stroke s = new BasicStroke(1.23f);
    plot1.setAngleGridlineStroke(s);
    assertFalse(plot1.equals(plot2));
    plot2.setAngleGridlineStroke(s);
    assertTrue(plot1.equals(plot2));

    plot1.setAngleTickUnit(new NumberTickUnit(11.0));
    assertFalse(plot1.equals(plot2));
    plot2.setAngleTickUnit(new NumberTickUnit(11.0));
    assertTrue(plot1.equals(plot2));

    plot1.setAngleGridlinesVisible(false);
    assertFalse(plot1.equals(plot2));
    plot2.setAngleGridlinesVisible(false);
    assertTrue(plot1.equals(plot2));

    plot1.setAngleLabelFont(new Font("Serif", Font.PLAIN, 9));
    assertFalse(plot1.equals(plot2));
    plot2.setAngleLabelFont(new Font("Serif", Font.PLAIN, 9));
    assertTrue(plot1.equals(plot2));

    plot1.setAngleLabelPaint(new GradientPaint(9.0f, 8.0f, Color.blue,
            7.0f, 6.0f, Color.red));
    assertFalse(plot1.equals(plot2));
    plot2.setAngleLabelPaint(new GradientPaint(9.0f, 8.0f, Color.blue,
            7.0f, 6.0f, Color.red));
    assertTrue(plot1.equals(plot2));

    plot1.setAngleLabelsVisible(false);
    assertFalse(plot1.equals(plot2));
    plot2.setAngleLabelsVisible(false);
    assertTrue(plot1.equals(plot2));

    plot1.setAxis(new NumberAxis("Test"));
    assertFalse(plot1.equals(plot2));
    plot2.setAxis(new NumberAxis("Test"));
    assertTrue(plot1.equals(plot2));

    plot1.setRadiusGridlinePaint(new GradientPaint(1.0f, 2.0f, Color.white,
            3.0f, 4.0f, Color.black));
    assertFalse(plot1.equals(plot2));
    plot2.setRadiusGridlinePaint(new GradientPaint(1.0f, 2.0f, Color.white,
            3.0f, 4.0f, Color.black));
    assertTrue(plot1.equals(plot2));

    plot1.setRadiusGridlineStroke(s);
    assertFalse(plot1.equals(plot2));
    plot2.setRadiusGridlineStroke(s);
    assertTrue(plot1.equals(plot2));

    plot1.setRadiusGridlinesVisible(false);
    assertFalse(plot1.equals(plot2));
    plot2.setRadiusGridlinesVisible(false);
    assertTrue(plot1.equals(plot2));

    plot1.setRadiusMinorGridlinesVisible(false);
    assertFalse(plot1.equals(plot2));
    plot2.setRadiusMinorGridlinesVisible(false);
    assertTrue(plot1.equals(plot2));

    plot1.addCornerTextItem("XYZ");
    assertFalse(plot1.equals(plot2));
    plot2.addCornerTextItem("XYZ");
    assertTrue(plot1.equals(plot2));

    plot1.setMargin(6);
    assertFalse(plot1.equals(plot2));
    plot2.setMargin(6);
    assertTrue(plot1.equals(plot2));

    LegendItemCollection lic1 = new LegendItemCollection();
    lic1.add(new LegendItem("XYZ", Color.red));
    plot1.setFixedLegendItems(lic1);
    assertFalse(plot1.equals(plot2));
    LegendItemCollection lic2 = new LegendItemCollection();
    lic2.add(new LegendItem("XYZ", Color.red));
    plot2.setFixedLegendItems(lic2);
    assertTrue(plot1.equals(plot2));
}
 
Example 12
Source File: Arja_00174_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * Returns a collection of legend items for the pie chart.
 *
 * @return The legend items.
 */
public LegendItemCollection getLegendItems() {

    LegendItemCollection result = new LegendItemCollection();

    if (this.dataset != null) {
        List keys = null;

        prefetchSectionPaints();
        if (this.dataExtractOrder == TableOrder.BY_ROW) {
            keys = this.dataset.getColumnKeys();
        }
        else if (this.dataExtractOrder == TableOrder.BY_COLUMN) {
            keys = this.dataset.getRowKeys();
        }

        if (keys != null) {
            int section = 0;
            Iterator iterator = keys.iterator();
            while (iterator.hasNext()) {
                Comparable key = (Comparable) iterator.next();
                String label = key.toString();
                String description = label;
                Paint paint = (Paint) this.sectionPaints.get(key);
                LegendItem item = new LegendItem(label, description,
                        null, null, Plot.DEFAULT_LEGEND_ITEM_CIRCLE,
                        paint, Plot.DEFAULT_OUTLINE_STROKE, paint);
                item.setDataset(getDataset());
                result.add(item);
                section++;
            }
        }
        if (this.limit > 0.0) {
            result.add(new LegendItem(this.aggregatedItemsKey.toString(),
                    this.aggregatedItemsKey.toString(), null, null,
                    Plot.DEFAULT_LEGEND_ITEM_CIRCLE,
                    this.aggregatedItemsPaint,
                    Plot.DEFAULT_OUTLINE_STROKE,
                    this.aggregatedItemsPaint));
        }
    }
    return result;
}
 
Example 13
Source File: Chart_12_MultiplePiePlot_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * Returns a collection of legend items for the pie chart.
 *
 * @return The legend items.
 */
public LegendItemCollection getLegendItems() {

    LegendItemCollection result = new LegendItemCollection();

    if (this.dataset != null) {
        List keys = null;

        prefetchSectionPaints();
        if (this.dataExtractOrder == TableOrder.BY_ROW) {
            keys = this.dataset.getColumnKeys();
        }
        else if (this.dataExtractOrder == TableOrder.BY_COLUMN) {
            keys = this.dataset.getRowKeys();
        }

        if (keys != null) {
            int section = 0;
            Iterator iterator = keys.iterator();
            while (iterator.hasNext()) {
                Comparable key = (Comparable) iterator.next();
                String label = key.toString();
                String description = label;
                Paint paint = (Paint) this.sectionPaints.get(key);
                LegendItem item = new LegendItem(label, description,
                        null, null, Plot.DEFAULT_LEGEND_ITEM_CIRCLE,
                        paint, Plot.DEFAULT_OUTLINE_STROKE, paint);
                item.setDataset(getDataset());
                result.add(item);
                section++;
            }
        }
        if (this.limit > 0.0) {
            result.add(new LegendItem(this.aggregatedItemsKey.toString(),
                    this.aggregatedItemsKey.toString(), null, null,
                    Plot.DEFAULT_LEGEND_ITEM_CIRCLE,
                    this.aggregatedItemsPaint,
                    Plot.DEFAULT_OUTLINE_STROKE,
                    this.aggregatedItemsPaint));
        }
    }
    return result;
}
 
Example 14
Source File: Arja_00174_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * Returns a collection of legend items for the pie chart.
 *
 * @return The legend items.
 */
public LegendItemCollection getLegendItems() {

    LegendItemCollection result = new LegendItemCollection();

    if (this.dataset != null) {
        List keys = null;

        prefetchSectionPaints();
        if (this.dataExtractOrder == TableOrder.BY_ROW) {
            keys = this.dataset.getColumnKeys();
        }
        else if (this.dataExtractOrder == TableOrder.BY_COLUMN) {
            keys = this.dataset.getRowKeys();
        }

        if (keys != null) {
            int section = 0;
            Iterator iterator = keys.iterator();
            while (iterator.hasNext()) {
                Comparable key = (Comparable) iterator.next();
                String label = key.toString();
                String description = label;
                Paint paint = (Paint) this.sectionPaints.get(key);
                LegendItem item = new LegendItem(label, description,
                        null, null, Plot.DEFAULT_LEGEND_ITEM_CIRCLE,
                        paint, Plot.DEFAULT_OUTLINE_STROKE, paint);
                item.setDataset(getDataset());
                result.add(item);
                section++;
            }
        }
        if (this.limit > 0.0) {
            result.add(new LegendItem(this.aggregatedItemsKey.toString(),
                    this.aggregatedItemsKey.toString(), null, null,
                    Plot.DEFAULT_LEGEND_ITEM_CIRCLE,
                    this.aggregatedItemsPaint,
                    Plot.DEFAULT_OUTLINE_STROKE,
                    this.aggregatedItemsPaint));
        }
    }
    return result;
}
 
Example 15
Source File: MultiplePiePlot.java    From buffer_bci with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Returns a collection of legend items for the pie chart.
 *
 * @return The legend items.
 */
@Override
public LegendItemCollection getLegendItems() {

    LegendItemCollection result = new LegendItemCollection();
    if (this.dataset == null) {
        return result;
    }

    List keys = null;
    prefetchSectionPaints();
    if (this.dataExtractOrder == TableOrder.BY_ROW) {
        keys = this.dataset.getColumnKeys();
    }
    else if (this.dataExtractOrder == TableOrder.BY_COLUMN) {
        keys = this.dataset.getRowKeys();
    }
    if (keys == null) {
        return result;
    }
    int section = 0;
    Iterator iterator = keys.iterator();
    while (iterator.hasNext()) {
        Comparable key = (Comparable) iterator.next();
        String label = key.toString();  // TODO: use a generator here
        String description = label;
        Paint paint = (Paint) this.sectionPaints.get(key);
        LegendItem item = new LegendItem(label, description, null,
                null, getLegendItemShape(), paint,
                Plot.DEFAULT_OUTLINE_STROKE, paint);
        item.setSeriesKey(key);
        item.setSeriesIndex(section);
        item.setDataset(getDataset());
        result.add(item);
        section++;
    }
    if (this.limit > 0.0) {
        LegendItem a = new LegendItem(this.aggregatedItemsKey.toString(),
                this.aggregatedItemsKey.toString(), null, null,
                getLegendItemShape(), this.aggregatedItemsPaint,
                Plot.DEFAULT_OUTLINE_STROKE, this.aggregatedItemsPaint);
        result.add(a);
    }
    return result;
}
 
Example 16
Source File: ProjectionPlotPanel.java    From mzmine3 with GNU General Public License v2.0 4 votes vote down vote up
public ProjectionPlotPanel(ProjectionPlotWindow masterFrame, ProjectionPlotDataset dataset,
    ParameterSet parameters) {
  super(null);

  boolean createLegend = false;
  if ((dataset.getNumberOfGroups() > 1) && (dataset.getNumberOfGroups() < 20))
    createLegend = true;

  chart = ChartFactory.createXYAreaChart("", dataset.getXLabel(), dataset.getYLabel(), dataset,
      PlotOrientation.VERTICAL, createLegend, 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(false);
  plot.setRangeCrosshairVisible(false);

  plot.setForegroundAlpha(dataPointAlpha);

  NumberFormat numberFormat = NumberFormat.getNumberInstance();

  // set the X axis (component 1) properties
  NumberAxis xAxis = (NumberAxis) plot.getDomainAxis();
  xAxis.setNumberFormatOverride(numberFormat);

  // set the Y axis (component 2) properties
  NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
  yAxis.setNumberFormatOverride(numberFormat);

  plot.setDataset(dataset);

  spotRenderer = new ProjectionPlotRenderer(plot, dataset);
  itemLabelGenerator = new ProjectionPlotItemLabelGenerator(parameters);
  spotRenderer.setDefaultItemLabelGenerator(itemLabelGenerator);
  spotRenderer.setDefaultItemLabelsVisible(true);
  spotRenderer.setDefaultToolTipGenerator(new ProjectionPlotToolTipGenerator(parameters));
  plot.setRenderer(spotRenderer);

  // Setup legend
  if (createLegend) {
    LegendItemCollection legendItemsCollection = new LegendItemCollection();
    for (int groupNumber = 0; groupNumber < dataset.getNumberOfGroups(); groupNumber++) {
      Object paramValue = dataset.getGroupParameterValue(groupNumber);
      if (paramValue == null) {
        // No parameter value available: search for raw data files
        // within this group, and use their names as group's name
        String fileNames = new String();
        for (int itemNumber = 0; itemNumber < dataset.getItemCount(0); itemNumber++) {
          String rawDataFile = dataset.getRawDataFile(itemNumber);
          if (dataset.getGroupNumber(itemNumber) == groupNumber)
            fileNames = fileNames.concat(rawDataFile);
        }
        if (fileNames.length() == 0)
          fileNames = "Empty group";

        paramValue = fileNames;
      }
      Color nextColor = (Color) spotRenderer.getGroupPaint(groupNumber);
      Color groupColor = new Color(nextColor.getRed(), nextColor.getGreen(), nextColor.getBlue(),
          Math.round(255 * dataPointAlpha));
      legendItemsCollection.add(new LegendItem(paramValue.toString(), "-", null, null,
          spotRenderer.getDataPointsShape(), groupColor));
    }
    plot.setFixedLegendItems(legendItemsCollection);
  }

  // reset zoom history
  ZoomHistory history = getZoomHistory();
  if (history != null)
    history.clear();
}
 
Example 17
Source File: Chart_12_MultiplePiePlot_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * Returns a collection of legend items for the pie chart.
 *
 * @return The legend items.
 */
public LegendItemCollection getLegendItems() {

    LegendItemCollection result = new LegendItemCollection();

    if (this.dataset != null) {
        List keys = null;

        prefetchSectionPaints();
        if (this.dataExtractOrder == TableOrder.BY_ROW) {
            keys = this.dataset.getColumnKeys();
        }
        else if (this.dataExtractOrder == TableOrder.BY_COLUMN) {
            keys = this.dataset.getRowKeys();
        }

        if (keys != null) {
            int section = 0;
            Iterator iterator = keys.iterator();
            while (iterator.hasNext()) {
                Comparable key = (Comparable) iterator.next();
                String label = key.toString();
                String description = label;
                Paint paint = (Paint) this.sectionPaints.get(key);
                LegendItem item = new LegendItem(label, description,
                        null, null, Plot.DEFAULT_LEGEND_ITEM_CIRCLE,
                        paint, Plot.DEFAULT_OUTLINE_STROKE, paint);
                item.setDataset(getDataset());
                result.add(item);
                section++;
            }
        }
        if (this.limit > 0.0) {
            result.add(new LegendItem(this.aggregatedItemsKey.toString(),
                    this.aggregatedItemsKey.toString(), null, null,
                    Plot.DEFAULT_LEGEND_ITEM_CIRCLE,
                    this.aggregatedItemsPaint,
                    Plot.DEFAULT_OUTLINE_STROKE,
                    this.aggregatedItemsPaint));
        }
    }
    return result;
}
 
Example 18
Source File: PiePlot.java    From buffer_bci with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Returns a collection of legend items for the pie chart.
 *
 * @return The legend items (never <code>null</code>).
 */
@Override
public LegendItemCollection getLegendItems() {

    LegendItemCollection result = new LegendItemCollection();
    if (this.dataset == null) {
        return result;
    }
    List keys = this.dataset.getKeys();
    int section = 0;
    Shape shape = getLegendItemShape();
    Iterator iterator = keys.iterator();
    while (iterator.hasNext()) {
        Comparable key = (Comparable) iterator.next();
        Number n = this.dataset.getValue(key);
        boolean include;
        if (n == null) {
            include = !this.ignoreNullValues;
        }
        else {
            double v = n.doubleValue();
            if (v == 0.0) {
                include = !this.ignoreZeroValues;
            }
            else {
                include = v > 0.0;
            }
        }
        if (include) {
            String label = this.legendLabelGenerator.generateSectionLabel(
                    this.dataset, key);
            if (label != null) {
                String description = label;
                String toolTipText = null;
                if (this.legendLabelToolTipGenerator != null) {
                    toolTipText = this.legendLabelToolTipGenerator
                            .generateSectionLabel(this.dataset, key);
                }
                String urlText = null;
                if (this.legendLabelURLGenerator != null) {
                    urlText = this.legendLabelURLGenerator.generateURL(
                            this.dataset, key, this.pieIndex);
                }
                Paint paint = lookupSectionPaint(key);
                Paint outlinePaint = lookupSectionOutlinePaint(key);
                Stroke outlineStroke = lookupSectionOutlineStroke(key);
                LegendItem item = new LegendItem(label, description,
                        toolTipText, urlText, true, shape, true, paint,
                        true, outlinePaint, outlineStroke,
                        false,          // line not visible
                        new Line2D.Float(), new BasicStroke(), Color.black);
                item.setDataset(getDataset());
                item.setSeriesIndex(this.dataset.getIndex(key));
                item.setSeriesKey(key);
                result.add(item);
            }
            section++;
        }
        else {
            section++;
        }
    }
    return result;
}
 
Example 19
Source File: arja3_three_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * Returns a collection of legend items for the pie chart.
 *
 * @return The legend items.
 */
public LegendItemCollection getLegendItems() {

    LegendItemCollection result = new LegendItemCollection();

    if (this.dataset != null) {
        List keys = null;

        prefetchSectionPaints();
        if (this.dataExtractOrder == TableOrder.BY_ROW) {
            keys = this.dataset.getColumnKeys();
        }
        else if (this.dataExtractOrder == TableOrder.BY_COLUMN) {
            keys = this.dataset.getRowKeys();
        }

        if (keys != null) {
            int section = 0;
            Iterator iterator = keys.iterator();
            while (iterator.hasNext()) {
                Comparable key = (Comparable) iterator.next();
                String label = key.toString();
                String description = label;
                Paint paint = (Paint) this.sectionPaints.get(key);
                LegendItem item = new LegendItem(label, description,
                        null, null, Plot.DEFAULT_LEGEND_ITEM_CIRCLE,
                        paint, Plot.DEFAULT_OUTLINE_STROKE, paint);
                item.setDataset(getDataset());
                result.add(item);
                section++;
            }
        }
        if (this.limit > 0.0) {
            result.add(new LegendItem(this.aggregatedItemsKey.toString(),
                    this.aggregatedItemsKey.toString(), null, null,
                    Plot.DEFAULT_LEGEND_ITEM_CIRCLE,
                    this.aggregatedItemsPaint,
                    Plot.DEFAULT_OUTLINE_STROKE,
                    this.aggregatedItemsPaint));
        }
    }
    return result;
}
 
Example 20
Source File: Chart_15_PiePlot_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * Returns a collection of legend items for the pie chart.
 *
 * @return The legend items (never <code>null</code>).
 */
public LegendItemCollection getLegendItems() {

    LegendItemCollection result = new LegendItemCollection();
    if (this.dataset == null) {
        return result;
    }
    List keys = this.dataset.getKeys();
    int section = 0;
    Shape shape = getLegendItemShape();
    Iterator iterator = keys.iterator();
    while (iterator.hasNext()) {
        Comparable key = (Comparable) iterator.next();
        Number n = this.dataset.getValue(key);
        boolean include = true;
        if (n == null) {
            include = !this.ignoreNullValues;   
        }
        else {
            double v = n.doubleValue();
            if (v == 0.0) {
                include = !this.ignoreZeroValues;   
            }
            else {
                include = v > 0.0;   
            }
        }
        if (include) {
            String label = this.legendLabelGenerator.generateSectionLabel(
                    this.dataset, key);
            if (label != null) {
                String description = label;
                String toolTipText = null;
                if (this.legendLabelToolTipGenerator != null) {
                    toolTipText = this.legendLabelToolTipGenerator
                            .generateSectionLabel(this.dataset, key);
                }
                String urlText = null;
                if (this.legendLabelURLGenerator != null) {
                    urlText = this.legendLabelURLGenerator.generateURL(
                            this.dataset, key, this.pieIndex);
                }
                Paint paint = lookupSectionPaint(key, true);
                Paint outlinePaint = lookupSectionOutlinePaint(key);
                Stroke outlineStroke = lookupSectionOutlineStroke(key);
                LegendItem item = new LegendItem(label, description, 
                        toolTipText, urlText, true, shape, true, paint, 
                        true, outlinePaint, outlineStroke, 
                        false,          // line not visible
                        new Line2D.Float(), new BasicStroke(), Color.black);
                item.setDataset(getDataset());
                result.add(item);
            }
            section++;
        }
        else {
            section++;
        }
    }
    return result;
}