Class AbstractRecentItemsHandler<M,​T>

    • Field Detail

      • m_PropertiesFile

        protected String m_PropertiesFile
        the props file to use.
      • m_PropertyPrefix

        protected String m_PropertyPrefix
        the prefix for the properties.
      • m_MaxCount

        protected int m_MaxCount
        the maximum number of items to keep.
      • m_AddShortcuts

        protected boolean m_AddShortcuts
        whether to add keyboard shortcuts.
      • m_Menu

        protected M m_Menu
        the menu to add the items as sub-items to.
      • m_RecentItems

        protected List<T> m_RecentItems
        the items.
      • m_IgnoreChanges

        protected boolean m_IgnoreChanges
        whether to ignore changes temporarily.
    • Constructor Detail

      • AbstractRecentItemsHandler

        public AbstractRecentItemsHandler​(String propsFile,
                                          M menu)
        Initializes the handler with a maximum of 5 items.
        Parameters:
        propsFile - the props file to store the items in
        menu - the menu to add the recent items as subitems to
      • AbstractRecentItemsHandler

        public AbstractRecentItemsHandler​(String propsFile,
                                          int maxCount,
                                          M menu)
        Initializes the handler.
        Parameters:
        propsFile - the props file to store the items in
        maxCount - the maximum number of items to keep in menu
        menu - the menu to add the recent items as subitems to
      • AbstractRecentItemsHandler

        public AbstractRecentItemsHandler​(String propsFile,
                                          String propPrefix,
                                          int maxCount,
                                          M menu)
        Initializes the handler.
        Parameters:
        propsFile - the props file to store the items in
        propPrefix - the properties prefix, use null to ignore
        maxCount - the maximum number of items to keep in menu
        menu - the menu to add the recent items as subitems to
    • Method Detail

      • getPropertiesFile

        public String getPropertiesFile()
        Returns the props file used to store the recent items in.
        Returns:
        the filename
      • getPropertyPrefix

        public String getPropertyPrefix()
        Returns the prefix for the property names.
        Returns:
        the prefix
      • getMaxCount

        public int getMaxCount()
        Returns the maximum number of items to keep.
        Returns:
        the maximum number
      • setAddShortcuts

        public void setAddShortcuts​(boolean value)
        Sets whether to add shortcuts to the menu.
        Parameters:
        value - true if to add shortcuts
      • getAddShortcuts

        public boolean getAddShortcuts()
        Returns whether to add shortcuts to the menu.
        Returns:
        true if to add shortcuts
      • getMenu

        public M getMenu()
        Returns the menu to add the recent items as subitems to.
        Returns:
        the menu
      • getCountKey

        protected abstract String getCountKey()
        Returns the key to use for the counts in the props file.
        Returns:
        the key
      • getItemPrefix

        protected abstract String getItemPrefix()
        Returns the key prefix to use for the items in the props file.
        Returns:
        the prefix
      • toString

        protected abstract String toString​(T obj)
        Turns an object into a string for storing in the props.
        Parameters:
        obj - the object to convert
        Returns:
        the string representation
      • fromString

        protected abstract T fromString​(String s)
        Turns the string obtained from the props into an object again.
        Parameters:
        s - the string representation
        Returns:
        the parsed object
      • expand

        protected String expand​(String property)
        Adds the prefix to the property name if provided.
        Parameters:
        property - the property to expand
        Returns:
        the expanded property name
      • loadProps

        protected Properties loadProps()
        Loads the properties file from disk, if possible.
        Returns:
        the properties file
      • check

        protected boolean check​(T item)
        Checks the item after obtaining from the props file.

        Default implementation performs no checks and always returns true.
        Parameters:
        item - the item to check
        Returns:
        true if checks passed
      • readProps

        protected void readProps()
        Reads the recent items from the props file.
      • writeProps

        protected void writeProps()
        Writes the current recent items back to the props file.
      • preUpdateMenu

        protected void preUpdateMenu()
        Hook method which gets executed just before the menu gets updated.

        Default implementation does nothing.
      • createMenuItemText

        protected abstract String createMenuItemText​(int index,
                                                     T item)
        Generates the text for the menuitem.
        Parameters:
        index - the index of the item
        item - the item itself
        Returns:
        the generated text
      • doUpdateMenu

        protected void doUpdateMenu()
        Updates the menu.
      • postUpdateMenu

        protected void postUpdateMenu()
        Hook method which gets executed just after the menu was updated.

        Default implementation does nothing.
      • updateMenu

        protected void updateMenu()
        Updates the menu with the currently stored recent files.
      • addRecentItem

        public void addRecentItem​(T item)
        Adds the item to the internal list.
        Parameters:
        item - the item to add to the list
      • removeRecentItem

        public void removeRecentItem​(T item)
        Removes the item from the internal list, e.g., if it no longer exists on disk.
        Parameters:
        item - the item to remove from the list
      • removeAll

        public void removeAll()
        Removes all items from the internal list.
      • getRecentItems

        public List<T> getRecentItems()
        Returns the currently stored recent items.
        Returns:
        the items
      • size

        public int size()
        Returns the number of recent items currently stored.
        Returns:
        the number of items
      • addRecentItemListener

        public void addRecentItemListener​(RecentItemListener<M,​T> l)
        Adds the listener to the internal list.
        Parameters:
        l - the listener to add
      • removeRecentItemListener

        public void removeRecentItemListener​(RecentItemListener<M,​T> l)
        Removes the listener from the internal list.
        Parameters:
        l - the listener to remove
      • notifyRecentItemListenersOfAdd

        protected void notifyRecentItemListenersOfAdd​(T item)
        Notifies the listeners of a item that got added.
        Parameters:
        item - the affected item
      • notifyRecentItemListenersOfSelect

        protected void notifyRecentItemListenersOfSelect​(T item)
        Notifies the listeners of a item that got selected.
        Parameters:
        item - the affected item