de.hagenah.diplomacy.map
Class MapData

java.lang.Object
  extended by de.hagenah.diplomacy.map.MapData
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable

public final class MapData
extends java.lang.Object
implements java.io.Serializable, java.lang.Comparable

The MapData class represents a map like Standard or Crowded. It only represents the map data that doesn't change and not game or turn specific data.

See Also:
Serialized Form

Field Summary
static java.awt.Color COLOR_LAND
          Color for land
static java.awt.Color COLOR_NEUTRAL
          Color for neutral
static java.awt.Color COLOR_SEA
          Color for sea
static java.awt.Color COLOR_TEXT
          Color for text
static int HOME_CENTERS_ALL
          All centers are home centers
static int HOME_CENTERS_PHASE
          The centers of the specified phase are the home centers
static int HOME_CENTERS_SPECIAL
          The home centers are explicitly specified
static int HOME_CENTERS_START
          The start centers are the home centers, too
static java.lang.String NAME_1897
          The name of the 1897 map
static java.lang.String NAME_1898
          The name of the 1898 map
static java.lang.String NAME_ASIA
          The name of the Asia map
static java.lang.String NAME_BRITAIN
          The name of the Britain map
static java.lang.String NAME_CHAOS
          The name of the Chaos map
static java.lang.String NAME_COLONIAL
          The name of the Colonial map
static java.lang.String NAME_COLONIAL96
          The name of the Colonial96 map
static java.lang.String NAME_CROWDED
          The name of the Crowded map
static java.lang.String NAME_CROWDED_1898
          The name of the Crowded 1898 map
static java.lang.String NAME_FLEET_ROME
          The name of the Fleet Rome map
static java.lang.String NAME_HUNDRED_1
          The name of the Hundred map (first version)
static java.lang.String NAME_HUNDRED_2
          The name of the Hundred map (second version)
static java.lang.String NAME_SAILHO
          The name of the Sail Ho!
static java.lang.String NAME_SAILHO_CROWDED
          The name of the Sail Ho!
static java.lang.String NAME_SAILHO2
          The name of the Sail Ho!
static java.lang.String NAME_SHIFT_AROUND
          The name of the Shift Around map
static java.lang.String NAME_SHIFT_LEFT
          The name of the Shift Left map
static java.lang.String NAME_SHIFT_RIGHT
          The name of the Shift Right map
static java.lang.String NAME_STANDARD
          The name of the Standard map
 
Method Summary
 int compareTo(java.lang.Object obj)
          Compares two Maps by Name ignoring case
 byte[] createPNG(int width, int height, java.util.Map centers, java.util.Collection units, java.util.Collection orders, boolean uniticons, boolean unitcolor, boolean abbreviations, int brightness)
          Creates a png file
 boolean equals(java.lang.Object obj)
          Compares two Maps by Name ignoring case
 java.util.SortedSet getCenters()
          Returns all centers (Province objects)
 java.lang.String getComment()
          Returns the comment of the map (can be null).
 java.util.SortedSet getCountries()
          Returns all countries
 Country getCountry(java.lang.String name)
          Retrieves the Country with the specified name.
 java.lang.String getDescription()
          Returns a description for the map.
 java.util.SortedSet getHomeCenters(Country country, java.util.Map specialcenters)
          Returns the home centers for a country
 Phase getHomeCentersPhase()
          Returns the special phase if getHomeCentersType() returns HOME_CENTERS_PHASE
 int getHomeCentersType()
          Returns the home centers type
 java.lang.String getMapBy()
          Returns the author of the map (can be null).
 java.lang.String getName()
          Returns the name of the map.
 java.awt.Rectangle getOrderBounds(java.awt.Graphics g, java.awt.geom.Rectangle2D rect, Order order)
          Returns a bounding rectangle for an order.
 Person getPerson(java.lang.String name)
          Retrieves the person (country, master, or observer) with the specified name.
 java.util.SortedSet getPersons()
          Returns all persons (countries, master, and observer).
 Province getProvince(java.lang.String name)
          Retrieves the Province with the specified name.
 java.awt.Rectangle getProvinceBounds(java.awt.geom.Rectangle2D rect, java.util.Collection provinces)
          Returns a bounding rectangle for the specified provinces.
 java.util.SortedSet getProvinces()
          Returns all countries
 java.util.Map getProvinces(java.lang.String namestart)
          Returns all provinces that start with the specified string.
 Phase getStartPhase()
          Returns the start phase of the map.
 SubProvince getSubProvince(java.awt.geom.Rectangle2D rect, java.awt.geom.Point2D pos)
          Retrieves the SubProvince in which pos lies.
 SubProvince getSubProvince(java.awt.geom.Rectangle2D rect, java.awt.geom.Point2D pos, boolean sea)
          Retrieves the SubProvince in which pos lies.
 SubProvince getSubProvince(java.lang.String name, int coast)
          Retrieves the SubProvince with the specified name and coast.
 SubProvince getSubProvince(java.lang.String name, java.lang.String coast)
          Retrieves the SubProvince with the specified name and coast.
 java.lang.String getVariantBy()
          Returns the author of the variant (can be null).
 int hashCode()
          Returns a hashcode for this MapData.
 boolean isHomeCenter(Country country, Province center, java.util.Map specialcenters)
          Tests whether the specified center is a home center of the specified country.
 boolean isOverUnit(java.awt.geom.Rectangle2D rect, java.awt.geom.Point2D pos, SubProvince subprovince, boolean uniticons)
          Is pos over the unit in subprovince?
 void paint(java.awt.Graphics g, java.awt.geom.Rectangle2D rect, java.util.Map centers, java.util.Collection units, java.util.Collection orders, java.util.Collection highlighted, boolean uniticons, boolean unitcolor, boolean abbreviations, int brightness, int highlighting, boolean unitantialiasing, boolean linetextantialiasing)
          Draws the Map into the rectangle rect
