All Implemented Interfaces:
Control, View

public class GridView extends BoxView
GridView is a layout container with no initial views. Loosely based on ideas from other grid layouts having features like rows and columns, column and row spanning, dynamic layouts based on container size using "CSS media queries" type of structure.
  • Constructor Details

    • GridView

      public GridView()
  • Method Details

    • setColumnSize

      public GridView setColumnSize(int... columns)
      Defines how the columns of the grid are distributed. Each value defines the size of one column, starting with the leftmost column. Values greater 0 represent absolute column widths (gaps not included). Values less or equal 0 represent proportional column widths or fractions of the remaining free space, where 0 is treated the same as -1. That is, a column with a value of -3 will have three times the width of a column with a value of -1 (or 0). The minimum width set with setMinSize(int, int) is always observed.

      Views may extend beyond the columns defined explicitly with this function. A value of 0 is assumed for any undefined column. In fact, if you never call this function, all columns occupied by Views will have the same width. On the other hand, unoccupied columns defined with this function will always take their place.

      Assuming a total width of the grid of 100 cells and a minimum width of 0, the following call will result in columns with widths of 30, 10, 15, 15, and 30 cells:

      grid.setColumnSize(30, 10, -1, -1, -2)

      If a View were then placed in the 6th and 7th column, the resulting widths would be: 30, 10, 10, 10, 20, 10, and 10 cells. If you then called setMinSize() as follows:

      grid.setMinSize(15, 20)

      The resulting widths would be: 30, 15, 15, 15, 20, 15, and 15 cells, a total of 125 cells, 25 cells wider than the available grid width.

      Parameters:
      columns - the column sizes
      Returns:
      a grid view for chaining
      See Also:
    • setRowSize

      public GridView setRowSize(int... rows)
      For documentation see setColumnSize(int...) as it's equivalent for rows.
      Parameters:
      rows - the row sizes
      Returns:
      a grid view for chaining
      See Also:
    • setMinSize

      public GridView setMinSize(int minWidth, int minHeight)
      Sets an absolute minimum width for rows and an absolute minimum height for columns. Negative values cannot be used.
      Parameters:
      minWidth - the rows minimum width
      minHeight - the columns minimum height
      Returns:
      a grid view for chaining
    • addItem

      public GridView addItem(View view, int row, int column, int rowSpan, int colSpan, int minGridHeight, int minGridWidth)
      Adds a View and its position to the grid. The top-left corner of the View will be located in the top-left corner of the grid cell at the given row and column and will span "rowSpan" rows and "colSpan" columns. For example, for a primitive to occupy rows 2, 3, and 4 and columns 5 and 6:

      grid.addItem(view, 2, 5, 3, 2, 0, 0) If rowSpan or colSpan is 0, the View will not be drawn.

      You can add the same View multiple times with different grid positions. The minGridWidth and minGridHeight values will then determine which of those positions will be used. These minimum values refer to the overall size of the grid. If multiple items for the same primitive apply, the one that has at least one highest minimum value will be used, or the View added last if those values are the same. Example:

      AddItem(view, 0, 0, 0, 0, 0, 0). // Hide in small grids. AddItem(view, 0, 0, 1, 2, 100, 0). // One-column layout for medium grids. AddItem(view, 1, 1, 3, 2, 300, 0) // Multi-column layout for large grids.

      To use the same grid layout for all sizes, simply set minGridWidth and minGridHeight to 0.

      If the item's focus is set to true, it will receive focus when the grid receives focus. If there are multiple items with a true focus flag, the last visible one that was added will receive focus.

      Parameters:
      view - the view to add
      row - the row
      column - the column
      rowSpan - the row span
      colSpan - the column span
      minGridHeight - the mininum height
      minGridWidth - the minimun width
      Returns:
      a grid view for chaining
    • clearItems

      public void clearItems()
      Remove all items.
    • setShowBorders

      public void setShowBorders(boolean showBorders)
      Defines if borders is shown.
      Parameters:
      showBorders - the flag showing borders
    • isShowBorders

      public boolean isShowBorders()
      Returns if borders is shown.
      Returns:
      true if borders is shown
    • getMouseHandler

      public MouseHandler getMouseHandler()
      Description copied from class: AbstractView
      Handles mouse events by dispatching registered consumers into an event loop. Override to change default behaviour.
      Specified by:
      getMouseHandler in interface View
      Overrides:
      getMouseHandler in class AbstractView
      Returns:
      a view mouse handler
      See Also:
    • initInternal

      protected void initInternal()
      Description copied from class: AbstractView
      Internal init method called from AbstractView.init(). Override to do something usefull. Typically key and mousebindings are registered from this method.
      Overrides:
      initInternal in class AbstractView
    • getKeyHandler

      public KeyHandler getKeyHandler()
      Description copied from class: AbstractView
      Handles keys by dispatching registered command runnable into an event loop. Override to change default behaviour.
      Specified by:
      getKeyHandler in interface View
      Overrides:
      getKeyHandler in class AbstractView
      Returns:
      a view key handler
      See Also:
    • getHotKeyHandler

      public KeyHandler getHotKeyHandler()
      Description copied from interface: View
      Gets a View hotkey KeyHandler. Can be null which indicates view will not handle any key events.
      Specified by:
      getHotKeyHandler in interface View
      Overrides:
      getHotKeyHandler in class AbstractView
      Returns:
      a view hotkey handler
      See Also:
    • hasFocus

      public boolean hasFocus()
      Description copied from interface: View
      Gets if this View has a focus.
      Specified by:
      hasFocus in interface View
      Overrides:
      hasFocus in class AbstractView
      Returns:
      true if view has a focus
    • drawInternal

      protected void drawInternal(Screen screen)
      Description copied from class: BoxView
      Possibly draws a box around this view and title in a box top boundary. Also calls a draw function if defined.
      Overrides:
      drawInternal in class BoxView
      Parameters:
      screen - the screen