+ }
+ 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 );
+ }
+ }
+ }
+
+ public void activateSaveAllIfNeeded() {
+ if ( ( getMainPanel().getTabbedPane() != null ) && ( getMainPanel().getTabbedPane().getTabCount() > 1 ) ) {
+ _save_all_item.setEnabled( true );
+ }
+ else {
+ _save_all_item.setEnabled( false );
+ }
+ }
+
+ void buildFileMenu() {
+ _file_jmenu = MainFrame.createMenu( "File", getConfiguration() );
+ _file_jmenu.add( _save_item = new JMenuItem( "Save Tree As..." ) );
+ _file_jmenu.addSeparator();
+ _file_jmenu.add( _write_to_pdf_item = new JMenuItem( "Export to PDF file ..." ) );
+ if ( AptxUtil.canWriteFormat( "tif" ) || AptxUtil.canWriteFormat( "tiff" ) || AptxUtil.canWriteFormat( "TIF" ) ) {
+ _file_jmenu.add( _write_to_tif_item = new JMenuItem( "Export to TIFF file..." ) );
+ }
+ _file_jmenu.add( _write_to_png_item = new JMenuItem( "Export to PNG file..." ) );
+ _file_jmenu.add( _write_to_jpg_item = new JMenuItem( "Export to JPG file..." ) );
+ if ( AptxUtil.canWriteFormat( "gif" ) ) {
+ _file_jmenu.add( _write_to_gif_item = new JMenuItem( "Export to GIF file..." ) );
+ }
+ if ( AptxUtil.canWriteFormat( "bmp" ) ) {
+ _file_jmenu.add( _write_to_bmp_item = new JMenuItem( "Export to BMP file..." ) );
+ }
+ _file_jmenu.addSeparator();
+ _file_jmenu.add( _print_item = new JMenuItem( "Print..." ) );
+ _file_jmenu.addSeparator();
+ _file_jmenu.add( _exit_item = new JMenuItem( "Exit" ) );
+ customizeJMenuItem( _save_item );
+ customizeJMenuItem( _write_to_pdf_item );
+ customizeJMenuItem( _write_to_png_item );
+ customizeJMenuItem( _write_to_jpg_item );
+ customizeJMenuItem( _write_to_gif_item );
+ customizeJMenuItem( _write_to_tif_item );
+ customizeJMenuItem( _write_to_bmp_item );
+ customizeJMenuItem( _print_item );
+ customizeJMenuItem( _exit_item );
+ _jmenubar.add( _file_jmenu );
+ }
+
+ void buildFontSizeMenu() {
+ _font_size_menu = createMenu( FONT_SIZE_MENU_LABEL, getConfiguration() );
+ _font_size_menu.add( _super_tiny_fonts_item = new JMenuItem( "Super Tiny Fonts" ) );
+ _font_size_menu.add( _tiny_fonts_item = new JMenuItem( "Tiny Fonts" ) );
+ _font_size_menu.add( _small_fonts_item = new JMenuItem( "Small Fonts" ) );
+ _font_size_menu.add( _medium_fonts_item = new JMenuItem( "Medium Fonts" ) );
+ _font_size_menu.add( _large_fonts_item = new JMenuItem( "Large Fonts" ) );
+ customizeJMenuItem( _super_tiny_fonts_item );
+ customizeJMenuItem( _tiny_fonts_item );
+ customizeJMenuItem( _small_fonts_item );
+ customizeJMenuItem( _medium_fonts_item );
+ customizeJMenuItem( _large_fonts_item );
+ _jmenubar.add( _font_size_menu );
+ }
+
+ void buildHelpMenu() {
+ _help_jmenu = createMenu( "Help", getConfiguration() );
+ _help_jmenu.add( _help_item = new JMenuItem( "Documentation" ) );
+ _help_jmenu.addSeparator();
+ _help_jmenu.add( _website_item = new JMenuItem( "Archaeopteryx Home" ) );
+ _help_jmenu.add( _aptxjs_website_item = new JMenuItem( "NEW! Archaeopteryx online version: Archaeopteryx.js" ) );
+ _help_jmenu.add( _mailing_list_item = new JMenuItem( "Mailing List" ) );
+ _aptx_ref_item = new JMenuItem( "Archaeopteryx Reference" ); //TODO need to add this...
+ _help_jmenu.add( _phyloxml_website_item = new JMenuItem( "phyloXML Home" ) );
+ _help_jmenu.add( _phyloxml_ref_item = new JMenuItem( "phyloXML Reference" ) );
+ _help_jmenu.addSeparator();
+ _help_jmenu.add( _about_item = new JMenuItem( "About" ) );
+ customizeJMenuItem( _help_item );
+ customizeJMenuItem( _website_item );
+ customizeJMenuItem( _aptxjs_website_item );
+ customizeJMenuItem( _mailing_list_item );
+ customizeJMenuItem( _phyloxml_website_item );
+ customizeJMenuItem( _aptx_ref_item );
+ customizeJMenuItem( _phyloxml_ref_item );
+ customizeJMenuItem( _about_item );
+ _phyloxml_ref_item.setToolTipText( PHYLOXML_REF_TOOL_TIP );
+ _aptx_ref_item.setToolTipText( APTX_REF_TOOL_TIP );
+ _jmenubar.add( _help_jmenu );
+ }
+
+ void buildTypeMenu() {
+ _type_menu = createMenu( TYPE_MENU_HEADER, getConfiguration() );
+ _type_menu.add( _rectangular_type_cbmi = new JCheckBoxMenuItem( MainFrame.RECTANGULAR_TYPE_CBMI_LABEL ) );
+ _type_menu.add( _euro_type_cbmi = new JCheckBoxMenuItem( MainFrame.EURO_TYPE_CBMI_LABEL ) );
+ _type_menu.add( _rounded_type_cbmi = new JCheckBoxMenuItem( MainFrame.ROUNDED_TYPE_CBMI_LABEL ) );
+ _type_menu.add( _curved_type_cbmi = new JCheckBoxMenuItem( MainFrame.CURVED_TYPE_CBMI_LABEL ) );
+ _type_menu.add( _triangular_type_cbmi = new JCheckBoxMenuItem( MainFrame.TRIANGULAR_TYPE_CBMI_LABEL ) );
+ _type_menu.add( _convex_type_cbmi = new JCheckBoxMenuItem( MainFrame.CONVEX_TYPE_CBMI_LABEL ) );
+ _type_menu.add( _unrooted_type_cbmi = new JCheckBoxMenuItem( MainFrame.UNROOTED_TYPE_CBMI_LABEL ) );
+ _type_menu.add( _circular_type_cbmi = new JCheckBoxMenuItem( MainFrame.CIRCULAR_TYPE_CBMI_LABEL ) );
+ customizeCheckBoxMenuItem( _rectangular_type_cbmi, false );
+ customizeCheckBoxMenuItem( _triangular_type_cbmi, false );
+ customizeCheckBoxMenuItem( _euro_type_cbmi, false );
+ customizeCheckBoxMenuItem( _rounded_type_cbmi, false );
+ customizeCheckBoxMenuItem( _curved_type_cbmi, false );
+ customizeCheckBoxMenuItem( _convex_type_cbmi, false );
+ customizeCheckBoxMenuItem( _unrooted_type_cbmi, false );
+ customizeCheckBoxMenuItem( _circular_type_cbmi, false );
+ _triangular_type_cbmi.setToolTipText( "not suitable for phylograms" );
+ _curved_type_cbmi.setToolTipText( "not suitable for phylograms" );
+ _unrooted_type_cbmi.setToolTipText( MainFrame.USE_MOUSEWHEEL_SHIFT_TO_ROTATE );
+ _circular_type_cbmi.setToolTipText( MainFrame.USE_MOUSEWHEEL_SHIFT_TO_ROTATE );
+ initializeTypeMenu( getOptions() );
+ _jmenubar.add( _type_menu );
+ }
+
+ void buildViewMenu() {
+ _view_jmenu = createMenu( "View", getConfiguration() );
+ _view_jmenu.add( _display_basic_information_item = new JMenuItem( SHOW_BASIC_TREE_INFORMATION_LABEL ) );
+ _view_jmenu.addSeparator();
+ _view_jmenu.add( _view_as_XML_item = new JMenuItem( "as phyloXML" ) );
+ _view_jmenu.add( _view_as_NH_item = new JMenuItem( "as Newick" ) );
+ _view_jmenu.add( _view_as_nexus_item = new JMenuItem( "as Nexus" ) );
+ customizeJMenuItem( _display_basic_information_item );
+ customizeJMenuItem( _view_as_NH_item );
+ customizeJMenuItem( _view_as_XML_item );
+ customizeJMenuItem( _view_as_nexus_item );
+ _jmenubar.add( _view_jmenu );
+ }
+
+ void checkTextFrames() {
+ if ( _textframes.size() > 5 ) {
+ try {
+ if ( _textframes.getFirst() != null ) {
+ _textframes.getFirst().removeMe();
+ }
+ else {
+ _textframes.removeFirst();
+ }
+ }
+ catch ( final NoSuchElementException e ) {
+ // Ignore.
+ }
+ }
+ }
+
+ void choosePdfWidth() {
+ final String s = ( String ) JOptionPane.showInputDialog( this,
+ "Please enter the default line width for PDF export.\n"
+ + "[current value: "
+ + getOptions().getPrintLineWidth() + "]\n",
+ "Line Width for PDF Export",
+ JOptionPane.QUESTION_MESSAGE,
+ null,
+ null,
+ getOptions().getPrintLineWidth() );
+ if ( !ForesterUtil.isEmpty( s ) ) {
+ boolean success = true;
+ float f = 0.0f;
+ final String m_str = s.trim();
+ if ( !ForesterUtil.isEmpty( m_str ) ) {
+ try {
+ f = Float.parseFloat( m_str );
+ }
+ catch ( final Exception ex ) {
+ success = false;
+ }
+ }
+ else {
+ success = false;
+ }
+ if ( success && ( f > 0.0 ) ) {
+ getOptions().setPrintLineWidth( f );