JAL-1648 made further abstraction and createda new interface CacheBox in order to...
authortcofoegbu <tcnofoegbu@dundee.ac.uk>
Fri, 2 Dec 2016 12:24:55 +0000 (12:24 +0000)
committertcofoegbu <tcnofoegbu@dundee.ac.uk>
Fri, 2 Dec 2016 12:24:55 +0000 (12:24 +0000)
src/jalview/fts/core/GFTSPanel.java
src/jalview/fts/service/pdb/PDBFTSPanel.java
src/jalview/io/cache/AppCache.java
src/jalview/io/cache/CacheBoxI.java [new file with mode: 0644]
src/jalview/io/cache/Cacheable.java
src/jalview/jbgui/GFinder.java

index a581717..5425f5d 100644 (file)
@@ -29,6 +29,7 @@ import jalview.gui.IProgressIndicator;
 import jalview.gui.JvSwingUtils;
 import jalview.gui.SequenceFetcher;
 import jalview.io.cache.AppCache;
+import jalview.io.cache.CacheBoxI;
 import jalview.io.cache.Cacheable;
 import jalview.util.MessageManager;
 
@@ -58,7 +59,6 @@ import java.util.List;
 import javax.swing.ImageIcon;
 import javax.swing.JButton;
 import javax.swing.JComboBox;
-import javax.swing.JComponent;
 import javax.swing.JFrame;
 import javax.swing.JInternalFrame;
 import javax.swing.JLabel;
@@ -1005,11 +1005,6 @@ public abstract class GFTSPanel extends JPanel implements GFTSPanelI, Cacheable
     // reset();
   }
 
-  @Override
-  public JComponent getNextFocusableElement()
-  {
-    return mainFrame;
-  }
 
   @Override
   public String getCacheKey()
@@ -1018,10 +1013,56 @@ public abstract class GFTSPanel extends JPanel implements GFTSPanelI, Cacheable
   }
 
   @Override
-  public JComboBox<String> getCacheComboBox()
+  public CacheBoxI<String> getCacheComboBox()
   {
-    return txt_search;
+    return new CacheBoxI<String>()
+    {
+
+      @Override
+      public void setSelectedItem(Object anObject)
+      {
+        txt_search.setSelectedItem(anObject);
+      }
+
+      @Override
+      public void requestFocus()
+      {
+        txt_search.requestFocusInWindow();
+      }
+
+      @Override
+      public void looseFocus()
+      {
+        mainFrame.requestFocusInWindow();
+      }
+
+      @Override
+      public void addItem(String item)
+      {
+        txt_search.addItem(item);
+      }
+
+      @Override
+      public void removeAllItems()
+      {
+        txt_search.removeAllItems();
+      }
+
+      @Override
+      public int getItemCount()
+      {
+        return txt_search.getItemCount();
+      }
+
+      @Override
+      public String getUserInput()
+      {
+        return txt_search.getEditor().getItem() == null ? "" : txt_search
+                .getEditor().getItem().toString().trim();
+      }
+    };
   }
 
 
+
 }
index 66b8261..5a747be 100644 (file)
@@ -284,4 +284,5 @@ public class PDBFTSPanel extends GFTSPanel
     return PDB_FTS_CACHE_KEY;
   }
 
+
 }
index 9201341..111a99b 100644 (file)
@@ -5,9 +5,6 @@ import java.util.Hashtable;
 import java.util.LinkedHashSet;
 import java.util.Set;
 
