forked from igvteam/igv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSelectableFeatureRenderer.java
85 lines (71 loc) · 2.95 KB
/
SelectableFeatureRenderer.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
* Copyright (c) 2007-2012 The Broad Institute, Inc.
* SOFTWARE COPYRIGHT NOTICE
* This software and its documentation are the copyright of the Broad Institute, Inc. All rights are reserved.
*
* This software is supplied without any warranty or guaranteed support whatsoever. The Broad Institute is not responsible for its use, misuse, or functionality.
*
* This software is licensed under the terms of the GNU Lesser General Public License (LGPL),
* Version 2.1 which is available at http://www.opensource.org/licenses/lgpl-2.1.php.
*/
package org.broad.igv.renderer;
import com.google.common.base.Predicate;
import org.broad.igv.feature.Exon;
import org.broad.igv.feature.IExon;
import org.broad.igv.feature.IGVFeature;
import org.broad.igv.track.RenderContext;
import org.broad.igv.track.Track;
import org.broad.igv.util.collections.CollUtils;
import java.awt.*;
import java.util.Collections;
import java.util.List;
import java.util.Set;
/**
* User: jacob
* Date: 2013-Jan-28
*/
public class SelectableFeatureRenderer extends IGVFeatureRenderer {
private static final Stroke lineStroke;
private static final Color selectedBorderColor;
private Set<IExon> selectedExons = Collections.emptySet();
static{
lineStroke = new BasicStroke(2.0f);
selectedBorderColor = Color.blue;
}
public SelectableFeatureRenderer(){
AA_COLOR_1 = new Color(AA_COLOR_1.getRed(), AA_COLOR_1.getGreen(), AA_COLOR_1.getBlue(), 120);
AA_COLOR_2 = new Color(AA_COLOR_2.getRed(), AA_COLOR_2.getGreen(), AA_COLOR_2.getBlue(), 120);
}
@Override
public void render(List<IGVFeature> featureList, RenderContext context, Rectangle trackRectangle, Track track) {
List<IGVFeature> featuresWithExons = CollUtils.filter(featureList, new Predicate<IGVFeature>() {
@Override
public boolean apply(IGVFeature input) {
return input.getExons() != null && input.getExons().size() > 0;
}
});
super.render(featuresWithExons, context, trackRectangle, track);
}
@Override
protected void drawExonRect(Graphics blockGraphics, Exon exon, int x, int y, int width, int height) {
boolean isSelected = selectedExons.contains(exon);
for(IExon selEx: selectedExons){
if(selEx.contains(exon.getStart()) || selEx.contains(exon.getEnd())){
isSelected = true;
break;
}
}
if(isSelected){
blockGraphics.clearRect(x, y, width, height);
Graphics2D borderGraphics = (Graphics2D) blockGraphics.create();
borderGraphics.setColor(selectedBorderColor);
borderGraphics.setStroke(lineStroke);
borderGraphics.drawRect(x, y, width, height);
}else{
super.drawExonRect(blockGraphics, exon, x, y, width, height);
}
}
public void setSelectedExons(Set<IExon> selectedExons) {
this.selectedExons = selectedExons;
}
}