00001 package org.swtchart.ext.internal.properties;
00002
00003 import org.eclipse.jface.preference.ColorSelector;
00004 import org.eclipse.swt.SWT;
00005 import org.eclipse.swt.events.SelectionAdapter;
00006 import org.eclipse.swt.events.SelectionEvent;
00007 import org.eclipse.swt.graphics.Color;
00008 import org.eclipse.swt.graphics.Font;
00009 import org.eclipse.swt.graphics.FontData;
00010 import org.eclipse.swt.graphics.RGB;
00011 import org.eclipse.swt.layout.GridLayout;
00012 import org.eclipse.swt.widgets.Button;
00013 import org.eclipse.swt.widgets.Composite;
00014 import org.eclipse.swt.widgets.Control;
00015 import org.eclipse.swt.widgets.Display;
00016 import org.eclipse.swt.widgets.Group;
00017 import org.eclipse.swt.widgets.Label;
00018 import org.eclipse.swt.widgets.Spinner;
00019 import org.eclipse.swt.widgets.Text;
00020 import org.swtchart.Constants;
00021 import org.swtchart.ITitle;
00022 import org.swtchart.ext.InteractiveChart;
00023
00027 public class ChartPage extends AbstractPage {
00028
00030 private static final String PLOT_AREA_BACKGROUND = "org.swtchart.plotarea.background";
00031
00033 private static final String CHART_BACKGROUND = "org.swtchart.chart.background";
00034
00036 private static final String TITLE_FOREGROUND = "org.swtchart.chart.title.foreground";
00037
00039 private static final String TITLE_FONT = "org.swtchart.chart.title.font";
00040
00042 private ColorSelector backgroundInPlotAreaButton;
00043
00045 private ColorSelector backgroundButton;
00046
00048 private Button orientationButton;
00049
00051 protected Button showTitleButton;
00052
00054 private Label titleLabel;
00055
00057 private Text titleText;
00058
00060 private Label fontSizeLabel;
00061
00063 private Spinner fontSizeSpinner;
00064
00066 private Label titleColorLabel;
00067
00069 private ColorSelector titleColorButton;
00070
00081 public ChartPage(InteractiveChart chart,
00082 PropertiesResources resources, String title) {
00083 super(chart, resources, title);
00084 }
00085
00086
00087
00088
00089 @Override
00090 protected Control createContents(Composite parent) {
00091 Composite composite = new Composite(parent, SWT.NONE);
00092 GridLayout layout = new GridLayout();
00093 layout.marginHeight = 0;
00094 layout.marginWidth = 0;
00095 composite.setLayout(layout);
00096
00097 addChartPanel(composite);
00098 addTitleGroup(composite);
00099
00100 selectValues();
00101 return composite;
00102 }
00103
00110 private void addChartPanel(Composite parent) {
00111 Composite panel = new Composite(parent, SWT.NONE);
00112 panel.setLayout(new GridLayout(2, false));
00113
00114 createLabelControl(panel, "Background in plot area:");
00115 backgroundInPlotAreaButton = createColorButtonControl(panel);
00116
00117 createLabelControl(panel, "Background:");
00118 backgroundButton = createColorButtonControl(panel);
00119
00120 orientationButton = createCheckBoxControl(panel,
00121 "Vertical orientation:");
00122 }
00123
00130 private void addTitleGroup(Composite parent) {
00131 Group group = createGroupControl(parent, "Title:", false);
00132
00133 showTitleButton = createCheckBoxControl(group, "Show title");
00134 showTitleButton.addSelectionListener(new SelectionAdapter() {
00135 @Override
00136 public void widgetSelected(SelectionEvent e) {
00137 setTitleControlsEnable(showTitleButton.getSelection());
00138 }
00139 });
00140
00141 titleLabel = createLabelControl(group, "Text:");
00142 titleText = createTextControl(group);
00143
00144 fontSizeLabel = createLabelControl(group, "Font size:");
00145 fontSizeSpinner = createSpinnerControl(group, 8, 30);
00146
00147 titleColorLabel = createLabelControl(group, "Color:");
00148 titleColorButton = createColorButtonControl(group);
00149 }
00150
00154 private void selectValues() {
00155 backgroundInPlotAreaButton.setColorValue(chart
00156 .getBackgroundInPlotArea().getRGB());
00157 backgroundButton.setColorValue(chart.getBackground().getRGB());
00158 orientationButton.setSelection(chart.getOrientation() == SWT.VERTICAL);
00159
00160 ITitle title = chart.getTitle();
00161 showTitleButton.setSelection(title.isVisible());
00162 setTitleControlsEnable(title.isVisible());
00163 titleText.setText(title.getText());
00164 fontSizeSpinner.setSelection(title.getFont().getFontData()[0]
00165 .getHeight());
00166 titleColorButton.setColorValue(title.getForeground().getRGB());
00167 }
00168
00175 protected void setTitleControlsEnable(boolean enabled) {
00176 titleLabel.setEnabled(enabled);
00177 titleText.setEnabled(enabled);
00178 fontSizeLabel.setEnabled(enabled);
00179 fontSizeSpinner.setEnabled(enabled);
00180 titleColorLabel.setEnabled(enabled);
00181 titleColorButton.setEnabled(enabled);
00182 }
00183
00184
00185
00186
00187 @Override
00188 public void apply() {
00189 Color color = new Color(Display.getDefault(),
00190 backgroundInPlotAreaButton.getColorValue());
00191 chart.setBackgroundInPlotArea(color);
00192 resources.put(PLOT_AREA_BACKGROUND, color);
00193
00194 color = new Color(Display.getDefault(), backgroundButton
00195 .getColorValue());
00196 chart.setBackground(color);
00197 resources.put(CHART_BACKGROUND, color);
00198
00199 chart.setOrientation(orientationButton.getSelection() ? SWT.VERTICAL
00200 : SWT.HORIZONTAL);
00201
00202 ITitle title = chart.getTitle();
00203 title.setVisible(showTitleButton.getSelection());
00204 title.setText(titleText.getText());
00205
00206 FontData fontData = title.getFont().getFontData()[0];
00207 fontData.setHeight(fontSizeSpinner.getSelection());
00208 Font font = new Font(Display.getDefault(), fontData);
00209 title.setFont(font);
00210 resources.put(TITLE_FONT, font);
00211
00212 color = new Color(Display.getDefault(), titleColorButton
00213 .getColorValue());
00214 title.setForeground(color);
00215 resources.put(TITLE_FOREGROUND, color);
00216 }
00217
00218
00219
00220
00221 @Override
00222 protected void performDefaults() {
00223 backgroundInPlotAreaButton.setColorValue(new RGB(255, 255, 255));
00224 backgroundButton.setColorValue(Display.getDefault().getSystemColor(
00225 SWT.COLOR_WIDGET_BACKGROUND).getRGB());
00226 orientationButton.setSelection(false);
00227
00228 showTitleButton.setSelection(true);
00229 setTitleControlsEnable(true);
00230 titleText.setText("Chart Title");
00231 fontSizeSpinner.setSelection(Constants.LARGE_FONT_SIZE);
00232 titleColorButton.setColorValue(new RGB(0, 0, 255));
00233
00234 super.performDefaults();
00235 }
00236 }