needs: testing, proper error messages and dialogs, code cleanup, cache mechanism...
[jalview.git] / forester / java / src / org / forester / archaeopteryx / MainFrame.java
index 5e78865..0e8f328 100644 (file)
@@ -116,6 +116,7 @@ public abstract class MainFrame extends JFrame implements ActionListener {
     JMenuItem                 _midpoint_root_item;
     JMenuItem                 _taxcolor_item;
     JMenuItem                 _confcolor_item;
+    JMenuItem                 _color_rank_jmi;
     JMenuItem                 _infer_common_sn_names_item;
     JMenuItem                 _collapse_species_specific_subtrees;
     JMenuItem                 _collapse_below_threshold;                                                                                                                                                                                //TODO implememt me
@@ -231,6 +232,9 @@ public abstract class MainFrame extends JFrame implements ActionListener {
         else if ( o == _confcolor_item ) {
             confColor();
         }
+        else if ( o == _color_rank_jmi ) {
+            colorRank();
+        }
         else if ( o == _infer_common_sn_names_item ) {
             if ( isSubtreeDisplayed() ) {
                 return;
@@ -639,6 +643,30 @@ public abstract class MainFrame extends JFrame implements ActionListener {
         }
     }
 
+    void colorRank() {
+        if ( _mainpanel.getCurrentTreePanel() != null ) {
+            final String[] ranks = Util.getAllRanks( _mainpanel.getCurrentTreePanel().getPhylogeny() );
+            if ( ranks.length < 1 ) {
+                JOptionPane.showMessageDialog( this,
+                                               "No rank information was found",
+                                               "No Rank Inoformation",
+                                               JOptionPane.WARNING_MESSAGE );
+                return;
+            }
+            final String rank = ( String ) JOptionPane
+                    .showInputDialog( this,
+                                      "What rank should the colorization be based on",
+                                      "Rank Selection",
+                                      JOptionPane.PLAIN_MESSAGE,
+                                      null,
+                                      ranks,
+                                      null );
+            if ( !ForesterUtil.isEmpty( rank ) ) {
+                _mainpanel.getCurrentTreePanel().colorRank( rank );
+            }
+        }
+    }
+
     void customizeCheckBoxMenuItem( final JCheckBoxMenuItem item, final boolean is_selected ) {
         if ( item != null ) {
             item.setFont( MainFrame.menu_font );