JAL-2055 prototype alternate feature colouring based on
[jalview.git] / src / jalview / gui / FeatureColourChooser.java
index 064d58b..d4e37f7 100644 (file)
@@ -84,6 +84,31 @@ public class FeatureColourChooser extends JalviewDialog
 
   String type = null;
 
+  JPanel minColour = new JPanel();
+
+  JPanel maxColour = new JPanel();
+
+  JComboBox threshold = new JComboBox();
+
+  JSlider slider = new JSlider();
+
+  JTextField thresholdValue = new JTextField(20);
+
+  // TODO implement GUI for tolower flag
+  // JCheckBox toLower = new JCheckBox();
+
+  JCheckBox thresholdIsMin = new JCheckBox();
+
+  JCheckBox colourAlternately = new JCheckBox();
+
+  JCheckBox colourByLabel = new JCheckBox();
+
+  private GraphLine threshline;
+
+  private Color oldmaxColour;
+
+  private Color oldminColour;
+
   public FeatureColourChooser(FeatureRenderer frender, String type)
   {
     this(frender, false, type);
@@ -127,7 +152,7 @@ public class FeatureColourChooser extends JalviewDialog
       }
     });
 
-    float mm[] = ((float[][]) fr.getMinMax().get(type))[0];
+    float mm[] = fr.getMinMax().get(type)[0];
     min = mm[0];
     max = mm[1];
 
@@ -176,6 +201,7 @@ public class FeatureColourChooser extends JalviewDialog
     // update the gui from threshold state
     thresholdIsMin.setSelected(!cs.isAutoScale());
     colourByLabel.setSelected(cs.isColourByLabel());
+    colourAlternately.setSelected(cs.isColourAlternately());
     if (cs.getThreshType() != AnnotationColourGradient.NO_THRESHOLD)
     {
       // initialise threshold slider and selector
@@ -229,12 +255,16 @@ public class FeatureColourChooser extends JalviewDialog
       }
     });
     maxColour.setBorder(new LineBorder(Color.black));
+    JLabel minText = new JLabel();
     minText.setText(MessageManager.getString("label.min"));
     minText.setFont(JvSwingUtils.getLabelFont());
+    JLabel maxText = new JLabel();
     maxText.setText(MessageManager.getString("label.max"));
     maxText.setFont(JvSwingUtils.getLabelFont());
-    this.setLayout(borderLayout1);
-    jPanel2.setLayout(flowLayout1);
+    this.setLayout(new BorderLayout());
+    JPanel jPanel1 = new JPanel();
+    JPanel jPanel2 = new JPanel();
+    jPanel2.setLayout(new FlowLayout());
     jPanel1.setBackground(Color.white);
     jPanel2.setBackground(Color.white);
     threshold.addActionListener(new ActionListener()
@@ -253,7 +283,8 @@ public class FeatureColourChooser extends JalviewDialog
             .getString("label.threshold_feature_above_thereshold")); // index 1
     threshold.addItem(MessageManager
             .getString("label.threshold_feature_below_thereshold")); // index 2
-    jPanel3.setLayout(flowLayout2);
+    JPanel jPanel3 = new JPanel();
+    jPanel3.setLayout(new FlowLayout());
     thresholdValue.addActionListener(new ActionListener()
     {
       @Override
@@ -286,6 +317,19 @@ public class FeatureColourChooser extends JalviewDialog
         thresholdIsMin_actionPerformed(actionEvent);
       }
     });
+    colourAlternately.setBackground(Color.white);
+    colourAlternately.setText(MessageManager
+            .getString("label.colour_alternately"));
+    colourAlternately.setToolTipText(MessageManager
+            .getString("label.colour_alternately_tip"));
+    colourAlternately.addActionListener(new ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent actionEvent)
+      {
+        colourAlternately_actionPerformed(actionEvent);
+      }
+    });
     colourByLabel.setBackground(Color.white);
     colourByLabel
             .setText(MessageManager.getString("label.colour_by_label"));
@@ -300,10 +344,13 @@ public class FeatureColourChooser extends JalviewDialog
         colourByLabel_actionPerformed(actionEvent);
       }
     });
+
+    JPanel colourPanel = new JPanel();
     colourPanel.setBackground(Color.white);
     jPanel1.add(ok);
     jPanel1.add(cancel);
-    jPanel2.add(colourByLabel, java.awt.BorderLayout.WEST);
+    jPanel2.add(colourAlternately, java.awt.BorderLayout.WEST);
+    jPanel2.add(colourByLabel, java.awt.BorderLayout.CENTER);
     jPanel2.add(colourPanel, java.awt.BorderLayout.EAST);
     colourPanel.add(minText);
     colourPanel.add(minColour);
@@ -318,46 +365,10 @@ public class FeatureColourChooser extends JalviewDialog
     this.add(jPanel2, java.awt.BorderLayout.NORTH);
   }
 
-  JLabel minText = new JLabel();
-
-  JLabel maxText = new JLabel();
-
-  JPanel minColour = new JPanel();
-
-  JPanel maxColour = new JPanel();
-
-  JPanel colourPanel = new JPanel();
-
-  JPanel jPanel1 = new JPanel();
-
-  JPanel jPanel2 = new JPanel();
-
-  BorderLayout borderLayout1 = new BorderLayout();
-
-  JComboBox threshold = new JComboBox();
-
-  FlowLayout flowLayout1 = new FlowLayout();
-
-  JPanel jPanel3 = new JPanel();
-
-  FlowLayout flowLayout2 = new FlowLayout();
-
-  JSlider slider = new JSlider();
-
-  JTextField thresholdValue = new JTextField(20);
-
-  // TODO implement GUI for tolower flag
-  // JCheckBox toLower = new JCheckBox();
-
-  JCheckBox thresholdIsMin = new JCheckBox();
-
-  JCheckBox colourByLabel = new JCheckBox();
-
-  private GraphLine threshline;
-
-  private Color oldmaxColour;
-
-  private Color oldminColour;
+  protected void colourAlternately_actionPerformed(ActionEvent actionEvent)
+  {
+    changeColour();
+  }
 
   public void minColour_actionPerformed()
   {
@@ -472,6 +483,14 @@ public class FeatureColourChooser extends JalviewDialog
       acg.setAutoScaled(true);
     }
     acg.setColourByLabel(colourByLabel.isSelected());
+    acg.setColourAlternately(colourAlternately.isSelected());
+    colourByLabel.setEnabled(!colourAlternately.isSelected());
+    colourAlternately.setEnabled(!colourByLabel.isSelected());
+    if (!fr.isOrdinal(type))
+    {
+      // don't allow colour alternately if no feature numbering on features
+      colourAlternately.setEnabled(false);
+    }
     if (acg.isColourByLabel())
     {
       maxColour.setEnabled(false);