+ public static List<TreeNodeI> getUniqueWrappers(
+ List<PhylogenyNode> aptxNodes)
+ {
+ List<TreeNodeI> wrappedNodes = new ArrayList<>(
+ aptxNodes.size());
+
+ for (PhylogenyNode aptxNode : aptxNodes)
+ {
+ wrappedNodes.add(getUniqueWrapper(aptxNode));
+ }
+ return wrappedNodes;
+ }
+
+ /**
+ * This method should be used to create new wrappers as there is a possibility
+ * the Archaeopteryx node was already introduced to Jalview previously so this
+ * avoids giving one node duplicate wrappers
+ *
+ * @param aptxNode
+ * @return
+ */
+ public static TreeNodeI getUniqueWrapper(
+ PhylogenyNode aptxNode)
+ {
+ if (aptxNode == null)
+ {
+ return null;
+ }
+ TreeNodeI wrappedNode = originalNodes.get(aptxNode);
+ if (wrappedNode == null)
+ {
+ wrappedNode = new TreeNode(aptxNode);
+ }
+ return wrappedNode;
+ }
+
+ /**
+ * Attempts to unwrap the given node, if the unwrapped node already exists it
+ * is simply returned as is. If it is not however, the wrapper will be used to
+ * create a new Archaeopteryx node. This way it becomes possible to construct
+ * new Archaeopteryx nodes from different tree viewers, as long as they
+ * implement the interface.
+ *
+ * @param wrappedNode
+ * @return
+ */
+ protected static PhylogenyNode unwrapNode(TreeNodeI wrappedNode)
+ {
+ if (wrappedNode == null)
+ {
+ return null;
+ }
+ PhylogenyNode aptxNode = wrappedNodes.get(wrappedNode);
+ if (aptxNode == null)
+ {
+ // expand this
+ aptxNode = new PhylogenyNode(wrappedNode.getNodeName());
+
+ }
+ return aptxNode;
+
+ }
+
+
+ @Override
+ public int hashCode()
+ {
+ final int prime = 31;
+ int result = 1;
+ result = (int) (prime * result
+ + ((node == null) ? 0 : (node.hashCode() * getId())));
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (this == obj)
+ {
+ return true;
+ }
+ if (obj == null)
+ {
+ return false;
+ }
+ if (getClass() != obj.getClass())
+ {
+ return false;
+ }
+ TreeNode other = (TreeNode) obj;
+ if (node == null)
+ {
+ if (other.node != null)
+ {
+ return false;
+ }
+ }
+ if (getId() != other.getId())
+ {
+ return false;
+ }
+
+ if (!node.equals(other.node))
+ {
+ return false;
+ }
+ return true;
+ }
+
+
+ @Override
+ public float getYcoord()
+ {
+ return node.getYcoord();
+ }
+
+ @Override
+ public boolean isCollapsed()
+ {
+ return node.isCollapse();
+ }