inprogress
authorcmzmasek@gmail.com <cmzmasek@gmail.com@ca865154-3058-d1c3-3e42-d8f55a55bdbd>
Thu, 10 Apr 2014 00:28:48 +0000 (00:28 +0000)
committercmzmasek@gmail.com <cmzmasek@gmail.com@ca865154-3058-d1c3-3e42-d8f55a55bdbd>
Thu, 10 Apr 2014 00:28:48 +0000 (00:28 +0000)
forester/java/src/org/forester/archaeopteryx/TreePanel.java
forester/java/src/org/forester/archaeopteryx/webservices/WebserviceUtil.java

index 68b6376..25e5040 100644 (file)
@@ -4143,49 +4143,78 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
                         .getUris().isEmpty() ) ) {
             x += drawTaxonomyImage( node.getXcoord() + 2 + half_box_size, node.getYcoord(), node, g );
         }
-        if ( ( getControlPanel().isShowTaxonomyCode() || getControlPanel().isShowTaxonomyScientificNames() || getControlPanel()
-                .isShowTaxonomyCommonNames() ) && node.getNodeData().isHasTaxonomy() ) {
-            x += paintTaxonomy( g, node, is_in_found_nodes, to_pdf, to_graphics_file, x );
-        }
-        if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
-            g.setColor( Color.BLACK );
-        }
-        else if ( is_in_found_nodes ) {
-            g.setColor( getColorForFoundNode( node ) );
-        }
-        else if ( getControlPanel().isUseVisualStyles() && ( node.getNodeData().getNodeVisualData() != null )
-                && ( node.getNodeData().getNodeVisualData().getFontColor() != null ) ) {
-            g.setColor( node.getNodeData().getNodeVisualData().getFontColor() );
-        }
-        else if ( getControlPanel().isColorAccordingToTaxonomy() ) {
-            g.setColor( getTaxonomyBasedColor( node ) );
-        }
-        else if ( getControlPanel().isColorAccordingToAnnotation()
-                && ( node.getNodeData().isHasSequence() && ( node.getNodeData().getSequence().getAnnotations() != null ) && ( !node
-                        .getNodeData().getSequence().getAnnotations().isEmpty() ) ) ) {
-            g.setColor( calculateColorForAnnotation( node.getNodeData().getSequence().getAnnotations() ) );
-        }
-        else if ( getOptions().isColorLabelsSameAsParentBranch() && getControlPanel().isUseVisualStyles()
-                && ( PhylogenyMethods.getBranchColorValue( node ) != null ) ) {
-            g.setColor( PhylogenyMethods.getBranchColorValue( node ) );
-        }
-        else if ( to_pdf ) {
-            g.setColor( Color.BLACK );
-        }
-        else {
-            g.setColor( getTreeColorSet().getSequenceColor() );
+        //if ( ( getControlPanel().isShowTaxonomyCode() || getControlPanel().isShowTaxonomyScientificNames() || getControlPanel()
+        //      .isShowTaxonomyCommonNames() ) && node.getNodeData().isHasTaxonomy() ) {
+        // 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() );
+        //
+        if ( node.getNodeData().isHasTaxonomy() ) {
+            final Taxonomy taxonomy = node.getNodeData().getTaxonomy();
+            if ( _control_panel.isShowTaxonomyCode() && !ForesterUtil.isEmpty( taxonomy.getTaxonomyCode() ) ) {
+                _sb.append( taxonomy.getTaxonomyCode() );
+                _sb.append( " " );
+            }
+            if ( _control_panel.isShowTaxonomyScientificNames() && _control_panel.isShowTaxonomyCommonNames() ) {
+                if ( !ForesterUtil.isEmpty( taxonomy.getScientificName() )
+                        && !ForesterUtil.isEmpty( taxonomy.getCommonName() ) ) {
+                    if ( getOptions().isAbbreviateScientificTaxonNames()
+                            && ( taxonomy.getScientificName().indexOf( ' ' ) > 0 ) ) {
+                        abbreviateScientificName( taxonomy.getScientificName() );
+                    }
+                    else {
+                        _sb.append( taxonomy.getScientificName() );
+                    }
+                    _sb.append( " (" );
+                    _sb.append( taxonomy.getCommonName() );
+                    _sb.append( ") " );
+                }
+                else if ( !ForesterUtil.isEmpty( taxonomy.getScientificName() ) ) {
+                    if ( getOptions().isAbbreviateScientificTaxonNames()
+                            && ( taxonomy.getScientificName().indexOf( ' ' ) > 0 ) ) {
+                        abbreviateScientificName( taxonomy.getScientificName() );
+                    }
+                    else {
+                        _sb.append( taxonomy.getScientificName() );
+                    }
+                    _sb.append( " " );
+                }
+                else if ( !ForesterUtil.isEmpty( taxonomy.getCommonName() ) ) {
+                    _sb.append( taxonomy.getCommonName() );
+                    _sb.append( " " );
+                }
+            }
+            else if ( _control_panel.isShowTaxonomyScientificNames() ) {
+                if ( !ForesterUtil.isEmpty( taxonomy.getScientificName() ) ) {
+                    if ( getOptions().isAbbreviateScientificTaxonNames()
+                            && ( taxonomy.getScientificName().indexOf( ' ' ) > 0 ) ) {
+                        abbreviateScientificName( taxonomy.getScientificName() );
+                    }
+                    else {
+                        _sb.append( taxonomy.getScientificName() );
+                    }
+                    _sb.append( " " );
+                }
+            }
+            else if ( _control_panel.isShowTaxonomyCommonNames() ) {
+                if ( !ForesterUtil.isEmpty( taxonomy.getCommonName() ) ) {
+                    _sb.append( taxonomy.getCommonName() );
+                    _sb.append( " " );
+                }
+            }
         }
+        //
         if ( node.isCollapse() && ( ( !node.isRoot() && !node.getParent().isCollapse() ) || node.isRoot() ) ) {
             if ( _sb.length() > 0 ) {
-                _sb.setLength( 0 );
-                _sb.append( "(" );
+                //_sb.setLength( 0 );
+                _sb.append( " (" );
                 _sb.append( node.getAllExternalDescendants().size() );
                 _sb.append( ")" );
             }
         }
-        else {
-            _sb.setLength( 0 );
-        }
+        //else {
+        //_sb.setLength( 0 );
+        //}
         if ( getControlPanel().isShowNodeNames() && ( node.getName().length() > 0 ) ) {
             if ( _sb.length() > 0 ) {
                 _sb.append( " " );
@@ -4228,9 +4257,10 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
             }
             _sb.append( propertiesToString( node ) );
         }
+        Font visual_font = null;
         if ( getControlPanel().isUseVisualStyles() && ( node.getNodeData().getNodeVisualData() != null ) ) {
-            final Font f = node.getNodeData().getNodeVisualData().getFont();
-            g.setFont( f != null ? f : getTreeFontSet().getLargeFont() );
+            visual_font = node.getNodeData().getNodeVisualData().getFont();
+            g.setFont( visual_font != null ? visual_font : getTreeFontSet().getLargeFont() );
         }
         else {
             g.setFont( getTreeFontSet().getLargeFont() );
@@ -4243,7 +4273,13 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
             down_shift_factor = 1;
         }
         final double pos_x = node.getXcoord() + x + 2 + half_box_size;
-        final double pos_y = ( node.getYcoord() + ( getTreeFontSet()._fm_large.getAscent() / down_shift_factor ) );
+        double pos_y;
+        if ( visual_font == null ) {
+            pos_y = ( node.getYcoord() + ( getTreeFontSet()._fm_large.getAscent() / down_shift_factor ) );
+        }
+        else {
+            pos_y = ( node.getYcoord() + ( getFontMetrics( visual_font ).getAscent() / down_shift_factor ) );
+        }
         final String sb_str = _sb.toString();
         // GUILHEM_BEG ______________
         if ( _control_panel.isShowSequenceRelations() && node.getNodeData().isHasSequence()
@@ -4366,22 +4402,22 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
         }
     }
 
