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
9
* Xavier Raynaud <xavier.raynaud@st.com> - initial API and implementation
10
*******************************************************************************/
11
package org.eclipse.linuxtools.internal.gcov.view.annotatedsource;
13
import java.util.ArrayList;
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;
27
public class STAnnotatedSourceEditorInput extends
28
AbstractSTAnnotatedSourceEditorInput {
30
private final SourceFile sourceFile;
31
private final int lineCount;
32
private final ArrayList<ISTAnnotationColumn> columns = new ArrayList<ISTAnnotationColumn>();
34
public static final Color GREEN = new Color(PlatformUI.getWorkbench().getDisplay(), 0 ,128, 0);
36
// FIXME: dispose colors ?
37
private static final Color[] greenColors = new Color[129];
40
public STAnnotatedSourceEditorInput(IFileStore fileStore, SourceFile sourceFile){
42
this.sourceFile = sourceFile;
43
lineCount = sourceFile.getLines().size();
44
this.columns.add(new CoverageAnnotationColumn(sourceFile));
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);
62
return greenColors[colorIndex];
65
return display.getSystemColor(SWT.COLOR_WHITE);
69
public ArrayList<ISTAnnotationColumn> getColumns() {