JAL-1648 improvements: enter key closes the popup and updates cache immidately, unifo...
authortcofoegbu <tcnofoegbu@dundee.ac.uk>
Thu, 4 May 2017 18:22:16 +0000 (19:22 +0100)
committertcofoegbu <tcnofoegbu@dundee.ac.uk>
Thu, 4 May 2017 18:22:16 +0000 (19:22 +0100)
src/jalview/io/cache/JvCacheableInputBox.java

index 06302c3..499654c 100644 (file)
@@ -7,6 +7,7 @@ import java.awt.Color;
 import java.awt.Dimension;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
+import java.awt.event.KeyEvent;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
@@ -33,7 +34,7 @@ public class JvCacheableInputBox<E> extends JComboBox<String>
 
   private static final int INPUT_LIMIT = 2;
 
-  private static final int LEFT_BOARDER_WIDTH = 2;
+  private static final int LEFT_BOARDER_WIDTH = 18;
 
   private String cacheKey;
 
@@ -80,7 +81,7 @@ public class JvCacheableInputBox<E> extends JComboBox<String>
             .split(AppCache.CACHE_DELIMITER));
 
     LinkedHashSet<String> foundCacheItems = appCache
-            .getAllCachedItemsFor(cacheKey);// cacheItems.get(cacheKey);
+            .getAllCachedItemsFor(cacheKey);
     if (foundCacheItems == null)
     {
       foundCacheItems = new LinkedHashSet<String>();
@@ -103,8 +104,10 @@ public class JvCacheableInputBox<E> extends JComboBox<String>
     pnlDefaultCache.setBorder(BorderFactory.createEmptyBorder(0,
             LEFT_BOARDER_WIDTH, 0, 0));
     txtDefaultCacheSize.setPreferredSize(new Dimension(45, 20));
+    txtDefaultCacheSize.setFont(new java.awt.Font("Verdana", 0, 12));
     lblDefaultCacheSize.setText(MessageManager
             .getString("label.default_cache_size"));
+    lblDefaultCacheSize.setFont(new java.awt.Font("Verdana", 0, 12));
     // Force input to accept only Integer entries up to length - INPUT_LIMIT
     txtDefaultCacheSize.setDocument(new PlainDocument()
     {
@@ -120,8 +123,23 @@ public class JvCacheableInputBox<E> extends JComboBox<String>
         }
       }
     });
+    txtDefaultCacheSize.addKeyListener(new java.awt.event.KeyAdapter()
+    {
+      @Override
+      public void keyPressed(KeyEvent e)
+      {
+        if (e.getKeyCode() == KeyEvent.VK_ENTER)
+        {
+          e.consume();
+          updateCache();
+          closePopup();
+        }
+      }
+    });
+
     txtDefaultCacheSize.setText(appCache.getCacheLimit(cacheKey));
     pnlDefaultCache.add(lblDefaultCacheSize);
+    menuItemClearCache.setFont(new java.awt.Font("Verdana", 0, 12));
     pnlDefaultCache.add(txtDefaultCacheSize);
     menuItemClearCache.setText(MessageManager
             .getString("action.clear_cached_items"));
@@ -143,6 +161,12 @@ public class JvCacheableInputBox<E> extends JComboBox<String>
     add(popup);
   }
 
+  private void closePopup()
+  {
+    popup.setVisible(false);
+    popup.transferFocus();
+  }
+
   /**
    * Answers true if input text is an integer
    *