-    final private void paintNodeDataUnrootedCirc( final Graphics2D g,
-                                                  final PhylogenyNode node,
-                                                  final boolean to_pdf,
-                                                  final boolean to_graphics_file,
-                                                  final boolean radial_labels,
-                                                  final double ur_angle,
-                                                  final boolean is_in_found_nodes ) {
-        if ( isNodeDataInvisibleUnrootedCirc( node ) && !to_graphics_file && !to_pdf ) {
-            return;
-        }
+    private void setColor( final Graphics2D g,
+                           final PhylogenyNode node,
+                           final boolean to_graphics_file,
+                           final boolean to_pdf,
+                           final boolean is_in_found_nodes,
+                           final Color default_color ) {
         if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
             g.setColor( Color.BLACK );
         }
         else if ( is_in_found_nodes ) {
             g.setColor( getColorForFoundNode( node ) );
         }
+        else if ( getControlPanel().isUseVisualStyles() && ( node.getNodeData().getNodeVisualData() != null )
+                && ( node.getNodeData().getNodeVisualData().getFontColor() != null ) ) {
+            g.setColor( node.getNodeData().getNodeVisualData().getFontColor() );
+        }
         else if ( getControlPanel().isColorAccordingToTaxonomy() ) {
             g.setColor( getTaxonomyBasedColor( node ) );
         }
@@ -4390,9 +4426,29 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
                         .getNodeData().getSequence().getAnnotations().isEmpty() ) ) ) {
             g.setColor( calculateColorForAnnotation( node.getNodeData().getSequence().getAnnotations() ) );
         }
