+ if ( ( isInFoundNodes( node ) || isInCurrentExternalNodes( node ) )
+ || ( getOptions().isShowDefaultNodeShapesExternal() && node.isExternal() )
+ || ( getOptions().isShowDefaultNodeShapesInternal() && node.isInternal() )
+ || ( getOptions().isShowDefaultNodeShapesForMarkedNodes()
+ && ( node.getNodeData().getNodeVisualData() != null )
+ && ( !node.getNodeData().getNodeVisualData().isEmpty() ) )
+ || ( getControlPanel().isUseVisualStyles() && ( ( node.getNodeData().getNodeVisualData() != null )
+ && ( ( node.getNodeData().getNodeVisualData().getNodeColor() != null )
+ || ( node.getNodeData().getNodeVisualData().getSize() != NodeVisualData.DEFAULT_SIZE )
+ || ( node.getNodeData().getNodeVisualData().getFillType() != NodeFill.DEFAULT )
+ || ( node.getNodeData().getNodeVisualData().getShape() != NodeShape.DEFAULT ) ) ) )
+ || ( getControlPanel().isEvents() && node.isHasAssignedEvent()
+ && ( node.getNodeData().getEvent().isDuplication()
+ || node.getNodeData().getEvent().isSpeciation()
+ || node.getNodeData().getEvent().isSpeciationOrDuplication() ) ) ) {
+ NodeVisualData vis = null;
+ if ( getControlPanel().isUseVisualStyles() && ( node.getNodeData().getNodeVisualData() != null )
+ && ( !node.getNodeData().getNodeVisualData().isEmpty() ) ) {
+ vis = node.getNodeData().getNodeVisualData();
+ }
+ float box_size = getOptions().getDefaultNodeShapeSize();
+ if ( ( vis != null ) && ( vis.getSize() != NodeVisualData.DEFAULT_SIZE ) ) {
+ box_size = vis.getSize();
+ }
+ final float half_box_size = box_size / 2.0f;
+ Color outline_color = null;
+ if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
+ outline_color = Color.BLACK;
+ }
+ else if ( isInFoundNodes( node ) || isInCurrentExternalNodes( node ) ) {
+ outline_color = getColorForFoundNode( node );
+ }
+ else if ( vis != null ) {
+ if ( vis.getNodeColor() != null ) {
+ outline_color = vis.getNodeColor();
+ }
+ else if ( vis.getFontColor() != null ) {
+ outline_color = vis.getFontColor();
+ }
+ }
+ else if ( getControlPanel().isEvents() && TreePanelUtil.isHasAssignedEvent( node ) ) {
+ final Event event = node.getNodeData().getEvent();
+ if ( event.isDuplication() ) {
+ outline_color = getTreeColorSet().getDuplicationBoxColor();
+ }
+ else if ( event.isSpeciation() ) {
+ outline_color = getTreeColorSet().getSpecBoxColor();
+ }
+ else if ( event.isSpeciationOrDuplication() ) {
+ outline_color = getTreeColorSet().getDuplicationOrSpeciationColor();
+ }
+ }
+ if ( outline_color == null ) {
+ outline_color = getGraphicsForNodeBoxWithColorForParentBranch( node );
+ if ( to_pdf && ( outline_color == getTreeColorSet().getBranchColor() ) ) {
+ outline_color = getTreeColorSet().getBranchColorForPdf();
+ }
+ }
+ NodeShape shape = null;
+ if ( vis != null ) {
+ if ( vis.getShape() == NodeShape.CIRCLE ) {
+ shape = NodeShape.CIRCLE;
+ }
+ else if ( vis.getShape() == NodeShape.RECTANGLE ) {
+ shape = NodeShape.RECTANGLE;
+ }
+ }
+ if ( shape == null ) {
+ if ( getOptions().getDefaultNodeShape() == NodeShape.CIRCLE ) {
+ shape = NodeShape.CIRCLE;
+ }
+ else if ( getOptions().getDefaultNodeShape() == NodeShape.RECTANGLE ) {
+ shape = NodeShape.RECTANGLE;
+ }
+ }
+ NodeFill fill = null;
+ if ( vis != null ) {
+ if ( vis.getFillType() == NodeFill.SOLID ) {
+ fill = NodeFill.SOLID;
+ }
+ else if ( vis.getFillType() == NodeFill.NONE ) {
+ fill = NodeFill.NONE;
+ }
+ else if ( vis.getFillType() == NodeFill.GRADIENT ) {
+ fill = NodeFill.GRADIENT;
+ }
+ }
+ if ( fill == null ) {
+ if ( getOptions().getDefaultNodeFill() == NodeFill.SOLID ) {
+ fill = NodeFill.SOLID;
+ }
+ else if ( getOptions().getDefaultNodeFill() == NodeFill.NONE ) {
+ fill = NodeFill.NONE;
+ }
+ else if ( getOptions().getDefaultNodeFill() == NodeFill.GRADIENT ) {
+ fill = NodeFill.GRADIENT;
+ }
+ }
+ Color vis_fill_color = null;
+ if ( ( vis != null ) && ( vis.getNodeColor() != null ) ) {
+ vis_fill_color = vis.getNodeColor();
+ }
+ if ( shape == NodeShape.CIRCLE ) {
+ if ( fill == NodeFill.GRADIENT ) {
+ drawOvalGradient( x - half_box_size,
+ y - half_box_size,
+ box_size,
+ box_size,
+ g,
+ to_pdf ? Color.WHITE : outline_color,
+ to_pdf ? outline_color : getBackground(),
+ outline_color );
+ }
+ else if ( fill == NodeFill.NONE ) {
+ Color background = getBackground();
+ if ( to_pdf ) {
+ background = Color.WHITE;
+ }
+ drawOvalGradient( x - half_box_size,
+ y - half_box_size,
+ box_size,
+ box_size,
+ g,
+ background,
+ background,
+ outline_color );
+ }
+ else if ( fill == NodeVisualData.NodeFill.SOLID ) {
+ if ( vis_fill_color != null ) {
+ g.setColor( vis_fill_color );
+ }
+ else {
+ g.setColor( outline_color );
+ }
+ drawOvalFilled( x - half_box_size, y - half_box_size, box_size, box_size, g );
+ }
+ }
+ else if ( shape == NodeVisualData.NodeShape.RECTANGLE ) {
+ if ( fill == NodeVisualData.NodeFill.GRADIENT ) {
+ drawRectGradient( x - half_box_size,
+ y - half_box_size,
+ box_size,
+ box_size,
+ g,
+ to_pdf ? Color.WHITE : outline_color,
+ to_pdf ? outline_color : getBackground(),
+ outline_color );
+ }
+ else if ( fill == NodeVisualData.NodeFill.NONE ) {
+ Color background = getBackground();
+ if ( to_pdf ) {
+ background = Color.WHITE;
+ }
+ drawRectGradient( x - half_box_size,
+ y - half_box_size,
+ box_size,
+ box_size,
+ g,
+ background,
+ background,
+ outline_color );
+ }
+ else if ( fill == NodeVisualData.NodeFill.SOLID ) {
+ if ( vis_fill_color != null ) {
+ g.setColor( vis_fill_color );
+ }
+ else {
+ g.setColor( outline_color );
+ }
+ drawRectFilled( x - half_box_size, y - half_box_size, box_size, box_size, g );
+ }
+ }
+ }
+ }
+
+ final private int paintNodeData( final Graphics2D g,
+ final PhylogenyNode node,
+ final boolean to_graphics_file,
+ final boolean to_pdf,
+ final boolean is_in_found_nodes,
+ final double add ) {
+ if ( isNodeDataInvisible( node ) && !to_graphics_file && !to_pdf ) {
+ return 0;
+ }
+ if ( getControlPanel().isWriteBranchLengthValues()
+ && ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR )
+ || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED )
+ || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE ) )
+ && ( !node.isRoot() ) && ( node.getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) ) {
+ paintBranchLength( g, node, to_pdf, to_graphics_file );
+ }
+ if ( !getControlPanel().isShowInternalData() && !node.isExternal() && !node.isCollapse() ) {
+ return 0;
+ }
+ if ( !getControlPanel().isShowExternalData() && ( node.isExternal() || node.isCollapse() ) ) {
+ return 0;
+ }
+ _sb.setLength( 0 );
+ int x = 0;
+ if ( add > 0 ) {
+ x += add;
+ }
+ final int half_box_size = getOptions().getDefaultNodeShapeSize() / 2;
+ if ( getControlPanel().isShowTaxonomyImages() && ( getImageMap() != null ) && !getImageMap().isEmpty()
+ && node.getNodeData().isHasTaxonomy() && ( ( node.getNodeData().getTaxonomy().getUris() != null )
+ && !node.getNodeData().getTaxonomy().getUris().isEmpty() ) ) {
+ x += drawTaxonomyImage( node.getXcoord() + 2 + half_box_size, node.getYcoord(), node, g );
+ }
+ if ( ( getControlPanel().isShowTaxonomyCode() || getControlPanel().isShowTaxonomyScientificNames()
+ || getControlPanel().isShowTaxonomyCommonNames() || getControlPanel().isShowTaxonomyRank() )
+ && 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() );
+ final 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 ) && !saw_species ) {
+ if ( getOptions().isShowAbbreviatedLabelsForCollapsedNodes()
+ && ( getControlPanel().isShowTaxonomyCode() || getControlPanel().isShowTaxonomyScientificNames()
+ || getControlPanel().isShowSeqNames() || getControlPanel().isShowNodeNames() ) ) {
+ final PhylogenyNode first = PhylogenyMethods.getFirstExternalNode( node );
+ final PhylogenyNode last = PhylogenyMethods.getLastExternalNode( node );
+ if ( getControlPanel().isShowTaxonomyCode() && first.getNodeData().isHasTaxonomy()
+ && 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(),
+ node );
+ }
+ else if ( getControlPanel().isShowTaxonomyScientificNames() && first.getNodeData().isHasTaxonomy()
+ && last.getNodeData().isHasTaxonomy()
+ && !ForesterUtil.isEmpty( first.getNodeData().getTaxonomy().getScientificName() )
+ && !ForesterUtil.isEmpty( last.getNodeData().getTaxonomy().getScientificName() ) ) {
+ addLabelForCollapsed( first.getNodeData().getTaxonomy().getScientificName(),
+ last.getNodeData().getTaxonomy().getScientificName(),
+ node.getAllExternalDescendants().size(),
+ node );
+ }
+ else if ( getControlPanel().isShowSeqNames() && first.getNodeData().isHasSequence()
+ && last.getNodeData().isHasSequence()
+ && !ForesterUtil.isEmpty( first.getNodeData().getSequence().getName() )
+ && !ForesterUtil.isEmpty( last.getNodeData().getSequence().getName() ) ) {
+ addLabelForCollapsed( first.getNodeData().getSequence().getName(),
+ last.getNodeData().getSequence().getName(),
+ node.getAllExternalDescendants().size(),
+ node );
+ }
+ else if ( getControlPanel().isShowNodeNames() && !ForesterUtil.isEmpty( first.getName() )
+ && !ForesterUtil.isEmpty( last.getName() ) ) {
+ addLabelForCollapsed( first.getName(),
+ last.getName(),
+ node.getAllExternalDescendants().size(),
+ node );
+ }
+ }
+ }
+ else if ( ( _sb.length() > 0 ) || saw_species ) {
+ // _sb.setLength( 0 );
+ _sb.append( " [" );
+ _sb.append( node.getAllExternalDescendants().size() );
+ _sb.append( "]" );
+ if ( _found_nodes_0 != null || _found_nodes_1 != null ) {
+ int[] res = calcFoundNodesInSubtree( node );
+ if ( res[ 0 ] > 0 ) {
+ _sb.append( " [" );
+ _sb.append( res[ 0 ] );
+ _sb.append( "/" );
+ _sb.append( res[ 1 ] );
+ _sb.append( "]" );
+ }
+ }
+ }
+ }
+ else {
+ // _sb.setLength( 0 );
+ }
+ // 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;
+ }
+ float pos_x;
+ if ( getControlPanel().getTreeDisplayType() == Options.PHYLOGENY_DISPLAY_TYPE.ALIGNED_PHYLOGRAM
+ && ( 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 ) );
+ }
+ else {
+ pos_y = ( node.getYcoord() + ( getFontMetrics( g.getFont() ).getAscent() / down_shift_factor ) );
+ }
+ if ( getControlPanel().getTreeDisplayType() == Options.PHYLOGENY_DISPLAY_TYPE.ALIGNED_PHYLOGRAM
+ && ( 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 ) ) {
+ 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 );
+ }
+ else {
+ drawStringX( sb_str, pos_x, pos_y, g );
+ }
+ }
+ if ( _sb.length() > 0 ) {
+ if ( !using_visual_font && !is_in_found_nodes ) {
+ x += getFontMetricsForLargeDefaultFont().stringWidth( _sb.toString() ) + 5;
+ }
+ else {
+ x += getFontMetrics( g.getFont() ).stringWidth( _sb.toString() ) + 5;
+ }
+ }
+ if ( getControlPanel().isShowAnnotation() && node.getNodeData().isHasSequence()
+ && ( node.getNodeData().getSequence().getAnnotations() != null )
+ && ( !node.getNodeData().getSequence().getAnnotations().isEmpty() ) ) {
+ final SortedSet<Annotation> ann = node.getNodeData().getSequence().getAnnotations();
+ if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
+ g.setColor( Color.BLACK );
+ }
+ else if ( getControlPanel().isColorAccordingToAnnotation() ) {
+ g.setColor( calculateColorForAnnotation( ann ) );
+ }
+ final String ann_str = TreePanelUtil.createAnnotationString( ann,
+ getOptions().isShowAnnotationRefSource() );
+ TreePanel.drawString( ann_str,
+ node.getXcoord() + x + 3 + half_box_size,
+ node.getYcoord()
+ + ( getFontMetricsForLargeDefaultFont().getAscent() / down_shift_factor ),
+ g );
+ _sb.setLength( 0 );
+ _sb.append( ann_str );
+ if ( _sb.length() > 0 ) {
+ if ( !using_visual_font && !is_in_found_nodes ) {
+ x += getFontMetricsForLargeDefaultFont().stringWidth( _sb.toString() ) + 5;
+ }
+ else {
+ x += getFontMetrics( g.getFont() ).stringWidth( _sb.toString() ) + 5;
+ }
+ }
+ }
+ if ( ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR )
+ || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE )
+ || ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.ROUNDED ) ) {
+ if ( ( getControlPanel().isShowBinaryCharacters() || getControlPanel().isShowBinaryCharacterCounts() )
+ && node.getNodeData().isHasBinaryCharacters() ) {
+ if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) {
+ g.setColor( Color.BLACK );
+ }
+ else {
+ g.setColor( getTreeColorSet().getBinaryDomainCombinationsColor() );
+ }
+ if ( getControlPanel().isShowBinaryCharacters() ) {
+ TreePanel.drawString( node.getNodeData().getBinaryCharacters().getPresentCharactersAsStringBuffer()
+ .toString(),
+ node.getXcoord() + x + 1 + half_box_size,
+ node.getYcoord() + ( getFontMetricsForLargeDefaultFont().getAscent()
+ / down_shift_factor ),
+ g );
+ paintGainedAndLostCharacters( g,
+ node,
+ node.getNodeData().getBinaryCharacters()
+ .getGainedCharactersAsStringBuffer().toString(),
+ node.getNodeData().getBinaryCharacters()
+ .getLostCharactersAsStringBuffer().toString() );
+ }
+ else {
+ TreePanel.drawString( " " + node.getNodeData().getBinaryCharacters().getPresentCount(),
+ node.getXcoord() + x + 4 + half_box_size,
+ node.getYcoord() + ( getFontMetricsForLargeDefaultFont().getAscent()
+ / down_shift_factor ),
+ g );
+ paintGainedAndLostCharacters( g,
+ node,
+ "+" + node.getNodeData().getBinaryCharacters().getGainedCount(),
+ "-" + node.getNodeData().getBinaryCharacters().getLostCount() );
+ }
+ }