X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=forester%2Fjava%2Fsrc%2Forg%2Fforester%2Farchaeopteryx%2FMainFrameApplet.java;h=75801961043171d65d471793e312b36cedb60f96;hb=1472d0ec482c8642dab9336b17041e6e398acb78;hp=4a5c93204424b13e73b6b29ded75fe31cf450a64;hpb=e928c819cdb894764733f5d40441a8235a6c629a;p=jalview.git diff --git a/forester/java/src/org/forester/archaeopteryx/MainFrameApplet.java b/forester/java/src/org/forester/archaeopteryx/MainFrameApplet.java index 4a5c932..7580196 100644 --- a/forester/java/src/org/forester/archaeopteryx/MainFrameApplet.java +++ b/forester/java/src/org/forester/archaeopteryx/MainFrameApplet.java @@ -33,6 +33,9 @@ import java.awt.event.ComponentAdapter; import java.awt.event.ComponentEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.net.MalformedURLException; import java.net.URL; import javax.swing.ButtonGroup; @@ -40,13 +43,13 @@ import javax.swing.JApplet; import javax.swing.JCheckBoxMenuItem; import javax.swing.JMenuBar; import javax.swing.JMenuItem; -import javax.swing.JOptionPane; import javax.swing.JRadioButtonMenuItem; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import org.forester.archaeopteryx.Options.CLADOGRAM_TYPE; import org.forester.archaeopteryx.Options.NODE_LABEL_DIRECTION; +import org.forester.io.parsers.nhx.NHXParser.TAXONOMY_EXTRACTION; import org.forester.phylogeny.Phylogeny; import org.forester.util.ForesterUtil; @@ -58,63 +61,32 @@ public final class MainFrameApplet extends MainFrame { private final ArchaeopteryxA _applet; private ButtonGroup _radio_group_1; - MainFrameApplet( final ArchaeopteryxA parent_applet, final Configuration configuration ) { + MainFrameApplet( final ArchaeopteryxA parent_applet, + final Configuration configuration, + final String species_tree_url_str ) { setTitle( ArchaeopteryxA.NAME ); _applet = parent_applet; setConfiguration( configuration ); setOptions( Options.createInstance( configuration ) ); - //_textframes = null; //~~~~ - URL url = null; - Phylogeny[] phys = null; - // Get URL to tree file - if ( _applet.getTreeUrlStr() != null ) { - try { - url = new URL( _applet.getTreeUrlStr() ); - } - catch ( final Exception e ) { - ForesterUtil.printErrorMessage( ArchaeopteryxA.NAME, e.toString() ); - e.printStackTrace(); - JOptionPane.showMessageDialog( this, - ArchaeopteryxA.NAME + ": Could not create URL from: \"" - + _applet.getTreeUrlStr() + "\"\nError: " + e, - "Failed to create URL", - JOptionPane.ERROR_MESSAGE ); - close(); - } - } - // Load the tree from URL - if ( url != null ) { + _mainpanel = new MainPanelApplets( _configuration, this ); + if ( !ForesterUtil.isEmpty( species_tree_url_str ) ) { try { - phys = AptxUtil.readPhylogeniesFromUrl( url, - configuration.isValidatePhyloXmlAgainstSchema(), - configuration.isReplaceUnderscoresInNhParsing(), - configuration.isInternalNumberAreConfidenceForNhParsing(), - configuration.getTaxonomyExtraction() ); + readSpeciesTree( configuration, species_tree_url_str ); } catch ( final Exception e ) { + ForesterUtil.printErrorMessage( ArchaeopteryxA.NAME, "failed to read species tree from " + + species_tree_url_str ); ForesterUtil.printErrorMessage( ArchaeopteryxA.NAME, e.toString() ); - e.printStackTrace(); - JOptionPane.showMessageDialog( this, ArchaeopteryxA.NAME + ": Failed to read phylogenies: " - + "\nError: " + e, "Failed to read phylogenies", JOptionPane.ERROR_MESSAGE ); - close(); } } - if ( ( phys == null ) || ( phys.length < 1 ) ) { - ForesterUtil.printErrorMessage( ArchaeopteryxA.NAME, "phylogenies from [" + url + "] are null or empty" ); - JOptionPane.showMessageDialog( this, ArchaeopteryxA.NAME + ": phylogenies from [" + url - + "] are null or empty", "Failed to read phylogenies", JOptionPane.ERROR_MESSAGE ); - } - else { - AptxUtil.printAppletMessage( ArchaeopteryxA.NAME, "loaded " + phys.length + " phylogenies from: " + url ); - } - _mainpanel = new MainPanelApplets( _configuration, this ); // build the menu bar _jmenubar = new JMenuBar(); if ( !_configuration.isUseNativeUI() ) { _jmenubar.setBackground( _configuration.getGuiMenuBackgroundColor() ); } - //TODO if species tree... - buildAnalysisMenu(); + if ( getSpeciesTree() != null ) { + buildAnalysisMenu(); + } buildToolsMenu(); buildViewMenu(); buildFontSizeMenu(); @@ -154,6 +126,41 @@ public final class MainFrameApplet extends MainFrame { System.gc(); } + private void readSpeciesTree( final Configuration configuration, final String species_tree_url_str ) + throws MalformedURLException, FileNotFoundException, IOException { + final URL species_tree_url = new URL( species_tree_url_str ); + final Phylogeny[] species_trees = AptxUtil.readPhylogeniesFromUrl( species_tree_url, + configuration + .isValidatePhyloXmlAgainstSchema(), + configuration + .isReplaceUnderscoresInNhParsing(), + false, + TAXONOMY_EXTRACTION.NO, + false ); + if ( ( species_trees != null ) && ( species_trees.length > 0 ) ) { + AptxUtil.printAppletMessage( ArchaeopteryxA.NAME, "successfully read species tree" ); + if ( species_trees[ 0 ].isEmpty() ) { + ForesterUtil.printErrorMessage( ArchaeopteryxA.NAME, "species tree is empty" ); + } + else if ( !species_trees[ 0 ].isRooted() ) { + ForesterUtil.printErrorMessage( ArchaeopteryxA.NAME, "species tree is not rooted" ); + } + else { + setSpeciesTree( species_trees[ 0 ] ); + AptxUtil.printAppletMessage( ArchaeopteryxA.NAME, "species tree OK" ); + } + } + else { + ForesterUtil.printErrorMessage( ArchaeopteryxA.NAME, "failed to read species tree from " + + species_tree_url_str ); + } + } + + @Override + public MainPanel getMainPanel() { + return _mainpanel; + } + void buildAnalysisMenu() { _analysis_menu = MainFrame.createMenu( "Analysis", getConfiguration() ); _analysis_menu.add( _gsdi_item = new JMenuItem( "GSDI (Generalized Speciation Duplication Inference)" ) ); @@ -225,6 +232,7 @@ public final class MainFrameApplet extends MainFrame { if ( getConfiguration().doDisplayOption( Configuration.show_domain_architectures ) ) { _options_jmenu.add( _show_domain_labels = new JCheckBoxMenuItem( SHOW_DOMAIN_LABELS_LABEL ) ); } + _options_jmenu.add( _show_annotation_ref_source = new JCheckBoxMenuItem( SHOW_ANN_REF_SOURCE_LABEL ) ); _options_jmenu.add( _choose_minimal_confidence_mi = new JMenuItem( "" ) ); _options_jmenu.add( _overview_placment_mi = new JMenuItem( "" ) ); _options_jmenu.add( _switch_colors_mi = new JMenuItem( "" ) ); @@ -252,6 +260,7 @@ public final class MainFrameApplet extends MainFrame { customizeCheckBoxMenuItem( _screen_antialias_cbmi, getOptions().isAntialiasScreen() ); customizeCheckBoxMenuItem( _background_gradient_cbmi, getOptions().isBackgroundColorGradient() ); customizeCheckBoxMenuItem( _show_domain_labels, getOptions().isShowDomainLabels() ); + customizeCheckBoxMenuItem( _show_annotation_ref_source, getOptions().isShowAnnotationRefSource() ); customizeCheckBoxMenuItem( _abbreviate_scientific_names, getOptions().isAbbreviateScientificTaxonNames() ); customizeCheckBoxMenuItem( _search_case_senstive_cbmi, getOptions().isSearchCaseSensitive() ); customizeCheckBoxMenuItem( _show_scale_cbmi, getOptions().isShowScale() ); @@ -294,16 +303,7 @@ public final class MainFrameApplet extends MainFrame { } @Override - public MainPanel getMainPanel() { - return _mainpanel; - } - - @Override void readPhylogeniesFromURL() { throw new NoSuchMethodError( "not implemented" ); } - - void setSpeciesTree( final Phylogeny species_tree ) { - _species_tree = species_tree; - } }