static MapData read(java.io.File input)
          Reads a map from a XML file (see Map.dtd).
static MapData read(java.lang.String input)
          Reads a map from a XML file (see Map.dtd).
 java.lang.String toString()
          Returns the name of the map
 void updateColors(MapData newmap)
          Updates the colors of this map.
 void updateTSR()
          Update Colonial TSR SpecialCountry from version 2.0
 void write(java.io.OutputStream stream)
          Writes a map to a XML file (see Map.dtd).
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

COLOR_LAND

public static final java.awt.Color COLOR_LAND
Color for land


COLOR_SEA

public static final java.awt.Color COLOR_SEA
Color for sea


COLOR_NEUTRAL

public static final java.awt.Color COLOR_NEUTRAL
Color for neutral


COLOR_TEXT

public static final java.awt.Color COLOR_TEXT
Color for text


HOME_CENTERS_START

public static final int HOME_CENTERS_START
The start centers are the home centers, too

See Also:
Constant Field Values

HOME_CENTERS_SPECIAL

public static final int HOME_CENTERS_SPECIAL
The home centers are explicitly specified

See Also:
Constant Field Values

HOME_CENTERS_ALL

public static final int HOME_CENTERS_ALL
All centers are home centers

See Also:
Constant Field Values

HOME_CENTERS_PHASE

public static final int HOME_CENTERS_PHASE
The centers of the specified phase are the home centers

See Also:
Constant Field Values

NAME_1897

public static final java.lang.String NAME_1897
The name of the 1897 map

See Also:
Constant Field Values

NAME_1898

public static final java.lang.String NAME_1898
The name of the 1898 map

See Also:
Constant Field Values

NAME_ASIA

public static final java.lang.String NAME_ASIA
The name of the Asia map

See Also:
Constant Field Values

NAME_BRITAIN

public static final java.lang.String NAME_BRITAIN
The name of the Britain map

See Also:
Constant Field Values

NAME_CHAOS

public static final java.lang.String NAME_CHAOS
The name of the Chaos map

See Also:
Constant Field Values

NAME_COLONIAL

public static final java.lang.String NAME_COLONIAL
The name of the Colonial map

See Also:
Constant Field Values

NAME_COLONIAL96

public static final java.lang.String NAME_COLONIAL96
The name of the Colonial96 map

See Also:
Constant Field Values

NAME_CROWDED

public static final java.lang.String NAME_CROWDED
The name of the Crowded map

See Also:
Constant Field Values

NAME_CROWDED_1898

public static final java.lang.String NAME_CROWDED_1898
The name of the Crowded 1898 map

See Also:
Constant Field Values

NAME_FLEET_ROME

public static final java.lang.String NAME_FLEET_ROME
The name of the Fleet Rome map

See Also:
Constant Field Values

NAME_HUNDRED_1

public static final java.lang.String NAME_HUNDRED_1
The name of the Hundred map (first version)

See Also:
Constant Field Values

NAME_HUNDRED_2

public static final java.lang.String NAME_HUNDRED_2
The name of the Hundred map (second version)

See Also:
Constant Field Values

NAME_SAILHO

public static final java.lang.String NAME_SAILHO
The name of the Sail Ho! map

