in progress
authorcmzmasek <cmzmasek@yahoo.com>
Thu, 29 Sep 2016 18:53:12 +0000 (11:53 -0700)
committercmzmasek <cmzmasek@yahoo.com>
Thu, 29 Sep 2016 18:53:12 +0000 (11:53 -0700)
forester/java/src/org/forester/archaeopteryx/ControlPanel.java
forester/java/src/org/forester/archaeopteryx/Options.java
forester/java/src/org/forester/archaeopteryx/TreePanel.java
forester/java/src/org/forester/phylogeny/Phylogeny.java
forester/java/src/org/forester/phylogeny/PhylogenyMethods.java

index 32121a0..03f5590 100644 (file)
@@ -104,7 +104,7 @@ final class ControlPanel extends JPanel implements ActionListener {
             .getDefaultFontFamilyName(), Font.PLAIN, 9 );
     final static Font                         js_font                   = new Font( Configuration
             .getDefaultFontFamilyName(), Font.PLAIN, 9 );
-    private static final String               RETURN_TO_SUPER_TREE_TEXT = "Back to Super Tree";
+    private static final String               RETURN_TO_SUPER_TREE_TEXT = "R";
     private static final String               SEARCH_TIP_TEXT           = "Enter text to search for. Use ',' for logical OR and '+' for logical AND (not used in this manner for regular expression searches).";
     private static final long                 serialVersionUID          = -8463483932821545633L;
     private NodeClickAction                   _action_when_node_clicked;
@@ -631,12 +631,13 @@ final class ControlPanel extends JPanel implements ActionListener {
         return getIsDrawPhylogramList().get( index );
     }
 
