JAL-2808 spike updated with latest
[jalview.git] / src / jalview / gui / FeatureColourChooser.java
index d8db546..89b64a7 100644 (file)
@@ -29,6 +29,7 @@ import java.awt.BorderLayout;
 import java.awt.Color;
 import java.awt.Dimension;
 import java.awt.FlowLayout;
+import java.awt.GridLayout;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.awt.event.FocusAdapter;
@@ -221,54 +222,35 @@ public class FeatureColourChooser extends JalviewDialog
 
   private void jbInit() throws Exception
   {
+    this.setLayout(new GridLayout(4, 1));
 
-    minColour.setFont(JvSwingUtils.getLabelFont());
-    minColour.setBorder(BorderFactory.createLineBorder(Color.black));
-    minColour.setPreferredSize(new Dimension(40, 20));
-    minColour.setToolTipText(MessageManager.getString("label.min_colour"));
-    minColour.addMouseListener(new MouseAdapter()
-    {
-      @Override
-      public void mousePressed(MouseEvent e)
-      {
-        if (minColour.isEnabled())
-        {
-          minColour_actionPerformed();
-        }
-      }
-    });
-    maxColour.setFont(JvSwingUtils.getLabelFont());
-    maxColour.setBorder(BorderFactory.createLineBorder(Color.black));
-    maxColour.setPreferredSize(new Dimension(40, 20));
-    maxColour.setToolTipText(MessageManager.getString("label.max_colour"));
-    maxColour.addMouseListener(new MouseAdapter()
-    {
-      @Override
-      public void mousePressed(MouseEvent e)
-      {
-        if (maxColour.isEnabled())
-        {
-          maxColour_actionPerformed();
-        }
-      }
-    });
-    maxColour.setBorder(new LineBorder(Color.black));
-    JLabel minText = new JLabel(MessageManager.getString("label.min"));
-    minText.setFont(JvSwingUtils.getLabelFont());
-    JLabel maxText = new JLabel(MessageManager.getString("label.max"));
-    maxText.setFont(JvSwingUtils.getLabelFont());
-    this.setLayout(new BorderLayout());
-    JPanel jPanel1 = new JPanel();
-    jPanel1.setBackground(Color.white);
-    JPanel jPanel2 = new JPanel();
-    jPanel2.setLayout(new FlowLayout());
-    jPanel2.setBackground(Color.white);
+    JPanel colourByPanel = initColoursPanel();
+
+    JPanel thresholdPanel = initThresholdPanel();
+
+    JPanel okCancelPanel = initOkCancelPanel();
+
+    this.add(colourByPanel);
+    this.add(thresholdPanel);
+
+    this.add(okCancelPanel);
+  }
+
+  /**
+   * Lay out fields for threshold options
+   * 
+   * @return
+   */
+  protected JPanel initThresholdPanel()
+  {
+    JPanel thresholdPanel = new JPanel();
+    thresholdPanel.setLayout(new FlowLayout());
     threshold.addActionListener(new ActionListener()
     {
       @Override
       public void actionPerformed(ActionEvent e)
       {
-        threshold_actionPerformed();
+        changeColour(true);
       }
     });
     threshold.setToolTipText(MessageManager
@@ -280,8 +262,6 @@ public class FeatureColourChooser extends JalviewDialog
     threshold.addItem(MessageManager
             .getString("label.threshold_feature_below_threshold")); // index 2
 
-    JPanel jPanel3 = new JPanel();
-    jPanel3.setLayout(new FlowLayout());
     thresholdValue.addActionListener(new ActionListener()
     {
       @Override
@@ -308,7 +288,7 @@ public class FeatureColourChooser extends JalviewDialog
             MessageManager.getString("label.adjust_threshold"));
     thresholdValue.setEnabled(false);
     thresholdValue.setColumns(7);
-    jPanel3.setBackground(Color.white);
+    thresholdPanel.setBackground(Color.white);
     thresholdIsMin.setBackground(Color.white);
     thresholdIsMin
             .setText(MessageManager.getString("label.threshold_minmax"));
@@ -319,40 +299,101 @@ public class FeatureColourChooser extends JalviewDialog
       @Override
       public void actionPerformed(ActionEvent actionEvent)
       {
-        thresholdIsMin_actionPerformed();
+        changeColour(true);
       }
     });
-    colourByLabel.setBackground(Color.white);
-    colourByLabel
-            .setText(MessageManager.getString("label.colour_by_label"));
-    colourByLabel.setToolTipText(MessageManager.getString(
-            "label.display_features_same_type_different_label_using_different_colour"));
-    colourByLabel.addActionListener(new ActionListener()
+    thresholdPanel.add(threshold);
+    thresholdPanel.add(slider);
+    thresholdPanel.add(thresholdValue);
+    thresholdPanel.add(thresholdIsMin);
+    return thresholdPanel;
+  }
+
+  /**
+   * Lay out OK and Cancel buttons
+   * 
+   * @return
+   */
+  protected JPanel initOkCancelPanel()
+  {
+    JPanel okCancelPanel = new JPanel();
+    okCancelPanel.setBackground(Color.white);
+    okCancelPanel.add(ok);
+    okCancelPanel.add(cancel);
+    return okCancelPanel;
+  }
+
+  /**
+   * Lay out Colour by Label and min/max colour widgets
+   * 
+   * @return
+   */
+  protected JPanel initColoursPanel()
+  {
+    JPanel colourByPanel = new JPanel();
+    colourByPanel.setLayout(new FlowLayout());
+    colourByPanel.setBackground(Color.white);
+    minColour.setFont(JvSwingUtils.getLabelFont());
+    minColour.setBorder(BorderFactory.createLineBorder(Color.black));
+    minColour.setPreferredSize(new Dimension(40, 20));
+    minColour.setToolTipText(MessageManager.getString("label.min_colour"));
+    minColour.addMouseListener(new MouseAdapter()
     {
       @Override
-      public void actionPerformed(ActionEvent actionEvent)
+      public void mousePressed(MouseEvent e)
       {
-        colourByLabel_actionPerformed();
+        if (minColour.isEnabled())
+        {
+          minColour_actionPerformed();
+        }
       }
     });
+    maxColour.setFont(JvSwingUtils.getLabelFont());
+    maxColour.setBorder(BorderFactory.createLineBorder(Color.black));
+    maxColour.setPreferredSize(new Dimension(40, 20));
+    maxColour.setToolTipText(MessageManager.getString("label.max_colour"));
+    maxColour.addMouseListener(new MouseAdapter()
+    {
+      @Override
+      public void mousePressed(MouseEvent e)
+      {
+        if (maxColour.isEnabled())
+        {
+          maxColour_actionPerformed();
+        }
+      }
+    });
+    maxColour.setBorder(new LineBorder(Color.black));
+    JLabel minText = new JLabel(MessageManager.getString("label.min"));
+    minText.setFont(JvSwingUtils.getLabelFont());
+    JLabel maxText = new JLabel(MessageManager.getString("label.max"));
+    maxText.setFont(JvSwingUtils.getLabelFont());
 
     JPanel colourPanel = new JPanel();
     colourPanel.setBackground(Color.white);
-    jPanel1.add(ok);
-    jPanel1.add(cancel);
-    jPanel2.add(colourByLabel, BorderLayout.WEST);
-    jPanel2.add(colourPanel, BorderLayout.EAST);
     colourPanel.add(minText);
     colourPanel.add(minColour);
     colourPanel.add(maxText);
     colourPanel.add(maxColour);
-    this.add(jPanel3, BorderLayout.CENTER);
-    jPanel3.add(threshold);
-    jPanel3.add(slider);
-    jPanel3.add(thresholdValue);
-    jPanel3.add(thresholdIsMin);
-    this.add(jPanel1, BorderLayout.SOUTH);
-    this.add(jPanel2, BorderLayout.NORTH);
+    colourByPanel.add(colourByLabel, BorderLayout.WEST);
+    colourByPanel.add(colourPanel, BorderLayout.EAST);
+
+    colourByLabel.setBackground(Color.white);
+    colourByLabel
+            .setText(MessageManager.getString("label.colour_by_label"));
+    colourByLabel
+            .setToolTipText(MessageManager
+                    .getString("label.display_features_same_type_different_label_using_different_colour"));
+    colourByLabel.addActionListener(new ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent actionEvent)
+      {
+        changeColour(true);
+      }
+    });
+
+    return colourByPanel;
   }
 
   /**
@@ -505,6 +546,7 @@ public class FeatureColourChooser extends JalviewDialog
       maxColour.setForeground(oldmaxColour);
       minColour.setForeground(oldminColour);
     }
+
     fr.setColour(type, acg);
     cs = acg;
     ap.paintAlignment(updateStructsAndOverview, updateStructsAndOverview);
@@ -544,14 +586,6 @@ public class FeatureColourChooser extends JalviewDialog
   }
 
   /**
-   * Action on change of choice of No / Above / Below Threshold
-   */
-  protected void threshold_actionPerformed()
-  {
-    changeColour(true);
-  }
-
-  /**
    * Action on text entry of a threshold value
    */
   protected void thresholdValue_actionPerformed()
@@ -594,16 +628,6 @@ public class FeatureColourChooser extends JalviewDialog
     changeColour(false);
   }
 
-  protected void thresholdIsMin_actionPerformed()
-  {
-    changeColour(true);
-  }
-
-  protected void colourByLabel_actionPerformed()
-  {
-    changeColour(true);
-  }
-
   void addActionListener(ActionListener graduatedColorEditor)
   {
     if (colourEditor != null)