X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FTreeCanvas.java;h=82998412796e1a3b1c440e737948c4e9e7ef3295;hb=7bcf1bc9aa417c4b256687d86d4e37a9f8a3aa11;hp=3494fb8c847f0a25eab90827c372198ac4b4b4e6;hpb=e529f0aa0690ac7a6f58677fd043135d21e5e148;p=jalview.git diff --git a/src/jalview/gui/TreeCanvas.java b/src/jalview/gui/TreeCanvas.java index 3494fb8..8299841 100755 --- a/src/jalview/gui/TreeCanvas.java +++ b/src/jalview/gui/TreeCanvas.java @@ -28,11 +28,8 @@ import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; import jalview.datamodel.SequenceNode; import jalview.schemes.ColourSchemeI; -import jalview.schemes.ColourSchemeProperty; -import jalview.schemes.UserColourScheme; import jalview.structure.SelectionSource; import jalview.util.Format; -import jalview.util.MappingUtils; import jalview.util.MessageManager; import java.awt.Color; @@ -279,8 +276,9 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, g.drawString(nodeLabel, xstart + 2, ypos - 2); } - String name = (markPlaceholders && node.isPlaceholder()) ? (PLACEHOLDER + node - .getName()) : node.getName(); + String name = (markPlaceholders && node.isPlaceholder()) + ? (PLACEHOLDER + node.getName()) + : node.getName(); int charWidth = fm.stringWidth(name) + 3; int charHeight = font.getSize(); @@ -332,9 +330,10 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, g.fillRect(xend - 2, ypos - 2, 4, 4); } - int ystart = (int) (((SequenceNode) node.left()).ycount * chunk) - + offy; - int yend = (int) (((SequenceNode) node.right()).ycount * chunk) + int ystart = (node.left() == null ? 0 + : (int) (((SequenceNode) node.left()).ycount * chunk)) + offy; + int yend = (node.right() == null ? 0 + : (int) (((SequenceNode) node.right()).ycount * chunk)) + offy; Rectangle pos = new Rectangle(xend - 2, ypos - 2, 5, 5); @@ -423,8 +422,7 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, SequenceNode top = tree.getTopNode(); - double wscale = ((width * .8) - (offx * 2)) - / tree.getMaxHeight(); + double wscale = ((width * .8) - (offx * 2)) / tree.getMaxHeight(); if (top.count == 0) { @@ -511,29 +509,21 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, return; } - if ((node.left() == null) && (node.right() == null)) // TODO: internal node + node.color = c; + if (node.element() instanceof SequenceI) { - node.color = c; - - if (node.element() instanceof SequenceI) + final SequenceI seq = (SequenceI) node.element(); + AlignmentPanel[] aps = getAssociatedPanels(); + if (aps != null) { - AlignmentPanel[] aps = getAssociatedPanels(); - if (aps != null) + for (int a = 0; a < aps.length; a++) { - for (int a = 0; a < aps.length; a++) - { - final SequenceI seq = (SequenceI) node.element(); - aps[a].av.setSequenceColour(seq, c); - } + aps[a].av.setSequenceColour(seq, c); } } } - else - { - node.color = c; - setColor((SequenceNode) node.left(), c); - setColor((SequenceNode) node.right(), c); - } + setColor((SequenceNode) node.left(), c); + setColor((SequenceNode) node.right(), c); } /** @@ -653,8 +643,9 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, if (tree == null) { - g.drawString(MessageManager.getString("label.calculating_tree") - + "....", 20, getHeight() / 2); + g.drawString( + MessageManager.getString("label.calculating_tree") + "....", + 20, getHeight() / 2); } else { @@ -665,9 +656,8 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, repaint(); } - if (fitToWindow - || (!fitToWindow && (scrollPane.getHeight() > ((fm - .getHeight() * nameHash.size()) + offy)))) + if (fitToWindow || (!fitToWindow && (scrollPane + .getHeight() > ((fm.getHeight() * nameHash.size()) + offy)))) { draw(g, scrollPane.getWidth(), scrollPane.getHeight()); setPreferredSize(null); @@ -751,7 +741,8 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, g2.setColor(Color.gray); } - int x = (int) ((threshold * (getWidth() - labelLength - (2 * offx))) + offx); + int x = (int) ((threshold * (getWidth() - labelLength - (2 * offx))) + + offx); g2.drawLine(x, 0, x, getHeight()); } @@ -860,8 +851,8 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, if (ob instanceof SequenceNode) { highlightNode = (SequenceNode) ob; - this.setToolTipText("" - + MessageManager.getString("label.highlightnode")); + this.setToolTipText( + "" + MessageManager.getString("label.highlightnode")); repaint(); } @@ -958,8 +949,18 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, .deleteAllGroups(); aps[a].av.getCodingComplement().clearSequenceColours(); } + aps[a].av.setUpdateStructures(true); } colourGroups(groups); + + /* + * clear partition (don't show vertical line) if + * it is to the right of all nodes + */ + if (groups.isEmpty()) + { + threshold = 0f; + } } PaintRefresher.Refresh(tp, ap.av.getSequenceSetId()); @@ -979,7 +980,7 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, Vector l = tree.findLeaves(groups.get(i)); - Vector sequences = new Vector(); + Vector sequences = new Vector<>(); for (int j = 0; j < l.size(); j++) { @@ -992,78 +993,48 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, } ColourSchemeI cs = null; - SequenceGroup sg = new SequenceGroup(sequences, null, cs, true, true, + SequenceGroup _sg = new SequenceGroup(sequences, null, cs, true, true, false, 0, av.getAlignment().getWidth() - 1); - if (av.getGlobalColourScheme() != null) - { - if (av.getGlobalColourScheme() instanceof UserColourScheme) - { - cs = new UserColourScheme( - ((UserColourScheme) av.getGlobalColourScheme()) - .getColours()); - - } - else - { - cs = ColourSchemeProperty.getColourScheme(sg, - ColourSchemeProperty.getColourName(av - .getGlobalColourScheme())); - } - // cs is null if shading is an annotationColourGradient - // if (cs != null) - // { - // cs.setThreshold(av.getViewportColourScheme().getThreshold(), - // av.isIgnoreGapsConsensus()); - // } - } - sg.setColourScheme(cs); - sg.getGroupColourScheme().setThreshold( - av.getResidueShading().getThreshold(), - av.isIgnoreGapsConsensus()); - // sg.recalcConservation(); - sg.setName("JTreeGroup:" + sg.hashCode()); - sg.setIdColour(col); + _sg.setName("JTreeGroup:" + _sg.hashCode()); + _sg.setIdColour(col); for (int a = 0; a < aps.length; a++) { - if (aps[a].av.getGlobalColourScheme() != null - && aps[a].av.getResidueShading() - .conservationApplied()) - { - Conservation c = new Conservation("Group", sg.getSequences(null), - sg.getStartRes(), sg.getEndRes()); - c.calculate(); - c.verdict(false, aps[a].av.getConsPercGaps()); - sg.cs.setConservation(c); - } + SequenceGroup sg = new SequenceGroup(_sg); + AlignViewport viewport = aps[a].av; - aps[a].av.getAlignment().addGroup(new SequenceGroup(sg)); - // TODO can we push all of the below into AlignViewportI? - final AlignViewportI codingComplement = aps[a].av - .getCodingComplement(); - if (codingComplement != null) + // Propagate group colours in each view + if (viewport.getGlobalColourScheme() != null) { - SequenceGroup mappedGroup = MappingUtils.mapSequenceGroup(sg, av, - codingComplement); - if (mappedGroup.getSequences().size() > 0) + cs = viewport.getGlobalColourScheme().getInstance(viewport, sg); + sg.setColourScheme(cs); + sg.getGroupColourScheme().setThreshold( + viewport.getResidueShading().getThreshold(), + viewport.isIgnoreGapsConsensus()); + + if (viewport.getResidueShading().conservationApplied()) { - codingComplement.getAlignment().addGroup(mappedGroup); - for (SequenceI seq : mappedGroup.getSequences()) - { - codingComplement.setSequenceColour(seq, col.brighter()); - } + Conservation c = new Conservation("Group", + sg.getSequences(null), sg.getStartRes(), + sg.getEndRes()); + c.calculate(); + c.verdict(false, viewport.getConsPercGaps()); + sg.cs.setConservation(c); } } + // indicate that associated structure views will need an update + viewport.setUpdateStructures(true); + // propagate structure view update and sequence group to complement view + viewport.addSequenceGroup(sg); } } - // notify the panel(s) to redo any group specific stuff. + // notify the panel(s) to redo any group specific stuff + // also updates structure views if necessary for (int a = 0; a < aps.length; a++) { aps[a].updateAnnotation(); - // TODO: JAL-868 - need to ensure view colour change message is broadcast - // to any Jmols listening in final AlignViewportI codingComplement = aps[a].av .getCodingComplement(); if (codingComplement != null)