Package adams.gui.goe

Class Favorites

    • Field Detail

      • m_Properties

        protected Properties m_Properties
        the properties.
      • m_TempProperties

        protected Properties m_TempProperties
        the temporary favorites.
      • m_Modified

        protected boolean m_Modified
        whether the favorites were modified.
      • m_AutoSave

        protected boolean m_AutoSave
        whether to save the properties whenever a change happened.
      • m_Singleton

        protected static Favorites m_Singleton
        the singleton.
    • Constructor Detail

      • Favorites

        public Favorites()
        Initializes the favorites with immediate saving enabled.
      • Favorites

        public Favorites​(boolean autosave)
        Initializes the favorites.
        Parameters:
        autosave - whether to save the favorites immediately whenever modified
    • Method Detail

      • setAutoSave

        public void setAutoSave​(boolean value)
        Sets auto save to on or off.
        Parameters:
        value - if true then auto save is on
      • isAutoSave

        public boolean isAutoSave()
        Returns whether the favorites get immediately saved whenever modified.
        Returns:
        true if autosave is on
      • setModified

        public void setModified​(boolean value)
        Sets the modified state.
        Parameters:
        value - the modified state
      • isModified

        public boolean isModified()
        Returns whether the favorites are modified.
        Returns:
        true if modified
      • setProperties

        public void setProperties​(Properties value)
        Sets the properties containing the favorites to use.
        Parameters:
        value - the properties to use
      • getProperties

        public Properties getProperties()
        Returns the properties of the favorites.
        Returns:
        the properties
      • getTempProperties

        protected Properties getTempProperties()
        Returns the properties of the temp favorites.
        Returns:
        the properties
      • load

        protected void load()
        Loads the favorites.
      • clear

        public void clear()
        Removes all favorites.
      • getFavorites

        protected List<Favorites.Favorite> getFavorites​(Properties props,
                                                        Class cls)
        Returns the favorites for the specified class.
        Parameters:
        props - the properties to extract the favorites from
        cls - the class to get the favorites for, can be array classes as well
        Returns:
        the favorites
      • getFavorites

        public List<Favorites.Favorite> getFavorites​(Class cls)
        Returns the favorites for the specified class.
        Parameters:
        cls - the class to get the favorites for, can be array classes as well
        Returns:
        the favorites
      • getTempFavorites

        public List<Favorites.Favorite> getTempFavorites​(Class cls)
        Returns the temporary favorites for the specified class.
        Parameters:
        cls - the class to get the favorites for, can be array classes as well
        Returns:
        the favorites
      • getSuperclasses

        public List<String> getSuperclasses()
        Returns all the current superclasses.
        Returns:
        the classnames of the superclasses
      • fixName

        protected String fixName​(String name)
        Fixes the name by replacing all "|" with "/".
        Parameters:
        name - the name to fix
        Returns:
        the fixed name
      • createKey

        protected String createKey​(Class cls)
        Generates a properties key prefix for the class.
        Parameters:
        cls - the class to generate the key for
        Returns:
        the key
      • createFavoritesClass

        protected Class createFavoritesClass​(Class cls,
                                             boolean array)
        Creates the class for the favorite.
        Parameters:
        cls - the base class
        array - whether for an array
        Returns:
        the favorites class
      • createKey

        protected String createKey​(Class cls,
                                   String name)
        Generates a properties key for the class/name.
        Parameters:
        cls - the class to generate the key for
        name - the name to generete the key for
        Returns:
        the key
      • getFavorite

        public Favorites.Favorite getFavorite​(Class cls,
                                              boolean array,
                                              String name)
        Returns the named favorite for the specified class.
        Parameters:
        cls - the class to get the favorite for
        array - whether for an array
        name - the name of the favorite
        Returns:
        the favorite, null if not available
      • getTempFavorite

        public Favorites.Favorite getTempFavorite​(Class cls,
                                                  boolean array,
                                                  String name)
        Returns the named temporary favorite for the specified class.
        Parameters:
        cls - the class to get the favorite for
        array - whether for an array
        name - the name of the favorite
        Returns:
        the favorite, null if not available
      • addFavorite

        public void addFavorite​(Class cls,
                                Object obj,
                                String name)
        Adds a favorite for a class.
        Parameters:
        cls - the class to add the favorite for (array or not)
        obj - the favorite
        name - the name of the favorite
      • addTempFavorite

        public void addTempFavorite​(Class cls,
                                    Object obj,
                                    String name)
        Adds a temporary favorite for a class.
        Parameters:
        cls - the class to add the favorite for (array or not)
        obj - the favorite
        name - the name of the favorite
      • addFavorite

        protected void addFavorite​(Properties props,
                                   Class cls,
                                   boolean array,
                                   Object obj,
                                   String name)
        Adds a favorite for a class.
        Parameters:
        cls - the class to add the favorite for, component type for arrays
        array - whether for an array
        obj - the favorite
        name - the name of the favorite
      • addFavorite

        public void addFavorite​(Class cls,
                                boolean array,
                                Object obj,
                                String name)
        Adds a favorite for a class.
        Parameters:
        cls - the class to add the favorite for, component type for arrays
        array - whether for an array
        obj - the favorite
        name - the name of the favorite
      • addTempFavorite

        public void addTempFavorite​(Class cls,
                                    boolean array,
                                    Object obj,
                                    String name)
        Adds a temporary favorite for a class.
        Parameters:
        cls - the class to add the favorite for, component type for arrays
        array - whether for an array
        obj - the favorite
        name - the name of the favorite
      • removeFavorites

        public void removeFavorites​(String classname)
        Removes the favorites for the specified class.
        Parameters:
        classname - the class to remove the favorites for, use [] suffix for arrays
      • removeFavorites

        public void removeFavorites​(Class cls,
                                    boolean array)
        Removes the favorites for the specified class.
        Parameters:
        cls - the class to remove the favorites for
        array - whether for an array
      • removeFavorite

        public void removeFavorite​(Class cls,
                                   String name)
        Removes a favorite for a class (array or not).
        Parameters:
        cls - the class to remove the favorite for
        name - the name of the favorite
      • removeTempFavorite

        public void removeTempFavorite​(Class cls,
                                       String name)
        Removes a temporary favorite for a class (array or not).
        Parameters:
        cls - the class to remove the favorite for
        name - the name of the favorite
      • removeFavorite

        public void removeFavorite​(Class cls,
                                   boolean array,
                                   String name)
        Removes a favorite for a class.
        Parameters:
        cls - the class to remove the favorite for
        array - whether an array or not
        name - the name of the favorite
      • removeTempFavorite

        public void removeTempFavorite​(Class cls,
                                       boolean array,
                                       String name)
        Removes a temporary favorite for a class.
        Parameters:
        cls - the class to remove the favorite for
        array - whether an array or not
        name - the name of the favorite
      • getFilename

        public String getFilename()
        Returns the filename the favorites will be saved as.
        Returns:
        the filename
      • updateFavorites

        public boolean updateFavorites()
        Updates the favorites, i.e., stores the properties on disk.
        Returns:
        true if successfully saved
      • addMenuItem

        protected void addMenuItem​(Object menu,
                                   JMenuItem menuitem)
        Adds the menuitem to the menu.
        Parameters:
        menu - the JMenu or JPopupMenu to add to
        menuitem - the item to add
      • addSeparator

        protected void addSeparator​(Object menu)
        Adds a separator to the menu.
        Parameters:
        menu - the JMenu or JPopupMenu to add to
      • promptRemoval

        protected void promptRemoval​(boolean temp,
                                     Class cls,
                                     String name)
        Prompts the user whether to remove the favorite.
        Parameters:
        temp - temporary or permanent favorites
        cls - the class of the favorite (array or not)
        name - the name of the favorite
      • addFavoritesMenuItems

        protected void addFavoritesMenuItems​(boolean temp,
                                             Object menu,
                                             Class cls,
                                             Object current,
                                             Favorites.FavoriteSelectionListener listener)
        Adds menu items with the favorites (permanent or temporary) to the menu.
        Parameters:
        menu - the menu (JMenu/JPopupMenu) to add the favorites to
        cls - the class the favorites are for, can be array class as well
        current - the current object
        listener - the listener to attach to the menu items' ActionListener
      • addFavoritesMenuItems

        public void addFavoritesMenuItems​(Object menu,
                                          Class cls,
                                          Object current,
                                          Favorites.FavoriteSelectionListener listener)
        Adds a menu item with the favorites to the menu.
        Parameters:
        menu - the menu (JMenu/JPopupMenu) to add the favorites to
        cls - the class the favorites are for, can be array class as well
        current - the current object
        listener - the listener to attach to the menu items' ActionListener
      • addFavoritesSubMenu

        public void addFavoritesSubMenu​(Object menu,
                                        Class cls,
                                        Object current,
                                        Favorites.FavoriteSelectionListener listener)
        Adds a menu item with the favorites submenu to the popup menu.
        Parameters:
        menu - the menu (JMenu/JPopMenu) to add the favorites to
        cls - the class the favorites are for
        current - the current object
        listener - the listener to attach to the menu items' ActionListener
      • compareTo

        public int compareTo​(Object o)
        Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
        Specified by:
        compareTo in interface Comparable
        Parameters:
        o - the object to be compared.
        Returns:
        a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
        Throws:
        ClassCastException - if the specified object's type prevents it from being compared to this object.
      • equals

        public boolean equals​(Object obj)
        Indicates whether some other object is "equal to" this one.
        Overrides:
        equals in class Object
        Parameters:
        obj - the reference object with which to compare.
        Returns:
        true if this object is the same as the obj argument; false otherwise.
      • getSingleton

        public static Favorites getSingleton()
        Returns the singleton (and initializes it, if necessary).
        Returns:
        the singleton
      • reload

        public static void reload()
        Reloads the system-wide favorites.