00001 package org.swtchart.examples;
00002
00003 import java.util.Vector;
00004
00005 import org.eclipse.swt.SWT;
00006 import org.eclipse.swt.custom.SashForm;
00007 import org.eclipse.swt.custom.StackLayout;
00008 import org.eclipse.swt.events.SelectionAdapter;
00009 import org.eclipse.swt.events.SelectionEvent;
00010 import org.eclipse.swt.layout.FillLayout;
00011 import org.eclipse.swt.layout.GridData;
00012 import org.eclipse.swt.widgets.Composite;
00013 import org.eclipse.swt.widgets.Display;
00014 import org.eclipse.swt.widgets.List;
00015 import org.eclipse.swt.widgets.Shell;
00016 import org.eclipse.swt.widgets.TabFolder;
00017 import org.eclipse.swt.widgets.TabItem;
00018 import org.swtchart.Chart;
00019 import org.swtchart.examples.advanced.AxisTickBoundsExample;
00020 import org.swtchart.examples.advanced.BarBoundsExample;
00021 import org.swtchart.examples.advanced.CustomPaintListenerExample;
00022 import org.swtchart.examples.advanced.DataToPixelConversionExample;
00023 import org.swtchart.examples.advanced.LegendBoundsExample;
00024 import org.swtchart.examples.advanced.PxielToDataConversionExample;
00025 import org.swtchart.examples.advanced.SymbolBoundsExample;
00026
00030 public class RunAllExamples {
00031
00032 static Vector<Chart> basicCharts;
00033 static Vector<Chart> advancedCharts;
00034
00041 public static void main(String[] args) {
00042 Display display = new Display();
00043 Shell shell = new Shell(display);
00044 shell.setText("Examples");
00045 shell.setSize(750, 400);
00046 shell.setLayout(new FillLayout());
00047
00048 SashForm sashForm = new SashForm(shell, SWT.HORIZONTAL);
00049
00050 TabFolder tabFolder = new TabFolder(sashForm, SWT.NONE);
00051 tabFolder.setLayoutData(new GridData(GridData.FILL_VERTICAL));
00052 tabFolder.setLayout(new FillLayout());
00053
00054 final Composite composite = new Composite(sashForm, SWT.NONE);
00055 composite.setLayoutData(new GridData(GridData.FILL_BOTH));
00056 final StackLayout layout = new StackLayout();
00057 composite.setLayout(layout);
00058
00059 sashForm.setWeights(new int[] { 1, 2 });
00060
00061 createList("Basic", createBasicCharts(composite), tabFolder, layout,
00062 composite);
00063 createList("Advanced", createAdvancedCharts(composite), tabFolder,
00064 layout, composite);
00065
00066 shell.open();
00067 while (!shell.isDisposed()) {
00068 if (!display.readAndDispatch()) {
00069 display.sleep();
00070 }
00071 }
00072 display.dispose();
00073 }
00074
00075 private static void createList(String tabName, final Vector<Chart> charts,
00076 TabFolder tabFolder, final StackLayout layout,
00077 final Composite composite) {
00078 final List list = new List(tabFolder, SWT.H_SCROLL | SWT.V_SCROLL);
00079 TabItem basicTabItem = new TabItem(tabFolder, SWT.NONE);
00080 basicTabItem.setText(tabName);
00081 basicTabItem.setControl(list);
00082 for (Chart chart : charts) {
00083 list.add(chart.getTitle().getText());
00084 }
00085
00086 list.addSelectionListener(new SelectionAdapter() {
00087 @Override
00088 public void widgetSelected(SelectionEvent event) {
00089 Chart chart = charts.get(list.getSelectionIndex());
00090 chart.getAxisSet().adjustRange();
00091 layout.topControl = chart;
00092 composite.layout();
00093 }
00094 });
00095 }
00096
00097 private static Vector<Chart> createBasicCharts(Composite parent) {
00098 basicCharts = new Vector<Chart>();
00099
00100 basicCharts.add(LineChartExample.createChart(parent));
00101 basicCharts.add(BarChartExample.createChart(parent));
00102 basicCharts.add(ScatterChartExample.createChart(parent));
00103 basicCharts.add(AreaChartExample.createChart(parent));
00104 basicCharts.add(StepChartExample.createChart(parent));
00105 basicCharts.add(StackSeriesExample.createChart(parent));
00106 basicCharts.add(LogScaleExample.createChart(parent));
00107 basicCharts.add(OrientationExample.createChart(parent));
00108 basicCharts.add(CategoryExample.createChart(parent));
00109 basicCharts.add(SeriesLabelExample.createChart(parent));
00110 basicCharts.add(ErrorBarsExample.createChart(parent));
00111 basicCharts.add(MultipleAxesExample.createChart(parent));
00112 basicCharts.add(LargeSeriesExample.createChart(parent));
00113 basicCharts.add(AngledAxisTickLabelsExample.createChart(parent));
00114
00115 return basicCharts;
00116 }
00117
00118 private static Vector<Chart> createAdvancedCharts(Composite parent) {
00119 basicCharts = new Vector<Chart>();
00120
00121 basicCharts.add(PxielToDataConversionExample.createChart(parent));
00122 basicCharts.add(DataToPixelConversionExample.createChart(parent));
00123 basicCharts.add(SymbolBoundsExample.createChart(parent));
00124 basicCharts.add(BarBoundsExample.createChart(parent));
00125 basicCharts.add(AxisTickBoundsExample.createChart(parent));
00126 basicCharts.add(LegendBoundsExample.createChart(parent));
00127 basicCharts.add(CustomPaintListenerExample.createChart(parent));
00128
00129 return basicCharts;
00130 }
00131 }