VASSAL.build.module.map.boardPicker.board
Class HexGrid

java.lang.Object
  |
  +--VASSAL.build.AbstractBuildable
        |
        +--VASSAL.build.AbstractConfigurable
              |
              +--VASSAL.build.module.map.boardPicker.board.HexGrid
All Implemented Interfaces:
AutoConfigurable, Buildable, Configurable, MapGrid

public class HexGrid
extends AbstractConfigurable
implements MapGrid

A Hexgrid is a map grid composed of hexes.


Nested Class Summary
 
Nested classes inherited from class VASSAL.build.module.map.boardPicker.board.MapGrid
MapGrid.BadCoords
 
Nested classes inherited from class VASSAL.build.AutoConfigurable
AutoConfigurable.Util
 
Field Summary
protected  boolean alternate
           
protected  Board board
           
protected  java.awt.Color color
           
static java.lang.String COLOR
           
static java.lang.String CORNERS
           
protected  boolean cornersLegal
           
static java.lang.String DOTS_VISIBLE
           
protected  boolean dotsVisible
           
protected  double dx
           
static java.lang.String DX
           
protected  double dy
           
static java.lang.String DY
           
static java.lang.String EDGES
           
protected  boolean edgesLegal
           
protected  GridNumbering numbering
           
protected  java.awt.Point origin
           
protected  boolean sideways
           
static java.lang.String SIDEWAYS
           
protected  boolean visible
           
static java.lang.String VISIBLE
           
static java.lang.String X0
           
static java.lang.String Y0
           
 
Fields inherited from class VASSAL.build.AbstractConfigurable
changeSupport, config, name
 
Fields inherited from class VASSAL.build.AbstractBuildable
buildComponents
 
Fields inherited from interface VASSAL.build.Configurable
NAME_PROPERTY
 
Constructor Summary
HexGrid()
           
HexGrid(double size, boolean alt)
           
HexGrid(double height, double width, boolean alt)
           
 
Method Summary
 void addTo(Buildable b)
          Adds this component to its parent.
 javax.swing.JPanel configurePanel()
           
 void draw(java.awt.Graphics g, java.awt.Rectangle bounds, java.awt.Rectangle visibleRect, double zoom, boolean reversed)
          Draw the grid
 java.lang.Class[] getAllowableConfigureComponents()
          Return a list of valid sub-component Classes.
 java.lang.String[] getAttributeDescriptions()
          Return an array of Strings describing the attributes of this object.
 java.lang.String[] getAttributeNames()
           
 java.lang.Class[] getAttributeTypes()
          Return the Class for the attributes of this object.
 java.lang.String getAttributeValueString(java.lang.String key)
          Called by the AbstractBuildable.getBuildElement(org.w3c.dom.Document) method to write the attributes into an XML element
 VisibilityCondition getAttributeVisibility(java.lang.String name)
          By default, all attributes are visible
 java.lang.String getConfigureName()
          The name of this Configurable Object
 Configurer getConfigurer()
          The default Configurer of an AbstractConfigurable class is an instance of AutoConfigurer
static java.lang.String getConfigureTypeName()
           
 GridNumbering getGridNumbering()
           
 HelpFile getHelpFile()
           
 double getHexSize()
           
 double getHexWidth()
           
 java.awt.Point getLocation(java.lang.String hex)
           
 java.awt.Point getOrigin()
           
protected  int hexX(int x, int y)
           
protected  int hexY(int x, int y)
           
 boolean isCornersLegal()
           
 boolean isEdgesLegal()
           
 boolean isSideways()
           
 boolean isVisible()
          Whether this grid should be drawn on the map
 java.lang.String locationName(java.awt.Point p)
           
 int range(java.awt.Point p1, java.awt.Point p2)
           
 void removeFrom(Buildable b)
          Remove this component from its parent
 void rotate(java.awt.Point p)
           
 void rotateIfSideways(java.awt.Point p)
           
 void setAttribute(java.lang.String key, java.lang.Object val)
          Called by the AbstractBuildable.build(org.w3c.dom.Element) method, where value is the String value read by the XML attribute.
 void setCornersLegal(boolean legal)
           
 void setEdgesLegal(boolean legal)
           
 void setGridNumbering(GridNumbering numbering)
           
 void setHexSize(double size)
           
 void setHexWidth(double w)
           
 void setVisible(boolean legal)
           
protected  int sideX(int x, int y)
           
