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.layout.FillLayout; 49 import org.eclipse.swt.layout.GridData; 50 import org.eclipse.swt.layout.GridLayout; 51 import org.eclipse.swt.widgets.Button; 52 import org.eclipse.swt.widgets.Composite; 53 import org.eclipse.swt.widgets.Display; 54 import org.eclipse.swt.widgets.Shell; 55 import org.eclipse.swt.widgets.TabFolder; 56 import org.eclipse.swt.widgets.TabItem; 57 import org.jfree.chart.JFreeChart; 58 import org.jfree.chart.editor.ChartEditor; 59 60 63 public class SWTChartEditor implements ChartEditor { 64 65 66 private Shell shell; 67 68 69 private JFreeChart chart; 70 71 72 private SWTTitleEditor titleEditor; 73 74 75 private SWTPlotEditor plotEditor; 76 77 78 private SWTOtherEditor otherEditor; 79 80 81 protected static ResourceBundle localizationResources 82 = ResourceBundle.getBundle("org.jfree.chart.editor.LocalizationBundle"); 83 84 90 public SWTChartEditor(Display display, JFreeChart chart2edit) { 91 shell = new Shell(display, SWT.DIALOG_TRIM); 92 shell.setSize(400, 500); 93 this.chart = chart2edit; 94 shell.setText(ResourceBundle.getBundle( 95 "org.jfree.chart.LocalizationBundle").getString( 96 "Chart_Properties")); 97 GridLayout layout = new GridLayout(2, true); 98 layout.marginLeft = layout.marginTop = layout.marginRight 99 = layout.marginBottom = 5; 100 shell.setLayout(layout); 101 Composite main = new Composite(shell, SWT.NONE); 102 main.setLayout(new FillLayout()); 103 main.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); 104 105 TabFolder tab = new TabFolder(main, SWT.BORDER); 106 TabItem item1 = new TabItem(tab, SWT.NONE); 108 item1.setText(" " + localizationResources.getString("Title") + " "); 109 titleEditor = new SWTTitleEditor(tab, SWT.NONE, chart.getTitle()); 110 item1.setControl(titleEditor); 111 TabItem item2 = new TabItem(tab, SWT.NONE); 113 item2.setText(" " + localizationResources.getString( "Plot" ) + " "); 114 plotEditor = new SWTPlotEditor(tab, SWT.NONE, chart.getPlot()); 115 item2.setControl(plotEditor); 116 TabItem item3 = new TabItem(tab, SWT.NONE); 118 item3.setText(" " + localizationResources.getString("Other") + " "); 119 otherEditor = new SWTOtherEditor(tab, SWT.NONE, chart); 120 item3.setControl(otherEditor); 121 122 Button ok = new Button(shell, SWT.PUSH | SWT.OK); 124 ok.setText(" Ok "); 125 ok.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); 126 ok.addSelectionListener(new SelectionAdapter() { 127 public void widgetSelected(SelectionEvent e) { 128 updateChart(chart); 129 shell.dispose(); 130 } 131 }); 132 Button cancel = new Button(shell, SWT.PUSH); 133 cancel.setText(" Cancel "); 134 cancel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); 135 cancel.addSelectionListener(new SelectionAdapter() { 136 public void widgetSelected(SelectionEvent e) { 137 shell.dispose(); 138 } 139 } ); 140 } 141 142 145 public void open() { 146 shell.open(); 147 shell.layout(); 148 while (!shell.isDisposed()) { 149 if (!shell.getDisplay().readAndDispatch()) { 150 shell.getDisplay().sleep(); 151 } 152 } 153 } 154 155 160 public void updateChart(JFreeChart chart) 161 { 162 this.titleEditor.setTitleProperties(chart); 163 this.plotEditor.updatePlotProperties(chart.getPlot()); 164 this.otherEditor.updateChartProperties(chart ); 165 } 166 167 } 168 | Popular Tags |