(no commit message)
[jalview.git] / forester / java / src / org / forester / archaeopteryx / ControlPanel.java
index 789edcc..26d5c6b 100644 (file)
@@ -81,6 +81,7 @@ final class ControlPanel extends JPanel implements ActionListener {
                                                                                     Font.PLAIN,
                                                                                     9 );
     private static final String               RETURN_TO_SUPER_TREE_TEXT = "Back to Super Tree";
+    private static final String               SEARCH_TIP_TEXT           = "Enter text to search for. Use ',' for logical OR and '+' for logical AND (not used in this manner for regular expression searches).";
     private static final long                 serialVersionUID          = -8463483932821545633L;
     private NodeClickAction                   _action_when_node_clicked;
     private int                               _add_new_node_item;
@@ -125,7 +126,7 @@ final class ControlPanel extends JPanel implements ActionListener {
     private int                               _paste_subtree_item;
     private int                               _reroot_cb_item;
     private JButton                           _return_to_super_tree;
-    // Search 
+    // Search
     private JLabel                            _search_found_label_0;
     private JLabel                            _search_found_label_1;
     private JButton                           _search_reset_button_0;
@@ -251,6 +252,7 @@ final class ControlPanel extends JPanel implements ActionListener {
                     displayedPhylogenyMightHaveChanged( false );
                 }
                 else if ( e.getSource() == _show_whole ) {
+                    displayedPhylogenyMightHaveChanged( true );
                     showWhole();
                 }
                 else if ( e.getSource() == _return_to_super_tree ) {
@@ -258,14 +260,12 @@ final class ControlPanel extends JPanel implements ActionListener {
                     showWhole();
                 }
                 else if ( e.getSource() == _order ) {
-                    DESCENDANT_SORT_PRIORITY pri = DESCENDANT_SORT_PRIORITY.TAXONOMY;
-                    if ( ( !isShowTaxonomyScientificNames() && !isShowTaxonomyCode() && !isShowTaxonomyCommonNames() ) ) {
-                        if ( ( isShowSequenceAcc() || isShowSeqNames() || isShowSeqSymbols() ) ) {
-                            pri = DESCENDANT_SORT_PRIORITY.SEQUENCE;
-                        }
-                        else if ( isShowNodeNames() ) {
-                            pri = DESCENDANT_SORT_PRIORITY.NODE_NAME;
-                        }
+                    DESCENDANT_SORT_PRIORITY pri = DESCENDANT_SORT_PRIORITY.NODE_NAME;
+                    if ( isShowTaxonomyScientificNames() || isShowTaxonomyCode() ) {
+                        pri = DESCENDANT_SORT_PRIORITY.TAXONOMY;
+                    }
+                    else if ( isShowSeqNames() || isShowSeqSymbols() || isShowGeneNames() ) {
+                        pri = DESCENDANT_SORT_PRIORITY.SEQUENCE;
                     }
                     PhylogenyMethods.orderAppearance( tp.getPhylogeny().getRoot(), _order_of_appearance, true, pri );
                     _order_of_appearance = !_order_of_appearance;
@@ -275,7 +275,7 @@ final class ControlPanel extends JPanel implements ActionListener {
                     tp.getPhylogeny().recalculateNumberOfExternalDescendants( true );
                     tp.resetNodeIdToDistToLeafMap();
                     tp.setEdited( true );
-                    displayedPhylogenyMightHaveChanged( false );
+                    displayedPhylogenyMightHaveChanged( true );
                 }
                 else if ( e.getSource() == _uncollapse_all ) {
                     uncollapseAll( tp );
@@ -766,7 +766,7 @@ final class ControlPanel extends JPanel implements ActionListener {
 
     /**
      * Indicates what action should be execute when a node is clicked
-     * 
+     *
      * @return the click-on action
      */
     NodeClickAction getActionWhenNodeClicked() {
@@ -1362,14 +1362,13 @@ final class ControlPanel extends JPanel implements ActionListener {
     }
 
     void setupSearchTools0() {
-        final String tip = "Enter text to search for. Use ',' for multiple searches (logical OR) and '+' for logical AND.";
         final JLabel search_label = new JLabel( "Search (A):" );
         search_label.setFont( ControlPanel.jcb_bold_font );
         if ( !getConfiguration().isUseNativeUI() ) {
             search_label.setForeground( getConfiguration().getGuiCheckboxTextColor() );
         }
         add( search_label );
-        search_label.setToolTipText( tip );
+        search_label.setToolTipText( SEARCH_TIP_TEXT );
         _search_found_label_0 = new JLabel();
         getSearchFoundCountsLabel0().setVisible( false );
         _search_found_label_0.setFont( ControlPanel.jcb_bold_font );
@@ -1377,7 +1376,7 @@ final class ControlPanel extends JPanel implements ActionListener {
             _search_found_label_0.setForeground( getConfiguration().getGuiCheckboxTextColor() );
         }
         _search_tf_0 = new JTextField( 3 );
-        _search_tf_0.setToolTipText( tip );
+        _search_tf_0.setToolTipText( SEARCH_TIP_TEXT );
         _search_tf_0.setEditable( true );
         if ( !getConfiguration().isUseNativeUI() ) {
             _search_tf_0.setForeground( getConfiguration().getGuiMenuBackgroundColor() );
@@ -1423,14 +1422,13 @@ final class ControlPanel extends JPanel implements ActionListener {
     }
 
     void setupSearchTools1() {
-        final String tip = "Enter text to search for. Use ',' for multiple searches (logical OR) and '+' for logical AND.";
         final JLabel search_label = new JLabel( "Search (B):" );
         search_label.setFont( ControlPanel.jcb_bold_font );
         if ( !getConfiguration().isUseNativeUI() ) {
             search_label.setForeground( getConfiguration().getGuiCheckboxTextColor() );
         }
         add( search_label );
-        search_label.setToolTipText( tip );
+        search_label.setToolTipText( SEARCH_TIP_TEXT );
         _search_found_label_1 = new JLabel();
         getSearchFoundCountsLabel1().setVisible( false );
         _search_found_label_1.setFont( ControlPanel.jcb_bold_font );
@@ -1438,7 +1436,7 @@ final class ControlPanel extends JPanel implements ActionListener {
             _search_found_label_1.setForeground( getConfiguration().getGuiCheckboxTextColor() );
         }
         _search_tf_1 = new JTextField( 3 );
-        _search_tf_1.setToolTipText( tip );
+        _search_tf_1.setToolTipText( SEARCH_TIP_TEXT );
         _search_tf_1.setEditable( true );
         if ( !getConfiguration().isUseNativeUI() ) {
             _search_tf_1.setForeground( getConfiguration().getGuiMenuBackgroundColor() );
@@ -1512,16 +1510,14 @@ final class ControlPanel extends JPanel implements ActionListener {
         _mainpanel.getCurrentTreePanel().validate();
         _mainpanel.validate();
         _mainpanel.getCurrentTreePanel().calcParametersForPainting( _mainpanel.getSizeOfViewport().width,
-                                                                    _mainpanel.getSizeOfViewport().height,
-                                                                    true );
+                                                                    _mainpanel.getSizeOfViewport().height );
         _mainpanel.getCurrentTreePanel().resetPreferredSize();
         _mainpanel.adjustJScrollPane();
         _mainpanel.getCurrentTreePanel().repaint();
         _mainpanel.getCurrentTreePanel().validate();
         _mainpanel.validate();
         _mainpanel.getCurrentTreePanel().calcParametersForPainting( _mainpanel.getSizeOfViewport().width,
-                                                                    _mainpanel.getSizeOfViewport().height,
-                                                                    true );
+                                                                    _mainpanel.getSizeOfViewport().height );
         _mainpanel.getCurrentTreePanel().resetPreferredSize();
         _mainpanel.adjustJScrollPane();
         _mainpanel.getCurrentTreePanel().repaint();
@@ -1533,8 +1529,7 @@ final class ControlPanel extends JPanel implements ActionListener {
             if ( tree_panel != null ) {
                 tree_panel.validate();
                 tree_panel.calcParametersForPainting( _mainpanel.getSizeOfViewport().width,
-                                                      _mainpanel.getSizeOfViewport().height,
-                                                      true );
+                                                      _mainpanel.getSizeOfViewport().height );
                 tree_panel.resetPreferredSize();
                 tree_panel.repaint();
             }
@@ -1809,7 +1804,7 @@ final class ControlPanel extends JPanel implements ActionListener {
         getSearchResetButton0().setVisible( true );
         String[] queries = null;
         List<PhylogenyNode> nodes = null;
-        if ( query_str.indexOf( ',' ) >= 0 ) {
+        if ( ( query_str.indexOf( ',' ) >= 0 ) && !getOptions().isSearchWithRegex() ) {
             queries = query_str.split( ",+" );
         }
         else {
@@ -1823,7 +1818,7 @@ final class ControlPanel extends JPanel implements ActionListener {
                     continue;
                 }
                 query = query.trim();
-                if ( query.indexOf( '+' ) >= 0 ) {
+                if ( ( query.indexOf( '+' ) >= 0 ) && !getOptions().isSearchWithRegex() ) {
                     nodes.addAll( PhylogenyMethods.searchDataLogicalAnd( query.split( "\\++" ),
                                                                          tree,
                                                                          getOptions().isSearchCaseSensitive(),
@@ -1835,6 +1830,7 @@ final class ControlPanel extends JPanel implements ActionListener {
                                                                tree,
                                                                getOptions().isSearchCaseSensitive(),
                                                                !getOptions().isMatchWholeTermsOnly(),
+                                                               getOptions().isSearchWithRegex(),
                                                                isShowDomainArchitectures() ) );
                 }
             }
@@ -1863,7 +1859,7 @@ final class ControlPanel extends JPanel implements ActionListener {
         getSearchResetButton1().setVisible( true );
         String[] queries = null;
         List<PhylogenyNode> nodes = null;
-        if ( query_str.indexOf( ',' ) >= 0 ) {
+        if ( ( query_str.indexOf( ',' ) >= 0 ) && !getOptions().isSearchWithRegex() ) {
             queries = query_str.split( ",+" );
         }
         else {
@@ -1877,7 +1873,7 @@ final class ControlPanel extends JPanel implements ActionListener {
                     continue;
                 }
                 query = query.trim();
-                if ( query.indexOf( '+' ) >= 0 ) {
+                if ( ( query.indexOf( '+' ) >= 0 ) && !getOptions().isSearchWithRegex() ) {
                     nodes.addAll( PhylogenyMethods.searchDataLogicalAnd( query.split( "\\++" ),
                                                                          tree,
                                                                          getOptions().isSearchCaseSensitive(),
@@ -1889,6 +1885,7 @@ final class ControlPanel extends JPanel implements ActionListener {
                                                                tree,
                                                                getOptions().isSearchCaseSensitive(),
                                                                !getOptions().isMatchWholeTermsOnly(),
+                                                               getOptions().isSearchWithRegex(),
                                                                isShowDomainArchitectures() ) );
                 }
             }
@@ -2305,122 +2302,138 @@ final class ControlPanel extends JPanel implements ActionListener {
 
     private void setVisibilityOfDomainStrucureControls() {
         if ( _zoom_in_domain_structure != null ) {
-            if ( isShowDomainArchitectures() ) {
-                _domain_display_label.setVisible( true );
-                _zoom_in_domain_structure.setVisible( true );
-                _zoom_out_domain_structure.setVisible( true );
-                _decr_domain_structure_evalue_thr.setVisible( true );
-                _incr_domain_structure_evalue_thr.setVisible( true );
-                _domain_structure_evalue_thr_tf.setVisible( true );
-                if ( getMainPanel().getMainFrame()._right_line_up_domains_cbmi != null ) {
-                    getMainPanel().getMainFrame()._right_line_up_domains_cbmi.setVisible( true );
+            final MainFrame mf = getMainFrame();
+            if ( mf != null ) {
+                if ( isShowDomainArchitectures() ) {
+                    _domain_display_label.setVisible( true );
+                    _zoom_in_domain_structure.setVisible( true );
+                    _zoom_out_domain_structure.setVisible( true );
+                    _decr_domain_structure_evalue_thr.setVisible( true );
+                    _incr_domain_structure_evalue_thr.setVisible( true );
+                    _domain_structure_evalue_thr_tf.setVisible( true );
+                    if ( mf._right_line_up_domains_cbmi != null ) {
+                        mf._right_line_up_domains_cbmi.setVisible( true );
+                    }
+                    if ( mf._show_domain_labels != null ) {
+                        mf._show_domain_labels.setVisible( true );
+                    }
                 }
-                if ( getMainPanel().getMainFrame()._show_domain_labels != null ) {
-                    getMainPanel().getMainFrame()._show_domain_labels.setVisible( true );
+                else {
+                    _domain_display_label.setVisible( false );
+                    _zoom_in_domain_structure.setVisible( false );
+                    _zoom_out_domain_structure.setVisible( false );
+                    _decr_domain_structure_evalue_thr.setVisible( false );
+                    _incr_domain_structure_evalue_thr.setVisible( false );
+                    _domain_structure_evalue_thr_tf.setVisible( false );
+                    if ( mf._right_line_up_domains_cbmi != null ) {
+                        mf._right_line_up_domains_cbmi.setVisible( false );
+                    }
+                    if ( mf._show_domain_labels != null ) {
+                        mf._show_domain_labels.setVisible( false );
+                    }
                 }
             }
-            else {
-                _domain_display_label.setVisible( false );
-                _zoom_in_domain_structure.setVisible( false );
-                _zoom_out_domain_structure.setVisible( false );
-                _decr_domain_structure_evalue_thr.setVisible( false );
-                _incr_domain_structure_evalue_thr.setVisible( false );
-                _domain_structure_evalue_thr_tf.setVisible( false );
-                if ( getMainPanel().getMainFrame()._right_line_up_domains_cbmi != null ) {
-                    getMainPanel().getMainFrame()._right_line_up_domains_cbmi.setVisible( false );
-                }
-                if ( getMainPanel().getMainFrame()._show_domain_labels != null ) {
-                    getMainPanel().getMainFrame()._show_domain_labels.setVisible( false );
-                }
+        }
+    }
+
+    // This takes care of ArchaeopteryxE-issue.
+    // Can, and will, return null prior to  ArchaeopteryxE initialization completion.
+    final private MainFrame getMainFrame() {
+        MainFrame mf = getMainPanel().getMainFrame();
+        if ( mf == null ) {
+            // Must be "E" applet version.
+            final ArchaeopteryxE e = ( ArchaeopteryxE ) ( ( MainPanelApplets ) getMainPanel() ).getApplet();
+            if ( e.getMainPanel() == null ) {
+                return null;
             }
+            mf = e.getMainPanel().getMainFrame();
         }
+        return mf;
     }
 
     void setVisibilityOfX() {
-        try {
+        final MainFrame mf = getMainFrame();
+        if ( mf != null ) {
             if ( ( getCurrentTreePanel() != null ) && ( getCurrentTreePanel().getPhylogeny() != null ) ) {
                 if ( AptxUtil.isHasAtLeastOneBranchWithSupportSD( getCurrentTreePanel().getPhylogeny() ) ) {
-                    if ( getMainPanel().getMainFrame()._show_confidence_stddev_cbmi != null ) {
-                        getMainPanel().getMainFrame()._show_confidence_stddev_cbmi.setVisible( true );
+                    if ( mf._show_confidence_stddev_cbmi != null ) {
+                        mf._show_confidence_stddev_cbmi.setVisible( true );
                     }
                 }
                 else {
-                    if ( getMainPanel().getMainFrame()._show_confidence_stddev_cbmi != null ) {
-                        getMainPanel().getMainFrame()._show_confidence_stddev_cbmi.setVisible( false );
+                    if ( mf._show_confidence_stddev_cbmi != null ) {
+                        mf._show_confidence_stddev_cbmi.setVisible( false );
                     }
                 }
                 if ( AptxUtil.isHasAtLeastOneNodeWithScientificName( getCurrentTreePanel().getPhylogeny() ) ) {
-                    if ( getMainPanel().getMainFrame()._abbreviate_scientific_names != null ) {
-                        getMainPanel().getMainFrame()._abbreviate_scientific_names.setVisible( true );
+                    if ( mf._abbreviate_scientific_names != null ) {
+                        mf._abbreviate_scientific_names.setVisible( true );
                     }
                 }
                 else {
-                    if ( getMainPanel().getMainFrame()._abbreviate_scientific_names != null ) {
-                        getMainPanel().getMainFrame()._abbreviate_scientific_names.setVisible( false );
+                    if ( mf._abbreviate_scientific_names != null ) {
+                        mf._abbreviate_scientific_names.setVisible( false );
                     }
                 }
                 if ( AptxUtil.isHasAtLeastOneNodeWithSequenceAnnotation( getCurrentTreePanel().getPhylogeny() ) ) {
-                    if ( getMainPanel().getMainFrame()._show_annotation_ref_source != null ) {
-                        getMainPanel().getMainFrame()._show_annotation_ref_source.setVisible( true );
+                    if ( mf._show_annotation_ref_source != null ) {
+                        mf._show_annotation_ref_source.setVisible( true );
                     }
                 }
                 else {
-                    if ( getMainPanel().getMainFrame()._show_annotation_ref_source != null ) {
-                        getMainPanel().getMainFrame()._show_annotation_ref_source.setVisible( false );
+                    if ( mf._show_annotation_ref_source != null ) {
+                        mf._show_annotation_ref_source.setVisible( false );
                     }
                 }
             }
             if ( isDrawPhylogram()
                     || ( ( getCurrentTreePanel() != null ) && ( ( getCurrentTreePanel().getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR ) || ( getCurrentTreePanel()
                             .getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) ) ) ) {
-                if ( getMainPanel().getMainFrame()._non_lined_up_cladograms_rbmi != null ) {
-                    getMainPanel().getMainFrame()._non_lined_up_cladograms_rbmi.setVisible( false );
+                if ( mf._non_lined_up_cladograms_rbmi != null ) {
+                    mf._non_lined_up_cladograms_rbmi.setVisible( false );
                 }
-                if ( getMainPanel().getMainFrame()._uniform_cladograms_rbmi != null ) {
-                    getMainPanel().getMainFrame()._uniform_cladograms_rbmi.setVisible( false );
+                if ( mf._uniform_cladograms_rbmi != null ) {
+                    mf._uniform_cladograms_rbmi.setVisible( false );
                 }
-                if ( getMainPanel().getMainFrame()._ext_node_dependent_cladogram_rbmi != null ) {
-                    getMainPanel().getMainFrame()._ext_node_dependent_cladogram_rbmi.setVisible( false );
+                if ( mf._ext_node_dependent_cladogram_rbmi != null ) {
+                    mf._ext_node_dependent_cladogram_rbmi.setVisible( false );
                 }
             }
             else {
-                if ( getMainPanel().getMainFrame()._non_lined_up_cladograms_rbmi != null ) {
-                    getMainPanel().getMainFrame()._non_lined_up_cladograms_rbmi.setVisible( true );
+                if ( mf._non_lined_up_cladograms_rbmi != null ) {
+                    mf._non_lined_up_cladograms_rbmi.setVisible( true );
                 }
-                if ( getMainPanel().getMainFrame()._uniform_cladograms_rbmi != null ) {
-                    getMainPanel().getMainFrame()._uniform_cladograms_rbmi.setVisible( true );
+                if ( mf._uniform_cladograms_rbmi != null ) {
+                    mf._uniform_cladograms_rbmi.setVisible( true );
                 }
-                if ( getMainPanel().getMainFrame()._ext_node_dependent_cladogram_rbmi != null ) {
-                    getMainPanel().getMainFrame()._ext_node_dependent_cladogram_rbmi.setVisible( true );
+                if ( mf._ext_node_dependent_cladogram_rbmi != null ) {
+                    mf._ext_node_dependent_cladogram_rbmi.setVisible( true );
                 }
             }
             if ( isDrawPhylogram() ) {
-                if ( getMainPanel().getMainFrame()._show_scale_cbmi != null ) {
-                    getMainPanel().getMainFrame()._show_scale_cbmi.setVisible( true );
+                if ( mf._show_scale_cbmi != null ) {
+                    mf._show_scale_cbmi.setVisible( true );
                 }
             }
             else {
-                if ( getMainPanel().getMainFrame()._show_scale_cbmi != null ) {
-                    getMainPanel().getMainFrame()._show_scale_cbmi.setVisible( false );
+                if ( mf._show_scale_cbmi != null ) {
+                    mf._show_scale_cbmi.setVisible( false );
                 }
             }
             if ( getCurrentTreePanel() != null ) {
                 if ( ( getCurrentTreePanel().getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR )
                         || ( getCurrentTreePanel().getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED ) ) {
-                    if ( getMainPanel().getMainFrame()._label_direction_cbmi != null ) {
-                        getMainPanel().getMainFrame()._label_direction_cbmi.setVisible( true );
+                    if ( mf._label_direction_cbmi != null ) {
+                        mf._label_direction_cbmi.setVisible( true );
                     }
                 }
                 else {
-                    if ( getMainPanel().getMainFrame()._label_direction_cbmi != null ) {
-                        getMainPanel().getMainFrame()._label_direction_cbmi.setVisible( false );
+                    if ( mf._label_direction_cbmi != null ) {
+                        mf._label_direction_cbmi.setVisible( false );
                     }
                 }
             }
         }
-        catch ( final Exception ignore ) {
-            //not important...
-        }
     }
 
     void setVisibilityOfDomainStrucureCB() {