Conservation and PID colouring methods updated
authoramwaterhouse <Andrew Waterhouse>
Tue, 1 Feb 2005 19:02:28 +0000 (19:02 +0000)
committeramwaterhouse <Andrew Waterhouse>
Tue, 1 Feb 2005 19:02:28 +0000 (19:02 +0000)
src/jalview/gui/AlignFrame.java
src/jalview/gui/Desktop.java

index 5173fed..9a87b90 100755 (executable)
@@ -39,6 +39,9 @@ public class AlignFrame extends GAlignFrame
     getContentPane().add(alignPanel, java.awt.BorderLayout.CENTER);\r
     fontNameMenuItem.setText(viewport.getFont().getName());\r
     fontSizeMenuItem.setText(viewport.getFont().getSize()+"");\r
+\r
+    clustalColour.setSelected(true);\r
+    clustalColour_actionPerformed(null);\r
   }\r
 \r
   protected void saveAs_actionPerformed(ActionEvent e)\r
@@ -478,8 +481,8 @@ public class AlignFrame extends GAlignFrame
 \r
   public void clustalColour_actionPerformed(ActionEvent e)\r
   {\r
-    viewport.setGlobalColourScheme(new ClustalxColourScheme( ));\r
-    conservationMenuItem.setSelected(false);\r
+    viewport.setGlobalColourScheme(\r
+      new ClustalxColourScheme(viewport.alignment.getSequences(), viewport.alignment.getWidth()));\r
     abovePIDThreshold.setSelected(false);\r
     changeColour();\r
   }\r
@@ -544,119 +547,98 @@ public class AlignFrame extends GAlignFrame
     else if(conservationMenuItem.isSelected())\r
       conservationMenuItem_actionPerformed(null);\r
 \r
-\r
-     alignPanel.RefreshPanels();\r
+    alignPanel.RefreshPanels();\r
   }\r
 \r
