Class GridView
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 Summary
-
Method Summary
Modifier and TypeMethodDescriptionaddItem
(View view, int row, int column, int rowSpan, int colSpan, int minGridHeight, int minGridWidth) Adds aView
and its position to the grid.void
Remove all items.protected void
drawInternal
(Screen screen) Possibly draws a box around this view and title in a box top boundary.Gets aView
hotkeyKeyHandler
.Handles keys by dispatching registered command runnable into an event loop.Handles mouse events by dispatching registered consumers into an event loop.boolean
hasFocus()
Gets if thisView
has a focus.protected void
Internal init method called fromAbstractView.init()
.boolean
Returns if borders is shown.setColumnSize
(int... columns) Defines how the columns of the grid are distributed.setMinSize
(int minWidth, int minHeight) Sets an absolute minimum width for rows and an absolute minimum height for columns.setRowSize
(int... rows) For documentation seesetColumnSize(int...)
as it's equivalent for rows.void
setShowBorders
(boolean showBorders) Defines if borders is shown.Methods inherited from class org.springframework.shell.component.view.control.BoxView
drawBackground, getBackgroundStyle, getInnerRect, isShowBorder, setBackgroundColor, setBorderPadding, setFocusedTitleColor, setFocusedTitleStyle, setRect, setShowBorder, setTitle, setTitleAlign, setTitleColor, setTitleStyle
Methods inherited from class org.springframework.shell.component.view.control.AbstractView
destroy, dispatch, dispatchKeyRunCommand, dispatchMouseRunCommand, dispatchRunnable, draw, focus, getDrawFunction, getEventLoop, getHotKeyBindings, getKeyBindings, getLayer, getMouseBindings, getViewCommands, getViewService, init, onDestroy, registerHotKeyBinding, registerHotKeyBinding, registerHotKeyBinding, registerKeyBinding, registerKeyBinding, registerKeyBinding, registerMouseBinding, registerMouseBinding, registerMouseBinding, registerViewCommand, runViewCommand, setDrawFunction, setEventLoop, setLayer, setViewService, shortcut
Methods inherited from class org.springframework.shell.component.view.control.AbstractControl
getRect, getThemeName, getThemeResolver, resolveThemeBackground, resolveThemeForeground, resolveThemeStyle, setThemeName, setThemeResolver
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.springframework.shell.component.view.control.Control
getRect, setThemeName, setThemeResolver
-
Constructor Details
-
GridView
public GridView()
-
-
Method Details
-
setColumnSize
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 withsetMinSize(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
For documentation seesetColumnSize(int...)
as it's equivalent for rows.- Parameters:
rows
- the row sizes- Returns:
- a grid view for chaining
- See Also:
-
setMinSize
Sets an absolute minimum width for rows and an absolute minimum height for columns. Negative values cannot be used.- Parameters:
minWidth
- the rows minimum widthminHeight
- 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 aView
and its position to the grid. The top-left corner of theView
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, theView
will not be drawn.You can add the same
View
multiple times with different grid positions. TheminGridWidth
andminGridHeight
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 theView
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
andminGridHeight
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 addrow
- the rowcolumn
- the columnrowSpan
- the row spancolSpan
- the column spanminGridHeight
- the mininum heightminGridWidth
- 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
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 interfaceView
- Overrides:
getMouseHandler
in classAbstractView
- Returns:
- a view mouse handler
- See Also:
-
initInternal
protected void initInternal()Description copied from class:AbstractView
Internal init method called fromAbstractView.init()
. Override to do something usefull. Typically key and mousebindings are registered from this method.- Overrides:
initInternal
in classAbstractView
-
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 interfaceView
- Overrides:
getKeyHandler
in classAbstractView
- Returns:
- a view key handler
- See Also:
-
getHotKeyHandler
Description copied from interface:View
- Specified by:
getHotKeyHandler
in interfaceView
- Overrides:
getHotKeyHandler
in classAbstractView
- Returns:
- a view hotkey handler
- See Also:
-
hasFocus
public boolean hasFocus()Description copied from interface:View
Gets if thisView
has a focus.- Specified by:
hasFocus
in interfaceView
- Overrides:
hasFocus
in classAbstractView
- Returns:
- true if view has a focus
-
drawInternal
Description copied from class:BoxView
Possibly draws a box around this view and title in a box top boundary. Also calls adraw function
if defined.- Overrides:
drawInternal
in classBoxView
- Parameters:
screen
- the screen
-