Class ThemeMap

java.lang.Object
bibliothek.gui.dock.common.theme.ThemeMap

@FrameworkOnly public class ThemeMap extends Object
A map of ThemeFactorys. This map can change the DockTheme of its associated CControl. New factories can be added or removed from the map.
Author:
Benjamin Sigg
  • Field Details

  • Constructor Details

    • ThemeMap

      public ThemeMap()
      Creates a new empty map.
    • ThemeMap

      public ThemeMap(CControl control)
      Creates a new map and wires this map to control. Ensures that the standard themes are available.
      Every change of the selected factory will change the theme of control, and this map will ensure that the name of the theme is stored in the ApplicationResourceManager.
      Parameters:
      control - the control to monitor
  • Method Details

    • addThemeMapListener

      public void addThemeMapListener(ThemeMapListener listener)
      Adds a new listener to this map. The listener will be informed when a factory is changed or the theme changes.
      Parameters:
      listener - the new listener
    • removeThemeMapListener

      public void removeThemeMapListener(ThemeMapListener listener)
      Removes a listener from this map.
      Parameters:
      listener - the listener to remove
    • listeners

      protected ThemeMapListener[] listeners()
      Gets an array containing all ThemeMapListeners of this map.
      Returns:
      the list of listeners
    • setModifier

      public void setModifier(DockThemeModifier modifier)
      Sets the object which will modify the DockTheme before applying the theme to the DockController.
      Parameters:
      modifier - the new modifier, can be null
    • getModifier

      public DockThemeModifier getModifier()
      Gets the object which will modify the DockTheme before applying the theme to the DockController.
      Returns:
      the modifier, can be null
    • select

      public void select(String key)
      Changes the selected factory. If there is no factory with name key or key is null, then the null-factory is selected.
      Parameters:
      key - the name of the newly selected factory, can be null
    • select

      public void select(String key, boolean force)
      Changes the selected factory. If there is no factory with name key or key is null, then the null-factory is selected.
      Parameters:
      key - the name of the newly selected factory, can be null
      force - true if the theme is to be loaded even if it is already selected
    • select

      public void select(ThemeFactory factory)
      Changes the selected factory to factory.
      Parameters:
      factory - the factory to select
      Throws:
      IllegalArgumentException - if factory is not registered in this map.
    • select

      public void select(int index)
      Changes the selected factory.
      Parameters:
      index - the index of the newly selected factory, -1 will deselect any factory
    • select

      public void select(int index, boolean force)
      Changes the selected factory.
      Parameters:
      index - the index of the newly selected factory, -1 will deselect any factory
      force - true if an update should be forced even if there seems not to be a change
    • getSelectedKey

      public String getSelectedKey()
      Gets the name of the currently selected factory.
      Returns:
      the name or null
    • getSelectedFactory

      public ThemeFactory getSelectedFactory()
      Gets the currently selected factory.
      Returns:
      the factory or null
    • size

      public int size()
      Gets the number of elements of this map.
      Returns:
      the number of elements
    • put

      public void put(String key, ThemeFactory factory)
      Searches for an entry named key and changes its factory. If no such entry is found, then factory is added at the end of this map.
      Parameters:
      key - the name of the factory
      factory - the new factory
    • add

      public void add(String key, ThemeFactory factory)
      Adds factory at the end of this map. If there is already a factory named key, then that other factory is first removed.
      Parameters:
      key - the key of the new factory
      factory - the new factory
    • insert

      public void insert(int index, String key, ThemeFactory factory)
      Inserts a new factory into this map. If there is already a factory key in this map, then that other factory is removed.
      Parameters:
      index - the index where to insert the new factory
      key - the key of the new factory
      factory - the new factory
    • remove

      public void remove(int index)
      Removes the index'th entry of this map.
      Parameters:
      index - the name of the element to remove
    • remove

      public boolean remove(String key)
      Deletes the factory associated with key.
      Parameters:
      key - the name of the element to remove
      Returns:
      true if the element was deleted, false if no element named key was found
    • indexOf

      public int indexOf(ThemeFactory factory)
      Searches for factory and returns its index.
      Parameters:
      factory - the factory to search
      Returns:
      its index or -1
    • indexOf

      public int indexOf(String key)
      Searches for key and returns its location.
      Parameters:
      key - the key to search
      Returns:
      the index or -1
    • getKey

      public String getKey(int index)
      Gets the key of the index'th element.
      Parameters:
      index - the index of the element
      Returns:
      the key to that element
    • getFactory

      public ThemeFactory getFactory(int index)
      Gets the index'th factory.
      Parameters:
      index - the index of the factory
      Returns:
      the factory, not null
    • getFactory

      public ThemeFactory getFactory(String key)
      Searches the factory which is associated with key.
      Parameters:
      key - the unique name of a factory
      Returns:
      the factory, may be null