1st fix of embedded applet null pointer "issue"... ^^
[jalview.git] / forester / java / src / org / forester / archaeopteryx / ControlPanel.java
index 8a15e5a..d7df705 100644 (file)
@@ -61,9 +61,11 @@ import org.forester.archaeopteryx.Options.CLADOGRAM_TYPE;
 import org.forester.archaeopteryx.Options.PHYLOGENY_GRAPHICS_TYPE;
 import org.forester.phylogeny.Phylogeny;
 import org.forester.phylogeny.PhylogenyMethods;
+import org.forester.phylogeny.PhylogenyMethods.DESCENDANT_SORT_PRIORITY;
 import org.forester.phylogeny.PhylogenyNode;
 import org.forester.phylogeny.data.Sequence;
 import org.forester.phylogeny.data.SequenceRelation;
+import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
 import org.forester.util.ForesterUtil;
 
 final class ControlPanel extends JPanel implements ActionListener {
@@ -87,7 +89,6 @@ final class ControlPanel extends JPanel implements ActionListener {
     private JCheckBox            _show_node_names;
     private JCheckBox            _show_taxo_code;
     private JCheckBox            _write_confidence;
-    private JCheckBox            _write_confidence_sd;
     private JCheckBox            _show_events;
     private JCheckBox            _color_acc_species;
     private JCheckBox            _color_branches_cb;
@@ -125,6 +126,7 @@ final class ControlPanel extends JPanel implements ActionListener {
     private int                  _subtree_cb_item;
     private int                  _color_subtree_cb_item;
     private int                  _open_seq_web_item;
+    private int                  _sort_descendents_item;
     private int                  _open_tax_web_item;
     private int                  _cut_subtree_item;
     private int                  _copy_subtree_item;
@@ -132,6 +134,7 @@ final class ControlPanel extends JPanel implements ActionListener {
     private int                  _paste_subtree_item;
     private int                  _add_new_node_item;
     private int                  _edit_node_data_item;
+    private int                  _get_ext_desc_data;
     private int                  _blast_item;
     // zooming and quick tree manipulation buttons:
     private JButton              _zoom_in_x;
@@ -209,6 +212,10 @@ final class ControlPanel extends JPanel implements ActionListener {
                 }
                 displayedPhylogenyMightHaveChanged( false );
             }
+            else if ( e.getSource() == _show_domain_architectures ) {
+                search();
+                displayedPhylogenyMightHaveChanged( false );
+            }
             else if ( ( tp != null ) && ( tp.getPhylogeny() != null ) ) {
                 if ( e.getSource() == getDisplayAsPhylogramCb() ) {
                     setDrawPhylogram( getDisplayAsPhylogramCb().isSelected() );
@@ -239,8 +246,23 @@ final class ControlPanel extends JPanel implements ActionListener {
                     showWhole();
                 }
                 else if ( e.getSource() == _order ) {
-                    tp.getPhylogeny().orderAppearance( _order_of_appearance );
+                    DESCENDANT_SORT_PRIORITY pri = DESCENDANT_SORT_PRIORITY.TAXONOMY;
+                    if ( ( !isShowTaxonomyScientificNames() && !isShowTaxonomyCode() && !isShowTaxonomyCommonNames() ) ) {
+                        if ( ( isShowSequenceAcc() || isShowGeneNames() || isShowGeneSymbols() ) ) {
+                            pri = DESCENDANT_SORT_PRIORITY.SEQUENCE;
+                        }
+                        else if ( isShowNodeNames() ) {
+                            pri = DESCENDANT_SORT_PRIORITY.NODE_NAME;
+                        }
+                    }
+                    PhylogenyMethods.orderAppearance( tp.getPhylogeny().getRoot(), _order_of_appearance, true, pri );
                     _order_of_appearance = !_order_of_appearance;
+                    tp.setNodeInPreorderToNull();
+                    tp.getPhylogeny().externalNodesHaveChanged();
+                    tp.getPhylogeny().clearHashIdToNodeMap();
+                    tp.getPhylogeny().recalculateNumberOfExternalDescendants( true );
+                    tp.resetNodeIdToDistToLeafMap();
+                    tp.setEdited( true );
                     displayedPhylogenyMightHaveChanged( false );
                 }
                 else if ( e.getSource() == _uncollapse_all ) {
@@ -438,11 +460,6 @@ final class ControlPanel extends JPanel implements ActionListener {
                 addJCheckBox( getWriteConfidenceCb(), ch_panel );
                 add( ch_panel );
                 break;
-            case Configuration.write_confidence_values_sd:
-                _write_confidence_sd = new JCheckBox( title );
-                addJCheckBox( getWriteConfidenceSDCb(), ch_panel );
-                add( ch_panel );
-                break;
             case Configuration.write_events:
                 _show_events = new JCheckBox( title );
                 addJCheckBox( getShowEventsCb(), ch_panel );
@@ -613,7 +630,8 @@ final class ControlPanel extends JPanel implements ActionListener {
     }
 
     void displayedPhylogenyMightHaveChanged( final boolean recalc_longest_ext_node_info ) {
-        if ( ( _mainpanel != null ) && ( _mainpanel.getCurrentPhylogeny() != null ) ) {
+        if ( ( _mainpanel != null )
+                && ( ( _mainpanel.getCurrentPhylogeny() != null ) && !_mainpanel.getCurrentPhylogeny().isEmpty() ) ) {
             if ( getOptions().isShowOverview() ) {
                 _mainpanel.getCurrentTreePanel().updateOvSizes();
             }
@@ -762,10 +780,6 @@ final class ControlPanel extends JPanel implements ActionListener {
         return _write_confidence;
     }
 
-    public JCheckBox getWriteConfidenceSDCb() {
-        return _write_confidence_sd;
-    }
-
     private void init() {
         _draw_phylogram = new ArrayList<Boolean>();
         setSpeciesColors( new HashMap<String, Color>() );
@@ -824,10 +838,6 @@ final class ControlPanel extends JPanel implements ActionListener {
         return ( ( getWriteConfidenceCb() != null ) && getWriteConfidenceCb().isSelected() );
     }
 
-    boolean isShowConfidenceSDValues() {
-        return ( ( getWriteConfidenceSDCb() != null ) && getWriteConfidenceSDCb().isSelected() );
-    }
-
     boolean isShowDomainArchitectures() {
         return ( ( _show_domain_architectures != null ) && _show_domain_architectures.isSelected() );
     }
@@ -944,14 +954,18 @@ final class ControlPanel extends JPanel implements ActionListener {
                 }
                 query = query.trim();
                 if ( query.indexOf( '+' ) >= 0 ) {
-                    nodes.addAll( PhylogenyMethods.searchDataLogicalAnd( query.split( "\\++" ), tree, getOptions()
-                            .isSearchCaseSensitive(), !getOptions().isMatchWholeTermsOnly() ) );
+                    nodes.addAll( PhylogenyMethods.searchDataLogicalAnd( query.split( "\\++" ),
+                                                                         tree,
+                                                                         getOptions().isSearchCaseSensitive(),
+                                                                         !getOptions().isMatchWholeTermsOnly(),
+                                                                         isShowDomainArchitectures() ) );
                 }
                 else {
                     nodes.addAll( PhylogenyMethods.searchData( query,
                                                                tree,
                                                                getOptions().isSearchCaseSensitive(),
-                                                               !getOptions().isMatchWholeTermsOnly() ) );
+                                                               !getOptions().isMatchWholeTermsOnly(),
+                                                               isShowDomainArchitectures() ) );
                 }
             }
             if ( getOptions().isInverseSearchResult() ) {
@@ -1054,11 +1068,6 @@ final class ControlPanel extends JPanel implements ActionListener {
                     getWriteConfidenceCb().setSelected( state );
                 }
                 break;
-            case Configuration.write_confidence_values_sd:
-                if ( getWriteConfidenceSDCb() != null ) {
-                    getWriteConfidenceSDCb().setSelected( state );
-                }
-                break;
             case Configuration.write_events:
                 if ( getShowEventsCb() != null ) {
                     getShowEventsCb().setSelected( state );
@@ -1159,10 +1168,11 @@ final class ControlPanel extends JPanel implements ActionListener {
         else if ( action == _open_seq_web_item ) {
             setActionWhenNodeClicked( NodeClickAction.OPEN_SEQ_WEB );
         }
+        else if ( action == _sort_descendents_item ) {
+            setActionWhenNodeClicked( NodeClickAction.SORT_DESCENDENTS );
+        }
         else if ( action == _blast_item ) {
-            if ( !Constants.__RELEASE && !Constants.__SNAPSHOT_RELEASE ) {
-                setActionWhenNodeClicked( NodeClickAction.BLAST );
-            }
+            setActionWhenNodeClicked( NodeClickAction.BLAST );
         }
         else if ( action == _open_tax_web_item ) {
             setActionWhenNodeClicked( NodeClickAction.OPEN_TAX_WEB );
@@ -1185,6 +1195,9 @@ final class ControlPanel extends JPanel implements ActionListener {
         else if ( action == _edit_node_data_item ) {
             setActionWhenNodeClicked( NodeClickAction.EDIT_NODE_DATA );
         }
+        else if ( action == _get_ext_desc_data ) {
+            setActionWhenNodeClicked( NodeClickAction.GET_EXT_DESC_DATA );
+        }
         else {
             throw new RuntimeException( "unknown action: " + action );
         }
@@ -1333,6 +1346,15 @@ final class ControlPanel extends JPanel implements ActionListener {
             }
             cb_index++;
         }
+        if ( _configuration.doDisplayClickToOption( Configuration.sort_descendents ) ) {
+            _sort_descendents_item = cb_index;
+            addClickToOption( Configuration.sort_descendents,
+                              _configuration.getClickToTitle( Configuration.sort_descendents ) );
+            if ( default_option == Configuration.sort_descendents ) {
+                selected_index = cb_index;
+            }
+            cb_index++;
+        }
         if ( _configuration.doDisplayClickToOption( Configuration.color_subtree ) ) {
             _color_subtree_cb_item = cb_index;
             addClickToOption( Configuration.color_subtree, _configuration.getClickToTitle( Configuration.color_subtree ) );
@@ -1357,6 +1379,56 @@ final class ControlPanel extends JPanel implements ActionListener {
             }
             cb_index++;
         }
+        if ( _configuration.doDisplayClickToOption( Configuration.blast ) ) {
+            _blast_item = cb_index;
+            addClickToOption( Configuration.blast, _configuration.getClickToTitle( Configuration.blast ) );
+            if ( default_option == Configuration.blast ) {
+                selected_index = cb_index;
+            }
+            cb_index++;
+        }
+        if ( _configuration.doDisplayClickToOption( Configuration.get_ext_desc_data ) ) {
+            _get_ext_desc_data = cb_index;
+            if ( !ForesterUtil.isEmpty( getConfiguration().getLabelForGetExtDescendentsData() ) ) {
+                addClickToOption( Configuration.get_ext_desc_data, getConfiguration()
+                        .getLabelForGetExtDescendentsData() );
+            }
+            else {
+                String s = ";";
+                switch ( getConfiguration().getExtDescNodeDataToReturn() ) {
+                    case NODE_NAME:
+                        s = "Node Names";
+                        break;
+                    case SEQUENCE_ACC:
+                        s = "Sequence Accessors";
+                        break;
+                    case SEQUENCE_MOL_SEQ:
+                        s = "Molecular Sequence";
+                        break;
+                    case SEQUENCE_NAME:
+                        s = "Sequence Names";
+                        break;
+                    case SEQUENCE_SYMBOL:
+                        s = "Sequence Symbols";
+                        break;
+                    case TAXONOMY_CODE:
+                        s = "Taxonomy Codes";
+                        break;
+                    case TAXONOMY_SCIENTIFIC_NAME:
+                        s = "Scientific Names";
+                        break;
+                    case UNKNOWN:
+                        s = "User Selected Data";
+                        break;
+                }
+                final String label = _configuration.getClickToTitle( Configuration.get_ext_desc_data ) + " " + s;
+                addClickToOption( Configuration.get_ext_desc_data, label );
+            }
+            if ( default_option == Configuration.get_ext_desc_data ) {
+                selected_index = cb_index;
+            }
+            cb_index++;
+        }
         if ( getOptions().isEditable() ) {
             if ( _configuration.doDisplayClickToOption( Configuration.cut_subtree ) ) {
                 _cut_subtree_item = cb_index;
@@ -1411,16 +1483,6 @@ final class ControlPanel extends JPanel implements ActionListener {
                 }
                 cb_index++;
             }
-            if ( !Constants.__RELEASE && !Constants.__SNAPSHOT_RELEASE ) {
-                if ( _configuration.doDisplayClickToOption( Configuration.blast ) ) {
-                    _blast_item = cb_index;
-                    addClickToOption( Configuration.blast, _configuration.getClickToTitle( Configuration.blast ) );
-                    if ( default_option == Configuration.blast ) {
-                        selected_index = cb_index;
-                    }
-                    cb_index++;
-                }
-            }
         }
         // Set default selection and its action
         _click_to_combobox.setSelectedIndex( selected_index );
@@ -1603,10 +1665,6 @@ final class ControlPanel extends JPanel implements ActionListener {
                          _configuration.getDisplayTitle( Configuration.write_confidence_values ) );
             setCheckbox( Configuration.write_confidence_values,
                          _configuration.doCheckOption( Configuration.write_confidence_values ) );
-            addCheckbox( Configuration.write_confidence_values_sd,
-                         _configuration.getDisplayTitle( Configuration.write_confidence_values_sd ) );
-            setCheckbox( Configuration.write_confidence_values_sd,
-                         _configuration.doCheckOption( Configuration.write_confidence_values_sd ) );
         }
         if ( _configuration.doDisplayOption( Configuration.write_events ) ) {
             addCheckbox( Configuration.write_events, _configuration.getDisplayTitle( Configuration.write_events ) );
@@ -1709,10 +1767,11 @@ final class ControlPanel extends JPanel implements ActionListener {
      * Fit entire tree into window.
      */
     void showWhole() {
-        if ( _mainpanel.getCurrentScrollPane() == null ) {
+        if ( ( _mainpanel.getCurrentScrollPane() == null ) || _mainpanel.getCurrentTreePanel().getPhylogeny().isEmpty() ) {
             return;
         }
-        displayedPhylogenyMightHaveChanged( false );
+        getCurrentTreePanel().updateSetOfCollapsedExternalNodes();
+        displayedPhylogenyMightHaveChanged( true );
         _mainpanel.getCurrentTreePanel().updateOvSettings();
         _mainpanel.getCurrentTreePanel().validate();
         _mainpanel.validate();
@@ -1807,8 +1866,15 @@ final class ControlPanel extends JPanel implements ActionListener {
     void uncollapseAll( final TreePanel tp ) {
         final Phylogeny t = tp.getPhylogeny();
         if ( ( t != null ) && !t.isEmpty() ) {
-            t.setAllNodesToNotCollapse();
+            for( final PhylogenyNodeIterator iter = t.iteratorPreorder(); iter.hasNext(); ) {
+                final PhylogenyNode node = iter.next();
+                node.setCollapse( false );
+            }
+            tp.resetNodeIdToDistToLeafMap();
+            tp.updateSetOfCollapsedExternalNodes();
             t.recalculateNumberOfExternalDescendants( false );
+            tp.setNodeInPreorderToNull();
+            t.clearHashIdToNodeMap();
             showWhole();
         }
     }
@@ -1944,6 +2010,8 @@ final class ControlPanel extends JPanel implements ActionListener {
         PASTE_SUBTREE,
         ADD_NEW_NODE,
         EDIT_NODE_DATA,
+        SORT_DESCENDENTS,
+        GET_EXT_DESC_DATA,
         BLAST;
     }
 }