List of usage examples for org.jfree.chart LegendItemCollection iterator
public Iterator iterator()
From source file:unalcol.termites.boxplots.ECALMessages.java
private LegendTitle modifyLegend(JFreeChart chart, CategoryPlot plot) { LegendTitle legend = chart.getLegend(); chart.removeLegend();/*from ww w . java 2 s . co m*/ LegendItemSource[] items = legend.getSources(); for (LegendItemSource item : items) { //LegendItemCollection collection = items[i].getLegendItems(); LegendItemCollection collection = plot.getLegendItems(); for (Iterator iter = collection.iterator(); iter.hasNext();) { LegendItem element = (LegendItem) iter.next(); System.out.println(" ## #" + element.getLabel()); } } return legend; }
From source file:iDynoOptimizer.MOEAFramework26.src.org.moeaframework.analysis.diagnostics.LinePlot.java
@Override protected void update() { XYDataset dataset = null;/* w w w .j a v a 2 s . c o m*/ //generate the plot data if (controller.getShowIndividualTraces()) { dataset = new DefaultTableXYDataset(); for (ResultKey key : frame.getSelectedResults()) { generateIndividualSeries(key, (DefaultTableXYDataset) dataset); } } else { dataset = new YIntervalSeriesCollection(); for (ResultKey key : frame.getSelectedResults()) { generateQuantileSeries(key, (YIntervalSeriesCollection) dataset); } } //create the chart JFreeChart chart = ChartFactory.createXYLineChart(metric, localization.getString("text.NFE"), localization.getString("text.value"), dataset, PlotOrientation.VERTICAL, false, true, false); final XYPlot plot = chart.getXYPlot(); //setup the series renderer if (controller.getShowIndividualTraces()) { XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false); for (int i = 0; i < dataset.getSeriesCount(); i++) { Paint paint = frame.getPaintHelper().get(dataset.getSeriesKey(i)); renderer.setSeriesStroke(i, new BasicStroke(1f, 1, 1)); renderer.setSeriesPaint(i, paint); } plot.setRenderer(renderer); } else { DeviationRenderer renderer = new DeviationRenderer(true, false); for (int i = 0; i < dataset.getSeriesCount(); i++) { Paint paint = frame.getPaintHelper().get(dataset.getSeriesKey(i)); renderer.setSeriesStroke(i, new BasicStroke(3f, 1, 1)); renderer.setSeriesPaint(i, paint); renderer.setSeriesFillPaint(i, paint); } plot.setRenderer(renderer); } //create the legend final LegendItemCollection items = plot.getLegendItems(); Iterator<?> iterator = items.iterator(); Set<ResultKey> uniqueKeys = new HashSet<ResultKey>(); while (iterator.hasNext()) { LegendItem item = (LegendItem) iterator.next(); if (uniqueKeys.contains(item.getSeriesKey())) { iterator.remove(); } else { uniqueKeys.add((ResultKey) item.getSeriesKey()); } } LegendItemSource source = new LegendItemSource() { @Override public LegendItemCollection getLegendItems() { return items; } }; LegendTitle legend = new LegendTitle(source); legend.setMargin(new RectangleInsets(1.0, 1.0, 1.0, 1.0)); legend.setFrame(new LineBorder()); legend.setBackgroundPaint(Color.WHITE); legend.setPosition(RectangleEdge.BOTTOM); chart.addLegend(legend); //scale the axes final NumberAxis domainAxis = new NumberAxis(); domainAxis.setAutoRange(true); plot.setDomainAxis(domainAxis); //add overlay if (controller.getShowLastTrace() && !controller.getShowIndividualTraces() && (controller.getLastAccumulator() != null) && controller.getLastAccumulator().keySet().contains(metric)) { DefaultTableXYDataset dataset2 = new DefaultTableXYDataset(); XYSeries series = new XYSeries(localization.getString("text.last"), false, false); for (int i = 0; i < controller.getLastAccumulator().size(metric); i++) { series.add((Number) controller.getLastAccumulator().get("NFE", i), (Number) controller.getLastAccumulator().get(metric, i)); } dataset2.addSeries(series); XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(true, false); renderer2.setSeriesStroke(0, new BasicStroke(1f, 1, 1)); renderer2.setSeriesPaint(0, Color.BLACK); plot.setDataset(1, dataset2); plot.setRenderer(1, renderer2); plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); } //update the chart in the GUI removeAll(); add(new ChartPanel(chart), BorderLayout.CENTER); revalidate(); repaint(); }
From source file:unikn.dbis.univis.visualization.graph.plaf.VGraphUI.java
/** * Creates the listener responsible for calling the correct handlers based * on mouse events, and to select invidual cells. *//* w ww. j av a 2s .c o m*/ protected MouseListener createMouseListener() { return new MouseHandler() { /** * Invoked when a mouse button has been pressed on a component. * //@Override public void mousePressed(MouseEvent e) { Object o = graph.getFirstCellForLocation(e.getX(), e.getY()); if (o instanceof VGraphCell) { VGraphCell cell = (VGraphCell) o; JPopupMenu menu = new JPopupMenu(); VChartPanel chartPanel = (VChartPanel) cell.getUserObject(); if (chartPanel.isShowPopUp()) { LegendItemCollection collect = chartPanel.getChart().getPlot().getLegendItems(); JMenu first = new JMenu("1-39"); int checker = 0; for (Iterator iter = collect.iterator(); iter.hasNext();) { LegendItem item = (LegendItem) iter.next(); checker++; first.add(new JMenuItem(item.getLabel())); if ((checker % 40) == 0) { menu.add(first); first = new JMenu("" + checker + "-" + (checker + 39)); } if (!iter.hasNext()) { menu.add(first); } } menu.show(graph, e.getX(), e.getY()); } } super.mousePressed(e); } */ /** * Invoked when a mouse button has been pressed on a component. */ @Override public void mousePressed(MouseEvent e) { Object o = graph.getFirstCellForLocation(e.getX(), e.getY()); if (SwingUtilities.isLeftMouseButton(e) && e.isAltDown()) { if (o instanceof VGraphCell) { VGraphCell cell = (VGraphCell) o; JPopupMenu menu = new JPopupMenu(); VChartPanel chartPanel = (VChartPanel) cell.getUserObject(); LegendItemCollection collect = chartPanel.getChart().getPlot().getLegendItems(); JMenu first = new JMenu("1-39"); int checker = 0; for (Iterator iter = collect.iterator(); iter.hasNext();) { LegendItem item = (LegendItem) iter.next(); checker++; first.add(new JMenuItem(item.getLabel())); if ((checker % 40) == 0) { menu.add(first); first = new JMenu("" + checker + "-" + (checker + 39)); } if (!iter.hasNext()) { menu.add(first); } } menu.show(graph, e.getX(), e.getY()); } } super.mousePressed(e); if (o != null && o instanceof VGraphCell) { VGraphCell cell = (VGraphCell) o; o = cell.getUserObject(); if (o != null && o instanceof VChartPanel) { VChartPanel chart = (VChartPanel) o; for (MouseListener l : chart.getMouseListeners()) { l.mousePressed(e); } } } } // Event may be null when called to cancel the current operation. @Override public void mouseReleased(MouseEvent e) { super.mouseReleased(e); Object o = graph.getFirstCellForLocation(e.getX(), e.getY()); if (o != null && o instanceof VGraphCell) { VGraphCell cell = (VGraphCell) o; o = cell.getUserObject(); if (o != null && o instanceof VChartPanel) { VChartPanel chart = (VChartPanel) o; for (MouseListener l : chart.getMouseListeners()) { l.mouseReleased(e); } } } } /** * Invoked when the mouse has been clicked on a component. */ @Override public void mouseClicked(MouseEvent e) { super.mouseClicked(e); Object o = graph.getFirstCellForLocation(e.getX(), e.getY()); if (o != null && o instanceof VGraphCell) { VGraphCell cell = (VGraphCell) o; o = cell.getUserObject(); if (o != null && o instanceof VChartPanel) { VChartPanel chart = (VChartPanel) o; if (SwingUtilities.isRightMouseButton(e)) { JPopupMenu menu = chart.createPopupMenu(true, true, true, true); menu.show(graph, e.getX(), e.getY()); } /* for (MouseListener l : chart.getMouseListeners()) { System.out.println("LISTENS CLI"); l.mouseClicked(e); } */ } } } /* // Event may be null when called to cancel the current operation. @Override public void mouseReleased(MouseEvent e) { super.mouseReleased(e); Object[] cells = graphSelectionModel.getSelectionCells(); Rectangle2D bounds = graph.getCellBounds(cells); if (bounds != null) { Rectangle2D b2 = graph.toScreen((Rectangle2D) bounds.clone()); graph.scrollRectToVisible(new Rectangle((int) b2.getX(), (int) b2.getY(), (int) b2.getWidth(), (int) b2.getHeight())); } } */ /** * Invoked when the mouse pointer has been moved on a component (with no * buttons down). */ @Override public void mouseMoved(MouseEvent e) { if (graph.isMoveable()) { super.mouseMoved(e); } Object o = graph.getFirstCellForLocation(e.getX(), e.getY()); if (o != null && o instanceof VGraphCell) { selectedCell = (VGraphCell) o; Rectangle2D bounds = graph.getCellBounds(selectedCell); menu.show(graph, (int) (bounds.getX() + bounds.getWidth()), (int) bounds.getY() + (int) (bounds.getHeight() - menu.getHeight())); } } }; }