Revision 49

tmp/org.txm.chartsengine.core/src/org/txm/chartsengine/core/ChartsEngine.java (revision 49)
1
package org.txm.chartsengine.core;
2

  
3
import java.io.File;
4
import java.io.IOException;
5
import java.util.ArrayList;
6
import java.util.HashMap;
7
import java.util.Properties;
8

  
9
import org.eclipse.core.runtime.CoreException;
10
import org.eclipse.core.runtime.IConfigurationElement;
11
import org.eclipse.core.runtime.Platform;
12
import org.txm.Messages;
13
import org.txm.Toolbox;
14
import org.txm.functions.ca.CA;
15
import org.txm.functions.classification.CAH;
16
import org.txm.functions.progression.Progression;
17
import org.txm.functions.specificities.SpecificitesResult;
18
import org.txm.tbx.chartsengine.base.messages.ChartsEngineMessages;
19
import org.txm.utils.logger.Log;
20

  
21

  
22
/**
23
 * Common charts engine. This is the superclass of all chart engine implementations.
24
 * This class provides methods to create charts from variable chart creator stored by type of result data such as CA, CAH, Singular values, etc.
25
 * @author sjacquot
26
 *
27
 */
28
public abstract class ChartsEngine {
29

  
30
	/**
31
	 * Chart type constants.
32
	 */
33
	public final static int CHART_TYPE_PARTITION_DIMENSIONS = 0, CHART_TYPE_SPECIFICITIES = 1, CHART_TYPE_PROGRESSION = 2, CHART_TYPE_CA_FACTORIAL_MAP = 3, CHART_TYPE_CA_SINGULAR_VALUES = 4,
34
			CHART_TYPE_CAH_2D = 5, CHART_TYPE_CAH_3D = 6;
35

  
36
	/**
37
	 * Constants for output formats and file extensions.
38
	 */
39
	public final static String OUTPUT_FORMAT_JPEG = "jpeg", OUTPUT_FORMAT_PDF = "pdf", OUTPUT_FORMAT_PNG = "png", OUTPUT_FORMAT_PS = "ps", OUTPUT_FORMAT_SVG = "svg", OUTPUT_FORMAT_BMP = "bmp", OUTPUT_FORMAT_GIF = "gif";
40
	
41
	/**
42
	 * Constants for the colors rendering modes.
43
	 */
44
	public final static int RENDERING_COLORS_MODE = 0, RENDERING_GRAYSCALE_MODE = 1, RENDERING_MONOCHROME_MODE = 2;
45

  
46
	/**
47
	 * Prefix to use for properties names.
48
	 */
49
	public final static String propertiesPrefix = "charts_engine_";
50

  
51
	/**
52
	 * Constant for showing title or not in the charts.
53
	 */
54
	public final static String PROP_CHARTS_SHOW_TITLE = propertiesPrefix +  "show_title"; //$NON-NLS-1$
55

  
56

  
57
	/**
58
	 * Constant for showing legend or not in the charts.
59
	 */
60
	public final static String PROP_CHARTS_SHOW_LEGEND = propertiesPrefix +  "show_legend"; //$NON-NLS-1$
61

  
62

  
63
	/**
64
	 * Constant for showing grid/lines or not in the charts.
65
	 */
66
	public final static String PROP_CHARTS_SHOW_GRID_LINES = propertiesPrefix +  "show_grid"; //$NON-NLS-1$
67

  
68

  
69
	/**
70
	 * Constant for the partition dimensions parts order in chart.
71
	 */
72
	//public final static String PROP_PARTITION_DIMENSIONS_SORTED_BY_SIZE = propertiesPrefix + "partition_dimensions_sort_by_size";
73
	// FIXME : rename this property according to the line above
74
	//public final static String PROP_PARTITION_DIMENSIONS_SORTED_BY_SIZE = "diag_partssort"; //$NON-NLS-1$
75

  
76
	/**
77
	 * Constant for the partition dimensions display parts count in chart title.
78
	 */
79
	//public final static String PROP_PARTITION_DIMENSIONS_DISPLAY_PARTS_COUNT_IN_TITLE = propertiesPrefix +  "partition_dimensions_display_parts_count_in_title"; //$NON-NLS-1$
80

  
81
	/**
82
	 * Constant for the current charts engine used by the tool box.
83
	 */
84
	public static final String PROP_CHARTS_ENGINE_NAME = propertiesPrefix +  "name"; //$NON-NLS-1$
85

  
86
	/**
87
	 * Constant for the output format of the current charts engine.
88
	 */
89
	public static final String PROP_CHARTS_ENGINE_OUTPUT_FORMAT = propertiesPrefix + "output_format"; //$NON-NLS-1$
90

  
91

  
92
	/**
93
	 * Properties for each type of result data (as <code>Partition</code> : sort by size, <code>SpecificitesResult</code> : draw bars, draw lines, etc.)
94
	 */
95
	 // FIXME: creates a specific class for this extending Properties ? then put all the constant property names in it ?
96
	// FIXME: see that when we'll discuss about using RCP store for TBX plugin.
97
	public static Properties properties;
98

  
99
	/**
100
	 * The engine name.
101
	 */
102
	protected String name;
103

  
104

  
105
	/**
106
	 * The engine description.
107
	 */
108
	protected String description;
109

  
110

  
111
	/**
112
	 * The current output format.
113
	 */
114
	protected String outputFormat;
115

  
116
	
117
	
118
	protected HashMap<Class, HashMap<String, ChartCreator>> chartCreators;
119

  
120
	
121
	/**
122
	 * Installed charts engines.
123
	 */
124
	protected static ArrayList<ChartsEngine> chartsEngines;
125
	
126
	/**
127
	 * Current charts engine index in the charts engine list.
128
	 */
129
	protected static int currentChartsEngineIndex;
130
	
131
	/**
132
	 * Creates a charts engine.
133
	 */
134
	// FIXME : useless ?
135
//	protected ChartsEngine() {
136
//		this("abstract_charts_engine", "Abstract Charts Engine"); //$NON-NLS-1$
137
//	}
138

  
139
//	/**
140
//	 * Creates a charts engine with the specified name, description and output format.
141
//	 * @param name
142
//	 * @param description
143
//	 * @param outputFormat
144
//	 */
145
//	protected ChartsEngine(String name, String description, String outputFormat) {
146
//		this(name, description, outputFormat);
147
//		Log.warning("Starting Charts Engine: " + this);
148
//	}
149

  
150

  
151
	/**
152
	 * Creates a charts engine with the specified name, description and output format.
153
	 * @param name
154
	 * @param description
155
	 * @param outputFormat
156
	 */
157
	protected ChartsEngine(String name, String description, String outputFormat) {
158
		this();
159
		this.name = name;
160
		this.description = description;
161
		this.outputFormat = outputFormat;
162
		//this.setOutputFormat(outputFormat);
163
		Log.warning("Starting Charts Engine: " + this);
164
	}
165

  
166

  
167
	/**
168
	 * Creates a charts engine.
169
	 */
170
	protected ChartsEngine()	{
171
		this.chartCreators = new HashMap<Class, HashMap<String,ChartCreator>>();
172
	}
173
	
174
	
175
	/**
176
	 * Gets a chart creator for the specified result data type and chart type.
177
	 * @param resultDataType
178
	 * @param chartType
179
	 * @return A chart creator if it exists otherwise <code>null</code>
180
	 */
181
	public ChartCreator getChartCreator(Class resultDataType, String chartType)	{
182
		ChartCreator chartCreator = null;
183
		HashMap<String, ChartCreator> map = this.chartCreators.get(resultDataType);
184
		if(map != null)	{
185
			if(chartType == null)	{
186
				chartType = resultDataType.getName();
187
			}
188
			chartCreator = map.get(chartType);
189
		}
190
		
191
		if(chartCreator == null)	{
192
			Log.warning(this.name + ": No chart creator can be found for result: " + resultDataType + " and chart type: " + chartType);
193
		}
194
		return chartCreator;
195
	}
196
	
197
	/**
198
	 * Gets a chart creator for the specified result data type.
199
	 * @param resultDataType
200
	 * @return A chart creator if it exists otherwise <code>null</code>
201
	 */
202
	public ChartCreator getChartCreator(Class resultDataType)	{
203
		return this.getChartCreator(resultDataType, resultDataType.getName());
204
	}
205

  
206
	/**
207
	 * Adds a chart creator for the specified result data type and chart type.
208
	 * @param resultDataType
209
	 * @param chartCreator
210
	 * @param chartType
211
	 */
212
	public void addChartCreator(Class resultDataType, ChartCreator chartCreator, String chartType)	{
213
		
214
		if(chartType == null)	{
215
			chartType = resultDataType.getName();
216
		}
217
		
218
		if(!this.chartCreators.containsKey(resultDataType))	{
219
			HashMap<String, ChartCreator> m = new HashMap<String, ChartCreator>();
220
			m.put(chartType, chartCreator);
221
			this.chartCreators.put(resultDataType, m);
222
		}
223
		else	{
224
			this.chartCreators.get(resultDataType).put(chartType, chartCreator);
225
		}
226
		
227
		
228
		chartCreator.setChartsEngine(this);		
229

  
230
		Log.warning(this.name + ": Chart creator " + chartCreator.getClass().getSimpleName() + " added for result: " + resultDataType + " and chart type: " + chartType);
231
	}
232
	
233

  
234
	/**
235
	 * Checks if the charts engine can create a chart according to the specified result data type and chart type.
236
	 * @param resultDataType
237
	 * @param chartType
238
	 * @return <code>True</code> if a chart creator can be found, otherwise <code>false</code>
239
	 */
240
	public boolean canCreateChart(Class resultDataType, String chartType)	{
241
		return this.getChartCreator(resultDataType, chartType) != null;
242
	}
243

  
244
	/**
245
	 * Checks if the charts engine can create a chart according to the specified result data type.
246
	 * @param resultDataType
247
	 * @return <code>True</code> if a chart creator can be found, otherwise <code>false</code>
248
	 */
249
	public boolean canCreateChart(Class resultDataType)	{
250
		return this.getChartCreator(resultDataType) != null;
251
	}
252

  
253
	
254
	/**
255
	 * Creates and stores charts engines from installed extension contributions.
256
	 * @param outputFormat
257
	 */
258
	public static void createChartsEngines()	{
259
		
260
		ChartsEngine.chartsEngines = new ArrayList<ChartsEngine>();
261
		ChartsEngine.currentChartsEngineIndex = 0;
262
		
263
		String extensionPointId = "org.txm.chartsengine.chartsengine"; //$NON-NLS-1$
264
		IConfigurationElement[] contributions = Platform.getExtensionRegistry().getConfigurationElementsFor(extensionPointId);
265

  
266
		for(int i = 0; i < contributions.length; i++) {
267
			try {
268
				ChartsEngine chartsEngine = (ChartsEngine)contributions[i].createExecutableExtension("class"); //$NON-NLS-1$
269
				chartsEngine.registerChartCreatorExtensions();
270
				ChartsEngine.chartsEngines.add(chartsEngine);
271
			}
272
			catch(CoreException e) {
273
				e.printStackTrace();
274
			} 
275
		}
276
	}
277

  
278
	/**
279
	 * Gets the current charts engine.
280
	 * @return the current charts engine
281
	 */
282
	public static ChartsEngine getCurrent()	{
283
		return ChartsEngine.chartsEngines.get(ChartsEngine.currentChartsEngineIndex);
284
	}
285
	
286
	/**
287
	 * Sets the current charts engine according to its internal name. 
288
	 * @param name the name of the charts engine to set as current
289
	 */
290
	public static void setCurrrentChartsEngine(String name)	{
291
		for(int i = 0; i < ChartsEngine.chartsEngines.size(); i++) {
292
			if(chartsEngines.get(i).getName().equals(name))	{
293
				ChartsEngine.currentChartsEngineIndex = i;
294
				Log.warning("Set current charts engine to: " + ChartsEngine.getCurrent());
295
				break;
296
			}
297
		}
298
	}
299
	
300
	/**
301
	 * Gets an installed charts engine according to its class type.
302
	 * @param type
303
	 * @return the installed charts engine according to its class type if it exists otherwise null;
304
	 */
305
	public static ChartsEngine getChartsEngine(Class type)	{
306
		ChartsEngine chartsEngine = null;
307
		for(int i = 0; i < ChartsEngine.chartsEngines.size(); i++) {
308
			if(ChartsEngine.chartsEngines.get(i).getClass().equals(type))	{
309
				chartsEngine = ChartsEngine.chartsEngines.get(i);
310
				break;
311
			}
312
		}
313
		return chartsEngine;
314
	}
315
	
316
	/**
317
	 * Gets an installed charts engine that supports the specified output format.
318
	 * @param outputFormat
319
	 * @return
320
	 */
321
	public static ChartsEngine getChartsEngine(String outputFormat)	{
322
		ChartsEngine chartsEngine = null;
323
		for(int i = 0; i < ChartsEngine.chartsEngines.size(); i++) {
324
			if(ChartsEngine.chartsEngines.get(i).getSupportedOutputDisplayFormats().contains(outputFormat) || ChartsEngine.chartsEngines.get(i).getSupportedOutputFileFormats().contains(outputFormat))	{
325
				chartsEngine = ChartsEngine.chartsEngines.get(i);
326
				break;
327
			}
328
		}
329
		return chartsEngine;
330
	}
331
	
332
	/**
333
	 * Returns the installed charts engine contributions.
334
	 * @return
335
	 */
336
	public static  ArrayList<ChartsEngine> getChartsEngines()	{
337
		return ChartsEngine.chartsEngines;
338
	}
339
	
340
	
341
	// FIXME: old method managing only one charts engine
342
	// FIXME: this method should create all possible charts engines from currently installed extensions and store them in a list then define a current charts engine.
343
	// It would permit to call some ChartCreator of another chart engine than the current if a chart creator for a specified result doesn't exist
344
	// for a specified type of chart
345
	// SWTChartsComponentsProvider should do the same thing, then in createChartEditor go through all the Providers? or through all the charts engine that match the provider input format?
346
//	public static ChartsEngine createChartsEngines(String name)	{
347
//		
348
//		ChartsEngine chartsEngine = null;
349
//		
350
//		String extensionPointId = "org.txm.tbx.chartsengine"; //$NON-NLS-1$
351
//		IConfigurationElement[] contributions = Platform.getExtensionRegistry().getConfigurationElementsFor(extensionPointId);
352
//		IConfigurationElement chartsEngineExtension = null;
353
//
354
//		Log.warning("Installed Chart Engine extensions: ");
355
//		
356
//		for(int i = 0; i < contributions.length; i++) {
357
//			Log.warning(contributions[i].getAttribute("name"));   //$NON-NLS-1$
358
//			if(contributions[i].getAttribute("name").equals(name))	{ //$NON-NLS-1$
359
//				chartsEngineExtension = contributions[i];
360
//	            //break;
361
//			}
362
//		}
363
//		if(chartsEngineExtension != null) {
364
//			try {
365
//				chartsEngine = (ChartsEngine)chartsEngineExtension.createExecutableExtension("class"); //$NON-NLS-1$
366
//			}
367
//			catch(CoreException e) {
368
//				// TODO Auto-generated catch block
369
//				e.printStackTrace();
370
//			} 
371
//		}
372
//		
373
//		chartsEngine.registerChartCreatorExtensions();
374
//		
375
//		Log.warning("Charts Engine initialized.");
376
//		
377
//		return chartsEngine;
378
//	}
379
//	
380

  
381
	/**
382
	 * Populates the chart creators from loaded extensions according to the specified chars engine name.
383
	 * @param chartsEngineName
384
	 */
385
	protected void registerChartCreatorExtensions(String chartsEngineName)	{
386
		String extensionPointId = "org.txm.chartsengine.chartcreator"; //$NON-NLS-1$
387
		IConfigurationElement[] contributions = Platform.getExtensionRegistry().getConfigurationElementsFor(extensionPointId);
388
		
389
		for(int i = 0; i < contributions.length; i++) {
390
			
391
			if(contributions[i].getAttribute("chartsEngineName").equals(chartsEngineName))	{ //$NON-NLS-1$
392
				try {
393
					ChartCreator chartCreator = (ChartCreator) contributions[i].createExecutableExtension("class"); //$NON-NLS-1$
394
					chartCreator.setFileNamePrefix(contributions[i].getAttribute("fileNamePrefix")); //$NON-NLS-1$
395
					this.addChartCreator(chartCreator.getResultDataType(), chartCreator, contributions[i].getAttribute("chartType")); //$NON-NLS-1$
396
				}
397
				catch(CoreException e) {
398
					// TODO Auto-generated catch block
399
					e.printStackTrace();
400
				} 
401

  
402
			}
403
		}
404
	}
405
	
406
	
407
	/**
408
	 * Populates the chart creators from loaded extensions.
409
	 */
410
	public void registerChartCreatorExtensions()	{
411
		this.registerChartCreatorExtensions(this.name);
412
	}
413
	
414
	
415
	/**
416
	 * Creates a temporary file in USER_TXM_HOME\results with the specified prefix for writing the chart.
417
	 * The suffix is computed according to the current output format of the charts engine.
418
	 * @return
419
	 */
420
	public File createTmpFile(String prefix)	{
421
		File file = null;
422
		try {
423
			File resultsDir = new File(Toolbox.getParam(Toolbox.USER_TXM_HOME), "results"); //$NON-NLS-1$
424
			resultsDir.mkdirs();
425
			file = File.createTempFile(prefix, "." + this.outputFormat, resultsDir);
426
		}
427
		catch (IOException e) {
428
			Log.severe(ChartsEngineMessages.ChartsEngine_CANT_CREATE_TMP_FILE_CHART + e);
429
		}
430

  
431
		// TODO : old code, useful ? and/or return null instead of the file if canWrite() return false ?
432
		if(!file.canWrite()) {
433
			Log.severe(ChartsEngineMessages.ChartsEngine_CANT_WRITE_IN_FILE + file);
434
		}
435
		return file;
436
	}
437

  
438

  
439
	/**
440
	 * Creates a temporary file in USER_TXM_HOME\results.
441
	 * The prefix and the suffix are computed according to the specified chart type and the current output format of the charts engine.
442
	 * @param chartType
443
	 * @return
444
	 */
445
	// FIXME: stop to use and remove the chart static types in ChartsEngine? Cause this is now delegate to the chart creator extensions? 
446
	public File createTmpFile(int chartType)	{
447
		if(chartType == ChartsEngine.CHART_TYPE_PARTITION_DIMENSIONS)	{
448
			return this.createTmpFile("info");
449
		}
450
		else if(chartType == ChartsEngine.CHART_TYPE_SPECIFICITIES)	{
451
			return this.createTmpFile("specif");
452
		}
453
		else if(chartType == ChartsEngine.CHART_TYPE_CA_SINGULAR_VALUES)	{
454
			return this.createTmpFile("casingularvalues");
455
		}
456
		else if(chartType == ChartsEngine.CHART_TYPE_CA_FACTORIAL_MAP)	{
457
			return this.createTmpFile("cafactorialmap");
458
		}
459
		else if(chartType == ChartsEngine.CHART_TYPE_PROGRESSION)	{
460
			return this.createTmpFile("progression");
461
		}
462
		else if(chartType == ChartsEngine.CHART_TYPE_CAH_2D)	{
463
			return this.createTmpFile("cah2d");
464
		}
465
		else if(chartType == ChartsEngine.CHART_TYPE_CAH_3D)	{
466
			return this.createTmpFile("cah3d");
467
		}
468

  
469
		return this.createTmpFile("unknown");
470
	}
471

  
472

  
473
	/**
474
	 * Creates a factorial map chart from the specified CA result.
475
	 * @param ca
476
	 * @return the factorial map chart object
477
	 */
478
	public abstract Object createCAFactorialMapChart(CA ca);
479

  
480

  
481
	/**
482
	 * Creates a factorial map chart from the specified CA result and writes it in the specified file.
483
	 * @param ca
484
	 * @param file
485
	 * @return the generated file containing the chart
486
	 */
487
	public abstract File createCAFactorialMapChartFile(CA ca, File file);
488

  
489

  
490
	/**
491
	 * Creates a factorial map chart from the specified CA result and writes it in a temporary file in USER_TXM_HOME\results.
492
	 * The prefix and the suffix are computed according to the chart type and the current output format of the charts engine.
493
	 * @param ca
494
	 * @return
495
	 */
496
	public File createCAFactorialMapChartFile(CA ca)	{
497
		return this.createCAFactorialMapChartFile(ca, this.createTmpFile(ChartsEngine.CHART_TYPE_CA_FACTORIAL_MAP));
498
	}
499

  
500

  
501
	/**
502
	 * Creates a string title, shared by charts engine implementations, for the CA factorial map chart from the specified result.
503
	 * @param ca
504
	 * @return
505
	 */
506
	public String createCAFactorialMapChartTitle(CA ca)	{
507

  
508
		String partitionName;
509
		if (ca.getPartition() == null) {
510
			partitionName = "<no partition>";
511
		}
512
		else	{
513
			partitionName = ca.getPartition().getName();
514
		}
515

  
516
		String corpusName;
517
		if (ca.getCorpus() == null) {
518
			corpusName = "<no corpus>";
519
		}
520
		else	{
521
			corpusName = ca.getCorpus().getName();
522
		}
523

  
524
		return ChartsEngineMessages.bind(ChartsEngineMessages.ChartsEngine_CA_FACTORIAL_MAP_TITLE, partitionName, corpusName);
525
	}
526

  
527
	/**
528
	 * Creates a bar plot with singular values of the specified CA result.
529
	 * @param ca
530
	 * @return the singular values bar plot object
531
	 */
532
	public abstract Object createCASingularValuesBarChart(CA ca);
533

  
534
	/**
535
	 * Creates a bar plot with singular values of the specified CA result and writes it in the specified file.
536
	 * @param ca
537
	 * @return
538
	 */
539
	public abstract File createCASingularValuesBarChartFile(CA ca, File file);
540

  
541

  
542
	/**
543
	 * Creates a bar plot with singular values of the specified CA result and writes it in a temporary file in USER_TXM_HOME\results.
544
	 * The prefix and the suffix are computed according to the chart type and the current output format of the charts engine.
545
	 * @param ca
546
	 * @return
547
	 */
548
	public File createCASingularValuesBarChartFile(CA ca)	{
549
		return this.createCASingularValuesBarChartFile(ca, this.createTmpFile(ChartsEngine.CHART_TYPE_CA_SINGULAR_VALUES));
550
	}
551

  
552

  
553
// FIXME
554
//	/**
555
//	 * Creates a chart from the specified CAH result.
556
//	 * @param cah
557
//	 * @return
558
//	 */
559
//	public Object createCAHChart(CAH cah)	{
560
//		return this.createCAHChart(cah, cah.isDisplay2D());
561
//	}
562
//
563

  
564
	/**
565
	 * Creates a chart from the specified CAH result.
566
	 * @param cah
567
	 * @return
568
	 */
569
	public Object createCAHChart(CAH cah, boolean chart2d)	{
570
		if(chart2d)	{
571
			return this.createCAH2dChart(cah);
572
		}
573
		else	{
574
			return this.createCAH3dChart(cah);
575
		}
576
	}
577

  
578
// FIXME
579
//
580
//	/**
581
//	 * Creates a chart from the specified CAH result and writes it in a temporary file in USER_TXM_HOME\results
582
//	 * @param cah
583
//	 * @return
584
//	 */
585
//	public File createCAHChartFile(CAH cah)	{
586
//		return this.createCAHChartFile(cah, cah.isDisplay2D());
587
//	}
588
//
589
//
590
//	/**
591
//	 * Creates a chart from the specified CAH result and writes it in the specified file.
592
//	 * @param cah
593
//	 * @param file
594
//	 * @return
595
//	 */
596
//	public File createCAHChartFile(CAH cah, File file)	{
597
//		return this.createCAHChartFile(cah, cah.isDisplay2D(), file);
598
//	}
599

  
600

  
601
	/**
602
	 * Creates a chart from the specified CAH result and writes it in the specified file.
603
	 * @param cah
604
	 * @param file
605
	 * @return
606
	 */
607
	public File createCAHChartFile(CAH cah, boolean display2D, File file)	{
608
		if(display2D)	{
609
			return this.createCAH2dChartFile(cah, file);
610
		}
611
		else	{
612
			return this.createCAH3dChartFile(cah, file);
613
		}
614
	}
615

  
616
	/**
617
	 * Creates a chart from the specified CAH result and writes it in a temporary file in USER_TXM_HOME\results
618
	 * @param cah
619
	 * @param display2D
620
	 * @return
621
	 */
622
	public File createCAHChartFile(CAH cah, boolean display2D)	{
623
		if(display2D)	{
624
			return this.createCAH2dChartFile(cah);
625
		}
626
		else	{
627
			return this.createCAH3dChartFile(cah);
628
		}
629
	}
630

  
631
	/**
632
	 * Creates a 2d chart from the specified CAH result.
633
	 * @param cah
634
	 * @return
635
	 */
636
	public abstract Object createCAH2dChart(CAH cah);
637

  
638

  
639
	/**
640
	 * Creates a 2d chart from the specified CAH result and writes it in the specified file.
641
	 * @param cah
642
	 * @param file
643
	 * @return
644
	 */
645
	public abstract File createCAH2dChartFile(CAH cah, File file);
646

  
647

  
648
	/**
649
	 * Creates a 2d chart from the specified CAH result and writes it in a temporary file in USER_TXM_HOME\results.
650
	 * The prefix and the suffix are computed according to the chart type and the current output format of the charts engine.
651
	 * @param cah
652
	 * @return
653
	 */
654
	public File createCAH2dChartFile(CAH cah)	{
655
		return this.createCAH2dChartFile(cah, this.createTmpFile(ChartsEngine.CHART_TYPE_CAH_2D));
656
	}
657

  
658
	/**
659
	 * Creates a 3d chart from the specified CAH result.
660
	 * @param cah
661
	 * @return
662
	 */
663
	public abstract Object createCAH3dChart(CAH cah);
664

  
665

  
666
	/**
667
	 * Creates a 3d chart from the specified CAH result and writes it in the specified file.
668
	 * @param cah
669
	 * @param file
670
	 * @return
671
	 */
672
	public abstract File createCAH3dChartFile(CAH cah, File file);
673

  
674

  
675
	/**
676
	 * Creates a 3d chart from the specified CAH result and writes it in a temporary file in USER_TXM_HOME\results.
677
	 * The prefix and the suffix are computed according to the chart type and the current output format of the charts engine.
678
	 * @param cah
679
	 * @return
680
	 */
681
	public File createCAH3dChartFile(CAH cah)	{
682
		return this.createCAH3dChartFile(cah, this.createTmpFile(ChartsEngine.CHART_TYPE_CAH_3D));
683
	}
684

  
685
	/**
686
	 * Creates a chart from the specified specificities result.
687
	 * @param specificitesResult the specificities result
688
	 * @return
689
	 */
690
	public abstract Object createSpecificitiesChart(SpecificitesResult specificitiesResult, boolean transpose, boolean drawBars, boolean drawLines, float banalite, boolean grayscale);
691

  
692

  
693
	/**
694
	 * Creates a chart from the specified specificities result and writes it in the specified file.
695
	 * @param specificitesResult the specificities result
696
	 * @param file
697
	 * @return
698
	 */
699
	public abstract File createSpecificitiesChartFile(SpecificitesResult specificitiesResult, boolean transpose, boolean drawBars, boolean drawLines, float banalite, boolean grayscale, File file);
700

  
701

  
702
	/**
703
	 * Creates a chart from the specified specificities result and writes it in a temporary file in USER_TXM_HOME\results.
704
	 * The prefix and the suffix are computed according to the chart type and the current output format of the charts engine.
705
	 * @param specificitiesResult
706
	 * @param typeNames
707
	 * @param partNames
708
	 * @param specIndex
709
	 * @param transpose
710
	 * @param drawBars
711
	 * @param drawLines
712
	 * @param banalite
713
	 * @param monochrome
714
	 * @return
715
	 */
716
	public File createSpecificitiesChartFile(SpecificitesResult specificitiesResult, boolean transpose, boolean drawBars, boolean drawLines, float banalite, boolean monochrome)	{
717
		return this.createSpecificitiesChartFile(specificitiesResult, transpose, drawBars, drawLines, banalite, monochrome, this.createTmpFile(ChartsEngine.CHART_TYPE_SPECIFICITIES));
718
	}
719

  
720

  
721
	/**
722
	 * Creates a dimensions partition bar chart from the specified <code>Partition</code> result.
723
	 * @param partition
724
	 * @param sortPartsBySize
725
	 * @return
726
	 */
727
	//public abstract Object createPartitionDimensionsChart(Partition partition, boolean sortPartsBySize);
728

  
729

  
730
	/**
731
	 * Creates a dimensions partition bar chart from the specified <code>Partition</code> result and writes it in the specified file.
732
	 * @param partition
733
	 * @param sortPartsBySize
734
	 * @param file
735
	 * @return
736
	 */
737
	//public abstract File createPartitionDimensionsChartFile(Partition partition, boolean sortPartsBySize, File file);
738

  
739

  
740
	/**
741
	 * Creates a dimensions partition bar chart from the specified <code>Partition</code> result and writes it in a temporary file in USER_TXM_HOME\results.
742
	 * The prefix and the suffix are computed according to the chart type and the current output format of the charts engine.
743
	 * @param partition
744
	 * @param sortPartsBySize
745
	 * @return
746
	 */
747
//	public File createDimensionsPartitionChartFile(Partition partition, boolean sortPartsBySize)	{
748
//		return this.createPartitionDimensionsChartFile(partition, sortPartsBySize, this.createTmpFile(ChartsEngine.CHART_TYPE_PARTITION_DIMENSIONS));
749
//	}
750

  
751
	/**
752
	 *
753
	 * @param partition
754
	 * @param file
755
	 * @return
756
	 */
757
//	public File createDimensionsPartitionChartFile(Partition partition, File file)	{
758
//		return this.createPartitionDimensionsChartFile(partition, (Boolean) ChartsEngine.properties.get(ChartsEngine.PROP_PARTITION_DIMENSIONS_SORTED_BY_SIZE), file);
759
//	}
760

  
761

  
762
	/**
763
	 * Creates a string title, shared by charts engine implementations, for the dimensions partition chart from the specified result.
764
	 * @param the partition result
765
	 * @param sortPartsBySize the sort parts by size state
766
	 * @return the title string
767
	 */
768
//	public String createPartitionDimensionsChartTitle(Partition partition, boolean sortPartsBySize)	{
769
//
770
//		String title = ChartsEngineMessages.bind(ChartsEngineMessages.ChartsEngine_PARTITION_DIMENSIONS_DIMENSIONS_OF_PARTITION, partition.getName(), partition.getCorpus().getName());
771
//
772
//		if((Boolean) ChartsEngine.properties.get(PROP_PARTITION_DIMENSIONS_DISPLAY_PARTS_COUNT_IN_TITLE))	{
773
//			title += "\n(" +  partition.getParts().size() + " parts" + ")"; //$NON-NLS-1$ //$NON-NLS-3$
774
//		}
775
//
776
//		if(sortPartsBySize) {
777
//			title += ChartsEngineMessages.ChartsEngine_PARTITION_DIMENSIONS_SORTED_BY_SIZE;
778
//		}
779
//
780
//		return title;
781
//	}
782

  
783

  
784

  
785
	/**
786
	 * Creates a progression chart from the specified <code>Progression</code> result and writes it in the specified file.
787
	 * @param progression
788
	 * @return
789
	 */
790
	public abstract Object createProgressionChart(Progression progression, boolean grayscale, boolean monostyle, boolean cumulative);
791

  
792
	/**
793
	 * Creates a progression chart from the specified <code>Progression</code> result and writes it in the specified file.
794
	 * @param progression
795
	 * @param file
796
	 * @return
797
	 */
798
	public abstract File createProgressionChartFile(Progression progression, boolean grayscale, boolean monostyle, boolean cumulative, File file);
799

  
800

  
801
	/**
802
	 * Creates a progression chart from the specified <code>Progression</code> result and writes it in a temporary file in USER_TXM_HOME\results.
803
	 * The prefix and the suffix are computed according to the chart type and the current output format of the charts engine.
804
	 * @param progression
805
	 * @param grayscale
806
	 * @param monostyle
807
	 * @param cumulative
808
	 * @return
809
	 */
810
	public File createProgressionChartFile(Progression progression, boolean grayscale, boolean monostyle, boolean cumulative)	{
811
		return this.createProgressionChartFile(progression, grayscale, monostyle, cumulative, this.createTmpFile(ChartsEngine.CHART_TYPE_PROGRESSION));
812
	}
813

  
814

  
815

  
816
	/**
817
	 * Creates a string title, shared by charts engine implementations, for the progression chart from the specified result.
818
	 * @param the progression result
819
	 * @param doCumulative
820
	 * @return the titles string
821
	 */
822
	public String createProgressionChartTitle(Progression progression, boolean doCumulative)	{
823

  
824
		String title = Messages.Progression_9 + " "; //$NON-NLS-1$
825

  
826
		// Put queries in title
827
		for(int i = 0; i < progression.getQueries().size(); i++) {
828
			title +=  progression.getQueries().get(i).getQueryString();
829
			if(i < progression.getQueries().size() - 1)	{
830
				title += ", "; //$NON-NLS-1$
831
			}
832
		}
833

  
834

  
835
		title += " " + Messages.Progression_10 + " " + progression.getCorpus().getName(); //$NON-NLS-1$ //$NON-NLS-2$
836

  
837
		if(!doCumulative)	{
838
			title += " " + Messages.Progression_11; //$NON-NLS-1$
839
		}
840

  
841

  
842
		// FIXME : is this useful ? I needed to create the setName() method for this.
843
		progression.setName(title);
844

  
845
		if (progression.getStructure() != null) {
846
			title += "\n(" + Messages.Progression_12 + progression.getStructure().getName();
847
			if (progression.getProperty() != null) {
848
				title += Messages.Progression_13 + progression.getProperty().getName();
849
				if (progression.getPropertyRegex() != null)	{
850
					title += Messages.Progression_14 + progression.getPropertyRegex();
851
				}
852
			}
853
			title += ")";
854
		}
855

  
856
		return title;
857
	}
858

  
859

  
860

  
861
	/**
862
	 * Creates a chart according to the specified result and current output format and writes it in the specified file.
863
	 * @param result
864
	 * @param file
865
	 * @return
866
	 */
867
//	public File createChartFile(Object result, File file)	{
868
//
869
//		// Partition dimensions
870
//		if(result instanceof Partition)	{
871
//			return this.createDimensionsPartitionChartFile((Partition)result, file);
872
//		}
873
//		// Specificities
874
//		else if(result instanceof SpecificitesResult)	{
875
//			// FIXME : need to get the rendering properties
876
//			return this.createSpecificitiesChartFile((SpecificitesResult)result, false, true, false, 2, false, file);
877
//		}
878
//		// CA factorial map
879
//		else if(result instanceof CA)	{
880
//			return this.createCAFactorialMapChartFile((CA) result, file);
881
//		}
882
//		// CA singular values bar plot
883
//		// FIXME : j'ai besoin de connaître le type du graphe ici vu que résultat stockée est une CA pour les singular values bar plot
884
//		// Ajouter un champ int graphType dans ChartEditorPart ??? FAIT : le champ a été ajouté dans le ItemSelectionRenderer mais donc uniquement dispo pour JFC
885
////		else if(result instanceof Integer && (Integer)result == ChartsEngine.CHART_TYPE_CA_SINGULAR_VALUES)	{
886
////			return this.createCASingularValuesBarChartFile(((CA) result, file);
887
////		}
888
//
889
//
890
//		return null;
891
//	}
892

  
893
	/**
894
	 * Creates a file form the specified chart object.
895
	 * @param chart
896
	 * @param file
897
	 * @return
898
	 */
899
	public abstract File createChartFile(Object chart, File file);
900
	
901
	
902
	/**
903
	 * Creates a chart according to the specified result and output format and writes it in the specified file.
904
	 * @param result
905
	 * @param file
906
	 * @param outputFormat
907
	 * @return
908
	 */
909
	public File createChartFile(Object result, File file, String outputFormat)	{
910
		// FIXME : bad ? Switch the current charts engine output format, export the chart, and then roll back the output format
911
		String oldOutputFormat = this.outputFormat;
912
		this.setOutputFormat(outputFormat);
913
		file = this.createChartFile(result, file);
914
		//this.setOutputFormat(oldOutputFormat);
915
		this.outputFormat = oldOutputFormat;
916
		return file;
917
	}
918

  
919

  
920
	
921
	/**
922
	 * Exports the chart to the specified file. Also crops the image according to the specified drawing area values.
923
	 * @param chart
924
	 * @param file
925
	 * @param outputFormat
926
	 * @param imageWidth
927
	 * @param imageHeight
928
	 * @param drawingAreaX
929
	 * @param drawingAreaY
930
	 * @param drawingAreaWidth
931
	 * @param drawingAreaHeight
932
	 * @return
933
	 */
934
	public abstract File exportChart(Object chart, File file, String outputFormat, int imageWidth, int imageHeight, int drawingAreaX, int drawingAreaY, int drawingAreaWidth, int drawingAreaHeight);
935

  
936

  
937
	/**
938
	 * Exports the chart to the specified file.
939
	 * @param chart
940
	 * @param file
941
	 * @param outputFormat
942
	 * @param imageWidth
943
	 * @param imageHeight
944
	 * @return
945
	 */
946
	public File exportChart(Object chart, File file, String outputFormat, int imageWidth, int imageHeight)	{
947
		return this.exportChart(chart, file, outputFormat, imageWidth, imageHeight, 0, 0, imageWidth, imageHeight);
948
	}
949

  
950

  
951
	/**
952
	 * @return the name
953
	 */
954
	public String getName() {
955
		return name;
956
	}
957

  
958
	/**
959
	 * @param name the name to set
960
	 */
961
	public void setName(String name) {
962
		this.name = name;
963
	}
964

  
965

  
966
//	/**
967
//	 * Gets the output format as integer.
968
//	 * @return the output format
969
//	 */
970
//	public int getOutputFormatAsInt() {
971
//		return outputFormat;
972
//	}
973

  
974
	/**
975
	 * Gets the current output format.
976
	 * @return
977
	 */
978
	public String getOutputFormat() {
979
		return this.outputFormat;
980
		//return getOutputFormatDefinition(this.outputFormat);
981
	}
982

  
983
	/**
984
	 * Returns the output display formats supported by the implementation.
985
	 * This method is intended to be used in the purpose of knowing all the possible display outputs offered by the charts engine implementation and dedicated to the UI visualization (ex. Java2D, iplots, etc.).
986
	 * @return
987
	 */
988
	public abstract ArrayList<String> getSupportedOutputDisplayFormats();
989

  
990
	/**
991
	 * Returns the output file formats supported by the implementation.
992
	 * This method is intended to be used in the purpose of knowing all the possible file outputs offered by the charts engine implementation.
993
	 * @return
994
	 */
995
	public abstract ArrayList<String> getSupportedOutputFileFormats();
996

  
997

  
998
//	/**
999
//	 * Sets the output format for the generated charts.
1000
//	 * @param outputFormat the output format to set
1001
//	 */
1002
//	public void setOutputFormat(int outputFormat) {
1003
//		this.outputFormat = outputFormat;
1004
//	}
1005

  
1006
	/**
1007
	 * Sets the output format for the generated charts.
1008
	 * @param outputFormat the output format to set
1009
	 */
1010
	public void setOutputFormat(String outputFormat) {
1011
		this.outputFormat = outputFormat;
1012
		//this.setOutputFormat(ChartsEngine.getOutputFormatDefinition(outputFormat));
1013
	}
1014

  
1015

  
1016

  
1017
	/**
1018
	 * Replaces all non allowed characters in file name to '_' and returns the cleaned file name.
1019
	 * @param fileName the file name to clean
1020
	 * @return the cleaned file name
1021
	 */
1022
	public static String cleanFileName(String fileName)	{
1023
		return fileName.replaceAll("[^a-zA-Z0-9\\._-]+", "_");
1024
	}
1025

  
1026

  
1027
//	/**
1028
//	 * Checks if the specified properties are defined and if not, initializes them with default values.
1029
//	 */
1030
//	public static void initDefaultProperties(Properties props)	{
1031
//		// Set Java/JFreeChart charts engine as default
1032
//		if(props.getProperty(PROP_CHARTS_ENGINE_NAME) == null || props.getProperty(PROP_CHARTS_ENGINE_NAME).length() == 0)	{
1033
//			props.setProperty(PROP_CHARTS_ENGINE_NAME, ___JFCChartsEngine.NAME);
1034
//		}
1035
//		// Set JFreeChart/Java2D as default charts engine display format
1036
//		if(props.getProperty(PROP_CHARTS_ENGINE_OUTPUT_FORMAT) == null || props.getProperty(PROP_CHARTS_ENGINE_OUTPUT_FORMAT).length() == 0)	{
1037
//			props.setProperty(PROP_CHARTS_ENGINE_OUTPUT_FORMAT, outputFormatDefinitions.get(___JFCChartsEngine.OUTPUT_FORMAT_JFC_JAVA2D));
1038
//		}
1039
//		// Default property for partition dimensions charts sorting
1040
////		if(props.get(ChartsEngine.PROP_PARTITION_DIMENSIONS_SORTED_BY_SIZE) == null)	{
1041
////			props.put(ChartsEngine.PROP_PARTITION_DIMENSIONS_SORTED_BY_SIZE, false);
1042
////		}
1043
////		// Display partition dimensions parts count in chart title
1044
////		if(props.get(ChartsEngine.PROP_PARTITION_DIMENSIONS_DISPLAY_PARTS_COUNT_IN_TITLE) == null)	{
1045
////			props.put(ChartsEngine.PROP_PARTITION_DIMENSIONS_DISPLAY_PARTS_COUNT_IN_TITLE, false);
1046
////		}
1047
//	}
1048

  
1049
//	/**
1050
//	 * Returns an output format definition as a string specified by its key.
1051
//	 * @param key
1052
//	 * @return
1053
//	 */
1054
//	public static String getOutputFormatDefinition(int key)	{
1055
//		return outputFormatDefinitions.get(key);
1056
//	}
1057
//
1058
//	/**
1059
//	 * Returns an output format definition as an integer specified by its string value if it exists otherwise -1.
1060
//	 * @param outputFormat
1061
//	 * @return
1062
//	 */
1063
//	public static int getOutputFormatDefinition(String outputFormat)	{
1064
//		int index = -1;
1065
//
1066
//		for (Map.Entry<Integer, String> e : outputFormatDefinitions.entrySet()) {
1067
//		    if(e.getValue().equals(outputFormat) || e.getValue().equals(outputFormat.toLowerCase()))	{
1068
//		    	index = e.getKey();
1069
//		    	break;
1070
//		    }
1071
//		}
1072
//
1073
//		return index;
1074
//	}
1075

  
1076
	/**
1077
	 * Auto-populate supported output file raster formats list from available system image writers.
1078
	 * @param supportedOutputFileFormats
1079
	 * @return
1080
	 */
1081
	// FIXME: this method is useful but can lead to a deadlock when call during the SWT initialization maybe because of a multi-thread problem
1082
	public static ArrayList<String> populateSupportedOutputRasterFileFormats(ArrayList<String> supportedOutputFileFormats)	{
1083
		String[] writerFormatNames = javax.imageio.ImageIO.getWriterFormatNames();
1084

  
1085
		for(int i = 0; i < writerFormatNames.length; i++) {
1086
//			int outputFormat = getOutputFormatDefinition(writerFormatNames[i]);
1087
//			if(outputFormat != -1 && !supportedOutputFileFormats.contains(writerFormatNames[i]) && !supportedOutputFileFormats.contains(writerFormatNames[i].toLowerCase()))	 {
1088
			if(!supportedOutputFileFormats.contains(writerFormatNames[i]) && !supportedOutputFileFormats.contains(writerFormatNames[i].toLowerCase()))	 {
1089
				supportedOutputFileFormats.add(writerFormatNames[i].toLowerCase());
1090
			}
1091
		}
1092
		return supportedOutputFileFormats;
1093
	}
1094

  
1095
	/**
1096
	 * Sets the CA factorial map rows visibility and refreshes the chart.
1097
	 * @param ca
1098
	 * @param visible
1099
	 */
1100
	public void updateChartCAFactorialMapSetRowsVisible(Object chart, CA ca, boolean visible)	{
1101
		ca.setShown(ca.isShowIndividuals(), visible);
1102
	}
1103

  
1104
	/**
1105
	 * Sets the CA factorial map columns visibility and refreshes the chart.
1106
	 * @param ca
1107
	 * @param visible
1108
	 */
1109
	public void updateChartCAFactorialMapSetColumnsVisible(Object chart, CA ca, boolean visible)	{
1110
		ca.setShown(visible, ca.isShowVariables());
1111
	}
1112

  
1113

  
1114
	/**
1115
	 * Sets the CA factorial map dimensions.
1116
	 * @param editorPart
1117
	 * @param dimension1
1118
	 * @param dimension2
1119
	 */
1120
	public void updateChartCAFactorialMapSetDimensions(Object chart, CA ca, int dimension1, int dimension2)	{
1121
		ca.setDimensions(dimension1, dimension2);
1122
	}
1123

  
1124
	/**
1125
	 * Highlights points in the CA factorial map chart according to the specified labels.
1126
	 * @param chart
1127
	 * @param rows
1128
	 * @param labels
1129
	 */
1130
	public abstract void updateChartCAFactorialMapHighlightPoints(Object chart, boolean rows, String[] labels);
1131

  
1132
	/**
1133
	 * Sets the items selection order on label.
1134
	 * @param chart
1135
	 * @param itemsSelectionOrder
1136
	 */
1137
	public abstract void updateChartCAFactorialMapSetLabelItemsSelectionOrder(Object chart, String[] rowLabels, String[] colLabels);
1138
	
1139
	/**
1140
	 * Gets the rows points currently selected in the CA factorial map chart.
1141
	 * @return
1142
	 */
1143
	public abstract ArrayList<String> getCAFactorialMapChartSelectedRowPoints(Object chart);
1144

  
1145
	/**
1146
	 * Gets the columns points currently selected in the CA factorial map chart.
1147
	 * @return
1148
	 */
1149
	public abstract ArrayList<String> getCAFactorialMapChartSelectedColumnPoints(Object chart);
1150
	
1151
	
1152
	/**
1153
	 * Gets the positions of the points currently selected in the Progression step chart.
1154
	 * @param chart
1155
	 * @return
1156
	 */
1157
	public abstract ArrayList<Integer> getProgressionChartSelectedPointPositions(Object chart);
1158
	
1159
	/**
1160
	 * Gets the numbers of item in series of the selected points.
1161
	 * @param chart
1162
	 * @return
1163
	 */
1164
	public abstract ArrayList<Integer> getProgressionChartSelectedPointNumbers(Object chart);
1165
	
1166
	
1167
	/**
1168
	 * Gets the positions of all the points in the Progression step chart. 
1169
	 * @param chart
1170
	 * @return
1171
	 */
1172
	public abstract ArrayList<Integer> getProgressionChartAllPointPositions(Object chart);
1173
	
1174
	/**
1175
	 * Gets the selected series indexes.
1176
	 * @param chart
1177
	 * @return
1178
	 */
1179
	public abstract ArrayList<Integer> getProgressionChartSelectedSeries(Object chart);
1180
	
1181
	/**
1182
	 * Gets the last selected series.
1183
	 * @param chart
1184
	 * @return
1185
	 */
1186
	public abstract int getProgressionChartLastSelectedSeries(Object chart);
1187

  
1188
	
1189
	@Override
1190
	public String toString() {
1191
		String str = this.name + " (description: " + this.description + ", output format: " + this.outputFormat;
1192
		
1193
		str += ", supported output display formats: " + this.getSupportedOutputDisplayFormats().toString().replaceAll("\\[|\\]", ""); //$NON-NLS-2$ //$NON-NLS-3$
1194
		str += ", supported output file formats: " + this.getSupportedOutputFileFormats().toString().replaceAll("\\[|\\]", ""); //$NON-NLS-2$ //$NON-NLS-3$
1195
		
1196
		str += ")";
1197
		
1198
		return str;
1199
	} 
1200
	
1201
	
1202
	
1203
}
0 1204

  
tmp/org.txm.chartsengine.core/src/org/txm/chartsengine/core/ChartCreator.java (revision 49)
1
package org.txm.chartsengine.core;
2

  
3
import java.io.File;
4

  
5

  
6
/**
7
 * Abstract base for chart creation in command plugins from a result data.
8
 * @author sjacquot
9
 *
10
 */
