Example usage for org.jfree.chart ChartPanel doSaveAs

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

Introduction

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

Prototype

public void doSaveAs() throws IOException 

Source Link

Document

Opens a file chooser and gives the user an opportunity to save the chart in PNG format.

Usage

From source file:hr.restart.util.chart.ChartBase.java

final public void export() throws Exception {
    //System.out.println("(CHARTBASE) export");      
    try {/* w ww  . j  a  va  2  s.c  o m*/
        ChartPanel chartPanel = initGraph();
        chartPanel.setSize(chartPanel.getPreferredSize());
        chartPanel.doSaveAs();
    } catch (Exception e) {
        e.printStackTrace();
        preview();
    }
}

From source file:org.esa.snap.rcp.statistics.ChartPagePanel.java

private JPanel createChartBottomPanel(final ChartPanel chartPanel) {

    final AbstractButton zoomAllButton = ToolButtonFactory
            .createButton(UIUtils.loadImageIcon("icons/view-fullscreen.png"), false);
    zoomAllButton.setToolTipText("Zoom all.");
    zoomAllButton.setName("zoomAllButton.");
    zoomAllButton.addActionListener(e -> {
        chartPanel.restoreAutoBounds();/*from  w w  w.j  a v  a 2  s .com*/
        chartPanel.repaint();
    });

    final AbstractButton propertiesButton = ToolButtonFactory
            .createButton(UIUtils.loadImageIcon("icons/Edit24.gif"), false);
    propertiesButton.setToolTipText("Edit properties.");
    propertiesButton.setName("propertiesButton.");
    propertiesButton.addActionListener(e -> chartPanel.doEditChartProperties());

    final AbstractButton saveButton = ToolButtonFactory
            .createButton(UIUtils.loadImageIcon("icons/Export24.gif"), false);
    saveButton.setToolTipText("Save chart as image.");
    saveButton.setName("saveButton.");
    saveButton.addActionListener(e -> {
        try {
            chartPanel.doSaveAs();
        } catch (IOException e1) {
            JOptionPane.showMessageDialog(chartPanel, "Could not save chart:\n" + e1.getMessage(), "Error",
                    JOptionPane.ERROR_MESSAGE);
        }
    });

    final AbstractButton printButton = ToolButtonFactory
            .createButton(UIUtils.loadImageIcon("icons/Print24.gif"), false);
    printButton.setToolTipText("Print chart.");
    printButton.setName("printButton.");
    printButton.addActionListener(e -> chartPanel.createChartPrintJob());

    final TableLayout tableLayout = new TableLayout(6);
    tableLayout.setColumnFill(4, TableLayout.Fill.HORIZONTAL);
    tableLayout.setColumnWeightX(4, 1.0);
    JPanel buttonPanel = new JPanel(tableLayout);
    tableLayout.setRowPadding(0, new Insets(0, 4, 0, 0));
    buttonPanel.add(zoomAllButton);
    tableLayout.setRowPadding(0, new Insets(0, 0, 0, 0));
    buttonPanel.add(propertiesButton);
    buttonPanel.add(saveButton);
    buttonPanel.add(printButton);
    buttonPanel.add(new JPanel());
    buttonPanel.add(getHelpButton());

    return buttonPanel;
}

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

private JPanel createChartBottomPanel(final ChartPanel chartPanel) {

    final AbstractButton zoomAllButton = ToolButtonFactory.createButton(
            UIUtils.loadImageIcon("/com/bc/ceres/swing/actions/icons_22x22/view-fullscreen.png"), false);
    zoomAllButton.setToolTipText("Zoom all.");
    zoomAllButton.setName("zoomAllButton.");
    zoomAllButton.addActionListener(new ActionListener() {
        @Override/*from   ww w  . j  a v a  2  s. c om*/
        public void actionPerformed(ActionEvent e) {
            chartPanel.restoreAutoBounds();
            chartPanel.repaint();
        }
    });

    final AbstractButton propertiesButton = ToolButtonFactory
            .createButton(UIUtils.loadImageIcon("icons/Edit24.gif"), false);
    propertiesButton.setToolTipText("Edit properties.");
    propertiesButton.setName("propertiesButton.");
    propertiesButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            chartPanel.doEditChartProperties();
        }
    });

    final AbstractButton saveButton = ToolButtonFactory
            .createButton(UIUtils.loadImageIcon("icons/Export24.gif"), false);
    saveButton.setToolTipText("Save chart as image.");
    saveButton.setName("saveButton.");
    saveButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                chartPanel.doSaveAs();
            } catch (IOException e1) {
                JOptionPane.showMessageDialog(chartPanel, "Could not save chart:\n" + e1.getMessage(), "Error",
                        JOptionPane.ERROR_MESSAGE);
            }
        }
    });

    final AbstractButton printButton = ToolButtonFactory
            .createButton(UIUtils.loadImageIcon("icons/Print24.gif"), false);
    printButton.setToolTipText("Print chart.");
    printButton.setName("printButton.");
    printButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            chartPanel.createChartPrintJob();
        }
    });

    final TableLayout tableLayout = new TableLayout(6);
    tableLayout.setColumnFill(4, TableLayout.Fill.HORIZONTAL);
    tableLayout.setColumnWeightX(4, 1.0);
    JPanel buttonPanel = new JPanel(tableLayout);
    tableLayout.setRowPadding(0, new Insets(0, 4, 0, 0));
    buttonPanel.add(zoomAllButton);
    tableLayout.setRowPadding(0, new Insets(0, 0, 0, 0));
    buttonPanel.add(propertiesButton);
    buttonPanel.add(saveButton);
    buttonPanel.add(printButton);
    buttonPanel.add(new JPanel());
    buttonPanel.add(getHelpButton());

    return buttonPanel;
}