Project

General

Profile

Download (2.42 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2018 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix;
10

    
11
import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
12
import org.eclipse.jface.window.DefaultToolTip;
13
import org.eclipse.jface.window.ToolTip;
14
import org.eclipse.swt.graphics.Point;
15
import org.eclipse.swt.widgets.Event;
16

    
17
import eu.etaxonomy.cdm.model.description.Feature;
18

    
19
/**
20
 * @author pplitzner
21
 * @since Jul 6, 2018
22
 *
23
 */
24
public class QuantitativeChartTooltip extends DefaultToolTip {
25

    
26
    private CharacterMatrix matrix;
27

    
28
    public QuantitativeChartTooltip(CharacterMatrix matrix) {
29
        super(matrix.getNatTable(), ToolTip.NO_RECREATE, false);
30
        this.matrix = matrix;
31
    }
32

    
33
    @Override
34
    protected Object getToolTipArea(Event event) {
35
        int col = matrix.getNatTable().getColumnPositionByX(event.x);
36
        int row = matrix.getNatTable().getRowPositionByY(event.y);
37
        return new Point(col, row);
38
    }
39

    
40
    @Override
41
    protected String getText(Event event) {
42
        int colPos = matrix.getNatTable().getColumnPositionByX(event.x);
43
        int colIndex = matrix.getNatTable().getColumnIndexByPosition(colPos);
44
        Feature feature = matrix.getIndexToFeatureMap().get(colIndex);
45
        DescriptiveStatistics statistics = matrix.getFeatureToQuantStatisticsMap().get(feature);
46

    
47
        return statistics.toString();
48
    }
49

    
50
    @Override
51
    protected boolean shouldCreateToolTip(Event event) {
52
        //Differentiation between "index" and "position" is important here
53
        //"position" is the current visible index
54
        //"index" refers to the underlying data model
55
        int colPos = matrix.getNatTable().getColumnPositionByX(event.x);
56
        int colIndex = matrix.getNatTable().getColumnIndexByPosition(colPos);
57
        int rowPos = matrix.getNatTable().getRowPositionByY(event.y);
58
        Feature feature = matrix.getIndexToFeatureMap().get(colIndex);
59
        DescriptiveStatistics statistics = matrix.getFeatureToQuantStatisticsMap().get(feature);
60

    
61
        if(matrix.isShowTooltips()
62
                && rowPos==1
63
                && colIndex>=CharacterMatrix.LEADING_COLUMN_COUNT
64
                && statistics!=null) {
65
            return true;
66
        }
67
        return false;
68
    }
69

    
70
}
(17-17/19)