Conservation colour scheme is no more
[jalview.git] / src / jalview / gui / AlignFrame.java
index 3475e7a..fc59062 100755 (executable)
@@ -13,7 +13,7 @@
  * GNU General Public License for more details.\r
  *\r
  * You should have received a copy of the GNU General Public License\r
- * along with this program; if not, write to the Free Software\r
+ * along with this program; if not, write to the Free Softwarechang\r
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA\r
  */\r
 package jalview.gui;\r
@@ -1371,66 +1371,50 @@ public class AlignFrame
   {\r
     int threshold = 0;\r
 \r
-    if (viewport.getAbovePIDThreshold())\r
+    if(cs!=null)\r
     {\r
-      threshold = SliderPanel.setPIDSliderSource(alignPanel, cs,\r
-                                                 "Background");\r
-\r
-      if (cs instanceof ResidueColourScheme)\r
+      if (viewport.getAbovePIDThreshold())\r
       {\r
-        ( (ResidueColourScheme) cs).setThreshold(threshold,\r
-                                                 viewport.\r
-                                                 getIgnoreGapsConsensus());\r
+        threshold = SliderPanel.setPIDSliderSource(alignPanel, cs,\r
+                                                   "Background");\r
+\r
+        cs.setThreshold(threshold,\r
+                        viewport.getIgnoreGapsConsensus());\r
+\r
+        viewport.setGlobalColourScheme(cs);\r
       }\r
-      else if (cs instanceof ScoreColourScheme)\r
+      else\r
       {\r
-        ( (ScoreColourScheme) cs).setThreshold(threshold,\r
-                                               viewport.getIgnoreGapsConsensus());\r
+        cs.setThreshold(0, viewport.getIgnoreGapsConsensus());\r
       }\r
 \r
-      viewport.setGlobalColourScheme(cs);\r
-    }\r
-    else if (cs instanceof ResidueColourScheme)\r
-    {\r
-      ( (ResidueColourScheme) cs).setThreshold(0,\r
-                                               viewport.getIgnoreGapsConsensus());\r
-    }\r
-    else if (cs instanceof ScoreColourScheme)\r
-    {\r
-      ( (ScoreColourScheme) cs).setThreshold(0, viewport.getIgnoreGapsConsensus());\r
-    }\r
-\r
-    if (viewport.getConservationSelected())\r
-    {\r
-      ConservationColourScheme ccs = null;\r
-\r
-      Alignment al = (Alignment) viewport.alignment;\r
-      Conservation c = new Conservation("All",\r
-                                        ResidueProperties.propHash, 3,\r
-                                        al.getSequences(), 0,\r
-                                        al.getWidth() - 1);\r
+      if (viewport.getConservationSelected())\r
+      {\r
 \r
-      c.calculate();\r
-      c.verdict(false, viewport.ConsPercGaps);\r
+        Alignment al = (Alignment) viewport.alignment;\r
+        Conservation c = new Conservation("All",\r
+                                          ResidueProperties.propHash, 3,\r
+                                          al.getSequences(), 0,\r
+                                          al.getWidth() - 1);\r
 \r
-      ccs = new ConservationColourScheme(c, cs);\r
+        c.calculate();\r
+        c.verdict(false, viewport.ConsPercGaps);\r
 \r
-      viewport.setGlobalColourScheme(ccs);\r
+        cs.setConservation(c);\r
 \r
-      ccs.inc = SliderPanel.setConservationSlider(alignPanel, ccs,\r
-                                                  "Background");\r
-    }\r
-    else\r
-    {\r
-      // MUST NOTIFY THE COLOURSCHEME OF CONSENSUS!\r
-      if (cs != null)\r
+        cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel, cs,\r
+            "Background"));\r
+      }\r
+      else\r
       {\r
-        cs.setConsensus(viewport.vconsensus);\r
+        cs.setConservation(null);\r
       }\r
 \r
-      viewport.setGlobalColourScheme(cs);\r
+      cs.setConsensus(viewport.vconsensus);\r
     }\r
 \r
+    viewport.setGlobalColourScheme(cs);\r
+\r
     if (viewport.getColourAppliesToAllGroups())\r
     {\r
       Vector groups = viewport.alignment.getGroups();\r
@@ -1442,8 +1426,10 @@ public class AlignFrame
         if (cs == null)\r
         {\r
           sg.cs = null;\r
+          continue;\r
         }\r
-        else if (cs instanceof ClustalxColourScheme)\r
+\r
+        if (cs instanceof ClustalxColourScheme)\r
         {\r
           sg.cs = new ClustalxColourScheme(sg.sequences, sg.getWidth());\r
         }\r
@@ -1464,20 +1450,15 @@ public class AlignFrame
 \r
         if (viewport.getAbovePIDThreshold())\r
         {\r
-          if (sg.cs instanceof ResidueColourScheme)\r
-          {\r
-            ( (ResidueColourScheme) sg.cs).setThreshold(threshold,\r
-                viewport.getIgnoreGapsConsensus());\r
-          }\r
-          else if (sg.cs instanceof ScoreColourScheme)\r
-          {\r
-            ( (ScoreColourScheme) sg.cs).setThreshold(threshold,\r
+         sg.cs.setThreshold(threshold,\r
                 viewport.getIgnoreGapsConsensus());\r
-          }\r
 \r
           sg.cs.setConsensus(AAFrequency.calculate(sg.sequences, 0,\r
               sg.getWidth()));\r
         }\r
+        else\r
+          sg.cs.setThreshold(0, viewport.getIgnoreGapsConsensus());\r
+\r
 \r
         if (viewport.getConservationSelected())\r
         {\r
@@ -1487,21 +1468,10 @@ public class AlignFrame
                                             viewport.alignment.getWidth() - 1);\r
           c.calculate();\r
           c.verdict(false, viewport.ConsPercGaps);\r
-\r
-          ConservationColourScheme ccs = new ConservationColourScheme(c,\r
-              sg.cs);\r
-\r
-          // MUST NOTIFY THE COLOURSCHEME OF CONSENSUS!\r
-          ccs.setConsensus(AAFrequency.calculate(sg.sequences, 0,\r
-                                                 sg.getWidth()));\r
-          sg.cs = ccs;\r
-        }\r
-        else if (cs != null)\r
-        {\r
-          // MUST NOTIFY THE COLOURSCHEME OF CONSENSUS!\r
-          sg.cs.setConsensus(AAFrequency.calculate(sg.sequences, 0,\r
-              sg.getWidth()));\r
+          sg.cs.setConservation(c);\r
         }\r
+        else\r
+          sg.cs.setConservation(null);\r
       }\r
     }\r
 \r
