1 40 41 package org.jfree.experimental.chart.swt.editor; 42 43 import java.awt.Paint ; 44 import java.util.ResourceBundle ; 45 46 import org.eclipse.swt.SWT; 47 import org.eclipse.swt.events.SelectionAdapter; 48 import org.eclipse.swt.events.SelectionEvent; 49 import org.eclipse.swt.graphics.Color; 50 import org.eclipse.swt.graphics.Font; 51 import org.eclipse.swt.graphics.FontData; 52 import org.eclipse.swt.graphics.RGB; 53 import org.eclipse.swt.layout.FillLayout; 54 import org.eclipse.swt.layout.GridData; 55 import org.eclipse.swt.layout.GridLayout; 56 import org.eclipse.swt.widgets.Button; 57 import org.eclipse.swt.widgets.ColorDialog; 58 import org.eclipse.swt.widgets.Composite; 59 import org.eclipse.swt.widgets.FontDialog; 60 import org.eclipse.swt.widgets.Group; 61 import org.eclipse.swt.widgets.Label; 62 import org.eclipse.swt.widgets.TabFolder; 63 import org.eclipse.swt.widgets.TabItem; 64 import org.eclipse.swt.widgets.Text; 65 import org.jfree.chart.axis.Axis; 66 import org.jfree.chart.axis.NumberAxis; 67 import org.jfree.experimental.swt.SWTPaintCanvas; 68 import org.jfree.experimental.swt.SWTUtils; 69 70 73 class SWTAxisEditor extends Composite { 74 75 76 private Text label; 77 78 79 private FontData labelFont; 80 81 82 private Color labelPaintColor; 83 84 85 private FontData tickLabelFont; 86 87 88 private Color tickLabelPaintColor; 89 90 91 private Text labelFontField; 92 93 97 private Text tickLabelFontField; 98 99 100 protected static ResourceBundle localizationResources = 101 ResourceBundle.getBundle("org.jfree.chart.editor.LocalizationBundle"); 102 103 104 private Font font; 105 106 107 private Button showTickLabelsCheckBox; 108 109 110 private Button showTickMarksCheckBox; 111 112 113 private TabFolder otherTabs; 114 115 124 public SWTAxisEditor(Composite parent, int style, Axis axis) { 125 super(parent, style); 126 this.labelFont = SWTUtils.toSwtFontData(getDisplay(), 127 axis.getLabelFont(), true); 128 this.labelPaintColor = SWTUtils.toSwtColor(getDisplay(), 129 axis.getLabelPaint()); 130 this.tickLabelFont = SWTUtils.toSwtFontData(getDisplay(), 131 axis.getTickLabelFont(), true); 132 this.tickLabelPaintColor = SWTUtils.toSwtColor(getDisplay(), 133 axis.getTickLabelPaint()); 134 135 FillLayout layout = new FillLayout(SWT.VERTICAL); 136 layout.marginHeight = layout.marginWidth = 4; 137 this.setLayout(layout); 138 Group general = new Group(this, SWT.NONE); 139 general.setLayout(new GridLayout(3, false)); 140 general.setText(localizationResources.getString("General")); 141 new Label(general, SWT.NONE).setText(localizationResources.getString( 143 "Label")); 144 label = new Text(general, SWT.BORDER); 145 label.setText(axis.getLabel()); 146 label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); 147 new Label(general, SWT.NONE).setText(""); new Label(general, SWT.NONE).setText(localizationResources.getString( 150 "Font")); 151 labelFontField = new Text(general, SWT.BORDER); 152 labelFontField.setText(this.labelFont.toString()); 153 labelFontField.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, 154 false)); 155 Button selectFontButton = new Button(general, SWT.PUSH); 156 selectFontButton.setText(localizationResources.getString("Select...")); 157 selectFontButton.addSelectionListener( 158 new SelectionAdapter() { 159 public void widgetSelected(SelectionEvent event) { 160 FontDialog dlg = new FontDialog(getShell()); 162 dlg.setText(localizationResources.getString( 163 "Font_Selection")); 164 dlg.setFontList(new FontData[] { labelFont }); 165 if (dlg.open() != null) { 166 if (font != null) { 168 font.dispose(); 169 } 170 font = new Font(getShell().getDisplay(), 173 dlg.getFontList()); 174 labelFontField.setText( 176 font.getFontData()[0].toString()); 177 labelFont = font.getFontData()[0]; 178 } 179 } 180 } 181 ); 182 new Label(general, SWT.NONE).setText(localizationResources.getString( 184 "Paint")); 185 final SWTPaintCanvas colorCanvas = new SWTPaintCanvas(general, 187 SWT.NONE, this.labelPaintColor); 188 GridData canvasGridData = new GridData(SWT.FILL, SWT.CENTER, true, 189 false); 190 canvasGridData.heightHint = 20; 191 colorCanvas.setLayoutData(canvasGridData); 192 Button selectColorButton = new Button(general, SWT.PUSH); 193 selectColorButton.setText(localizationResources.getString("Select...")); 194 selectColorButton.addSelectionListener( 195 new SelectionAdapter() { 196 public void widgetSelected(SelectionEvent event) { 197 ColorDialog dlg = new ColorDialog(getShell()); 199 dlg.setText(localizationResources.getString( 200 "Title_Color")); 201 dlg.setRGB(labelPaintColor.getRGB()); 202 RGB rgb = dlg.open(); 203 if (rgb != null) { 204 labelPaintColor = new Color(getDisplay(), rgb); 207 colorCanvas.setColor(labelPaintColor); 208 } 209 } 210 } 211 ); 212 Group other = new Group(this, SWT.NONE); 213 FillLayout tabLayout = new FillLayout(); 214 tabLayout.marginHeight = tabLayout.marginWidth = 4; 215 other.setLayout(tabLayout); 216 other.setText(localizationResources.getString("Other")); 217 218 otherTabs = new TabFolder(other, SWT.NONE); 219 TabItem item1 = new TabItem(otherTabs, SWT.NONE); 220 item1.setText(" " + localizationResources.getString("Ticks") + " "); 221 Composite ticks = new Composite(otherTabs, SWT.NONE); 222 ticks.setLayout(new GridLayout(3, false)); 223 showTickLabelsCheckBox = new Button(ticks, SWT.CHECK); 224 showTickLabelsCheckBox.setText(localizationResources.getString( 225 "Show_tick_labels")); 226 showTickLabelsCheckBox.setSelection(axis.isTickLabelsVisible()); 227 showTickLabelsCheckBox.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, 228 true, false, 3, 1)); 229 new Label(ticks, SWT.NONE).setText(localizationResources.getString( 230 "Tick_label_font")); 231 tickLabelFontField = new Text(ticks, SWT.BORDER); 232 tickLabelFontField.setText(this.tickLabelFont.toString()); 233 tickLabelFontField.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, 236 true, false)); 237 Button selectTickLabelFontButton = new Button(ticks, SWT.PUSH); 238 selectTickLabelFontButton.setText(localizationResources.getString( 239 "Select...")); 240 selectTickLabelFontButton.addSelectionListener( 241 new SelectionAdapter() { 242 public void widgetSelected(SelectionEvent event) { 243 FontDialog dlg = new FontDialog(getShell()); 245 dlg.setText( localizationResources.getString( 246 "Font_Selection")); 247 dlg.setFontList(new FontData[] {tickLabelFont}); 248 if (dlg.open() != null) { 249 if (font != null) font.dispose(); 251 font = new Font(getShell().getDisplay(), 253 dlg.getFontList()); 254 tickLabelFontField.setText( 256 font.getFontData()[0].toString()); 257 tickLabelFont = font.getFontData()[0]; 258 } 259 } 260 } 261 ); 262 showTickMarksCheckBox = new Button(ticks, SWT.CHECK); 263 showTickMarksCheckBox.setText(localizationResources.getString( 264 "Show_tick_marks")); 265 showTickMarksCheckBox.setSelection(axis.isTickMarksVisible()); 266 showTickMarksCheckBox.setLayoutData(new GridData( SWT.FILL, SWT.CENTER, 267 true, false, 3, 1)); 268 item1.setControl(ticks); 269 } 270 271 281 public static SWTAxisEditor getInstance(Composite parent, int style, 282 Axis axis) { 283 284 if (axis != null) { 285 if (axis instanceof NumberAxis) 287 return new SWTNumberAxisEditor(parent, style, 288 (NumberAxis) axis ); 289 else return new SWTAxisEditor(parent, style, axis); 290 } 291 else return null; 292 } 293 294 299 public TabFolder getOtherTabs() { 300 return this.otherTabs; 301 } 302 303 308 public String getLabel() { 309 return this.label.getText(); 310 } 311 312 317 public java.awt.Font getLabelFont() { 318 return SWTUtils.toAwtFont(getDisplay(), this.labelFont, true); 319 } 320 321 326 public Paint getTickLabelPaint() { 327 return SWTUtils.toAwtColor(this.tickLabelPaintColor); 328 } 329 330 335 public java.awt.Font getTickLabelFont() { 336 return SWTUtils.toAwtFont(getDisplay(), tickLabelFont, true); 337 } 338 339 344 public Paint getLabelPaint() { 345 return SWTUtils.toAwtColor(this.labelPaintColor); 346 } 347 348 354 public void setAxisProperties(Axis axis) { 355 axis.setLabel(getLabel()); 356 axis.setLabelFont(getLabelFont()); 357 axis.setLabelPaint(getLabelPaint()); 358 axis.setTickMarksVisible(showTickMarksCheckBox.getSelection()); 359 axis.setTickLabelsVisible(showTickLabelsCheckBox.getSelection()); 360 axis.setTickLabelFont(getTickLabelFont()); 361 axis.setTickLabelPaint(getTickLabelPaint()); 362 } 363 } 364 | Popular Tags |