1 package jalview.io.cache;
4 import java.util.Hashtable;
5 import java.util.LinkedHashSet;
8 public class AppCache implements AppCacheI
10 private static AppCache instance = null;
12 private Hashtable<String, LinkedHashSet<String>> cacheItems;
16 cacheItems = new Hashtable<String, LinkedHashSet<String>>();
20 public LinkedHashSet<String> getAllCachedItemsFor(String cacheKey)
22 LinkedHashSet<String> foundCache = cacheItems.get(cacheKey);
23 if (foundCache == null)
25 foundCache = new LinkedHashSet<String>();
26 cacheItems.put(cacheKey, foundCache);
32 public static AppCache getInstance()
36 instance = new AppCache();
42 public void updateCache(Cacheable cacheable)
44 CacheBoxI<String> cacheComboBox = cacheable.getCacheComboBox();
45 String cacheKey = cacheable.getCacheKey();
46 cacheComboBox.looseFocus();
47 String userInput = cacheComboBox.getUserInput();
49 if (userInput != null && !userInput.isEmpty())
51 LinkedHashSet<String> foundCache = getAllCachedItemsFor(cacheKey);
52 foundCache.add(userInput);
53 cacheItems.put(cacheKey, foundCache);
56 String lastSearch = userInput;
57 if (cacheComboBox.getItemCount() > 0)
59 cacheComboBox.removeAllItems();
62 Set<String> cacheItems = getAllCachedItemsFor(cacheKey);
63 if (cacheItems != null && !cacheItems.isEmpty())
65 for (String cacheItem : cacheItems)
67 cacheComboBox.addItem(cacheItem);
71 if (!lastSearch.isEmpty())
73 cacheComboBox.setSelectedItem(lastSearch);
74 cacheComboBox.requestFocus();
79 cacheComboBox.addItem("");
80 cacheComboBox.setSelectedItem("");