initNodeData();
if ( recalc_longest_ext_node_info ) {
calculateLongestExtNodeInfo();
+ while ( getLongestExtNodeInfo() > y / 2 && getTreeFontSet().getLargeFont().getSize() > 2 ) {
+ getMainPanel().getTreeFontSet().decreaseFontSize();
+ calculateLongestExtNodeInfo();
+ }
+
}
int ext_nodes = _phylogeny.getRoot().getNumberOfExternalNodes();
final int max_depth = PhylogenyMethods.calculateMaxDepth( _phylogeny );
errorMessageNoCutCopyPasteInUnrootedDisplay();
return;
}
- if ( node.isRoot() ) {
+ if ( node.isRoot() && node.getNumberOfDescendants() != 1 ) {
JOptionPane.showMessageDialog( this,
"Cannot delete entire tree",
"Attempt to delete entire tree",
public Phylogeny copy() {
return copy( _root );
}
+
+
/**
* Returns a deep copy of this Phylogeny.
public void setRoot( final PhylogenyNode n ) {
_root = n;
- } // setRoot( PhylogenyNode )
+ }
/**
* Sets whether this Phylogeny is rooted or not.
final ArrayList<PhylogenyNode> to_delete = new ArrayList<PhylogenyNode>();
for( final PhylogenyNodeIterator iter = phy.iteratorPostorder(); iter.hasNext(); ) {
final PhylogenyNode n = iter.next();
- if ( !n.isExternal() && ( n.getNumberOfDescendants() == 1 ) ) {
+ if ( ( !n.isExternal() ) && ( !n.isRoot() ) && ( n.getNumberOfDescendants() == 1 ) ) {
to_delete.add( n );
}
}
}
public static void removeNode( final PhylogenyNode remove_me, final Phylogeny phylogeny ) {
- if ( remove_me.isRoot() ) {
- throw new IllegalArgumentException( "ill advised attempt to remove root node" );
+ if ( remove_me.isRoot() && remove_me.getNumberOfDescendants() != 1 ) {
+ throw new IllegalArgumentException( "attempt to remove a root node with more than one descendants" );
+ }
+
+ if ( remove_me.isRoot() && remove_me.getNumberOfDescendants() == 1 ) {
+ final PhylogenyNode desc = remove_me.getDescendants().get( 0 );
+
+ desc.setDistanceToParent( addPhylogenyDistances( remove_me.getDistanceToParent(),
+ desc.getDistanceToParent() ) );
+ desc.setParent( null );
+ phylogeny.setRoot( desc );
+ phylogeny.clearHashIdToNodeMap();
}
- if ( remove_me.isExternal() ) {
+
+ else if ( remove_me.isExternal() ) {
phylogeny.deleteSubtree( remove_me, false );
phylogeny.clearHashIdToNodeMap();
phylogeny.externalNodesHaveChanged();