11
public abstract class ChartCreator {
12

  
13
	
14
	/**
15
	 * Basic commands constants for chart updating.
16
	 */
17
	public static final int SHOW_TITLE = 0, SHOW_LEGEND = 1; 
18
	
19
	
20
	/**
21
	 * The linked charts engine.
22
	 */
23
	protected ChartsEngine chartsEngine;
24
	
25
	/**
26
	 * The prefix that will be added to the generated file name.
27
	 */
28
	protected String fileNamePrefix;
29
	
30
	/**
31
	 * 
32
	 */
33
	public ChartCreator() {
34
	}
35

  
36
	
37
	/**
38
	 * Sets the linked charts engine.
39
	 * @param chartsEngine
40
	 */
41
	public void setChartsEngine(ChartsEngine chartsEngine)	{
42
		this.chartsEngine = chartsEngine;
43
	}
44
	
45
	
46
	
47
	
48
	/**
49
	 * Creates a chart object according to the specified result data and parameters.
50
	 * @param resultData
51
	 * @param params
52
	 * @return
53
	 */
54
	public abstract Object createChart(Object resultData, String preferencesNode);
55
	
56
	/**
57
	 * Creates a chart object according to the specified result data.
58
	 * @param resultData
59
	 * @return
60
	 */
61
	public Object createChart(Object resultData)	{
62
		return this.createChart(resultData, null);
63
	}
64
	
65
	
66
	/**
67
	 * Creates a chart file according to the specified result data and parameters.
68
	 * @param resultData
69
	 * @param file
70
	 * @param params
71
	 * @return
72
	 */
73
	public File createChartFile(Object resultData, File file, String preferencesNode)	{
74
		Object chart = this.createChart(resultData, preferencesNode);
75
		// Synchronizes the chart with the shared preferences as show title, show legend, rendering colors mode, etc. 
76
		this.updateChart(chart, resultData, preferencesNode);
77
		return this.chartsEngine.createChartFile(chart, file);
78
	}
79
	
80
	/**
81
	 * Creates a chart file according to the specified result data and parameters.
82
	 * @param resultData
83
	 * @param fileNamePrefix
84
	 * @param params
85
	 * @return
86
	 */
87
	public File createChartFile(Object resultData, String fileNamePrefix, String preferencesNode)	{
88
		return this.createChartFile(resultData, this.chartsEngine.createTmpFile(fileNamePrefix), preferencesNode);
89
	}
90
	
91

  
92
	/**
93
	 * Creates a chart file according to the specified result data.
94
	 * This method should be overridden in implementations to define a prefix file name.
95
	 * @param resultData
96
	 * @param params
97
	 * @return
98
	 */
99
	public File createChartFile(Object resultData, String preferencesNode) {
100
		return this.createChartFile(resultData, this.fileNamePrefix, preferencesNode);
101
	}
102

  
103
	/**
104
	 * Updates an existing chart.
105
	 * By default this method does nothing.
106
	 * Subclasses should override this method to update a chart without recreating one.
107
	 * This method is dedicated for example, to hide a title, to change a rendering style, etc.
108
	 * The <code>command</code> integers may be used to determine what to do in the overridden methods.
109
	 * @param chart
110
	 * @param resultData
111
	 * @param preferencesNode
112
	 */
113
	public void updateChart(Object chart, Object resultData, String preferencesNode)	{
114
		System.out.println("ChartCreator.updateChart(): not implemented. This method is intended to be overridden in subclasses."); //$NON-NLS-1$
115
	}
116
	
117
	/**
118
	 * Gets the type of the result data linked with this chart creator.
119
	 * @return
120
	 */
121
	public abstract Class getResultDataType();
122

  
123

  
124
	/**
125
	 * @param fileNamePrefix the fileNamePrefix to set
126
	 */
127
	public void setFileNamePrefix(String fileNamePrefix) {
128
		this.fileNamePrefix = fileNamePrefix;
129
	}
130
	
131
}
0 132

  
tmp/org.txm.chartsengine.core/src/org/txm/chartsengine/core/preferences/ChartsEnginePreferences.java (revision 49)
1
package org.txm.chartsengine.core.preferences;
2

  
3

  
4
import org.eclipse.core.runtime.preferences.DefaultScope;
5
import org.osgi.framework.FrameworkUtil;
6
import org.osgi.service.prefs.Preferences;
7
import org.txm.chartsengine.core.ChartsEngine;
8
import org.txm.tbx.preferences.TXMPreferences;
9

  
10
/**
11
 * Preferences initializer and manager.
12
 * 
13
 * @author sjacquot
14
 *
15
 */
