+ final private void showNodeDataPopup( final MouseEvent e, final PhylogenyNode node ) {
+ try {
+ if ( ( node.getName().length() > 0 )
+ || ( node.getNodeData().isHasTaxonomy() && !TreePanelUtil.isTaxonomyEmpty( node.getNodeData()
+ .getTaxonomy() ) )
+ || ( node.getNodeData().isHasSequence() && !TreePanelUtil.isSequenceEmpty( node.getNodeData()
+ .getSequence() ) ) || ( node.getNodeData().isHasDate() )
+ || ( node.getNodeData().isHasDistribution() ) || node.getBranchData().isHasConfidences() ) {
+ _popup_buffer.setLength( 0 );
+ short lines = 0;
+ if ( node.getName().length() > 0 ) {
+ lines++;
+ _popup_buffer.append( node.getName() );
+ }
+ if ( node.getNodeData().isHasTaxonomy()
+ && !TreePanelUtil.isTaxonomyEmpty( node.getNodeData().getTaxonomy() ) ) {
+ lines++;
+ boolean enc_data = false;
+ final Taxonomy tax = node.getNodeData().getTaxonomy();
+ if ( _popup_buffer.length() > 0 ) {
+ _popup_buffer.append( "\n" );
+ }
+ if ( !ForesterUtil.isEmpty( tax.getTaxonomyCode() ) ) {
+ _popup_buffer.append( "[" );
+ _popup_buffer.append( tax.getTaxonomyCode() );
+ _popup_buffer.append( "]" );
+ enc_data = true;
+ }
+ if ( !ForesterUtil.isEmpty( tax.getScientificName() ) ) {
+ if ( enc_data ) {
+ _popup_buffer.append( " " );
+ }
+ _popup_buffer.append( tax.getScientificName() );
+ enc_data = true;
+ }
+ if ( !ForesterUtil.isEmpty( tax.getCommonName() ) ) {
+ if ( enc_data ) {
+ _popup_buffer.append( " (" );
+ }
+ else {
+ _popup_buffer.append( "(" );
+ }
+ _popup_buffer.append( tax.getCommonName() );
+ _popup_buffer.append( ")" );
+ enc_data = true;
+ }
+ if ( !ForesterUtil.isEmpty( tax.getAuthority() ) ) {
+ if ( enc_data ) {
+ _popup_buffer.append( " (" );
+ }
+ else {
+ _popup_buffer.append( "(" );
+ }
+ _popup_buffer.append( tax.getAuthority() );
+ _popup_buffer.append( ")" );
+ enc_data = true;
+ }
+ if ( !ForesterUtil.isEmpty( tax.getRank() ) ) {
+ if ( enc_data ) {
+ _popup_buffer.append( " [" );
+ }
+ else {
+ _popup_buffer.append( "[" );
+ }
+ _popup_buffer.append( tax.getRank() );
+ _popup_buffer.append( "]" );
+ enc_data = true;
+ }
+ if ( tax.getSynonyms().size() > 0 ) {
+ if ( enc_data ) {
+ _popup_buffer.append( " " );
+ }
+ _popup_buffer.append( "[" );
+ int counter = 1;
+ for( final String syn : tax.getSynonyms() ) {
+ if ( !ForesterUtil.isEmpty( syn ) ) {
+ enc_data = true;
+ _popup_buffer.append( syn );
+ if ( counter < tax.getSynonyms().size() ) {
+ _popup_buffer.append( ", " );
+ }
+ }
+ counter++;
+ }
+ _popup_buffer.append( "]" );
+ }
+ if ( !enc_data ) {
+ if ( ( tax.getIdentifier() != null ) && !ForesterUtil.isEmpty( tax.getIdentifier().getValue() ) ) {
+ if ( !ForesterUtil.isEmpty( tax.getIdentifier().getProvider() ) ) {
+ _popup_buffer.append( "[" );
+ _popup_buffer.append( tax.getIdentifier().getProvider() );
+ _popup_buffer.append( "] " );
+ }
+ _popup_buffer.append( tax.getIdentifier().getValue() );
+ }
+ }
+ }
+ if ( node.getNodeData().isHasSequence()
+ && !TreePanelUtil.isSequenceEmpty( node.getNodeData().getSequence() ) ) {
+ lines++;
+ boolean enc_data = false;
+ if ( _popup_buffer.length() > 0 ) {
+ _popup_buffer.append( "\n" );
+ }
+ final Sequence seq = node.getNodeData().getSequence();
+ if ( seq.getAccession() != null ) {
+ _popup_buffer.append( "[" );
+ if ( !ForesterUtil.isEmpty( seq.getAccession().getSource() ) ) {
+ _popup_buffer.append( seq.getAccession().getSource() );
+ _popup_buffer.append( ":" );
+ }
+ _popup_buffer.append( seq.getAccession().getValue() );
+ _popup_buffer.append( "]" );
+ enc_data = true;
+ }
+ if ( !ForesterUtil.isEmpty( seq.getSymbol() ) ) {
+ if ( enc_data ) {
+ _popup_buffer.append( " [" );
+ }
+ else {
+ _popup_buffer.append( "[" );
+ }
+ _popup_buffer.append( seq.getSymbol() );
+ _popup_buffer.append( "]" );
+ enc_data = true;
+ }
+ if ( !ForesterUtil.isEmpty( seq.getGeneName() ) ) {
+ if ( enc_data ) {
+ _popup_buffer.append( " [" );
+ }
+ else {
+ _popup_buffer.append( "[" );
+ }
+ _popup_buffer.append( seq.getGeneName() );
+ _popup_buffer.append( "]" );
+ enc_data = true;
+ }
+ if ( !ForesterUtil.isEmpty( seq.getName() ) ) {
+ if ( enc_data ) {
+ _popup_buffer.append( " " );
+ }
+ _popup_buffer.append( seq.getName() );
+ }
+ }
+ if ( node.getNodeData().isHasDate() ) {
+ lines++;
+ if ( _popup_buffer.length() > 0 ) {
+ _popup_buffer.append( "\n" );
+ }
+ _popup_buffer.append( node.getNodeData().getDate().asSimpleText() );
+ }
+ if ( node.getNodeData().isHasDistribution() ) {
+ lines++;
+ if ( _popup_buffer.length() > 0 ) {
+ _popup_buffer.append( "\n" );
+ }
+ _popup_buffer.append( node.getNodeData().getDistribution().asSimpleText() );
+ }
+ if ( node.getBranchData().isHasConfidences() ) {
+ final List<Confidence> confs = node.getBranchData().getConfidences();
+ for( final Confidence confidence : confs ) {
+ lines++;
+ if ( _popup_buffer.length() > 0 ) {
+ _popup_buffer.append( "\n" );
+ }
+ if ( !ForesterUtil.isEmpty( confidence.getType() ) ) {
+ _popup_buffer.append( "[" );
+ _popup_buffer.append( confidence.getType() );
+ _popup_buffer.append( "] " );
+ }
+ _popup_buffer
+ .append( FORMATTER_CONFIDENCE.format( ForesterUtil.round( confidence.getValue(),
+ getOptions()
+ .getNumberOfDigitsAfterCommaForConfidenceValues() ) ) );
+ if ( confidence.getStandardDeviation() != Confidence.CONFIDENCE_DEFAULT_VALUE ) {
+ _popup_buffer.append( " (sd=" );
+ _popup_buffer.append( FORMATTER_CONFIDENCE.format( ForesterUtil.round( confidence
+ .getStandardDeviation(), getOptions()
+ .getNumberOfDigitsAfterCommaForConfidenceValues() ) ) );
+ _popup_buffer.append( ")" );
+ }
+ }
+ }
+ if ( node.getNodeData().isHasProperties() ) {
+ final PropertiesMap properties = node.getNodeData().getProperties();
+ for( final String ref : properties.getPropertyRefs() ) {
+ _popup_buffer.append( "\n" );
+ final Property p = properties.getProperty( ref );
+ _popup_buffer.append( TreePanelUtil.getPartAfterColon( p.getRef() ) );
+ _popup_buffer.append( "=" );
+ _popup_buffer.append( p.getValue() );
+ if ( !ForesterUtil.isEmpty( p.getUnit() ) ) {
+ _popup_buffer.append( TreePanelUtil.getPartAfterColon( p.getUnit() ) );
+ }
+ }
+ }
+ if ( _popup_buffer.length() > 0 ) {
+ if ( !getConfiguration().isUseNativeUI() ) {
+ _rollover_popup
+ .setBorder( BorderFactory.createLineBorder( getTreeColorSet().getBranchColor() ) );
+ _rollover_popup.setBackground( getTreeColorSet().getBackgroundColor() );
+ if ( isInFoundNodes0( node ) && !isInFoundNodes1( node ) ) {
+ _rollover_popup.setForeground( getTreeColorSet().getFoundColor0() );
+ }
+ else if ( !isInFoundNodes0( node ) && isInFoundNodes1( node ) ) {
+ _rollover_popup.setForeground( getTreeColorSet().getFoundColor1() );
+ }
+ else if ( isInFoundNodes0( node ) && isInFoundNodes1( node ) ) {
+ _rollover_popup.setForeground( getTreeColorSet().getFoundColor0and1() );
+ }
+ else {
+ _rollover_popup.setForeground( getTreeColorSet().getSequenceColor() );
+ }
+ }
+ else {
+ _rollover_popup.setBorder( BorderFactory.createLineBorder( Color.BLACK ) );
+ }
+ _rollover_popup.setText( _popup_buffer.toString() );
+ _node_desc_popup = PopupFactory.getSharedInstance().getPopup( null,
+ _rollover_popup,
+ e.getLocationOnScreen().x + 10,
+ e.getLocationOnScreen().y
+ - ( lines * 20 ) );
+ _node_desc_popup.show();
+ }
+ }
+ }
+ catch ( final Exception ex ) {
+ // Do nothing.
+ }
+ }
+
+ final private void showNodeEditFrame( final PhylogenyNode n ) {
+ if ( _node_frame_index < TreePanel.MAX_NODE_FRAMES ) {
+ // pop up edit box for single node
+ _node_frames[ _node_frame_index ] = new NodeFrame( n, _phylogeny, this, _node_frame_index, "" );
+ _node_frame_index++;
+ }
+ else {
+ JOptionPane.showMessageDialog( this, "too many node windows are open" );
+ }
+ }
+
+ final private void showNodeFrame( final PhylogenyNode n ) {
+ if ( _node_frame_index < TreePanel.MAX_NODE_FRAMES ) {
+ // pop up edit box for single node
+ _node_frames[ _node_frame_index ] = new NodeFrame( n, _phylogeny, this, _node_frame_index );
+ _node_frame_index++;
+ }
+ else {
+ JOptionPane.showMessageDialog( this, "too many node windows are open" );
+ }
+ }
+
+ final private void switchDisplaygetPhylogenyGraphicsType() {
+ switch ( getPhylogenyGraphicsType() ) {
+ case RECTANGULAR:
+ setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE );
+ getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.EURO_STYLE );
+ break;
+ case EURO_STYLE:
+ setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.ROUNDED );
+ getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.ROUNDED );
+ break;
+ case ROUNDED:
+ setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CURVED );
+ getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CURVED );
+ break;
+ case CURVED:
+ setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR );
+ getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.TRIANGULAR );
+ break;
+ case TRIANGULAR:
+ setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CONVEX );
+ getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CONVEX );
+ break;
+ case CONVEX:
+ setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
+ getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
+ break;
+ case UNROOTED:
+ setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CIRCULAR );
+ getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.CIRCULAR );
+ break;
+ case CIRCULAR:
+ setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
+ getOptions().setPhylogenyGraphicsType( PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
+ break;
+ default:
+ throw new RuntimeException( "unkwnown display type: " + getPhylogenyGraphicsType() );
+ }
+ if ( getControlPanel().getDynamicallyHideData() != null ) {
+ if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
+ getControlPanel().getDynamicallyHideData().setEnabled( false );
+ }
+ else {
+ getControlPanel().getDynamicallyHideData().setEnabled( true );
+ }
+ }
+ if ( isPhyHasBranchLengths() && ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
+ getControlPanel().setDrawPhylogramEnabled( true );
+ }
+ else {
+ getControlPanel().setDrawPhylogramEnabled( false );
+ }
+ if ( getMainPanel().getMainFrame() == null ) {
+ // Must be "E" applet version.
+ ( ( ArchaeopteryxE ) ( ( MainPanelApplets ) getMainPanel() ).getApplet() )
+ .setSelectedTypeInTypeMenu( getPhylogenyGraphicsType() );
+ }
+ else {
+ getMainPanel().getMainFrame().setSelectedTypeInTypeMenu( getPhylogenyGraphicsType() );
+ }
+ }
+
+ final void calcMaxDepth() {
+ if ( _phylogeny != null ) {
+ _circ_max_depth = PhylogenyMethods.calculateMaxDepth( _phylogeny );
+ }
+ }
+
+ /**
+ * Set parameters for printing the displayed tree
+ *
+ */
+ final void calcParametersForPainting( final int x, final int y ) {
+ // updateStyle(); not needed?
+ if ( ( _phylogeny != null ) && !_phylogeny.isEmpty() ) {
+ initNodeData();
+ calculateLongestExtNodeInfo();
+ if ( ( getLongestExtNodeInfo() > ( x * 0.6 ) )
+ && ( getTreeFontSet().getLargeFont().getSize() > ( 2 + TreeFontSet.FONT_SIZE_CHANGE_STEP ) ) ) {
+ while ( ( getLongestExtNodeInfo() > ( x * 0.7 ) ) && ( getTreeFontSet().getLargeFont().getSize() > 2 ) ) {
+ getMainPanel().getTreeFontSet().decreaseFontSize( getConfiguration().getMinBaseFontSize(), true );
+ calculateLongestExtNodeInfo();
+ }
+ }
+ else {
+ while ( ( getLongestExtNodeInfo() < ( x * 0.6 ) )
+ && ( getTreeFontSet().getLargeFont().getSize() <= ( getTreeFontSet().getLargeFontMemory()
+ .getSize() - TreeFontSet.FONT_SIZE_CHANGE_STEP ) ) ) {
+ getMainPanel().getTreeFontSet().increaseFontSize();
+ calculateLongestExtNodeInfo();
+ }
+ }
+ //_length_of_longest_text = calcLengthOfLongestText();
+ int ext_nodes = _phylogeny.getRoot().getNumberOfExternalNodes();
+ final int max_depth = PhylogenyMethods.calculateMaxDepth( _phylogeny );
+ if ( ext_nodes == 1 ) {
+ ext_nodes = max_depth;
+ if ( ext_nodes < 1 ) {
+ ext_nodes = 1;
+ }
+ }
+ updateOvSizes();
+ float xdist = 0;
+ float ov_xdist = 0;
+ if ( !isNonLinedUpCladogram() && !isUniformBranchLengthsForCladogram() ) {
+ xdist = ( float ) ( ( x - getLongestExtNodeInfo() - TreePanel.MOVE ) / ( ext_nodes + 3.0 ) );
+ ov_xdist = ( float ) ( getOvMaxWidth() / ( ext_nodes + 3.0 ) );
+ }
+ else {
+ xdist = ( ( x - getLongestExtNodeInfo() - TreePanel.MOVE ) / ( max_depth + 1 ) );
+ ov_xdist = ( getOvMaxWidth() / ( max_depth + 1 ) );
+ }
+ float ydist = ( float ) ( ( y - TreePanel.MOVE ) / ( ext_nodes * 2.0 ) );
+ if ( xdist < 0.0 ) {
+ xdist = 0.0f;
+ }
+ if ( ov_xdist < 0.0 ) {
+ ov_xdist = 0.0f;
+ }
+ if ( ydist < 0.0 ) {
+ ydist = 0.0f;
+ }
+ setXdistance( xdist );
+ setYdistance( ydist );
+ setOvXDistance( ov_xdist );
+ final double height = _phylogeny.getHeight();
+ if ( height > 0 ) {
+ final float corr = ( float ) ( ( x - TreePanel.MOVE - getLongestExtNodeInfo() - getXdistance() ) / height );
+ setXcorrectionFactor( corr > 0 ? corr : 0 );
+ final float ov_corr = ( float ) ( ( getOvMaxWidth() - getOvXDistance() ) / height );
+ setOvXcorrectionFactor( ov_corr > 0 ? ov_corr : 0 );
+ }
+ else {
+ setXcorrectionFactor( 0 );
+ setOvXcorrectionFactor( 0 );
+ }
+ _circ_max_depth = max_depth;
+ setUpUrtFactor();
+ //
+ if ( ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED )
+ && ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) ) {
+ // int dynamic_hiding_factor = calcDynamicHidingFactor();
+ // if ( dynamic_hiding_factor > 1 ) {
+ // while ( dynamic_hiding_factor > 1
+ // && getTreeFontSet()._fm_large.getHeight() > TreeFontSet.SMALL_FONTS_BASE ) {
+ // getTreeFontSet().decreaseFontSize( 1, true );
+ // dynamic_hiding_factor = calcDynamicHidingFactor();
+ // }
+ // }
+ // else if ( getTreeFontSet().isDecreasedSizeBySystem() ) {
+ // while ( dynamic_hiding_factor < 1 && getTreeFontSet()._fm_large.getHeight() < 12 ) {
+ // getTreeFontSet().increaseFontSize();
+ // dynamic_hiding_factor = calcDynamicHidingFactor();
+ // }
+ // }
+ }
+ //
+ }
+ }
+
+ final void calculateLongestExtNodeInfo() {
+ if ( ( _phylogeny == null ) || _phylogeny.isEmpty() ) {
+ return;
+ }
+ int max_length = ForesterUtil.roundToInt( ( getSize().getWidth() - MOVE )
+ * Constants.EXT_NODE_INFO_LENGTH_MAX_RATIO );
+ if ( max_length < 40 ) {
+ max_length = 40;
+ }
+ 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;
+ if ( node.isCollapse() ) {
+ continue;
+ }
+ final StringBuilder sb = new StringBuilder();
+ nodeDataAsSB( node, sb );
+ if ( node.getNodeData().isHasTaxonomy() ) {
+ nodeTaxonomyDataAsSB( node.getNodeData().getTaxonomy(), sb );
+ }
+ final int txt = sb.length();
+ if ( txt > longest_txt ) {
+ longest_txt = txt;
+ longest_txt_node = node;
+ }
+ boolean use_vis = false;
+ final Graphics2D g = ( Graphics2D ) getGraphics();
+ if ( getControlPanel().isUseVisualStyles() ) {
+ use_vis = setFont( g, node, false );
+ }
+ if ( !use_vis ) {
+ sum = getFontMetricsForLargeDefaultFont().stringWidth( sb.toString() );
+ }
+ else {
+ sum = getFontMetrics( g.getFont() ).stringWidth( sb.toString() );
+ }
+ if ( getControlPanel().isShowBinaryCharacters() && node.getNodeData().isHasBinaryCharacters() ) {
+ sum += getFontMetricsForLargeDefaultFont().stringWidth( node.getNodeData().getBinaryCharacters()
+ .getGainedCharactersAsStringBuffer().toString() );
+ }
+ if ( getControlPanel().isShowVectorData() && ( node.getNodeData().getVector() != null )
+ && ( node.getNodeData().getVector().size() > 0 ) ) {
+ if ( getConfiguration() != null ) {
+ sum += getConfiguration().getVectorDataWidth() + 10;
+ }
+ else {
+ sum += RenderableVector.VECTOR_DEFAULT_WIDTH + 10;
+ }
+ }
+ if ( getControlPanel().isShowDomainArchitectures() && node.getNodeData().isHasSequence()
+ && ( node.getNodeData().getSequence().getDomainArchitecture() != null ) ) {
+ // FIXME
+ // TODO this might need some clean up
+ 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 ( getControlPanel().isShowMolSequences() && ( node.getNodeData().isHasSequence() )
+ && ( node.getNodeData().getSequence().isMolecularSequenceAligned() )
+ && ( !ForesterUtil.isEmpty( node.getNodeData().getSequence().getMolecularSequence() ) ) ) {
+ // FIXME
+ sum += RenderableMsaSequence.DEFAULT_WIDTH + 30;
+ }
+ if ( sum >= max_length ) {
+ _longest_ext_node_info = max_length;
+ // return; //FIXME why?
+ }
+ if ( sum > longest ) {
+ longest = sum;
+ }
+ }
+ _ext_node_with_longest_txt_info = longest_txt_node;
+ if ( longest >= max_length ) {
+ _longest_ext_node_info = max_length;
+ }
+ else {
+ _longest_ext_node_info = longest;
+ }
+ _length_of_longest_text = calcLengthOfLongestText();
+ }
+
+ final void calculateScaleDistance() {
+ if ( ( _phylogeny == null ) || _phylogeny.isEmpty() ) {