1 40 41 package org.jfree.experimental.chart.swt.editor; 42 43 import java.awt.BasicStroke ; 44 import java.awt.Stroke ; 45 import java.util.ResourceBundle ; 46 47 import org.eclipse.swt.SWT; 48 import org.eclipse.swt.events.SelectionAdapter; 49 import org.eclipse.swt.events.SelectionEvent; 50 import org.eclipse.swt.graphics.Color; 51 import org.eclipse.swt.graphics.RGB; 52 import org.eclipse.swt.layout.FillLayout; 53 import org.eclipse.swt.layout.GridData; 54 import org.eclipse.swt.layout.GridLayout; 55 import org.eclipse.swt.widgets.Button; 56 import org.eclipse.swt.widgets.ColorDialog; 57 import org.eclipse.swt.widgets.Combo; 58 import org.eclipse.swt.widgets.Composite; 59 import org.eclipse.swt.widgets.Group; 60 import org.eclipse.swt.widgets.Label; 61 import org.eclipse.swt.widgets.Spinner; 62 import org.jfree.chart.plot.CategoryPlot; 63 import org.jfree.chart.plot.Plot; 64 import org.jfree.chart.plot.PlotOrientation; 65 import org.jfree.chart.plot.XYPlot; 66 import org.jfree.experimental.swt.SWTPaintCanvas; 67 import org.jfree.experimental.swt.SWTUtils; 68 69 72 class SWTPlotAppearanceEditor extends Composite 73 { 74 75 private Spinner selectStroke; 76 77 78 private SWTStrokeCanvas strokeCanvas; 79 80 81 private SWTPaintCanvas backgroundPaintCanvas; 82 83 84 private SWTPaintCanvas outlinePaintCanvas; 85 86 87 private PlotOrientation plotOrientation; 88 89 private Combo orientation; 90 91 92 private final static String [] orientationNames = { "Vertical", 93 "Horizontal" }; 94 private final static int ORIENTATION_VERTICAL = 0; 95 private final static int ORIENTATION_HORIZONTAL = 1; 96 97 98 protected static ResourceBundle localizationResources 99 = ResourceBundle.getBundle("org.jfree.chart.editor.LocalizationBundle"); 100 101 SWTPlotAppearanceEditor(Composite parent, int style, Plot plot) 102 { 103 super(parent, style); 104 FillLayout layout = new FillLayout(); 105 layout.marginHeight = layout.marginWidth = 4; 106 this.setLayout(layout); 107 108 Group general = new Group(this, SWT.NONE); 109 GridLayout groupLayout = new GridLayout(3, false); 110 groupLayout.marginHeight = groupLayout.marginWidth = 4; 111 general.setLayout(groupLayout); 112 general.setText( localizationResources.getString("General")); 113 114 new Label(general, SWT.NONE).setText(localizationResources.getString( 116 "Outline_stroke")); 117 strokeCanvas = new SWTStrokeCanvas(general, SWT.NONE); 118 strokeCanvas.setStroke(plot.getOutlineStroke()); 119 GridData strokeGridData = new GridData(SWT.FILL, SWT.CENTER, true, 120 false); 121 strokeGridData.heightHint = 20; 122 strokeCanvas.setLayoutData(strokeGridData); 123 selectStroke = new Spinner(general, SWT.BORDER); 124 selectStroke.setMinimum(1); 125 selectStroke.setMaximum(3); 126 selectStroke.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, 127 false)); 128 selectStroke.addSelectionListener( 129 new SelectionAdapter() { 130 public void widgetSelected(SelectionEvent event) { 131 int w = selectStroke.getSelection(); 132 if (w > 0) { 133 strokeCanvas.setStroke(new BasicStroke (w)); 134 strokeCanvas.redraw(); 135 } 136 } 137 } 138 ); 139 new Label(general, SWT.NONE).setText(localizationResources.getString( 141 "Outline_Paint")); 142 outlinePaintCanvas = new SWTPaintCanvas(general, SWT.NONE, 143 SWTUtils.toSwtColor(getDisplay(), plot.getOutlinePaint())); 144 GridData outlineGridData = new GridData(SWT.FILL, SWT.CENTER, true, 145 false); 146 outlineGridData.heightHint = 20; 147 outlinePaintCanvas.setLayoutData(outlineGridData); 148 Button selectOutlineColor = new Button(general, SWT.PUSH); 149 selectOutlineColor.setText(localizationResources.getString( 150 "Select...")); 151 selectOutlineColor.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, 152 false, false)); 153 selectOutlineColor.addSelectionListener( 154 new SelectionAdapter() { 155 public void widgetSelected(SelectionEvent event) { 156 ColorDialog dlg = new ColorDialog(getShell()); 157 dlg.setText(localizationResources.getString( 158 "Outline_Paint")); 159 dlg.setRGB(outlinePaintCanvas.getColor().getRGB()); 160 RGB rgb = dlg.open(); 161 if (rgb != null) { 162 outlinePaintCanvas.setColor(new Color(getDisplay(), 163 rgb)); 164 } 165 } 166 } 167 ); 168 new Label(general, SWT.NONE).setText(localizationResources.getString( 170 "Background_paint")); 171 backgroundPaintCanvas = new SWTPaintCanvas(general, SWT.NONE, 172 SWTUtils.toSwtColor(getDisplay(), plot.getBackgroundPaint())); 173 GridData bgGridData = new GridData(SWT.FILL, SWT.CENTER, true, false); 174 bgGridData.heightHint = 20; 175 backgroundPaintCanvas.setLayoutData(bgGridData); 176 Button selectBgPaint = new Button(general, SWT.PUSH); 177 selectBgPaint.setText(localizationResources.getString("Select...")); 178 selectBgPaint.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, 179 false)); 180 selectBgPaint.addSelectionListener( 181 new SelectionAdapter() { 182 public void widgetSelected(SelectionEvent event) { 183 ColorDialog dlg = new ColorDialog(getShell()); 184 dlg.setText(localizationResources.getString( 185 "Background_paint")); 186 dlg.setRGB(backgroundPaintCanvas.getColor().getRGB()); 187 RGB rgb = dlg.open(); 188 if (rgb != null) { 189 backgroundPaintCanvas.setColor( 190 new Color(getDisplay(), rgb)); 191 } 192 } 193 } 194 ); 195 if (plot instanceof CategoryPlot) { 197 this.plotOrientation = ((CategoryPlot) plot).getOrientation(); 198 } 199 else if (plot instanceof XYPlot) { 200 this.plotOrientation = ((XYPlot) plot).getOrientation(); 201 } 202 if (this.plotOrientation != null) { 203 boolean isVertical 204 = this.plotOrientation.equals(PlotOrientation.VERTICAL); 205 int index = isVertical ? ORIENTATION_VERTICAL 206 : ORIENTATION_HORIZONTAL; 207 new Label(general, SWT.NONE).setText( 208 localizationResources.getString("Orientation")); 209 orientation = new Combo(general, SWT.DROP_DOWN); 210 orientation.setItems(orientationNames); 211 orientation.select(index); 212 orientation.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, true, 213 false, 2, 1)); 214 orientation.addSelectionListener( 215 new SelectionAdapter() { 216 public void widgetSelected(SelectionEvent event) { 217 switch (orientation.getSelectionIndex()) { 218 case ORIENTATION_VERTICAL: 219 plotOrientation = PlotOrientation.VERTICAL; 220 break; 221 case ORIENTATION_HORIZONTAL: 222 plotOrientation 223 = PlotOrientation.HORIZONTAL; 224 break; 225 default: 226 plotOrientation = PlotOrientation.VERTICAL; 227 } 228 } 229 } 230 ); 231 } 232 } 233 234 239 public PlotOrientation getPlotOrientation() { 240 return this.plotOrientation; 241 } 242 243 248 public Color getBackGroundPaint() { 249 return backgroundPaintCanvas.getColor(); 250 } 251 252 257 public Color getOutlinePaint() { 258 return outlinePaintCanvas.getColor(); 259 } 260 261 266 public Stroke getStroke() { 267 return strokeCanvas.getStroke(); 268 } 269 } 270 | Popular Tags |