Révision 2531

tmp/org.txm.progression.core/src/org/txm/progression/core/functions/Progression.java (revision 2531)
80 80
	public static final String DENSITY_CHART_TYPE = "density"; //$NON-NLS-1$
81 81
	
82 82
	/** The Xmin corpus. */
83
	protected int XminCorpus;
83
	protected int xMinCorpus;
84 84
	
85 85
	/** The Xmax corpus. */
86
	protected int XmaxCorpus;
86
	protected int xMaxCorpus;
87 87
	
88 88
	/** The writer. */
89 89
	private BufferedWriter writer;
......
97 97
	/** The structurenames. */
98 98
	protected String[] structureNames;
99 99
	
100
	/** graph boundaries. */
100
	/** chart boundaries. */
101 101
	protected int maxY;
102 102
	
103 103
	/** The max x. */
......
400 400
	public boolean stepQueries(List<QueryResult> queryResults) throws CqiClientException {
401 401
		if (queryResults.size() != queries.size()) return false;
402 402
		
403
		maxX = getCorpus().getSize();
403
		this.maxX = this.getCorpus().getSize();
404 404
		int npositions = 0;
405 405
		for (int iQuery = 0; iQuery < queries.size(); iQuery++) {
406 406
			QueryResult result = queryResults.get(iQuery);
407 407
			
408 408
			int nLines = result.getNMatch();
409
			if (maxY < nLines) {
410
				maxY = nLines;
409
			if (this.maxY < nLines) {
410
				this.maxY = nLines;
411 411
			}
412 412
			
413 413
			List<Match> matches = null;
......
421 421
			int[] positions = new int[matches.size()];
422 422
			// System.out.println("nb positions "+matches.size());
423 423
			// if (matches.size() > 0)
424
			allPositions.add(positions);
424
			this.allPositions.add(positions);
425 425
			int i = 0;
426 426
			for (Match m : matches) {
427 427
				positions[i++] = m.getStart();
......
437 437
	 * @throws CqiClientException the cqi client exception
438 438
	 */
439 439
	public boolean stepQueries() throws CqiClientException {
440
		maxX = getCorpus().getSize();
440
		this.maxX = this.getCorpus().getSize();
441 441
		int npositions = 0;
442 442
		
443 443
		for (int iQuery = 0; iQuery < queries.size(); iQuery++) {
......
570 570
	 * @throws CqiClientException the cqi client exception
571 571
	 */
572 572
	public boolean stepFinalize() throws CqiClientException {
573
		if (getCorpus() instanceof Subcorpus) {
573
		if (this.getCorpus() instanceof Subcorpus) {
574 574
			List<Match> matches = ((Subcorpus) getCorpus()).getMatches();
575 575
			if (matches.size() == 0) {
576 576
				System.out.println(ProgressionCoreMessages.errorColonSubcorpusWithSize0);
577 577
				return false;
578 578
			}
579 579
			
580
			XminCorpus = matches.get(0).getStart();
581
			XmaxCorpus = matches.get(matches.size() - 1).getEnd();
580
			xMinCorpus = matches.get(0).getStart();
581
			xMaxCorpus = matches.get(matches.size() - 1).getEnd();
582 582
		}
583 583
		else {
584
			XminCorpus = 0;
585
			XmaxCorpus = getCorpus().getSize();
584
			xMinCorpus = 0;
585
			xMaxCorpus = getCorpus().getSize();
586 586
		}
587 587
		// System.out.println("min: "+XminCorpus+ "max: "+XmaxCorpus);
588 588
		
589 589
		if (bande <= 0) {
590
			bande = ((XmaxCorpus - XminCorpus) / 100) * bandeMultiplier;
590
			bande = ((xMaxCorpus - xMinCorpus) / 100) * bandeMultiplier;
591 591
			if (bande == 0) {
592 592
				bande = 1.0f;
593 593
			}
......
746 746
	 * @return the xminCorpus
747 747
	 */
748 748
	public int getXminCorpus() {
749
		return XminCorpus;
749
		return xMinCorpus;
750 750
	}
751 751
	
752 752
	/**
753 753
	 * @return the xmaxCorpus
754 754
	 */
755 755
	public int getXmaxCorpus() {
756
		return XmaxCorpus;
756
		return xMaxCorpus;
757 757
	}
758 758
	
759 759
	
tmp/org.txm.progression.core/src/org/txm/progression/core/chartsengine/base/Utils.java (revision 2531)
6 6

  
7 7
/**
8 8
 * Progression chart utility class.
9
 * 
9 10
 * @author sjacquot
10 11
 *
11 12
 */
12 13
public abstract class Utils {
13

  
14
	
14 15
	public Utils() {
15 16
		// TODO Auto-generated constructor stub
16 17
	}
17

  
18

  
18
	
19
	
19 20
	/**
20 21
	 * Creates a string title, shared by charts engine implementations, for the progression chart from the specified result.
22
	 * 
21 23
	 * @param the progression result
22 24
	 * @param doCumulative
23 25
	 * @return the titles string
24 26
	 */
25
	public static String createProgressionChartTitle(Progression progression, boolean doCumulative)	{
26

  
27
	public static String createProgressionChartTitle(Progression progression, boolean doCumulative) {
28
		
27 29
		String title = ProgressionCoreMessages.progressionOf;
28

  
30
		
29 31
		// Put queries in title
30
		for(int i = 0; i < progression.getQueries().size(); i++) {
31
			title +=  progression.getQueries().get(i).getQueryString();
32
			if(i < progression.getQueries().size() - 1)	{
32
		for (int i = 0; i < progression.getQueries().size(); i++) {
33
			title += progression.getQueries().get(i).getQueryString();
34
			if (i < progression.getQueries().size() - 1) {
33 35
				title += ", "; //$NON-NLS-1$
34 36
			}
35 37
		}
36

  
37

  
38
		title += " " + NLS.bind(ProgressionCoreMessages.inP0, progression.getCorpus().getName());
39

  
40
		if(!doCumulative)	{
38
		
39
		
40
		title += " " + NLS.bind(ProgressionCoreMessages.inP0, progression.getCorpus().getName()); //$NON-NLS-1$
41
		
42
		if (!doCumulative) {
41 43
			title += " " + ProgressionCoreMessages.density; //$NON-NLS-1$
42 44
		}
43

  
45
		
44 46
		if (progression.getStructuralUnit() != null) {
45
			title += "\n(" + ProgressionCoreMessages.structureColon + progression.getStructuralUnit().getName();
47
			title += "\n(" + ProgressionCoreMessages.structureColon + progression.getStructuralUnit().getName(); //$NON-NLS-1$
46 48
			if (progression.getStructuralUnitProperty() != null) {
47 49
				title += ProgressionCoreMessages.propertyColon + progression.getStructuralUnitProperty().getName();
48
				if (progression.getPropertyRegex() != null)	{
50
				if (progression.getPropertyRegex() != null) {
49 51
					title += ProgressionCoreMessages.filteringREGEXColon + progression.getPropertyRegex();
50 52
				}
51 53
			}
52
			title += ")";
54
			title += ")"; //$NON-NLS-1$
53 55
		}
54

  
56
		
55 57
		return title;
56 58
	}
57 59
	
58

  
59
}
60
	
61
}
tmp/org.txm.progression.core/src/org/txm/progression/core/chartsengine/jfreechart/JFCProgressionCumulativeChartCreator.java (revision 2531)
25 25
import org.txm.progression.core.functions.Progression;
26 26
import org.txm.progression.core.messages.ProgressionCoreMessages;
27 27
import org.txm.progression.core.preferences.ProgressionPreferences;
28
import org.txm.searchengine.cqp.clientExceptions.CqiClientException;
28 29
import org.txm.searchengine.cqp.corpus.query.CQLQuery;
29 30

  
30 31
/**
......
34 35
 *
35 36
 */
36 37
public class JFCProgressionCumulativeChartCreator extends JFCChartCreator implements ProgressionChartCreator {
37

  
38

  
38
	
39
	
39 40
	@Override
40 41
	public JFreeChart createChart(ChartResult result) {
41

  
42 42
		
43
		
43 44
		Progression progression = (Progression) result;
44 45
		
45 46
		// parameters
......
47 48
		
48 49
		
49 50
		JFreeChart chart = null;
50

  
51
		
51 52
		// Creates the empty dataset
52 53
		XYSeriesCollection dataset = new XYSeriesCollection();
53 54
		// Y axis label
54 55
		String yAxisLabel;
55

  
56 56
		
57
		
57 58
		// Cumulative
58
		if(cumulative)	{
59

  
59
		if (cumulative) {
60
			
60 61
			// Create the chart
61 62
			yAxisLabel = ProgressionCoreMessages.occurrences;
62
			chart = this.getChartsEngine().createXYStepChart(dataset, Utils.createProgressionChartTitle(progression, cumulative),
63
					ProgressionCoreMessages.bind(ProgressionCoreMessages.tEqualsP0, progression.getXmaxCorpus()), yAxisLabel, true, true, true, true, true);
64

  
65

  
63
			try {
64
				chart = this.getChartsEngine().createXYStepChart(dataset, Utils.createProgressionChartTitle(progression, cumulative),
65
						ProgressionCoreMessages.bind(ProgressionCoreMessages.tEqualsP0, progression.getCorpus().getSize()), yAxisLabel, true, true, true, true, true);
66
			}
67
			catch (CqiClientException e) {
68
				// TODO Auto-generated catch block
69
				e.printStackTrace();
70
			}
71
			
72
			
66 73
			// Custom renderer
67 74
			chart.getXYPlot().setRenderer(new ProgressionItemSelectionRenderer());
68

  
75
			
69 76
		}
70 77
		// FIXME : Density, to implement when textometry R package will store the result in the Progression class
71 78
		// FIXME: put that in a new ChartCreator dedicated to the density progression chart
72
		else	{
73

  
79
		else {
80
			
74 81
			// FIXME : density not yet implemented
75 82
			System.err.println("JFCProgressionCumulativeChartCreator.createChart(): density mode not yet implemented.");
76

  
77
//			for(int i = 0; i < progression.getAllpositions().size(); i++) {
78
//				int[] liste = positions.get(i);
79
//				Query query = queries.get(i);
80
//				XYSeries series = new XYSeries(query.toString() + " " + liste.length);
81
//
82
//				for(int j = 0; j <  liste.length; j++) {
83
//
84
//					// FIXME : tests y
85
//					// y <- c( c(0), y , c(y[[length(x)]]) ) // R code
86
//					// FIXME : random Y value
87
//					double y = progression.getAllpositions().get(i)[j] * Math.random();
88
//	//				double y = progression.getAllpositions().get(i)[j];
89
//					series.add(liste[j], y);
90
//				}
91
//				dataset.addSeries(series);
92
//			}
93
//
94
//			// Create the chart
95
//			yAxisLabel =  ProgressionCoreMessages.ChartsEngine_PROGRESSION_Y_AXIS_NOT_CUMULATIVE_LABEL;
96
//			chart = this.getChartsEngine().createXYLineChart(dataset, Utils.createProgressionChartTitle(progression, cumulative),
97
//					ProgressionCoreMessages.bind(ProgressionCoreMessages.tEqualsP0, progression.getXmaxCorpus()), yAxisLabel,
98
//					true, true, true, false, true, false, true, null);
83
			
84
			// for(int i = 0; i < progression.getAllpositions().size(); i++) {
85
			// int[] liste = positions.get(i);
86
			// Query query = queries.get(i);
87
			// XYSeries series = new XYSeries(query.toString() + " " + liste.length);
88
			//
89
			// for(int j = 0; j < liste.length; j++) {
90
			//
91
			// // FIXME : tests y
92
			// // y <- c( c(0), y , c(y[[length(x)]]) ) // R code
93
			// // FIXME : random Y value
94
			// double y = progression.getAllpositions().get(i)[j] * Math.random();
95
			// // double y = progression.getAllpositions().get(i)[j];
96
			// series.add(liste[j], y);
97
			// }
98
			// dataset.addSeries(series);
99
			// }
100
			//
101
			// // Create the chart
102
			// yAxisLabel = ProgressionCoreMessages.ChartsEngine_PROGRESSION_Y_AXIS_NOT_CUMULATIVE_LABEL;
103
			// chart = this.getChartsEngine().createXYLineChart(dataset, Utils.createProgressionChartTitle(progression, cumulative),
104
			// ProgressionCoreMessages.bind(ProgressionCoreMessages.tEqualsP0, progression.getXmaxCorpus()), yAxisLabel,
105
			// true, true, true, false, true, false, true, null);
99 106
		}
100

  
101

  
102

  
103
        ((IRendererWithItemSelection) chart.getXYPlot().getRenderer()).getItemsSelector().setResult(progression);
104

  
105 107
		
108
		
109
		
110
		((IRendererWithItemSelection) chart.getXYPlot().getRenderer()).getItemsSelector().setResult(progression);
111
		
112
		
106 113
		return chart;
107 114
		
108 115
	}
109

  
110

  
116
	
117
	
111 118
	@Override
112 119
	public void updateChart(ChartResult result) {
113

  
120
		
114 121
		Progression progression = (Progression) result;
115 122
		JFreeChart chart = (JFreeChart) result.getChart();
116

  
123
		
117 124
		// freeze rendering while computing
118 125
		chart.setNotify(false);
119 126
		
120 127
		
121 128
		// Fill the data set from the result
122 129
		// FIXME: SJ: the tests on queries is not sufficient, it does not work when we switch from R chart to JFC chart because the queries didn't change
123
		//if(progression.hasParameterChanged(TXMPreferences.QUERIES))	{
124
			
125
			XYSeriesCollection dataset = (XYSeriesCollection) chart.getXYPlot().getDataset();
126
			dataset.removeAllSeries();
127
			
128
			List<int[]> positions = progression.getAllPositions();
129
			List<CQLQuery> queries = progression.getQueries();
130
			for(int i = 0; i < positions.size(); i++) {
131
				int[] list = positions.get(i);
132
				CQLQuery query = queries.get(i);
133
				XYSeries series = new XYSeries(query.toString() + " " + list.length);
134
				int c = 1;
135
				for(int j = 0; j < list.length; j++) {
136
					// add a first point to draw a vertical line
137
					if(j == 0)	{
138
						series.add(list[j], 0);
139
					}
140
					series.add(list[j], c++);
130
		// if(progression.hasParameterChanged(TXMPreferences.QUERIES)) {
131
		
132
		XYSeriesCollection dataset = (XYSeriesCollection) chart.getXYPlot().getDataset();
133
		dataset.removeAllSeries();
134
		
135
		List<int[]> positions = progression.getAllPositions();
136
		List<CQLQuery> queries = progression.getQueries();
137
		for (int i = 0; i < positions.size(); i++) {
138
			int[] list = positions.get(i);
139
			CQLQuery query = queries.get(i);
140
			XYSeries series = new XYSeries(query.toString() + " " + list.length);
141
			int c = 1;
142
			for (int j = 0; j < list.length; j++) {
143
				// add a first point to draw a vertical line
144
				if (j == 0) {
145
					series.add(list[j], 0);
141 146
				}
142
	
143
				// add a dummy point to draw horizontal line between last point and max X corpus
144
				series.add(progression.getXmaxCorpus(), --c);
145
				dataset.addSeries(series);
147
				series.add(list[j], c++);
146 148
			}
147 149
			
148
			// Custom domain axis for ticks drawing options
149
			chart.getXYPlot().setDomainAxis(new ExtendedNumberAxis((NumberAxis) chart.getXYPlot().getDomainAxis(), true, true, progression.getXminCorpus(), progression.getXmaxCorpus()));
150

  
151
			// Custom range axis for ticks drawing options
152
			chart.getXYPlot().setRangeAxis(new ExtendedNumberAxis((NumberAxis) chart.getXYPlot().getRangeAxis(), false, true, 0, progression.getMaxY()));
153

  
154
			// Match the X-axis origin value to the min x corpus (for subcorpus case)
155
			chart.getXYPlot().getDomainAxis().setLowerBound(progression.getXminCorpus());
156
		//}
150
			// add a dummy point to draw horizontal line between last point and max X corpus
151
			series.add(progression.getXmaxCorpus(), --c);
152
			dataset.addSeries(series);
153
		}
157 154
		
155
		// Custom domain axis for ticks drawing options
156
		chart.getXYPlot().setDomainAxis(new ExtendedNumberAxis((NumberAxis) chart.getXYPlot().getDomainAxis(), true, true, progression.getXminCorpus(), progression.getXmaxCorpus()));
158 157
		
158
		// Custom range axis for ticks drawing options
159
		chart.getXYPlot().setRangeAxis(new ExtendedNumberAxis((NumberAxis) chart.getXYPlot().getRangeAxis(), false, true, 0, progression.getMaxY()));
159 160
		
161
		
162
		// chart.getXYPlot().getDomainAxis().setRange(progression.getXminCorpus(), progression.getXmaxCorpus());
163
		// System.out.println("JFCProgressionCumulativeChartCreator.updateChart()" + progression.getXminCorpus());
164
		
165
		// // Match the X-axis origin value to the min x corpus (for sub-corpus case)
166
		// chart.getXYPlot().getDomainAxis().setLowerBound(progression.getXminCorpus());
167
		//
168
		// // Match the X-axis max value to the max x corpus (for sub-corpus case)
169
		// chart.getXYPlot().getDomainAxis().setUpperBound(progression.getXmaxCorpus());
170
		
171
		
172
		((NumberAxis) chart.getXYPlot().getDomainAxis()).setAutoRangeIncludesZero(false);
173
		
174
		
175
		
176
		
177
		
178
		// }
179
		
180
		
181
		
160 182
		// removes all existing domain marker
161 183
		chart.getXYPlot().clearDomainMarkers();
162 184
		
163 185
		// Add the limit markers
164
		BasicStroke dashedStroke = new BasicStroke(0.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1f, new float[] {2f}, 0f);
186
		BasicStroke dashedStroke = new BasicStroke(0.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1f, new float[] { 2f }, 0f);
165 187
		Marker marker = new ValueMarker(progression.getXminCorpus());
166
        marker.setPaint(Color.gray);
167
        marker.setStroke(dashedStroke);
168
        chart.getXYPlot().addDomainMarker(marker);
188
		marker.setPaint(Color.gray);
189
		marker.setStroke(dashedStroke);
190
		chart.getXYPlot().addDomainMarker(marker);
169 191
		marker = new ValueMarker(progression.getXmaxCorpus());
170
        marker.setPaint(Color.gray);
171
        marker.setStroke(dashedStroke);
172
        chart.getXYPlot().addDomainMarker(marker);
173

  
174

  
175
//        // FIXME : limit with annotations rather than markers (marker height is dynamically adapted to the real chart height.
176
        // Annotation have a fixed height)
177
//        XYLineAnnotation annotation = new XYLineAnnotation(0, 0, 0, dataset.getRangeUpperBound(true), dashedStroke, Color.gray);
178
//        chart.getXYPlot().addAnnotation(annotation, true);
179

  
192
		marker.setPaint(Color.gray);
193
		marker.setStroke(dashedStroke);
194
		chart.getXYPlot().addDomainMarker(marker);
195
		
196
		
197
		// // FIXME : limit with annotations rather than markers (marker height is dynamically adapted to the real chart height.
198
		// Annotation have a fixed height)
199
		// XYLineAnnotation annotation = new XYLineAnnotation(0, 0, 0, dataset.getRangeUpperBound(true), dashedStroke, Color.gray);
200
		// chart.getXYPlot().addAnnotation(annotation, true);
201
		
180 202
		// Add the part markers
181
        String previousPartName = ""; //$NON-NLS-1$
182
		if(progression.getStructuralUnit() != null && progression.getStructurePositions().length > 0)	{
183
			for(int i = 0; i < progression.getStructurePositions().length; i++) {
184
				if(progression.getStructurePositions()[i] != 0)	{
203
		String previousPartName = ""; //$NON-NLS-1$
204
		if (progression.getStructuralUnit() != null && progression.getStructurePositions().length > 0) {
205
			for (int i = 0; i < progression.getStructurePositions().length; i++) {
206
				if (progression.getStructurePositions()[i] != 0) {
185 207
					
186 208
					String currentPartName = progression.getStructureNames()[i];
187 209
					
188
					if(progression.isRepeatingValues() || !currentPartName.equals(previousPartName))	{
189
					
210
					if (progression.isRepeatingValues() || !currentPartName.equals(previousPartName)) {
211
						
190 212
						marker = new ValueMarker(progression.getStructurePositions()[i]);
191
				        marker.setPaint(Color.black);
192
				        marker.setLabel(progression.getStructureNames()[i]);
193
				        marker.setLabelAnchor(RectangleAnchor.TOP_RIGHT);
194
				        marker.setLabelTextAnchor(TextAnchor.HALF_ASCENT_LEFT);
195
	
196
	
197
				        // FIXME: test of rotated annotations rather than using marker label. The problem with this is that the position of annotation is not adjusted when zooming/dezooming.
198
				        // FIXME: the best approach is to redefine the drawing method of
199
	////			        double start = marker.getStartValue();
200
	////			        double end = TempIntervalMarker.getEndValue();
201
	////			        double middle = (end - start)/2;
202
	//			        XYTextAnnotation updateLabel = new XYTextAnnotation("Update", progression.getStructurePositions()[i], 0);
203
	//			        updateLabel.setFont(new Font("Sans Serif", Font.BOLD, 10));
204
	//			        updateLabel.setRotationAnchor(TextAnchor.BASELINE_CENTER);
205
	//			        updateLabel.setTextAnchor(TextAnchor.BASELINE_CENTER);
206
	//			        updateLabel.setRotationAngle(3.14 / 2);
207
	//			        updateLabel.setPaint(Color.black);
208
	//			        chart.getXYPlot().addAnnotation(updateLabel);
209
	
210
				        chart.getXYPlot().addDomainMarker(marker);
213
						marker.setPaint(Color.black);
214
						marker.setLabel(progression.getStructureNames()[i]);
215
						marker.setLabelAnchor(RectangleAnchor.TOP_RIGHT);
216
						marker.setLabelTextAnchor(TextAnchor.HALF_ASCENT_LEFT);
217
						
218
						
219
						// FIXME: test of rotated annotations rather than using marker label. The problem with this is that the position of annotation is not adjusted when zooming/dezooming.
220
						// FIXME: the best approach is to redefine the drawing method of
221
						//// double start = marker.getStartValue();
222
						//// double end = TempIntervalMarker.getEndValue();
223
						//// double middle = (end - start)/2;
224
						// XYTextAnnotation updateLabel = new XYTextAnnotation("Update", progression.getStructurePositions()[i], 0);
225
						// updateLabel.setFont(new Font("Sans Serif", Font.BOLD, 10));
226
						// updateLabel.setRotationAnchor(TextAnchor.BASELINE_CENTER);
227
						// updateLabel.setTextAnchor(TextAnchor.BASELINE_CENTER);
228
						// updateLabel.setRotationAngle(3.14 / 2);
229
						// updateLabel.setPaint(Color.black);
230
						// chart.getXYPlot().addAnnotation(updateLabel);
231
						
232
						chart.getXYPlot().addDomainMarker(marker);
211 233
					}
212 234
					
213 235
					previousPartName = currentPartName;
......
220 242
		super.updateChart(result);
221 243
		
222 244
	}
223

  
245
	
224 246
	@Override
225 247
	public ArrayList<Integer> getSelectedPointPositions(Object chart) {
226

  
227
		MultipleItemsSelector selector = (MultipleItemsSelector) ((IRendererWithItemSelection)((JFreeChart) chart).getXYPlot().getRenderer()).getItemsSelector();
228
		ArrayList<Integer> pointPositionsInCorpora = new ArrayList<Integer>();
229

  
230

  
248
		
249
		MultipleItemsSelector selector = (MultipleItemsSelector) ((IRendererWithItemSelection) ((JFreeChart) chart).getXYPlot().getRenderer()).getItemsSelector();
250
		ArrayList<Integer> pointPositionsInCorpora = new ArrayList<>();
251
		
252
		
231 253
		// FIXME: returns all the point positions
232 254
		XYDataset dataset = ((JFreeChart) chart).getXYPlot().getDataset();
233
		for(int i = 0; i < selector.getSelectedSeries().length; i++) {
255
		for (int i = 0; i < selector.getSelectedSeries().length; i++) {
234 256
			int selectedSeries = selector.getSelectedSeries()[i];
235
			int[] selectedItemsInSeries = selector.getSelectedItems(selectedSeries) ;
236
			for(int j = 0; j < selectedItemsInSeries.length; j++) {
257
			int[] selectedItemsInSeries = selector.getSelectedItems(selectedSeries);
258
			for (int j = 0; j < selectedItemsInSeries.length; j++) {
237 259
				// if it's the dummy last chart point, get the previous point position instead of ther last one
238
				if(selectedItemsInSeries[j] == dataset.getItemCount(selectedSeries) - 1)	{
260
				if (selectedItemsInSeries[j] == dataset.getItemCount(selectedSeries) - 1) {
239 261
					pointPositionsInCorpora.add((int) (dataset.getXValue(selectedSeries, selectedItemsInSeries[j] - 1)));
240 262
				}
241
				else	{
263
				else {
242 264
					pointPositionsInCorpora.add((int) (dataset.getXValue(selectedSeries, selectedItemsInSeries[j])));
243 265
				}
244 266
			}
245 267
			
246 268
		}
247

  
269
		
248 270
		// put the last selected point at the end of the list
249
		if(selector.getLastSelectedSeries() != -1 && selector.getLastSelectedItem() != -1)	{
271
		if (selector.getLastSelectedSeries() != -1 && selector.getLastSelectedItem() != -1) {
250 272
			int item = selector.getLastSelectedItem();
251 273
			// if it's the dummy last chart point, get the previous point position instead of ther last one
252
			if(item == dataset.getItemCount(selector.getLastSelectedSeries()) - 1)	{
274
			if (item == dataset.getItemCount(selector.getLastSelectedSeries()) - 1) {
253 275
				item--;
254 276
			}
255 277
			
......
259 281
		}
260 282
		return pointPositionsInCorpora;
261 283
	}
262

  
284
	
263 285
	@Override
264 286
	public ArrayList<Integer> getSelectedPointNumbers(Object chart) {
265

  
266
		MultipleItemsSelector selector = (MultipleItemsSelector) ((IRendererWithItemSelection)((JFreeChart) chart).getXYPlot().getRenderer()).getItemsSelector();
267
		ArrayList<Integer> pointNumbers = new ArrayList<Integer>();
287
		
288
		MultipleItemsSelector selector = (MultipleItemsSelector) ((IRendererWithItemSelection) ((JFreeChart) chart).getXYPlot().getRenderer()).getItemsSelector();
289
		ArrayList<Integer> pointNumbers = new ArrayList<>();
268 290
		XYDataset dataset = ((JFreeChart) chart).getXYPlot().getDataset();
269 291
		
270
		for(int i = 0; i < selector.getSelectedSeriesCount(); i++) {
292
		for (int i = 0; i < selector.getSelectedSeriesCount(); i++) {
271 293
			int series = selector.getSelectedSeries()[i];
272 294
			int[] items = selector.getSelectedItems(series);
273
			int lastDummyItem = dataset.getItemCount(series) - 1; 
274
			for(int j = 0; j < items.length; j++) {
295
			int lastDummyItem = dataset.getItemCount(series) - 1;
296
			for (int j = 0; j < items.length; j++) {
275 297
				int item = items[j];
276 298
				// manage the first dummy point
277
				if(item == 0)	{
299
				if (item == 0) {
278 300
					item++;
279 301
				}
280 302
				// manage the last dummy point
281
				else if(item == lastDummyItem)	 {
303
				else if (item == lastDummyItem) {
282 304
					item--;
283 305
				}
284 306
				
......
289 311
		return pointNumbers;
290 312
	}
291 313
	
292

  
293 314
	
315
	
294 316
	@Override
295 317
	public ArrayList<ArrayList<Integer>> getAllPointPositionsBySeries(Object chart) {
296

  
297
		ArrayList<ArrayList<Integer>> pointPositionsBySeries = new ArrayList<ArrayList<Integer>>();
298 318
		
319
		ArrayList<ArrayList<Integer>> pointPositionsBySeries = new ArrayList<>();
320
		
299 321
		XYDataset dataset = ((JFreeChart) chart).getXYPlot().getDataset();
300

  
301
		for(int i = 0; i < dataset.getSeriesCount(); i++) {
302
			ArrayList<Integer> pointPositionsInCorpora = new ArrayList<Integer>();
303
			for(int j = 0; j < dataset.getItemCount(i) - 1; j++) { // -1 to skip the last dummy point of the step chart
322
		
323
		for (int i = 0; i < dataset.getSeriesCount(); i++) {
324
			ArrayList<Integer> pointPositionsInCorpora = new ArrayList<>();
325
			for (int j = 0; j < dataset.getItemCount(i) - 1; j++) { // -1 to skip the last dummy point of the step chart
304 326
				pointPositionsInCorpora.add((int) dataset.getXValue(i, j));
305 327
			}
306 328
			pointPositionsBySeries.add(pointPositionsInCorpora);
307 329
		}
308

  
330
		
309 331
		return pointPositionsBySeries;
310 332
	}
311

  
312 333
	
313 334
	
335
	
314 336
	@Override
315 337
	public ArrayList<Integer> getSelectedSeries(Object chart) {
316
		ArrayList<Integer> selectedSeries = new ArrayList<Integer>();
317
		MultipleItemsSelector selector = (MultipleItemsSelector) ((IRendererWithItemSelection)((JFreeChart) chart).getXYPlot().getRenderer()).getItemsSelector();
338
		ArrayList<Integer> selectedSeries = new ArrayList<>();
339
		MultipleItemsSelector selector = (MultipleItemsSelector) ((IRendererWithItemSelection) ((JFreeChart) chart).getXYPlot().getRenderer()).getItemsSelector();
318 340
		Integer[] multipleSelectedSeries = selector.getSelectedSeries();
319
		for(int i = 0; i < multipleSelectedSeries.length; i++) {
341
		for (int i = 0; i < multipleSelectedSeries.length; i++) {
320 342
			selectedSeries.add(multipleSelectedSeries[i]);
321 343
		}
322 344
		return selectedSeries;
323 345
	}
324

  
325

  
346
	
347
	
326 348
	@Override
327 349
	public int getLastSelectedSeries(Object chart) {
328
		return ((MultipleItemsSelector) ((IRendererWithItemSelection)((JFreeChart) chart).getXYPlot().getRenderer()).getItemsSelector()).getLastSelectedSeries();
350
		return ((MultipleItemsSelector) ((IRendererWithItemSelection) ((JFreeChart) chart).getXYPlot().getRenderer()).getItemsSelector()).getLastSelectedSeries();
329 351
	}
330

  
331 352
	
332 353
	
354
	
333 355
	@Override
334 356
	public Class getResultDataClass() {
335 357
		return Progression.class;
336 358
	}
337

  
338

  
339 359
	
340

  
341
}
360
	
361
	
362
	
363
}
tmp/org.txm.progression.core/src/org/txm/progression/core/chartsengine/r/RProgressionBaseChartCreator.java (revision 2531)
27 27
 *
28 28
 */
29 29
public class RProgressionBaseChartCreator extends RChartCreator implements ProgressionChartCreator {
30

  
31

  
32

  
30
	
31
	
32
	
33 33
	/**
34 34
	 * Creates a progression chart file.
35
	 * 
35 36
	 * @param result
36 37
	 * @param file
37 38
	 * @param cumulative
38 39
	 * @return
39 40
	 */
40 41
	public File createChartFile(ChartResult result, File file, boolean cumulative) {
41

  
42
		
42 43
		try {
43 44
			
44 45
			Progression progression = (Progression) result;
......
53 54
			
54 55
			List<int[]> allPositions = progression.getAllPositions();
55 56
			String listString = "list("; //$NON-NLS-1$
56
			for(int i = 0; i < allPositions.size(); i++) {
57
			for (int i = 0; i < allPositions.size(); i++) {
57 58
				int[] positions = allPositions.get(i);
58 59
				// System.out.println("add vector "+i);
59 60
				rw.eval("rm(x" + i + ")"); //$NON-NLS-1$ //$NON-NLS-2$
......
64 65
			// System.out.println("create positions");
65 66
			rw.eval("rm(positions)"); //$NON-NLS-1$
66 67
			rw.eval("positions <- " + listString); //$NON-NLS-1$
67

  
68
			
68 69
			rw.eval("rm(structurepositions)"); //$NON-NLS-1$
69 70
			rw.addVectorToWorkspace("structurepositions", progression.getStructurePositions()); //$NON-NLS-1$
70 71
			rw.eval("rm(structurenames)"); //$NON-NLS-1$
71 72
			// if (structurenames != null) structurenames = new
72 73
			// String[structurepositions.length];
73
			for(int i = 0; i < progression.getStructureNames().length; i++) { // Fix empty attribute values
74
				if("".equals(progression.getStructureNames()[i]) || progression.getStructureNames()[i] == null) {  //$NON-NLS-1$
74
			for (int i = 0; i < progression.getStructureNames().length; i++) { // Fix empty attribute values
75
				if ("".equals(progression.getStructureNames()[i]) || progression.getStructureNames()[i] == null) {  //$NON-NLS-1$
75 76
					progression.getStructureNames()[i] = "--"; //$NON-NLS-1$
76 77
				}
77 78
			}
78 79
			rw.addVectorToWorkspace("structurenames", progression.getStructureNames()); //$NON-NLS-1$
79 80
			// System.out.println("create list positions");
80 81
			// rw.getConnection().assign("positions",Rpositions);
81

  
82
			
82 83
			this.getChartsEngine().setColors(renderingColorMode, progression.getQueries().size());
83 84
			
84
//			if(monochrome) {
85
//				rw.addVectorToWorkspace("colors", DefaultTheme.monocolors); //$NON-NLS-1$
86
//			}
87
//			else {
88
//				if(progression.getQueries().size() <= 5) {
89
//					// System.out.println("uses colors5");
90
//					
91
//					
92
//					rw.addVectorToWorkspace("colors", this.getChartsEngine().getTheme().getColorPaletteAsHexFor(5));
93
//					
94
//					
95
//					//rw.addVectorToWorkspace("colors", DefaultTheme.colors5); //$NON-NLS-1$
96
//				}
97
//				else if(progression.getQueries().size() <= 10) {
98
//					// System.out.println("uses colors10");
99
//					rw.addVectorToWorkspace("colors", DefaultTheme.colors10); //$NON-NLS-1$
100
//				}
101
//				else {
102
//					// System.out.println("uses colors16");
103
//					rw.addVectorToWorkspace("colors", DefaultTheme.colors); //$NON-NLS-1$
104
//				}
105
//			}
106

  
85
			// if(monochrome) {
86
			// rw.addVectorToWorkspace("colors", DefaultTheme.monocolors); //$NON-NLS-1$
87
			// }
88
			// else {
89
			// if(progression.getQueries().size() <= 5) {
90
			// // System.out.println("uses colors5");
91
			//
92
			//
93
			// rw.addVectorToWorkspace("colors", this.getChartsEngine().getTheme().getColorPaletteAsHexFor(5));
94
			//
95
			//
96
			// //rw.addVectorToWorkspace("colors", DefaultTheme.colors5); //$NON-NLS-1$
97
			// }
98
			// else if(progression.getQueries().size() <= 10) {
99
			// // System.out.println("uses colors10");
100
			// rw.addVectorToWorkspace("colors", DefaultTheme.colors10); //$NON-NLS-1$
101
			// }
102
			// else {
103
			// // System.out.println("uses colors16");
104
			// rw.addVectorToWorkspace("colors", DefaultTheme.colors); //$NON-NLS-1$
105
			// }
106
			// }
107
			
107 108
			// System.out.println("create styles vector");
108 109
			rw.eval("rm(styles)"); //$NON-NLS-1$
109
			if(!progression.isMultipleLineStrokes()) {
110
			if (!progression.isMultipleLineStrokes()) {
110 111
				rw.addVectorToWorkspace("styles", DefaultTheme.monostyles); //$NON-NLS-1$
111 112
			}
112 113
			else {
113 114
				rw.addVectorToWorkspace("styles", DefaultTheme.styles); //$NON-NLS-1$
114 115
			}
115

  
116
			
116 117
			// System.out.println("create styles vector");
117 118
			rw.eval("rm(widths)"); //$NON-NLS-1$
118 119
			rw.addVectorToWorkspace("widths", DefaultTheme.monoWidths); //$NON-NLS-1$
119

  
120
			
120 121
			// System.out.println("create names vector");
121 122
			String[] queriesstring = new String[progression.getQueries().size()];
122
			for(int i = 0; i < progression.getQueries().size(); i++) {
123
			for (int i = 0; i < progression.getQueries().size(); i++) {
123 124
				queriesstring[i] = progression.getQueries().get(i).getQueryString();
124 125
			}
125 126
			rw.eval("rm(names)"); //$NON-NLS-1$
126 127
			rw.addVectorToWorkspace("names", queriesstring); //$NON-NLS-1$
127

  
128
			
128 129
			String name = progression.getCorpus().getName();
129

  
130
			
130 131
			// System.out.println("BANDE="+bande);
131 132
			
132
			String cmd = "progression(positions, names, colors, styles, widths, \"" + name + "\"," + progression.getXminCorpus() + "," + progression.getXmaxCorpus() + ",\"" + cumulative + "\",structurepositions,structurenames, \"\", " + progression.getBande() + ");\n"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$
133
			String cmd = "progression(positions, names, colors, styles, widths, \"" + name + "\"," + progression.getXminCorpus() + "," + progression.getXmaxCorpus() + ",\"" + cumulative //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
134
					+ "\",structurepositions,structurenames, \"\", " + progression.getBande() + ");\n";  //$NON-NLS-1$ //$NON-NLS-2$
133 135
			
134 136
			this.getChartsEngine().plot(file, cmd, result, StringEscapeUtils.escapeJava(Utils.createProgressionChartTitle(progression, cumulative)), null);
135

  
136
			RWorkspace.getRWorkspaceInstance().eval(Progression.prefixR + Progression.norep + " <- list(positions=positions, names=names, xmin=" + progression.getXminCorpus() + ",xmax=" + progression.getXmaxCorpus() + ", structpositions=structurepositions, structnames=structurenames)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
137
			
138
			RWorkspace.getRWorkspaceInstance().eval(Progression.prefixR + Progression.norep + " <- list(positions=positions, names=names, xmin=" + progression.getXminCorpus() + ",xmax=" + progression //$NON-NLS-1$ //$NON-NLS-2$
139
					.getXmaxCorpus() + ", structpositions=structurepositions, structnames=structurenames)");  //$NON-NLS-1$
137 140
			Progression.norep++;
138 141
		}
139
		catch(RWorkspaceException e) {
142
		catch (RWorkspaceException e) {
140 143
			// TODO Auto-generated catch block
141 144
			org.txm.utils.logger.Log.printStackTrace(e);
142 145
		}
143

  
146
		
144 147
		return file;
145 148
	}
146 149
	
......
149 152
	public ArrayList<Integer> getSelectedPointPositions(Object chart) {
150 153
		// FIXME: not implemented
151 154
		Log.severe(this.getClass() + ".getProgressionChartSelectedPointPositions(): Not yet implemented."); //$NON-NLS-1$
152
		return new ArrayList<Integer>(0);
155
		return new ArrayList<>(0);
153 156
	}
154

  
155

  
156

  
157
	
158
	
159
	
157 160
	@Override
158 161
	public ArrayList<Integer> getSelectedSeries(Object chart) {
159 162
		Log.severe(this.getClass() + ".getProgressionChartSelectedSeries(): Not yet implemented."); //$NON-NLS-1$
160
		return new ArrayList<Integer>(0);
163
		return new ArrayList<>(0);
161 164
	}
162

  
163

  
165
	
166
	
164 167
	@Override
165 168
	public ArrayList<Integer> getSelectedPointNumbers(Object chart) {
166 169
		Log.severe(this.getClass() + ".getProgressionChartSelectedPointNumber(): Not yet implemented."); //$NON-NLS-1$
167
		return new ArrayList<Integer>(0);
170
		return new ArrayList<>(0);
168 171
	}
169

  
170

  
172
	
173
	
171 174
	@Override
172 175
	public int getLastSelectedSeries(Object chart) {
173 176
		Log.severe(this.getClass() + ".getProgressionChartLastSelectedSeries(): Not yet implemented."); //$NON-NLS-1$
174 177
		return -1;
175 178
	}
176

  
177

  
179
	
180
	
178 181
	@Override
179 182
	public Class getResultDataClass() {
180 183
		return Progression.class;
181 184
	}
182

  
185
	
183 186
	@Override
184 187
	public ArrayList<ArrayList<Integer>> getAllPointPositionsBySeries(Object chart) {
185 188
		Log.severe(this.getClass() + ".getAllPointPositionsBySeries(): Not yet implemented."); //$NON-NLS-1$
186 189
		return null;
187 190
	}
188

  
189

  
191
	
192
	
190 193
}

Formats disponibles : Unified diff