protected  int sideY(int x, int y)
           
 java.awt.Point snapTo(java.awt.Point p)
           
 java.awt.Point snapToHex(java.awt.Point p)
           
 java.awt.Point snapToHexSide(java.awt.Point p)
           
 java.awt.Point snapToHexVertex(java.awt.Point p)
           
protected  int vertexX(int x, int y)
           
protected  int vertexY(int x, int y)
           
 
Methods inherited from class VASSAL.build.AbstractConfigurable
addPropertyChangeListener, getConfigureComponents, remove, setConfigureName
 
Methods inherited from class VASSAL.build.AbstractBuildable
add, build, getBuildComponents, getBuildElement, getComponents
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface VASSAL.build.Buildable
add, build, getBuildElement
 

Field Detail

origin

protected java.awt.Point origin

dx

protected double dx

dy

protected double dy

board

protected Board board

numbering

protected GridNumbering numbering

visible

protected boolean visible

dotsVisible

protected boolean dotsVisible

edgesLegal

protected boolean edgesLegal

cornersLegal

protected boolean cornersLegal

color

protected java.awt.Color color

sideways

protected boolean sideways

X0

public static final java.lang.String X0
See Also:
Constant Field Values

Y0

public static final java.lang.String Y0
See Also:
Constant Field Values

DY

public static final java.lang.String DY
See Also:
Constant Field Values

DX

public static final java.lang.String DX
See Also:
Constant Field Values

VISIBLE

public static final java.lang.String VISIBLE
See Also:
Constant Field Values

DOTS_VISIBLE

public static final java.lang.String DOTS_VISIBLE
See Also:
Constant Field Values

CORNERS

public static final java.lang.String CORNERS
See Also:
Constant Field Values

EDGES

public static final java.lang.String EDGES
See Also:
Constant Field Values

SIDEWAYS

public static final java.lang.String SIDEWAYS
See Also:
Constant Field Values

COLOR

public static final java.lang.String COLOR
See Also:
Constant Field Values

alternate

protected boolean alternate
Constructor Detail

HexGrid

public HexGrid(double height,
               double width,
               boolean alt)

HexGrid

public HexGrid(double size,
               boolean alt)

HexGrid

public HexGrid()
Method Detail

getAttributeNames

public java.lang.String[] getAttributeNames()
Specified by:
getAttributeNames in interface AutoConfigurable
Specified by:
getAttributeNames in class AbstractBuildable
Returns:
an array of Strings giving all attributes of this Buildable component that will be written to/read from an XML element

getAttributeDescriptions

public java.lang.String[] getAttributeDescriptions()
Description copied from class: AbstractConfigurable
Return an array of Strings describing the attributes of this object. These strings are used as prompts in the Properties window for this object. The order of descriptions should be the same as the order of names in AbstractBuildable.getAttributeNames()

Specified by:
getAttributeDescriptions in interface AutoConfigurable
Specified by:
getAttributeDescriptions in class AbstractConfigurable

getAttributeTypes

public java.lang.Class[] getAttributeTypes()
Description copied from class: AbstractConfigurable
Return the Class for the attributes of this object. Valid classes are: String, Integer, Double, Boolean, Image, Color, and KeyStroke The order of classes should be the same as the order of names in AbstractBuildable.getAttributeNames()

Specified by:
getAttributeTypes in interface AutoConfigurable
Specified by:
getAttributeTypes in class AbstractConfigurable

getAttributeVisibility

public VisibilityCondition getAttributeVisibility(java.lang.String name)
Description copied from class: AbstractConfigurable
By default, all attributes are visible

Specified by:
getAttributeVisibility in interface AutoConfigurable
Overrides:
getAttributeVisibility in class AbstractConfigurable
Parameters:
name -
Returns:

getConfigurer

public Configurer getConfigurer()
Description copied from class: AbstractConfigurable
The default Configurer of an AbstractConfigurable class is an instance of AutoConfigurer

Specified by:
getConfigurer in interface Configurable
Overrides:
getConfigurer in class AbstractConfigurable

isVisible

public boolean isVisible()
Description copied from interface: MapGrid
Whether this grid should be drawn on the map

Specified by:
isVisible in interface MapGrid

isEdgesLegal

public boolean isEdgesLegal()

isCornersLegal

public boolean isCornersLegal()

setVisible

public void setVisible(boolean legal)

setEdgesLegal

public void setEdgesLegal(boolean legal)

isSideways

public boolean isSideways()

setCornersLegal

public void setCornersLegal(boolean legal)

setHexSize

public void setHexSize(double size)

getHexSize

public double getHexSize()

getHexWidth

public double getHexWidth()

