added a close button
[jalview.git] / forester / java / src / org / forester / archaeopteryx / MainFrame.java
index d91758d..4c85a4a 100644 (file)
@@ -58,6 +58,7 @@ import org.forester.archaeopteryx.AptxUtil.GraphicsExportType;
 import org.forester.archaeopteryx.Options.CLADOGRAM_TYPE;\r
 import org.forester.archaeopteryx.Options.NODE_LABEL_DIRECTION;\r
 import org.forester.archaeopteryx.Options.PHYLOGENY_GRAPHICS_TYPE;\r
+import org.forester.archaeopteryx.tools.AncestralTaxonomyInferrer;\r
 import org.forester.archaeopteryx.tools.InferenceManager;\r
 import org.forester.archaeopteryx.tools.ProcessPool;\r
 import org.forester.archaeopteryx.tools.ProcessRunning;\r
@@ -93,8 +94,8 @@ public abstract class MainFrame extends JFrame implements ActionListener {
     final static SequencesFileFilter seqsfilter                              = new SequencesFileFilter();\r
     final static DefaultFilter       defaultfilter                           = new DefaultFilter();\r
     static final String              USE_MOUSEWHEEL_SHIFT_TO_ROTATE          = "In this display type, use mousewheel + Shift to rotate [or A and S]";\r
-    static final String              PHYLOXML_REF_TOOL_TIP                   = Constants.PHYLOXML_REFERENCE;                                                                                                                                                //TODO //FIXME\r
-    static final String              APTX_REF_TOOL_TIP                       = Constants.APTX_REFERENCE;\r
+    static final String              PHYLOXML_REF_TOOL_TIP                   = AptxConstants.PHYLOXML_REFERENCE;                                                                                                                                                //TODO //FIXME\r
+    static final String              APTX_REF_TOOL_TIP                       = AptxConstants.APTX_REFERENCE;\r
     private static final long        serialVersionUID                        = 3655000897845508358L;\r
     final static Font                menu_font                               = new Font( Configuration.getDefaultFontFamilyName(),\r
                                                                                          Font.PLAIN,\r
@@ -145,6 +146,8 @@ public abstract class MainFrame extends JFrame implements ActionListener {
     static final String              SHOW_BASIC_TREE_INFORMATION_LABEL       = "Basic Tree Information";\r
     static final String              RIGHT_LINE_UP_DOMAINS                   = "Right-align Domain Architectures";\r
     static final String              LINE_UP_RENDERABLE_DATA                 = "Line Up Diagrams (such as Domain Architectures)";\r
+    static final String              INFER_ANCESTOR_TAXONOMIES               = "Infer Ancestor Taxonomies";\r
+    static final String              OBTAIN_DETAILED_TAXONOMIC_INFORMATION   = "Obtain Detailed Taxonomic Information";\r
     JMenuBar                         _jmenubar;\r
     JMenu                            _file_jmenu;\r
     JMenu                            _tools_menu;\r
@@ -250,6 +253,7 @@ public abstract class MainFrame extends JFrame implements ActionListener {
     JCheckBoxMenuItem                _search_whole_words_only_cbmi;\r
     JCheckBoxMenuItem                _inverse_search_result_cbmi;\r
     JCheckBoxMenuItem                _search_with_regex_cbmi;\r
+    JCheckBoxMenuItem                _color_all_found_nodes_when_coloring_subtree_cbmi;\r
     // type menu:\r
     JMenu                            _type_menu;\r
     JCheckBoxMenuItem                _rectangular_type_cbmi;\r
@@ -273,13 +277,12 @@ public abstract class MainFrame extends JFrame implements ActionListener {
     JMenuItem                        _phyloxml_ref_item;\r
     JMenuItem                        _aptx_ref_item;\r
     //\r
-    JFileChooser                     _writetopdf_filechooser;\r
     File                             _current_dir;\r
+    JFileChooser                     _writetopdf_filechooser;\r
     JFileChooser                     _save_filechooser;\r
     JFileChooser                     _writetographics_filechooser;\r
     // process menu:\r
     JMenu                            _process_menu;\r
-    // Handy pointers to child components:\r
     MainPanel                        _mainpanel;\r
     Container                        _contentpane;\r
     final LinkedList<TextFrame>      _textframes                             = new LinkedList<TextFrame>();                                                                                                                                                  ;\r
@@ -293,15 +296,27 @@ public abstract class MainFrame extends JFrame implements ActionListener {
     MainFrame() {\r
         _process_pool = ProcessPool.createInstance();\r
         _writetopdf_filechooser = new JFileChooser();\r
+        _writetopdf_filechooser.setMultiSelectionEnabled( false );\r
+        _writetopdf_filechooser.addChoosableFileFilter( pdffilter );\r
+        _writetographics_filechooser = new JFileChooser();\r
+        _writetographics_filechooser.setMultiSelectionEnabled( false );\r
+        _writetographics_filechooser.addChoosableFileFilter( graphicsfilefilter );\r
         _save_filechooser = new JFileChooser();\r
-        _save_filechooser.setCurrentDirectory( new File( "." ) );\r
         _save_filechooser.setMultiSelectionEnabled( false );\r
         _save_filechooser.setFileFilter( xmlfilter );\r
         _save_filechooser.addChoosableFileFilter( nhfilter );\r
         _save_filechooser.addChoosableFileFilter( nexusfilter );\r
         _save_filechooser.addChoosableFileFilter( _save_filechooser.getAcceptAllFileFilter() );\r
-        _writetographics_filechooser = new JFileChooser();\r
-        _writetographics_filechooser.addChoosableFileFilter( MainFrame.graphicsfilefilter );\r
+        try {\r
+            final String home_dir = System.getProperty( "user.home" );\r
+            _save_filechooser.setCurrentDirectory( new File( home_dir ) );\r
+            _writetopdf_filechooser.setCurrentDirectory( new File( home_dir ) );\r
+            _writetographics_filechooser.setCurrentDirectory( new File( home_dir ) );\r
+        }\r
+        catch ( final Exception e ) {\r
+            e.printStackTrace();\r
+            // Do nothing. Not important.\r
+        }\r
     }\r
 \r
     /**\r
@@ -520,6 +535,9 @@ public abstract class MainFrame extends JFrame implements ActionListener {
             getMainPanel().getControlPanel().search0();\r
             getMainPanel().getControlPanel().search1();\r
         }\r
+        else if ( o == _color_all_found_nodes_when_coloring_subtree_cbmi ) {\r
+            updateOptions( getOptions() );\r
+        }\r
         else if ( o == _show_scale_cbmi ) {\r
             updateOptions( getOptions() );\r
         }\r
@@ -572,42 +590,42 @@ public abstract class MainFrame extends JFrame implements ActionListener {
         }\r
         else if ( o == _help_item ) {\r
             try {\r
-                AptxUtil.openWebsite( Constants.APTX_DOC_SITE, is_applet, applet );\r
+                AptxUtil.openWebsite( AptxConstants.APTX_DOC_SITE, is_applet, applet );\r
             }\r
             catch ( final IOException e1 ) {\r
-                ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );\r
+                ForesterUtil.printErrorMessage( AptxConstants.PRG_NAME, e1.toString() );\r
             }\r
         }\r
         else if ( o == _website_item ) {\r
             try {\r
-                AptxUtil.openWebsite( Constants.APTX_WEB_SITE, is_applet, applet );\r
+                AptxUtil.openWebsite( AptxConstants.APTX_WEB_SITE, is_applet, applet );\r
             }\r
             catch ( final IOException e1 ) {\r
-                ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );\r
+                ForesterUtil.printErrorMessage( AptxConstants.PRG_NAME, e1.toString() );\r
             }\r
         }\r
         else if ( o == _phyloxml_website_item ) {\r
             try {\r
-                AptxUtil.openWebsite( Constants.PHYLOXML_WEB_SITE, is_applet, applet );\r
+                AptxUtil.openWebsite( AptxConstants.PHYLOXML_WEB_SITE, is_applet, applet );\r
             }\r
             catch ( final IOException e1 ) {\r
-                ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );\r
+                ForesterUtil.printErrorMessage( AptxConstants.PRG_NAME, e1.toString() );\r
             }\r
         }\r
         else if ( o == _aptx_ref_item ) {\r
             try {\r
-                AptxUtil.openWebsite( Constants.APTX_REFERENCE_URL, is_applet, applet );\r
+                AptxUtil.openWebsite( AptxConstants.APTX_REFERENCE_URL, is_applet, applet );\r
             }\r
             catch ( final IOException e1 ) {\r
-                ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );\r
+                ForesterUtil.printErrorMessage( AptxConstants.PRG_NAME, e1.toString() );\r
             }\r
         }\r
         else if ( o == _phyloxml_ref_item ) {\r
             try {\r
-                AptxUtil.openWebsite( Constants.PHYLOXML_REFERENCE_URL, is_applet, applet );\r
+                AptxUtil.openWebsite( AptxConstants.PHYLOXML_REFERENCE_URL, is_applet, applet );\r
             }\r
             catch ( final IOException e1 ) {\r
-                ForesterUtil.printErrorMessage( Constants.PRG_NAME, e1.toString() );\r
+                ForesterUtil.printErrorMessage( AptxConstants.PRG_NAME, e1.toString() );\r
             }\r
         }\r
         else if ( o == _write_to_pdf_item ) {\r
@@ -719,6 +737,16 @@ public abstract class MainFrame extends JFrame implements ActionListener {
         else if ( o == _choose_pdf_width_mi ) {\r
             choosePdfWidth();\r
         }\r
+        else if ( o == _lineage_inference ) {\r
+            if ( isSubtreeDisplayed() ) {\r
+                JOptionPane.showMessageDialog( this,\r
+                                               "Subtree is shown.",\r
+                                               "Cannot infer ancestral taxonomies",\r
+                                               JOptionPane.ERROR_MESSAGE );\r
+                return;\r
+            }\r
+            executeLineageInference();\r
+        }\r
         else {\r
             if ( _load_phylogeny_from_webservice_menu_items != null ) {\r
                 for( int i = 0; i < _load_phylogeny_from_webservice_menu_items.length; ++i ) {\r
@@ -1244,10 +1272,10 @@ public abstract class MainFrame extends JFrame implements ActionListener {
                                                                          + "[current values: "\r
                                                                          + getOptions().getPrintSizeX() + ", "\r
                                                                          + getOptions().getPrintSizeY() + "]\n"\r
-                                                                         + "[A4: " + Constants.A4_SIZE_X + ", "\r
-                                                                         + Constants.A4_SIZE_Y + "]\n" + "[US Letter: "\r
-                                                                         + Constants.US_LETTER_SIZE_X + ", "\r
-                                                                         + Constants.US_LETTER_SIZE_Y + "]",\r
+                                                                         + "[A4: " + AptxConstants.A4_SIZE_X + ", "\r
+                                                                         + AptxConstants.A4_SIZE_Y + "]\n" + "[US Letter: "\r
+                                                                         + AptxConstants.US_LETTER_SIZE_X + ", "\r
+                                                                         + AptxConstants.US_LETTER_SIZE_Y + "]",\r
                                                                  "Default Size for Graphics Export",\r
                                                                  JOptionPane.QUESTION_MESSAGE,\r
                                                                  null,\r
@@ -1521,6 +1549,24 @@ public abstract class MainFrame extends JFrame implements ActionListener {
         }\r
     }\r
 \r
+    void executeLineageInference() {\r
+        if ( ( _mainpanel.getCurrentPhylogeny() == null ) || ( _mainpanel.getCurrentPhylogeny().isEmpty() ) ) {\r
+            return;\r
+        }\r
+        if ( !_mainpanel.getCurrentPhylogeny().isRooted() ) {\r
+            JOptionPane.showMessageDialog( this,\r
+                                           "Phylogeny is not rooted.",\r
+                                           "Cannot infer ancestral taxonomies",\r
+                                           JOptionPane.ERROR_MESSAGE );\r
+            return;\r
+        }\r
+        final AncestralTaxonomyInferrer inferrer = new AncestralTaxonomyInferrer( this,\r
+                                                                                  _mainpanel.getCurrentTreePanel(),\r
+                                                                                  _mainpanel.getCurrentPhylogeny()\r
+                                                                                          .copy() );\r
+        new Thread( inferrer ).start();\r
+    }\r
+\r
     boolean GAndSDoHaveMoreThanOneSpeciesInComman( final Phylogeny gene_tree ) {\r
         if ( ( gene_tree == null ) || gene_tree.isEmpty() ) {\r
             JOptionPane.showMessageDialog( this,\r
@@ -1928,6 +1974,9 @@ public abstract class MainFrame extends JFrame implements ActionListener {
         if ( ( _line_up_renderable_data_cbmi != null ) && _line_up_renderable_data_cbmi.isEnabled() ) {\r
             options.setLineUpRendarableNodeData( _line_up_renderable_data_cbmi.isSelected() );\r
         }\r
+        if ( ( _color_all_found_nodes_when_coloring_subtree_cbmi != null ) && _color_all_found_nodes_when_coloring_subtree_cbmi.isEnabled() ) {\r
+            options.setColorAllFoundNodesWhenColoringSubtree( _color_all_found_nodes_when_coloring_subtree_cbmi.isSelected() );\r
+        }\r
     }\r
 \r
     void updateTypeCheckboxes( final Options options, final Object o ) {\r
@@ -2007,11 +2056,11 @@ public abstract class MainFrame extends JFrame implements ActionListener {
      * Display the about box.\r
      */\r
     static void about() {\r
-        final StringBuffer about = new StringBuffer( "Archaeopteryx\nVersion " + Constants.VERSION + "\n" );\r
-        about.append( "Copyright (C) 2014 Christian M Zmasek\n" );\r
+        final StringBuffer about = new StringBuffer( "Archaeopteryx\nVersion " + AptxConstants.VERSION + "\n" );\r
+        about.append( "Copyright (C) 2016 Christian M Zmasek\n" );\r
         about.append( "All Rights Reserved\n" );\r
         about.append( "License: GNU Lesser General Public License (LGPL)\n" );\r
-        about.append( "Last modified: " + Constants.PRG_DATE + "\n" );\r
+        about.append( "Last modified: " + AptxConstants.PRG_DATE + "\n" );\r
         about.append( "Based on: " + ForesterUtil.getForesterLibraryInformation() + "\n" );\r
         about.append( "phyloXML version : " + ForesterConstants.PHYLO_XML_VERSION + "\n" );\r
         about.append( "phyloXML location: " + ForesterConstants.PHYLO_XML_LOCATION + "\n" );\r
@@ -2029,13 +2078,13 @@ public abstract class MainFrame extends JFrame implements ActionListener {
         about.append( "[free memory: " + free_memory + "MB, total memory: " + total_memory + "MB]\n" );\r
         about.append( "[locale: " + Locale.getDefault() + "]\n" );\r
         about.append( "References:\n" );\r
-        about.append( Constants.PHYLOXML_REFERENCE_SHORT + "\n" );\r
+        about.append( AptxConstants.PHYLOXML_REFERENCE_SHORT + "\n" );\r
         about.append( "For more information & download:\n" );\r
-        about.append( Constants.APTX_WEB_SITE + "\n" );\r
+        about.append( AptxConstants.APTX_WEB_SITE + "\n" );\r
         about.append( "Documentation:\n" );\r
-        about.append( Constants.APTX_DOC_SITE + "\n" );\r
-        about.append( "Comments: " + Constants.AUTHOR_EMAIL );\r
-        JOptionPane.showMessageDialog( null, about, Constants.PRG_NAME, JOptionPane.PLAIN_MESSAGE );\r
+        about.append( AptxConstants.APTX_DOC_SITE + "\n" );\r
+        about.append( "Comments: " + AptxConstants.AUTHOR_EMAIL );\r
+        JOptionPane.showMessageDialog( null, about, AptxConstants.PRG_NAME, JOptionPane.PLAIN_MESSAGE );\r
     }\r
 \r
     static void chooseNodeSize( final Options options, final Component parent ) {\r
@@ -2168,7 +2217,7 @@ public abstract class MainFrame extends JFrame implements ActionListener {
             tp.resetPreferredSize();\r
             tp.repaint();\r
         }\r
-        final String job_name = Constants.PRG_NAME;\r
+        final String job_name = AptxConstants.PRG_NAME;\r
         boolean error = false;\r
         String printer_name = null;\r
         try {\r
@@ -2440,7 +2489,7 @@ public abstract class MainFrame extends JFrame implements ActionListener {
                     return null;\r
                 }\r
                 else {\r
-                    final File to = new File( file.getAbsoluteFile().toString() + Constants.BACKUP_FILE_SUFFIX );\r
+                    final File to = new File( file.getAbsoluteFile().toString() + AptxConstants.BACKUP_FILE_SUFFIX );\r
                     try {\r
                         ForesterUtil.copyFile( file, to );\r
                     }\r