1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.gui; |
22 |
|
|
23 |
|
import jalview.analysis.Conservation; |
24 |
|
import jalview.analysis.TreeModel; |
25 |
|
import jalview.api.AlignViewportI; |
26 |
|
import jalview.datamodel.Sequence; |
27 |
|
import jalview.datamodel.SequenceGroup; |
28 |
|
import jalview.datamodel.SequenceI; |
29 |
|
import jalview.datamodel.SequenceNode; |
30 |
|
import jalview.gui.JalviewColourChooser.ColourChooserListener; |
31 |
|
import jalview.schemes.ColourSchemeI; |
32 |
|
import jalview.schemes.ColourSchemeProperty; |
33 |
|
import jalview.schemes.UserColourScheme; |
34 |
|
import jalview.structure.SelectionSource; |
35 |
|
import jalview.util.Format; |
36 |
|
import jalview.util.MappingUtils; |
37 |
|
import jalview.util.MessageManager; |
38 |
|
|
39 |
|
import java.awt.Color; |
40 |
|
import java.awt.Dimension; |
41 |
|
import java.awt.Font; |
42 |
|
import java.awt.FontMetrics; |
43 |
|
import java.awt.Graphics; |
44 |
|
import java.awt.Graphics2D; |
45 |
|
import java.awt.Point; |
46 |
|
import java.awt.Rectangle; |
47 |
|
import java.awt.RenderingHints; |
48 |
|
import java.awt.event.MouseEvent; |
49 |
|
import java.awt.event.MouseListener; |
50 |
|
import java.awt.event.MouseMotionListener; |
51 |
|
import java.awt.print.PageFormat; |
52 |
|
import java.awt.print.Printable; |
53 |
|
import java.awt.print.PrinterException; |
54 |
|
import java.awt.print.PrinterJob; |
55 |
|
import java.util.Enumeration; |
56 |
|
import java.util.Hashtable; |
57 |
|
import java.util.List; |
58 |
|
import java.util.Vector; |
59 |
|
|
60 |
|
import javax.swing.JColorChooser; |
61 |
|
import javax.swing.JPanel; |
62 |
|
import javax.swing.JScrollPane; |
63 |
|
import javax.swing.SwingUtilities; |
64 |
|
import javax.swing.ToolTipManager; |
65 |
|
|
66 |
|
|
67 |
|
|
68 |
|
|
69 |
|
@author |
70 |
|
@version |
71 |
|
|
|
|
| 28.3% |
Uncovered Elements: 363 (506) |
Complexity: 125 |
Complexity Density: 0.39 |
|
72 |
|
public class TreeCanvas extends JPanel implements MouseListener, Runnable, |
73 |
|
Printable, MouseMotionListener, SelectionSource |
74 |
|
{ |
75 |
|
|
76 |
|
public static final String PLACEHOLDER = " * "; |
77 |
|
|
78 |
|
TreeModel tree; |
79 |
|
|
80 |
|
JScrollPane scrollPane; |
81 |
|
|
82 |
|
TreePanel tp; |
83 |
|
|
84 |
|
AlignViewport av; |
85 |
|
|
86 |
|
AlignmentPanel ap; |
87 |
|
|
88 |
|
Font font; |
89 |
|
|
90 |
|
FontMetrics fm; |
91 |
|
|
92 |
|
boolean fitToWindow = true; |
93 |
|
|
94 |
|
boolean showDistances = false; |
95 |
|
|
96 |
|
boolean showBootstrap = false; |
97 |
|
|
98 |
|
boolean markPlaceholders = false; |
99 |
|
|
100 |
|
int offx = 20; |
101 |
|
|
102 |
|
int offy; |
103 |
|
|
104 |
|
float threshold; |
105 |
|
|
106 |
|
String longestName; |
107 |
|
|
108 |
|
int labelLength = -1; |
109 |
|
|
110 |
|
Hashtable nameHash = new Hashtable(); |
111 |
|
|
112 |
|
Hashtable nodeHash = new Hashtable(); |
113 |
|
|
114 |
|
SequenceNode highlightNode; |
115 |
|
|
116 |
|
boolean applyToAllViews = false; |
117 |
|
|
118 |
|
|
119 |
|
|
120 |
|
|
121 |
|
@param |
122 |
|
|
123 |
|
@param |
124 |
|
|
125 |
|
@param |
126 |
|
|
127 |
|
@param |
128 |
|
|
129 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
|
130 |
12 |
public TreeCanvas(TreePanel tp, AlignmentPanel ap, JScrollPane scroller)... |
131 |
|
{ |
132 |
12 |
this.tp = tp; |
133 |
12 |
this.av = ap.av; |
134 |
12 |
this.ap = ap; |
135 |
12 |
font = av.getFont(); |
136 |
12 |
scrollPane = scroller; |
137 |
12 |
addMouseListener(this); |
138 |
12 |
addMouseMotionListener(this); |
139 |
12 |
ToolTipManager.sharedInstance().registerComponent(this); |
140 |
|
} |
141 |
|
|
142 |
|
|
143 |
|
|
144 |
|
|
145 |
|
@param |
146 |
|
|
147 |
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 3 |
Complexity Density: 0.38 |
|
148 |
0 |
public void treeSelectionChanged(SequenceI sequence)... |
149 |
|
{ |
150 |
0 |
AlignmentPanel[] aps = getAssociatedPanels(); |
151 |
|
|
152 |
0 |
for (int a = 0; a < aps.length; a++) |
153 |
|
{ |
154 |
0 |
SequenceGroup selected = aps[a].av.getSelectionGroup(); |
155 |
|
|
156 |
0 |
if (selected == null) |
157 |
|
{ |
158 |
0 |
selected = new SequenceGroup(); |
159 |
0 |
aps[a].av.setSelectionGroup(selected); |
160 |
|
} |
161 |
|
|
162 |
0 |
selected.setEndRes(aps[a].av.getAlignment().getWidth() - 1); |
163 |
0 |
selected.addOrRemove(sequence, true); |
164 |
|
} |
165 |
|
} |
166 |
|
|
167 |
|
|
168 |
|
|
169 |
|
|
170 |
|
@param |
171 |
|
|
172 |
|
|
|
|
| 88.9% |
Uncovered Elements: 2 (18) |
Complexity: 4 |
Complexity Density: 0.33 |
|
173 |
12 |
public void setTree(TreeModel tree)... |
174 |
|
{ |
175 |
12 |
this.tree = tree; |
176 |
12 |
tree.findHeight(tree.getTopNode()); |
177 |
|
|
178 |
|
|
179 |
12 |
Vector<SequenceNode> leaves = tree.findLeaves(tree.getTopNode()); |
180 |
12 |
boolean has_placeholders = false; |
181 |
12 |
longestName = ""; |
182 |
|
|
183 |
132 |
for (int i = 0; i < leaves.size(); i++) |
184 |
|
{ |
185 |
120 |
SequenceNode lf = leaves.elementAt(i); |
186 |
|
|
187 |
120 |
if (lf.isPlaceholder()) |
188 |
|
{ |
189 |
0 |
has_placeholders = true; |
190 |
|
} |
191 |
|
|
192 |
120 |
if (longestName.length() < ((Sequence) lf.element()).getName() |
193 |
|
.length()) |
194 |
|
{ |
195 |
24 |
longestName = TreeCanvas.PLACEHOLDER |
196 |
|
+ ((Sequence) lf.element()).getName(); |
197 |
|
} |
198 |
|
} |
199 |
|
|
200 |
12 |
setMarkPlaceholders(has_placeholders); |
201 |
|
} |
202 |
|
|
203 |
|
|
204 |
|
|
205 |
|
|
206 |
|
@param |
207 |
|
|
208 |
|
@param |
209 |
|
|
210 |
|
@param |
211 |
|
|
212 |
|
@param |
213 |
|
|
214 |
|
@param |
215 |
|
|
216 |
|
@param |
217 |
|
|
218 |
|
@param |
219 |
|
|
220 |
|
|
|
|
| 63.5% |
Uncovered Elements: 35 (96) |
Complexity: 25 |
Complexity Density: 0.4 |
|
221 |
6802 |
public void drawNode(Graphics g, SequenceNode node, float chunk,... |
222 |
|
double wscale, int width, int offx, int offy) |
223 |
|
{ |
224 |
6802 |
if (node == null) |
225 |
|
{ |
226 |
0 |
return; |
227 |
|
} |
228 |
|
|
229 |
6802 |
if ((node.left() == null) && (node.right() == null)) |
230 |
|
{ |
231 |
|
|
232 |
3580 |
double height = node.height; |
233 |
3580 |
double dist = node.dist; |
234 |
|
|
235 |
3580 |
int xstart = (int) ((height - dist) * wscale) + offx; |
236 |
3580 |
int xend = (int) (height * wscale) + offx; |
237 |
|
|
238 |
3580 |
int ypos = (int) (node.ycount * chunk) + offy; |
239 |
|
|
240 |
3580 |
if (node.element() instanceof SequenceI) |
241 |
|
{ |
242 |
3580 |
SequenceI seq = (SequenceI) node.element(); |
243 |
|
|
244 |
3580 |
if (av.getSequenceColour(seq) == Color.white) |
245 |
|
{ |
246 |
0 |
g.setColor(Color.black); |
247 |
|
} |
248 |
|
else |
249 |
|
{ |
250 |
3580 |
g.setColor(av.getSequenceColour(seq).darker()); |
251 |
|
} |
252 |
|
} |
253 |
|
else |
254 |
|
{ |
255 |
0 |
g.setColor(Color.black); |
256 |
|
} |
257 |
|
|
258 |
|
|
259 |
3580 |
g.drawLine(xstart, ypos, xend, ypos); |
260 |
|
|
261 |
3580 |
String nodeLabel = ""; |
262 |
|
|
263 |
3580 |
if (showDistances && (node.dist > 0)) |
264 |
|
{ |
265 |
0 |
nodeLabel = new Format("%-.2f").form(node.dist); |
266 |
|
} |
267 |
|
|
268 |
3580 |
if (showBootstrap && node.bootstrap > -1) |
269 |
|
{ |
270 |
0 |
if (showDistances) |
271 |
|
{ |
272 |
0 |
nodeLabel = nodeLabel + " : "; |
273 |
|
} |
274 |
|
|
275 |
0 |
nodeLabel = nodeLabel + String.valueOf(node.bootstrap); |
276 |
|
} |
277 |
|
|
278 |
3580 |
if (!nodeLabel.equals("")) |
279 |
|
{ |
280 |
0 |
g.drawString(nodeLabel, xstart + 2, ypos - 2); |
281 |
|
} |
282 |
|
|
283 |
3580 |
String name = (markPlaceholders && node.isPlaceholder()) |
284 |
|
? (PLACEHOLDER + node.getName()) |
285 |
|
: node.getName(); |
286 |
|
|
287 |
3580 |
int charWidth = fm.stringWidth(name) + 3; |
288 |
3580 |
int charHeight = font.getSize(); |
289 |
|
|
290 |
3580 |
Rectangle rect = new Rectangle(xend + 10, ypos - charHeight / 2, |
291 |
|
charWidth, charHeight); |
292 |
|
|
293 |
3580 |
nameHash.put(node.element(), rect); |
294 |
|
|
295 |
|
|
296 |
3580 |
SequenceGroup selected = av.getSelectionGroup(); |
297 |
|
|
298 |
3580 |
if ((selected != null) |
299 |
|
&& selected.getSequences(null).contains(node.element())) |
300 |
|
{ |
301 |
0 |
g.setColor(Color.gray); |
302 |
|
|
303 |
0 |
g.fillRect(xend + 10, ypos - charHeight / 2, charWidth, charHeight); |
304 |
0 |
g.setColor(Color.white); |
305 |
|
} |
306 |
|
|
307 |
3580 |
g.drawString(name, xend + 10, ypos + fm.getDescent()); |
308 |
3580 |
g.setColor(Color.black); |
309 |
|
} |
310 |
|
else |
311 |
|
{ |
312 |
3222 |
drawNode(g, (SequenceNode) node.left(), chunk, wscale, width, offx, |
313 |
|
offy); |
314 |
3222 |
drawNode(g, (SequenceNode) node.right(), chunk, wscale, width, offx, |
315 |
|
offy); |
316 |
|
|
317 |
3222 |
double height = node.height; |
318 |
3222 |
double dist = node.dist; |
319 |
|
|
320 |
3222 |
int xstart = (int) ((height - dist) * wscale) + offx; |
321 |
3222 |
int xend = (int) (height * wscale) + offx; |
322 |
3222 |
int ypos = (int) (node.ycount * chunk) + offy; |
323 |
|
|
324 |
3222 |
g.setColor(node.color.darker()); |
325 |
|
|
326 |
|
|
327 |
3222 |
g.drawLine(xstart, ypos, xend, ypos); |
328 |
3222 |
if (node == highlightNode) |
329 |
|
{ |
330 |
0 |
g.fillRect(xend - 3, ypos - 3, 6, 6); |
331 |
|
} |
332 |
|
else |
333 |
|
{ |
334 |
3222 |
g.fillRect(xend - 2, ypos - 2, 4, 4); |
335 |
|
} |
336 |
|
|
337 |
3222 |
int ystart = (node.left() == null ? 0 |
338 |
|
: (int) (((SequenceNode) node.left()).ycount * chunk)) + offy; |
339 |
3222 |
int yend = (node.right() == null ? 0 |
340 |
|
: (int) (((SequenceNode) node.right()).ycount * chunk)) |
341 |
|
+ offy; |
342 |
|
|
343 |
3222 |
Rectangle pos = new Rectangle(xend - 2, ypos - 2, 5, 5); |
344 |
3222 |
nodeHash.put(node, pos); |
345 |
|
|
346 |
3222 |
g.drawLine((int) (height * wscale) + offx, ystart, |
347 |
|
(int) (height * wscale) + offx, yend); |
348 |
|
|
349 |
3222 |
String nodeLabel = ""; |
350 |
|
|
351 |
3222 |
if (showDistances && (node.dist > 0)) |
352 |
|
{ |
353 |
0 |
nodeLabel = new Format("%-.2f").form(node.dist); |
354 |
|
} |
355 |
|
|
356 |
3222 |
if (showBootstrap && node.bootstrap > -1) |
357 |
|
{ |
358 |
0 |
if (showDistances) |
359 |
|
{ |
360 |
0 |
nodeLabel = nodeLabel + " : "; |
361 |
|
} |
362 |
|
|
363 |
0 |
nodeLabel = nodeLabel + String.valueOf(node.bootstrap); |
364 |
|
} |
365 |
|
|
366 |
3222 |
if (!nodeLabel.equals("")) |
367 |
|
{ |
368 |
0 |
g.drawString(nodeLabel, xstart + 2, ypos - 2); |
369 |
|
} |
370 |
|
} |
371 |
|
} |
372 |
|
|
373 |
|
|
374 |
|
|
375 |
|
|
376 |
|
@param |
377 |
|
|
378 |
|
@param |
379 |
|
|
380 |
|
|
381 |
|
@return |
382 |
|
|
|
|
| 0% |
Uncovered Elements: 21 (21) |
Complexity: 11 |
Complexity Density: 0.85 |
|
383 |
0 |
public Object findElement(int x, int y)... |
384 |
|
{ |
385 |
0 |
Enumeration keys = nameHash.keys(); |
386 |
|
|
387 |
0 |
while (keys.hasMoreElements()) |
388 |
|
{ |
389 |
0 |
Object ob = keys.nextElement(); |
390 |
0 |
Rectangle rect = (Rectangle) nameHash.get(ob); |
391 |
|
|
392 |
0 |
if ((x >= rect.x) && (x <= (rect.x + rect.width)) && (y >= rect.y) |
393 |
|
&& (y <= (rect.y + rect.height))) |
394 |
|
{ |
395 |
0 |
return ob; |
396 |
|
} |
397 |
|
} |
398 |
|
|
399 |
0 |
keys = nodeHash.keys(); |
400 |
|
|
401 |
0 |
while (keys.hasMoreElements()) |
402 |
|
{ |
403 |
0 |
Object ob = keys.nextElement(); |
404 |
0 |
Rectangle rect = (Rectangle) nodeHash.get(ob); |
405 |
|
|
406 |
0 |
if ((x >= rect.x) && (x <= (rect.x + rect.width)) && (y >= rect.y) |
407 |
|
&& (y <= (rect.y + rect.height))) |
408 |
|
{ |
409 |
0 |
return ob; |
410 |
|
} |
411 |
|
} |
412 |
|
|
413 |
0 |
return null; |
414 |
|
} |
415 |
|
|
416 |
|
|
417 |
|
|
418 |
|
|
419 |
|
@param |
420 |
|
|
421 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 2 |
Complexity Density: 0.25 |
|
422 |
0 |
public void pickNodes(Rectangle pickBox)... |
423 |
|
{ |
424 |
0 |
int width = getWidth(); |
425 |
0 |
int height = getHeight(); |
426 |
|
|
427 |
0 |
SequenceNode top = tree.getTopNode(); |
428 |
|
|
429 |
0 |
double wscale = ((width * .8) - (offx * 2)) / tree.getMaxHeight(); |
430 |
|
|
431 |
0 |
if (top.count == 0) |
432 |
|
{ |
433 |
0 |
top.count = ((SequenceNode) top.left()).count |
434 |
|
+ ((SequenceNode) top.right()).count; |
435 |
|
} |
436 |
|
|
437 |
0 |
float chunk = (float) (height - (offy)) / top.count; |
438 |
|
|
439 |
0 |
pickNode(pickBox, top, chunk, wscale, width, offx, offy); |
440 |
|
} |
441 |
|
|
442 |
|
|
443 |
|
|
444 |
|
|
445 |
|
@param |
446 |
|
|
447 |
|
@param |
448 |
|
|
449 |
|
@param |
450 |
|
|
451 |
|
@param |
452 |
|
|
453 |
|
@param |
454 |
|
|
455 |
|
@param |
456 |
|
|
457 |
|
@param |
458 |
|
|
459 |
|
|
|
|
| 0% |
Uncovered Elements: 26 (26) |
Complexity: 7 |
Complexity Density: 0.44 |
|
460 |
0 |
public void pickNode(Rectangle pickBox, SequenceNode node, float chunk,... |
461 |
|
double wscale, int width, int offx, int offy) |
462 |
|
{ |
463 |
0 |
if (node == null) |
464 |
|
{ |
465 |
0 |
return; |
466 |
|
} |
467 |
|
|
468 |
0 |
if ((node.left() == null) && (node.right() == null)) |
469 |
|
{ |
470 |
0 |
double height = node.height; |
471 |
0 |
double dist = node.dist; |
472 |
|
|
473 |
0 |
int xstart = (int) ((height - dist) * wscale) + offx; |
474 |
0 |
int xend = (int) (height * wscale) + offx; |
475 |
|
|
476 |
0 |
int ypos = (int) (node.ycount * chunk) + offy; |
477 |
|
|
478 |
0 |
if (pickBox.contains(new Point(xend, ypos))) |
479 |
|
{ |
480 |
0 |
if (node.element() instanceof SequenceI) |
481 |
|
{ |
482 |
0 |
SequenceI seq = (SequenceI) node.element(); |
483 |
0 |
SequenceGroup sg = av.getSelectionGroup(); |
484 |
|
|
485 |
0 |
if (sg != null) |
486 |
|
{ |
487 |
0 |
sg.addOrRemove(seq, true); |
488 |
|
} |
489 |
|
} |
490 |
|
} |
491 |
|
} |
492 |
|
else |
493 |
|
{ |
494 |
0 |
pickNode(pickBox, (SequenceNode) node.left(), chunk, wscale, width, |
495 |
|
offx, offy); |
496 |
0 |
pickNode(pickBox, (SequenceNode) node.right(), chunk, wscale, width, |
497 |
|
offx, offy); |
498 |
|
} |
499 |
|
} |
500 |
|
|
501 |
|
|
502 |
|
|
503 |
|
|
504 |
|
@param |
505 |
|
|
506 |
|
@param |
507 |
|
|
508 |
|
|
|
|
| 0% |
Uncovered Elements: 23 (23) |
Complexity: 7 |
Complexity Density: 0.54 |
|
509 |
0 |
public void setColor(SequenceNode node, Color c)... |
510 |
|
{ |
511 |
0 |
if (node == null) |
512 |
|
{ |
513 |
0 |
return; |
514 |
|
} |
515 |
|
|
516 |
0 |
if ((node.left() == null) && (node.right() == null)) |
517 |
|
{ |
518 |
0 |
node.color = c; |
519 |
|
|
520 |
0 |
if (node.element() instanceof SequenceI) |
521 |
|
{ |
522 |
0 |
AlignmentPanel[] aps = getAssociatedPanels(); |
523 |
0 |
if (aps != null) |
524 |
|
{ |
525 |
0 |
for (int a = 0; a < aps.length; a++) |
526 |
|
{ |
527 |
0 |
final SequenceI seq = (SequenceI) node.element(); |
528 |
0 |
aps[a].av.setSequenceColour(seq, c); |
529 |
|
} |
530 |
|
} |
531 |
|
} |
532 |
|
} |
533 |
|
else |
534 |
|
{ |
535 |
0 |
node.color = c; |
536 |
0 |
setColor((SequenceNode) node.left(), c); |
537 |
0 |
setColor((SequenceNode) node.right(), c); |
538 |
|
} |
539 |
|
} |
540 |
|
|
541 |
|
|
542 |
|
|
543 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
544 |
0 |
void startPrinting()... |
545 |
|
{ |
546 |
0 |
Thread thread = new Thread(this); |
547 |
0 |
thread.start(); |
548 |
|
} |
549 |
|
|
550 |
|
|
|
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 4 |
Complexity Density: 0.4 |
|
551 |
0 |
@Override... |
552 |
|
public void run() |
553 |
|
{ |
554 |
0 |
PrinterJob printJob = PrinterJob.getPrinterJob(); |
555 |
0 |
PageFormat defaultPage = printJob.defaultPage(); |
556 |
0 |
PageFormat pf = printJob.pageDialog(defaultPage); |
557 |
|
|
558 |
0 |
if (defaultPage == pf) |
559 |
|
{ |
560 |
|
|
561 |
|
|
562 |
|
|
563 |
0 |
return; |
564 |
|
} |
565 |
|
|
566 |
0 |
printJob.setPrintable(this, pf); |
567 |
|
|
568 |
0 |
if (printJob.printDialog()) |
569 |
|
{ |
570 |
0 |
try |
571 |
|
{ |
572 |
0 |
printJob.print(); |
573 |
|
} catch (Exception PrintException) |
574 |
|
{ |
575 |
0 |
PrintException.printStackTrace(); |
576 |
|
} |
577 |
|
} |
578 |
|
} |
579 |
|
|
580 |
|
|
581 |
|
|
582 |
|
|
583 |
|
@param |
584 |
|
|
585 |
|
@param |
586 |
|
|
587 |
|
@param |
588 |
|
|
589 |
|
|
590 |
|
@return |
591 |
|
|
592 |
|
@throws |
593 |
|
|
594 |
|
|
|
|
| 0% |
Uncovered Elements: 28 (28) |
Complexity: 5 |
Complexity Density: 0.25 |
|
595 |
0 |
@Override... |
596 |
|
public int print(Graphics pg, PageFormat pf, int pi) |
597 |
|
throws PrinterException |
598 |
|
{ |
599 |
0 |
pg.setFont(font); |
600 |
0 |
pg.translate((int) pf.getImageableX(), (int) pf.getImageableY()); |
601 |
|
|
602 |
0 |
int pwidth = (int) pf.getImageableWidth(); |
603 |
0 |
int pheight = (int) pf.getImageableHeight(); |
604 |
|
|
605 |
0 |
int noPages = getHeight() / pheight; |
606 |
|
|
607 |
0 |
if (pi > noPages) |
608 |
|
{ |
609 |
0 |
return Printable.NO_SUCH_PAGE; |
610 |
|
} |
611 |
|
|
612 |
0 |
if (pwidth > getWidth()) |
613 |
|
{ |
614 |
0 |
pwidth = getWidth(); |
615 |
|
} |
616 |
|
|
617 |
0 |
if (fitToWindow) |
618 |
|
{ |
619 |
0 |
if (pheight > getHeight()) |
620 |
|
{ |
621 |
0 |
pheight = getHeight(); |
622 |
|
} |
623 |
|
|
624 |
0 |
noPages = 0; |
625 |
|
} |
626 |
|
else |
627 |
|
{ |
628 |
0 |
FontMetrics fm = pg.getFontMetrics(font); |
629 |
0 |
int height = fm.getHeight() * nameHash.size(); |
630 |
0 |
pg.translate(0, -pi * pheight); |
631 |
0 |
pg.setClip(0, pi * pheight, pwidth, (pi * pheight) + pheight); |
632 |
|
|
633 |
|
|
634 |
|
|
635 |
|
|
636 |
0 |
pheight = height; |
637 |
|
} |
638 |
|
|
639 |
0 |
draw(pg, pwidth, pheight); |
640 |
|
|
641 |
0 |
return Printable.PAGE_EXISTS; |
642 |
|
} |
643 |
|
|
644 |
|
|
645 |
|
|
646 |
|
|
647 |
|
@param |
648 |
|
|
649 |
|
|
|
|
| 84.2% |
Uncovered Elements: 3 (19) |
Complexity: 6 |
Complexity Density: 0.46 |
|
650 |
361 |
@Override... |
651 |
|
public void paintComponent(Graphics g) |
652 |
|
{ |
653 |
361 |
super.paintComponent(g); |
654 |
361 |
g.setFont(font); |
655 |
|
|
656 |
361 |
if (tree == null) |
657 |
|
{ |
658 |
3 |
g.drawString( |
659 |
|
MessageManager.getString("label.calculating_tree") + "....", |
660 |
|
20, getHeight() / 2); |
661 |
|
} |
662 |
|
else |
663 |
|
{ |
664 |
358 |
fm = g.getFontMetrics(font); |
665 |
|
|
666 |
358 |
if (nameHash.size() == 0) |
667 |
|
{ |
668 |
12 |
repaint(); |
669 |
|
} |
670 |
|
|
671 |
358 |
if (fitToWindow || (!fitToWindow && (scrollPane |
672 |
|
.getHeight() > ((fm.getHeight() * nameHash.size()) + offy)))) |
673 |
|
{ |
674 |
358 |
draw(g, scrollPane.getWidth(), scrollPane.getHeight()); |
675 |
358 |
setPreferredSize(null); |
676 |
|
} |
677 |
|
else |
678 |
|
{ |
679 |
0 |
setPreferredSize(new Dimension(scrollPane.getWidth(), |
680 |
|
fm.getHeight() * nameHash.size())); |
681 |
0 |
draw(g, scrollPane.getWidth(), fm.getHeight() * nameHash.size()); |
682 |
|
} |
683 |
|
|
684 |
358 |
scrollPane.revalidate(); |
685 |
|
} |
686 |
|
} |
687 |
|
|
688 |
|
|
689 |
|
|
690 |
|
|
691 |
|
@param |
692 |
|
|
693 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
694 |
24 |
@Override... |
695 |
|
public void setFont(Font font) |
696 |
|
{ |
697 |
24 |
this.font = font; |
698 |
24 |
repaint(); |
699 |
|
} |
700 |
|
|
701 |
|
|
702 |
|
|
703 |
|
|
704 |
|
@param |
705 |
|
|
706 |
|
@param |
707 |
|
|
708 |
|
@param |
709 |
|
|
710 |
|
|
|
|
| 83.3% |
Uncovered Elements: 5 (30) |
Complexity: 6 |
Complexity Density: 0.27 |
|
711 |
358 |
public void draw(Graphics g1, int width, int height)... |
712 |
|
{ |
713 |
358 |
Graphics2D g2 = (Graphics2D) g1; |
714 |
358 |
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, |
715 |
|
RenderingHints.VALUE_ANTIALIAS_ON); |
716 |
358 |
g2.setColor(Color.white); |
717 |
358 |
g2.fillRect(0, 0, width, height); |
718 |
358 |
g2.setFont(font); |
719 |
|
|
720 |
358 |
if (longestName == null || tree == null) |
721 |
|
{ |
722 |
0 |
g2.drawString("Calculating tree.", 20, 20); |
723 |
|
} |
724 |
358 |
offy = font.getSize() + 10; |
725 |
|
|
726 |
358 |
fm = g2.getFontMetrics(font); |
727 |
|
|
728 |
358 |
labelLength = fm.stringWidth(longestName) + 20; |
729 |
|
|
730 |
358 |
double wscale = (width - labelLength - (offx * 2)) |
731 |
|
/ tree.getMaxHeight(); |
732 |
|
|
733 |
358 |
SequenceNode top = tree.getTopNode(); |
734 |
|
|
735 |
358 |
if (top.count == 0) |
736 |
|
{ |
737 |
0 |
top.count = ((SequenceNode) top.left()).count |
738 |
|
+ ((SequenceNode) top.right()).count; |
739 |
|
} |
740 |
|
|
741 |
358 |
float chunk = (float) (height - (offy)) / top.count; |
742 |
|
|
743 |
358 |
drawNode(g2, tree.getTopNode(), chunk, wscale, width, offx, offy); |
744 |
|
|
745 |
358 |
if (threshold != 0) |
746 |
|
{ |
747 |
358 |
if (av.getCurrentTree() == tree) |
748 |
|
{ |
749 |
357 |
g2.setColor(Color.red); |
750 |
|
} |
751 |
|
else |
752 |
|
{ |
753 |
1 |
g2.setColor(Color.gray); |
754 |
|
} |
755 |
|
|
756 |
358 |
int x = (int) ((threshold * (getWidth() - labelLength - (2 * offx))) |
757 |
|
+ offx); |
758 |
|
|
759 |
358 |
g2.drawLine(x, 0, x, getHeight()); |
760 |
|
} |
761 |
|
} |
762 |
|
|
763 |
|
|
764 |
|
|
765 |
|
|
766 |
|
@param |
767 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
768 |
0 |
@Override... |
769 |
|
public void mouseReleased(MouseEvent e) |
770 |
|
{ |
771 |
|
|
772 |
|
|
773 |
|
|
774 |
0 |
if (e.isPopupTrigger()) |
775 |
|
{ |
776 |
0 |
chooseSubtreeColour(); |
777 |
0 |
e.consume(); |
778 |
|
} |
779 |
|
} |
780 |
|
|
781 |
|
|
782 |
|
|
783 |
|
|
784 |
|
@param |
785 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
786 |
0 |
@Override... |
787 |
|
public void mouseEntered(MouseEvent e) |
788 |
|
{ |
789 |
|
} |
790 |
|
|
791 |
|
|
792 |
|
|
793 |
|
|
794 |
|
@param |
795 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
796 |
0 |
@Override... |
797 |
|
public void mouseExited(MouseEvent e) |
798 |
|
{ |
799 |
|
} |
800 |
|
|
801 |
|
|
802 |
|
|
803 |
|
|
804 |
|
|
805 |
|
|
806 |
|
@param |
807 |
|
|
|
|
| 0% |
Uncovered Elements: 19 (19) |
Complexity: 4 |
Complexity Density: 0.31 |
|
808 |
0 |
@Override... |
809 |
|
public void mouseClicked(MouseEvent evt) |
810 |
|
{ |
811 |
0 |
if (highlightNode == null) |
812 |
|
{ |
813 |
0 |
return; |
814 |
|
} |
815 |
|
|
816 |
0 |
if (evt.getClickCount() > 1) |
817 |
|
{ |
818 |
0 |
tree.swapNodes(highlightNode); |
819 |
0 |
tree.reCount(tree.getTopNode()); |
820 |
0 |
tree.findHeight(tree.getTopNode()); |
821 |
|
} |
822 |
|
else |
823 |
|
{ |
824 |
0 |
Vector<SequenceNode> leaves = tree.findLeaves(highlightNode); |
825 |
|
|
826 |
0 |
for (int i = 0; i < leaves.size(); i++) |
827 |
|
{ |
828 |
0 |
SequenceI seq = (SequenceI) leaves.elementAt(i).element(); |
829 |
0 |
treeSelectionChanged(seq); |
830 |
|
} |
831 |
0 |
av.sendSelection(); |
832 |
|
} |
833 |
|
|
834 |
0 |
PaintRefresher.Refresh(tp, av.getSequenceSetId()); |
835 |
0 |
repaint(); |
836 |
|
} |
837 |
|
|
838 |
|
|
839 |
|
|
840 |
|
|
841 |
|
|
842 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
843 |
0 |
void chooseSubtreeColour()... |
844 |
|
{ |
845 |
0 |
String ttl = MessageManager.getString("label.select_subtree_colour"); |
846 |
0 |
ColourChooserListener listener = new ColourChooserListener() { |
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
847 |
0 |
@Override... |
848 |
|
public void colourSelected(Color c) |
849 |
|
{ |
850 |
0 |
setColor(highlightNode, c); |
851 |
0 |
PaintRefresher.Refresh(tp, ap.av.getSequenceSetId()); |
852 |
0 |
repaint(); |
853 |
|
} |
854 |
|
}; |
855 |
0 |
JalviewColourChooser.showColourChooser(this, ttl, highlightNode.color, listener); |
856 |
|
} |
857 |
|
|
|
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 3 |
Complexity Density: 0.3 |
|
858 |
0 |
@Override... |
859 |
|
public void mouseMoved(MouseEvent evt) |
860 |
|
{ |
861 |
0 |
av.setCurrentTree(tree); |
862 |
|
|
863 |
0 |
Object ob = findElement(evt.getX(), evt.getY()); |
864 |
|
|
865 |
0 |
if (ob instanceof SequenceNode) |
866 |
|
{ |
867 |
0 |
highlightNode = (SequenceNode) ob; |
868 |
0 |
this.setToolTipText( |
869 |
|
"<html>" + MessageManager.getString("label.highlightnode")); |
870 |
0 |
repaint(); |
871 |
|
|
872 |
|
} |
873 |
|
else |
874 |
|
{ |
875 |
0 |
if (highlightNode != null) |
876 |
|
{ |
877 |
0 |
highlightNode = null; |
878 |
0 |
setToolTipText(null); |
879 |
0 |
repaint(); |
880 |
|
} |
881 |
|
} |
882 |
|
} |
883 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
884 |
0 |
@Override... |
885 |
|
public void mouseDragged(MouseEvent ect) |
886 |
|
{ |
887 |
|
} |
888 |
|
|
889 |
|
|
890 |
|
|
891 |
|
|
892 |
|
|
893 |
|
|
894 |
|
|
895 |
|
@param |
896 |
|
|
|
|
| 0% |
Uncovered Elements: 53 (53) |
Complexity: 10 |
Complexity Density: 0.29 |
|
897 |
0 |
@Override... |
898 |
|
public void mousePressed(MouseEvent e) |
899 |
|
{ |
900 |
0 |
av.setCurrentTree(tree); |
901 |
|
|
902 |
|
|
903 |
|
|
904 |
|
|
905 |
|
|
906 |
0 |
if (e.isPopupTrigger()) |
907 |
|
{ |
908 |
0 |
if (highlightNode != null) |
909 |
|
{ |
910 |
0 |
chooseSubtreeColour(); |
911 |
|
} |
912 |
0 |
return; |
913 |
|
} |
914 |
|
|
915 |
|
|
916 |
|
|
917 |
|
|
918 |
|
|
919 |
|
|
920 |
|
|
921 |
0 |
if (SwingUtilities.isRightMouseButton(e)) |
922 |
|
{ |
923 |
0 |
return; |
924 |
|
} |
925 |
|
|
926 |
0 |
int x = e.getX(); |
927 |
0 |
int y = e.getY(); |
928 |
|
|
929 |
0 |
Object ob = findElement(x, y); |
930 |
|
|
931 |
0 |
if (ob instanceof SequenceI) |
932 |
|
{ |
933 |
0 |
treeSelectionChanged((Sequence) ob); |
934 |
0 |
PaintRefresher.Refresh(tp, ap.av.getSequenceSetId()); |
935 |
0 |
repaint(); |
936 |
0 |
av.sendSelection(); |
937 |
0 |
return; |
938 |
|
} |
939 |
0 |
else if (!(ob instanceof SequenceNode)) |
940 |
|
{ |
941 |
|
|
942 |
0 |
if (tree.getMaxHeight() != 0) |
943 |
|
{ |
944 |
0 |
threshold = (float) (x - offx) |
945 |
|
/ (float) (getWidth() - labelLength - (2 * offx)); |
946 |
|
|
947 |
0 |
List<SequenceNode> groups = tree.groupNodes(threshold); |
948 |
0 |
setColor(tree.getTopNode(), Color.black); |
949 |
|
|
950 |
0 |
AlignmentPanel[] aps = getAssociatedPanels(); |
951 |
|
|
952 |
|
|
953 |
|
|
954 |
0 |
for (int a = 0; a < aps.length; a++) |
955 |
|
{ |
956 |
0 |
aps[a].av.setSelectionGroup(null); |
957 |
0 |
aps[a].av.getAlignment().deleteAllGroups(); |
958 |
0 |
aps[a].av.clearSequenceColours(); |
959 |
0 |
if (aps[a].av.getCodingComplement() != null) |
960 |
|
{ |
961 |
0 |
aps[a].av.getCodingComplement().setSelectionGroup(null); |
962 |
0 |
aps[a].av.getCodingComplement().getAlignment() |
963 |
|
.deleteAllGroups(); |
964 |
0 |
aps[a].av.getCodingComplement().clearSequenceColours(); |
965 |
|
} |
966 |
|
} |
967 |
0 |
colourGroups(groups); |
968 |
|
|
969 |
|
|
970 |
|
|
971 |
|
|
972 |
|
|
973 |
0 |
if (groups.isEmpty()) |
974 |
|
{ |
975 |
0 |
threshold = 0f; |
976 |
|
} |
977 |
|
} |
978 |
|
|
979 |
0 |
PaintRefresher.Refresh(tp, ap.av.getSequenceSetId()); |
980 |
0 |
repaint(); |
981 |
|
} |
982 |
|
|
983 |
|
} |
984 |
|
|
|
|
| 0% |
Uncovered Elements: 61 (61) |
Complexity: 13 |
Complexity Density: 0.33 |
|
985 |
0 |
void colourGroups(List<SequenceNode> groups)... |
986 |
|
{ |
987 |
0 |
AlignmentPanel[] aps = getAssociatedPanels(); |
988 |
0 |
for (int i = 0; i < groups.size(); i++) |
989 |
|
{ |
990 |
0 |
Color col = new Color((int) (Math.random() * 255), |
991 |
|
(int) (Math.random() * 255), (int) (Math.random() * 255)); |
992 |
0 |
setColor(groups.get(i), col.brighter()); |
993 |
|
|
994 |
0 |
Vector<SequenceNode> l = tree.findLeaves(groups.get(i)); |
995 |
|
|
996 |
0 |
Vector<SequenceI> sequences = new Vector<>(); |
997 |
|
|
998 |
0 |
for (int j = 0; j < l.size(); j++) |
999 |
|
{ |
1000 |
0 |
SequenceI s1 = (SequenceI) l.elementAt(j).element(); |
1001 |
|
|
1002 |
0 |
if (!sequences.contains(s1)) |
1003 |
|
{ |
1004 |
0 |
sequences.addElement(s1); |
1005 |
|
} |
1006 |
|
} |
1007 |
|
|
1008 |
0 |
ColourSchemeI cs = null; |
1009 |
0 |
SequenceGroup sg = new SequenceGroup(sequences, null, cs, true, true, |
1010 |
|
false, 0, av.getAlignment().getWidth() - 1); |
1011 |
|
|
1012 |
0 |
if (av.getGlobalColourScheme() != null) |
1013 |
|
{ |
1014 |
0 |
if (av.getGlobalColourScheme() instanceof UserColourScheme) |
1015 |
|
{ |
1016 |
0 |
cs = new UserColourScheme( |
1017 |
|
((UserColourScheme) av.getGlobalColourScheme()) |
1018 |
|
.getColours()); |
1019 |
|
|
1020 |
|
} |
1021 |
|
else |
1022 |
|
{ |
1023 |
0 |
cs = ColourSchemeProperty.getColourScheme(sg, ColourSchemeProperty |
1024 |
|
.getColourName(av.getGlobalColourScheme())); |
1025 |
|
} |
1026 |
|
|
1027 |
|
|
1028 |
|
|
1029 |
|
|
1030 |
|
|
1031 |
|
|
1032 |
|
} |
1033 |
0 |
sg.setColourScheme(cs); |
1034 |
0 |
sg.getGroupColourScheme().setThreshold( |
1035 |
|
av.getResidueShading().getThreshold(), |
1036 |
|
av.isIgnoreGapsConsensus()); |
1037 |
|
|
1038 |
0 |
sg.setName("JTreeGroup:" + sg.hashCode()); |
1039 |
0 |
sg.setIdColour(col); |
1040 |
|
|
1041 |
0 |
for (int a = 0; a < aps.length; a++) |
1042 |
|
{ |
1043 |
0 |
if (aps[a].av.getGlobalColourScheme() != null |
1044 |
|
&& aps[a].av.getResidueShading().conservationApplied()) |
1045 |
|
{ |
1046 |
0 |
Conservation c = new Conservation("Group", sg.getSequences(null), |
1047 |
|
sg.getStartRes(), sg.getEndRes()); |
1048 |
0 |
c.calculate(); |
1049 |
0 |
c.verdict(false, aps[a].av.getConsPercGaps()); |
1050 |
0 |
sg.cs.setConservation(c); |
1051 |
|
} |
1052 |
|
|
1053 |
0 |
aps[a].av.getAlignment().addGroup(new SequenceGroup(sg)); |
1054 |
|
|
1055 |
0 |
final AlignViewportI codingComplement = aps[a].av |
1056 |
|
.getCodingComplement(); |
1057 |
0 |
if (codingComplement != null) |
1058 |
|
{ |
1059 |
0 |
SequenceGroup mappedGroup = MappingUtils.mapSequenceGroup(sg, av, |
1060 |
|
codingComplement); |
1061 |
0 |
if (mappedGroup.getSequences().size() > 0) |
1062 |
|
{ |
1063 |
0 |
codingComplement.getAlignment().addGroup(mappedGroup); |
1064 |
0 |
for (SequenceI seq : mappedGroup.getSequences()) |
1065 |
|
{ |
1066 |
0 |
codingComplement.setSequenceColour(seq, col.brighter()); |
1067 |
|
} |
1068 |
|
} |
1069 |
|
} |
1070 |
|
} |
1071 |
|
} |
1072 |
|
|
1073 |
|
|
1074 |
0 |
for (int a = 0; a < aps.length; a++) |
1075 |
|
{ |
1076 |
0 |
aps[a].updateAnnotation(); |
1077 |
|
|
1078 |
|
|
1079 |
0 |
final AlignViewportI codingComplement = aps[a].av |
1080 |
|
.getCodingComplement(); |
1081 |
0 |
if (codingComplement != null) |
1082 |
|
{ |
1083 |
0 |
((AlignViewport) codingComplement).getAlignPanel() |
1084 |
|
.updateAnnotation(); |
1085 |
|
} |
1086 |
|
} |
1087 |
|
} |
1088 |
|
|
1089 |
|
|
1090 |
|
|
1091 |
|
|
1092 |
|
@param |
1093 |
|
|
1094 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
1095 |
24 |
public void setShowDistances(boolean state)... |
1096 |
|
{ |
1097 |
24 |
this.showDistances = state; |
1098 |
24 |
repaint(); |
1099 |
|
} |
1100 |
|
|
1101 |
|
|
1102 |
|
|
1103 |
|
|
1104 |
|
@param |
1105 |
|
|
1106 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
1107 |
24 |
public void setShowBootstrap(boolean state)... |
1108 |
|
{ |
1109 |
24 |
this.showBootstrap = state; |
1110 |
24 |
repaint(); |
1111 |
|
} |
1112 |
|
|
1113 |
|
|
1114 |
|
|
1115 |
|
|
1116 |
|
@param |
1117 |
|
|
1118 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
1119 |
24 |
public void setMarkPlaceholders(boolean state)... |
1120 |
|
{ |
1121 |
24 |
this.markPlaceholders = state; |
1122 |
24 |
repaint(); |
1123 |
|
} |
1124 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
1125 |
0 |
AlignmentPanel[] getAssociatedPanels()... |
1126 |
|
{ |
1127 |
0 |
if (applyToAllViews) |
1128 |
|
{ |
1129 |
0 |
return PaintRefresher.getAssociatedPanels(av.getSequenceSetId()); |
1130 |
|
} |
1131 |
|
else |
1132 |
|
{ |
1133 |
0 |
return new AlignmentPanel[] { ap }; |
1134 |
|
} |
1135 |
|
} |
1136 |
|
} |