Revision 578

tmp/org.txm.chartsengine.rcp/src/org/txm/chartsengine/rcp/swt/AdvancedChartEditorToolBar.java (revision 578)
173 173
			for(int i = 0; i < chartCreators.size(); i++) {
174 174
				chartTypes[i] = chartCreators.get(i).getChartType();
175 175
				if(chartTypes[i] == null)	{
176
					chartTypes[i] = this.chartEditorPart.getResultData().getClass().getName();
176
					chartTypes[i] = ChartsEnginePreferences.DEFAULT_CHART_TYPE;
177 177
				}
178 178
				if(this.getEditorPart().getChartType() != null && this.getEditorPart().getChartType().equals(chartTypes[i])) {
179 179
					currentChartTypeIndex = i;
tmp/org.txm.chartsengine.core/src/org/txm/chartsengine/core/ChartsEngine.java (revision 578)
169 169
	 * @param chartCreator
170 170
	 * @param chartType
171 171
	 */
172
	public void addChartCreator(Class resultDataType, ChartCreator chartCreator, String chartType)	{
172
	public void addChartCreator(Class resultDataType, ChartCreator chartCreator)	{
173 173
		
174
		
175
		String chartType = chartCreator.getChartType();
176
		if(chartType == null)	{
177
			chartType = ChartsEnginePreferences.DEFAULT_CHART_TYPE;
178
		}
179
		
174 180
		if(!this.chartCreators.containsKey(resultDataType))	{
175 181
			HashMap<String, ChartCreator> m = new HashMap<String, ChartCreator>();
176 182
			m.put(chartType, chartCreator);
......
314 320
				if(chartsEngineClass.equals(chartCreator.getChartsEngineClass()))	{
315 321
					chartCreator.setFileNamePrefix(contributions[i].getAttribute("fileNamePrefix")); //$NON-NLS-1$
316 322
					chartCreator.setChartType(contributions[i].getAttribute("chartType")); //$NON-NLS-1$
317
					this.addChartCreator(chartCreator.getResultDataClass(), chartCreator, contributions[i].getAttribute("chartType")); //$NON-NLS-1$
323
					this.addChartCreator(chartCreator.getResultDataClass(), chartCreator); //$NON-NLS-1$
318 324
				}
319 325
			}
320 326
			catch(CoreException e) {
tmp/org.txm.chartsengine.core/src/org/txm/chartsengine/core/preferences/ChartsEnginePreferences.java (revision 578)
77 77
	 */
78 78
	public final static String DEFAULT_FONT = "1|Lucida Sans Unicode|11.0|0|WINDOWS|1|-16|0|0|0|400|0|0|0|0|3|2|1|34|Lucida Sans Unicode;"; //$NON-NLS-1$  
79 79
	
80
	public final static String DEFAULT_CHART_TYPE = "[Default]"; //$NON-NLS-1$
81
	
80 82

  
81 83
	@Override
82 84
	public void initializeDefaultPreferences() {
......
101 103
		preferences.putInt(RENDERING_COLORS_MODE, ChartsEngine.RENDERING_COLORS_MODE);
102 104
		preferences.put(MONOCHROME_COLOR, "0,220,20"); //$NON-NLS-1$
103 105

  
106
		preferences.put(CHART_TYPE, DEFAULT_CHART_TYPE);
107
		
104 108
		// FIXME: maybe need need to check here the target OS and set a default Unicode installed font
105 109
		preferences.put(FONT, DEFAULT_FONT);
106 110
		
tmp/org.txm.chartsengine.core/src/org/txm/chartsengine/core/results/ChartResult.java (revision 578)
31 31
	protected Object chart;
32 32
	
33 33
	/**
34
	 * The chart type;
35
	 */
36
	protected String chartType;
37
	
38
	/**
39 34
	 * The chart dirty state.
40 35
	 */
41 36
	protected boolean chartDirty;
......
58 53

  
59 54
	
60 55
	
56

  
57
	/**
58
	 * The chart type;
59
	 */
60
	@Parameter(key=ChartsEnginePreferences.CHART_TYPE, type=Parameter.RENDERING)
61
	protected String chartType;
61 62
	
62 63
	
63 64
	/**
......
125 126
		this.gridVisible = this.getBooleanParameterValue(ChartsEnginePreferences.SHOW_GRID);
126 127
		this.renderingColorsMode = this.getIntParameterValue(ChartsEnginePreferences.RENDERING_COLORS_MODE);
127 128
		this.font = this.getStringParameterValue(ChartsEnginePreferences.FONT);
129
		this.chartType = this.getStringParameterValue(ChartsEnginePreferences.CHART_TYPE);
128 130
		return true;
129 131
	}
130 132
	
......
136 138
	 * @return
137 139
	 */
138 140
	public boolean hasRenderingParameterChanged(String key) {
139
		if ("".equals(key)) {
141
		if (key.isEmpty()) {
140 142
			return false;
141 143
		}
142 144
		Object lastValue = this.lastRenderingParameters.get(key);
143 145
		Object newValue = this.getRenderingParameter(key);
144
		if (lastValue == null && newValue != null) {
145
			return true;
146
		if (lastValue == null) {
147
			if(newValue != null)	{
148
				return true;
149
			}
150
			else	{
151
				return false;
152
			}
146 153
		}
147 154
		else {
148 155
			return !lastValue.equals(newValue);
......
180 187
		this.subTask("Rendering chart.");
181 188

  
182 189
		// FIXME: Debug
183
		System.err.println("ChartResult.renderChart(): rendering chart of type " + this.getClass() + "...");
190
		System.err.println("ChartResult.renderChart(): rendering chart for result " + this.getClass() + " and chart type " + this.getChartType() + "...");
184 191

  
185 192
		
186 193
		if (!this.isChartDirtyFromHistory()) {
......
201 208
		ChartCreator chartCreator = ChartsEngine.getCurrent().getChartCreator(this);
202 209
		if(chartCreator != null)	{
203 210
			
204
			if(update)	{
211

  
212
			// Creating, if needed
213
			if(this.hasRenderingParameterChanged(ChartsEnginePreferences.CHART_TYPE))	{
205 214
				// FIXME: debug
206
				System.err.println("ChartResult.renderChart(): updating chart.");
207
				
208
				chartCreator.updateChart(this);
209
			}
210
			else	{
211
				
212
				// FIXME: debug
213 215
				System.err.println("ChartResult.renderChart(): creating chart.");
214 216
				
215 217
				this.chart = chartCreator.createChart(this);
216

  
217
				// FIXME: debug
218
				System.err.println("ChartResult.renderChart(): updating chart.");
219
				
220
				// FIXME: the update must be done here (BEFORE the call of this.updateLastRenderingParameters()) rather than in the SWTChartComponentsProvider => the problem is that for File based Engine, the file may be created twice, need to check this
221
				chartCreator.updateChart(this);
222 218
			}
223 219
			
220
			// Updating
221
			// FIXME: debug
222
			System.err.println("ChartResult.renderChart(): updating chart.");
223
			
224
			// FIXME: the update must be done here (BEFORE the call of this.updateLastRenderingParameters()) rather than in the SWTChartComponentsProvider => the problem is that for File based Engine, the file may be created twice, need to check this
225
			chartCreator.updateChart(this);
226
			
224 227
			this.updateLastRenderingParameters();
225 228
			
226 229
			
......
235 238
	}
236 239
	
237 240
	
241
	@Override
242
	public String dumpParameters() {
243
		return super.dumpParameters() + "\n" + this.dumpParameters(Parameter.RENDERING);
244
	}
245
	
238 246
	/**
239 247
	 * Updates the parameters used for last rendering.
240 248
	 * Loop through all inherited fields/parameters except those of the TXMResult class.
......
336 344
	 * @param newValue may be null
337 345
	 */
338 346
	protected void updateChartDirty(Object lastValue, Object newValue) {
347
		if(lastValue == null && newValue == null)	{
348
			return;
349
		}
339 350
		if (lastValue == null || !lastValue.equals(newValue)) {
340 351
			Log.info("Setting chart dirty to true: old = "+ lastValue + " / new = " + newValue);
341 352
			this.chartDirty = true;
......
377 388
	 * @param chartType the chartType to set
378 389
	 */
379 390
	public void setChartType(String chartType) {
380
		// set to null to match the way that the chart engine returns the creator
381
		if(chartType.equals(this.getClass().getName()))	{
382
			chartType = null;
383
		}
384 391
		this.chartType = chartType;
385 392
	}
386 393

  
tmp/org.txm.lexicaltable.core/src/org/txm/lexicaltable/core/functions/LexicalTable.java (revision 578)
578 578
	}
579 579

  
580 580
	public void setParameters(Property prop, Integer fmin, Integer vmax, Boolean useAllOccurrences) {
581
		if (prop != null) this.pProperty = prop;
582
		if (fmin != null) this.pfMinFilter = fmin;
583
		if (vmax != null) this.pVMaxFilter = vmax;
584
		if (useAllOccurrences != null) this.pUseAllOccurrences = useAllOccurrences;
585

  
581
		if (prop != null) {
582
			this.pProperty = prop;
583
		}
584
		if (fmin != null) {
585
			this.pfMinFilter = fmin;
586
		}
587
		if (vmax != null) {
588
			this.pVMaxFilter = vmax;
589
		}
590
		if (useAllOccurrences != null) {
591
			this.pUseAllOccurrences = useAllOccurrences;
592
		}
586 593
		this.dirty = true;
587 594
	}
588 595

  
tmp/org.txm.rcp/src/main/java/org/txm/rcp/views/cmdparameters/ParametersView.java (revision 578)
70 70
	 * Refresh.
71 71
	 */
72 72
	public static void refresh() {
73

  
73
		
74 74
	}
75 75

  
76 76
	EditorPart desactivated, activated, broughtToTop, closed, opened;
......
92 92

  
93 93

  
94 94
			try {
95
				// Preferences
95 96
				String[] keys = result.getParametersKeys();
96
				buffer.append("Parameters ("+keys.length+"): \n");
97
				for (String key : keys)
98
					buffer.append(" - "+key+"="+result.getStringParameterValue(key)+"\n");
99
			} catch(Exception e) {
97
				buffer.append("Command preferences (" + keys.length + "): \n");
98
				for (String key : keys) {
99
					buffer.append(key + "=" + result.getStringParameterValue(key) + "\n");
100
				}
101
				buffer.append("\n");
102
				
103
				// Parameters
104
				buffer.append(result.dumpParameters());
105
				
106
				
107
			}
108
			catch(Exception e) {
100 109
				System.out.println("Error: "+e.getLocalizedMessage());
101 110
			}
111
			
112
			
102 113
			currentEditorLabel.setText(buffer.toString());
103 114
		} else {
104 115
			currentEditorLabel.setText("Editor is not a TXMPartEditor: "+editor);
tmp/org.txm.rcp/src/main/java/org/txm/rcp/views/corpora/CorporaView.java (revision 578)
239 239
				System.out.println("CorporaView.createPartControl(...).new SelectionListener() {...}.widgetSelected(): ********************************************************************************");
240 240
				System.err.println("CorporaView.createPartControl(...).new SelectionListener() {...}.widgetSelected(): selected object = " + selectedItem + ", visible = " + ((TXMResult)selectedItem).isVisible());
241 241
				if (selectedItem instanceof ChartResult) 	{
242
					System.err.println("CorporaView.createPartControl(...).new SelectionListener() {...}.widgetSelected(): chart object = " + ((ChartResult)selectedItem).getChart());
242
					System.err.println("CorporaView.createPartControl(...).new SelectionListener() {...}.widgetSelected(): chart object = " + ((ChartResult)selectedItem).getChart() + ", chart type = " + ((ChartResult)selectedItem).getChartType());
243 243
				}
244 244
				System.err.println("CorporaView.createPartControl(...).new SelectionListener() {...}.widgetSelected(): selection full path name = " + ((TXMResult)selectedItem).getFullPathSimpleName() + " - " + ((TXMResult)selectedItem).getName());
245 245
				System.err.println("CorporaView.createPartControl(...).new SelectionListener() {...}.widgetSelected(): direct children count = " + ((TXMResult)selectedItem).getResults().size()
tmp/org.txm.partition.core/src/org/txm/partition/core/chartsengine/jfreechart/JFCPartitionDimensionsBarChartCreator.java (revision 578)
11 11
import org.jfree.data.xy.XYSeries;
12 12
import org.jfree.data.xy.XYSeriesCollection;
13 13
import org.txm.chartsengine.core.ChartsEngine;
14
import org.txm.chartsengine.core.preferences.ChartsEnginePreferences;
14 15
import org.txm.chartsengine.core.results.ChartResult;
15 16
import org.txm.chartsengine.jfreechart.core.JFCChartCreator;
16 17
import org.txm.chartsengine.jfreechart.core.renderers.interfaces.IRendererWithItemSelection;
......
36 37

  
37 38
		JFreeChart chart = null;
38 39

  
39
		// Creating the data set from the partition result
40
		// Creating an empty data set
40 41
		XYSeriesCollection dataset = new XYSeriesCollection();
41 42

  
42 43
		// Create the chart
......
65 66
		boolean displayPartsCountInTitle = partitionDimensions.isDisplayingPartCountInTitle();
66 67
		
67 68
		
68
		if(result.hasRenderingParameterChanged(PartitionDimensionsPreferences.CHART_DIMENSIONS_SORT_BY_SIZE))	{
69
			// Fill the data set
69
		if(result.hasRenderingParameterChanged(ChartsEnginePreferences.CHART_TYPE)
70
				|| result.hasRenderingParameterChanged(PartitionDimensionsPreferences.CHART_DIMENSIONS_SORT_BY_SIZE))	{
71
			
72
			// Fill the data set from the result
70 73
			XYSeriesCollection dataset = (XYSeriesCollection) chart.getXYPlot().getDataset();
71 74
			dataset.removeAllSeries();
72 75
			
......
94 97
		}
95 98
		
96 99
		
97
		
98
		
99
		
100 100
		// Create chart title
101 101
		chart.setTitle(Utils.createPartitionDimensionsChartTitle(partitionDimensions, sortPartsBySize, displayPartsCountInTitle));
102 102
		
tmp/org.txm.partition.core/src/org/txm/partition/core/chartsengine/jfreechart/JFCPartitionDimensionsPieChartCreator.java (revision 578)
1 1
package org.txm.partition.core.chartsengine.jfreechart;
2
import java.awt.Color;
2 3
import java.util.List;
3 4

  
4 5
import org.jfree.chart.JFreeChart;
6
import org.jfree.chart.plot.PiePlot;
7
import org.jfree.chart.title.TextTitle;
8
import org.jfree.chart.title.Title;
5 9
import org.jfree.data.general.DefaultPieDataset;
10
import org.jfree.util.SortOrder;
11
import org.txm.chartsengine.core.preferences.ChartsEnginePreferences;
6 12
import org.txm.chartsengine.core.results.ChartResult;
7 13
import org.txm.chartsengine.jfreechart.core.JFCChartCreator;
8 14
import org.txm.partition.core.chartsengine.base.Utils;
9 15
import org.txm.partition.core.functions.PartitionDimensions;
16
import org.txm.partition.core.preferences.PartitionDimensionsPreferences;
10 17
import org.txm.searchengine.cqp.clientExceptions.CqiClientException;
11 18
import org.txm.searchengine.cqp.corpus.Part;
12 19

  
......
22 29
	@Override
23 30
	public Object createChart(ChartResult result) {
24 31
		
32
		JFreeChart chart = null;
33

  
34
		// Creating an empty data set
35
		DefaultPieDataset dataset = new DefaultPieDataset();
36

  
37
		// Create the chart
38
		chart = this.getChartsEngine().createPieChart(dataset, null, true);
39
		
40
		return chart;
41
	}
42

  
43
	
44
	@Override
45
	public void updateChart(ChartResult result) {
46

  
25 47
		PartitionDimensions partitionDimensions = (PartitionDimensions) result;
48
		JFreeChart chart = (JFreeChart) result.getChart();
49

  
26 50
		
51
		// freeze rendering while computing
52
		chart.setNotify(false);
53
		
54
		
27 55
		// parameters
28 56
		boolean sortPartsBySize = partitionDimensions.isSortingBySize();
29 57
		boolean displayPartsCountInTitle = partitionDimensions.isDisplayingPartCountInTitle();
30 58

  
31
		
32
		JFreeChart chart = null;
33
		
34
		try {
35
			// Creating the data set from the partition result
36
			DefaultPieDataset dataset = new DefaultPieDataset();
37 59

  
38
			List<Part> parts = partitionDimensions.getParts(sortPartsBySize);
39

  
40
			for (int i = 0 ; i < parts.size() ; i++) {
41
				dataset.setValue(parts.get(i).getName(), parts.get(i).getSize());
60
		if(result.hasRenderingParameterChanged(ChartsEnginePreferences.CHART_TYPE)
61
				|| result.hasRenderingParameterChanged(PartitionDimensionsPreferences.CHART_DIMENSIONS_SORT_BY_SIZE))	{
62
			
63
			// Fill the data set from the result
64
			DefaultPieDataset dataset = (DefaultPieDataset)((PiePlot) chart.getPlot()).getDataset();
65
			dataset.clear();
66
			
67
			try {
68
	
69
				List<Part> parts = partitionDimensions.getParts(sortPartsBySize);
70
	
71
				for (int i = 0 ; i < parts.size() ; i++) {
72
					dataset.setValue(parts.get(i).getName(), parts.get(i).getSize());
73
				}
74
	
75
				if(sortPartsBySize)	{
76
					dataset.sortByValues(SortOrder.ASCENDING);
77
				}
78
				else	{
79
					dataset.sortByKeys(SortOrder.ASCENDING);
80
				}
42 81
			}
82
			catch(CqiClientException e) {
83
				e.printStackTrace();
84
			}
85
		}
43 86

  
44
			// Create chart title
45
			String title = Utils.createPartitionDimensionsChartTitle(partitionDimensions, sortPartsBySize, displayPartsCountInTitle);
87
		// Create chart title
88
		chart.setTitle(Utils.createPartitionDimensionsChartTitle(partitionDimensions, sortPartsBySize, displayPartsCountInTitle));
46 89

  
47
			// Create the chart
48
	        chart = this.getChartsEngine().createPieChart(dataset, title, true);
49
	        //((IItemSelectionRenderer) chart.getXYPlot().getRenderer()).setChartType(___ChartsEngine.CHART_TYPE_PARTITION_DIMENSIONS);
90
		super.updateChart(result);
91
		
92
		
93
		// Subtitle
94
		if(chart.getSubtitleCount() > 0)	{
95
			chart.removeSubtitle(chart.getSubtitle(0));	
96
		}
97
		chart.addSubtitle(new TextTitle(Utils.createPartitionDimensionsChartSubtitle(partitionDimensions, sortPartsBySize, displayPartsCountInTitle), this.getChartsEngine().getJFCTheme().getSmallFont(),
98
				((Color)this.getChartsEngine().getJFCTheme().getAxisLabelPaint()), Title.DEFAULT_POSITION,
99
                Title.DEFAULT_HORIZONTAL_ALIGNMENT,
100
                Title.DEFAULT_VERTICAL_ALIGNMENT, Title.DEFAULT_PADDING));
50 101

  
51

  
52
	        this.getChartsEngine().getJFCTheme().apply(chart);
53

  
54
		}
55
		catch(CqiClientException e) {
56
			e.printStackTrace();
57
		}
58 102
		
59
		
60
		return chart;
61 103
	}
62

  
104
	
63 105
	@Override
64 106
	public Class getResultDataClass() {
65 107
		return PartitionDimensions.class;
tmp/org.txm.core/src/java/org/txm/core/results/TXMResult.java (revision 578)
6 6
import java.text.DateFormat;
7 7
import java.text.SimpleDateFormat;
8 8
import java.util.ArrayList;
9
import java.util.Arrays;
9 10
import java.util.Date;
10 11
import java.util.HashMap;
11 12
import java.util.List;
......
230 231
	}
231 232

  
232 233
	
234
	
235
	
236
	public String dumpParameters()	{
237
		return this.dumpParameters(Parameter.COMPUTING);
238
	}
239
	
240
	
241
	public String dumpParameters(int parametersType)	{
242
		
243
		StringBuilder str = new StringBuilder();
244
		
245
		str.append("Parameters (type = " + parametersType + ")\n");
246
		
247
		List<Field> fields = new ArrayList<Field>();
248
		Class<?> clazz = this.getClass();
249
		while (clazz != Object.class) {
250
			fields.addAll(Arrays.asList(clazz.getDeclaredFields()));
251
			clazz = clazz.getSuperclass();
252
		}
233 253

  
254
		for (Field f : fields) {
255
			Parameter parameter = f.getAnnotation(Parameter.class);
256
			if (parameter == null || parameter.type() != parametersType) {
257
				continue;
258
			}
259
			f.setAccessible(true);
260
			
261
			String name;
262
			if(!parameter.key().isEmpty())	{
263
				name = parameter.key();
264
			}
265
			else	{
266
				name = f.getName();
267
			}
268

  
269
			try {
270
				str.append(name + " = " + f.get(this) + "\n");
271
			}
272
			catch (IllegalArgumentException e) {
273
				// TODO Auto-generated catch block
274
				e.printStackTrace();
275
			}
276
			catch (IllegalAccessException e) {
277
				// TODO Auto-generated catch block
278
				e.printStackTrace();
279
			}
280
		}
281
		return str.toString();
282
	}
283
	
284

  
234 285
	/**
235 286
	 * Updates the dirty state by comparing an old parameter with a new one.
236 287
	 * 
......
238 289
	 * @param newValue may be null
239 290
	 */
240 291
	protected void updateDirty(Object lastValue, Object newValue) {
292
		if(lastValue == null && newValue == null)	{
293
			return;
294
		}
241 295
		if (lastValue == null || !lastValue.equals(newValue)) {
242 296
			Log.info("Setting dirty to true: old = "+ lastValue + " / new = " + newValue);
243 297
			this.setDirty();
......
279 333
			f.setAccessible(true); // not to set accessible to test the field values
280 334
			Object previousValue = this.lastComputingParameters.get(name);
281 335
			Object newValue = f.get(this);
282
			updateDirty(previousValue, newValue);
336
			
337
			// FIXME: debug
338
			//System.err.println("TXMResult.isDirtyFromHistory(): checking parameter: " + name);
339
			
340
			this.updateDirty(previousValue, newValue);
283 341
			if (this.dirty) {
284 342
				return this.dirty; // no need to go further
285 343
			}

Also available in: Unified diff