Search in sources :

Example 1 with BarChart

use of org.eclipse.swtchart.extensions.barcharts.BarChart in project swtchart by eclipse.

the class RScriptExportHandler method execute.

@Override
public void execute(Shell shell, ScrollableChart scrollableChart) {
    BaseChart baseChart = scrollableChart.getBaseChart();
    /*
		 * Select the export file.
		 */
    FileDialog fileDialog = new FileDialog(shell, SWT.SAVE);
    fileDialog.setOverwrite(true);
    fileDialog.setText(TITLE);
    fileDialog.setFilterExtensions(new String[] { FILE_EXTENSION });
    // 
    String fileName = fileDialog.open();
    if (fileName != null) {
        /*
			 * Select the X and Y axis to export.
			 */
        ExportSettingsDialog exportSettingsDialog = new ExportSettingsDialog(shell, baseChart);
        exportSettingsDialog.create();
        if (exportSettingsDialog.open() == Window.OK) {
            // 
            int indexAxisX = exportSettingsDialog.getIndexAxisSelectionX();
            int indexAxisY = exportSettingsDialog.getIndexAxisSelectionY();
            // 
            if (indexAxisX >= 0 && indexAxisY >= 0) {
                /*
					 * X Axis Settings
					 */
                IAxisSettings axisSettingsX = baseChart.getXAxisSettings(indexAxisX);
                IAxisScaleConverter axisScaleConverterX = null;
                if (axisSettingsX instanceof ISecondaryAxisSettings) {
                    ISecondaryAxisSettings secondaryAxisSettings = (ISecondaryAxisSettings) axisSettingsX;
                    axisScaleConverterX = secondaryAxisSettings.getAxisScaleConverter();
                }
                /*
					 * Y Axis Settings
					 */
                IAxisSettings axisSettingsY = baseChart.getYAxisSettings(indexAxisY);
                IAxisScaleConverter axisScaleConverterY = null;
                if (axisSettingsY instanceof ISecondaryAxisSettings) {
                    ISecondaryAxisSettings secondaryAxisSettings = (ISecondaryAxisSettings) axisSettingsY;
                    axisScaleConverterY = secondaryAxisSettings.getAxisScaleConverter();
                }
                /*
					 * Print the XY data.
					 */
                PrintWriter printWriter = null;
                try {
                    printWriter = new PrintWriter(new File(fileName));
                    /*
						 * Axis settings.
						 */
                    AxisSettings axisSettings = new AxisSettings();
                    axisSettings.setIndexAxisX(indexAxisX);
                    axisSettings.setIndexAxisY(indexAxisY);
                    axisSettings.setAxisSettingsX(axisSettingsX);
                    axisSettings.setAxisScaleConverterX(axisScaleConverterX);
                    axisSettings.setAxisSettingsY(axisSettingsY);
                    axisSettings.setAxisScaleConverterY(axisScaleConverterY);
                    axisSettings.setExportVisibleOnly(exportSettingsDialog.isExportVisibleOnly());
                    // 
                    if (scrollableChart instanceof LineChart) {
                        printLinePlot(fileName, printWriter, scrollableChart, axisSettings);
                    } else if (scrollableChart instanceof BarChart) {
                        printBarPlot(fileName, printWriter, scrollableChart, axisSettings);
                    } else if (scrollableChart instanceof ScatterChart) {
                        printScatterPlot(fileName, printWriter, scrollableChart, axisSettings);
                    }
                    // 
                    printWriter.flush();
                    MessageDialog.openInformation(shell, TITLE, MESSAGE_OK);
                } catch (FileNotFoundException e) {
                    MessageDialog.openError(shell, TITLE, MESSAGE_ERROR);
                    System.out.println(e);
                } finally {
                    if (printWriter != null) {
                        printWriter.close();
                    }
                }
            }
        }
    }
}
Also used : ISecondaryAxisSettings(org.eclipse.swtchart.extensions.core.ISecondaryAxisSettings) ScatterChart(org.eclipse.swtchart.extensions.scattercharts.ScatterChart) FileNotFoundException(java.io.FileNotFoundException) IAxisSettings(org.eclipse.swtchart.extensions.core.IAxisSettings) IAxisSettings(org.eclipse.swtchart.extensions.core.IAxisSettings) ISecondaryAxisSettings(org.eclipse.swtchart.extensions.core.ISecondaryAxisSettings) Point(org.eclipse.swt.graphics.Point) BaseChart(org.eclipse.swtchart.extensions.core.BaseChart) IAxisScaleConverter(org.eclipse.swtchart.extensions.core.IAxisScaleConverter) BarChart(org.eclipse.swtchart.extensions.barcharts.BarChart) FileDialog(org.eclipse.swt.widgets.FileDialog) File(java.io.File) LineChart(org.eclipse.swtchart.extensions.linecharts.LineChart) PrintWriter(java.io.PrintWriter)

