+ // final List<PhylogenyNode> nodes = phy.getNodesViaTaxonomyCode( tax_code );
+ // Color c = null;
+ // if ( ( nodes == null ) || nodes.isEmpty() ) {
+ // throw new IllegalArgumentException( "code " + tax_code + " is not found" );
+ // }
+ // if ( nodes.size() != 1 ) {
+ // throw new IllegalArgumentException( "code " + tax_code + " is not unique" );
+ // }
+ // PhylogenyNode n = nodes.get( 0 );
+ // while ( n != null ) {
+ // if ( n.getNodeData().isHasTaxonomy()
+ // && !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getScientificName() ) ) {
+ // c = ForesterUtil.obtainColorDependingOnTaxonomyGroup( n.getNodeData().getTaxonomy()
+ // .getScientificName(), tax_code );
+ // }
+ // if ( ( c == null ) && !ForesterUtil.isEmpty( n.getName() ) ) {
+ // c = ForesterUtil.obtainColorDependingOnTaxonomyGroup( n.getName(), tax_code );
+ // }
+ // if ( c != null ) {
+ // break;
+ // }
+ // n = n.getParent();
+ // }
+ final String group = obtainTaxonomyGroup( tax_code, phy );
+ final Color c = ForesterUtil.obtainColorDependingOnTaxonomyGroup( group );
+ if ( c == null ) {
+ throw new IllegalArgumentException( "no color found for taxonomy group \"" + group
+ + "\" for code \"" + tax_code + "\"" );
+ }
+ final String hex = String.format( "#%02x%02x%02x", c.getRed(), c.getGreen(), c.getBlue() );
+ _TAXCODE_HEXCOLORSTRING_MAP.put( tax_code, hex );
+ }
+ else {
+ throw new IllegalArgumentException( "unable to obtain color for code " + tax_code
+ + " (tree is null or empty and code is not in map)" );
+ }
+ }
+ return _TAXCODE_HEXCOLORSTRING_MAP.get( tax_code );
+ }
+
+ public static String obtainTaxonomyGroup( final String tax_code, final Phylogeny species_tree )
+ throws IllegalArgumentException {
+ if ( !_TAXCODE_TAXGROUP_MAP.containsKey( tax_code ) ) {
+ if ( ( species_tree != null ) && !species_tree.isEmpty() ) {
+ final List<PhylogenyNode> nodes = species_tree.getNodesViaTaxonomyCode( tax_code );