Révision 641
tmp/org.txm.chartsengine.core/src/org/txm/chartsengine/core/ChartsEngine.java (revision 641) | ||
---|---|---|
286 | 286 |
/** |
287 | 287 |
* Gets an installed charts engine according to its class type. |
288 | 288 |
* @param type |
289 |
* @return the installed charts engine according to its class type if it exists otherwise null;
|
|
289 |
* @return the installed charts engine according to its class type if it exists otherwise null |
|
290 | 290 |
*/ |
291 | 291 |
public static ChartsEngine getChartsEngine(Class type) { |
292 | 292 |
ChartsEngine chartsEngine = null; |
... | ... | |
317 | 317 |
|
318 | 318 |
|
319 | 319 |
/** |
320 |
* Gets an installed charts engine according to its name. |
|
321 |
* @param type |
|
322 |
* @return the installed charts engine according to its name if it exists otherwise null |
|
323 |
*/ |
|
324 |
public static ChartsEngine getChartsEngineByName(String name) { |
|
325 |
ChartsEngine chartsEngine = null; |
|
326 |
for(int i = 0; i < ChartsEngine.chartsEngines.size(); i++) { |
|
327 |
if(chartsEngines.get(i).getName().equals(name)) { |
|
328 |
chartsEngine = ChartsEngine.chartsEngines.get(i); |
|
329 |
break; |
|
330 |
} |
|
331 |
} |
|
332 |
return chartsEngine; |
|
333 |
} |
|
334 |
|
|
335 |
/** |
|
320 | 336 |
* Gets the first charts engine that can render the specified result. |
321 | 337 |
* @param result |
322 | 338 |
* @return |
tmp/org.txm.chartsengine.core/src/org/txm/chartsengine/core/results/ChartResult.java (revision 641) | ||
---|---|---|
22 | 22 |
*/ |
23 | 23 |
public abstract class ChartResult extends TXMResult { |
24 | 24 |
|
25 |
|
|
25 | 26 |
/** |
27 |
* Linked charts engine. |
|
28 |
*/ |
|
29 |
protected ChartsEngine chartsEngine; |
|
30 |
|
|
31 |
/** |
|
26 | 32 |
* The chart object. |
27 | 33 |
*/ |
28 | 34 |
protected Object chart; |
... | ... | |
98 | 104 |
*/ |
99 | 105 |
public ChartResult(TXMResult parent) { |
100 | 106 |
super(parent); |
107 |
this.chartsEngine = ChartsEngine.getCurrent(); |
|
101 | 108 |
this.chartDirty = true; |
102 | 109 |
this.needsToResetView = false; |
103 | 110 |
this.needsToClearItemsSelection = false; |
... | ... | |
510 | 517 |
this.multipleLineStrokes = multipleStrokes; |
511 | 518 |
} |
512 | 519 |
|
520 |
|
|
521 |
/** |
|
522 |
* Gets the current charts engine used for the rendering. |
|
523 |
* @return the chartsEngine |
|
524 |
*/ |
|
525 |
public ChartsEngine getChartsEngine() { |
|
526 |
return chartsEngine; |
|
527 |
} |
|
528 |
|
|
529 |
|
|
530 |
/** |
|
531 |
* Sets the charts engine to use for the rendering. |
|
532 |
* @param chartsEngine the chartsEngine to set |
|
533 |
*/ |
|
534 |
public void setChartsEngine(ChartsEngine chartsEngine) { |
|
535 |
this.chartsEngine = chartsEngine; |
|
536 |
} |
|
537 |
|
|
513 | 538 |
|
514 | 539 |
|
515 | 540 |
// FIXME |
tmp/org.txm.chartsengine.rcp/src/org/txm/chartsengine/rcp/editors/ChartEditor.java (revision 641) | ||
---|---|---|
207 | 207 |
|
208 | 208 |
|
209 | 209 |
// check that the charts engine used for the result matches the SWT components provider otherwise fin a suitable components provider |
210 |
ChartsEngine chartsEngine = ChartsEngine.getChartsEngine(this.getResult()); |
|
211 |
if(chartsEngine != this.getSWTChartsComponentsProvider().getChartsEngine()) { |
|
212 |
this.getEditorInput().setSWTChartsComponentsProvider(SWTChartsComponentsProvider.getComponentsProvider(chartsEngine)); |
|
213 |
this.getSWTChartsComponentsProvider().setChartsEngine(chartsEngine); |
|
210 |
if(this.getResult().getChartsEngine() != this.getSWTChartsComponentsProvider().getChartsEngine()) { |
|
211 |
this.getEditorInput().setSWTChartsComponentsProvider(SWTChartsComponentsProvider.getComponentsProvider(this.getResult().getChartsEngine())); |
|
212 |
this.getSWTChartsComponentsProvider().setChartsEngine(this.getResult().getChartsEngine()); |
|
214 | 213 |
System.err.println("ChartEditor.__updateEditorFromResult(): charts engine used to create the chart is not the current one. The SWT components provider has been changed to match it: " + this.getSWTChartsComponentsProvider() + "."); |
215 | 214 |
|
216 | 215 |
// recreating the chart composite |
tmp/org.txm.chartsengine.rcp/src/org/txm/chartsengine/rcp/swt/AdvancedChartEditorToolBar.java (revision 641) | ||
---|---|---|
3 | 3 |
import java.awt.Font; |
4 | 4 |
import java.awt.GraphicsEnvironment; |
5 | 5 |
import java.util.ArrayList; |
6 |
import java.util.HashMap; |
|
7 |
import java.util.Iterator; |
|
8 |
import java.util.Map; |
|
6 | 9 |
|
10 |
import org.apache.commons.lang.StringUtils; |
|
7 | 11 |
import org.eclipse.swt.SWT; |
8 | 12 |
import org.eclipse.swt.events.SelectionEvent; |
9 | 13 |
import org.eclipse.swt.events.SelectionListener; |
... | ... | |
15 | 19 |
import org.txm.chartsengine.core.ChartsEngine; |
16 | 20 |
import org.txm.chartsengine.core.preferences.ChartsEnginePreferences; |
17 | 21 |
import org.txm.chartsengine.core.results.ChartResult; |
22 |
import org.txm.chartsengine.rcp.SWTChartsComponentsProvider; |
|
18 | 23 |
import org.txm.chartsengine.rcp.editors.ChartEditor; |
19 | 24 |
import org.txm.chartsengine.rcp.messages.SWTComponentsProviderMessages; |
20 | 25 |
import org.txm.rcp.IImageKeys; |
... | ... | |
160 | 165 |
fontSizeCombo.select(currentFontSizeIndex); |
161 | 166 |
|
162 | 167 |
|
163 |
// Chart types from installed chart creators |
|
168 |
// Chart types from installed chart creators in all installed charts engines |
|
169 |
final Combo chartTypeCombo = new Combo(this, SWT.READ_ONLY); |
|
170 |
ArrayList<String> chartsEngineNames = new ArrayList<String>(); |
|
171 |
ArrayList<ChartCreator> allChartCreators = new ArrayList<ChartCreator>(); |
|
164 | 172 |
|
165 |
// if(contributions.length > 1) { |
|
166 |
final Combo chartTypeCombo = new Combo(this, SWT.READ_ONLY); |
|
167 |
|
|
168 |
ArrayList<ChartCreator> chartCreators = new ArrayList<ChartCreator>(); |
|
169 |
for (int i = 0; i < ChartsEngine.getChartsEngines().size(); i++) { |
|
170 |
chartCreators.addAll(ChartsEngine.getChartsEngines().get(i).getChartCreators(this.chartEditorPart.getResult())); |
|
173 |
for (int i = 0; i < ChartsEngine.getChartsEngines().size(); i++) { |
|
174 |
ArrayList<ChartCreator> chartCreators = ChartsEngine.getChartsEngines().get(i).getChartCreators(this.chartEditorPart.getResult()); |
|
175 |
for (int j = 0; j < chartCreators.size(); j++) { |
|
176 |
chartsEngineNames.add(ChartsEngine.getChartsEngines().get(i).getName()); |
|
177 |
allChartCreators.add(chartCreators.get(j)); |
|
171 | 178 |
} |
179 |
} |
|
180 |
|
|
181 |
|
|
182 |
String chartTypes[] = new String[allChartCreators.size()]; |
|
183 |
int currentChartTypeIndex = 0; |
|
184 |
|
|
185 |
for(int i = 0; i < allChartCreators.size(); i++) { |
|
172 | 186 |
|
173 |
|
|
174 |
String chartTypes[] = new String[chartCreators.size()]; |
|
175 |
int currentChartTypeIndex = 0; |
|
176 |
for(int i = 0; i < chartCreators.size(); i++) { |
|
177 |
chartTypes[i] = chartCreators.get(i).getChartType(); |
|
178 |
if(chartTypes[i] == null) { |
|
179 |
chartTypes[i] = ChartsEnginePreferences.DEFAULT_CHART_TYPE; |
|
180 |
} |
|
181 |
if(this.getEditorPart().getChartType() != null && this.getEditorPart().getChartType().equals(chartTypes[i])) { |
|
182 |
currentChartTypeIndex = i; |
|
183 |
} |
|
184 |
|
|
187 |
chartTypes[i] = allChartCreators.get(i).getChartType(); |
|
188 |
if(chartTypes[i] == null) { |
|
189 |
chartTypes[i] = ChartsEnginePreferences.DEFAULT_CHART_TYPE; |
|
185 | 190 |
} |
186 |
chartTypeCombo.setItems(chartTypes); |
|
187 |
|
|
188 |
ToolItem chartTypeComboItem = new ToolItem(this, SWT.SEPARATOR); |
|
189 |
chartTypeComboItem.setControl(chartTypeCombo); |
|
190 |
chartTypeCombo.pack(); |
|
191 |
chartTypeComboItem.setWidth(chartTypeCombo.getBounds().width); |
|
192 |
|
|
193 |
chartTypeCombo.select(currentChartTypeIndex); |
|
194 |
|
|
195 |
|
|
196 |
if(chartCreators.size() < 2) { |
|
197 |
chartTypeCombo.setVisible(false); |
|
191 |
|
|
192 |
if(this.getEditorPart().getChartType() != null && this.getEditorPart().getChartType().equals(chartTypes[i]) |
|
193 |
&& this.getEditorPart().getChartsEngine().getName().equals(chartsEngineNames.get(i))) { |
|
194 |
currentChartTypeIndex = i; |
|
198 | 195 |
} |
199 |
// } |
|
200 |
// else { |
|
201 |
// final Combo chartTypeCombo = null; |
|
202 |
// } |
|
196 |
chartTypes[i] = chartsEngineNames.get(i) + " / " + chartTypes[i]; |
|
197 |
} |
|
198 |
chartTypeCombo.setItems(chartTypes); |
|
203 | 199 |
|
200 |
ToolItem chartTypeComboItem = new ToolItem(this, SWT.SEPARATOR); |
|
201 |
chartTypeComboItem.setControl(chartTypeCombo); |
|
202 |
chartTypeCombo.pack(); |
|
203 |
chartTypeComboItem.setWidth(chartTypeCombo.getBounds().width); |
|
204 | 204 |
|
205 |
chartTypeCombo.select(currentChartTypeIndex); |
|
205 | 206 |
|
206 | 207 |
|
208 |
if(allChartCreators.size() < 2) { |
|
209 |
chartTypeCombo.setVisible(false); |
|
210 |
} |
|
211 |
|
|
212 |
|
|
207 | 213 |
// Listeners |
208 | 214 |
SelectionListener listener = new SelectionListener() { |
209 | 215 |
|
... | ... | |
228 | 234 |
chartEditorPart.getResult().setFont("1|" + fontCombo.getItem(fontCombo.getSelectionIndex()) + "|" + fontSizeCombo.getItem(fontSizeCombo.getSelectionIndex()) + "|0"); |
229 | 235 |
} |
230 | 236 |
else if(e.getSource() == chartTypeCombo) { |
231 |
chartEditorPart.getResult().setChartType(chartTypeCombo.getItem(chartTypeCombo.getSelectionIndex())); |
|
237 |
|
|
238 |
String[] data = StringUtils.split(chartTypeCombo.getItem(chartTypeCombo.getSelectionIndex()), '/'); |
|
239 |
data[0] = StringUtils.trim(data[0]); |
|
240 |
data[1] = StringUtils.trim(data[1]); |
|
241 |
chartEditorPart.getResult().setChartType(data[1]); |
|
242 |
chartEditorPart.getResult().setChartsEngine(ChartsEngine.getChartsEngineByName(data[0])); |
|
232 | 243 |
update = false; |
233 | 244 |
} |
234 | 245 |
|
Formats disponibles : Unified diff