-  void addConservationOrPIDColour()\r
+\r
+  protected  void conservationMenuItem_actionPerformed(ActionEvent e)\r
   {\r
-    int x=0, y=0, threshold = 70;\r
+   if(abovePIDThreshold.isSelected())\r
+   {\r
+     abovePIDThreshold.setSelected(false);\r
+     Desktop.hidePIDSlider();\r
+   }\r
 \r
-    if(sliderFrame!=null)\r
-       try\r
-       {\r
-         x = sliderFrame.getX();\r
-         y = sliderFrame.getY();\r
-         SliderPanel sp = (SliderPanel) sliderFrame.getContentPane();\r
-         threshold = sp.getValue();\r
-         sliderFrame.setClosed(true);\r
-       }\r
-       catch (Exception ex)\r
-       {    ex.printStackTrace();   }\r
+   viewport.setConservationSelected(conservationMenuItem.isSelected());\r
 \r
-     ColourSchemeI oldCs = viewport.getGlobalColourScheme();\r
+   ColourSchemeI oldCs = viewport.getGlobalColourScheme();\r
 \r
-     ConservationColourScheme ccs = null;\r
-     if (oldCs instanceof ConservationColourScheme)\r
-       ccs = (ConservationColourScheme) oldCs;\r
+   ConservationColourScheme ccs = null;\r
+   if (oldCs instanceof ConservationColourScheme)\r
+         ccs = (ConservationColourScheme) oldCs;\r
 \r
-     if(conservationMenuItem.isSelected())\r
-     {\r
-       Alignment al = (Alignment)viewport.alignment;\r
-       Conservation c = new Conservation("All",\r
-                            ResidueProperties.propHash, 3, al.getSequences(), 0,\r
-                            al.getWidth() );\r
+       if (conservationMenuItem.isSelected())\r
+       {\r
+         Alignment al = (Alignment) viewport.alignment;\r
+         Conservation c = new Conservation("All",\r
+                                           ResidueProperties.propHash, 3,\r
+                                           al.getSequences(), 0,\r
+                                           al.getWidth());\r
 \r
-       c.calculate();\r
-       c.verdict(false, 100);\r
+         c.calculate();\r
+         c.verdict(false, 100);\r
 \r
-       if(ccs!=null)\r
-         ccs = new ConservationColourScheme(c, ccs.cs);\r
-       else\r
-         ccs = new ConservationColourScheme(c, oldCs);\r
+         if (ccs != null)\r
+           ccs = new ConservationColourScheme(c, ccs.cs);\r
+         else\r
+           ccs = new ConservationColourScheme(c, oldCs);\r
 \r
-        viewport.setGlobalColourScheme( ccs );\r
 \r
-     }\r
-     else if(oldCs instanceof ConservationColourScheme)\r
-     {\r
-       oldCs = ccs.cs;\r
-       viewport.setGlobalColourScheme( oldCs );\r
-     }\r
+         int threshold = Desktop.setConservationSliderSource(alignPanel, ccs, "Background");\r
 \r
+         ccs.inc = threshold;\r
+\r
+         if (ccs.cs instanceof ResidueColourScheme)\r
+           ((ResidueColourScheme) ccs.cs).setThreshold(0);\r
+         else if (ccs.cs instanceof ScoreColourScheme)\r
+           ((ScoreColourScheme)ccs.cs).setThreshold(0);\r
+\r
+         viewport.setGlobalColourScheme(ccs);\r
 \r
-     if( conservationMenuItem.isSelected() || abovePIDThreshold.isSelected() )\r
-     {\r
-       sliderFrame = new JInternalFrame();\r
-       sliderFrame.setMaximizable(false);\r
-       sliderFrame.setResizable(false);\r
 \r
-       SliderPanel sp = null;\r
-       if (conservationMenuItem.isSelected())\r
-       {\r
-        if(threshold > 50)\r
-          threshold = 30;\r
-        sp = new SliderPanel(alignPanel, threshold, true,ccs);\r
-        Desktop.addInternalFrame(sliderFrame, "Conservation Colour Increment  (Global colour)", 400, 90);\r
-        threshold = 0;\r
        }\r
-       else if (abovePIDThreshold.isSelected())\r
+       else if (oldCs instanceof ConservationColourScheme)\r
        {\r
-         sp = new SliderPanel(alignPanel, threshold, false, oldCs);\r
-         sp.cs = oldCs;\r
-         Desktop.addInternalFrame(sliderFrame, "Percentage Identity Threshold (Global colour)", 400, 90);\r
+         /// ie, if we remove ConservationColourScheme from backgroundColour\r
+         oldCs = ccs.cs;\r
+         viewport.setGlobalColourScheme(oldCs);\r
+         Desktop.hideConservationSlider();\r
        }\r
 \r
-       sliderFrame.setContentPane(sp);\r
-       if(x!=0 && y!=0)\r
-               sliderFrame.setLocation(x,y);\r
+       if(e!=null)\r
+         alignPanel.RefreshPanels();\r
+  }\r
 \r
-     }\r
-     else\r
-       threshold = 0;\r
 \r
+  public void abovePIDThreshold_actionPerformed(ActionEvent e)\r
+  {\r
+      if(conservationMenuItem.isSelected())\r
+        conservationMenuItem.setSelected(false);\r
 \r
-     if (oldCs instanceof ResidueColourScheme)\r
+      ColourSchemeI oldCs = viewport.getGlobalColourScheme();\r
+      int threshold = 0;\r
+      if (oldCs instanceof ConservationColourScheme)\r
      {\r
-       ResidueColourScheme rcs = (ResidueColourScheme) oldCs;\r
-       rcs.setThreshold(threshold);\r
+       ConservationColourScheme ccs = (ConservationColourScheme) oldCs;\r
+       oldCs = ccs.cs;\r
      }\r
-     else if (oldCs instanceof ScoreColourScheme)\r
+\r
+     if(abovePIDThreshold.isSelected())\r
      {\r
-       ScoreColourScheme scs = (ScoreColourScheme) oldCs;\r
-       scs.setThreshold(threshold);\r
+       threshold = Desktop.setPIDSliderSource(alignPanel, oldCs, "Background");\r
+       Desktop.hideConservationSlider();\r
      }\r
+     else\r
+       Desktop.hidePIDSlider();\r
 \r
+      if (oldCs instanceof ResidueColourScheme)\r
+          ((ResidueColourScheme) oldCs).setThreshold(threshold);\r
+      else if (oldCs instanceof ScoreColourScheme)\r
+          ((ScoreColourScheme)oldCs).setThreshold(threshold);\r
 \r
-  }\r
-\r
-  protected  void conservationMenuItem_actionPerformed(ActionEvent e)\r
-  {\r
-   if(abovePIDThreshold.isSelected())\r
-    abovePIDThreshold.setSelected(false);\r
-\r
-   viewport.setConservationSelected(conservationMenuItem.isSelected());\r
-\r
-   addConservationOrPIDColour();\r
-  }\r
-\r
-  JInternalFrame sliderFrame;\r
-  public void abovePIDThreshold_actionPerformed(ActionEvent e)\r
-  {\r
-      if(conservationMenuItem.isSelected())\r
-        conservationMenuItem.setSelected(false);\r
-\r
-      addConservationOrPIDColour();\r
+    viewport.setGlobalColourScheme(oldCs);\r
+     if(e!=null)\r
+        alignPanel.RefreshPanels();\r
   }\r
 \r
 \r
@@ -682,7 +664,7 @@ public class AlignFrame extends GAlignFrame
   public void BLOSUM62Colour_actionPerformed(ActionEvent e)\r
   {\r
     viewport.setGlobalColourScheme( new Blosum62ColourScheme(viewport)  );\r
-    alignPanel.setColourScheme();\r
+    changeColour();\r
   }\r
 \r
 \r
index 464ec59..2c475fa 100755 (executable)
@@ -12,6 +12,7 @@ package jalview.gui;
 import jalview.gui.*;\r
 import jalview.io.*;\r
 import jalview.datamodel.*;\r
+import jalview.schemes.*;\r
 import javax.swing.*;\r
 import java.awt.*;\r
 import java.awt.event.*;\r
@@ -261,4 +262,86 @@ public class Desktop extends jalview.jbgui.GDesktop
    }\r
  }\r
 \r
+ static JInternalFrame conservationSlider;\r
+ static JInternalFrame PIDSlider;\r
+ public static int setConservationSliderSource(AlignmentPanel ap, ColourSchemeI cs, String source)\r
+ {\r
+   SliderPanel sp = null;\r
+\r
+   if(conservationSlider == null)\r
+   {\r
+     sp = new SliderPanel(ap, 30, true, cs);\r
+     conservationSlider = new JInternalFrame();\r
+     conservationSlider.setContentPane(sp);\r
+     conservationSlider.setResizable(false);\r
+     addInternalFrame(conservationSlider, "Conservation Colour Increment  ("+source+")", 420, 90);\r
+     conservationSlider.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()\r
+                  {\r
+                    public void internalFrameClosed(javax.swing.event.InternalFrameEvent e)\r
+                    {\r
+                      conservationSlider = null;\r
+                    }\r
+                  });\r
+   }\r
+   else\r
+   {\r
+       conservationSlider.setTitle("Conservation Colour Increment  ("+source+")");\r
+       sp = (SliderPanel)conservationSlider.getContentPane();\r
+       sp.cs = cs;\r
+   }\r
+\r
+   if(ap.av.alignment.getGroups()!=null)\r
+     sp.setAllGroupsCheckEnabled( true );\r
+   else\r
+     sp.setAllGroupsCheckEnabled( false);\r
+\r
+   return sp.getValue();\r
+\r
+ }\r
+\r
+ public static void hideConservationSlider()\r
+ {\r
+  try{\r
+    conservationSlider.setClosed(true);\r
+    conservationSlider = null;\r
+  }catch(Exception ex){}\r
+}\r
+\r
+\r
+ public static void hidePIDSlider()\r
+ {\r
+   try{\r
+     PIDSlider.setClosed(true);\r
+     PIDSlider = null;\r
+   }catch(Exception ex){}\r
+ }\r
+\r
+ public static int setPIDSliderSource(AlignmentPanel ap, ColourSchemeI cs, String source)\r
+ {\r
+   SliderPanel pid = null;\r
+   if(PIDSlider == null)\r
+   {\r
+     pid = new SliderPanel(ap, 50, false, cs);\r
+     PIDSlider = new JInternalFrame();\r
+     PIDSlider.setContentPane(pid);\r
+     PIDSlider.setResizable(false);\r
+     addInternalFrame(PIDSlider, "Percentage Identity Threshold ("+source+")", 420, 90);\r
+   }\r
+   else\r
+   {\r
+       PIDSlider.setTitle("Percentage Identity Threshold ("+source+")");\r
+       pid = (SliderPanel)PIDSlider.getContentPane();\r
+       pid.cs = cs;\r
+   }\r
+\r
+   if (ap.av.alignment.getGroups() != null)\r
+     pid.setAllGroupsCheckEnabled(true);\r
+   else\r
+     pid.setAllGroupsCheckEnabled(false);\r
+\r
+\r
+   return pid.getValue();\r
+\r
+ }\r
+\r
 }\r