+
+ public Options getOptions() {
+ return _options;
+ }
+
+ @Override
+ public void init() {
+ final String config_filename = getParameter( Constants.APPLET_PARAM_NAME_FOR_CONFIG_FILE_URL );
+ AptxUtil.printAppletMessage( NAME, "URL for configuration file is: " + config_filename );
+ final Configuration configuration = new Configuration( config_filename, true, true, true );
+ setConfiguration( configuration );
+ setOptions( Options.createInstance( configuration ) );
+ setupUI();
+ final String tree_url_str = getParameter( Constants.APPLET_PARAM_NAME_FOR_URL_OF_TREE_TO_LOAD );
+ if ( ForesterUtil.isEmpty( tree_url_str ) ) {
+ ForesterUtil.printErrorMessage( NAME, "could not get tree URL from "
+ + Constants.APPLET_PARAM_NAME_FOR_URL_OF_TREE_TO_LOAD );
+ JOptionPane.showMessageDialog( this, NAME + ": could not get tree URL from "
+ + Constants.APPLET_PARAM_NAME_FOR_URL_OF_TREE_TO_LOAD, "Failed get URL", JOptionPane.ERROR_MESSAGE );
+ return;
+ }
+ AptxUtil.printAppletMessage( NAME, "URL for phylogenies is " + tree_url_str );
+ // Get URL to tree file
+ URL phys_url = null;
+ try {
+ phys_url = new URL( tree_url_str );
+ }
+ catch ( final Exception e ) {
+ ForesterUtil.printErrorMessage( NAME, "error: " + e );
+ e.printStackTrace();
+ JOptionPane.showMessageDialog( this, NAME + ": Could not create URL from: \"" + tree_url_str
+ + "\"\nException: " + e, "Failed to create URL", JOptionPane.ERROR_MESSAGE );
+ }
+ if ( phys_url == null ) {
+ ForesterUtil.printErrorMessage( NAME, "failed to get tree URL from "
+ + Constants.APPLET_PARAM_NAME_FOR_URL_OF_TREE_TO_LOAD );
+ JOptionPane.showMessageDialog( this,
+ NAME + ": Could not create URL from: \"" + tree_url_str,
+ "Failed to create URL",
+ JOptionPane.ERROR_MESSAGE );
+ return;
+ }
+ // Load the tree from URL
+ Phylogeny[] phys = null;
+ try {
+ phys = AptxUtil.readPhylogeniesFromUrl( phys_url,
+ getConfiguration().isValidatePhyloXmlAgainstSchema(),
+ getConfiguration().isReplaceUnderscoresInNhParsing(),
+ getConfiguration().isInternalNumberAreConfidenceForNhParsing(),
+ getConfiguration().getTaxonomyExtraction(),
+ getConfiguration().isMidpointReroot() );
+ }
+ catch ( final Exception e ) {
+ ForesterUtil.printErrorMessage( NAME, e.toString() );
+ e.printStackTrace();
+ JOptionPane.showMessageDialog( this,
+ NAME + ": Failed to read phylogenies: " + "\nException: " + e,
+ "Failed to read phylogenies",
+ JOptionPane.ERROR_MESSAGE );
+ }
+ if ( phys == null ) {
+ ForesterUtil.printErrorMessage( NAME, "phylogenies from [" + phys_url + "] are null" );
+ JOptionPane.showMessageDialog( this,
+ NAME + ": phylogenies from [" + phys_url + "] are null",
+ "Failed to read phylogenies",
+ JOptionPane.ERROR_MESSAGE );
+ return;
+ }
+ else if ( phys.length < 1 ) {
+ ForesterUtil.printErrorMessage( NAME, "phylogenies from [" + phys_url + "] are empty" );
+ JOptionPane.showMessageDialog( this,
+ NAME + ": phylogenies from [" + phys_url + "] are empty",
+ "Failed to read phylogenies",
+ JOptionPane.ERROR_MESSAGE );
+ return;
+ }
+ else {
+ AptxUtil.printAppletMessage( NAME, "loaded " + phys.length + " phylogenies from: " + phys_url );
+ }
+ //
+ final String species_tree_url_str = getParameter( Constants.APPLET_PARAM_NAME_FOR_URL_OF_SPECIES_TREE_TO_LOAD );
+ if ( !ForesterUtil.isEmpty( species_tree_url_str ) ) {
+ AptxUtil.printAppletMessage( NAME, "URL of species tree to load: \"" + species_tree_url_str + "\"" );
+ Phylogeny[] species_trees = null;
+ try {
+ final URL species_tree_url = new URL( species_tree_url_str );
+ species_trees = AptxUtil.readPhylogeniesFromUrl( species_tree_url,
+ configuration.isValidatePhyloXmlAgainstSchema(),
+ configuration.isReplaceUnderscoresInNhParsing(),
+ false,
+ TAXONOMY_EXTRACTION.NO,
+ false );
+ }
+ catch ( final IOException e ) {
+ ForesterUtil.printErrorMessage( NAME, "could not read species tree from [" + species_tree_url_str
+ + "]" );
+ JOptionPane.showMessageDialog( this, NAME + ": could not read species tree from ["
+ + species_tree_url_str + "]", "Failed to read species tree", JOptionPane.ERROR_MESSAGE );
+ }
+ if ( ( species_trees != null ) && ( species_trees.length > 0 ) ) {
+ AptxUtil.printAppletMessage( NAME, "successfully read species tree" );
+ if ( species_trees[ 0 ].isEmpty() ) {
+ ForesterUtil.printErrorMessage( NAME, "species tree is empty" );
+ }
+ else if ( !species_trees[ 0 ].isRooted() ) {
+ ForesterUtil.printErrorMessage( NAME, "species tree is not rooted" );
+ }
+ else {
+ setSpeciesTree( species_trees[ 0 ] );
+ AptxUtil.printAppletMessage( NAME, "species tree OK" );
+ }
+ }
+ }
+ //
+ try {
+ setVisible( false );
+ setMainPanel( new MainPanelApplets( getConfiguration(), this ) );
+ _jmenubar = new JMenuBar();
+ if ( !getConfiguration().isHideControlPanelAndMenubar() ) {
+ buildFileMenu();
+ if ( !getConfiguration().isUseNativeUI() ) {
+ _jmenubar.setBackground( getConfiguration().getGuiMenuBackgroundColor() );
+ }
+ if ( getSpeciesTree() != null ) {
+ buildAnalysisMenu();
+ }
+ buildToolsMenu();
+ buildViewMenu();
+ buildFontSizeMenu();
+ buildOptionsMenu();
+ buildTypeMenu();
+ buildHelpMenu();
+ setJMenuBar( _jmenubar );
+ }
+ final Container contentpane = getContentPane();
+ contentpane.setLayout( new BorderLayout() );
+ contentpane.add( getMainPanel(), BorderLayout.CENTER );
+ addComponentListener( new ComponentAdapter() {
+
+ @Override
+ public void componentResized( final ComponentEvent e ) {
+ if ( getMainPanel().getCurrentTreePanel() != null ) {
+ getMainPanel().getCurrentTreePanel().calcParametersForPainting( getMainPanel()
+ .getCurrentTreePanel()
+ .getWidth(),
+ getMainPanel()
+ .getCurrentTreePanel()
+ .getHeight() );
+ }
+ }
+ } );
+ if ( getConfiguration().isUseTabbedDisplay() ) {
+ try {
+ AptxUtil.printAppletMessage( NAME, "using tabbed display" );
+ AptxUtil.addPhylogeniesToTabs( phys,
+ new File( phys_url.getFile() ).getName(),
+ phys_url.toString(),
+ getConfiguration(),
+ getMainPanel() );
+ }
+ catch ( final Exception e ) {
+ ForesterUtil.printErrorMessage( NAME, e.toString() );
+ e.printStackTrace();
+ }
+ }
+ else {
+ AptxUtil.printAppletMessage( NAME, "not using tabbed display" );
+ if ( getSpeciesTree() != null ) {
+ AptxUtil.printAppletMessage( NAME,
+ "Warning: gsdi (gene duplication inference) only available tabbed display" );
+ }
+ AptxUtil.addPhylogenyToPanel( phys, getConfiguration(), getMainPanel() );
+ }
+ validate();
+ setName( NAME );
+ getMainPanel().getControlPanel().showWholeAll();
+ getMainPanel().getControlPanel().showWhole();
+ /* GUILHEM_BEG */
+ getCurrentTreePanel().getControlPanel().getSequenceRelationTypeBox().removeAllItems();
+ for( final SequenceRelation.SEQUENCE_RELATION_TYPE type : getMainPanel().getCurrentPhylogeny()
+ .getRelevantSequenceRelationTypes() ) {
+ getCurrentTreePanel().getControlPanel().getSequenceRelationTypeBox().addItem( type );
+ }
+ final String default_relation = getParameter( Constants.APPLET_PARAM_NAME_FOR_DEFAULT_SEQUENCE_RELATION_TYPE );
+ if ( default_relation != null ) {
+ getCurrentTreePanel().getControlPanel().getSequenceRelationTypeBox().setSelectedItem( default_relation );
+ }
+ final String default_sequence = getParameter( Constants.APPLET_PARAM_NAME_FOR_DEFAULT_QUERY_SEQUENCE );
+ if ( default_sequence != null ) {
+ getCurrentTreePanel().getControlPanel().getSequenceRelationBox().setSelectedItem( default_sequence );
+ }
+ /* GUILHEM_END */
+ System.gc();
+ AptxUtil.printAppletMessage( NAME, "successfully initialized" );
+ setVisible( true );
+ }
+ catch ( final Exception e ) {
+ ForesterUtil.printErrorMessage( NAME, e.toString() );
+ e.printStackTrace();
+ }
+ }
+
+ public void showTextFrame( final String s, final String title ) {
+ checkTextFrames();
+ _textframes.addLast( TextFrame.instantiate( s, title, _textframes ) );
+ }
+
+ @Override
+ public void start() {
+ if ( getMainPanel() != null ) {
+ getMainPanel().validate();
+ }
+ requestFocus();
+ requestFocusInWindow();
+ requestFocus();
+ AptxUtil.printAppletMessage( NAME, "started" );
+ }
+
+ void buildAnalysisMenu() {
+ _analysis_menu = MainFrame.createMenu( "Analysis", getConfiguration() );
+ _analysis_menu.add( _gsdi_item = new JMenuItem( "GSDI (Generalized Speciation Duplication Inference)" ) );
+ _analysis_menu.add( _gsdir_item = new JMenuItem( "GSDIR (GSDI with re-rooting)" ) );
+ customizeJMenuItem( _gsdi_item );
+ customizeJMenuItem( _gsdir_item );
+ // _analysis_menu.addSeparator();
+ // _analysis_menu.add( _lineage_inference = new JMenuItem( INFER_ANCESTOR_TAXONOMIES ) );
+ // customizeJMenuItem( _lineage_inference );
+ // _lineage_inference.setToolTipText( "Inference of ancestor taxonomies/lineages" );
+ _jmenubar.add( _analysis_menu );
+ }
+