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 package org.utgenome.gwt.utgb.client.track.lib;
26
27 import org.utgenome.gwt.utgb.client.db.Value;
28 import org.utgenome.gwt.utgb.client.db.ValueDomain;
29 import org.utgenome.gwt.utgb.client.db.datatype.IntegerType;
30 import org.utgenome.gwt.utgb.client.track.RangeSelectable;
31 import org.utgenome.gwt.utgb.client.track.Track;
32 import org.utgenome.gwt.utgb.client.track.TrackBase;
33 import org.utgenome.gwt.utgb.client.track.TrackConfigChange;
34 import org.utgenome.gwt.utgb.client.track.TrackFrame;
35 import org.utgenome.gwt.utgb.client.track.TrackGroup;
36 import org.utgenome.gwt.utgb.client.track.TrackGroupPropertyChange;
37 import org.utgenome.gwt.utgb.client.track.TrackRangeSelector;
38 import org.utgenome.gwt.utgb.client.track.TrackWindow;
39 import org.utgenome.gwt.utgb.client.track.UTGBProperty;
40 import org.utgenome.gwt.utgb.client.ui.AbsoluteFocusPanel;
41 import org.utgenome.gwt.widget.client.Style;
42
43 import com.google.gwt.user.client.DOM;
44 import com.google.gwt.user.client.ui.Grid;
45 import com.google.gwt.user.client.ui.Label;
46 import com.google.gwt.user.client.ui.Widget;
47
48
49
50
51
52
53
54
55 public class SequenceRulerTrack extends TrackBase implements RangeSelectable {
56 private final TrackRangeSelector _rangeSelector;
57 private final Grid _layoutPanel = new Grid(1, 2);
58 private final AbsoluteFocusPanel _basePanel = new AbsoluteFocusPanel();
59 private final Ruler _ruler;
60 private final Label range = new Label();
61
62 public static TrackFactory factory() {
63 return new TrackFactory() {
64 @Override
65 public Track newInstance() {
66 return new SequenceRulerTrack();
67 }
68 };
69 }
70
71 public SequenceRulerTrack() {
72 super("Sequence Ruler");
73 _basePanel.setStyleName("global-ruler");
74 _basePanel.setTitle("click twice to change the focus area on the sequence");
75 DOM.setStyleAttribute(_basePanel.getElement(), "cursor", "pointer");
76 _rangeSelector = new TrackRangeSelector(this);
77 _ruler = new Ruler(_rangeSelector, "global-ruler-tick");
78 range.setStyleName("ruler-range");
79 range.setWidth("0px");
80 range.addMouseDownHandler(new MouseListenerOnRulerWidget(_rangeSelector));
81 _layoutPanel.setCellPadding(0);
82 _layoutPanel.setCellSpacing(0);
83 Style.fontSize(_layoutPanel, 0);
84 }
85
86 public void clear() {
87 _basePanel.clear();
88 }
89
90 @Override
91 public int getDefaultWindowHeight() {
92 return 14;
93 }
94
95 public Widget getWidget() {
96 return _layoutPanel;
97 }
98
99 @Override
100 public void onChangeTrackGroupProperty(TrackGroupPropertyChange change) {
101 final String[] relatedProperties = { UTGBProperty.SPECIES, UTGBProperty.REVISION, UTGBProperty.TARGET };
102 if (change.containsOneOf(relatedProperties)) {
103 refresh();
104 }
105
106 if (change.contains(UTGBProperty.SEQUENCE_SIZE))
107 refresh();
108 }
109
110 @Override
111 public void onChangeTrackWindow(TrackWindow newWindow) {
112 _rangeSelector.setWindowWidth(newWindow.getPixelWidth());
113 refresh();
114 }
115
116 private int getSequenceSize() {
117 return getConfig().getInt(UTGBProperty.SEQUENCE_SIZE, 1000000);
118 }
119
120 private void drawTrackSelectionRange(TrackWindow newWindow) {
121 long startOnGenome = newWindow.getStartOnGenome();
122 long endOnGenome = newWindow.getEndOnGenome();
123
124 int windowWidth = newWindow.getPixelWidth();
125
126 double pixelPerCode = windowWidth / (double) getSequenceSize();
127 int x1 = (int) (startOnGenome * pixelPerCode);
128 int x2 = (int) (endOnGenome * pixelPerCode);
129
130 if (startOnGenome <= endOnGenome) {
131 int rangeWidth = x2 - x1;
132 if (rangeWidth <= 0)
133 rangeWidth = 1;
134 range.setWidth(rangeWidth + "px");
135 _basePanel.add(range, x1, 0);
136 }
137 else {
138 int rangeWidth = x1 - x2;
139 if (rangeWidth <= 0)
140 rangeWidth = 1;
141 range.setWidth(rangeWidth + "px");
142 _basePanel.add(range, windowWidth - x1, 0);
143 }
144 }
145
146 @Override
147 public void draw() {
148 _basePanel.clear();
149
150
151 _layoutPanel.setWidget(0, 1, _basePanel);
152
153 TrackWindow w = getTrackGroup().getTrackWindow();
154 int windowWidth = w.getPixelWidth();
155 int sequenceSize = getSequenceSize();
156 _ruler.updateTickUnit(windowWidth, 1, sequenceSize);
157 _ruler.draw(_basePanel, windowWidth, 1, sequenceSize, w.getStartOnGenome() > w.getEndOnGenome());
158 drawTrackSelectionRange(w);
159 }
160
161 public AbsoluteFocusPanel getAbsoluteFocusPanel() {
162 return _basePanel;
163 }
164
165 public void onRangeSelect(int x1OnTrackWindow, int x2OnTrackWindow) {
166 TrackWindow window = getTrackGroup().getTrackWindow();
167 int width = window.getPixelWidth();
168 int sequenceSize = getSequenceSize();
169 double genomeLengthPerPixel = (double) sequenceSize / width;
170
171 if (!window.isReverseStrand()) {
172 int startOnGenome = (int) (x1OnTrackWindow * genomeLengthPerPixel);
173 int endOnGenome = (int) (x2OnTrackWindow * genomeLengthPerPixel);
174 getTrackGroup().getPropertyWriter().setTrackWindow(startOnGenome, endOnGenome);
175 }
176 else {
177 int startOnGenome = (int) ((width - x1OnTrackWindow) * genomeLengthPerPixel);
178 int endOnGenome = (int) ((width - x2OnTrackWindow) * genomeLengthPerPixel);
179 getTrackGroup().getPropertyWriter().setTrackWindow(startOnGenome, endOnGenome);
180 }
181 }
182
183 @Override
184 public void setUp(TrackFrame trackFrame, TrackGroup group) {
185
186 TrackWindow w = group.getTrackWindow();
187
188
189
190 ValueDomain windowSizeDomain = new ValueDomain();
191 windowSizeDomain.addValueList(new Value("1K", "1000"));
192 windowSizeDomain.addValueList(new Value("10K", "10000"));
193 windowSizeDomain.addValueList(new Value("100K", "100000"));
194 windowSizeDomain.addValueList(new Value("1M", "1000000"));
195 windowSizeDomain.addValueList(new Value("10M", "10000000"));
196 windowSizeDomain.addValueList(new Value("100M", "100000000"));
197 windowSizeDomain.addValueList(new Value("1G", "1000000000"));
198 getConfig().addConfig("Sequence Ruler Size", new IntegerType(UTGBProperty.SEQUENCE_SIZE, windowSizeDomain), "1000000");
199
200
201 trackFrame.pack();
202 trackFrame.disablePack();
203 trackFrame.disableResize();
204
205 }
206
207 @Override
208 public void onChangeTrackConfig(TrackConfigChange change) {
209 if (change.contains(UTGBProperty.SEQUENCE_SIZE))
210 refresh();
211 }
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250 }