use of org.eclipse.swtchart.extensions.scattercharts.ScatterChart 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();
}
}
}
}
}
}
use of org.eclipse.swtchart.extensions.scattercharts.ScatterChart in project swtchart by eclipse.
the class ScatterSeries_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 ScatterSeriesPreferencePage();
preferencePage.setTitle("Chart Settings");
IPreferencePage preferencePrimaryAxesPage = new ScatterSeriesPrimaryAxesPreferencePage();
preferencePrimaryAxesPage.setTitle("Primary Axes");
IPreferencePage preferenceDataPage = new ScatterSeriesDataPreferencePage();
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", 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.");
}
}
}
});
//
scatterChart = new ScatterChart(this, SWT.NONE);
scatterChart.setLayoutData(new GridData(GridData.FILL_BOTH));
//
applyChartSettings();
applySeriesSettings();
}
Aggregations