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);
String name;
+ String label=null;
+
BinaryNode<T> left;
BinaryNode<T> right;
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.
return c;
}
+
+ public String getDisplayName()
+ {
+ if (name!=null && !name.isBlank())
+ {
+
+ if (hasLabel()) {
+ return getName()+"|"+label;
+ }
+ return name;
+ }
+ return hasLabel() ? label:"";
+ }
}
int labelLength = -1;
- Map<Object, Rectangle> nameHash = new Hashtable<>();
+ /**
+ * TODO - these rectangle-hash lookups should be optimised for big trees...
+ */
+ Map<BinaryNode, Rectangle> nameHash = new Hashtable<>();
Map<BinaryNode, Rectangle> nodeHash = new Hashtable<>();
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)
{
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();
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;
nodeLabel = nodeLabel + String.valueOf(node.bootstrap);
}
+ if (node.hasLabel())
+ {
+ nodeLabel = node.getLabel()+" "+nodeLabel;
+ }
if (!nodeLabel.equals(""))
{
*/
public Object findElement(int x, int y)
{
- for (Entry<Object, Rectangle> entry : nameHash.entrySet())
+ for (Entry<BinaryNode, Rectangle> 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();
}
}