getTempUserPrefs().put("FTSPanel.x", mainFrame.getX());
getTempUserPrefs().put("FTSPanel.y", mainFrame.getY());
mainFrame.dispose();
+ AppCache.getInstance().persistCache(this);
}
public class DeferredTextInputListener implements DocumentListener
mainFrame.setTitle(getFTSFrameTitle());
}
-
- protected void fireCache()
+ @Override
+ public void initCache()
{
- AppCache.getInstance().updateCache(this);
+ AppCache.getInstance().initCache(this);
}
@Override
- public void init()
+ public void updateCache()
{
- // reset();
+ AppCache.getInstance().updateCache(this);
}
+
@Override
public String getCacheKey()
{
private static Map<String, Integer> tempUserPrefs = new HashMap<String, Integer>();
- private static final String PDB_FTS_CACHE_KEY = "PDB_FTS_CACHE_KEY";
+ private static final String PDB_FTS_CACHE_KEY = "CACHE.PDB_FTS";
public PDBFTSPanel(SequenceFetcher seqFetcher)
{
this.seqFetcher = seqFetcher;
this.progressIndicator = (seqFetcher == null) ? null : seqFetcher
.getProgressIndicator();
- fireCache();
+ initCache();
}
@Override
refreshPaginatorState();
updateSummaryTableSelections();
}
- fireCache();
+ updateCache();
}
}.start();
}
private static Map<String, Integer> tempUserPrefs = new HashMap<String, Integer>();
- private static final String UNIPROT_FTS_CACHE_KEY = "UNIPROT_FTS_CACHE_KEY";
+ private static final String UNIPROT_FTS_CACHE_KEY = "CACHE.UNIPROT_FTS";
public UniprotFTSPanel(SequenceFetcher seqFetcher)
{
this.seqFetcher = seqFetcher;
this.progressIndicator = (seqFetcher == null) ? null : seqFetcher
.getProgressIndicator();
- fireCache();
+ initCache();
}
@Override
refreshPaginatorState();
updateSummaryTableSelections();
}
- fireCache();
+ updateCache();
}
}.start();
import jalview.datamodel.SearchResultsI;
import jalview.datamodel.SequenceFeature;
import jalview.datamodel.SequenceI;
+import jalview.io.cache.AppCache;
import jalview.jbgui.GFinder;
import jalview.util.MessageManager;
import jalview.viewmodel.AlignmentViewport;
import javax.swing.JInternalFrame;
import javax.swing.JLayeredPane;
import javax.swing.KeyStroke;
+import javax.swing.event.InternalFrameEvent;
/**
* Performs the menu option for searching the alignment, for the next or all
{
this(null, null);
focusfixed = false;
+ initCache();
}
/**
frame = new JInternalFrame();
frame.setContentPane(this);
frame.setLayer(JLayeredPane.PALETTE_LAYER);
+ frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
+ {
+ @Override
+ public void internalFrameClosing(InternalFrameEvent e)
+ {
+ closeAction();
+ }
+ });
addEscapeHandler();
Desktop.addInternalFrame(frame, MessageManager.getString("label.find"),
WIDTH, HEIGHT);
seqIndex = 0;
}
}
-
+ updateCache();
}
/**
}
return error;
}
+
+ protected void closeAction()
+ {
+ frame.dispose();
+ AppCache.getInstance().persistCache(this);
+ }
}
package jalview.io.cache;
+import jalview.bin.Cache;
+
+import java.util.Arrays;
import java.util.Hashtable;
import java.util.LinkedHashSet;
+import java.util.List;
import java.util.Set;
public class AppCache implements AppCacheI
private Hashtable<String, LinkedHashSet<String>> cacheItems;
+ private static final String CACHE_DELIMITER = ";";
+
private AppCache()
{
cacheItems = new Hashtable<String, LinkedHashSet<String>>();
}
@Override
- public LinkedHashSet<String> getAllCachedItemsFor(String cacheKey)
+ public LinkedHashSet<String> getAllCachedItemsFor(Cacheable cacheable)
{
+ String cacheKey = cacheable.getCacheKey();
LinkedHashSet<String> foundCache = cacheItems.get(cacheKey);
if (foundCache == null)
{
if (userInput != null && !userInput.isEmpty())
{
- LinkedHashSet<String> foundCache = getAllCachedItemsFor(cacheKey);
+ LinkedHashSet<String> foundCache = getAllCachedItemsFor(cacheable);
foundCache.add(userInput);
cacheItems.put(cacheKey, foundCache);
}
cacheComboBox.removeAllItems();
}
- Set<String> cacheItems = getAllCachedItemsFor(cacheKey);
+ Set<String> cacheItems = getAllCachedItemsFor(cacheable);
if (cacheItems != null && !cacheItems.isEmpty())
{
for (String cacheItem : cacheItems)
}
else
{
- cacheable.init();
+ cacheable.initCache();
cacheComboBox.addItem("");
cacheComboBox.setSelectedItem("");
}
}
+ @Override
+ public void initCache(Cacheable cacheable)
+ {
+ String separatedStr = Cache.getProperty(cacheable.getCacheKey());
+ if (separatedStr == null || separatedStr.isEmpty())
+ {
+ return;
+ }
+
+ List<String> persistedCacheItems = Arrays.asList(separatedStr.split(CACHE_DELIMITER));
+ String cacheKey = cacheable.getCacheKey();
+
+ LinkedHashSet<String> foundCacheItems = cacheItems.get(cacheKey);
+ if (foundCacheItems == null)
+ {
+ foundCacheItems = new LinkedHashSet<String>();
+ }
+
+ for (String cacheItem : persistedCacheItems)
+ {
+ foundCacheItems.add(cacheItem);
+ }
+ cacheItems.put(cacheKey, foundCacheItems);
+ updateCache(cacheable);
+ }
+
+ @Override
+ public void persistCache(Cacheable cacheable)
+ {
+ String cacheKey = cacheable.getCacheKey();
+ LinkedHashSet<String> foundCache = getAllCachedItemsFor(cacheable);
+ String commaJoinedStr = String.join(CACHE_DELIMITER, foundCache);
+ Cache.setProperty(cacheKey, commaJoinedStr);
+ }
}
public interface AppCacheI
{
- public Set<String> getAllCachedItemsFor(String cacheKey);
+ public void initCache(Cacheable cacheable);
public void updateCache(Cacheable cacheable);
+
+ public void persistCache(Cacheable cacheable);
+
+ public Set<String> getAllCachedItemsFor(Cacheable cacheable);
}
/**
* method executed on cache initialisation
*/
- public void init();
+ public void initCache();
+
+ /**
+ * method executed on cache update
+ */
+ public void updateCache();
/**
* Combo-box instance for the cache component
* @return
*/
public String getCacheKey();
-
-
}
GridLayout optionsGridLayout = new GridLayout();
- private static final String FINDER_CACHE_KEY = "FINDER_CACHE_KEY";
+ private static final String FINDER_CACHE_KEY = "CACHE.FINDER";
public GFinder()
{
optionsPanel.add(searchDescription, null);
jPanel4.add(optionsPanel, java.awt.BorderLayout.WEST);
- fireCache();
}
protected void findNext_actionPerformed(ActionEvent e)
{
e.consume();
findNext_actionPerformed(null);
- fireCache();
}
}
}
- protected void fireCache()
- {
- AppCache.getInstance().updateCache(this);
- }
- @Override
- public void init()
- {
- // TODO Auto-generated method stub
- }
@Override
public CacheBoxI<String> getCacheComboBox()
return FINDER_CACHE_KEY;
}
+ @Override
+ public void initCache()
+ {
+ AppCache.getInstance().initCache(this);
+ }
+
+ @Override
+ public void updateCache()
+ {
+ AppCache.getInstance().updateCache(this);
+ }
+
}