Example usage for org.jfree.chart ChartPanel getPopupMenu

List of usage examples for org.jfree.chart ChartPanel getPopupMenu

Introduction

In this page you can find the example usage for org.jfree.chart ChartPanel getPopupMenu.

Prototype

public JPopupMenu getPopupMenu() 

Source Link

Document

Returns the popup menu.

Usage

From source file:velocitekProStartAnalyzer.MainWindow.java

private void createChartPanel() {
    XYSeriesCollection dataset = JDBCPointDao.dataSet;
    JFreeChart chart = createChart(dataset);
    ChartPanel chartPanel = new ChartPanel(chart, true, false, false, true, false);
    chartPanel.setMinimumDrawWidth(0);//from ww  w.  j a  v a  2 s. c o  m
    chartPanel.setMinimumDrawHeight(0);
    chartPanel.setMaximumDrawWidth(1920);
    chartPanel.setMaximumDrawHeight(1200);
    chartPanel.getPopupMenu().addSeparator();
    chartPanel.getPopupMenu().add(btnAvgSpeedChart);
    chartPanel.getPopupMenu().add(btnMedianSpeedChart);
    chartPanel.getPopupMenu().add(btnResetSpeedChart);
    chartPanel.getPopupMenu().addSeparator();
    btnMenuSaveSubmenuForChart = new JMenu("Save");
    chartPanel.getPopupMenu().add(btnMenuSaveSubmenuForChart);

    if (JDBCPointDao.points.isEmpty()) {
        btnSaveAsVCC.setEnabled(false);
    }
    saveChartAsPng(chartPanel);

    btnMenuSaveSubmenuForChart.add(btnSaveChartAsPngForChart);
    btnMenuSaveSubmenuForChart.add(btnSaveTableAsPngForChart);
    btnMenuSaveSubmenuForChart.add(btnSaveMapAsPngForChart);
    btnMenuSaveSubmenuForChart.addSeparator();
    btnMenuSaveSubmenuForChart.add(btnSaveAsVCC);
    chartPanel.addChartMouseListener(new ChartMouseListener() {

        @Override
        public void chartMouseClicked(ChartMouseEvent event) {
            Rectangle2D dataArea = chartPanel.getScreenDataArea();
            JFreeChart chart = event.getChart();
            XYPlot plot = (XYPlot) chart.getPlot();
            ValueAxis xAxis = plot.getDomainAxis();
            double x = xAxis.java2DToValue(event.getTrigger().getX(), dataArea, RectangleEdge.BOTTOM);
            // make the crosshairs disappear if the mouse is out of range
            if (!xAxis.getRange().contains(x)) {
                x = Double.NaN;
            }

            x = Math.round(x);

            if (SwingUtilities.isLeftMouseButton(event.getTrigger()) && event.getTrigger().isShiftDown()) {
                for (PointDto cord : JDBCPointDao.points) {
                    {
                        if (cord.getPointID() == x) {
                            if (pointTable.getSelectionModel() == null) {
                                for (int i = 0; i < pointTable.getModel().getRowCount(); i++) {
                                    if (pointTable.getModel().getValueAt(i, 0).equals(cord.getPointID())) {
                                        pointTable.setRowSelectionInterval(i, i);
                                    }
                                }
                            } else {
                                for (int i = 0; i < pointTable.getModel().getRowCount(); i++) {
                                    if (pointTable.getModel().getValueAt(i, 0).equals(cord.getPointID())) {
                                        pointTable.addRowSelectionInterval(pointTable.getSelectedRow(), i);
                                    }
                                }
                            }
                            pointTable.scrollRectToVisible(
                                    pointTable.getCellRect(pointTable.getSelectedRow(), 0, true));
                        }
                    }
                }
            } else {
                for (PointDto cord : JDBCPointDao.points) {
                    {
                        if (cord.getPointID() == x) {
                            if (pointTable.getSelectionModel() != null) {
                                pointTable.getSelectionModel().clearSelection();
                            }
                            for (int i = 0; i < pointTable.getModel().getRowCount(); i++) {
                                if (pointTable.getModel().getValueAt(i, 0).equals(cord.getPointID())) {
                                    pointTable.setRowSelectionInterval(i, i);
                                }
                            }
                            pointTable.scrollRectToVisible(
                                    pointTable.getCellRect(pointTable.getSelectedRow(), 0, true));
                            //MainWindow.pointTable.revalidate();                      
                        }
                    }

                }
            }
        }

        @Override
        public void chartMouseMoved(ChartMouseEvent event) {

            Rectangle2D dataArea = chartPanel.getScreenDataArea();
            JFreeChart chart = event.getChart();
            XYPlot plot = (XYPlot) chart.getPlot();
            ValueAxis xAxis = plot.getDomainAxis();
            double x = xAxis.java2DToValue(event.getTrigger().getX(), dataArea, RectangleEdge.BOTTOM);
            // make the crosshairs disappear if the mouse is out of range
            if (!xAxis.getRange().contains(x)) {
                x = Double.NaN;
            }
            double y = DatasetUtilities.findYValue(plot.getDataset(), 0, x);
            xCrosshair.setValue(x);
            yCrosshair.setValue(y);
            x = Math.round(x);
            for (PointDto cord : JDBCPointDao.points) {

                if (cord.getPointID() == x) {
                    mapPanel.map().removeMapMarker(mapPanel.getMapPoint());
                    mapPanel.setMapPoint(
                            new MapMarkerDot(null, null, cord.getPointLatidude(), cord.getPointLongtidude()));
                    mapPanel.setMapPoint(mapPanel.getMapPoint());
                    mapPanel.getMapPoint().setColor(colorMapMarkerCircle);
                    mapPanel.getMapPoint().setBackColor(colorMapMarkerHover);
                    mapPanel.map().addMapMarker(mapPanel.getMapPoint());
                }

            }
        }

    });
    XYPlot xyPlot = (XYPlot) chart.getPlot();
    ValueAxis rangeAxis = xyPlot.getRangeAxis();
    NavigableMap<Double, PointDto> pointDtoSortedSpeedMap = new TreeMap<Double, PointDto>();

    if (!JDBCPointDao.points.isEmpty()) {
        for (PointDto pointDto : JDBCPointDao.points) {
            pointDtoSortedSpeedMap.put(pointDto.getPointSpeed(), pointDto);
        }
        rangeAxis.setRange(pointDtoSortedSpeedMap.firstEntry().getKey() - 0.1,
                pointDtoSortedSpeedMap.lastEntry().getKey() + 0.1);
    }

    CrosshairOverlay crosshairOverlay = new CrosshairOverlay();
    xCrosshair = new Crosshair(Double.NaN, Color.GRAY, new BasicStroke(0f));
    xCrosshair.setLabelVisible(true);
    yCrosshair = new Crosshair(Double.NaN, Color.GRAY, new BasicStroke(0f));
    yCrosshair.setLabelVisible(true);
    crosshairOverlay.addDomainCrosshair(xCrosshair);
    crosshairOverlay.addRangeCrosshair(yCrosshair);
    chartPanel.addOverlay(crosshairOverlay);
    graphPanel.removeAll();
    graphPanel.add(chartPanel, BorderLayout.CENTER);
    graphPanel.revalidate();
    graphPanel.repaint();
    graphMapSplitPanel.revalidate();
}

