JAL-1663 detect tab out of RGB value; correct field tab order
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Mon, 18 May 2015 12:39:34 +0000 (13:39 +0100)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Mon, 18 May 2015 12:39:34 +0000 (13:39 +0100)
src/jalview/appletgui/UserDefinedColours.java

index 342c065..277bd55 100644 (file)
  */
 package jalview.appletgui;
 
-import jalview.datamodel.SequenceGroup;
-import jalview.schemes.ColourSchemeI;
-import jalview.schemes.GraduatedColor;
-import jalview.schemes.ResidueProperties;
-import jalview.schemes.UserColourScheme;
-import jalview.util.MessageManager;
-
 import java.awt.Button;
 import java.awt.Color;
 import java.awt.Component;
@@ -44,11 +37,20 @@ import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.awt.event.AdjustmentEvent;
 import java.awt.event.AdjustmentListener;
+import java.awt.event.FocusEvent;
+import java.awt.event.FocusListener;
 import java.awt.event.MouseEvent;
 import java.util.Vector;
 
+import jalview.datamodel.SequenceGroup;
+import jalview.schemes.ColourSchemeI;
+import jalview.schemes.GraduatedColor;
+import jalview.schemes.ResidueProperties;
+import jalview.schemes.UserColourScheme;
+import jalview.util.MessageManager;
+
 public class UserDefinedColours extends Panel implements ActionListener,
-        AdjustmentListener
+        AdjustmentListener, FocusListener
 {
 
   AlignmentPanel ap;
@@ -225,27 +227,28 @@ public class UserDefinedColours extends Panel implements ActionListener,
 
   public void actionPerformed(ActionEvent evt)
   {
-    if (evt.getSource() == okButton)
+    final Object source = evt.getSource();
+    if (source == okButton)
     {
       okButton_actionPerformed();
     }
-    else if (evt.getSource() == applyButton)
+    else if (source == applyButton)
     {
       applyButton_actionPerformed();
     }
-    else if (evt.getSource() == cancelButton)
+    else if (source == cancelButton)
     {
       cancelButton_actionPerformed();
     }
-    else if (evt.getSource() == rText)
+    else if (source == rText)
     {
       rText_actionPerformed();
     }
-    else if (evt.getSource() == gText)
+    else if (source == gText)
     {
       gText_actionPerformed();
     }
-    else if (evt.getSource() == bText)
+    else if (source == bText)
     {
       bText_actionPerformed();
     }
@@ -664,6 +667,7 @@ public class UserDefinedColours extends Panel implements ActionListener,
     rText.setText("0        ");
     rText.setBounds(new Rectangle(156, 27, 53, 19));
     rText.addActionListener(this);
+    rText.addFocusListener(this);
     label4.setAlignment(Label.RIGHT);
     label4.setText("G");
     label4.setBounds(new Rectangle(15, 56, 20, 15));
@@ -678,6 +682,7 @@ public class UserDefinedColours extends Panel implements ActionListener,
     gText.setText("0        ");
     gText.setBounds(new Rectangle(156, 52, 53, 20));
     gText.addActionListener(this);
+    gText.addFocusListener(this);
     label5.setAlignment(Label.RIGHT);
     label5.setText("B");
     label5.setBounds(new Rectangle(14, 82, 20, 15));
@@ -692,12 +697,16 @@ public class UserDefinedColours extends Panel implements ActionListener,
     bText.setText("0        ");
     bText.setBounds(new Rectangle(157, 78, 52, 20));
     bText.addActionListener(this);
+    bText.addFocusListener(this);
     target.setBackground(Color.black);
     target.setBounds(new Rectangle(229, 26, 134, 79));
     this.add(okcancelPanel, null);
     okcancelPanel.add(okButton, null);
     okcancelPanel.add(applyButton, null);
     okcancelPanel.add(cancelButton, null);
+    this.add(rText);
+    this.add(gText);
+    this.add(bText);
     this.add(buttonPanel, null);
     this.add(target, null);
     this.add(gScroller);
@@ -706,9 +715,40 @@ public class UserDefinedColours extends Panel implements ActionListener,
     this.add(label5);
     this.add(label4);
     this.add(label1);
-    this.add(gText);
-    this.add(rText);
-    this.add(bText);
+  }
+
+  @Override
+  public void focusGained(FocusEvent e)
+  {
+    // noop
+  }
+
+  /**
+   * This method applies any change to an RGB value if the user tabs out of the
+   * field instead of pressing Enter
+   */
+  @Override
+  public void focusLost(FocusEvent e)
+  {
+    Component c = e.getComponent();
+    if (c == rText)
+    {
+      rText_actionPerformed();
+    }
+    else
+    {
+      if (c == gText)
+      {
+        gText_actionPerformed();
+      }
+      else
+      {
+        if (c == bText)
+        {
+          bText_actionPerformed();
+        }
+      }
+    }
   }
 
 }