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 && ((SequenceNode)node).isPlaceholder())))
291 ? (PLACEHOLDER + node.getName())
294 int charWidth = fm.stringWidth(name) + 3;
295 int charHeight = font.getSize();
297 Rectangle rect = new Rectangle(xend + 10, ypos - charHeight / 2,
298 charWidth, charHeight);
300 nameHash.put(node.element(), rect);
302 // Colour selected leaves differently
303 boolean isSelected = false;
304 if (tp.isColumnWise())
306 isSelected = isColumnForNodeSelected(node);
310 SequenceGroup selected = av.getSelectionGroup();
312 if ((selected != null)
313 && selected.getSequences(null).contains(node.element()))
320 g.setColor(Color.gray);
322 g.fillRect(xend + 10, ypos - charHeight / 2, charWidth, charHeight);
323 g.setColor(Color.white);
326 g.drawString(name, xend + 10, ypos + fm.getDescent());
327 g.setColor(Color.black);
331 drawNode(g, (BinaryNode) node.left(), chunk, wscale, width, offx,
333 drawNode(g, (BinaryNode) node.right(), chunk, wscale, width, offx,
336 double height = node.height;
337 double dist = node.dist;
339 int xstart = (int) ((height - dist) * wscale) + offx;
340 int xend = (int) (height * wscale) + offx;
341 int ypos = (int) (node.ycount * chunk) + offy;
343 g.setColor(node.color.darker());
345 // Draw horizontal line
346 g.drawLine(xstart, ypos, xend, ypos);
347 if (node == highlightNode)
349 g.fillRect(xend - 3, ypos - 3, 6, 6);
353 g.fillRect(xend - 2, ypos - 2, 4, 4);
356 int ystart = (node.left() == null ? 0
357 : (int) (((BinaryNode) node.left()).ycount * chunk)) + offy;
358 int yend = (node.right() == null ? 0
359 : (int) (((BinaryNode) node.right()).ycount * chunk))
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()) {
832 markColumnsFor(getAssociatedPanels(), leaves, Color.red);
834 for (int i = 0; i < leaves.size(); i++)
836 SequenceI seq = (SequenceI) leaves.elementAt(i).element();
837 treeSelectionChanged(seq);
843 PaintRefresher.Refresh(tp, av.getSequenceSetId());
848 * Offer the user the option to choose a colour for the highlighted node and
849 * its children; this colour is also applied to the corresponding sequence ids
852 void chooseSubtreeColour()
854 String ttl = MessageManager.getString("label.select_subtree_colour");
855 ColourChooserListener listener = new ColourChooserListener()
858 public void colourSelected(Color c)
860 setColor(highlightNode, c);
861 PaintRefresher.Refresh(tp, ap.av.getSequenceSetId());
865 JalviewColourChooser.showColourChooser(this, ttl, highlightNode.color,
870 public void mouseMoved(MouseEvent evt)
872 av.setCurrentTree(tree);
874 Object ob = findElement(evt.getX(), evt.getY());
876 if (ob instanceof BinaryNode)
878 highlightNode = (BinaryNode) ob;
880 "<html>" + MessageManager.getString("label.highlightnode"));
886 if (highlightNode != null)
888 highlightNode = null;
889 setToolTipText(null);
896 public void mouseDragged(MouseEvent ect)
901 * Handles a mouse press on a sequence name or the tree background canvas
902 * (click on a node is handled in mouseClicked). The action is to create
903 * groups by partitioning the tree at the mouse position. Colours for the
904 * groups (and sequence names) are generated randomly.
909 public void mousePressed(MouseEvent e)
911 av.setCurrentTree(tree);
914 * isPopupTrigger is set for mousePressed (Mac)
915 * or mouseReleased (Windows)
917 if (e.isPopupTrigger())
919 if (highlightNode != null)
921 chooseSubtreeColour();
927 * defer right-click handling on Windows to
928 * mouseClicked; note isRightMouseButton
929 * also matches Cmd-click on Mac which should do
932 if (SwingUtilities.isRightMouseButton(e))
940 Object ob = findElement(x, y);
942 if (ob instanceof SequenceI)
944 treeSelectionChanged((Sequence) ob);
945 PaintRefresher.Refresh(tp,
946 getAssociatedPanel().av.getSequenceSetId());
951 else if (!(ob instanceof BinaryNode))
954 if (tree.getMaxHeight() != 0)
956 threshold = (float) (x - offx)
957 / (float) (getWidth() - labelLength - (2 * offx));
959 List<BinaryNode> groups = tree.groupNodes(threshold);
960 setColor(tree.getTopNode(), Color.black);
962 AlignmentPanel[] aps = getAssociatedPanels();
964 // TODO push calls below into a single AlignViewportI method?
965 // see also AlignViewController.deleteGroups
966 for (int a = 0; a < aps.length; a++)
968 aps[a].av.setSelectionGroup(null);
969 aps[a].av.getAlignment().deleteAllGroups();
970 aps[a].av.clearSequenceColours();
971 if (aps[a].av.getCodingComplement() != null)
973 aps[a].av.getCodingComplement().setSelectionGroup(null);
974 aps[a].av.getCodingComplement().getAlignment()
976 aps[a].av.getCodingComplement().clearSequenceColours();
978 aps[a].av.setUpdateStructures(true);
980 colourGroups(groups);
983 * clear partition (don't show vertical line) if
984 * it is to the right of all nodes
986 if (groups.isEmpty())
992 PaintRefresher.Refresh(tp,
993 getAssociatedPanel().av.getSequenceSetId());
999 void colourGroups(List<BinaryNode> groups)
1001 AlignmentPanel[] aps = getAssociatedPanels();
1002 List<BitSet> colGroups = new ArrayList<>();
1003 Map<BitSet,Color> colors=new HashMap();
1004 for (int i = 0; i < groups.size(); i++)
1006 Color col = new Color((int) (Math.random() * 255),
1007 (int) (Math.random() * 255), (int) (Math.random() * 255));
1008 setColor(groups.get(i), col.brighter());
1010 Vector<BinaryNode> l = tree.findLeaves(groups.get(i));
1011 if (!tp.isColumnWise()) {
1012 createSeqGroupFor(aps, l, col);
1014 BitSet gp=createColumnGroupFor(l,col);
1017 colors.put(gp, col);
1020 if (tp.isColumnWise())
1022 AlignmentAnnotation aa = tp.getAssocAnnotation();
1024 ContactMatrixI cm = av.getContactMatrix(aa);
1027 cm.updateGroups(colGroups);
1028 for (BitSet gp:colors.keySet())
1030 cm.setColorForGroup(gp, colors.get(gp));
1033 // stash colors in linked annotation row.
1034 // doesn't work yet. TESTS!
1035 int sstart=aa.sequenceRef!=null ? aa.sequenceRef.getStart()-1 : 0;
1039 for (BitSet gp : colors.keySet())
1041 gpcol = colors.get(gp);
1042 for (int p = gp.nextSetBit(0); p >= 0 && p < Integer.MAX_VALUE; p = gp.nextSetBit(p + 1))
1044 if (cm instanceof MappableContactMatrixI)
1046 MappableContactMatrixI mcm = (MappableContactMatrixI) cm;
1047 seqpos = mcm.getMappedPositionsFor(aa.sequenceRef,p);
1050 // no mapping for this column.
1053 // TODO: handle ranges...
1054 ae = aa.getAnnotationForPosition(seqpos[0]);
1056 ae = aa.getAnnotationForPosition(p+sstart);
1060 ae.colour = gpcol.brighter().darker();
1067 // notify the panel(s) to redo any group specific stuff
1068 // also updates structure views if necessary
1069 for (int a = 0; a < aps.length; a++)
1071 aps[a].updateAnnotation();
1072 final AlignViewportI codingComplement = aps[a].av
1073 .getCodingComplement();
1074 if (codingComplement != null)
1076 ((AlignViewport) codingComplement).getAlignPanel()
1077 .updateAnnotation();
1082 private boolean isColumnForNodeSelected(BinaryNode bn)
1084 SequenceI rseq = tp.assocAnnotation.sequenceRef;
1088 colm = Integer.parseInt(
1089 bn.getName().substring(bn.getName().indexOf("c") + 1));
1090 } catch (Exception e)
1094 if (av==null||av.getAlignment()==null)
1096 // alignment is closed
1099 ColumnSelection cs = av.getColumnSelection();
1101 HiddenColumns hc = av.getAlignment().getHiddenColumns();
1102 int offp = (rseq != null) ? rseq.findIndex(rseq.getStart() + colm)
1105 if (!av.hasHiddenColumns())
1107 return cs.contains(offp-1);
1109 if (hc.isVisible(offp-1))
1111 return cs.contains(offp-1);
1112 // return cs.contains(hc.absoluteToVisibleColumn(offp));
1117 private BitSet createColumnGroupFor(Vector<BinaryNode> l,
1120 BitSet gp=new BitSet();
1121 for (BinaryNode bn:l)
1124 if (bn.element()!=null && bn.element()instanceof Integer)
1125 { colm = (Integer)bn.element();
1127 // parse out from nodename
1129 colm = Integer.parseInt(bn.getName().substring(bn.getName().indexOf("c")+1));
1130 } catch (Exception e)
1140 private void markColumnsFor(AlignmentPanel[] aps, Vector<BinaryNode> l,
1143 SequenceI rseq = tp.assocAnnotation.sequenceRef;
1145 if (av == null || av.getAlignment() == null)
1147 // alignment is closed
1151 for (BinaryNode bn : l)
1156 colm = Integer.parseInt(
1157 bn.getName().substring(bn.getName().indexOf("c") + 1));
1158 } catch (Exception e)
1162 // TODO - sort indices for faster lookup
1164 ColumnSelection cs = av.getColumnSelection();
1165 HiddenColumns hc = av.getAlignment().getHiddenColumns();
1166 ContactMatrixI cm = av.getContactMatrix(tp.assocAnnotation);
1167 MappableContactMatrixI mcm = null;
1169 if (cm instanceof MappableContactMatrixI)
1171 mcm = (MappableContactMatrixI) cm;
1172 int[] seqpos = mcm.getMappedPositionsFor(tp.assocAnnotation.sequenceRef,colm);
1175 // no mapping for this column.
1178 // TODO: handle ranges...
1183 offp = (rseq != null) ? rseq.findIndex(rseq.getStart() + colm)
1186 if (!av.hasHiddenColumns() || hc.isVisible(offp - 1))
1188 if (cs.contains(offp - 1))
1190 cs.removeElement(offp - 1);
1194 cs.addElement(offp - 1);
1200 public void createSeqGroupFor(AlignmentPanel[] aps, Vector<BinaryNode> l,
1204 Vector<SequenceI> sequences = new Vector<>();
1206 for (int j = 0; j < l.size(); j++)
1208 SequenceI s1 = (SequenceI) l.elementAt(j).element();
1210 if (!sequences.contains(s1))
1212 sequences.addElement(s1);
1216 ColourSchemeI cs = null;
1217 SequenceGroup _sg = new SequenceGroup(sequences, null, cs, true, true,
1218 false, 0, av.getAlignment().getWidth() - 1);
1220 _sg.setName("JTreeGroup:" + _sg.hashCode());
1221 _sg.setIdColour(col);
1223 for (int a = 0; a < aps.length; a++)
1225 SequenceGroup sg = new SequenceGroup(_sg);
1226 AlignViewport viewport = aps[a].av;
1228 // Propagate group colours in each view
1229 if (viewport.getGlobalColourScheme() != null)
1231 cs = viewport.getGlobalColourScheme().getInstance(viewport, sg);
1232 sg.setColourScheme(cs);
1233 sg.getGroupColourScheme().setThreshold(
1234 viewport.getResidueShading().getThreshold(),
1235 viewport.isIgnoreGapsConsensus());
1237 if (viewport.getResidueShading().conservationApplied())
1239 Conservation c = new Conservation("Group", sg.getSequences(null),
1240 sg.getStartRes(), sg.getEndRes());
1242 c.verdict(false, viewport.getConsPercGaps());
1243 sg.cs.setConservation(c);
1246 // indicate that associated structure views will need an update
1247 viewport.setUpdateStructures(true);
1248 // propagate structure view update and sequence group to complement view
1249 viewport.addSequenceGroup(sg);
1259 public void setShowDistances(boolean state)
1261 this.showDistances = state;
1271 public void setShowBootstrap(boolean state)
1273 this.showBootstrap = state;
1283 public void setMarkPlaceholders(boolean state)
1285 this.markPlaceholders = state;
1289 AlignmentPanel[] getAssociatedPanels()
1291 if (applyToAllViews)
1293 return PaintRefresher.getAssociatedPanels(av.getSequenceSetId());
1297 return new AlignmentPanel[] { getAssociatedPanel() };
1301 public AlignmentPanel getAssociatedPanel()
1306 public void setAssociatedPanel(AlignmentPanel ap)
1311 public AlignViewport getViewport()
1316 public void setViewport(AlignViewport av)
1321 public float getThreshold()
1326 public void setThreshold(float threshold)
1328 this.threshold = threshold;
1331 public boolean isApplyToAllViews()
1333 return this.applyToAllViews;
1336 public void setApplyToAllViews(boolean applyToAllViews)
1338 this.applyToAllViews = applyToAllViews;