JAL-2738 copy to spikes/mungo
[jalview.git] / src / jalview / jbgui / GSliderPanel.java
index 07cfc23..356c294 100755 (executable)
@@ -1,27 +1,46 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
- * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
  * 
  * This file is part of Jalview.
  * 
  * Jalview is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License 
- * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
  *  
  * Jalview is distributed in the hope that it will be useful, but 
  * WITHOUT ANY WARRANTY; without even the implied warranty 
  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
  * PURPOSE.  See the GNU General Public License for more details.
  * 
- * You should have received a copy of the GNU General Public License along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
  */
 package jalview.jbgui;
 
 import jalview.util.MessageManager;
 
-import java.awt.*;
-import java.awt.event.*;
-import javax.swing.*;
+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;
+import java.awt.event.FocusEvent;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+
+import javax.swing.JButton;
+import javax.swing.JCheckBox;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JSlider;
+import javax.swing.JTextField;
+import javax.swing.SwingConstants;
 
 /**
  * DOCUMENT ME!
@@ -89,6 +108,7 @@ public class GSliderPanel extends JPanel
     slider.setDoubleBuffered(true);
     slider.addMouseListener(new MouseAdapter()
     {
+      @Override
       public void mouseReleased(MouseEvent e)
       {
         slider_mouseReleased(e);
@@ -99,11 +119,20 @@ public class GSliderPanel extends JPanel
     valueField.setPreferredSize(new Dimension(50, 12));
     valueField.setText("");
     valueField.setHorizontalAlignment(SwingConstants.CENTER);
-    valueField.addActionListener(new java.awt.event.ActionListener()
+    valueField.addActionListener(new ActionListener()
     {
+      @Override
       public void actionPerformed(ActionEvent e)
       {
-        valueField_actionPerformed(e);
+        valueField_actionPerformed();
+      }
+    });
+    valueField.addFocusListener(new FocusAdapter()
+    {
+      @Override
+      public void focusLost(FocusEvent e)
+      {
+        valueField_actionPerformed();
       }
     });
     label.setFont(new java.awt.Font("Verdana", 0, 11));
@@ -118,6 +147,7 @@ public class GSliderPanel extends JPanel
     applyButton.setText(MessageManager.getString("action.apply"));
     applyButton.addActionListener(new java.awt.event.ActionListener()
     {
+      @Override
       public void actionPerformed(ActionEvent e)
       {
         applyButton_actionPerformed(e);
@@ -129,6 +159,7 @@ public class GSliderPanel extends JPanel
     undoButton.setText(MessageManager.getString("action.undo"));
     undoButton.addActionListener(new java.awt.event.ActionListener()
     {
+      @Override
       public void actionPerformed(ActionEvent e)
       {
         undoButton_actionPerformed(e);
@@ -137,9 +168,11 @@ public class GSliderPanel extends JPanel
     allGroupsCheck.setEnabled(false);
     allGroupsCheck.setFont(new java.awt.Font("Verdana", 0, 11));
     allGroupsCheck.setOpaque(false);
-    allGroupsCheck.setText(MessageManager.getString("action.apply_all_groups"));
+    allGroupsCheck
+            .setText(MessageManager.getString("action.apply_all_groups"));
     allGroupsCheck.addActionListener(new java.awt.event.ActionListener()
     {
+      @Override
       public void actionPerformed(ActionEvent e)
       {
         allGroupsCheck_actionPerformed(e);
@@ -163,13 +196,18 @@ public class GSliderPanel extends JPanel
   }
 
   /**
-   * DOCUMENT ME!
-   * 
-   * @param e
-   *          DOCUMENT ME!
+   * Action on changing the slider text field value
    */
-  protected void valueField_actionPerformed(ActionEvent e)
+  protected void valueField_actionPerformed()
   {
+    try
+    {
+      int i = Integer.valueOf(valueField.getText());
+      slider.setValue(i);
+    } catch (NumberFormatException ex)
+    {
+      valueField.setText(String.valueOf(slider.getValue()));
+    }
   }
 
   /**