Class RegionShapeCellRenderer

    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void gameDataChanged​(GameDataEvent e)
      Invoked when the current game data object becomes invalid.
      protected java.awt.Color[] getColor​(Region r)  
      java.lang.String getComponentConfiguration()
      Just returns the current mode number.
      javax.swing.JMenuItem getContextAdapter()
      Returns an item for this renderer.
      protected java.awt.Color getFactionColor​(java.lang.String f)
      Returns the color for faction with name f.
      protected java.awt.Color getFactionColor​(java.lang.String f, java.awt.Color c)
      Returns the color for faction with name f.
      protected java.awt.Color getFactionColor​(Faction f)
      Returns the color for faction f.
      protected java.awt.Color getFactionColor​(Faction f, java.awt.Color c)
      Returns the color for faction f.
      java.lang.String getFactionKey()
      Returns the default key for settings operations concerning the faction-colors table.
      protected java.awt.Color getLowestGuardingTrustColor​(Region r)  
      protected java.awt.Color getLowestTrustColor​(Region r)  
      static Faction getMaxPeopleFaction​(Region r)
      Counts the people of all faction in the given region and returns the faction with most of them, or null if there are no units.
      java.lang.String getName()
      Returns a name for this renderer.
      java.awt.Color getOceanColor()
      Returns the colors used for ocean regions in Politics Mode.
      java.lang.String getPaintKey()
      Returns the default key for settings operations concerning the mode of this renderer.
      int getPaintMode()
      Returns the current Politics Mode.
      protected java.awt.Color getPoliticsColor​(Region r)
      Returns the color of a region depending on the faction which own this region.
      PreferencesAdapter getPreferencesAdapter()
      Returns the PreferencesAdapter this renderer uses.
      java.lang.String getRegionKey()
      Returns the default key for settings operations concerning the region-colors table.
      protected java.awt.Color getRegionTypeColor​(RegionType type)
      Returns the color of a region type.
      protected java.awt.Color getSingleColor​(Region r)  
      protected java.awt.Color getTagColor​(Region r)
      If the region has a tag with the key MAP_TAG, its value is interpreted as a color, encoded like #00ff00 (see Color.decode(String)).
      protected java.awt.Color getTrustColor​(Region r, boolean guard)
      Fills the cell polygon if in TrustLevel mode.
      java.awt.Color getUnknownColor()
      Returns the colors used for unassigned regions in Politics Mode.
      void initComponent​(java.lang.String p1)
      Tries to convert the string to a number and set the corresponding paint mode.
      protected void initContextMenu()  
      protected void initDefaultRegionTypeColors()
      Puts default values for some region-types to the region-color table.
      protected void initFactionColors​(GameData newData)  
      protected void initRegionColors​(GameData newData)  
      protected void load​(java.util.Map<java.lang.String,​java.awt.Color> dest, java.lang.String key, boolean reset)  
      protected <T> void load​(java.util.Map<T,​java.awt.Color> dest, java.lang.String key, boolean reset, java.lang.Class<T> keyType)
      Parses the global settings value with the given key into the hashtable dest.
      void loadFactionColors​(boolean reset)
      Loads the faction colors saved with the default key factionKey.
      void loadFactionColors​(java.lang.String key, boolean reset)
      Loads the faction colors saved with the given key.
      void loadOceanColor()
      Loads the ocean color used for ocean fields in Politics Mode.
      void loadRegionColors​(boolean reset)
      Loads the region colors saved with the default key regionKey.
      void loadRegionColors​(java.lang.String key, boolean reset)
      Loads the region colors saved with the given key.
      void loadUnknownColor()
      Loads the unknown color used for unassigned fields in Politics Mode.
      protected void save​(java.util.Map<?,​java.awt.Color> source, java.lang.String key)
      Writes the given hashtable into the global settings using the given key.
      void saveFactionColors()
      Saves the faction colors into the global settings using the default key factionKey.
      void saveFactionColors​(java.lang.String key)
      Saves the faction colors into the global settings using the given key.
      void saveOceanColor()
      Saves the ocean color using the key "GeomRenderer.OceanColor".
      void saveRegionColors()
      Saves the faction colors into the global settings using the default key regionKey.
      void saveRegionColors​(java.lang.String key)
      Saves the region colors into the global settings using the given key.
      void saveUnknownColor()
      Saves the unknown color using the key "GeomRenderer.UnknownColor".
      void setContextObserver​(ContextObserver co)
      Sets an observer that should be notified if the state of this renderer changes.
      void setFactionColor​(java.lang.String name, java.awt.Color c)
      Changes the color of the faction with title name to color c.
      void setFactionColor​(Faction f, java.awt.Color c)
      Changes the color of faction f to color c.
      void setFactionColors​(java.util.Map<?,​java.awt.Color> map)
      Puts a whole map to the faction-colors Table.
      void setFactionKey​(java.lang.String fKey)
      Sets the key used for default settings operations concerning the faction colors.
      void setOceanColor​(java.awt.Color c)
      Sets the color used for ocean fields in Politics Mode and stores it in the global settings.
      void setPaintKey​(java.lang.String pKey)
      Sets the key used for deafult settings operations concerning the Politics Mode.
      void setPaintMode​(int mode)
      Sets the Paint Mode of this renderer to pm.
      void setRegionColor​(RegionType r, java.awt.Color c)
      Changes the color of region-type r to color c.
      void setRegionColor​(StringID name, java.awt.Color c)
      Changes the color of the region-type with title name to color c.
      void setRegionColors​(java.util.Map<java.lang.Object,​java.awt.Color> map)
      Puts a whole map to the region-colors Table.
      void setRegionKey​(java.lang.String rKey)
      Sets the key used for deafult settings operations concerning the region colors.
      void setUnknownColor​(java.awt.Color c)
      Sets the color used for unassigned fields in Politics Mode and stores it in the global settings.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • MAP_TAG

        public static final java.lang.String MAP_TAG
        The (REGION) tag in the cr that is used to define a color, the tag value is expected to be a string like #00ff00
        See Also:
        Constant Field Values
      • DEFAULT_FACTION_KEY

        public static final java.lang.String DEFAULT_FACTION_KEY
        The default value for factionKey.
        See Also:
        Constant Field Values
      • DEFAULT_REGION_KEY

        public static final java.lang.String DEFAULT_REGION_KEY
        The default value for regionKey.
        See Also:
        Constant Field Values
      • DEFAULT_PAINTMODE_KEY

        public static final java.lang.String DEFAULT_PAINTMODE_KEY
        The default value for paintKey.
        See Also:
        Constant Field Values
      • PAINT_REGIONTYPE

        public static final int PAINT_REGIONTYPE
        Defines the RegionType paint mode.
        See Also:
        Constant Field Values
      • PAINT_POLITICS

        public static final int PAINT_POLITICS
        Defines the Politics paint mode.
        See Also:
        Constant Field Values
      • PAINT_ALLFACTIONS

        public static final int PAINT_ALLFACTIONS
        Defines the All Factions paint mode.
        See Also:
        Constant Field Values
      • PAINT_TRUST_OVERALL

        public static final int PAINT_TRUST_OVERALL
        Defines the Trust Level OVERALL paint mode.
        See Also:
        Constant Field Values
      • PAINT_TRUST_GUARD

        public static final int PAINT_TRUST_GUARD
        Defines the Trust Level GUARD paint mode.
        See Also:
        Constant Field Values
      • paintMode

        protected int paintMode
        Stores the current painting mode.
      • factionColors

        protected java.util.Map<java.lang.String,​java.awt.Color> factionColors
        Stores the faction - color pairs. The key is the faction name (Faction.getName())
      • oceanColor

        protected java.awt.Color oceanColor
        The ocean is rendered with this color in Politics Mode.
      • unknownColor

        protected java.awt.Color unknownColor
        All regions which can't be assigned to a faction are rendered with this color.
      • regionColors

        protected java.util.Map<StringID,​java.awt.Color> regionColors
        Stores the region - color paires. The key is the region type name (RegionType.getName()).
      • factionKey

        protected java.lang.String factionKey
        The default key for settings operations with the faction-color table.
      • regionKey

        protected java.lang.String regionKey
        The default key for settings operations with the region-color table.
      • paintKey

        protected java.lang.String paintKey
        The default key for settings operations with the Politics Mode variable.
      • typelessColor

        public static java.awt.Color typelessColor
        A default color for regions without type.
      • contextMenu

        protected javax.swing.JMenu contextMenu
      • singleColorArray

        protected java.awt.Color[] singleColorArray
    • Constructor Detail

      • RegionShapeCellRenderer

        public RegionShapeCellRenderer​(CellGeometry geo,
                                       MagellanContext context)
        Constructs a new RegionShapeCellRenderer object using the given geometry and settings. The default settings-operations keys are initialized to:
        • factionKey="GeomRenderer.FactionColors"
        • regionKey="GeomRenderer.RegionColors"
        • paintKey="GeomRenderer.paintMode"
        Parameters:
        geo - The CellGeometry to be used
        context - The Properties to be used
      • RegionShapeCellRenderer

        public RegionShapeCellRenderer​(CellGeometry geo,
                                       MagellanContext context,
                                       java.lang.String fKey,
                                       java.lang.String rKey,
                                       java.lang.String pKey)
        Constructs a new RegionShapeCellRenderer object using the given geometry and settings. The given Strings fKey, rKey and pKey are used to initialize the default settings-operations keys.
        Parameters:
        geo - The CellGeometry to be used
        context - The Properties to be used
        fKey - The factionKey value for settings operations
        rKey - The regionKey value for settings operations
        pKey - The paintKey value for settings operations
    • Method Detail

      • initDefaultRegionTypeColors

        protected void initDefaultRegionTypeColors()
        Puts default values for some region-types to the region-color table. Currently the following region-types are implemented:
        • Ebene
        • Sumpf
        • Wald
        • Wüste
        • Ozean
        • Feuerwand
        • Hochebene
        • Berge
        • Gletscher
      • getPaintMode

        public int getPaintMode()
        Returns the current Politics Mode.
        Returns:
        the current mode
      • setPaintMode

        public void setPaintMode​(int mode)
        Sets the Paint Mode of this renderer to pm. The new setting is stored with the paintKey in the global settings.
        Parameters:
        mode - The new mode
      • setFactionColor

        public void setFactionColor​(Faction f,
                                    java.awt.Color c)
        Changes the color of faction f to color c.
        Parameters:
        f - The faction the color is for
        c - The (new) color
      • setFactionColor

        public void setFactionColor​(java.lang.String name,
                                    java.awt.Color c)
        Changes the color of the faction with title name to color c.
        Parameters:
        name - The faction name the color is for
        c - The (new) color
      • setFactionColors

        public void setFactionColors​(java.util.Map<?,​java.awt.Color> map)
        Puts a whole map to the faction-colors Table. Keys of this map should be factions or strings.
        Parameters:
        map - A map containing Faction/String - Color pairs
      • setRegionColor

        public void setRegionColor​(RegionType r,
                                   java.awt.Color c)
        Changes the color of region-type r to color c.
        Parameters:
        r - The RegionType the color is for
        c - The (new) color
      • setRegionColor

        public void setRegionColor​(StringID name,
                                   java.awt.Color c)
        Changes the color of the region-type with title name to color c.
        Parameters:
        name - The RegionType name the color is for
        c - The (new) color
      • setRegionColors

        public void setRegionColors​(java.util.Map<java.lang.Object,​java.awt.Color> map)
        Puts a whole map to the region-colors Table. Keys should be region-types or strings.
        Parameters:
        map - A map containig RegionType/String - Color pairs
      • getOceanColor

        public java.awt.Color getOceanColor()
        Returns the colors used for ocean regions in Politics Mode.
        Returns:
        the ocean color
      • setOceanColor

        public void setOceanColor​(java.awt.Color c)
        Sets the color used for ocean fields in Politics Mode and stores it in the global settings.
        Parameters:
        c - The new ocean color
      • getUnknownColor

        public java.awt.Color getUnknownColor()
        Returns the colors used for unassigned regions in Politics Mode.
        Returns:
        The color for unassigned regions
      • setUnknownColor

        public void setUnknownColor​(java.awt.Color c)
        Sets the color used for unassigned fields in Politics Mode and stores it in the global settings.
        Parameters:
        c - The new color for unassigned regions
      • getFactionKey

        public java.lang.String getFactionKey()
        Returns the default key for settings operations concerning the faction-colors table.
        Returns:
        the faction-color table key
      • setFactionKey

        public void setFactionKey​(java.lang.String fKey)
        Sets the key used for default settings operations concerning the faction colors.
        Parameters:
        fKey - the new key
      • getRegionKey

        public java.lang.String getRegionKey()
        Returns the default key for settings operations concerning the region-colors table.
        Returns:
        the region-color table key
      • setRegionKey

        public void setRegionKey​(java.lang.String rKey)
        Sets the key used for deafult settings operations concerning the region colors.
        Parameters:
        rKey - the new key
      • getPaintKey

        public java.lang.String getPaintKey()
        Returns the default key for settings operations concerning the mode of this renderer.
        Returns:
        the Politics Mode key
      • setPaintKey

        public void setPaintKey​(java.lang.String pKey)
        Sets the key used for deafult settings operations concerning the Politics Mode.
        Parameters:
        pKey - the new key
      • load

        protected void load​(java.util.Map<java.lang.String,​java.awt.Color> dest,
                            java.lang.String key,
                            boolean reset)
      • load

        protected <T> void load​(java.util.Map<T,​java.awt.Color> dest,
                                java.lang.String key,
                                boolean reset,
                                java.lang.Class<T> keyType)
        Parses the global settings value with the given key into the hashtable dest. If the reset flag is set, the hashtable is cleared before parsing.
        Parameters:
        dest - The destination hashtable
        key - the settings key to use
        reset - true if the hashtable should be cleared
      • save

        protected void save​(java.util.Map<?,​java.awt.Color> source,
                            java.lang.String key)
        Writes the given hashtable into the global settings using the given key.
        Parameters:
        source - The source hashtable with name-Color pairs
        key - The key for the property to set
      • loadFactionColors

        public void loadFactionColors​(boolean reset)
        Loads the faction colors saved with the default key factionKey. If the reset flag is set, the color-table is cleared before loading.
        Parameters:
        reset - true if the faction-colors should be resetted
      • loadFactionColors

        public void loadFactionColors​(java.lang.String key,
                                      boolean reset)
        Loads the faction colors saved with the given key. If the reset flag is set, the color-table is cleared before loading.
        Parameters:
        key - The key for the settings to load from
        reset - true if the faction colors should be reset
      • saveFactionColors

        public void saveFactionColors()
        Saves the faction colors into the global settings using the default key factionKey.
      • saveFactionColors

        public void saveFactionColors​(java.lang.String key)
        Saves the faction colors into the global settings using the given key.
        Parameters:
        key - The property to save to
      • loadRegionColors

        public void loadRegionColors​(boolean reset)
        Loads the region colors saved with the default key regionKey. If the reset flag is set, the color-table is cleared before loading.
        Parameters:
        reset - true if the region colors should be resetted
      • loadRegionColors

        public void loadRegionColors​(java.lang.String key,
                                     boolean reset)
        Loads the region colors saved with the given key. If the reset flag is set, the color-table is cleared before loading.
        Parameters:
        key - the property to load from
        reset - true if the region colors should be resetted
      • saveRegionColors

        public void saveRegionColors()
        Saves the faction colors into the global settings using the default key regionKey.
      • saveRegionColors

        public void saveRegionColors​(java.lang.String key)
        Saves the region colors into the global settings using the given key.
        Parameters:
        key - the property to save to
      • loadOceanColor

        public void loadOceanColor()
        Loads the ocean color used for ocean fields in Politics Mode. The key for this is "GeomRenderer.OceanColor".
      • saveOceanColor

        public void saveOceanColor()
        Saves the ocean color using the key "GeomRenderer.OceanColor".
      • loadUnknownColor

        public void loadUnknownColor()
        Loads the unknown color used for unassigned fields in Politics Mode. The key for this is "GeomRenderer.UnknownColor".
      • saveUnknownColor

        public void saveUnknownColor()
        Saves the unknown color using the key "GeomRenderer.UnknownColor".
      • getTagColor

        protected java.awt.Color getTagColor​(Region r)
        If the region has a tag with the key MAP_TAG, its value is interpreted as a color, encoded like #00ff00 (see Color.decode(String)).
        Returns:
        A color or null if the region has no color tag
      • getTrustColor

        protected java.awt.Color getTrustColor​(Region r,
                                               boolean guard)
        Fills the cell polygon if in TrustLevel mode. Fallback is Politics mode. After that left side is filled with lowest over all trustlevel, right side with lowest trustlevel of guarding units.
      • getLowestTrustColor

        protected java.awt.Color getLowestTrustColor​(Region r)
      • getLowestGuardingTrustColor

        protected java.awt.Color getLowestGuardingTrustColor​(Region r)
      • getRegionTypeColor

        protected java.awt.Color getRegionTypeColor​(RegionType type)
        Returns the color of a region type. If the type can't be found in the region-color table, a new random color entry is put.
        Parameters:
        type - the region type for which a color is needed
        Returns:
        the color for the given type
      • getPoliticsColor

        protected java.awt.Color getPoliticsColor​(Region r)
        Returns the color of a region depending on the faction which own this region. The current implementation first looks if the type of this region is "Ozean" in which case the ocean color is used. Then it checks for an explicitly set owner unit. Normally the owner of the biggest "Burg" is returned. If there's no "Burg", the people of the different factions are counted and the faction with most people "wins". If this algorithm does not supply a faction, the unknown color is used.
        Parameters:
        r - The region for which a color is needed
        Returns:
        the color for the given region
      • getFactionColor

        protected java.awt.Color getFactionColor​(Faction f)
        Returns the color for faction f. If there's no entry in the faction-color table a new random-color entry is created.
        Parameters:
        f - the faction for which a color is needed
        Returns:
        the color for the given faction
      • getFactionColor

        protected java.awt.Color getFactionColor​(java.lang.String f)
        Returns the color for faction with name f. If there's no entry in the faction-color table a new random-color entry is created.
        Parameters:
        f - the faction for which a color is needed
        Returns:
        the color for the given faction
      • getFactionColor

        protected java.awt.Color getFactionColor​(Faction f,
                                                 java.awt.Color c)
        Returns the color for faction f. If there's no entry in the faction-color table the entry is created with given color.
        Parameters:
        f - the faction for which a color is needed
        c - the default color
        Returns:
        the color for the given faction
      • getFactionColor

        protected java.awt.Color getFactionColor​(java.lang.String f,
                                                 java.awt.Color c)
        Returns the color for faction with name f. If there's no entry in the faction-color table the entry is created with given color.
        Parameters:
        f - the faction for which a color is needed
        c - the default color
        Returns:
        the color for the given faction
      • getMaxPeopleFaction

        public static Faction getMaxPeopleFaction​(Region r)
        Counts the people of all faction in the given region and returns the faction with most of them, or null if there are no units.
        Parameters:
        r - A region to count
        Returns:
        the faction with most people or null if there are no units
      • initComponent

        public void initComponent​(java.lang.String p1)
        Tries to convert the string to a number and set the corresponding paint mode.
        Specified by:
        initComponent in interface Initializable
      • initContextMenu

        protected void initContextMenu()
      • initRegionColors

        protected void initRegionColors​(GameData newData)
      • initFactionColors

        protected void initFactionColors​(GameData newData)