See Also:
Constant Field Values

NAME_SAILHO2

public static final java.lang.String NAME_SAILHO2
The name of the Sail Ho! map (equal to the NAME_SAILHO map)

See Also:
Constant Field Values

NAME_SAILHO_CROWDED

public static final java.lang.String NAME_SAILHO_CROWDED
The name of the Sail Ho! Crowded map

See Also:
Constant Field Values

NAME_SHIFT_AROUND

public static final java.lang.String NAME_SHIFT_AROUND
The name of the Shift Around map

See Also:
Constant Field Values

NAME_SHIFT_LEFT

public static final java.lang.String NAME_SHIFT_LEFT
The name of the Shift Left map

See Also:
Constant Field Values

NAME_SHIFT_RIGHT

public static final java.lang.String NAME_SHIFT_RIGHT
The name of the Shift Right map

See Also:
Constant Field Values

NAME_STANDARD

public static final java.lang.String NAME_STANDARD
The name of the Standard map

See Also:
Constant Field Values
Method Detail

getName

public java.lang.String getName()
Returns the name of the map.


getStartPhase

public Phase getStartPhase()
Returns the start phase of the map.


getMapBy

public java.lang.String getMapBy()
Returns the author of the map (can be null).


getVariantBy

public java.lang.String getVariantBy()
Returns the author of the variant (can be null).


getComment

public java.lang.String getComment()
Returns the comment of the map (can be null).


getCountries

public java.util.SortedSet getCountries()
Returns all countries


getPersons

public java.util.SortedSet getPersons()
Returns all persons (countries, master, and observer). Note: Person.POWER is not included.


getProvinces

public java.util.SortedSet getProvinces()
Returns all countries


getCenters

public java.util.SortedSet getCenters()
Returns all centers (Province objects)


read

public static MapData read(java.io.File input)
                    throws org.xml.sax.SAXException,
                           java.io.IOException
Reads a map from a XML file (see Map.dtd).

Parameters:
input - The XML file
Returns:
The Map
Throws:
org.xml.sax.SAXException
java.io.IOException

read

public static MapData read(java.lang.String input)
                    throws org.xml.sax.SAXException,
                           java.io.IOException
Reads a map from a XML file (see Map.dtd).

Parameters:
input - The URI of the XML file
Returns:
The Map
Throws:
org.xml.sax.SAXException
java.io.IOException

write

public void write(java.io.OutputStream stream)
           throws java.io.IOException
Writes a map to a XML file (see Map.dtd).

Parameters:
stream - A Writer for the output. It is not closed at the end.
Throws:
java.io.IOException

getCountry

public Country getCountry(java.lang.String name)
                   throws java.lang.IllegalArgumentException
Retrieves the Country with the specified name.

Parameters:
name - Name or abbreviation of the country (!=null).
Returns:
The Country (!=null).
Throws:
java.lang.IllegalArgumentException

getPerson

public Person getPerson(java.lang.String name)
                 throws java.lang.IllegalArgumentException
Retrieves the person (country, master, or observer) with the specified name. Note: Person.POWER is not supported.

Parameters:
name - Name or abbreviation of the person (!=null).
Returns:
The person (!=null).
Throws:
java.lang.IllegalArgumentException

getProvince

public Province getProvince(java.lang.String name)
                     throws java.lang.IllegalArgumentException
Retrieves the Province with the specified name.

Parameters:
name - A name of the province (!=null).
Returns:
The Province (!=null).
Throws:
java.lang.IllegalArgumentException

getProvinces

public java.util.Map getProvinces(java.lang.String namestart)
Returns all provinces that start with the specified string.

Parameters:
namestart - The start of the name (case is ignored)
Returns:
A Map (String → Province) with the provinces starting with namestart. The strings are through StringHelper.normalizeIgnoreCase.

getSubProvince

public SubProvince getSubProvince(java.lang.String name,
                                  int coast)
                           throws java.lang.IllegalArgumentException
Retrieves the SubProvince with the specified name and coast.

Parameters:
name - A Name of the province (!=null).
coast - The coast of the province.
Returns:
The SubProvince (!=null).
Throws:
java.lang.IllegalArgumentException

getSubProvince

public SubProvince getSubProvince(java.lang.String name,
                                  java.lang.String coast)
                           throws java.lang.IllegalArgumentException
Retrieves the SubProvince with the specified name and coast.

Parameters:
name - A name of the province (!=null).
coast - The coast of the province (!=null).
Returns:
The SubProvince (!=null).
Throws:
java.lang.IllegalArgumentException

getSubProvince