Example 2 with BarChart

use of org.eclipse.swtchart.extensions.barcharts.BarChart in project swtchart by eclipse.

the class BarSeries_Preferences_Part method initialize.

private void initialize() throws Exception {
    this.setLayout(new GridLayout(1, true));
    /*
		 * Buttons
		 */
    Composite compositeButtons = new Composite(this, SWT.NONE);
    GridData gridDataComposite = new GridData(GridData.FILL_HORIZONTAL);
    gridDataComposite.horizontalAlignment = SWT.END;
    compositeButtons.setLayoutData(gridDataComposite);
    compositeButtons.setLayout(new GridLayout(1, false));
    // 
    Button buttonOpenSettings = new Button(compositeButtons, SWT.PUSH);
    modifySettingsButton(buttonOpenSettings);
    buttonOpenSettings.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            IPreferencePage preferencePage = new BarSeriesPreferencePage();
            preferencePage.setTitle("Chart Settings");
            IPreferencePage preferencePrimaryAxesPage = new BarSeriesPrimaryAxesPreferencePage();
            preferencePrimaryAxesPage.setTitle("Primary Axes");
            IPreferencePage preferenceSecondaryAxesPage = new BarSeriesSecondaryAxesPreferencePage();
            preferenceSecondaryAxesPage.setTitle("Secondary Axes");
            IPreferencePage preferenceDataPage = new BarSeriesDataPreferencePage();
            preferenceDataPage.setTitle("Series Data");
            // 
            PreferenceManager preferenceManager = new PreferenceManager();
            preferenceManager.addToRoot(new PreferenceNode("1", preferencePage));
            preferenceManager.addToRoot(new PreferenceNode("2", preferencePrimaryAxesPage));
            preferenceManager.addToRoot(new PreferenceNode("3", preferenceSecondaryAxesPage));
            preferenceManager.addToRoot(new PreferenceNode("4", preferenceDataPage));
            // 
            // 
            PreferenceDialog preferenceDialog = new PreferenceDialog(e.display.getActiveShell(), preferenceManager);
            preferenceDialog.create();
            preferenceDialog.setMessage("Settings");
            if (preferenceDialog.open() == Window.OK) {
                try {
                    applyChartSettings();
                    applySeriesSettings();
                } catch (Exception e1) {
                    MessageDialog.openError(e.display.getActiveShell(), "Settings", "Something has gone wrong to apply the chart settings.");
                }
            }
        }
    });
    // 
    barChart = new BarChart(this, SWT.NONE);
    barChart.setLayoutData(new GridData(GridData.FILL_BOTH));
    // 
    applyChartSettings();
    applySeriesSettings();
}
Also used : Composite(org.eclipse.swt.widgets.Composite) PreferenceNode(org.eclipse.jface.preference.PreferenceNode) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) BarSeriesPreferencePage(org.eclipse.swtchart.extensions.examples.preferences.BarSeriesPreferencePage) BarSeriesSecondaryAxesPreferencePage(org.eclipse.swtchart.extensions.examples.preferences.BarSeriesSecondaryAxesPreferencePage) BarSeriesDataPreferencePage(org.eclipse.swtchart.extensions.examples.preferences.BarSeriesDataPreferencePage) PreferenceManager(org.eclipse.jface.preference.PreferenceManager) GridLayout(org.eclipse.swt.layout.GridLayout) PreferenceDialog(org.eclipse.jface.preference.PreferenceDialog) Button(org.eclipse.swt.widgets.Button) BarSeriesPrimaryAxesPreferencePage(org.eclipse.swtchart.extensions.examples.preferences.BarSeriesPrimaryAxesPreferencePage) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) BarChart(org.eclipse.swtchart.extensions.barcharts.BarChart) IPreferencePage(org.eclipse.jface.preference.IPreferencePage)

Aggregations

BarChart (org.eclipse.swtchart.extensions.barcharts.BarChart)2 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 PrintWriter (java.io.PrintWriter)1 IPreferencePage (org.eclipse.jface.preference.IPreferencePage)1 PreferenceDialog (org.eclipse.jface.preference.PreferenceDialog)1 PreferenceManager (org.eclipse.jface.preference.PreferenceManager)1 PreferenceNode (org.eclipse.jface.preference.PreferenceNode)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 Point (org.eclipse.swt.graphics.Point)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Button (org.eclipse.swt.widgets.Button)1 Composite (org.eclipse.swt.widgets.Composite)1 FileDialog (org.eclipse.swt.widgets.FileDialog)1 BaseChart (org.eclipse.swtchart.extensions.core.BaseChart)1 IAxisScaleConverter (org.eclipse.swtchart.extensions.core.IAxisScaleConverter)1 IAxisSettings (org.eclipse.swtchart.extensions.core.IAxisSettings)1 ISecondaryAxisSettings (org.eclipse.swtchart.extensions.core.ISecondaryAxisSettings)1