~ubuntu-branches/ubuntu/utopic/eclipse-linuxtools/utopic

« back to all changes in this revision

Viewing changes to gcov/org.eclipse.linuxtools.gcov.core/src/org/eclipse/linuxtools/internal/gcov/view/annotatedsource/STAnnotatedSourceEditorInput.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2014-05-12 18:11:40 UTC
  • mfrom: (3.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20140512181140-w237r3vsah1tmybz
Tags: 2.2.1-1
* New upstream release.
* Refreshed d/patches.
* Removed eclipse-cdt-valgrind-remote package, all its functionality
  is now provided by eclipse-cdt-profiling-framework-remote.
* Added remove-license-feature.patch.
* Bump Standards-Version to 3.9.5.
* Enable eclipse-changelog package.
* Enable eclipse-rpm-editor package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*******************************************************************************
2
 
 * Copyright (c) 2009 STMicroelectronics.
3
 
 * All rights reserved. This program and the accompanying materials
4
 
 * are made available under the terms of the Eclipse Public License v1.0
5
 
 * which accompanies this distribution, and is available at
6
 
 * http://www.eclipse.org/legal/epl-v10.html
7
 
 *
8
 
 * Contributors:
9
 
 *    Xavier Raynaud <xavier.raynaud@st.com> - initial API and implementation
10
 
 *******************************************************************************/
11
 
package org.eclipse.linuxtools.internal.gcov.view.annotatedsource;
12
 
 
13
 
import java.util.ArrayList;
14
 
 
15
 
import org.eclipse.core.filesystem.IFileStore;
16
 
import org.eclipse.linuxtools.dataviewers.annotatedsourceeditor.AbstractSTAnnotatedSourceEditorInput;
17
 
import org.eclipse.linuxtools.dataviewers.annotatedsourceeditor.ISTAnnotationColumn;
18
 
import org.eclipse.linuxtools.internal.gcov.parser.Line;
19
 
import org.eclipse.linuxtools.internal.gcov.parser.SourceFile;
20
 
import org.eclipse.swt.SWT;
21
 
import org.eclipse.swt.graphics.Color;
22
 
import org.eclipse.swt.widgets.Display;
23
 
import org.eclipse.ui.PlatformUI;
24
 
 
25
 
 
26
 
 
27
 
public class STAnnotatedSourceEditorInput extends
28
 
AbstractSTAnnotatedSourceEditorInput {
29
 
 
30
 
        private final SourceFile sourceFile;
31
 
        private final int lineCount;
32
 
        private final ArrayList<ISTAnnotationColumn> columns = new ArrayList<ISTAnnotationColumn>();
33
 
 
34
 
        public static final Color GREEN = new Color(PlatformUI.getWorkbench().getDisplay(), 0 ,128, 0);
35
 
 
36
 
        // FIXME: dispose colors ?
37
 
        private static final Color[] greenColors = new Color[129];
38
 
        
39
 
        
40
 
        public STAnnotatedSourceEditorInput(IFileStore fileStore, SourceFile sourceFile){
41
 
                super(fileStore);
42
 
                this.sourceFile = sourceFile; 
43
 
                lineCount = sourceFile.getLines().size();
44
 
                this.columns.add(new CoverageAnnotationColumn(sourceFile));
45
 
        }
46
 
 
47
 
        @Override
48
 
        public Color getColor(int ln) {
49
 
                final int index = ln + 1;
50
 
                Display display = PlatformUI.getWorkbench().getDisplay();
51
 
                if (index < lineCount){
52
 
                        ArrayList<Line> lines = sourceFile.getLines();
53
 
                        Line line = lines.get(index);
54
 
                        if (line.isExists()) {
55
 
                                long count = line.getCount();
56
 
                                if (count == 0) return display.getSystemColor(SWT.COLOR_RED);
57
 
                                if (count == sourceFile.getmaxLineCount()) return GREEN;
58
 
                                int colorIndex = 128 - (int) ((128*count)/sourceFile.getmaxLineCount());
59
 
                                if (greenColors[colorIndex] == null) {
60
 
                                        greenColors[colorIndex] = new Color(display, colorIndex,127+colorIndex,colorIndex);
61
 
                                }
62
 
                                return greenColors[colorIndex];
63
 
                        }
64
 
                }
65
 
                return display.getSystemColor(SWT.COLOR_WHITE);
66
 
        }       
67
 
 
68
 
        @Override
69
 
        public ArrayList<ISTAnnotationColumn> getColumns() {
70
 
                return columns;
71
 
        }
72
 
 
73
 
}