2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import java.awt.Color;
24 import java.awt.Dimension;
26 import java.awt.FontMetrics;
27 import java.awt.Graphics;
28 import java.awt.Graphics2D;
29 import java.awt.Point;
30 import java.awt.Rectangle;
31 import java.awt.RenderingHints;
32 import java.awt.event.MouseEvent;
33 import java.awt.event.MouseListener;
34 import java.awt.event.MouseMotionListener;
35 import java.awt.print.PageFormat;
36 import java.awt.print.Printable;
37 import java.awt.print.PrinterException;
38 import java.awt.print.PrinterJob;
39 import java.util.ArrayList;
40 import java.util.BitSet;
41 import java.util.HashMap;
42 import java.util.Hashtable;
43 import java.util.List;
45 import java.util.Map.Entry;
46 import java.util.Vector;
48 import javax.swing.JPanel;
49 import javax.swing.JScrollPane;
50 import javax.swing.SwingUtilities;
51 import javax.swing.ToolTipManager;
53 import jalview.analysis.Conservation;
54 import jalview.analysis.TreeModel;
55 import jalview.api.AlignViewportI;
56 import jalview.datamodel.AlignmentAnnotation;
57 import jalview.datamodel.Annotation;
58 import jalview.datamodel.BinaryNode;
59 import jalview.datamodel.ColumnSelection;
60 import jalview.datamodel.ContactMatrixI;
61 import jalview.datamodel.HiddenColumns;
62 import jalview.datamodel.Sequence;
63 import jalview.datamodel.SequenceGroup;
64 import jalview.datamodel.SequenceI;
65 import jalview.datamodel.SequenceNode;
66 import jalview.gui.JalviewColourChooser.ColourChooserListener;
67 import jalview.schemes.ColourSchemeI;
68 import jalview.structure.SelectionSource;
69 import jalview.util.Format;
70 import jalview.util.MessageManager;
71 import jalview.ws.datamodel.MappableContactMatrixI;
79 public class TreeCanvas extends JPanel implements MouseListener, Runnable,
80 Printable, MouseMotionListener, SelectionSource
83 public static final String PLACEHOLDER = " * ";
87 JScrollPane scrollPane;
91 private AlignViewport av;
93 private AlignmentPanel ap;
99 boolean fitToWindow = true;
101 boolean showDistances = false;
103 boolean showBootstrap = false;
105 boolean markPlaceholders = false;
111 private float threshold;
115 int labelLength = -1;
117 Map<Object, Rectangle> nameHash = new Hashtable<>();
119 Map<BinaryNode, Rectangle> nodeHash = new Hashtable<>();
121 BinaryNode highlightNode;
123 boolean applyToAllViews = false;
126 * Creates a new TreeCanvas object.
137 public TreeCanvas(TreePanel tp, AlignmentPanel ap, JScrollPane scroller)
141 this.setAssociatedPanel(ap);
143 scrollPane = scroller;
144 addMouseListener(this);
145 addMouseMotionListener(this);
146 ToolTipManager.sharedInstance().registerComponent(this);
155 public void treeSelectionChanged(SequenceI sequence)
157 AlignmentPanel[] aps = getAssociatedPanels();
159 for (int a = 0; a < aps.length; a++)
161 SequenceGroup selected = aps[a].av.getSelectionGroup();
163 if (selected == null)
165 selected = new SequenceGroup();
166 aps[a].av.setSelectionGroup(selected);
169 selected.setEndRes(aps[a].av.getAlignment().getWidth() - 1);
170 selected.addOrRemove(sequence, true);
180 public void setTree(TreeModel tree)
183 tree.findHeight(tree.getTopNode());
185 // Now have to calculate longest name based on the leaves
186 Vector<BinaryNode> leaves = tree.findLeaves(tree.getTopNode());
187 boolean has_placeholders = false;
190 for (int i = 0; i < leaves.size(); i++)
192 BinaryNode lf = leaves.elementAt(i);
194 if (lf instanceof SequenceNode && ((SequenceNode) lf).isPlaceholder())
196 has_placeholders = true;
199 if (longestName.length() < ((Sequence) lf.element()).getName()
202 longestName = TreeCanvas.PLACEHOLDER
203 + ((Sequence) lf.element()).getName();
207 setMarkPlaceholders(has_placeholders);
228 public void drawNode(Graphics g, BinaryNode node, float chunk,
229 double wscale, int width, int offx, int offy)
236 if ((node.left() == null) && (node.right() == null))
239 double height = node.height;
240 double dist = node.dist;
242 int xstart = (int) ((height - dist) * wscale) + offx;
243 int xend = (int) (height * wscale) + offx;
245 int ypos = (int) (node.ycount * chunk) + offy;
247 if (node.element() instanceof SequenceI)
249 SequenceI seq = (SequenceI) node.element();
251 if (av.getSequenceColour(seq) == Color.white)
253 g.setColor(Color.black);
257 g.setColor(av.getSequenceColour(seq).darker());
262 g.setColor(Color.black);
265 // Draw horizontal line
266 g.drawLine(xstart, ypos, xend, ypos);
268 String nodeLabel = "";
270 if (showDistances && (node.dist > 0))
272 nodeLabel = new Format("%g").form(node.dist);
275 if (showBootstrap && node.bootstrap > -1)
279 nodeLabel = nodeLabel + " : ";
282 nodeLabel = nodeLabel + String.valueOf(node.bootstrap);
285 if (!nodeLabel.equals(""))
287 g.drawString(nodeLabel, xstart + 2, ypos - 2);
290 String name = (markPlaceholders && ((node instanceof SequenceNode
291 && ((SequenceNode) node).isPlaceholder())))
292 ? (PLACEHOLDER + node.getName())
295 int charWidth = fm.stringWidth(name) + 3;
296 int charHeight = font.getSize();
298 Rectangle rect = new Rectangle(xend + 10, ypos - charHeight / 2,
299 charWidth, charHeight);
301 nameHash.put(node.element(), rect);
303 // Colour selected leaves differently
304 boolean isSelected = false;
305 if (tp.isColumnWise())
307 isSelected = isColumnForNodeSelected(node);
311 SequenceGroup selected = av.getSelectionGroup();
313 if ((selected != null)
314 && selected.getSequences(null).contains(node.element()))
321 g.setColor(Color.gray);
323 g.fillRect(xend + 10, ypos - charHeight / 2, charWidth, charHeight);
324 g.setColor(Color.white);
327 g.drawString(name, xend + 10, ypos + fm.getDescent());
328 g.setColor(Color.black);
332 drawNode(g, (BinaryNode) node.left(), chunk, wscale, width, offx,
334 drawNode(g, (BinaryNode) node.right(), chunk, wscale, width, offx,
337 double height = node.height;
338 double dist = node.dist;
340 int xstart = (int) ((height - dist) * wscale) + offx;
341 int xend = (int) (height * wscale) + offx;
342 int ypos = (int) (node.ycount * chunk) + offy;
344 g.setColor(node.color.darker());
346 // Draw horizontal line
347 g.drawLine(xstart, ypos, xend, ypos);
348 if (node == highlightNode)
350 g.fillRect(xend - 3, ypos - 3, 6, 6);
354 g.fillRect(xend - 2, ypos - 2, 4, 4);
357 int ystart = (node.left() == null ? 0
358 : (int) (((BinaryNode) node.left()).ycount * chunk)) + offy;
359 int yend = (node.right() == null ? 0
360 : (int) (((BinaryNode) node.right()).ycount * chunk)) + offy;
362 Rectangle pos = new Rectangle(xend - 2, ypos - 2, 5, 5);
363 nodeHash.put(node, pos);
365 g.drawLine((int) (height * wscale) + offx, ystart,
366 (int) (height * wscale) + offx, yend);
368 String nodeLabel = "";
370 if (showDistances && (node.dist > 0))
372 nodeLabel = new Format("%g").form(node.dist);
375 if (showBootstrap && node.bootstrap > -1)
379 nodeLabel = nodeLabel + " : ";
382 nodeLabel = nodeLabel + String.valueOf(node.bootstrap);
385 if (!nodeLabel.equals(""))
387 g.drawString(nodeLabel, xstart + 2, ypos - 2);
400 * @return DOCUMENT ME!
402 public Object findElement(int x, int y)
404 for (Entry<Object, Rectangle> entry : nameHash.entrySet())
406 Rectangle rect = entry.getValue();
408 if ((x >= rect.x) && (x <= (rect.x + rect.width)) && (y >= rect.y)
409 && (y <= (rect.y + rect.height)))
411 return entry.getKey();
415 for (Entry<BinaryNode, Rectangle> entry : nodeHash.entrySet())
417 Rectangle rect = entry.getValue();
419 if ((x >= rect.x) && (x <= (rect.x + rect.width)) && (y >= rect.y)
420 && (y <= (rect.y + rect.height)))
422 return entry.getKey();
435 public void pickNodes(Rectangle pickBox)
437 int width = getWidth();
438 int height = getHeight();
440 BinaryNode top = tree.getTopNode();
442 double wscale = ((width * .8) - (offx * 2)) / tree.getMaxHeight();
446 top.count = ((BinaryNode) top.left()).count
447 + ((BinaryNode) top.right()).count;
450 float chunk = (float) (height - (offy)) / top.count;
452 pickNode(pickBox, top, chunk, wscale, width, offx, offy);
473 public void pickNode(Rectangle pickBox, BinaryNode node, float chunk,
474 double wscale, int width, int offx, int offy)
481 if ((node.left() == null) && (node.right() == null))
483 double height = node.height;
484 // double dist = node.dist;
485 // int xstart = (int) ((height - dist) * wscale) + offx;
486 int xend = (int) (height * wscale) + offx;
488 int ypos = (int) (node.ycount * chunk) + offy;
490 if (pickBox.contains(new Point(xend, ypos)))
492 if (node.element() instanceof SequenceI)
494 SequenceI seq = (SequenceI) node.element();
495 SequenceGroup sg = av.getSelectionGroup();
499 sg.addOrRemove(seq, true);
506 pickNode(pickBox, (BinaryNode) node.left(), chunk, wscale, width,
508 pickNode(pickBox, (BinaryNode) node.right(), chunk, wscale, width,
521 public void setColor(BinaryNode node, Color c)
529 if (node.element() instanceof SequenceI)
531 final SequenceI seq = (SequenceI) node.element();
532 AlignmentPanel[] aps = getAssociatedPanels();
535 for (int a = 0; a < aps.length; a++)
537 aps[a].av.setSequenceColour(seq, c);
541 setColor((BinaryNode) node.left(), c);
542 setColor((BinaryNode) node.right(), c);
550 Thread thread = new Thread(this);
554 // put printing in a thread to avoid painting problems
558 PrinterJob printJob = PrinterJob.getPrinterJob();
559 PageFormat defaultPage = printJob.defaultPage();
560 PageFormat pf = printJob.pageDialog(defaultPage);
562 if (defaultPage == pf)
570 printJob.setPrintable(this, pf);
572 if (printJob.printDialog())
577 } catch (Exception PrintException)
579 PrintException.printStackTrace();
594 * @return DOCUMENT ME!
596 * @throws PrinterException
600 public int print(Graphics pg, PageFormat pf, int pi)
601 throws PrinterException
604 pg.translate((int) pf.getImageableX(), (int) pf.getImageableY());
606 int pwidth = (int) pf.getImageableWidth();
607 int pheight = (int) pf.getImageableHeight();
609 int noPages = getHeight() / pheight;
613 return Printable.NO_SUCH_PAGE;
616 if (pwidth > getWidth())
623 if (pheight > getHeight())
625 pheight = getHeight();
632 FontMetrics fm = pg.getFontMetrics(font);
633 int height = fm.getHeight() * nameHash.size();
634 pg.translate(0, -pi * pheight);
635 pg.setClip(0, pi * pheight, pwidth, (pi * pheight) + pheight);
637 // translate number of pages,
638 // height is screen size as this is the
639 // non overlapping text size
643 draw(pg, pwidth, pheight);
645 return Printable.PAGE_EXISTS;
655 public void paintComponent(Graphics g)
657 super.paintComponent(g);
663 MessageManager.getString("label.calculating_tree") + "....",
664 20, getHeight() / 2);
668 fm = g.getFontMetrics(font);
670 int nameCount = nameHash.size();
676 if (fitToWindow || (!fitToWindow && (scrollPane
677 .getHeight() > ((fm.getHeight() * nameCount) + offy))))
679 draw(g, scrollPane.getWidth(), scrollPane.getHeight());
680 setPreferredSize(null);
684 setPreferredSize(new Dimension(scrollPane.getWidth(),
685 fm.getHeight() * nameCount));
686 draw(g, scrollPane.getWidth(), fm.getHeight() * nameCount);
689 scrollPane.revalidate();
700 public void setFont(Font font)
716 public void draw(Graphics g1, int width, int height)
718 Graphics2D g2 = (Graphics2D) g1;
719 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
720 RenderingHints.VALUE_ANTIALIAS_ON);
721 g2.setColor(Color.white);
722 g2.fillRect(0, 0, width, height);
725 if (longestName == null || tree == null)
727 g2.drawString("Calculating tree.", 20, 20);
730 offy = font.getSize() + 10;
732 fm = g2.getFontMetrics(font);
734 labelLength = fm.stringWidth(longestName) + 20; // 20 allows for scrollbar
736 double wscale = (width - labelLength - (offx * 2))
737 / tree.getMaxHeight();
739 BinaryNode top = tree.getTopNode();
743 top.count = ((BinaryNode) top.left()).count
744 + ((BinaryNode) top.right()).count;
747 float chunk = (float) (height - (offy)) / top.count;
749 drawNode(g2, tree.getTopNode(), chunk, wscale, width, offx, offy);
753 if (av.getCurrentTree() == tree)
755 g2.setColor(Color.red);
759 g2.setColor(Color.gray);
762 int x = (int) ((threshold * (getWidth() - labelLength - (2 * offx)))
765 g2.drawLine(x, 0, x, getHeight());
770 * Empty method to satisfy the MouseListener interface
775 public void mouseReleased(MouseEvent e)
778 * isPopupTrigger is set on mouseReleased on Windows
780 if (e.isPopupTrigger())
782 chooseSubtreeColour();
783 e.consume(); // prevent mouseClicked happening
788 * Empty method to satisfy the MouseListener interface
793 public void mouseEntered(MouseEvent e)
798 * Empty method to satisfy the MouseListener interface
803 public void mouseExited(MouseEvent e)
808 * Handles a mouse click on a tree node (clicks elsewhere are handled in
809 * mousePressed). Click selects the sub-tree, double-click swaps leaf nodes
810 * order, right-click opens a dialogue to choose colour for the sub-tree.
815 public void mouseClicked(MouseEvent evt)
817 if (highlightNode == null)
822 if (evt.getClickCount() > 1)
824 tree.swapNodes(highlightNode);
825 tree.reCount(tree.getTopNode());
826 tree.findHeight(tree.getTopNode());
830 Vector<BinaryNode> leaves = tree.findLeaves(highlightNode);
831 if (tp.isColumnWise())
833 markColumnsFor(getAssociatedPanels(), leaves, Color.red);
837 for (int i = 0; i < leaves.size(); i++)
839 SequenceI seq = (SequenceI) leaves.elementAt(i).element();
840 treeSelectionChanged(seq);
846 PaintRefresher.Refresh(tp, av.getSequenceSetId());
851 * Offer the user the option to choose a colour for the highlighted node and
852 * its children; this colour is also applied to the corresponding sequence ids
855 void chooseSubtreeColour()
857 String ttl = MessageManager.getString("label.select_subtree_colour");
858 ColourChooserListener listener = new ColourChooserListener()
861 public void colourSelected(Color c)
863 setColor(highlightNode, c);
864 PaintRefresher.Refresh(tp, ap.av.getSequenceSetId());
868 JalviewColourChooser.showColourChooser(this, ttl, highlightNode.color,
873 public void mouseMoved(MouseEvent evt)
875 av.setCurrentTree(tree);
877 Object ob = findElement(evt.getX(), evt.getY());
879 if (ob instanceof BinaryNode)
881 highlightNode = (BinaryNode) ob;
883 "<html>" + MessageManager.getString("label.highlightnode"));
889 if (highlightNode != null)
891 highlightNode = null;
892 setToolTipText(null);
899 public void mouseDragged(MouseEvent ect)
904 * Handles a mouse press on a sequence name or the tree background canvas
905 * (click on a node is handled in mouseClicked). The action is to create
906 * groups by partitioning the tree at the mouse position. Colours for the
907 * groups (and sequence names) are generated randomly.
912 public void mousePressed(MouseEvent e)
914 av.setCurrentTree(tree);
917 * isPopupTrigger is set for mousePressed (Mac)
918 * or mouseReleased (Windows)
920 if (e.isPopupTrigger())
922 if (highlightNode != null)
924 chooseSubtreeColour();
930 * defer right-click handling on Windows to
931 * mouseClicked; note isRightMouseButton
932 * also matches Cmd-click on Mac which should do
935 if (SwingUtilities.isRightMouseButton(e))
943 Object ob = findElement(x, y);
945 if (ob instanceof SequenceI)
947 treeSelectionChanged((Sequence) ob);
948 PaintRefresher.Refresh(tp,
949 getAssociatedPanel().av.getSequenceSetId());
954 else if (!(ob instanceof BinaryNode))
957 if (tree.getMaxHeight() != 0)
959 threshold = (float) (x - offx)
960 / (float) (getWidth() - labelLength - (2 * offx));
962 List<BinaryNode> groups = tree.groupNodes(threshold);
963 setColor(tree.getTopNode(), Color.black);
965 AlignmentPanel[] aps = getAssociatedPanels();
967 // TODO push calls below into a single AlignViewportI method?
968 // see also AlignViewController.deleteGroups
969 for (int a = 0; a < aps.length; a++)
971 aps[a].av.setSelectionGroup(null);
972 aps[a].av.getAlignment().deleteAllGroups();
973 aps[a].av.clearSequenceColours();
974 if (aps[a].av.getCodingComplement() != null)
976 aps[a].av.getCodingComplement().setSelectionGroup(null);
977 aps[a].av.getCodingComplement().getAlignment()
979 aps[a].av.getCodingComplement().clearSequenceColours();
981 aps[a].av.setUpdateStructures(true);
983 colourGroups(groups);
986 * clear partition (don't show vertical line) if
987 * it is to the right of all nodes
989 if (groups.isEmpty())
995 PaintRefresher.Refresh(tp,
996 getAssociatedPanel().av.getSequenceSetId());
1002 void colourGroups(List<BinaryNode> groups)
1004 AlignmentPanel[] aps = getAssociatedPanels();
1005 List<BitSet> colGroups = new ArrayList<>();
1006 Map<BitSet, Color> colors = new HashMap();
1007 for (int i = 0; i < groups.size(); i++)
1009 Color col = new Color((int) (Math.random() * 255),
1010 (int) (Math.random() * 255), (int) (Math.random() * 255));
1011 setColor(groups.get(i), col.brighter());
1013 Vector<BinaryNode> l = tree.findLeaves(groups.get(i));
1014 if (!tp.isColumnWise())
1016 createSeqGroupFor(aps, l, col);
1020 BitSet gp = createColumnGroupFor(l, col);
1023 colors.put(gp, col);
1026 if (tp.isColumnWise())
1028 AlignmentAnnotation aa = tp.getAssocAnnotation();
1031 ContactMatrixI cm = av.getContactMatrix(aa);
1034 cm.updateGroups(colGroups);
1035 for (BitSet gp : colors.keySet())
1037 cm.setColorForGroup(gp, colors.get(gp));
1040 // stash colors in linked annotation row.
1041 // doesn't work yet. TESTS!
1042 int sstart = aa.sequenceRef != null ? aa.sequenceRef.getStart() - 1
1046 int[] seqpos = null;
1047 for (BitSet gp : colors.keySet())
1049 gpcol = colors.get(gp);
1050 for (int p = gp.nextSetBit(0); p >= 0
1051 && p < Integer.MAX_VALUE; p = gp.nextSetBit(p + 1))
1053 if (cm instanceof MappableContactMatrixI)
1055 MappableContactMatrixI mcm = (MappableContactMatrixI) cm;
1056 seqpos = mcm.getMappedPositionsFor(aa.sequenceRef, p);
1059 // no mapping for this column.
1062 // TODO: handle ranges...
1063 ae = aa.getAnnotationForPosition(seqpos[0]);
1067 ae = aa.getAnnotationForPosition(p + sstart);
1071 ae.colour = gpcol.brighter().darker();
1078 // notify the panel(s) to redo any group specific stuff
1079 // also updates structure views if necessary
1080 for (int a = 0; a < aps.length; a++)
1082 aps[a].updateAnnotation();
1083 final AlignViewportI codingComplement = aps[a].av
1084 .getCodingComplement();
1085 if (codingComplement != null)
1087 ((AlignViewport) codingComplement).getAlignPanel()
1088 .updateAnnotation();
1093 private boolean isColumnForNodeSelected(BinaryNode bn)
1095 SequenceI rseq = tp.assocAnnotation.sequenceRef;
1099 colm = Integer.parseInt(
1100 bn.getName().substring(bn.getName().indexOf("c") + 1));
1101 } catch (Exception e)
1105 if (av == null || av.getAlignment() == null)
1107 // alignment is closed
1110 ColumnSelection cs = av.getColumnSelection();
1111 HiddenColumns hc = av.getAlignment().getHiddenColumns();
1112 AlignmentAnnotation aa = tp.getAssocAnnotation();
1116 ContactMatrixI cm = av.getContactMatrix(aa);
1117 if (cm instanceof MappableContactMatrixI)
1119 MappableContactMatrixI mcm = (MappableContactMatrixI) cm;
1120 int pos[]=mcm.getMappedPositionsFor(rseq, colm);
1123 offp=rseq.findIndex(pos[0])-1;
1131 // assume a direct mapping to reference or column number
1132 offp = (rseq != null) ? rseq.findIndex(rseq.getStart() + colm)
1136 if (!av.hasHiddenColumns())
1138 return cs.contains(offp);
1140 if (hc.isVisible(offp - 1))
1142 return cs.contains(offp - 1);
1143 // return cs.contains(hc.absoluteToVisibleColumn(offp));
1147 private BitSet createColumnGroupFor(Vector<BinaryNode> l, Color col)
1149 BitSet gp = new BitSet();
1150 for (BinaryNode bn : l)
1153 if (bn.element() != null && bn.element() instanceof Integer)
1155 colm = (Integer) bn.element();
1159 // parse out from nodename
1162 colm = Integer.parseInt(
1163 bn.getName().substring(bn.getName().indexOf("c") + 1));
1164 } catch (Exception e)
1174 private void markColumnsFor(AlignmentPanel[] aps, Vector<BinaryNode> l,
1177 SequenceI rseq = tp.assocAnnotation.sequenceRef;
1178 if (av == null || av.getAlignment() == null)
1180 // alignment is closed
1184 // TODO - sort indices for faster lookup
1185 ColumnSelection cs = av.getColumnSelection();
1186 HiddenColumns hc = av.getAlignment().getHiddenColumns();
1187 ContactMatrixI cm = av.getContactMatrix(tp.assocAnnotation);
1188 MappableContactMatrixI mcm = null;
1190 if (cm instanceof MappableContactMatrixI)
1192 mcm = (MappableContactMatrixI) cm;
1194 for (BinaryNode bn : l)
1199 colm = Integer.parseInt(
1200 bn.getName().substring(bn.getName().indexOf("c") + 1));
1201 } catch (Exception e)
1207 int[] seqpos = mcm.getMappedPositionsFor(
1208 tp.assocAnnotation.sequenceRef, colm);
1211 // no mapping for this column.
1214 // TODO: handle ranges...
1219 offp = (rseq != null) ? rseq.findIndex(rseq.getStart() + colm)
1222 if (!av.hasHiddenColumns() || hc.isVisible(offp - 1))
1224 if (cs.contains(offp - 1))
1226 cs.removeElement(offp - 1);
1230 cs.addElement(offp - 1);
1236 public void createSeqGroupFor(AlignmentPanel[] aps, Vector<BinaryNode> l,
1240 Vector<SequenceI> sequences = new Vector<>();
1242 for (int j = 0; j < l.size(); j++)
1244 SequenceI s1 = (SequenceI) l.elementAt(j).element();
1246 if (!sequences.contains(s1))
1248 sequences.addElement(s1);
1252 ColourSchemeI cs = null;
1253 SequenceGroup _sg = new SequenceGroup(sequences, null, cs, true, true,
1254 false, 0, av.getAlignment().getWidth() - 1);
1256 _sg.setName("JTreeGroup:" + _sg.hashCode());
1257 _sg.setIdColour(col);
1259 for (int a = 0; a < aps.length; a++)
1261 SequenceGroup sg = new SequenceGroup(_sg);
1262 AlignViewport viewport = aps[a].av;
1264 // Propagate group colours in each view
1265 if (viewport.getGlobalColourScheme() != null)
1267 cs = viewport.getGlobalColourScheme().getInstance(viewport, sg);
1268 sg.setColourScheme(cs);
1269 sg.getGroupColourScheme().setThreshold(
1270 viewport.getResidueShading().getThreshold(),
1271 viewport.isIgnoreGapsConsensus());
1273 if (viewport.getResidueShading().conservationApplied())
1275 Conservation c = new Conservation("Group", sg.getSequences(null),
1276 sg.getStartRes(), sg.getEndRes());
1278 c.verdict(false, viewport.getConsPercGaps());
1279 sg.cs.setConservation(c);
1282 // indicate that associated structure views will need an update
1283 viewport.setUpdateStructures(true);
1284 // propagate structure view update and sequence group to complement view
1285 viewport.addSequenceGroup(sg);
1295 public void setShowDistances(boolean state)
1297 this.showDistances = state;
1307 public void setShowBootstrap(boolean state)
1309 this.showBootstrap = state;
1319 public void setMarkPlaceholders(boolean state)
1321 this.markPlaceholders = state;
1325 AlignmentPanel[] getAssociatedPanels()
1327 if (applyToAllViews)
1329 return PaintRefresher.getAssociatedPanels(av.getSequenceSetId());
1333 return new AlignmentPanel[] { getAssociatedPanel() };
1337 public AlignmentPanel getAssociatedPanel()
1342 public void setAssociatedPanel(AlignmentPanel ap)
1347 public AlignViewport getViewport()
1352 public void setViewport(AlignViewport av)
1357 public float getThreshold()
1362 public void setThreshold(float threshold)
1364 this.threshold = threshold;
1367 public boolean isApplyToAllViews()
1369 return this.applyToAllViews;
1372 public void setApplyToAllViews(boolean applyToAllViews)
1374 this.applyToAllViews = applyToAllViews;