in progress
[jalview.git] / forester / java / src / org / forester / archaeopteryx / TreePanel.java
index ab1a753..4178b2a 100644 (file)
@@ -251,7 +251,8 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
     private float                        _x_correction_factor                               = 0.0f;
     private float                        _x_distance                                        = 0.0f;
     private float                        _y_distance                                        = 0.0f;
-    
+    private int                          _length_of_longest_text;
+    private int                          _longest_domain;
     //  private Image                           offscreenImage;
     //  private Graphics                        offscreenGraphics;
     //  private Dimension                       offscreenDimension;
@@ -520,6 +521,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
                         }
                     }
                 }
+                _length_of_longest_text = calcLengthOfLongestText();
             }
             int ext_nodes = _phylogeny.getRoot().getNumberOfExternalNodes();
             final int max_depth = PhylogenyMethods.calculateMaxDepth( _phylogeny );
@@ -601,6 +603,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
         }
         int longest = 30;
         int longest_txt = 0;
+        _longest_domain = 0;
         PhylogenyNode longest_txt_node = _phylogeny.getFirstExternalNode();
         for( final PhylogenyNode node : _phylogeny.getExternalNodes() ) {
             int sum = 0;
@@ -648,6 +651,9 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
                 final DomainArchitecture d = node.getNodeData().getSequence().getDomainArchitecture();
                 sum += ( ( _domain_structure_width / ( ( RenderableDomainArchitecture ) d ).getOriginalSize()
                         .getWidth() ) * d.getTotalLength() ) + 10;
+                if ( d.getTotalLength() > _longest_domain ) {
+                    _longest_domain = d.getTotalLength();
+                }
             }
             if ( sum >= max_length ) {
                 _longest_ext_node_info = max_length;
@@ -731,11 +737,11 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
             }
             if ( c == null ) {
                 if ( !ForesterUtil.isEmpty( tax.getTaxonomyCode() ) ) {
-                    c = TreePanelUtil.calculateColorFromString( tax.getTaxonomyCode(), true );
+                    c = AptxUtil.calculateColorFromString( tax.getTaxonomyCode(), true );
                     getControlPanel().getSpeciesColors().put( tax.getTaxonomyCode(), c );
                 }
                 else {
-                    c = TreePanelUtil.calculateColorFromString( tax.getScientificName(), true );
+                    c = AptxUtil.calculateColorFromString( tax.getScientificName(), true );
                     getControlPanel().getSpeciesColors().put( tax.getScientificName(), c );
                 }
             }
@@ -751,7 +757,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
         final String seq_name = seq.getName();
         c = getControlPanel().getSequenceColors().get( seq_name );
         if ( c == null ) {
-            c = TreePanelUtil.calculateColorFromString( seq_name, false );
+            c = AptxUtil.calculateColorFromString( seq_name, false );
             getControlPanel().getSequenceColors().put( seq_name, c );
         }
         return c;
@@ -883,6 +889,9 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
                 _control_panel.getColorAccSpeciesCb().setSelected( false );
             }
             _options.setColorLabelsSameAsParentBranch( true );
+            if ( getMainPanel().getMainFrame()._color_labels_same_as_parent_branch != null ) {
+                getMainPanel().getMainFrame()._color_labels_same_as_parent_branch.setSelected( true );
+            }
             _control_panel.repaint();
         }
         setArrowCursor();
@@ -1043,10 +1052,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
         return getTreeColorSet().getSequenceColor();
     }
 