From source file:com.itemanalysis.jmetrik.graph.piechart.PieChartPanel.java

public void setGraph() {
    if (hasGroupVariable) {
        DefaultCategoryDataset piedat = new DefaultCategoryDataset();
        chart = ChartFactory.createMultiplePieChart(chartTitle, piedat, TableOrder.BY_ROW, showLegend, true,
                false);/*from   w w  w.  jav a2s  .  c o m*/

        if (chartSubtitle != null && !"".equals(chartSubtitle)) {
            TextTitle subtitle1 = new TextTitle(chartSubtitle);
            chart.addSubtitle(subtitle1);
        }

        MultiplePiePlot plot = (MultiplePiePlot) chart.getPlot();
        JFreeChart subchart = plot.getPieChart();
        PiePlot p = (PiePlot) subchart.getPlot();
        p.setBackgroundPaint(Color.WHITE);
        p.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} ({2})"));
        if (explode)
            p.setExplodePercent(explodeValue, explodePercent);

        ChartPanel panel = new ChartPanel(chart);
        panel.setPreferredSize(new Dimension(width, height));

        chart.setPadding(new RectangleInsets(20.0, 5.0, 20.0, 5.0));
        this.add(panel);
    } else {
        DefaultPieDataset piedat = new DefaultPieDataset();
        if (command.getSelectOneOption("view").isValueSelected("3D")) {
            chart = ChartFactory.createPieChart3D(chartTitle, piedat, showLegend, true, false);

            PiePlot3D plot = (PiePlot3D) chart.getPlot();
            plot.setStartAngle(290);
            plot.setDirection(Rotation.CLOCKWISE);
            plot.setForegroundAlpha(0.5f);
            plot.setNoDataMessage("No data to display");
            if (explode)
                plot.setExplodePercent(explodeValue, explodePercent);

        } else {
            chart = ChartFactory.createPieChart(command.getFreeOption("title").getString(), piedat, showLegend,
                    true, false);
        }

        if (chartSubtitle != null && !"".equals(chartSubtitle)) {
            TextTitle subtitle = new TextTitle(chartSubtitle);
            chart.addSubtitle(subtitle);
        }

        PiePlot plot = (PiePlot) chart.getPlot();
        plot.setLabelGap(0.02);
        plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} ({2})"));
        plot.setBackgroundPaint(Color.WHITE);
        if (explode)
            plot.setExplodePercent(explodeValue, explodePercent);

        ChartPanel panel = new ChartPanel(chart);
        panel.getPopupMenu().addSeparator();
        this.addJpgMenuItem(this, panel.getPopupMenu());
        panel.setPreferredSize(new Dimension(width, height));

        chart.setPadding(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
        this.setBackground(Color.WHITE);
        this.add(panel);
    }

}

