1 40 41 package org.jfree.experimental.chart.swt.editor; 42 43 import java.util.ResourceBundle ; 44 45 import org.eclipse.swt.SWT; 46 import org.eclipse.swt.events.SelectionAdapter; 47 import org.eclipse.swt.events.SelectionEvent; 48 import org.eclipse.swt.graphics.Color; 49 import org.eclipse.swt.graphics.RGB; 50 import org.eclipse.swt.layout.FillLayout; 51 import org.eclipse.swt.layout.GridData; 52 import org.eclipse.swt.layout.GridLayout; 53 import org.eclipse.swt.widgets.Button; 54 import org.eclipse.swt.widgets.ColorDialog; 55 import org.eclipse.swt.widgets.Composite; 56 import org.eclipse.swt.widgets.Group; 57 import org.eclipse.swt.widgets.Label; 58 import org.jfree.chart.JFreeChart; 59 import org.jfree.experimental.swt.SWTPaintCanvas; 60 import org.jfree.experimental.swt.SWTUtils; 61 62 65 class SWTOtherEditor extends Composite { 66 67 69 private Button antialias; 70 71 72 private SWTPaintCanvas backgroundPaintCanvas; 73 74 75 protected static ResourceBundle localizationResources 76 = ResourceBundle.getBundle("org.jfree.chart.editor.LocalizationBundle"); 77 78 85 public SWTOtherEditor(Composite parent, int style, JFreeChart chart) 86 { 87 super(parent, style); 88 FillLayout layout = new FillLayout(); 89 layout.marginHeight = layout.marginWidth = 4; 90 setLayout(layout); 91 92 Group general = new Group(this, SWT.NONE); 93 general.setLayout(new GridLayout(3, false)); 94 general.setText(localizationResources.getString("General")); 95 96 antialias = new Button(general, SWT.CHECK); 98 antialias.setText(localizationResources.getString("Draw_anti-aliased")); 99 antialias.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 100 3, 1)); 101 antialias.setSelection(chart.getAntiAlias()); 102 103 new Label(general, SWT.NONE).setText(localizationResources.getString( 105 "Background_paint")); 106 backgroundPaintCanvas = new SWTPaintCanvas(general, SWT.NONE, 107 SWTUtils.toSwtColor(getDisplay(), chart.getBackgroundPaint())); 108 GridData bgGridData = new GridData(SWT.FILL, SWT.CENTER, true, false); 109 bgGridData.heightHint = 20; 110 backgroundPaintCanvas.setLayoutData(bgGridData); 111 Button selectBgPaint = new Button(general, SWT.PUSH); 112 selectBgPaint.setText(localizationResources.getString("Select...")); 113 selectBgPaint.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, 114 false)); 115 selectBgPaint.addSelectionListener( 116 new SelectionAdapter() { 117 public void widgetSelected(SelectionEvent event) { 118 ColorDialog dlg = new ColorDialog(getShell()); 119 dlg.setText(localizationResources.getString( 120 "Background_paint")); 121 dlg.setRGB(backgroundPaintCanvas.getColor().getRGB()); 122 RGB rgb = dlg.open(); 123 if (rgb != null) { 124 backgroundPaintCanvas.setColor( 125 new Color(getDisplay(), rgb)); 126 } 127 } 128 } 129 ); 130 } 131 132 137 public void updateChartProperties(JFreeChart chart) { 138 chart.setAntiAlias(this.antialias.getSelection()); 139 chart.setBackgroundPaint(SWTUtils.toAwtColor( 140 this.backgroundPaintCanvas.getColor())); 141 } 142 143 } 144 | Popular Tags |