-    /**
-     * @return pointer to colorset for tree drawing
-     */
-    final TreeColorSet getTreeColorSet() {
+    public final TreeColorSet getTreeColorSet() {
         return getMainPanel().getTreeColorSet();
     }
 
@@ -1082,8 +1088,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
                     && ( node.getNodeData().getSequence().getDomainArchitecture() != null ) ) {
                 RenderableDomainArchitecture rds = null;
                 if ( !( node.getNodeData().getSequence().getDomainArchitecture() instanceof RenderableDomainArchitecture ) ) {
-                    rds = new RenderableDomainArchitecture( node.getNodeData().getSequence().getDomainArchitecture(),
-                                                            getConfiguration() );
+                    rds = new RenderableDomainArchitecture( node.getNodeData().getSequence().getDomainArchitecture() );
                     node.getNodeData().getSequence().setDomainArchitecture( rds );
                 }
                 else {
@@ -2382,7 +2387,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
             if ( !ForesterUtil.isEmpty( ann_str ) ) {
                 c = getControlPanel().getAnnotationColors().get( ann_str );
                 if ( c == null ) {
-                    c = TreePanelUtil.calculateColorFromString( ann_str, false );
+                    c = AptxUtil.calculateColorFromString( ann_str, false );
                     getControlPanel().getAnnotationColors().put( ann_str, c );
                 }
                 if ( c == null ) {
@@ -4695,7 +4700,6 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
         final boolean disallow_shortcutting = ( dynamic_hiding_factor < 40 );
         float min_dist = 1.5f;
         if ( !disallow_shortcutting ) {
-            //   System.out.println( dynamic_hiding_factor );
             if ( dynamic_hiding_factor > 4000 ) {
                 min_dist = 4;
             }
@@ -4773,7 +4777,6 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
         if ( ( !getControlPanel().isShowInternalData() && !node.isExternal() ) ) {
             return;
         }
-        int length_of_longest_text = -1;
         if ( getControlPanel().isShowDomainArchitectures() && node.getNodeData().isHasSequence()
                 && ( node.getNodeData().getSequence().getDomainArchitecture() != null ) ) {
             RenderableDomainArchitecture rds = null;
@@ -4784,27 +4787,61 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
                 cce.printStackTrace();
             }
             if ( rds != null ) {
-                rds.setRenderingHeight( 6 );
+                final int default_height = 7;
+                float y = getYdistance();
+                if ( getControlPanel().isDynamicallyHideData() ) {
+                    y = getTreeFontSet().getFontMetricsLarge().getHeight();
+                }
+                final int h = y < default_height ? ForesterUtil.roundToInt( y ) : default_height;
+                rds.setRenderingHeight( h > 1 ? h : 2 );
                 if ( getControlPanel().isDrawPhylogram() ) {
-                    rds.render( node.getXcoord() + x, node.getYcoord() - 3, g, this, to_pdf );
+                    if ( getOptions().isLineUpRendarableNodeData() ) {
+                        if ( getOptions().isRightLineUpDomains() ) {
+                            rds.render( getMaxDistanceToRoot() * getXcorrectionFactor() + _length_of_longest_text
+                                                + ( _longest_domain - rds.getTotalLength() )
+                                                * rds.getRenderingFactorWidth(),
+                                        node.getYcoord() - ( h / 2 ),
+                                        g,
+                                        this,
+                                        to_pdf );
+                        }
+                        else {
+                            rds.render( getMaxDistanceToRoot() * getXcorrectionFactor() + _length_of_longest_text,
+                                        node.getYcoord() - ( h / 2 ),
+                                        g,
+                                        this,
+                                        to_pdf );
+                        }
+                    }
+                    else {
+                        rds.render( node.getXcoord() + x, node.getYcoord() - ( h / 2 ), g, this, to_pdf );
+                    }
                 }
                 else {
-                    length_of_longest_text = calcLengthOfLongestText();
-                    rds.render( getPhylogeny().getFirstExternalNode().getXcoord() + length_of_longest_text,
-                                node.getYcoord() - 3,
-                                g,
-                                this,
-                                to_pdf );
+                    if ( getOptions().isRightLineUpDomains() ) {
+                        rds.render( getPhylogeny().getFirstExternalNode().getXcoord() + _length_of_longest_text
+                                            - 20 + ( _longest_domain - rds.getTotalLength() ) 
+                                            * rds.getRenderingFactorWidth(),
+                                    node.getYcoord() - ( h / 2 ),
+                                    g,
+                                    this,
+                                    to_pdf );
+                    }
+                    else {
+                        rds.render( getPhylogeny().getFirstExternalNode().getXcoord() + _length_of_longest_text,
+                                    node.getYcoord() - ( h / 2 ),
+                                    g,
+                                    this,
+                                    to_pdf );
+                    }
                 }
             }
         }
-      
         if ( getControlPanel().isShowVectorData() && ( node.getNodeData().getVector() != null )
                 && ( node.getNodeData().getVector().size() > 0 ) && ( getStatisticsForExpressionValues() != null ) ) {
             final RenderableVector rv = RenderableVector.createInstance( node.getNodeData().getVector(),
                                                                          getStatisticsForExpressionValues(),
                                                                          getConfiguration() );
-
             if ( rv != null ) {
                 double domain_add = 0;
                 if ( getControlPanel().isShowDomainArchitectures() && node.getNodeData().isHasSequence()
@@ -4815,26 +4852,23 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
                     rv.render( node.getXcoord() + x + domain_add, node.getYcoord() - 3, g, this, to_pdf );
                 }
                 else {
-                    if ( length_of_longest_text < 0 ) {
-                        length_of_longest_text = calcLengthOfLongestText();
-                    }
-                    rv.render( getPhylogeny().getFirstExternalNode().getXcoord() + length_of_longest_text + domain_add,
-                                node.getYcoord() - 3,
-                                g,
-                                this,
-                                to_pdf );
+                    rv.render( getPhylogeny().getFirstExternalNode().getXcoord() + _length_of_longest_text + domain_add,
+                               node.getYcoord() - 3,
+                               g,
+                               this,
+                               to_pdf );
                 }
             }
         }
     }
 
-    private int calcLengthOfLongestText() {
+    final private int calcLengthOfLongestText() {
         final StringBuilder sb = new StringBuilder();
         nodeDataAsSB( _ext_node_with_longest_txt_info, sb );
         if ( _ext_node_with_longest_txt_info.getNodeData().isHasTaxonomy() ) {
             nodeTaxonomyDataAsSB( _ext_node_with_longest_txt_info.getNodeData().getTaxonomy(), sb );
         }
-        return getFontMetricsForLargeDefaultFont().stringWidth( sb.toString() + " " );
+        return getFontMetricsForLargeDefaultFont().stringWidth( sb.toString() );
     }
 
     final private void paintOvRectangle( final Graphics2D g ) {