00001 package org.swtchart.ext.internal.properties;
00002
00003 import org.eclipse.jface.preference.ColorSelector;
00004 import org.eclipse.jface.preference.PreferencePage;
00005 import org.eclipse.swt.SWT;
00006 import org.eclipse.swt.layout.GridData;
00007 import org.eclipse.swt.layout.GridLayout;
00008 import org.eclipse.swt.widgets.Button;
00009 import org.eclipse.swt.widgets.Combo;
00010 import org.eclipse.swt.widgets.Composite;
00011 import org.eclipse.swt.widgets.Group;
00012 import org.eclipse.swt.widgets.Label;
00013 import org.eclipse.swt.widgets.Spinner;
00014 import org.eclipse.swt.widgets.Text;
00015 import org.swtchart.ext.InteractiveChart;
00016
00020 public abstract class AbstractPage extends PreferencePage {
00021
00023 protected InteractiveChart chart;
00024
00026 protected PropertiesResources resources;
00027
00038 public AbstractPage(InteractiveChart chart,
00039 PropertiesResources resources, String title) {
00040 this.chart = chart;
00041 this.resources = resources;
00042 setTitle(title);
00043 }
00044
00045
00046
00047
00048 @Override
00049 public boolean performOk() {
00050 if (getControl() != null) {
00051 apply();
00052 chart.redraw();
00053 }
00054 return true;
00055 }
00056
00060 abstract public void apply();
00061
00073 protected Group createGroupControl(Composite parent, String text,
00074 boolean equal) {
00075 Group group = new Group(parent, SWT.NULL);
00076 group.setText(text);
00077
00078 group.setLayout(new GridLayout(2, equal));
00079 group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
00080
00081 return group;
00082 }
00083
00093 protected Label createLabelControl(Composite parent, String text) {
00094 Label label = new Label(parent, SWT.NULL);
00095 label.setText(text);
00096
00097 GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
00098 gridData.horizontalSpan = 1;
00099 label.setLayoutData(gridData);
00100
00101 return label;
00102 }
00103
00111 protected ColorSelector createColorButtonControl(Composite parent) {
00112 return new ColorSelector(parent);
00113 }
00114
00124 protected Button createCheckBoxControl(Composite parent, String label) {
00125 Composite composite = new Composite(parent, SWT.NULL);
00126 GridData gridData = new GridData();
00127 gridData.horizontalSpan = 2;
00128 composite.setLayoutData(gridData);
00129 composite.setLayout(new GridLayout(2, false));
00130
00131 Button button = new Button(composite, SWT.CHECK);
00132 GridData gridData1 = new GridData();
00133 gridData1.horizontalSpan = 1;
00134 button.setLayoutData(gridData1);
00135
00136 createLabelControl(composite, label);
00137
00138 return button;
00139 }
00140
00148 protected Text createTextControl(Composite parent) {
00149 Text text = new Text(parent, SWT.BORDER | SWT.SINGLE);
00150
00151 GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
00152 gridData.horizontalSpan = 1;
00153 text.setLayoutData(gridData);
00154
00155 return text;
00156 }
00157
00167 protected Combo createComboControl(Composite parent, String[] items) {
00168 Combo combo = new Combo(parent, SWT.BORDER | SWT.SINGLE);
00169 combo.setItems(items);
00170
00171 GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
00172 gridData.horizontalSpan = 1;
00173 combo.setLayoutData(gridData);
00174
00175 return combo;
00176 }
00177
00189 protected Spinner createSpinnerControl(Composite parent, int min, int max) {
00190 Spinner spinner = new Spinner(parent, SWT.BORDER);
00191 spinner.setMinimum(min);
00192 spinner.setMaximum(max);
00193
00194 GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
00195 gridData.horizontalSpan = 1;
00196 spinner.setLayoutData(gridData);
00197
00198 return spinner;
00199 }
00200 }