-import javax.swing.JComboBox;
-import javax.swing.JComponent;
-
 public class AppCache implements AppCacheI
 {
   private static AppCache instance = null;
@@ -44,11 +41,10 @@ public class AppCache implements AppCacheI
   @Override
   public void updateCache(Cacheable cacheable)
   {
-    JComboBox<String> cacheComboBox = cacheable.getCacheComboBox();
+    CacheBoxI<String> cacheComboBox = cacheable.getCacheComboBox();
     String cacheKey = cacheable.getCacheKey();
-    JComponent nextFocusableComponent = cacheable.getNextFocusableElement();
-    String userInput = cacheComboBox.getEditor().getItem() == null ? ""
-            : cacheComboBox.getEditor().getItem().toString().trim();
+    cacheComboBox.looseFocus();
+    String userInput = cacheComboBox.getUserInput();
 
     if (userInput != null && !userInput.isEmpty())
     {
@@ -58,7 +54,6 @@ public class AppCache implements AppCacheI
     }
 
     String lastSearch = userInput;
-    nextFocusableComponent.requestFocusInWindow();
     if (cacheComboBox.getItemCount() > 0)
     {
       cacheComboBox.removeAllItems();
diff --git a/src/jalview/io/cache/CacheBoxI.java b/src/jalview/io/cache/CacheBoxI.java
new file mode 100644 (file)
index 0000000..c9b65fe
--- /dev/null
@@ -0,0 +1,18 @@
+package jalview.io.cache;
+
+public interface CacheBoxI<E>
+{
+  public void setSelectedItem(Object anObject);
+
+  public void requestFocus();
+
+  public void looseFocus();
+
+  public void addItem(E item);
+
+  public void removeAllItems();
+
+  public int getItemCount();
+
+  public String getUserInput();
+}
index d17cab4..9aa0a0a 100644 (file)
@@ -1,7 +1,5 @@
 package jalview.io.cache;
 
-import javax.swing.JComboBox;
-import javax.swing.JComponent;
 
 public interface Cacheable
 {
@@ -16,7 +14,7 @@ public interface Cacheable
    * 
    * @return
    */
-  public JComboBox<String> getCacheComboBox();
+  public CacheBoxI<String> getCacheComboBox();
 
   /**
    * The unique key that will be used for storing user input for this cacheable
@@ -26,12 +24,5 @@ public interface Cacheable
    */
   public String getCacheKey();
 
-  /**
-   * Get next focusable component. Required to delegate focus while updating the
-   * cacheable component cache
-   * 
-   * @return
-   */
-  public JComponent getNextFocusableElement();
 
 }
index 76f75e1..e5d760c 100755 (executable)
@@ -25,6 +25,7 @@ import jalview.io.DataSourceType;
 import jalview.io.FileFormat;
 import jalview.io.FormatAdapter;
 import jalview.io.cache.AppCache;
+import jalview.io.cache.CacheBoxI;
 import jalview.io.cache.Cacheable;
 import jalview.util.MessageManager;
 
@@ -39,7 +40,6 @@ import java.awt.event.KeyEvent;
 import javax.swing.JButton;
 import javax.swing.JCheckBox;
 import javax.swing.JComboBox;
-import javax.swing.JComponent;
 import javax.swing.JLabel;
 import javax.swing.JPanel;
 import javax.swing.SwingConstants;
@@ -62,7 +62,6 @@ public class GFinder extends JPanel implements Cacheable
 
   protected JButton createNewGroup = new JButton();
 
-
   protected JComboBox<String> searchBox = new JComboBox<String>();
 
   BorderLayout mainBorderLayout = new BorderLayout();
@@ -260,9 +259,54 @@ public class GFinder extends JPanel implements Cacheable
   }
 
   @Override
-  public JComboBox<String> getCacheComboBox()
+  public CacheBoxI<String> getCacheComboBox()
   {
-    return searchBox;
+    return new CacheBoxI<String>()
+    {
+
+      @Override
+      public void setSelectedItem(Object anObject)
+      {
+        searchBox.setSelectedItem(anObject);
+      }
+
+      @Override
+      public void requestFocus()
+      {
+        searchBox.requestFocusInWindow();
+      }
+
+      @Override
+      public void looseFocus()
+      {
+        jPanel6.requestFocusInWindow();
+      }
+
+      @Override
+      public void addItem(String item)
+      {
+        searchBox.addItem(item);
+      }
+
+      @Override
+      public void removeAllItems()
+      {
+        searchBox.removeAllItems();
+      }
+
+      @Override
+      public int getItemCount()
+      {
+        return searchBox.getItemCount();
+      }
+
+      @Override
+      public String getUserInput()
+      {
+        return searchBox.getEditor().getItem() == null ? "" : searchBox
+                .getEditor().getItem().toString().trim();
+      }
+    };
   }
 
   @Override
@@ -271,9 +315,4 @@ public class GFinder extends JPanel implements Cacheable
     return FINDER_CACHE_KEY;
   }
 
-  @Override
-  public JComponent getNextFocusableElement()
-  {
-    return this;
-  }
 }