From source file:org.esa.beam.visat.toolviews.stat.HistogramPanel.java

private ChartPanel createChartPanel(JFreeChart chart) {
    XYPlot plot = chart.getXYPlot();//w w w .  j  a v  a  2s. com

    plot.setForegroundAlpha(0.85f);
    plot.setNoDataMessage(NO_DATA_MESSAGE);
    plot.setAxisOffset(new RectangleInsets(5, 5, 5, 5));

    ChartPanel chartPanel = new ChartPanel(chart);

    MaskSelectionToolSupport maskSelectionToolSupport = new MaskSelectionToolSupport(this, chartPanel,
            "histogram_plot_area", "Mask generated from selected histogram plot area", Color.RED,
            PlotAreaSelectionTool.AreaType.X_RANGE) {

        @Override
        protected String createMaskExpression(PlotAreaSelectionTool.AreaType areaType, Shape shape) {
            Rectangle2D bounds = shape.getBounds2D();
            return createMaskExpression(bounds.getMinX(), bounds.getMaxX());
        }

        protected String createMaskExpression(double x1, double x2) {
            String bandName = BandArithmetic.createExternalName(getRaster().getName());
            HistogramPanelModel.HistogramConfig currentConfig = createHistogramConfig();
            return String.format("%s >= %s && %s <= %s", bandName,
                    model.hasStx(currentConfig)
                            ? model.getStx(currentConfig).getHistogramScaling().scaleInverse(x1)
                            : x1,
                    bandName,
                    model.hasStx(currentConfig)
                            ? model.getStx(currentConfig).getHistogramScaling().scaleInverse(x2)
                            : x2);
        }
    };

    chartPanel.getPopupMenu().addSeparator();
    chartPanel.getPopupMenu().add(maskSelectionToolSupport.createMaskSelectionModeMenuItem());
    chartPanel.getPopupMenu().add(maskSelectionToolSupport.createDeleteMaskMenuItem());
    chartPanel.getPopupMenu().addSeparator();
    chartPanel.getPopupMenu().add(createCopyDataToClipboardMenuItem());
    return chartPanel;
}

From source file:org.openmicroscopy.shoola.util.ui.graphutils.ChartObject.java

/**
 * Builds the graph and returns the UI component hosting it.
 * //  w  ww . j a  v  a  2s  . c  o  m
 * @param image The background image of the plot.
 * @param removeLegend Pass <code>true</code> to remove the legend,
 *                   <code>false</code>.
 * @param actions Additional actions which will be added to the chart's popup menu
 *
 * @return See above.
 */
public JPanel getChart(Image image, boolean removeLegend, List<AbstractAction> actions) {
    backgroundImage = image;
    createChart();
    if (removeLegend)
        chart.removeLegend();
    JPanel graphPanel = new JPanel();
    if (chart == null)
        return graphPanel;
    graphPanel.setLayout(new BorderLayout());

    // create ChartPanel which does not include "Save as..." menu, as it
    // only allows JPEG; instead provide "Save as" functionality as custom action
    ChartPanel p = new ChartPanel(chart, true, false, true, true, true);
    if (!CollectionUtils.isEmpty(actions))
        p.getPopupMenu().add(new JSeparator());
    for (AbstractAction action : actions) {
        JMenuItem exportMenu = new JMenuItem(action);
        p.getPopupMenu().add(exportMenu);
    }

    graphPanel.add(p, BorderLayout.CENTER);
    return graphPanel;
}