+ "Need to select nodes, either via direct selection or via the \"Search\" function",
+ "No nodes selected for annotation",
+ JOptionPane.ERROR_MESSAGE );
+ return;
+ }
+ final Phylogeny phy = getMainPanel().getCurrentPhylogeny();
+ if ( ( phy != null ) && !phy.isEmpty() ) {
+ final JTextField ref_field = new JTextField( 10 );
+ final JTextField desc_filed = new JTextField( 20 );
+ ref_field.setText( ForesterUtil.isEmpty( getPreviousNodeAnnotationReference() ) ? ""
+ : getPreviousNodeAnnotationReference() );
+ final JPanel my_panel = new JPanel();
+ my_panel.add( new JLabel( "Reference " ) );
+ my_panel.add( ref_field );
+ my_panel.add( Box.createHorizontalStrut( 15 ) );
+ my_panel.add( new JLabel( "Description " ) );
+ my_panel.add( desc_filed );
+ final int result = JOptionPane.showConfirmDialog( null,
+ my_panel,
+ "Enter the sequence annotation(s) for the "
+ + nodes.size() + " selected nodes",
+ JOptionPane.OK_CANCEL_OPTION );
+ if ( result == JOptionPane.OK_OPTION ) {
+ String ref = ref_field.getText();
+ String desc = desc_filed.getText();
+ if ( !ForesterUtil.isEmpty( ref ) ) {
+ ref = ref.trim();
+ ref = ref.replaceAll( "\\s+", " " );
+ if ( ( ref.indexOf( ':' ) < 1 ) || ( ref.indexOf( ':' ) > ( ref.length() - 2 ) )
+ || ( ref.length() < 3 ) ) {
+ JOptionPane.showMessageDialog( this,
+ "Reference needs to be in the form of \"GO:1234567\"",
+ "Illegal Format for Annotation Reference",
+ JOptionPane.ERROR_MESSAGE );
+ return;
+ }
+ }
+ if ( ref != null ) {
+ setPreviousNodeAnnotationReference( ref );
+ }
+ if ( desc != null ) {
+ desc = desc.trim();
+ desc = desc.replaceAll( "\\s+", " " );
+ }
+ if ( !ForesterUtil.isEmpty( ref ) || !ForesterUtil.isEmpty( desc ) ) {
+ for( final PhylogenyNode n : nodes ) {
+ ForesterUtil.ensurePresenceOfSequence( n );
+ final Annotation ann = ForesterUtil.isEmpty( ref ) ? new Annotation()
+ : new Annotation( ref );
+ if ( !ForesterUtil.isEmpty( desc ) ) {
+ ann.setDesc( desc );
+ }
+ n.getNodeData().getSequence().addAnnotation( ann );
+ }
+ }
+ getMainPanel().getControlPanel().showAnnotations();
+ }
+ }
+ }
+ }
+
+ private void chooseFont() {
+ final FontChooser fc = new FontChooser();
+ fc.setFont( getMainPanel().getTreeFontSet().getLargeFont() );
+ fc.showDialog( this, "Select the Base Font" );
+ getMainPanel().getTreeFontSet().setBaseFont( fc.getFont() );
+ getControlPanel().displayedPhylogenyMightHaveChanged( true );
+ if ( getMainPanel().getCurrentTreePanel() != null ) {
+ getMainPanel().getCurrentTreePanel().resetPreferredSize();
+ getMainPanel().getCurrentTreePanel().updateOvSizes();
+ }
+
+ repaint();
+ }
+
+ private void chooseMinimalConfidence() {
+ final String s = ( String ) JOptionPane
+ .showInputDialog( this,
+ "Please enter the minimum for confidence values to be displayed.\n"
+ + "[current value: " + getOptions().getMinConfidenceValue() + "]\n",
+ "Minimal Confidence Value",
+ JOptionPane.QUESTION_MESSAGE,
+ null,
+ null,
+ getOptions().getMinConfidenceValue() );
+ if ( !ForesterUtil.isEmpty( s ) ) {
+ boolean success = true;
+ double m = 0.0;
+ final String m_str = s.trim();
+ if ( !ForesterUtil.isEmpty( m_str ) ) {
+ try {
+ m = Double.parseDouble( m_str );
+ }
+ catch ( final Exception ex ) {
+ success = false;
+ }
+ }
+ else {
+ success = false;
+ }
+ if ( success && ( m >= 0.0 ) ) {
+ getOptions().setMinConfidenceValue( m );
+ }
+ }
+ }
+
+ private void deleteSelectedNodes( final boolean delete ) {
+ final Phylogeny phy = getMainPanel().getCurrentPhylogeny();
+ if ( ( phy == null ) || ( phy.getNumberOfExternalNodes() < 2 ) ) {
+ return;
+ }
+ final List<PhylogenyNode> nodes = new ArrayList<PhylogenyNode>();
+ if ( ( getCurrentTreePanel().getFoundNodes0() != null ) || ( getCurrentTreePanel().getFoundNodes1() != null ) ) {
+ final List<PhylogenyNode> all_selected_nodes = getCurrentTreePanel().getFoundNodesAsListOfPhylogenyNodes();
+ for( final PhylogenyNode n : all_selected_nodes ) {
+ if ( n.isExternal() ) {
+ nodes.add( n );
+ }
+ }
+ }
+ String function = "Retain";
+ if ( delete ) {
+ function = "Delete";
+ }
+ if ( ( nodes == null ) || nodes.isEmpty() ) {
+ JOptionPane
+ .showMessageDialog( this,
+ "Need to select external nodes, either via direct selection or via the \"Search\" function",
+ "No external nodes selected to " + function.toLowerCase(),
+ JOptionPane.ERROR_MESSAGE );
+ return;
+ }
+ final int todo = nodes.size();
+ final int ext = phy.getNumberOfExternalNodes();
+ int res = todo;
+ if ( delete ) {
+ res = ext - todo;
+ }
+ if ( res < 1 ) {
+ JOptionPane.showMessageDialog( this,
+ "Cannot delete all nodes",
+ "Attempt to delete all nodes ",
+ JOptionPane.ERROR_MESSAGE );
+ return;
+ }
+ final int result = JOptionPane.showConfirmDialog( null, function + " " + todo
+ + " external node(s), from a total of " + ext + " external nodes," + "\nresulting in tree with " + res
+ + " nodes?", function + " external nodes", JOptionPane.OK_CANCEL_OPTION );
+ if ( result == JOptionPane.OK_OPTION ) {
+ if ( !delete ) {
+ final List<PhylogenyNode> to_delete = new ArrayList<PhylogenyNode>();
+ for( final PhylogenyNodeIterator it = phy.iteratorExternalForward(); it.hasNext(); ) {
+ final PhylogenyNode n = it.next();
+ if ( !nodes.contains( n ) ) {
+ to_delete.add( n );
+ }
+ }
+ for( final PhylogenyNode n : to_delete ) {
+ phy.deleteSubtree( n, true );
+ }
+ }
+ else {
+ for( final PhylogenyNode n : nodes ) {
+ phy.deleteSubtree( n, true );
+ }
+ }
+ resetSearch();
+ getCurrentTreePanel().setNodeInPreorderToNull();
+ phy.externalNodesHaveChanged();
+ phy.clearHashIdToNodeMap();
+ phy.recalculateNumberOfExternalDescendants( true );
+ getCurrentTreePanel().resetNodeIdToDistToLeafMap();
+ getCurrentTreePanel().setEdited( true );
+ repaint();
+ }
+ }
+
+ private void doUpdateProcessMenu() {
+ if ( _process_pool.size() > 0 ) {
+ if ( _process_menu == null ) {
+ _process_menu = createMenu( "", getConfiguration() );
+ _process_menu.setForeground( Color.RED );
+ }
+ _process_menu.removeAll();
+ final String text = "processes running: " + _process_pool.size();
+ _process_menu.setText( text );
+ _jmenubar.add( _process_menu );
+ for( int i = 0; i < _process_pool.size(); ++i ) {
+ final ProcessRunning p = _process_pool.getProcessByIndex( i );
+ _process_menu.add( customizeJMenuItem( new JMenuItem( p.getName() + " [" + p.getStart() + "]" ) ) );
+ }
+ }
+ else {
+ if ( _process_menu != null ) {
+ _process_menu.removeAll();
+ _jmenubar.remove( _process_menu );
+ }
+ }
+ _jmenubar.validate();
+ _jmenubar.repaint();
+ repaint();
+ }
+
+ private String getPreviousNodeAnnotationReference() {
+ return _previous_node_annotation_ref;
+ }
+
+ private void removeBranchColors() {
+ if ( getMainPanel().getCurrentPhylogeny() != null ) {
+ AptxUtil.removeBranchColors( getMainPanel().getCurrentPhylogeny() );
+ }
+ }
+
+ private void removeVisualStyles() {
+ if ( getMainPanel().getCurrentPhylogeny() != null ) {
+ AptxUtil.removeVisualStyles( getMainPanel().getCurrentPhylogeny() );
+ }
+ }
+
+ private void setPreviousNodeAnnotationReference( final String previous_node_annotation_ref ) {
+ _previous_node_annotation_ref = previous_node_annotation_ref;
+ }
+
+ private void writeAllToFile() {
+ if ( ( getMainPanel().getTabbedPane() == null ) || ( getMainPanel().getTabbedPane().getTabCount() < 1 ) ) {
+ return;
+ }
+ final File my_dir = getCurrentDir();
+ if ( my_dir != null ) {
+ _save_filechooser.setCurrentDirectory( my_dir );
+ }
+ _save_filechooser.setSelectedFile( new File( "" ) );
+ final int result = _save_filechooser.showSaveDialog( _contentpane );
+ final File file = _save_filechooser.getSelectedFile();
+ setCurrentDir( _save_filechooser.getCurrentDirectory() );
+ if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
+ if ( file.exists() ) {
+ final int i = JOptionPane.showConfirmDialog( this,
+ file + " already exists. Overwrite?",
+ "Warning",
+ JOptionPane.OK_CANCEL_OPTION,
+ JOptionPane.WARNING_MESSAGE );
+ if ( i != JOptionPane.OK_OPTION ) {
+ return;
+ }
+ else {
+ try {
+ file.delete();
+ }
+ catch ( final Exception e ) {
+ JOptionPane.showMessageDialog( this,
+ "Failed to delete: " + file,
+ "Error",
+ JOptionPane.WARNING_MESSAGE );
+ }
+ }
+ }
+ final int count = getMainPanel().getTabbedPane().getTabCount();
+ final List<Phylogeny> trees = new ArrayList<Phylogeny>();
+ for( int i = 0; i < count; ++i ) {
+ final Phylogeny phy = getMainPanel().getPhylogeny( i );
+ if ( ForesterUtil.isEmpty( phy.getName() )
+ && !ForesterUtil.isEmpty( getMainPanel().getTabbedPane().getTitleAt( i ) ) ) {
+ phy.setName( getMainPanel().getTabbedPane().getTitleAt( i ) );
+ }
+ trees.add( phy );
+ getMainPanel().getTreePanels().get( i ).setEdited( false );
+ }
+ final PhylogenyWriter writer = new PhylogenyWriter();
+ try {
+ writer.toPhyloXML( file, trees, 0, ForesterUtil.LINE_SEPARATOR );
+ }
+ catch ( final IOException e ) {
+ JOptionPane.showMessageDialog( this,
+ "Failed to write to: " + file,
+ "Error",
+ JOptionPane.WARNING_MESSAGE );