From: Jim Procter Date: Fri, 28 Jun 2024 16:03:09 +0000 (+0100) Subject: JAL-4386 move provider label into a new attribute on BinaryNodes so it can be recover... X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=a88dcd09810e318fe75846e62bf3c16cd95f3fe8;p=jalview.git JAL-4386 move provider label into a new attribute on BinaryNodes so it can be recovered easily --- diff --git a/src/jalview/analysis/TreeBuilder.java b/src/jalview/analysis/TreeBuilder.java index 560a0a4..e713525 100644 --- a/src/jalview/analysis/TreeBuilder.java +++ b/src/jalview/analysis/TreeBuilder.java @@ -186,12 +186,14 @@ public abstract class TreeBuilder extends TreeEngine SequenceNode sn = new SequenceNode(); sn.setElement(sequences[i]); + if (labels.size()==noseqs) { - sn.setName(labels.get(i)); - } else { - sn.setName(sequences[i].getName()); + sn.setLabel(labels.get(i)); } + + sn.setName(sequences[i].getName()); + node.addElement(sn); BitSet bs = new BitSet(); bs.set(i); diff --git a/src/jalview/analysis/scoremodels/SecondaryStructureDistanceModel.java b/src/jalview/analysis/scoremodels/SecondaryStructureDistanceModel.java index 97200bf..dc35efb 100644 --- a/src/jalview/analysis/scoremodels/SecondaryStructureDistanceModel.java +++ b/src/jalview/analysis/scoremodels/SecondaryStructureDistanceModel.java @@ -128,7 +128,7 @@ public class SecondaryStructureDistanceModel extends DistanceScoreModel // not defined newSequences.add(alSeq); if (alSeq!=null) { - labels.add(alSeq.getName()+"|"+" No Secondary Structure"); + labels.add("No Secondary Structure"); } SeqCigar newSeqCigar = scig; //new SeqCigar(scig); newCigs.add(newSeqCigar); @@ -138,7 +138,7 @@ public class SecondaryStructureDistanceModel extends DistanceScoreModel { if (alSeq != null) { - labels.add(alSeq.getName() + "|" + AlignmentUtils + labels.add(AlignmentUtils .extractSSSourceFromAnnotationDescription(ssec.get(i))); } //newSequences.add(seq); diff --git a/src/jalview/datamodel/BinaryNode.java b/src/jalview/datamodel/BinaryNode.java index 624c2b9..2b5894a 100755 --- a/src/jalview/datamodel/BinaryNode.java +++ b/src/jalview/datamodel/BinaryNode.java @@ -34,6 +34,8 @@ public class BinaryNode String name; + String label=null; + BinaryNode left; BinaryNode right; @@ -364,6 +366,23 @@ public class BinaryNode return oldstate; } + /** + * check if there's a label to show + * @return true if non-empty/null string + */ + public boolean hasLabel() + { + return label!=null && !label.isEmpty(); + } + public String getLabel() + { + return label; + } + + public void setLabel(String label) + { + this.label = label; + } /** * ascends the tree but doesn't stop until a non-dummy node is discovered. @@ -380,4 +399,17 @@ public class BinaryNode return c; } + + public String getDisplayName() + { + if (name!=null && !name.isBlank()) + { + + if (hasLabel()) { + return getName()+"|"+label; + } + return name; + } + return hasLabel() ? label:""; + } } diff --git a/src/jalview/gui/TreeCanvas.java b/src/jalview/gui/TreeCanvas.java index 9180d52..993d563 100755 --- a/src/jalview/gui/TreeCanvas.java +++ b/src/jalview/gui/TreeCanvas.java @@ -116,7 +116,10 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, int labelLength = -1; - Map nameHash = new Hashtable<>(); + /** + * TODO - these rectangle-hash lookups should be optimised for big trees... + */ + Map nameHash = new Hashtable<>(); Map nodeHash = new Hashtable<>(); @@ -240,11 +243,11 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, has_placeholders = true; } - if (longestName.length() < ((Sequence) lf.element()).getName() + if (longestName.length() < lf.getDisplayName() .length()) { longestName = TreeCanvas.PLACEHOLDER - + ((Sequence) lf.element()).getName(); + + lf.getDisplayName(); } if (tp.isColumnWise() && cm != null) { @@ -345,8 +348,8 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, String name = (markPlaceholders && ((node instanceof SequenceNode && ((SequenceNode) node).isPlaceholder()))) - ? (PLACEHOLDER + node.getName()) - : node.getName(); + ? (PLACEHOLDER + node.getDisplayName()) + : node.getDisplayName(); int charWidth = fm.stringWidth(name) + 3; int charHeight = font.getSize(); @@ -354,7 +357,7 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, Rectangle rect = new Rectangle(xend + 10, ypos - charHeight / 2, charWidth, charHeight); - nameHash.put(node.element(), rect); + nameHash.put(node, rect); // Colour selected leaves differently boolean isSelected = false; @@ -437,6 +440,10 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, nodeLabel = nodeLabel + String.valueOf(node.bootstrap); } + if (node.hasLabel()) + { + nodeLabel = node.getLabel()+" "+nodeLabel; + } if (!nodeLabel.equals("")) { @@ -457,14 +464,14 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, */ public Object findElement(int x, int y) { - for (Entry entry : nameHash.entrySet()) + for (Entry entry : nameHash.entrySet()) { Rectangle rect = entry.getValue(); if ((x >= rect.x) && (x <= (rect.x + rect.width)) && (y >= rect.y) && (y <= (rect.y + rect.height))) { - return entry.getKey(); + return entry.getKey().element(); } }