-    private void search0( final MainPanel main_panel, final Phylogeny tree, final String query_str ) {
+    private void search0( final MainPanel main_panel, final Phylogeny tree, String query_str ) {
         getSearchFoundCountsLabel0().setVisible( true );
         getSearchResetButton0().setEnabled( true );
         getSearchResetButton0().setVisible( true );
         String[] queries = null;
         Set<Long> nodes = null;
+        query_str = query_str.replaceAll("\\s+", " " );
         if ( ( query_str.indexOf( ',' ) >= 0 ) && !getOptions().isSearchWithRegex() ) {
             queries = query_str.split( ",+" );
         }
@@ -698,12 +699,13 @@ final class ControlPanel extends JPanel implements ActionListener {
         }
     }
 
-    private void search1( final MainPanel main_panel, final Phylogeny tree, final String query_str ) {
+    private void search1( final MainPanel main_panel, final Phylogeny tree, String query_str ) {
         getSearchFoundCountsLabel1().setVisible( true );
         getSearchResetButton1().setEnabled( true );
         getSearchResetButton1().setVisible( true );
         String[] queries = null;
         Set<Long> nodes = null;
+        query_str = query_str.replaceAll("\\s+", " " );
         if ( ( query_str.indexOf( ',' ) >= 0 ) && !getOptions().isSearchWithRegex() ) {
             queries = query_str.split( ",+" );
         }
@@ -1200,6 +1202,12 @@ final class ControlPanel extends JPanel implements ActionListener {
         _return_to_super_tree.setForeground( getConfiguration().getGuiCheckboxAndButtonActiveColor() );
         _return_to_super_tree.setEnabled( true );
     }
+    
+    void activateButtonToUncollapseAll() {
+        _uncollapse_all.setForeground( getConfiguration().getGuiCheckboxAndButtonActiveColor() );
+        _uncollapse_all.setEnabled( true );
+    }
+    
 
     /**
      * Add zoom and quick edit buttons. (Last modified 8/9/04)
@@ -1211,10 +1219,12 @@ final class ControlPanel extends JPanel implements ActionListener {
         final JPanel x_panel = new JPanel( new GridLayout( 1, 1, 0, 0 ) );
         final JPanel y_panel = new JPanel( new GridLayout( 1, 3, 0, 0 ) );
         final JPanel z_panel = new JPanel( new GridLayout( 1, 1, 0, 0 ) );
+        final JPanel o_panel = new JPanel( new GridLayout( 1, 3, 0, 0 ) );
         if ( !getConfiguration().isUseNativeUI() ) {
             x_panel.setBackground( getBackground() );
             y_panel.setBackground( getBackground() );
             z_panel.setBackground( getBackground() );
+            o_panel.setBackground( getBackground() );
         }
         add( _zoom_label = new JLabel( "Zoom:" ) );
         customizeLabel( _zoom_label, getConfiguration() );
@@ -1249,14 +1259,25 @@ final class ControlPanel extends JPanel implements ActionListener {
         _zoom_in_y.setPreferredSize( new Dimension( 10, 10 ) );
         _show_whole.setPreferredSize( new Dimension( 10, 10 ) );
         _return_to_super_tree = new JButton( RETURN_TO_SUPER_TREE_TEXT );
+        _return_to_super_tree.setToolTipText( "return to the super-tree (if in sub-tree)" );
         _return_to_super_tree.setEnabled( false );
-        _order = new JButton( "Order Tree" );
-        _uncollapse_all = new JButton( "Uncollapse All" );
+        _order = new JButton( "O" );
+        _order.setToolTipText( "order all" );
+        _uncollapse_all = new JButton( "U" );
+        _uncollapse_all.setToolTipText( "uncollapse all" );
         addJButton( _zoom_in_y, x_panel );
         addJButton( _zoom_out_x, y_panel );
         addJButton( _show_whole, y_panel );
         addJButton( _zoom_in_x, y_panel );
         addJButton( _zoom_out_y, z_panel );
+        
+        final JLabel spacer2 = new JLabel( "" );
+        add( spacer2 );
+        add( o_panel );
+        addJButton( _order, o_panel );
+        addJButton( _return_to_super_tree, o_panel );
+        addJButton( _uncollapse_all, o_panel );
+        
         if ( getConfiguration().doDisplayOption( Configuration.show_domain_architectures ) ) {
             setUpControlsForDomainStrucures();
         }
@@ -1266,11 +1287,7 @@ final class ControlPanel extends JPanel implements ActionListener {
         if ( true ) {
             setUpControlsForRankCollapse();
         }
-        final JLabel spacer2 = new JLabel( "" );
-        add( spacer2 );
-        addJButton( _return_to_super_tree, this );
-        addJButton( _order, this );
-        addJButton( _uncollapse_all, this );
+      
         final JLabel spacer3 = new JLabel( "" );
         add( spacer3 );
         setVisibilityOfDomainStrucureControls();
@@ -1482,6 +1499,12 @@ final class ControlPanel extends JPanel implements ActionListener {
         _return_to_super_tree.setForeground( getConfiguration().getGuiButtonTextColor() );
         _return_to_super_tree.setEnabled( false );
     }
+    
+    void  deactivateButtonToUncollapseAll() {
+        _uncollapse_all.setForeground( getConfiguration().getGuiButtonTextColor() );
+        _uncollapse_all.setEnabled( false );
+    }
+    
 
     void displayedPhylogenyMightHaveChanged( final boolean recalc_longest_ext_node_info ) {
         if ( ( _mainpanel != null )
@@ -1499,6 +1522,7 @@ final class ControlPanel extends JPanel implements ActionListener {
             updateDepthCollapseDepthDisplay();
             updateRankCollapseRankDisplay();
             getMainPanel().getControlPanel();
+            _mainpanel.getCurrentTreePanel().updateButtonToUncollapseAll();
             _mainpanel.getCurrentTreePanel().calculateScaleDistance();
             _mainpanel.getCurrentTreePanel().calcMaxDepth();
             _mainpanel.adjustJScrollPane();
@@ -2509,6 +2533,7 @@ final class ControlPanel extends JPanel implements ActionListener {
                         .setSelectedTypeInTypeMenu( getMainPanel().getCurrentTreePanel().getPhylogenyGraphicsType() );
             }
             getMainPanel().getCurrentTreePanel().updateSubSuperTreeButton();
+            getMainPanel().getCurrentTreePanel().updateButtonToUncollapseAll();
             getMainPanel().getControlPanel().search0();
             getMainPanel().getControlPanel().search1();
             getMainPanel().getControlPanel().updateDomainStructureEvaluethresholdDisplay();
index 5a083b4..0aecc53 100644 (file)
@@ -122,6 +122,7 @@ final public class Options {
     private boolean                           _parse_beast_style_extended_nexus_tags;
     private boolean                           _collapsed_with_average_height;
     private boolean                           _show_abbreviated_labels_for_collapsed_nodes;
+    private boolean                           _align_ext_labels_in_phylogram;
     
     private Options() {
         init();
@@ -228,6 +229,7 @@ final public class Options {
         _right_align_domains = false;
         _collapsed_with_average_height = true;
         _show_abbreviated_labels_for_collapsed_nodes = true;
+        _align_ext_labels_in_phylogram = true;
     }
 
     final private void setNumberOfDigitsAfterCommaForBranchLength( final short number_of_digits_after_comma_for_branch_length_values ) {
@@ -622,5 +624,13 @@ final public class Options {
         _show_abbreviated_labels_for_collapsed_nodes =  show_abbreviated_labels_for_collapsed_nodes;
     }
     
+    final boolean isAlignExtLabelsInPhylogram() {
+        return _align_ext_labels_in_phylogram;
+    }
+
+    final void setAlignExtLabelsInPhylogram( final boolean align_ext_labels_in_phylogram ) {
+        _align_ext_labels_in_phylogram = align_ext_labels_in_phylogram;
+    }
+    
     
 }
index 53b1620..4961579 100644 (file)
@@ -239,6 +239,29 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
     private static final BasicStroke      STROKE_075                                         = new BasicStroke( 0.75f );
     private static final BasicStroke      STROKE_1                                           = new BasicStroke( 1f );
     private static final BasicStroke      STROKE_2                                           = new BasicStroke( 2f );
+    private static final BasicStroke      STROKE_01_DASHED                                  = new BasicStroke( 0.1f,
+                                                                                                                BasicStroke.CAP_SQUARE,
+                                                                                                                BasicStroke.JOIN_ROUND,
+                                                                                                                0,
+                                                                                                                new float[] {
+                                                                                                                        2.0f },   0f );
+   
+    
+    
+    private static final BasicStroke      STROKE_005_DASHED                                  = new BasicStroke( 0.05f,
+                                                                                                                BasicStroke.CAP_SQUARE,
+                                                                                                                BasicStroke.JOIN_ROUND,
+                                                                                                                0,
+                                                                                                                new float[] {
+                                                                                                                        2.0f },
+                                                                                                                0f );
+    private static final BasicStroke      STROKE_001_DASHED                                  = new BasicStroke( 0.01f,
+                                                                                                                BasicStroke.CAP_SQUARE,
+                                                                                                                BasicStroke.JOIN_ROUND,
+                                                                                                                0,
+                                                                                                                new float[] {
+                                                                                                                        2.0f },
+                                                                                                                0f );
     private static final double           TWO_PI                                             = 2 * Math.PI;
     private final static int              WIGGLE                                             = 2;
     private static final String           SHOW_ONLY_THIS_CONF_TYPE                           = null;                                                     //TODO remove me
@@ -2827,8 +2850,11 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
             x += paintTaxonomy( g, node, is_in_found_nodes, to_pdf, to_graphics_file, x );
         }
         setColor( g, node, to_graphics_file, to_pdf, is_in_found_nodes, getTreeColorSet().getSequenceColor() );
+        boolean saw_species = _sb.length() > 0;
+        _sb.setLength( 0 );
+        nodeDataAsSB( node, _sb );
         if ( node.isCollapse() && ( ( !node.isRoot() && !node.getParent().isCollapse() ) || node.isRoot() ) ) {
-            if ( _sb.length() == 0 ) {
+            if ( _sb.length() == 0 && !saw_species ) {
                 if ( getOptions().isShowAbbreviatedLabelsForCollapsedNodes()
                         && ( getControlPanel().isShowTaxonomyCode() || getControlPanel().isShowTaxonomyScientificNames()
                                 || getControlPanel().isShowSeqNames() || getControlPanel().isShowNodeNames() ) ) {
@@ -2838,6 +2864,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
                             && last.getNodeData().isHasTaxonomy()
                             && !ForesterUtil.isEmpty( first.getNodeData().getTaxonomy().getTaxonomyCode() )
                             && !ForesterUtil.isEmpty( last.getNodeData().getTaxonomy().getTaxonomyCode() ) ) {
+                       
                         addLabelForCollapsed( first.getNodeData().getTaxonomy().getTaxonomyCode(),
                                               last.getNodeData().getTaxonomy().getTaxonomyCode(),
                                               node.getAllExternalDescendants().size() );
@@ -2846,7 +2873,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
                             && last.getNodeData().isHasTaxonomy()
                             && !ForesterUtil.isEmpty( first.getNodeData().getTaxonomy().getScientificName() )
                             && !ForesterUtil.isEmpty( last.getNodeData().getTaxonomy().getScientificName() ) ) {
-                        addLabelForCollapsed( first.getNodeData().getTaxonomy().getScientificName(),
+                         addLabelForCollapsed( first.getNodeData().getTaxonomy().getScientificName(),
                                               last.getNodeData().getTaxonomy().getScientificName(),
                                               node.getAllExternalDescendants().size() );
                     }
@@ -2866,23 +2893,35 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
                     }
                 }
             }
-            else if ( _sb.length() > 0 ) {
-                _sb.setLength( 0 );
+            else if ( _sb.length() > 0 || saw_species ) {
+              //  _sb.setLength( 0 );
                 _sb.append( " (" );
                 _sb.append( node.getAllExternalDescendants().size() );
                 _sb.append( ")" );
+              
             }
         }
         else {
-            _sb.setLength( 0 );
+           // _sb.setLength( 0 );
         }
-        nodeDataAsSB( node, _sb );
+       
+       // nodeDataAsSB( node, _sb );
+        
         final boolean using_visual_font = setFont( g, node, is_in_found_nodes );
         float down_shift_factor = 3.0f;
         if ( !node.isExternal() && ( node.getNumberOfDescendants() == 1 ) ) {
             down_shift_factor = 1;
         }
-        final float pos_x = node.getXcoord() + x + 2 + half_box_size;
+        float pos_x;
+        if ( getControlPanel().isDrawPhylogram() && getOptions().isAlignExtLabelsInPhylogram() && (node.isExternal() || node.isCollapse() ) ) {
+            pos_x = ( float ) ( ( getMaxDistanceToRoot() * getXcorrectionFactor() )
+                    + ( getOptions().getDefaultNodeShapeSize() / 2 ) + x + ( 2 * TreePanel.MOVE ) + getXdistance()
+                    + 3 );
+           
+        }
+        else {
+            pos_x = node.getXcoord() + x + 2 + half_box_size;
+        }
         float pos_y;
         if ( !using_visual_font ) {
             pos_y = ( node.getYcoord() + ( getFontMetricsForLargeDefaultFont().getAscent() / down_shift_factor ) );
@@ -2890,64 +2929,19 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
         else {
             pos_y = ( node.getYcoord() + ( getFontMetrics( g.getFont() ).getAscent() / down_shift_factor ) );
         }
+        if ( getControlPanel().isDrawPhylogram() && getOptions().isAlignExtLabelsInPhylogram() && (node.isExternal() || node.isCollapse() ) ) {
+            drawConnection( node.getXcoord(), pos_x - x, node.getYcoord(), 5, 20, g, to_pdf );
+            if ( node.isCollapse()) {
+                pos_x -= add;
+            }
+        }
         final String sb_str = _sb.toString();
         // GUILHEM_BEG ______________
         if ( _control_panel.isShowSequenceRelations() && node.getNodeData().isHasSequence()
                 && ( _query_sequence != null ) ) {
-            int nodeTextBoundsWidth = 0;
-            if ( sb_str.length() > 0 ) {
-                final Rectangle2D node_text_bounds = new TextLayout( sb_str, g.getFont(), _frc ).getBounds(); //would like to remove this 'new', but how...
-                nodeTextBoundsWidth = ( int ) node_text_bounds.getWidth();
-            }
-            if ( node.getNodeData().getSequence().equals( _query_sequence ) ) {
-                if ( nodeTextBoundsWidth > 0 ) { // invert font color and background color to show that this is the query sequence
-                    g.fillRect( ( int ) pos_x - 1, ( int ) pos_y - 8, nodeTextBoundsWidth + 5, 11 );
-                    g.setColor( getTreeColorSet().getBackgroundColor() );
-                }
-            }
-            else {
-                final List<SequenceRelation> seqRelations = node.getNodeData().getSequence().getSequenceRelations();
-                for( final SequenceRelation seqRelation : seqRelations ) {
-                    final boolean fGotRelationWithQuery = ( seqRelation.getRef0().isEqual( _query_sequence )
-                            || seqRelation.getRef1().isEqual( _query_sequence ) )
-                            && seqRelation.getType()
-                                    .equals( getControlPanel().getSequenceRelationTypeBox().getSelectedItem() );
-                    if ( fGotRelationWithQuery ) { // we will underline the text to show that this sequence is ortholog to the query
-                        final double linePosX = node.getXcoord() + 2 + half_box_size;
-                        final String sConfidence = ( !getControlPanel().isShowSequenceRelationConfidence()
-                                || ( seqRelation.getConfidence() == null ) ) ? null
-                                        : " (" + seqRelation.getConfidence().getValue() + ")";
-                        if ( sConfidence != null ) {
-                            float confidenceX = pos_x;
-                            if ( sb_str.length() > 0 ) {
-                                confidenceX += new TextLayout( sb_str, g.getFont(), _frc ).getBounds().getWidth()
-                                        + CONFIDENCE_LEFT_MARGIN;
-                            }
-                            if ( confidenceX > linePosX ) { // let's only display confidence value if we are already displaying at least one of Prot/Gene Name and Taxonomy Code
-                                final int confidenceWidth = ( int ) new TextLayout( sConfidence, g.getFont(), _frc )
-                                        .getBounds().getWidth();
-                                TreePanel.drawString( sConfidence, confidenceX, pos_y, g );
-                                x += CONFIDENCE_LEFT_MARGIN + confidenceWidth;
-                            }
-                        }
-                        if ( ( x + nodeTextBoundsWidth ) > 0 ) /* we only underline if there is something displayed */
-                        {
-                            if ( nodeTextBoundsWidth == 0 ) {
-                                nodeTextBoundsWidth -= 3; /* the gap between taxonomy code and node name should not be underlined if nothing comes after it */
-                            }
-                            else {
-                                nodeTextBoundsWidth += 2;
-                            }
-                            g.drawLine( ( int ) linePosX + 1,
-                                        3 + ( int ) pos_y,
-                                        ( int ) linePosX + x + nodeTextBoundsWidth,
-                                        3 + ( int ) pos_y );
-                            break;
-                        }
-                    }
-                }
-            }
+            x = paintSequenceRelation( g, node, x, half_box_size, pos_x, pos_y, sb_str );
         }
