- final private void pasteSubtree( final PhylogenyNode node ) {
- if ( getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) {
- errorMessageNoCutCopyPasteInUnrootedDisplay();
- return;
- }
- if ( ( getCutOrCopiedTree() == null ) || getCutOrCopiedTree().isEmpty() ) {
- JOptionPane.showMessageDialog( this,
- "No tree in buffer (need to copy or cut a subtree first)",
- "Attempt to paste with empty buffer",
- JOptionPane.ERROR_MESSAGE );
- return;
- }
- final String label = createASimpleTextRepresentationOfANode( getCutOrCopiedTree().getRoot() );
- final Object[] options = { "As sibling", "As descendant", "Cancel" };
- final int r = JOptionPane.showOptionDialog( this,
- "How to paste subtree" + label + "?",
- "Paste Subtree",
- JOptionPane.CLOSED_OPTION,
- JOptionPane.QUESTION_MESSAGE,
- null,
- options,
- options[ 2 ] );
- boolean paste_as_sibling = true;
- if ( r == 1 ) {
- paste_as_sibling = false;
- }
- else if ( r != 0 ) {
- return;
- }
- final Phylogeny buffer_phy = getCutOrCopiedTree().copy();
- buffer_phy.setAllNodesToNotCollapse();
- PhylogenyMethods.preOrderReId( buffer_phy );
- buffer_phy.setRooted( true );
- boolean need_to_show_whole = false;
- if ( paste_as_sibling ) {
- if ( node.isRoot() ) {
- JOptionPane.showMessageDialog( this,
- "Cannot paste sibling to root",
- "Attempt to paste sibling to root",
- JOptionPane.ERROR_MESSAGE );
- return;
- }
- buffer_phy.addAsSibling( node );
- }
- else {
- if ( ( node.getNumberOfExternalNodes() == 1 ) && node.isRoot() ) {
- need_to_show_whole = true;
- _phylogeny = buffer_phy;
- }
- else {
- buffer_phy.addAsChild( node );
- }
- }
- if ( getCopiedAndPastedNodes() == null ) {
- setCopiedAndPastedNodes( new HashSet<Long>() );
- }
- final List<PhylogenyNode> nodes = PhylogenyMethods.obtainAllNodesAsList( buffer_phy );
- final Set<Long> node_ids = new HashSet<Long>( nodes.size() );
- for( final PhylogenyNode n : nodes ) {
- node_ids.add( n.getId() );
- }
- node_ids.add( node.getId() );
- getCopiedAndPastedNodes().addAll( node_ids );
- setNodeInPreorderToNull();
- _phylogeny.externalNodesHaveChanged();
- _phylogeny.clearHashIdToNodeMap();
- _phylogeny.recalculateNumberOfExternalDescendants( true );
- resetNodeIdToDistToLeafMap();
- setEdited( true );
- if ( need_to_show_whole ) {
- getControlPanel().showWhole();
- }
- repaint();
- }
-
- private final StringBuffer propertiesToString( final PhylogenyNode node ) {
- final PropertiesMap properties = node.getNodeData().getProperties();
- final StringBuffer sb = new StringBuffer();
- boolean first = true;
- for( final String ref : properties.getPropertyRefs() ) {
- if ( first ) {
- first = false;
- }
- else {
- sb.append( " " );
- }
- final Property p = properties.getProperty( ref );
- sb.append( getPartAfterColon( p.getRef() ) );
- sb.append( "=" );
- sb.append( p.getValue() );
- if ( !ForesterUtil.isEmpty( p.getUnit() ) ) {
- sb.append( getPartAfterColon( p.getUnit() ) );
- }
- }
- return sb;
- }
-
- final private void setCopiedAndPastedNodes( final Set<Long> nodeIds ) {
- getMainPanel().setCopiedAndPastedNodes( nodeIds );
- }
-
- final private void setCutOrCopiedTree( final Phylogeny cut_or_copied_tree ) {
- getMainPanel().setCutOrCopiedTree( cut_or_copied_tree );
- }
-
- final private void setInOv( final boolean in_ov ) {
- _in_ov = in_ov;
- }
-
- final private void setOvMaxHeight( final float ov_max_height ) {
- _ov_max_height = ov_max_height;
- }
-
- final private void setOvMaxWidth( final float ov_max_width ) {
- _ov_max_width = ov_max_width;
- }
-
- final private void setOvXcorrectionFactor( final float f ) {
- _ov_x_correction_factor = f;
- }
-
- final private void setOvXDistance( final float ov_x_distance ) {
- _ov_x_distance = ov_x_distance;
- }
-
- final private void setOvXPosition( final int ov_x_position ) {
- _ov_x_position = ov_x_position;
- }
-
- final private void setOvYDistance( final float ov_y_distance ) {
- _ov_y_distance = ov_y_distance;
- }
-
- final private void setOvYPosition( final int ov_y_position ) {
- _ov_y_position = ov_y_position;
- }
-
- final private void setOvYStart( final int ov_y_start ) {
- _ov_y_start = ov_y_start;
- }
-
- final private void setScaleDistance( final double scale_distance ) {
- _scale_distance = scale_distance;
- }
-
- final private void setScaleLabel( final String scale_label ) {
- _scale_label = scale_label;
- }
-
- final private void setUpUrtFactor() {
- final int d = getVisibleRect().width < getVisibleRect().height ? getVisibleRect().width
- : getVisibleRect().height;
- if ( isPhyHasBranchLengths() && getControlPanel().isDrawPhylogram() ) {
- setUrtFactor( ( float ) ( d / ( 2 * getMaxDistanceToRoot() ) ) );
- }
- else {
- final int max_depth = _circ_max_depth;
- if ( max_depth > 0 ) {
- setUrtFactor( d / ( 2 * max_depth ) );
- }
- else {
- setUrtFactor( d / 2 );
- }
- }
- setUrtFactorOv( getUrtFactor() );
- }
-
- final private void setUrtFactor( final float urt_factor ) {
- _urt_factor = urt_factor;
- }
-
- final private void setUrtFactorOv( final float urt_factor_ov ) {
- _urt_factor_ov = urt_factor_ov;
- }
-
- private void showExtDescNodeData( final PhylogenyNode node ) {
- final List<String> data = new ArrayList<String>();
- for( final PhylogenyNode n : node.getAllExternalDescendants() ) {
- switch ( getOptions().getExtDescNodeDataToReturn() ) {
- case NODE_NAME:
- if ( !ForesterUtil.isEmpty( n.getName() ) ) {
- data.add( n.getName() );
- }
- break;
- case SEQUENCE_NAME:
- if ( n.getNodeData().isHasSequence()
- && !ForesterUtil.isEmpty( n.getNodeData().getSequence().getName() ) ) {
- data.add( n.getNodeData().getSequence().getName() );
- }
- break;
- case SEQUENCE_SYMBOL:
- if ( n.getNodeData().isHasSequence()
- && !ForesterUtil.isEmpty( n.getNodeData().getSequence().getSymbol() ) ) {
- data.add( n.getNodeData().getSequence().getSymbol() );
- }
- break;
- case SEQUENCE_MOL_SEQ:
- if ( n.getNodeData().isHasSequence()
- && !ForesterUtil.isEmpty( n.getNodeData().getSequence().getMolecularSequence() ) ) {
- data.add( n.getNodeData().getSequence().getMolecularSequence() );
- }
- break;
- case SEQUENCE_MOL_SEQ_FASTA:
- final StringBuilder sb = new StringBuilder();
- if ( n.getNodeData().isHasSequence()
- && !ForesterUtil.isEmpty( n.getNodeData().getSequence().getMolecularSequence() ) ) {
- if ( !ForesterUtil.isEmpty( n.getNodeData().getSequence().getName() ) ) {
- sb.append( SequenceWriter.toFasta( n.getNodeData().getSequence().getName(), n.getNodeData()
- .getSequence().getMolecularSequence(), 60 ) );
- }
- else {
- sb.append( SequenceWriter.toFasta( n.getName(), n.getNodeData().getSequence()
- .getMolecularSequence(), 60 ) );
- }
- data.add( sb.toString() );
- }
- break;
- case SEQUENCE_ACC:
- if ( n.getNodeData().isHasSequence() && ( n.getNodeData().getSequence().getAccession() != null )
- && !ForesterUtil.isEmpty( n.getNodeData().getSequence().getAccession().toString() ) ) {
- data.add( n.getNodeData().getSequence().getAccession().toString() );
- }
- break;
- case TAXONOMY_SCIENTIFIC_NAME:
- if ( n.getNodeData().isHasTaxonomy()
- && !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getScientificName() ) ) {
- data.add( n.getNodeData().getTaxonomy().getScientificName() );
- }
- break;
- case TAXONOMY_CODE:
- if ( n.getNodeData().isHasTaxonomy()
- && !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getTaxonomyCode() ) ) {
- data.add( n.getNodeData().getTaxonomy().getTaxonomyCode() );
- }
- break;
- case UNKNOWN:
- AptxUtil.showExtDescNodeDataUserSelectedHelper( getControlPanel(), n, data );
- break;
- default:
- throw new IllegalArgumentException( "unknown data element: "
- + getOptions().getExtDescNodeDataToReturn() );
- }
- } // for loop
- if ( ( getConfiguration().getExtNodeDataReturnOn() == EXT_NODE_DATA_RETURN_ON.CONSOLE )
- || ( getConfiguration().getExtNodeDataReturnOn() == EXT_NODE_DATA_RETURN_ON.BUFFER_ONLY ) ) {
- final StringBuilder sb = new StringBuilder();
- for( final String d : data ) {
- if ( !ForesterUtil.isEmpty( d ) ) {
- if ( getConfiguration().getExtNodeDataReturnOn() == EXT_NODE_DATA_RETURN_ON.CONSOLE ) {
- System.out.println( d );
- }
- sb.append( d );
- sb.append( ForesterUtil.LINE_SEPARATOR );
- }
- }
- if ( sb.length() < 1 ) {
- clearCurrentExternalNodesDataBuffer();
- }
- else {
- setCurrentExternalNodesDataBuffer( sb );
- }
- }
- else if ( getConfiguration().getExtNodeDataReturnOn() == EXT_NODE_DATA_RETURN_ON.WINODW ) {
- final StringBuilder sb = new StringBuilder();
- for( final String d : data ) {
- if ( !ForesterUtil.isEmpty( d ) ) {
- sb.append( d );
- sb.append( ForesterUtil.LINE_SEPARATOR );
- }
- }
- if ( sb.length() < 1 ) {
- AptxUtil.showInformationMessage( this,
- "No Appropriate Data (" + obtainTitleForExtDescNodeData() + ")",
- "Descendants of selected node do not contain selected data" );
- clearCurrentExternalNodesDataBuffer();
- }
- else {
- setCurrentExternalNodesDataBuffer( sb );
- final String title = "External Descendants "
- + ( getOptions().getExtDescNodeDataToReturn() == NODE_DATA.UNKNOWN ? "Data"
- : obtainTitleForExtDescNodeData() ) + " (" + data.size() + "/"
- + node.getNumberOfExternalNodes() + ") For Node " + node;
- final String s = sb.toString().trim();
- if ( getMainPanel().getMainFrame() == null ) {
- // Must be "E" applet version.
- final ArchaeopteryxE ae = ( ArchaeopteryxE ) ( ( MainPanelApplets ) getMainPanel() ).getApplet();
- ae.showTextFrame( s, title );
- }
- else {
- getMainPanel().getMainFrame().showTextFrame( s, title );
- }
- }
- }