in progress
[jalview.git] / forester / java / src / org / forester / archaeopteryx / MainFrameApplication.java
index a6e2569..97a7a7a 100644 (file)
@@ -6,7 +6,7 @@
 // Copyright (C) 2008-2009 Burnham Institute for Medical Research
 // Copyright (C) 2003-2007 Ethalinda K.S. Cannon
 // All rights reserved
-// 
+//
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
@@ -16,7 +16,7 @@
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 // Lesser General Public License for more details.
-// 
+//
 // You should have received a copy of the GNU Lesser General Public
 // License along with this library; if not, write to the Free Software
 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
@@ -57,11 +57,19 @@ import javax.swing.WindowConstants;
 import javax.swing.event.ChangeEvent;
 import javax.swing.event.ChangeListener;
 import javax.swing.filechooser.FileFilter;
+import javax.swing.plaf.synth.SynthLookAndFeel;
 
 import org.forester.archaeopteryx.Options.CLADOGRAM_TYPE;
 import org.forester.archaeopteryx.Options.NODE_LABEL_DIRECTION;
 import org.forester.archaeopteryx.Options.PHYLOGENY_GRAPHICS_TYPE;
 import org.forester.archaeopteryx.Util.GraphicsExportType;
+import org.forester.archaeopteryx.tools.AncestralTaxonomyInferrer;
+import org.forester.archaeopteryx.tools.GoAnnotation;
+import org.forester.archaeopteryx.tools.PhyloInferenceDialog;
+import org.forester.archaeopteryx.tools.PhylogeneticInferenceOptions;
+import org.forester.archaeopteryx.tools.PhylogeneticInferrer;
+import org.forester.archaeopteryx.tools.SequenceDataRetriver;
+import org.forester.archaeopteryx.tools.TaxonomyDataObtainer;
 import org.forester.archaeopteryx.webservices.PhylogeniesWebserviceClient;
 import org.forester.archaeopteryx.webservices.WebservicesManager;
 import org.forester.io.parsers.FastaParser;
@@ -94,9 +102,9 @@ import org.forester.util.BasicTable;
 import org.forester.util.BasicTableParser;
 import org.forester.util.DescriptiveStatistics;
 import org.forester.util.ForesterUtil;
-import org.forester.util.WindowsUtils;
 import org.forester.util.ForesterUtil.PhylogenyNodeField;
 import org.forester.util.ForesterUtil.TAXONOMY_EXTRACTION;