16
public class ChartsEnginePreferences extends TXMPreferences {
17

  
18

  
19
	// auto populate the preference node qualifier from the current bundle id
20
	public static final String PREFERENCES_NODE = FrameworkUtil.getBundle(ChartsEnginePreferences.class).getSymbolicName();
21

  
22
	public static final String PREFERENCES_PREFIX = "charts_engine_"; //$NON-NLS-1$
23
	
24
	/**
25
	 * The name of the current charts engine.
26
	 */
27
	public final static String CURRENT_NAME = PREFERENCES_PREFIX +  "current_name"; //$NON-NLS-1$
28
	
29
	
30
	/**
31
	 * Constant for showing title or not in the charts.
32
	 */
33
	public final static String SHOW_TITLE = PREFERENCES_PREFIX +  "show_title"; //$NON-NLS-1$
34

  
35

  
36
	/**
37
	 * Constant for showing legend or not in the charts.
38
	 */
39
	public final static String SHOW_LEGEND = PREFERENCES_PREFIX +  "show_legend"; //$NON-NLS-1$
40

  
41

  
42
	/**
43
	 * Constant for showing grid/lines or not in the charts.
44
	 */
45
	public final static String SHOW_GRID = PREFERENCES_PREFIX +  "show_grid"; //$NON-NLS-1$
46

  
47
	
48
	/**
49
	 * Constant for the color mode (colors, grayscale, monochrome).
50
	 */
51
	public final static String RENDERING_COLORS_MODE = PREFERENCES_PREFIX +  "colors_mode"; //$NON-NLS-1$
52
	
53
	
54
	
55
	
56
	// local result preferences
57
	public final static String CHART_TYPE = PREFERENCES_PREFIX +  "chart_type"; //$NON-NLS-1$
58
	public final static String RESULT_DATA_TYPE = PREFERENCES_PREFIX +  "result_data_type"; //$NON-NLS-1$
59
	
60
	
61
	/**
62
	 * 
63
	 */
64
	public ChartsEnginePreferences() {
65
		// TODO Auto-generated constructor stub
66
	}
67

  
68
	@Override
69
	public void initializeDefaultPreferences() {
70
		Preferences defaultPreferences = DefaultScope.INSTANCE.getNode(PREFERENCES_NODE);
71
		
72
		defaultPreferences.put(CURRENT_NAME, "jfreechart_charts_engine");
73
		
74
		defaultPreferences.putBoolean(SHOW_TITLE, true);
75
		defaultPreferences.putBoolean(SHOW_LEGEND, true);
76
		defaultPreferences.putBoolean(SHOW_GRID, true);
77
		
78
		defaultPreferences.putInt(RENDERING_COLORS_MODE, ChartsEngine.RENDERING_COLORS_MODE);
79
		
80
	}
81
	
82
}
83

  
0 84

  
tmp/org.txm.chartsengine.core/build.properties (revision 49)
1
source.. = src/
2
output.. = bin/
3
bin.includes = META-INF/,\
4
               .,\
5
               plugin.xml
0 6

  
tmp/org.txm.chartsengine.core/plugin.xml (revision 49)
1
<?xml version="1.0" encoding="UTF-8"?>
2
<?eclipse version="3.4"?>
3
<plugin>
4
   <extension-point id="org.txm.chartsengine.chartsengine" name="Charts Engine" schema="schema/org.txm.chartsengine.chartsengine.exsd"/>
5
   <extension-point id="org.txm.chartsengine.chartcreator" name="Chart Creator" schema="schema/org.txm.chartsengine.chartcreator.exsd"/>
6
   <extension
7
         point="org.eclipse.core.runtime.preferences">
8
      <initializer
9
            class="org.txm.chartsengine.core.preferences.ChartsEnginePreferences">
10
      </initializer>
11
   </extension>
12

  
13
</plugin>
0 14

  
tmp/org.txm.chartsengine.core/.settings/org.eclipse.jdt.core.prefs (revision 49)
1
eclipse.preferences.version=1
2
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
4
org.eclipse.jdt.core.compiler.compliance=1.6
5
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
6
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff