Unique name for new group and treegroup
[jalview.git] / src / jalview / gui / AnnotationColourChooser.java
index 49e835d..b748c85 100755 (executable)
@@ -1,6 +1,6 @@
 /*\r
 * Jalview - A Sequence Alignment Editor and Viewer\r
-* Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
+* Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
 *\r
 * This program is free software; you can redistribute it and/or\r
 * modify it under the terms of the GNU General Public License\r
@@ -26,6 +26,8 @@ import jalview.schemes.*;
 import javax.swing.event.*;\r
 import java.util.*;\r
 import jalview.datamodel.SequenceGroup;\r
+import java.awt.Dimension;\r
+import javax.swing.BorderFactory;\r
 \r
 public class AnnotationColourChooser\r
     extends JPanel\r
@@ -36,6 +38,7 @@ public class AnnotationColourChooser
   ColourSchemeI oldcs;\r
   Hashtable oldgroupColours;\r
   jalview.datamodel.AlignmentAnnotation currentAnnotation;\r
+  boolean adjusting = false;\r
 \r
   public AnnotationColourChooser(AlignViewport av, AlignmentPanel ap)\r
   {\r
@@ -48,7 +51,8 @@ public class AnnotationColourChooser
       for (int g = 0; g < allGroups.size(); g++)\r
       {\r
         sg = (SequenceGroup) allGroups.get(g);\r
-        oldgroupColours.put(sg, sg.cs);\r
+        if(sg.cs!=null)\r
+          oldgroupColours.put(sg, sg.cs);\r
       }\r
     }\r
     this.av = av;\r
@@ -56,7 +60,7 @@ public class AnnotationColourChooser
     frame = new JInternalFrame();\r
     frame.setContentPane(this);\r
     frame.setLayer(JLayeredPane.PALETTE_LAYER);\r
-    Desktop.addInternalFrame(frame, "Colour by Annotation", 480, 145, false);\r
+    Desktop.addInternalFrame(frame, "Colour by Annotation", 480, 145);\r
 \r
     try\r
     {\r
@@ -69,8 +73,11 @@ public class AnnotationColourChooser
     {\r
       public void stateChanged(ChangeEvent evt)\r
       {\r
-        thresholdValue.setText( ( (float) slider.getValue() / 1000f) + "");\r
-        valueChanged();\r
+        if(!adjusting)\r
+        {\r
+          thresholdValue.setText( ( (float) slider.getValue() / 1000f) + "");\r
+          valueChanged();\r
+        }\r
       }\r
     });\r
 \r
@@ -89,6 +96,7 @@ public class AnnotationColourChooser
       maxColour.setBackground(Color.red);\r
     }\r
 \r
+    adjusting = true;\r
     for (int i = 0; i < av.alignment.getAlignmentAnnotation().length; i++)\r
     {\r
       if (av.alignment.getAlignmentAnnotation()[i].graph > 0)\r
@@ -99,6 +107,10 @@ public class AnnotationColourChooser
     threshold.addItem("Above Threshold");\r
     threshold.addItem("Below Threshold");\r
 \r
+    adjusting = false;\r
+\r
+    changeColour();\r
+\r
   }\r
 \r
   public AnnotationColourChooser()\r
@@ -117,24 +129,27 @@ public class AnnotationColourChooser
       throws Exception\r
   {\r
     minColour.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));\r
-    minColour.setToolTipText("");\r
-    minColour.setMargin(new Insets(2, 2, 2, 2));\r
-    minColour.setText("Min Colour");\r
-    minColour.addActionListener(new ActionListener()\r
+    minColour.setBorder(BorderFactory.createEtchedBorder());\r
+    minColour.setPreferredSize(new Dimension(40, 20));\r
+    minColour.setToolTipText("Minimum Colour");\r
+    minColour.addMouseListener(new MouseAdapter()\r
     {\r
-      public void actionPerformed(ActionEvent e)\r
+      public void mousePressed(MouseEvent e)\r
       {\r
-        minColour_actionPerformed(e);\r
+        if (minColour.isEnabled())\r
+          minColour_actionPerformed();\r
       }\r
     });\r
     maxColour.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));\r
-    maxColour.setMargin(new Insets(2, 2, 2, 2));\r
-    maxColour.setText("Max Colour");\r
-    maxColour.addActionListener(new ActionListener()\r
+    maxColour.setBorder(BorderFactory.createEtchedBorder());\r
+    maxColour.setPreferredSize(new Dimension(40, 20));\r
+    maxColour.setToolTipText("Maximum Colour");\r
+    maxColour.addMouseListener(new MouseAdapter()\r
     {\r
-      public void actionPerformed(ActionEvent e)\r
+      public void mousePressed(MouseEvent e)\r
       {\r
-        maxColour_actionPerformed(e);\r
+        if (maxColour.isEnabled())\r
+          maxColour_actionPerformed();\r
       }\r
     });\r
     ok.setOpaque(false);\r
@@ -181,10 +196,12 @@ public class AnnotationColourChooser
         thresholdValue_actionPerformed(e);\r
       }\r
     });\r
+    slider.setPaintLabels(false);\r
     slider.setPaintTicks(true);\r
     slider.setBackground(Color.white);\r
     slider.setEnabled(false);\r
     slider.setOpaque(false);\r
+    slider.setPreferredSize(new Dimension(150, 32));\r
     thresholdValue.setEnabled(false);\r
     thresholdValue.setColumns(10);\r
     jPanel3.setBackground(Color.white);\r
@@ -213,8 +230,8 @@ public class AnnotationColourChooser
   }\r
 \r
   JComboBox annotations = new JComboBox();\r
-  JButton minColour = new JButton();\r
-  JButton maxColour = new JButton();\r
+  JPanel minColour = new JPanel();\r
+  JPanel maxColour = new JPanel();\r
   JButton ok = new JButton();\r
   JButton cancel = new JButton();\r
   JPanel jPanel1 = new JPanel();\r
@@ -228,7 +245,7 @@ public class AnnotationColourChooser
   JTextField thresholdValue = new JTextField(20);\r
   JCheckBox currentColours = new JCheckBox();\r
 \r
-  public void minColour_actionPerformed(ActionEvent e)\r
+  public void minColour_actionPerformed()\r
   {\r
     Color col = JColorChooser.showDialog(this,\r
                                          "Select Colour for Minimum Value",\r
@@ -239,7 +256,7 @@ public class AnnotationColourChooser
     changeColour();\r
   }\r
 \r
-  public void maxColour_actionPerformed(ActionEvent e)\r
+  public void maxColour_actionPerformed()\r
   {\r
     Color col = JColorChooser.showDialog(this,\r
                                          "Select Colour for Maximum Value",\r
@@ -253,7 +270,7 @@ public class AnnotationColourChooser
   void changeColour()\r
   {\r
     // Check if combobox is still adjusting\r
-    if (threshold.getSelectedIndex() == -1)\r
+    if (adjusting)\r
       return;\r
 \r
     // We removed the non-graph annotations when filling the combobox\r
@@ -278,9 +295,11 @@ public class AnnotationColourChooser
     else if (threshold.getSelectedItem().equals("Below Threshold"))\r
       aboveThreshold = AnnotationColourGradient.BELOW_THRESHOLD;\r
 \r
+    slider.setEnabled(true);\r
+    thresholdValue.setEnabled(true);\r
+\r
     if (aboveThreshold == AnnotationColourGradient.NO_THRESHOLD)\r
     {\r
-      currentAnnotation.threshold = null;\r
       slider.setEnabled(false);\r
       thresholdValue.setEnabled(false);\r
       thresholdValue.setText("");\r
@@ -293,6 +312,11 @@ public class AnnotationColourChooser
                                         currentAnnotation.graphMin) / 2f,\r
                                       "Threshold",\r
                                       Color.black));\r
+    }\r
+\r
+    if(aboveThreshold != AnnotationColourGradient.NO_THRESHOLD)\r
+    {\r
+      adjusting = true;\r
       float range = currentAnnotation.graphMax * 1000 -\r
           currentAnnotation.graphMin * 1000;\r
 \r
@@ -301,9 +325,9 @@ public class AnnotationColourChooser
       slider.setValue( (int) (currentAnnotation.threshold.value * 1000));\r
       thresholdValue.setText(currentAnnotation.threshold.value + "");\r
       slider.setMajorTickSpacing( (int) (range / 10f));\r
-      slider.setMinorTickSpacing( (int) (range / 100f));\r
       slider.setEnabled(true);\r
       thresholdValue.setEnabled(true);\r
+      adjusting = false;\r
     }\r
 \r
     AnnotationColourGradient acg = null;\r
@@ -396,8 +420,6 @@ public class AnnotationColourChooser
 \r
   public void annotations_actionPerformed(ActionEvent e)\r
   {\r
-    if(currentAnnotation!=null)\r
-      currentAnnotation.threshold = null;\r
     changeColour();\r
   }\r
 \r
@@ -419,6 +441,12 @@ public class AnnotationColourChooser
 \r
   public void valueChanged()\r
   {\r
+    if (currentColours.isSelected()\r
+        && !(av.getGlobalColourScheme() instanceof AnnotationColourGradient))\r
+    {\r
+      changeColour();\r
+    }\r
+\r
     currentAnnotation.threshold.value = (float)slider.getValue()/1000f;\r
     ap.repaint();\r
   }\r