+        else if ( getOptions().isColorLabelsSameAsParentBranch() && getControlPanel().isUseVisualStyles()
+                && ( PhylogenyMethods.getBranchColorValue( node ) != null ) ) {
+            g.setColor( PhylogenyMethods.getBranchColorValue( node ) );
+        }
+        else if ( to_pdf ) {
+            g.setColor( Color.BLACK );
+        }
         else {
-            g.setColor( getTreeColorSet().getSequenceColor() );
+            g.setColor( default_color );
+        }
+    }
+
+    final private void paintNodeDataUnrootedCirc( final Graphics2D g,
+                                                  final PhylogenyNode node,
+                                                  final boolean to_pdf,
+                                                  final boolean to_graphics_file,
+                                                  final boolean radial_labels,
+                                                  final double ur_angle,
+                                                  final boolean is_in_found_nodes ) {
+        if ( isNodeDataInvisibleUnrootedCirc( node ) && !to_graphics_file && !to_pdf ) {
+            return;
         }
+        setColor( g, node, to_graphics_file, to_pdf, is_in_found_nodes, getTreeColorSet().getSequenceColor() );
         _sb.setLength( 0 );
         _sb.append( " " );
         if ( node.getNodeData().isHasTaxonomy()
@@ -4875,30 +4931,25 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
                                      final boolean to_graphics_file,
                                      final double x_shift ) {
         final Taxonomy taxonomy = node.getNodeData().getTaxonomy();
-        g.setFont( getTreeFontSet().getLargeItalicFont() );
-        if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
-            g.setColor( Color.BLACK );
-        }
-        else if ( is_in_found_nodes ) {
-            g.setFont( getTreeFontSet().getLargeItalicFont().deriveFont( TreeFontSet.BOLD_AND_ITALIC ) );
-            g.setColor( getColorForFoundNode( node ) );
-        }
-        else if ( getControlPanel().isColorAccordingToTaxonomy() ) {
-            g.setColor( getTaxonomyBasedColor( node ) );
+        Font visual_font = null;
+        if ( getControlPanel().isUseVisualStyles() && ( node.getNodeData().getNodeVisualData() != null ) ) {
+            visual_font = node.getNodeData().getNodeVisualData().getFont();
+            g.setFont( visual_font != null ? visual_font : getTreeFontSet().getLargeItalicFont() );
         }
-        else if ( getOptions().isColorLabelsSameAsParentBranch() && getControlPanel().isUseVisualStyles()
-                && ( PhylogenyMethods.getBranchColorValue( node ) != null ) ) {
-            g.setColor( PhylogenyMethods.getBranchColorValue( node ) );
+        else {
+            g.setFont( getTreeFontSet().getLargeItalicFont() );
         }
-        else if ( to_pdf ) {
-            g.setColor( Color.BLACK );
+        setColor( g, node, to_graphics_file, to_pdf, is_in_found_nodes, getTreeColorSet().getTaxonomyColor() );
+        final double start_x = node.getXcoord() + 3 + ( getOptions().getDefaultNodeShapeSize() / 2 ) + x_shift;
+        double start_y;
+        if ( visual_font == null ) {
+            start_y = node.getYcoord()
+                    + ( getTreeFontSet()._fm_large.getAscent() / ( node.getNumberOfDescendants() == 1 ? 1 : 3.0 ) );
         }
         else {
-            g.setColor( getTreeColorSet().getTaxonomyColor() );
+            start_y = node.getYcoord()
+                    + ( getFontMetrics( visual_font ).getAscent() / ( node.getNumberOfDescendants() == 1 ? 1 : 3.0 ) );
         }
-        final double start_x = node.getXcoord() + 3 + ( getOptions().getDefaultNodeShapeSize() / 2 ) + x_shift;
-        final double start_y = node.getYcoord()
-                + ( getTreeFontSet()._fm_large.getAscent() / ( node.getNumberOfDescendants() == 1 ? 1 : 3.0 ) );
         _sb.setLength( 0 );
         if ( _control_panel.isShowTaxonomyCode() && !ForesterUtil.isEmpty( taxonomy.getTaxonomyCode() ) ) {
             _sb.append( taxonomy.getTaxonomyCode() );
@@ -4969,7 +5020,10 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
             return getTreeFontSet()._fm_large_italic_bold.stringWidth( label );
         }
         else {
-            return getTreeFontSet()._fm_large_italic.stringWidth( label );
+            if ( visual_font == null ) {
+                return getTreeFontSet()._fm_large_italic.stringWidth( label );
+            }
+            return getFontMetrics( visual_font ).stringWidth( label );
         }
     }
 
index ce35430..e56eb9f 100644 (file)
@@ -61,17 +61,6 @@ public final class WebserviceUtil {
 
     public static List<PhylogeniesWebserviceClient> createDefaultClients() {
         final List<PhylogeniesWebserviceClient> clients = new ArrayList<PhylogeniesWebserviceClient>();
-        clients.add( new BasicPhylogeniesWebserviceClient( TOL_NAME,
-                                                           "Read Tree from Tree of Life (ToL)...",
-                                                           "Use ToL webservice to obtain a evolutionary tree",
-                                                           "Please enter a Tree of Life node identifier\n(Examples: "
-                                                                   + "14923 for ray-finned fishes, 19386 for Cephalopoda, 2461 for Cnidaria)",
-                                                           WsPhylogenyFormat.TOL_XML_RESPONSE,
-                                                           PhylogenyMethods.PhylogenyNodeField.TAXONOMY_SCIENTIFIC_NAME,
-                                                           WebserviceUtil.TOL_WEBSERVER,
-                                                           true,
-                                                           "http://tolweb.org",
-                                                           null ) );
         clients.add( new BasicPhylogeniesWebserviceClient( TREE_BASE_NAME,
                                                            "Read Tree(s) from TreeBASE Study...",
                                                            "Use TreeBASE to obtain evolutionary tree(s) from a study",
@@ -120,6 +109,17 @@ public final class WebserviceUtil {
                                                            true,
                                                            "http://www.treefam.org",
                                                            TREE_FAM_INST ) );
+        clients.add( new BasicPhylogeniesWebserviceClient( TOL_NAME,
+                                                           "Read Tree from Tree of Life (ToL)...",
+                                                           "Use ToL webservice to obtain a evolutionary tree",
+                                                           "Please enter a Tree of Life node identifier\n(Examples: "
+                                                                   + "14923 for ray-finned fishes, 19386 for Cephalopoda, 2461 for Cnidaria)",
+                                                           WsPhylogenyFormat.TOL_XML_RESPONSE,
+                                                           PhylogenyMethods.PhylogenyNodeField.TAXONOMY_SCIENTIFIC_NAME,
+                                                           WebserviceUtil.TOL_WEBSERVER,
+                                                           true,
+                                                           "http://tolweb.org",
+                                                           null ) );
         return clients;
     }