@@ -1520,7 +1490,7 @@ public class AlignFrame
    */\r
   protected void modifyPID_actionPerformed(ActionEvent e)\r
   {\r
-    if (viewport.getAbovePIDThreshold())\r
+    if (viewport.getAbovePIDThreshold() && viewport.globalColourScheme!=null)\r
     {\r
       SliderPanel.setPIDSliderSource(alignPanel,\r
                                      viewport.getGlobalColourScheme(),\r
@@ -1536,7 +1506,7 @@ public class AlignFrame
    */\r
   protected void modifyConservation_actionPerformed(ActionEvent e)\r
   {\r
-    if (viewport.getConservationSelected())\r
+    if (viewport.getConservationSelected() && viewport.globalColourScheme!=null)\r
     {\r
       SliderPanel.setConservationSlider(alignPanel,\r
                                         viewport.globalColourScheme,\r
@@ -1557,16 +1527,7 @@ public class AlignFrame
     viewport.setAbovePIDThreshold(false);\r
     abovePIDThreshold.setSelected(false);\r
 \r
-    ColourSchemeI cs = viewport.getGlobalColourScheme();\r
-\r
-    if (cs instanceof ConservationColourScheme)\r
-    {\r
-      changeColour( ( (ConservationColourScheme) cs).cs);\r
-    }\r
-    else\r
-    {\r
-      changeColour(cs);\r
-    }\r
+    changeColour(viewport.getGlobalColourScheme());\r
 \r
     modifyConservation_actionPerformed(null);\r
   }\r
@@ -1585,14 +1546,7 @@ public class AlignFrame
 \r
     ColourSchemeI cs = viewport.getGlobalColourScheme();\r
 \r
-    if (cs instanceof ConservationColourScheme)\r
-    {\r
-      changeColour( ( (ConservationColourScheme) cs).cs);\r
-    }\r
-    else\r
-    {\r
-      changeColour(cs);\r
-    }\r
+    changeColour(viewport.getGlobalColourScheme());\r
 \r
     modifyPID_actionPerformed(null);\r
   }\r
@@ -1638,8 +1592,37 @@ public class AlignFrame
 \r
       while (userColours.hasMoreElements())\r
       {\r
-        JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(userColours.\r
+        final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(userColours.\r
             nextElement().toString());\r
+        radioItem.setName("USER_DEFINED");\r
+        radioItem.addMouseListener(new MouseAdapter()\r
+            {\r
+              public void mousePressed(MouseEvent evt)\r
+              {\r
+                if(evt.isControlDown() || SwingUtilities.isRightMouseButton(evt))\r
+                {\r
+                  radioItem.removeActionListener(radioItem.getActionListeners()[0]);\r
+\r
+                  int option = JOptionPane.showInternalConfirmDialog(jalview.gui.Desktop.desktop,\r
+                      "Remove from default list?",\r
+                      "Remove user defined colour",\r
+                      JOptionPane.YES_NO_OPTION);\r
+                  if(option == JOptionPane.YES_OPTION)\r
+                  {\r
+                    jalview.gui.UserDefinedColours.removeColourFromDefaults(radioItem.getText());\r
+                    colourMenu.remove(radioItem);\r
+                  }\r
+                  else\r
+                    radioItem.addActionListener(new ActionListener()\r
+                    {\r
+                      public void actionPerformed(ActionEvent evt)\r
+                      {\r
+                        userDefinedColour_actionPerformed(evt);\r
+                      }\r
+                    });\r
+                }\r
+              }\r
+            });\r
         radioItem.addActionListener(new ActionListener()\r
         {\r
           public void actionPerformed(ActionEvent evt)\r
@@ -1647,6 +1630,7 @@ public class AlignFrame
             userDefinedColour_actionPerformed(evt);\r
           }\r
         });\r
+\r
         colourMenu.insert(radioItem, 15);\r
         colours.add(radioItem);\r
       }\r
@@ -2219,7 +2203,7 @@ public class AlignFrame
           if (sh.getName().indexOf("lustal") > -1)\r
           {\r
             // We know that ClustalWS can accept partial alignments for refinement.\r
-            final JMenuItem methodR = new JMenuItem(sh.getName() + " realign");\r
+            final JMenuItem methodR = new JMenuItem(sh.getName()+" Realign");\r
             methodR.addActionListener(new ActionListener()\r
             {\r
               public void actionPerformed(ActionEvent e)\r