1 40 41 package org.jfree.experimental.chart.swt.editor; 42 43 import java.awt.Stroke ; 44 import java.util.ResourceBundle ; 45 46 import org.eclipse.swt.SWT; 47 import org.eclipse.swt.graphics.Color; 48 import org.eclipse.swt.layout.FillLayout; 49 import org.eclipse.swt.widgets.Composite; 50 import org.eclipse.swt.widgets.Group; 51 import org.eclipse.swt.widgets.TabFolder; 52 import org.eclipse.swt.widgets.TabItem; 53 import org.jfree.chart.axis.Axis; 54 import org.jfree.chart.plot.CategoryPlot; 55 import org.jfree.chart.plot.Plot; 56 import org.jfree.chart.plot.XYPlot; 57 import org.jfree.experimental.swt.SWTUtils; 58 59 62 class SWTPlotEditor extends Composite { 63 64 67 private SWTAxisEditor domainAxisPropertyPanel; 68 69 72 private SWTAxisEditor rangeAxisPropertyPanel; 73 74 private SWTPlotAppearanceEditor plotAppearance; 75 76 77 protected static ResourceBundle localizationResources 78 = ResourceBundle.getBundle("org.jfree.chart.editor.LocalizationBundle"); 79 80 87 public SWTPlotEditor(Composite parent, int style, Plot plot) { 88 super(parent, style); 89 FillLayout layout = new FillLayout(); 90 layout.marginHeight = layout.marginWidth = 4; 91 this.setLayout(layout); 92 93 Group plotType = new Group(this, SWT.NONE); 94 FillLayout plotTypeLayout = new FillLayout(); 95 plotTypeLayout.marginHeight = plotTypeLayout.marginWidth = 4; 96 plotType.setLayout(plotTypeLayout); 97 plotType.setText(plot.getPlotType() + localizationResources.getString( 98 ":")); 99 100 TabFolder tabs = new TabFolder(plotType, SWT.NONE); 101 102 TabItem item1 = new TabItem(tabs, SWT.NONE); 104 item1.setText(localizationResources.getString("Domain_Axis")); 105 Axis domainAxis = null; 106 if (plot instanceof CategoryPlot) { 107 domainAxis = ((CategoryPlot) plot).getDomainAxis(); 108 } 109 else if (plot instanceof XYPlot) { 110 domainAxis = ((XYPlot) plot).getDomainAxis(); 111 } 112 this.domainAxisPropertyPanel = SWTAxisEditor.getInstance(tabs, 113 SWT.NONE, domainAxis); 114 item1.setControl(this.domainAxisPropertyPanel); 115 116 TabItem item2 = new TabItem(tabs, SWT.NONE); 118 item2.setText(localizationResources.getString("Range_Axis")); 119 Axis rangeAxis = null; 120 if (plot instanceof CategoryPlot) { 121 rangeAxis = ((CategoryPlot) plot).getRangeAxis(); 122 } 123 else if (plot instanceof XYPlot) { 124 rangeAxis = ((XYPlot) plot).getRangeAxis(); 125 } 126 this.rangeAxisPropertyPanel = SWTAxisEditor.getInstance(tabs, SWT.NONE, 127 rangeAxis); 128 item2.setControl(this.rangeAxisPropertyPanel); 129 130 TabItem item3 = new TabItem(tabs, SWT.NONE); 132 item3.setText(localizationResources.getString("Appearance")); 133 plotAppearance = new SWTPlotAppearanceEditor(tabs, SWT.NONE, plot); 134 item3.setControl(plotAppearance); 135 } 136 137 142 public Color getBackgroundPaint() { 143 return this.plotAppearance.getBackGroundPaint(); 144 } 145 146 151 public Color getOutlinePaint() { 152 return this.plotAppearance.getOutlinePaint(); 153 } 154 155 160 public Stroke getOutlineStroke() { 161 return this.plotAppearance.getStroke(); 162 } 163 164 165 171 public void updatePlotProperties(Plot plot) { 172 plot.setBackgroundPaint(SWTUtils.toAwtColor(getBackgroundPaint())); 174 plot.setOutlinePaint(SWTUtils.toAwtColor(getOutlinePaint())); 175 plot.setOutlineStroke(getOutlineStroke()); 176 177 if (this.domainAxisPropertyPanel != null) { 179 Axis domainAxis = null; 180 if (plot instanceof CategoryPlot) { 181 CategoryPlot p = (CategoryPlot) plot; 182 domainAxis = p.getDomainAxis(); 183 } 184 else if (plot instanceof XYPlot) { 185 XYPlot p = (XYPlot) plot; 186 domainAxis = p.getDomainAxis(); 187 } 188 if (domainAxis != null) 189 this.domainAxisPropertyPanel.setAxisProperties(domainAxis); 190 } 191 if (this.rangeAxisPropertyPanel != null) { 192 Axis rangeAxis = null; 193 if (plot instanceof CategoryPlot) { 194 CategoryPlot p = (CategoryPlot) plot; 195 rangeAxis = p.getRangeAxis(); 196 } 197 else if (plot instanceof XYPlot) { 198 XYPlot p = ( XYPlot ) plot; 199 rangeAxis = p.getRangeAxis(); 200 } 201 if (rangeAxis != null) 202 this.rangeAxisPropertyPanel.setAxisProperties(rangeAxis); 203 } 204 if (this.plotAppearance.getPlotOrientation() != null) { 205 if (plot instanceof CategoryPlot) { 206 CategoryPlot p = (CategoryPlot) plot; 207 p.setOrientation(this.plotAppearance.getPlotOrientation() ); 208 } 209 else if (plot instanceof XYPlot) { 210 XYPlot p = (XYPlot) plot; 211 p.setOrientation(this.plotAppearance.getPlotOrientation()); 212 } 213 } 214 } 215 } 216 | Popular Tags |