X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2Fcache%2FJvCacheableInputBox.java;h=beef3e77a2df3a8b7e5d6e96ad348290ba68f0a1;hb=20a4d7ddb86ee996f2b6617a0470922b83354c35;hp=a837512c9d76d14dd905cfb4023b10c1a93dbba7;hpb=adc777ea521b25d7daf841dd0fd9a88266a93baf;p=jalview.git diff --git a/src/jalview/io/cache/JvCacheableInputBox.java b/src/jalview/io/cache/JvCacheableInputBox.java index a837512..beef3e7 100644 --- a/src/jalview/io/cache/JvCacheableInputBox.java +++ b/src/jalview/io/cache/JvCacheableInputBox.java @@ -23,8 +23,6 @@ package jalview.io.cache; import jalview.bin.Cache; import jalview.util.MessageManager; -import java.awt.Color; -import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyEvent; @@ -36,37 +34,22 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.Set; -import javax.swing.BorderFactory; import javax.swing.JComboBox; -import javax.swing.JLabel; import javax.swing.JMenuItem; -import javax.swing.JPanel; import javax.swing.JPopupMenu; -import javax.swing.JTextField; import javax.swing.SwingUtilities; -import javax.swing.text.AttributeSet; -import javax.swing.text.BadLocationException; -import javax.swing.text.PlainDocument; public class JvCacheableInputBox extends JComboBox { private static final long serialVersionUID = 5774610435079326695L; - private static final int INPUT_LIMIT = 2; - private static final int LEFT_BOARDER_WIDTH = 16; private String cacheKey; private AppCache appCache; - private JPanel pnlDefaultCache = new JPanel(); - - private JLabel lblDefaultCacheSize = new JLabel(); - - private JTextField txtDefaultCacheSize = new JTextField(); - private JPopupMenu popup = new JPopupMenu(); private JMenuItem menuItemClearCache = new JMenuItem(); @@ -123,8 +106,8 @@ public class JvCacheableInputBox extends JComboBox } /** - * Method for initialising cache items for a given cache key and populating - * the in-memory cache with persisted cache items + * Method for initialising cache items for a given cache key and populating the + * in-memory cache with persisted cache items * * @param cacheKey */ @@ -144,7 +127,7 @@ public class JvCacheableInputBox extends JComboBox .getAllCachedItemsFor(cacheKey); if (foundCacheItems == null) { - foundCacheItems = new LinkedHashSet(); + foundCacheItems = new LinkedHashSet<>(); } // populate memory cache for (String cacheItem : persistedCacheItems) @@ -159,48 +142,7 @@ public class JvCacheableInputBox extends JComboBox */ private void initCachePopupMenu() { - pnlDefaultCache.setBackground(Color.WHITE); - // pad panel so as to align with other menu items - 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() - { - private static final long serialVersionUID = 1L; - - @Override - public void insertString(int offs, String str, AttributeSet a) - throws BadLocationException - { - if (getLength() + str.length() <= INPUT_LIMIT && isInteger(str)) - { - super.insertString(offs, str, a); - } - } - }); - 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")); menuItemClearCache.addActionListener(new ActionListener() @@ -215,18 +157,11 @@ public class JvCacheableInputBox extends JComboBox } }); - popup.insert(pnlDefaultCache, 0); popup.add(menuItemClearCache); setComponentPopupMenu(popup); add(popup); } - private void closePopup() - { - popup.setVisible(false); - popup.transferFocus(); - } - /** * Answers true if input text is an integer * @@ -255,10 +190,7 @@ public class JvCacheableInputBox extends JComboBox @Override public void run() { - int userLimit = txtDefaultCacheSize.getText().trim().isEmpty() - ? Integer.valueOf(AppCache.DEFAULT_LIMIT) - : Integer.valueOf(txtDefaultCacheSize.getText()); - int cacheLimit = appCache.updateCacheLimit(cacheKey, userLimit); + int cacheLimit = Integer.parseInt(appCache.getCacheLimit(cacheKey)); String userInput = getUserInput(); if (userInput != null && !userInput.isEmpty()) { @@ -277,7 +209,7 @@ public class JvCacheableInputBox extends JComboBox removeAllItems(); } Set cacheItems = appCache.getAllCachedItemsFor(cacheKey); - List reversedCacheItems = new ArrayList(); + List reversedCacheItems = new ArrayList<>(); reversedCacheItems.addAll(cacheItems); cacheItems = null; Collections.reverse(reversedCacheItems); @@ -326,10 +258,6 @@ public class JvCacheableInputBox extends JComboBox public void persistCache() { appCache.persistCache(cacheKey); - int userLimit = txtDefaultCacheSize.getText().trim().isEmpty() - ? Integer.valueOf(AppCache.DEFAULT_LIMIT) - : Integer.valueOf(txtDefaultCacheSize.getText()); - appCache.updateCacheLimit(cacheKey, userLimit); } /**