+        // GUILHEM_END _____________
         if ( sb_str.length() > 0 ) {
             if ( !isAllowAttributedStrings() ) {
                 TreePanel.drawString( sb_str, pos_x, pos_y, g );
@@ -2956,7 +2950,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
                 drawStringX( sb_str, pos_x, pos_y, g );
             }
         }
-        // GUILHEM_END _____________
+       
         if ( _sb.length() > 0 ) {
             if ( !using_visual_font && !is_in_found_nodes ) {
                 x += getFontMetricsForLargeDefaultFont().stringWidth( _sb.toString() ) + 5;
@@ -3034,6 +3028,109 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
         return x;
     }
 
+    private final int paintSequenceRelation( final Graphics2D g,
+                      final PhylogenyNode node,
+                      int x,
+                      final int half_box_size,
+                      float pos_x,
+                      float pos_y,
+                      final String sb_str ) {
+        int nodeTextBoundsWidth = 0;
+        if ( sb_str.length() > 0 ) {
+            final Rectangle2D node_text_bounds = new TextLayout( sb_str, g.getFont(), _frc ).getBounds(); //would like to remove this 'new', but how...
+            nodeTextBoundsWidth = ( int ) node_text_bounds.getWidth();
+        }
+        if ( node.getNodeData().getSequence().equals( _query_sequence ) ) {
+            if ( nodeTextBoundsWidth > 0 ) { // invert font color and background color to show that this is the query sequence
+                g.fillRect( ( int ) pos_x - 1, ( int ) pos_y - 8, nodeTextBoundsWidth + 5, 11 );
+                g.setColor( getTreeColorSet().getBackgroundColor() );
+            }
+        }
+        else {
+            final List<SequenceRelation> seqRelations = node.getNodeData().getSequence().getSequenceRelations();
+            for( final SequenceRelation seqRelation : seqRelations ) {
+                final boolean fGotRelationWithQuery = ( seqRelation.getRef0().isEqual( _query_sequence )
+                        || seqRelation.getRef1().isEqual( _query_sequence ) )
+                        && seqRelation.getType()
+                                .equals( getControlPanel().getSequenceRelationTypeBox().getSelectedItem() );
+                if ( fGotRelationWithQuery ) { // we will underline the text to show that this sequence is ortholog to the query
+                    final double linePosX = node.getXcoord() + 2 + half_box_size;
+                    final String sConfidence = ( !getControlPanel().isShowSequenceRelationConfidence()
+                            || ( seqRelation.getConfidence() == null ) ) ? null
+                                    : " (" + seqRelation.getConfidence().getValue() + ")";
+                    if ( sConfidence != null ) {
+                        float confidenceX = pos_x;
+                        if ( sb_str.length() > 0 ) {
+                            confidenceX += new TextLayout( sb_str, g.getFont(), _frc ).getBounds().getWidth()
+                                    + CONFIDENCE_LEFT_MARGIN;
+                        }
+                        if ( confidenceX > linePosX ) { // let's only display confidence value if we are already displaying at least one of Prot/Gene Name and Taxonomy Code
+                            final int confidenceWidth = ( int ) new TextLayout( sConfidence, g.getFont(), _frc )
+                                    .getBounds().getWidth();
+                            TreePanel.drawString( sConfidence, confidenceX, pos_y, g );
+                            x += CONFIDENCE_LEFT_MARGIN + confidenceWidth;
+                        }
+                    }
+                    if ( ( x + nodeTextBoundsWidth ) > 0 ) /* we only underline if there is something displayed */
+                    {
+                        if ( nodeTextBoundsWidth == 0 ) {
+                            nodeTextBoundsWidth -= 3; /* the gap between taxonomy code and node name should not be underlined if nothing comes after it */
+                        }
+                        else {
+                            nodeTextBoundsWidth += 2;
+                        }
+                        g.drawLine( ( int ) linePosX + 1,
+                                    3 + ( int ) pos_y,
+                                    ( int ) linePosX + x + nodeTextBoundsWidth,
+                                    3 + ( int ) pos_y );
+                        break;
+                    }
+                }
+            }
+        }
+        return x;
+    }
+
+    private final void drawConnection( final float x1,
+                                       final float x2,
+                                       final float y,
+                                       final int dist_left,
+                                       final int dist_right,
+                                       final Graphics2D g,
+                                       final boolean pdf ) {
+        if ( ( ( x1 + dist_left ) < ( x2 - dist_right ) ) ) {
+            final Stroke strok = g.getStroke();
+            Color col = null;
+            if ( strok == STROKE_005 ) {
+                g.setStroke( STROKE_001_DASHED );
+            }
+            else if ( strok == STROKE_01 ) {
+                g.setStroke( STROKE_005_DASHED );
+            }
+            else {
+                g.setStroke( STROKE_01_DASHED );
+            }
+            if ( pdf ) {
+                col = g.getColor();
+                g.setColor( lighter( col ) );
+            }
+            drawLine( x1 + dist_left, y, x2 - dist_right, y, g );
+            g.setStroke( strok );
+            if ( pdf ) {
+                g.setColor( col );
+            }
+        }
+    }
+
+    public static Color lighter( final Color color ) {
+        if ( ( color.getRed() == 0 ) && ( color.getGreen() == 0 ) && ( color.getBlue() == 0 ) ) {
+            return new Color( 200, 200, 200 );
+        }
+        else {
+            return color;
+        }
+    }
+
     private final void addLabelForCollapsed( final String first, final String last, final int size ) {
         _sb.append( first.length() < AptxConstants.MAX_LENGTH_FOR_COLLAPSED_NAME ? first
                 : first.substring( 0, AptxConstants.MAX_LENGTH_FOR_COLLAPSED_NAME - 1 ) );
@@ -3538,7 +3635,12 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
         final Taxonomy taxonomy = node.getNodeData().getTaxonomy();
         final boolean using_visual_font = setFont( g, node, is_in_found_nodes );
         setColor( g, node, to_graphics_file, to_pdf, is_in_found_nodes, getTreeColorSet().getTaxonomyColor() );
-        final float start_x = node.getXcoord() + 3 + ( getOptions().getDefaultNodeShapeSize() / 2 ) + x_shift;
+        float start_x = node.getXcoord() + 3 + ( getOptions().getDefaultNodeShapeSize() / 2 ) + x_shift;
+        if ( getControlPanel().isDrawPhylogram() && getOptions().isAlignExtLabelsInPhylogram() && node.isExternal() ) {
+            start_x = ( float ) ( ( getMaxDistanceToRoot() * getXcorrectionFactor() )
+                    + ( getOptions().getDefaultNodeShapeSize() / 2 ) + x_shift + ( 2 * TreePanel.MOVE ) + getXdistance()
+                    + 3 );
+        }
         float start_y;
         if ( !using_visual_font ) {
             start_y = node.getYcoord() + ( getFontMetricsForLargeDefaultFont().getAscent()
@@ -4546,6 +4648,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
             setYdistance( ydist );
             setOvXDistance( ov_xdist );
             final double height = _phylogeny.calculateHeight( !_options.isCollapsedWithAverageHeigh() );
+            //final double height = PhylogenyMethods.calculateMaxDepth( _phylogeny );
             if ( height > 0 ) {
                 final float corr = ( float ) ( ( x - ( 2.0 * TreePanel.MOVE ) - getLongestExtNodeInfo()
                         - getXdistance() ) / height );
@@ -5827,6 +5930,9 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
 
     final void recalculateMaxDistanceToRoot() {
         _max_distance_to_root = PhylogenyMethods.calculateMaxDistanceToRoot( getPhylogeny() );
+        if ( getPhylogeny().getRoot().getDistanceToParent() > 0 ) {
+            _max_distance_to_root += getPhylogeny().getRoot().getDistanceToParent();
+        }
     }
 
     /**
@@ -6294,6 +6400,15 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
             getControlPanel().activateButtonToReturnToSuperTree( _subtree_index );
         }
     }
+    
+    final void updateButtonToUncollapseAll() {
+        if ( PhylogenyMethods.isHasCollapsedNodes(_phylogeny) ) {
+            getControlPanel().activateButtonToUncollapseAll();
+        }
+        else {
+            getControlPanel().deactivateButtonToUncollapseAll();
+        }
+    }
 
     final void zoomInDomainStructure() {
         if ( _domain_structure_width < 2000 ) {
index 34eb487..876510c 100644 (file)
@@ -143,7 +143,7 @@ public class Phylogeny {
                     max = l;
                 }
             }
-            return max + ( n.getDistanceToParent() > 0 ? n.getDistanceToParent() : 0) ;
+            return max + ( n.getDistanceToParent() > 0 ? n.getDistanceToParent() : 0);
         }
     }
 
@@ -1064,7 +1064,7 @@ public class Phylogeny {
      */
     public void setRooted( final boolean b ) {
         _rooted = b;
-    } // setRooted( boolean )
+    }
 
     public void setSequenceRelationQueries( final Collection<Sequence> sequencesByName ) {
         _sequenceRelationQueries = sequencesByName;
index 97eba29..1532e41 100644 (file)
@@ -1004,7 +1004,7 @@ public class PhylogenyMethods {
     private static enum NDF {
                              NodeName( "NN" ),
                              TaxonomyCode( "TC" ),
-                             TaxonomyCommonName( "CN" ),
+                             TaxonomyCommonName( "TN" ),
                              TaxonomyScientificName( "TS" ),
                              TaxonomyIdentifier( "TI" ),
                              TaxonomySynonym( "SY" ),
@@ -2142,5 +2142,15 @@ public class PhylogenyMethods {
         }
         return n;
     }
+
+    public final static boolean isHasCollapsedNodes( final Phylogeny phy ) {
+        for( final PhylogenyNodeIterator iter = phy.iteratorPreorder(); iter.hasNext(); ) {
+            final PhylogenyNode n = iter.next();
+            if ( !n.isExternal() && ( n.isCollapse() ) ) {
+                return true;
+            }
+        }
+        return false;
+    }
     
 }