1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.appletgui; |
22 |
|
|
23 |
|
import jalview.datamodel.SequenceFeature; |
24 |
|
import jalview.datamodel.SequenceGroup; |
25 |
|
import jalview.datamodel.SequenceI; |
26 |
|
import jalview.urls.api.UrlProviderFactoryI; |
27 |
|
import jalview.urls.api.UrlProviderI; |
28 |
|
import jalview.urls.applet.AppletUrlProviderFactory; |
29 |
|
import jalview.viewmodel.AlignmentViewport; |
30 |
|
|
31 |
|
import java.awt.BorderLayout; |
32 |
|
import java.awt.Panel; |
33 |
|
import java.awt.event.InputEvent; |
34 |
|
import java.awt.event.MouseEvent; |
35 |
|
import java.awt.event.MouseListener; |
36 |
|
import java.awt.event.MouseMotionListener; |
37 |
|
import java.util.ArrayList; |
38 |
|
import java.util.HashMap; |
39 |
|
import java.util.List; |
40 |
|
|
|
|
| 0% |
Uncovered Elements: 236 (236) |
Complexity: 63 |
Complexity Density: 0.43 |
|
41 |
|
public class IdPanel extends Panel |
42 |
|
implements MouseListener, MouseMotionListener |
43 |
|
{ |
44 |
|
|
45 |
|
protected IdCanvas idCanvas; |
46 |
|
|
47 |
|
protected AlignmentViewport av; |
48 |
|
|
49 |
|
protected AlignmentPanel alignPanel; |
50 |
|
|
51 |
|
ScrollThread scrollThread = null; |
52 |
|
|
53 |
|
int lastid = -1; |
54 |
|
|
55 |
|
boolean mouseDragging = false; |
56 |
|
|
57 |
|
UrlProviderI urlProvider = null; |
58 |
|
|
|
|
| 0% |
Uncovered Elements: 27 (27) |
Complexity: 5 |
Complexity Density: 0.26 |
|
59 |
0 |
public IdPanel(AlignViewport viewport, AlignmentPanel parent)... |
60 |
|
{ |
61 |
0 |
this.av = viewport; |
62 |
0 |
alignPanel = parent; |
63 |
0 |
idCanvas = new IdCanvas(viewport); |
64 |
0 |
setLayout(new BorderLayout()); |
65 |
0 |
add(idCanvas, BorderLayout.CENTER); |
66 |
0 |
idCanvas.addMouseListener(this); |
67 |
0 |
idCanvas.addMouseMotionListener(this); |
68 |
|
|
69 |
0 |
String label, url; |
70 |
|
|
71 |
|
|
72 |
|
|
73 |
0 |
HashMap<String, String> urlList = new HashMap<>(); |
74 |
0 |
if (viewport.applet != null) |
75 |
|
{ |
76 |
0 |
for (int i = 1; i < 10; i++) |
77 |
|
{ |
78 |
0 |
label = viewport.applet.getParameter("linkLabel_" + i); |
79 |
0 |
url = viewport.applet.getParameter("linkURL_" + i); |
80 |
|
|
81 |
|
|
82 |
0 |
if (label != null) |
83 |
|
{ |
84 |
0 |
urlList.put(label, url); |
85 |
|
} |
86 |
|
} |
87 |
|
|
88 |
0 |
if (!urlList.isEmpty()) |
89 |
|
{ |
90 |
|
|
91 |
0 |
String defaultUrl = viewport.applet.getParameter("linkLabel_1"); |
92 |
0 |
UrlProviderFactoryI factory = new AppletUrlProviderFactory( |
93 |
|
defaultUrl, urlList); |
94 |
0 |
urlProvider = factory.createUrlProvider(); |
95 |
|
} |
96 |
|
} |
97 |
|
} |
98 |
|
|
99 |
|
Tooltip tooltip; |
100 |
|
|
|
|
| 0% |
Uncovered Elements: 64 (64) |
Complexity: 14 |
Complexity Density: 0.33 |
|
101 |
0 |
@Override... |
102 |
|
public void mouseMoved(MouseEvent e) |
103 |
|
{ |
104 |
0 |
int seq = alignPanel.seqPanel.findSeq(e); |
105 |
|
|
106 |
0 |
SequenceI sequence = av.getAlignment().getSequenceAt(seq); |
107 |
|
|
108 |
0 |
StringBuffer tooltiptext = new StringBuffer(); |
109 |
0 |
if (sequence == null) |
110 |
|
{ |
111 |
0 |
return; |
112 |
|
} |
113 |
0 |
if (sequence.getDescription() != null) |
114 |
|
{ |
115 |
0 |
tooltiptext.append(sequence.getDescription()); |
116 |
0 |
tooltiptext.append("\n"); |
117 |
|
} |
118 |
|
|
119 |
0 |
for (SequenceFeature sf : sequence.getFeatures() |
120 |
|
.getNonPositionalFeatures()) |
121 |
|
{ |
122 |
0 |
boolean nl = false; |
123 |
0 |
if (sf.getFeatureGroup() != null) |
124 |
|
{ |
125 |
0 |
tooltiptext.append(sf.getFeatureGroup()); |
126 |
0 |
nl = true; |
127 |
|
} |
128 |
0 |
if (sf.getType() != null) |
129 |
|
{ |
130 |
0 |
tooltiptext.append(" "); |
131 |
0 |
tooltiptext.append(sf.getType()); |
132 |
0 |
nl = true; |
133 |
|
} |
134 |
0 |
if (sf.getDescription() != null) |
135 |
|
{ |
136 |
0 |
tooltiptext.append(" "); |
137 |
0 |
tooltiptext.append(sf.getDescription()); |
138 |
0 |
nl = true; |
139 |
|
} |
140 |
0 |
if (!Float.isNaN(sf.getScore()) && sf.getScore() != 0f) |
141 |
|
{ |
142 |
0 |
tooltiptext.append(" Score = "); |
143 |
0 |
tooltiptext.append(sf.getScore()); |
144 |
0 |
nl = true; |
145 |
|
} |
146 |
0 |
if (sf.getStatus() != null && sf.getStatus().length() > 0) |
147 |
|
{ |
148 |
0 |
tooltiptext.append(" ("); |
149 |
0 |
tooltiptext.append(sf.getStatus()); |
150 |
0 |
tooltiptext.append(")"); |
151 |
0 |
nl = true; |
152 |
|
} |
153 |
0 |
if (nl) |
154 |
|
{ |
155 |
0 |
tooltiptext.append("\n"); |
156 |
|
} |
157 |
|
} |
158 |
|
|
159 |
0 |
if (tooltiptext.length() == 0) |
160 |
|
{ |
161 |
|
|
162 |
0 |
if (tooltip != null) |
163 |
|
{ |
164 |
0 |
tooltip.setVisible(false); |
165 |
|
} |
166 |
0 |
tooltip = null; |
167 |
0 |
tooltiptext = null; |
168 |
0 |
return; |
169 |
|
} |
170 |
0 |
if (tooltip == null) |
171 |
|
{ |
172 |
0 |
tooltip = new Tooltip( |
173 |
|
sequence.getDisplayId(true) + "\n" + tooltiptext.toString(), |
174 |
|
idCanvas); |
175 |
|
} |
176 |
|
else |
177 |
|
{ |
178 |
0 |
tooltip.setTip( |
179 |
|
sequence.getDisplayId(true) + "\n" + tooltiptext.toString()); |
180 |
|
} |
181 |
0 |
tooltiptext = null; |
182 |
|
} |
183 |
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 3 |
Complexity Density: 0.38 |
|
184 |
0 |
@Override... |
185 |
|
public void mouseDragged(MouseEvent e) |
186 |
|
{ |
187 |
0 |
mouseDragging = true; |
188 |
|
|
189 |
0 |
int seq = Math.max(0, alignPanel.seqPanel.findSeq(e)); |
190 |
|
|
191 |
0 |
if (seq < lastid) |
192 |
|
{ |
193 |
0 |
selectSeqs(lastid - 1, seq); |
194 |
|
} |
195 |
0 |
else if (seq > lastid) |
196 |
|
{ |
197 |
0 |
selectSeqs(lastid + 1, seq); |
198 |
|
} |
199 |
|
|
200 |
0 |
lastid = seq; |
201 |
0 |
alignPanel.paintAlignment(false, false); |
202 |
|
} |
203 |
|
|
|
|
| 0% |
Uncovered Elements: 20 (20) |
Complexity: 5 |
Complexity Density: 0.36 |
|
204 |
0 |
@Override... |
205 |
|
public void mouseClicked(MouseEvent e) |
206 |
|
{ |
207 |
0 |
if (e.getClickCount() < 2) |
208 |
|
{ |
209 |
0 |
return; |
210 |
|
} |
211 |
|
|
212 |
|
|
213 |
0 |
int seq = alignPanel.seqPanel.findSeq(e); |
214 |
0 |
SequenceI sq = av.getAlignment().getSequenceAt(seq); |
215 |
0 |
if (sq == null) |
216 |
|
{ |
217 |
0 |
return; |
218 |
|
} |
219 |
0 |
String id = sq.getName(); |
220 |
|
|
221 |
|
|
222 |
0 |
if (urlProvider == null) |
223 |
|
{ |
224 |
0 |
return; |
225 |
|
} |
226 |
0 |
String url = urlProvider.getPrimaryUrl(id); |
227 |
0 |
String target = urlProvider.getPrimaryTarget(id); |
228 |
0 |
try |
229 |
|
{ |
230 |
0 |
alignPanel.alignFrame.showURL(url, target); |
231 |
|
} catch (Exception ex) |
232 |
|
{ |
233 |
0 |
ex.printStackTrace(); |
234 |
|
} |
235 |
|
} |
236 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
237 |
0 |
@Override... |
238 |
|
public void mouseEntered(MouseEvent e) |
239 |
|
{ |
240 |
0 |
if (scrollThread != null) |
241 |
|
{ |
242 |
0 |
scrollThread.running = false; |
243 |
|
} |
244 |
|
} |
245 |
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 8 |
Complexity Density: 1.33 |
|
246 |
0 |
@Override... |
247 |
|
public void mouseExited(MouseEvent e) |
248 |
|
{ |
249 |
0 |
if (av.getWrapAlignment()) |
250 |
|
{ |
251 |
0 |
return; |
252 |
|
} |
253 |
|
|
254 |
0 |
if (mouseDragging && e.getY() < 0 && av.getRanges().getStartSeq() > 0) |
255 |
|
{ |
256 |
0 |
scrollThread = new ScrollThread(true); |
257 |
|
} |
258 |
|
|
259 |
0 |
if (mouseDragging && e.getY() >= getSize().height |
260 |
|
&& av.getAlignment().getHeight() > av.getRanges().getEndSeq()) |
261 |
|
{ |
262 |
0 |
scrollThread = new ScrollThread(false); |
263 |
|
} |
264 |
|
} |
265 |
|
|
|
|
| 0% |
Uncovered Elements: 42 (42) |
Complexity: 12 |
Complexity Density: 0.43 |
|
266 |
0 |
@Override... |
267 |
|
public void mousePressed(MouseEvent e) |
268 |
|
{ |
269 |
0 |
if (e.getClickCount() > 1) |
270 |
|
{ |
271 |
0 |
return; |
272 |
|
} |
273 |
|
|
274 |
0 |
int y = e.getY(); |
275 |
0 |
if (av.getWrapAlignment()) |
276 |
|
{ |
277 |
0 |
y -= 2 * av.getCharHeight(); |
278 |
|
} |
279 |
|
|
280 |
0 |
int seq = alignPanel.seqPanel.findSeq(e); |
281 |
|
|
282 |
0 |
if ((e.getModifiersEx() |
283 |
|
& InputEvent.BUTTON3_DOWN_MASK) == InputEvent.BUTTON3_DOWN_MASK) |
284 |
|
{ |
285 |
0 |
SequenceI sq = av.getAlignment().getSequenceAt(seq); |
286 |
|
|
287 |
|
|
288 |
|
|
289 |
|
|
290 |
|
|
291 |
0 |
List<String> nlinks; |
292 |
0 |
if (urlProvider != null) |
293 |
|
{ |
294 |
0 |
nlinks = urlProvider.getLinksForMenu(); |
295 |
|
} |
296 |
|
else |
297 |
|
{ |
298 |
0 |
nlinks = new ArrayList<>(); |
299 |
|
} |
300 |
|
|
301 |
0 |
for (SequenceFeature sf : sq.getFeatures().getNonPositionalFeatures()) |
302 |
|
{ |
303 |
0 |
if (sf.links != null) |
304 |
|
{ |
305 |
0 |
for (String link : sf.links) |
306 |
|
{ |
307 |
0 |
nlinks.add(link); |
308 |
|
} |
309 |
|
} |
310 |
|
} |
311 |
|
|
312 |
0 |
APopupMenu popup = new APopupMenu(alignPanel, sq, nlinks); |
313 |
0 |
this.add(popup); |
314 |
0 |
popup.show(this, e.getX(), e.getY()); |
315 |
0 |
return; |
316 |
|
} |
317 |
|
|
318 |
0 |
if ((av.getSelectionGroup() == null) |
319 |
|
|| ((!jalview.util.Platform.isControlDown(e) |
320 |
|
&& !e.isShiftDown()) && av.getSelectionGroup() != null)) |
321 |
|
{ |
322 |
0 |
av.setSelectionGroup(new SequenceGroup()); |
323 |
0 |
av.getSelectionGroup().setStartRes(0); |
324 |
0 |
av.getSelectionGroup().setEndRes(av.getAlignment().getWidth() - 1); |
325 |
|
} |
326 |
|
|
327 |
0 |
if (e.isShiftDown() && lastid != -1) |
328 |
|
{ |
329 |
0 |
selectSeqs(lastid, seq); |
330 |
|
} |
331 |
|
else |
332 |
|
{ |
333 |
0 |
selectSeq(seq); |
334 |
|
} |
335 |
|
|
336 |
0 |
alignPanel.paintAlignment(false, false); |
337 |
|
} |
338 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
339 |
0 |
void selectSeq(int seq)... |
340 |
|
{ |
341 |
0 |
lastid = seq; |
342 |
0 |
SequenceI pickedSeq = av.getAlignment().getSequenceAt(seq); |
343 |
0 |
av.getSelectionGroup().addOrRemove(pickedSeq, true); |
344 |
|
} |
345 |
|
|
|
|
| 0% |
Uncovered Elements: 20 (20) |
Complexity: 5 |
Complexity Density: 0.42 |
|
346 |
0 |
void selectSeqs(int start, int end)... |
347 |
|
{ |
348 |
|
|
349 |
0 |
lastid = start; |
350 |
|
|
351 |
0 |
if (end >= av.getAlignment().getHeight()) |
352 |
|
{ |
353 |
0 |
end = av.getAlignment().getHeight() - 1; |
354 |
|
} |
355 |
|
|
356 |
0 |
if (end < start) |
357 |
|
{ |
358 |
0 |
int tmp = start; |
359 |
0 |
start = end; |
360 |
0 |
end = tmp; |
361 |
0 |
lastid = end; |
362 |
|
} |
363 |
0 |
if (av.getSelectionGroup() == null) |
364 |
|
{ |
365 |
0 |
av.setSelectionGroup(new SequenceGroup()); |
366 |
|
} |
367 |
0 |
for (int i = start; i <= end; i++) |
368 |
|
{ |
369 |
0 |
av.getSelectionGroup().addSequence(av.getAlignment().getSequenceAt(i), |
370 |
|
i == end); |
371 |
|
} |
372 |
|
|
373 |
|
} |
374 |
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 3 |
Complexity Density: 0.43 |
|
375 |
0 |
@Override... |
376 |
|
public void mouseReleased(MouseEvent e) |
377 |
|
{ |
378 |
0 |
if (scrollThread != null) |
379 |
|
{ |
380 |
0 |
scrollThread.running = false; |
381 |
|
} |
382 |
|
|
383 |
0 |
if (av.getSelectionGroup() != null) |
384 |
|
{ |
385 |
0 |
av.getSelectionGroup().recalcConservation(); |
386 |
|
} |
387 |
|
|
388 |
0 |
mouseDragging = false; |
389 |
0 |
PaintRefresher.Refresh(this, av.getSequenceSetId()); |
390 |
|
|
391 |
0 |
av.sendSelection(); |
392 |
|
} |
393 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 5 |
Complexity Density: 0.83 |
|
394 |
0 |
public void highlightSearchResults(List<SequenceI> list)... |
395 |
|
{ |
396 |
0 |
idCanvas.setHighlighted(list); |
397 |
|
|
398 |
0 |
if (list == null || list.isEmpty()) |
399 |
|
{ |
400 |
0 |
return; |
401 |
|
} |
402 |
|
|
403 |
0 |
int index = av.getAlignment().findIndex(list.get(0)); |
404 |
|
|
405 |
|
|
406 |
0 |
if (av.getRanges().getStartSeq() > index |
407 |
|
|| av.getRanges().getEndSeq() < index) |
408 |
|
{ |
409 |
0 |
av.getRanges().setStartSeq(index); |
410 |
|
} |
411 |
|
} |
412 |
|
|
413 |
|
|
|
|
| 0% |
Uncovered Elements: 31 (31) |
Complexity: 10 |
Complexity Density: 0.56 |
|
414 |
|
class ScrollThread extends Thread |
415 |
|
{ |
416 |
|
boolean running = false; |
417 |
|
|
418 |
|
boolean up = true; |
419 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
420 |
0 |
public ScrollThread(boolean isUp)... |
421 |
|
{ |
422 |
0 |
this.up = isUp; |
423 |
0 |
start(); |
424 |
|
} |
425 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
426 |
0 |
public void stopScrolling()... |
427 |
|
{ |
428 |
0 |
running = false; |
429 |
|
} |
430 |
|
|
|
|
| 0% |
Uncovered Elements: 25 (25) |
Complexity: 8 |
Complexity Density: 0.53 |
|
431 |
0 |
@Override... |
432 |
|
public void run() |
433 |
|
{ |
434 |
0 |
running = true; |
435 |
0 |
while (running) |
436 |
|
{ |
437 |
0 |
if (av.getRanges().scrollUp(up)) |
438 |
|
{ |
439 |
|
|
440 |
0 |
int seq = av.getRanges().getStartSeq(); |
441 |
0 |
if (!up) |
442 |
|
{ |
443 |
0 |
seq = av.getRanges().getEndSeq(); |
444 |
|
} |
445 |
|
|
446 |
0 |
if (seq < lastid) |
447 |
|
{ |
448 |
0 |
selectSeqs(lastid - 1, seq); |
449 |
|
} |
450 |
0 |
else if (seq > lastid && seq < av.getAlignment().getHeight()) |
451 |
|
{ |
452 |
0 |
selectSeqs(lastid + 1, seq); |
453 |
|
} |
454 |
|
|
455 |
0 |
lastid = seq; |
456 |
|
} |
457 |
|
else |
458 |
|
{ |
459 |
0 |
running = false; |
460 |
|
} |
461 |
|
|
462 |
0 |
alignPanel.paintAlignment(true, false); |
463 |
0 |
try |
464 |
|
{ |
465 |
0 |
Thread.sleep(100); |
466 |
|
} catch (Exception ex) |
467 |
|
{ |
468 |
|
} |
469 |
|
} |
470 |
|
} |
471 |
|
} |
472 |
|
} |