Revision 166

tmp/org.txm.progression.core/src/org/txm/progression/core/chartsengine/jfreechart/JFCProgressionChartCreator.java (revision 166)
322 322
	}
323 323

  
324 324

  
325
	@Override
326
	public ArrayList<Integer> getProgressionChartSelectedPointPositions(Object chart) {
327

  
328
		MultipleItemsSelector selector = (MultipleItemsSelector) ((IItemSelectionRenderer)((JFreeChart) chart).getXYPlot().getRenderer()).getItemsSelector();
329
		ArrayList<Integer> pointPositionsInCorpora = new ArrayList<Integer>();
330

  
331

  
332
		// FIXME: returns all the point positions
333
		XYDataset dataset = ((JFreeChart) chart).getXYPlot().getDataset();
334
		for(int i = 0; i < selector.getSelectedSeries().length; i++) {
335
			int selectedSeries = selector.getSelectedSeries()[i];
336
			int[] selectedItemsInSeries = selector.getSelectedItems(selectedSeries) ;
337
			for(int j = 0; j < selectedItemsInSeries.length; j++) {
338
				// if it's the dummy last chart point, get the previous point position instead of ther last one
339
				if(selectedItemsInSeries[j] == dataset.getItemCount(selectedSeries) - 1)	{
340
					pointPositionsInCorpora.add((int) (dataset.getXValue(selectedSeries, selectedItemsInSeries[j] - 1)));
341
				}
342
				else	{
343
					pointPositionsInCorpora.add((int) (dataset.getXValue(selectedSeries, selectedItemsInSeries[j])));
344
				}
345
			}
346
			
347
		}
348

  
349
		// put the last selected point at the end of the list
350
		if(selector.getLastSelectedSeries() != -1 && selector.getLastSelectedItem() != -1)	{
351
			int item = selector.getLastSelectedItem();
352
			// if it's the dummy last chart point, get the previous point position instead of ther last one
353
			if(item == dataset.getItemCount(selector.getLastSelectedSeries()) - 1)	{
354
				item--;
355
			}
356
			
357
			Integer lastSelectedPointPosition = (int) (dataset.getXValue(selector.getLastSelectedSeries(), item));
358
			pointPositionsInCorpora.remove(lastSelectedPointPosition);
359
			pointPositionsInCorpora.add(lastSelectedPointPosition);
360
		}
361
		
362
		
363
		// FIXME: old version which returns only 1 point position
364
//		if(selector.getMultipleSelectedSeries().length > 0)	{
365
//			int selectedSeries = selector.getMultipleSelectedSeries()[0];
366
//			if(selector.getMouseOverItemInSeries(selectedSeries) != -1)	{
367
//				XYDataset dataset = ((JFreeChart) chart).getXYPlot().getDataset();
368
//				// if it's the dummy last chart point, get the previous point position instead of ther last one
369
//				if(selector.getMouseOverItemInSeries(selectedSeries) == dataset.getItemCount(selector.getMultipleSelectedSeries()[0]) - 1)	{
370
//					pointPositionsInCorpora.add((int) (dataset.getXValue(selector.getMultipleSelectedSeries()[0], selector.getMouseOverItemInSeries(selectedSeries) - 1)));
371
//				}
372
//				else	{
373
//					pointPositionsInCorpora.add((int) (dataset.getXValue(selector.getMultipleSelectedSeries()[0], selector.getMouseOverItemInSeries(selectedSeries))));
374
//				}
375
//				
376
//			}
377
//		}
378
		
379
		return pointPositionsInCorpora;
380
	}
381

  
382
	@Override
383
	public ArrayList<Integer> getProgressionChartSelectedPointNumbers(Object chart) {
384

  
385
		MultipleItemsSelector selector = (MultipleItemsSelector) ((IItemSelectionRenderer)((JFreeChart) chart).getXYPlot().getRenderer()).getItemsSelector();
386
		ArrayList<Integer> pointNumbers = new ArrayList<Integer>();
387
		XYDataset dataset = ((JFreeChart) chart).getXYPlot().getDataset();
388
		
389
		for(int i = 0; i < selector.getSelectedSeriesCount(); i++) {
390
			int series = selector.getSelectedSeries()[i];
391
			int[] items = selector.getSelectedItems(series);
392
			int lastDummyItem = dataset.getItemCount(series) - 1; 
393
			for(int j = 0; j < items.length; j++) {
394
				int item = items[j];
395
				// manage the first dummy point
396
				if(item == 0)	{
397
					item++;
398
				}
399
				// manage the last dummy point
400
				else if(item == lastDummyItem)	 {
401
					item--;
402
				}
403
				
404
				pointNumbers.add(item);
405
			}
406
		}
407
		
408
		return pointNumbers;
409
	}
410 325
	
411 326

  
412
	
413
	@Override
414
	public ArrayList<Integer> getProgressionChartAllPointPositions(Object chart) {
415

  
416
		ArrayList<Integer> pointPositionsInCorpora = new ArrayList<Integer>();
417
		XYDataset dataset = ((JFreeChart) chart).getXYPlot().getDataset();
418
		
419
		for(int i = 0; i < dataset.getSeriesCount(); i++) {
420
			for(int j = 0; j < dataset.getItemCount(i) - 1; j++) { // -1 to skip the last dummy point of the step chart
421
				pointPositionsInCorpora.add((int) dataset.getXValue(i, j));
422
			}
423
		}
424
		
425
		return pointPositionsInCorpora;
426
	}
427
	
428
	@Override
429
	public ArrayList<Integer> getProgressionChartSelectedSeries(Object chart) {
430
		ArrayList<Integer> selectedSeries = new ArrayList<Integer>();
431
		MultipleItemsSelector selector = (MultipleItemsSelector) ((IItemSelectionRenderer)((JFreeChart) chart).getXYPlot().getRenderer()).getItemsSelector();
432
		Integer[] multipleSelectedSeries = selector.getSelectedSeries();
433
		for(int i = 0; i < multipleSelectedSeries.length; i++) {
434
			selectedSeries.add(multipleSelectedSeries[i]);
435
		}
436
		return selectedSeries;
437
	}
438

  
439

  
440
	@Override
441
	public int getProgressionChartLastSelectedSeries(Object chart) {
442
		return ((MultipleItemsSelector) ((IItemSelectionRenderer)((JFreeChart) chart).getXYPlot().getRenderer()).getItemsSelector()).getLastSelectedSeries();
443
	}
444

  
445

  
446 327
}

Also available in: Unified diff