+import org.forester.util.WindowsUtils;
 
 class DefaultFilter extends FileFilter {
 
@@ -229,24 +237,42 @@ public final class MainFrameApplication extends MainFrame {
             throw new IllegalArgumentException( "configuration is null" );
         }
         try {
-            if ( _configuration.isUseNativeUI() ) {
-                UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );
+            boolean synth_exception = false;
+            if ( Constants.__SYNTH_LF ) {
+                try {
+                    final SynthLookAndFeel synth = new SynthLookAndFeel();
+                    synth.load( MainFrameApplication.class.getResourceAsStream( "/resources/synth_look_and_feel_1.xml" ),
+                                MainFrameApplication.class );
+                    UIManager.setLookAndFeel( synth );
+                }
+                catch ( Exception ex ) {
+                    synth_exception = true;
+                    ForesterUtil.printWarningMessage( Constants.PRG_NAME,
+                                                      "could not create synth look and feel: "
+                                                              + ex.getLocalizedMessage() );
+                }
             }
-            else {
-                UIManager.setLookAndFeel( UIManager.getCrossPlatformLookAndFeelClassName() );
+            if ( !Constants.__SYNTH_LF || synth_exception ) {
+                if ( _configuration.isUseNativeUI() ) {
+                    UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );
+                }
+                else {
+                    UIManager.setLookAndFeel( UIManager.getCrossPlatformLookAndFeelClassName() );
+                }
             }
+            //UIManager.setLookAndFeel( "com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel" );
         }
         catch ( final UnsupportedLookAndFeelException e ) {
-            Util.dieWithSystemError( "UnsupportedLookAndFeelException: " + e.toString() );
+            Util.dieWithSystemError( "unsupported look and feel: " + e.toString() );
         }
         catch ( final ClassNotFoundException e ) {
-            Util.dieWithSystemError( "ClassNotFoundException: " + e.toString() );
+            Util.dieWithSystemError( "class not found exception: " + e.toString() );
         }
         catch ( final InstantiationException e ) {
-            Util.dieWithSystemError( "InstantiationException: " + e.toString() );
+            Util.dieWithSystemError( "instantiation exception: " + e.toString() );
         }
         catch ( final IllegalAccessException e ) {
-            Util.dieWithSystemError( "IllegalAccessException: " + e.toString() );
+            Util.dieWithSystemError( "illegal access exception: " + e.toString() );
         }
         catch ( final Exception e ) {
             Util.dieWithSystemError( e.toString() );
@@ -470,6 +496,15 @@ public final class MainFrameApplication extends MainFrame {
                 }
                 obtainDetailedTaxonomicInformation();
             }
+            else if ( o == _obtain_detailed_taxonomic_information_deleting_jmi ) {
+                if ( isSubtreeDisplayed() ) {
+                    return;
+                }
+                obtainDetailedTaxonomicInformationDelete();
+            }
+            else if ( o == _obtain_uniprot_seq_information_jmi ) {
+                obtainUniProtSequenceInformation();
+            }
             else if ( o == _read_values_jmi ) {
                 if ( isSubtreeDisplayed() ) {
                     return;
@@ -674,7 +709,7 @@ public final class MainFrameApplication extends MainFrame {
 
             @Override
             public void stateChanged( final ChangeEvent e ) {
-                MainFrame.setOvPlacementColorChooseMenuItem( _overview_placment_mi, getCurrentTreePanel() );
+                MainFrame.setOvPlacementColorChooseMenuItem( _overview_placment_mi, getOptions() );
                 MainFrame.setTextColorChooseMenuItem( _switch_colors_mi, getCurrentTreePanel() );
                 MainFrame
                         .setTextMinSupportMenuItem( _choose_minimal_confidence_mi, getOptions(), getCurrentTreePanel() );
@@ -689,6 +724,9 @@ public final class MainFrameApplication extends MainFrame {
                                                                      _uniform_cladograms_rbmi,
                                                                      _ext_node_dependent_cladogram_rbmi,
                                                                      _label_direction_cbmi );
+                MainFrame.setCycleNodeFillMenuItem( _cycle_node_fill_mi, getOptions() );
+                MainFrame.setCycleNodeShapeMenuItem( _cycle_node_shape_mi, getOptions() );
+                MainFrame.setTextNodeSizeMenuItem( _choose_node_size_mi, getOptions() );
             }
         } );
         _options_jmenu.add( customizeMenuItemAsLabel( new JMenuItem( DISPLAY_SUBHEADER ), getConfiguration() ) );
@@ -700,7 +738,12 @@ public final class MainFrameApplication extends MainFrame {
         _radio_group_1.add( _ext_node_dependent_cladogram_rbmi );
         _radio_group_1.add( _uniform_cladograms_rbmi );
         _radio_group_1.add( _non_lined_up_cladograms_rbmi );
-        _options_jmenu.add( _show_node_boxes_cbmi = new JCheckBoxMenuItem( DISPLAY_NODE_BOXES_LABEL ) );
+        _options_jmenu.add( _show_default_node_shapes_cbmi = new JCheckBoxMenuItem( DISPLAY_NODE_BOXES_LABEL ) );
+        _options_jmenu
+                .add( _taxonomy_colorize_node_shapes_cbmi = new JCheckBoxMenuItem( MainFrame.TAXONOMY_COLORIZE_NODE_SHAPES_LABEL ) );
+        _options_jmenu.add( _cycle_node_shape_mi = new JMenuItem( MainFrame.CYCLE_NODE_SHAPE_LABEL ) );
+        _options_jmenu.add( _cycle_node_fill_mi = new JMenuItem( MainFrame.CYCLE_NODE_FILL_LABEL ) );
+        _options_jmenu.add( _choose_node_size_mi = new JMenuItem( MainFrame.CHOOSE_NODE_SIZE_LABEL ) );
         _options_jmenu.add( _show_scale_cbmi = new JCheckBoxMenuItem( DISPLAY_SCALE_LABEL ) );
         _options_jmenu
                 .add( _show_branch_length_values_cbmi = new JCheckBoxMenuItem( DISPLAY_BRANCH_LENGTH_VALUES_LABEL ) );
@@ -751,7 +794,11 @@ public final class MainFrameApplication extends MainFrame {
         customizeJMenuItem( _print_size_mi );
         customizeJMenuItem( _choose_pdf_width_mi );
         customizeJMenuItem( _overview_placment_mi );
-        customizeCheckBoxMenuItem( _show_node_boxes_cbmi, getOptions().isShowNodeBoxes() );
+        customizeCheckBoxMenuItem( _show_default_node_shapes_cbmi, getOptions().isShowDefaultNodeShapes() );
+        customizeCheckBoxMenuItem( _taxonomy_colorize_node_shapes_cbmi, getOptions().isTaxonomyColorizeNodeShapes() );
+        customizeJMenuItem( _cycle_node_shape_mi );
+        customizeJMenuItem( _cycle_node_fill_mi );
+        customizeJMenuItem( _choose_node_size_mi );
         customizeCheckBoxMenuItem( _color_labels_same_as_parent_branch, getOptions().isColorLabelsSameAsParentBranch() );
         customizeCheckBoxMenuItem( _screen_antialias_cbmi, getOptions().isAntialiasScreen() );
         customizeCheckBoxMenuItem( _background_gradient_cbmi, getOptions().isBackgroundColorGradient() );
@@ -828,6 +875,15 @@ public final class MainFrameApplication extends MainFrame {
         customizeJMenuItem( _obtain_detailed_taxonomic_information_jmi );
         _obtain_detailed_taxonomic_information_jmi
                 .setToolTipText( "To add additional taxonomic information (from UniProt Taxonomy)" );
+        _tools_menu
+                .add( _obtain_detailed_taxonomic_information_deleting_jmi = new JMenuItem( "Obtain Detailed Taxonomic Information (deletes nodes!)" ) );
+        customizeJMenuItem( _obtain_detailed_taxonomic_information_deleting_jmi );
+        _obtain_detailed_taxonomic_information_deleting_jmi
+                .setToolTipText( "To add additional taxonomic information, deletes nodes for which taxonomy cannot found (from UniProt Taxonomy)" );
+        _tools_menu
+                .add( _obtain_uniprot_seq_information_jmi = new JMenuItem( "Obtain Sequence Information (from UniProt)" ) );
+        customizeJMenuItem( _obtain_uniprot_seq_information_jmi );
+        _obtain_uniprot_seq_information_jmi.setToolTipText( "To add additional sequence information (from UniProt)" );
         _tools_menu.addSeparator();
         if ( !Constants.__RELEASE ) {
             _tools_menu.add( _function_analysis = new JMenuItem( "Add UniProtKB Annotations" ) );
@@ -1098,8 +1154,9 @@ public final class MainFrameApplication extends MainFrame {
         if ( ( _mainpanel.getCurrentPhylogeny() == null ) || ( _mainpanel.getCurrentPhylogeny().isEmpty() ) ) {
             return;
         }
-        final MainPanelEdit a = new MainPanelEdit( this, _mainpanel.getCurrentTreePanel(), _mainpanel
-                .getCurrentPhylogeny() );
+        final GoAnnotation a = new GoAnnotation( this,
+                                                 _mainpanel.getCurrentTreePanel(),
+                                                 _mainpanel.getCurrentPhylogeny() );
         new Thread( a ).start();
     }
 
@@ -1114,9 +1171,10 @@ public final class MainFrameApplication extends MainFrame {
                                            JOptionPane.ERROR_MESSAGE );
             return;
         }
-        final Phylogeny phy = _mainpanel.getCurrentPhylogeny().copy();
-        final AncestralTaxonomyInferrer inferrer = new AncestralTaxonomyInferrer( this, _mainpanel
-                .getCurrentTreePanel(), phy );
+        final AncestralTaxonomyInferrer inferrer = new AncestralTaxonomyInferrer( this,
+                                                                                  _mainpanel.getCurrentTreePanel(),
+                                                                                  _mainpanel.getCurrentPhylogeny()
+                                                                                          .copy() );
         new Thread( inferrer ).start();
     }
 
@@ -1130,8 +1188,7 @@ public final class MainFrameApplication extends MainFrame {
                 if ( getMsa() != null ) {
                     final PhylogeneticInferrer inferrer = new PhylogeneticInferrer( getMsa(),
                                                                                     getPhylogeneticInferenceOptions()
-                                                                                            .copy(),
-                                                                                    this );
+                                                                                            .copy(), this );
                     new Thread( inferrer ).start();
                 }
                 else {
@@ -1145,8 +1202,7 @@ public final class MainFrameApplication extends MainFrame {
                 if ( getSeqs() != null ) {
                     final PhylogeneticInferrer inferrer = new PhylogeneticInferrer( getSeqs(),
                                                                                     getPhylogeneticInferenceOptions()
-                                                                                            .copy(),
-                                                                                    this );
+                                                                                            .copy(), this );
                     new Thread( inferrer ).start();
                 }
                 else {
@@ -1281,7 +1337,7 @@ public final class MainFrameApplication extends MainFrame {
     }
 
     @Override
-    MainPanel getMainPanel() {
+    public MainPanel getMainPanel() {
         return _mainpanel;
     }
 
@@ -1374,13 +1430,39 @@ public final class MainFrameApplication extends MainFrame {
         if ( getCurrentTreePanel() != null ) {
             final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
             if ( ( phy != null ) && !phy.isEmpty() ) {
-                final TaxonomyDataObtainer t = new TaxonomyDataObtainer( this, _mainpanel.getCurrentTreePanel(), phy
-                        .copy() );
+                final TaxonomyDataObtainer t = new TaxonomyDataObtainer( this,
+                                                                         _mainpanel.getCurrentTreePanel(),
+                                                                         phy.copy() );
                 new Thread( t ).start();
             }
         }
     }
 
+    private void obtainDetailedTaxonomicInformationDelete() {
+        if ( getCurrentTreePanel() != null ) {
+            final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
+            if ( ( phy != null ) && !phy.isEmpty() ) {
+                final TaxonomyDataObtainer t = new TaxonomyDataObtainer( this,
+                                                                         _mainpanel.getCurrentTreePanel(),
+                                                                         phy.copy(),
+                                                                         true );
+                new Thread( t ).start();
+            }
+        }
+    }
+
+    private void obtainUniProtSequenceInformation() {
+        if ( getCurrentTreePanel() != null ) {
+            final Phylogeny phy = getCurrentTreePanel().getPhylogeny();
+            if ( ( phy != null ) && !phy.isEmpty() ) {
+                final SequenceDataRetriver u = new SequenceDataRetriver( this,
+                                                                         _mainpanel.getCurrentTreePanel(),
+                                                                         phy.copy() );
+                new Thread( u ).start();
+            }
+        }
+    }
+
     private void print() {
         if ( ( getCurrentTreePanel() == null ) || ( getCurrentTreePanel().getPhylogeny() == null )
                 || getCurrentTreePanel().getPhylogeny().isEmpty() ) {
@@ -1602,7 +1684,7 @@ public final class MainFrameApplication extends MainFrame {
                         try {
                             final NHXParser nhx = new NHXParser();
                             setSpecialOptionsForNhxParser( nhx );
-                            phys = Util.readPhylogenies( nhx, file );
+                            phys = ForesterUtil.readPhylogenies( nhx, file );
                             nhx_or_nexus = true;
                         }
                         catch ( final Exception e ) {
@@ -1614,7 +1696,7 @@ public final class MainFrameApplication extends MainFrame {
                         warnIfNotPhyloXmlValidation( getConfiguration() );
                         try {
                             final PhyloXmlParser xml_parser = createPhyloXmlParser();
-                            phys = Util.readPhylogenies( xml_parser, file );
+                            phys = ForesterUtil.readPhylogenies( xml_parser, file );
                         }
                         catch ( final Exception e ) {
                             exception = true;
@@ -1623,7 +1705,7 @@ public final class MainFrameApplication extends MainFrame {
                     }
                     else if ( _open_filechooser.getFileFilter() == MainFrameApplication.tolfilter ) {
                         try {
-                            phys = Util.readPhylogenies( new TolParser(), file );
+                            phys = ForesterUtil.readPhylogenies( new TolParser(), file );
                         }
                         catch ( final Exception e ) {
                             exception = true;
@@ -1634,7 +1716,7 @@ public final class MainFrameApplication extends MainFrame {
                         try {
                             final NexusPhylogeniesParser nex = new NexusPhylogeniesParser();
                             setSpecialOptionsForNexParser( nex );
-                            phys = Util.readPhylogenies( nex, file );
+                            phys = ForesterUtil.readPhylogenies( nex, file );
                             nhx_or_nexus = true;
                         }
                         catch ( final Exception e ) {
@@ -1661,7 +1743,7 @@ public final class MainFrameApplication extends MainFrame {
                             else if ( parser instanceof PhyloXmlParser ) {
                                 warnIfNotPhyloXmlValidation( getConfiguration() );
                             }
-                            phys = Util.readPhylogenies( parser, file );
+                            phys = ForesterUtil.readPhylogenies( parser, file );
                         }
                         catch ( final Exception e ) {
                             exception = true;
@@ -1710,7 +1792,7 @@ public final class MainFrameApplication extends MainFrame {
         System.gc();
     }
 
-    void readSeqsFromFile() {
+    public void readSeqsFromFile() {
         // Set an initial directory if none set yet
         final File my_dir = getCurrentDir();
         _seqs_filechooser.setMultiSelectionEnabled( false );
@@ -1817,7 +1899,7 @@ public final class MainFrameApplication extends MainFrame {
         }
     }
 
-    void readMsaFromFile() {
+    public void readMsaFromFile() {
         // Set an initial directory if none set yet
         final File my_dir = getCurrentDir();
         _msa_filechooser.setMultiSelectionEnabled( false );
@@ -1991,8 +2073,11 @@ public final class MainFrameApplication extends MainFrame {
                         ForesterUtil.transferInternalNodeNamesToConfidence( phy );
                     }
                 }
-                Util.addPhylogeniesToTabs( phys, new File( url.getFile() ).getName(), new File( url.getFile() )
-                        .toString(), getConfiguration(), getMainPanel() );
+                Util.addPhylogeniesToTabs( phys,
+                                           new File( url.getFile() ).getName(),
+                                           new File( url.getFile() ).toString(),
+                                           getConfiguration(),
+                                           getMainPanel() );
                 _mainpanel.getControlPanel().showWhole();
             }
         }
@@ -2013,7 +2098,7 @@ public final class MainFrameApplication extends MainFrame {
         if ( ( file != null ) && ( result == JFileChooser.APPROVE_OPTION ) ) {
             if ( _open_filechooser_for_species_tree.getFileFilter() == MainFrameApplication.xmlfilter ) {
                 try {
-                    final Phylogeny[] trees = Util.readPhylogenies( new PhyloXmlParser(), file );
+                    final Phylogeny[] trees = ForesterUtil.readPhylogenies( new PhyloXmlParser(), file );
                     t = trees[ 0 ];
                 }
                 catch ( final Exception e ) {
@@ -2023,7 +2108,7 @@ public final class MainFrameApplication extends MainFrame {
             }
             else if ( _open_filechooser_for_species_tree.getFileFilter() == MainFrameApplication.tolfilter ) {
                 try {
-                    final Phylogeny[] trees = Util.readPhylogenies( new TolParser(), file );
+                    final Phylogeny[] trees = ForesterUtil.readPhylogenies( new TolParser(), file );
                     t = trees[ 0 ];
                 }
                 catch ( final Exception e ) {
@@ -2034,7 +2119,7 @@ public final class MainFrameApplication extends MainFrame {
             // "*.*":
             else {
                 try {
-                    final Phylogeny[] trees = Util.readPhylogenies( new PhyloXmlParser(), file );
+                    final Phylogeny[] trees = ForesterUtil.readPhylogenies( new PhyloXmlParser(), file );
                     t = trees[ 0 ];
                 }
                 catch ( final Exception e ) {
@@ -2343,6 +2428,7 @@ public final class MainFrameApplication extends MainFrame {
                 }
             }
             if ( !exception ) {
+                getMainPanel().setTitleOfSelectedTab( file.getName() );
                 getMainPanel().getCurrentTreePanel().setTreeFile( file );
                 getMainPanel().getCurrentTreePanel().setEdited( false );
             }
@@ -2476,7 +2562,7 @@ public final class MainFrameApplication extends MainFrame {
         return _phylogenetic_inference_options;
     }
 
-    Msa getMsa() {
+    public Msa getMsa() {
         return _msa;
     }
 
@@ -2488,11 +2574,11 @@ public final class MainFrameApplication extends MainFrame {
         _msa_file = msa_file;
     }
 
-    File getMsaFile() {
+    public File getMsaFile() {
         return _msa_file;
     }
 
-    List<Sequence> getSeqs() {
+    public List<Sequence> getSeqs() {
         return _seqs;
     }
 
@@ -2504,7 +2590,7 @@ public final class MainFrameApplication extends MainFrame {
         _seqs_file = seqs_file;
     }
 
-    File getSeqsFile() {
+    public File getSeqsFile() {
         return _seqs_file;
     }
 } // MainFrameApplication.
@@ -2574,8 +2660,7 @@ class TolFilter extends FileFilter {
     public boolean accept( final File f ) {
         final String file_name = f.getName().trim().toLowerCase();
         return ( file_name.endsWith( ".tol" ) || file_name.endsWith( ".tolxml" ) || file_name.endsWith( ".zip" ) || f
-                .isDirectory() )
-                && ( !file_name.endsWith( ".xml.zip" ) );
+                .isDirectory() ) && ( !file_name.endsWith( ".xml.zip" ) );
     }
 
     @Override