Class TrueHexGridLayout

java.lang.Object
net.sf.colossus.gui.TrueHexGridLayout
All Implemented Interfaces:
LayoutManager

public class TrueHexGridLayout extends Object implements LayoutManager
The TrueHexGridLayout class is a layout manager that lays out a container's components in a grid with alternate rows offset by a partial grid component. The vertical gap is automatically sized so that the Hex components can draw the non base-rectangle portions of the hexes in the gap. This results in a hexagonal tesselation.

When constructed, the layout can start with an indented row or not. The sizing can be done Isometrically or not. TODO: implement the containers ComponentOrientation property If either the Number of Rows or the Number of Columns is set to Zero either by constructor or the set rows or set columns method, then the grid will be assumed to be square and layed out as such. This class is used for battle Hexes.

Author:
Edward Dranathi based loosely on Sun's GridLayout class.
  • Field Details

    • rows

      int rows
    • cols

      int cols
    • indentOddRows

      boolean indentOddRows
    • isometricShape

      private final boolean isometricShape
  • Constructor Details

    • TrueHexGridLayout

      public TrueHexGridLayout(int pRows, int pColumns, boolean pIndentFirstRow, boolean pIsometricShape)
    • TrueHexGridLayout

      public TrueHexGridLayout(int pRows, int pColumns, boolean pIndentFirstRow)
  • Method Details

    • addLayoutComponent

      public void addLayoutComponent(String name, Component comp)
      Specified by:
      addLayoutComponent in interface LayoutManager
    • removeLayoutComponent

      public void removeLayoutComponent(Component comp)
      Specified by:
      removeLayoutComponent in interface LayoutManager
    • layoutContainer

      public void layoutContainer(Container parent)
      Lays out the specified container using this layout.

      This method resizes the components in the specified target container in order to satisfy the constraints of the BattleHexGridLayout object.

      This layout manager determines the size of individual components by dividing the free space in the container into equal-sized portions according to the number of rows and columns in the layout. The container's free space equals the container's size minus any insets and vertical gap needed. All components in the layout are given the same size.

      Specified by:
      layoutContainer in interface LayoutManager
      Parameters:
      parent - the container in which to do the layout
      See Also:
    • minimumLayoutSize

      public Dimension minimumLayoutSize(Container parent)
      Specified by:
      minimumLayoutSize in interface LayoutManager
    • preferredLayoutSize

      public Dimension preferredLayoutSize(Container parent)
      Specified by:
      preferredLayoutSize in interface LayoutManager
    • main

      public static void main(String[] args)