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;
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;
// reset();
}
- @Override
- public JComponent getNextFocusableElement()
- {
- return mainFrame;
- }
@Override
public String getCacheKey()
}
@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();
+ }
+ };
}
+
}
return PDB_FTS_CACHE_KEY;
}
+
}
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;
@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())
{
}
String lastSearch = userInput;
- nextFocusableComponent.requestFocusInWindow();
if (cacheComboBox.getItemCount() > 0)
{
cacheComboBox.removeAllItems();
--- /dev/null
+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();
+}
package jalview.io.cache;
-import javax.swing.JComboBox;
-import javax.swing.JComponent;
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
*/
public String getCacheKey();
- /**
- * Get next focusable component. Required to delegate focus while updating the
- * cacheable component cache
- *
- * @return
- */
- public JComponent getNextFocusableElement();
}
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;
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;
protected JButton createNewGroup = new JButton();
-
protected JComboBox<String> searchBox = new JComboBox<String>();
BorderLayout mainBorderLayout = new BorderLayout();
}
@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
return FINDER_CACHE_KEY;
}
- @Override
- public JComponent getNextFocusableElement()
- {
- return this;
- }
}