public SubProvince getSubProvince(java.awt.geom.Rectangle2D rect,
                                  java.awt.geom.Point2D pos)
Retrieves the SubProvince in which pos lies.

Parameters:
pos - Position in Bounds
Returns:
A SubProvince or null.

getSubProvince

public SubProvince getSubProvince(java.awt.geom.Rectangle2D rect,
                                  java.awt.geom.Point2D pos,
                                  boolean sea)
Retrieves the SubProvince in which pos lies.

Parameters:
rect - The rectangle of the whole map
pos - Position in rect
sea - Type of the searched SubProvince
Returns:
A SubProvince or null.

isOverUnit

public boolean isOverUnit(java.awt.geom.Rectangle2D rect,
                          java.awt.geom.Point2D pos,
                          SubProvince subprovince,
                          boolean uniticons)
Is pos over the unit in subprovince?

Parameters:
rect - The rect into which to map is drawn
pos - A position
subprovince - A subprovince
Returns:
true if pos over the unit in subprovince, false otherwise

getProvinceBounds

public java.awt.Rectangle getProvinceBounds(java.awt.geom.Rectangle2D rect,
                                            java.util.Collection provinces)
Returns a bounding rectangle for the specified provinces.

Parameters:
rect - The rect into which to map is drawn
provinces - A collection with the provinces
Returns:
The bounding rectangle, null if provinces is empty

getOrderBounds

public java.awt.Rectangle getOrderBounds(java.awt.Graphics g,
                                         java.awt.geom.Rectangle2D rect,
                                         Order order)
Returns a bounding rectangle for an order.

Parameters:
rect - The rect into which to map is drawn
order - The order
Returns:
The bounding rectangle, null if the order is not displayed

getHomeCentersType

public int getHomeCentersType()
Returns the home centers type

Returns:
HOME_CENTERS_...

getHomeCentersPhase

public Phase getHomeCentersPhase()
                          throws java.lang.IllegalStateException
Returns the special phase if getHomeCentersType() returns HOME_CENTERS_PHASE

Returns:
The phase
Throws:
java.lang.IllegalStateException - If the home centers type is not HOME_CENTERS_PHASE

getHomeCenters

public java.util.SortedSet getHomeCenters(Country country,
                                          java.util.Map specialcenters)
Returns the home centers for a country

Parameters:
country - The country
specialcenters - The current centers (Province → Country). If the home centers type is HOME_CENTERS_PHASE and the special home centers phase is before the current phase the centers for the special home centers phase.
Returns:
The home centers for the country.

isHomeCenter

public boolean isHomeCenter(Country country,
                            Province center,
                            java.util.Map specialcenters)
Tests whether the specified center is a home center of the specified country.

Parameters:
country - The country
center - The center
specialcenters - The current centers (Province → Country). If the home centers type is HOME_CENTERS_PHASE and the special home centers phase is before the current phase the centers for the special home centers phase.
Returns:
The home centers for the country.

equals

public boolean equals(java.lang.Object obj)
Compares two Maps by Name ignoring case

Overrides:
equals in class java.lang.Object

compareTo

public int compareTo(java.lang.Object obj)
Compares two Maps by Name ignoring case

Specified by:
compareTo in interface java.lang.Comparable

hashCode

public int hashCode()
Returns a hashcode for this MapData.

Overrides:
hashCode in class java.lang.Object

toString

public java.lang.String toString()
Returns the name of the map

Overrides:
toString in class java.lang.Object

getDescription

public java.lang.String getDescription()
Returns a description for the map.


createPNG

public byte[] createPNG(int width,
                        int height,
                        java.util.Map centers,
                        java.util.Collection units,
                        java.util.Collection orders,
                        boolean uniticons,
                        boolean unitcolor,
                        boolean abbreviations,
                        int brightness)
Creates a png file

Returns:
The png data (null if an error occurs)

paint

public void paint(java.awt.Graphics g,
                  java.awt.geom.Rectangle2D rect,
                  java.util.Map centers,
                  java.util.Collection units,
                  java.util.Collection orders,
                  java.util.Collection highlighted,
                  boolean uniticons,
                  boolean unitcolor,
                  boolean abbreviations,
                  int brightness,
                  int highlighting,
                  boolean unitantialiasing,
                  boolean linetextantialiasing)
Draws the Map into the rectangle rect


updateColors

public void updateColors(MapData newmap)
Updates the colors of this map.

Parameters:
newmap - The colors from this map are used. The maps must have the same countries.

updateTSR

public void updateTSR()
Update Colonial TSR SpecialCountry from version 2.0