setHexWidth

public void setHexWidth(double w)

addTo

public void addTo(Buildable b)
Description copied from interface: Buildable
Adds this component to its parent. In order to make Buildable objects extensible, the child is reponsible for adding itself to the parent. That way, Buildable subcomponents can be defined in an extension package without needing to modify the containing class.

Specified by:
addTo in interface Buildable

removeFrom

public void removeFrom(Buildable b)
Description copied from interface: Configurable
Remove this component from its parent

Specified by:
removeFrom in interface Configurable

getConfigureTypeName

public static java.lang.String getConfigureTypeName()

getConfigureName

public java.lang.String getConfigureName()
Description copied from interface: Configurable
The name of this Configurable Object

Specified by:
getConfigureName in interface Configurable
Overrides:
getConfigureName in class AbstractConfigurable

getHelpFile

public HelpFile getHelpFile()
Specified by:
getHelpFile in interface Configurable
Returns:
a HelpFilte describing how to use and configure this component

getAttributeValueString

public java.lang.String getAttributeValueString(java.lang.String key)
Description copied from interface: AutoConfigurable
Called by the Buildable.getBuildElement(org.w3c.dom.Document) method to write the attributes into an XML element

Specified by:
getAttributeValueString in interface AutoConfigurable
Specified by:
getAttributeValueString in class AbstractBuildable
Parameters:
key - the name of the attribute. Will be one of those listed in AbstractBuildable.getAttributeNames()

setAttribute

public void setAttribute(java.lang.String key,
                         java.lang.Object val)
Description copied from interface: AutoConfigurable
Called by the Buildable.build(org.w3c.dom.Element) method, where value is the String value read by the XML attribute. Can also be called with Object value to set the attribute.

Specified by:
setAttribute in interface AutoConfigurable
Specified by:
setAttribute in class AbstractBuildable
Parameters:
key - the name of the attribute. Will be one of those listed in AbstractBuildable.getAttributeNames()

getAllowableConfigureComponents

public java.lang.Class[] getAllowableConfigureComponents()
Description copied from interface: Configurable
Return a list of valid sub-component Classes. If a Class appears in this list, then instances of that class may be added to this component from the Configuration Window.

Specified by:
getAllowableConfigureComponents in interface Configurable

locationName

public java.lang.String locationName(java.awt.Point p)
Specified by:
locationName in interface MapGrid
Returns:
a string describing the location containing the given point

getLocation

public java.awt.Point getLocation(java.lang.String hex)
                           throws MapGrid.BadCoords
Specified by:
getLocation in interface MapGrid
Returns:
A point p such that locationName(p).equals(location)
MapGrid.BadCoords

snapTo

public java.awt.Point snapTo(java.awt.Point p)
Specified by:
snapTo in interface MapGrid
Returns:
the nearest grid location to the given point

snapToHex

public java.awt.Point snapToHex(java.awt.Point p)
Returns:
the nearest hex center

snapToHexSide

public java.awt.Point snapToHexSide(java.awt.Point p)
Returns:
the nearest hex center or hexside

snapToHexVertex

public java.awt.Point snapToHexVertex(java.awt.Point p)
Returns:
the nearest hex center or vertex

rotate

public void rotate(java.awt.Point p)

rotateIfSideways

public void rotateIfSideways(java.awt.Point p)

range

public int range(java.awt.Point p1,
                 java.awt.Point p2)
Specified by:
range in interface MapGrid
Returns:
the range between two points, in some unit appropriate to the grid (e.g. hexes or squares)

hexX

protected int hexX(int x,
                   int y)

hexY

protected int hexY(int x,
                   int y)

sideX

protected int sideX(int x,
                    int y)

sideY

protected int sideY(int x,
                    int y)

vertexX

protected int vertexX(int x,
                      int y)

vertexY

protected int vertexY(int x,
                      int y)

draw

public void draw(java.awt.Graphics g,
                 java.awt.Rectangle bounds,
                 java.awt.Rectangle visibleRect,
                 double zoom,
                 boolean reversed)
Description copied from interface: MapGrid
Draw the grid

Specified by:
draw in interface MapGrid
Parameters:
bounds - the boundaries of the grid (in magnified coordinates)
zoom - the magnification factor

configurePanel

public javax.swing.JPanel configurePanel()

setGridNumbering

public void setGridNumbering(GridNumbering numbering)

getGridNumbering

public GridNumbering getGridNumbering()
Specified by:
getGridNumbering in interface MapGrid

getOrigin

public java.awt.Point getOrigin()