|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.vaadin.server.AbstractClientConnector
com.vaadin.ui.AbstractComponent
com.vaadin.ui.AbstractComponentContainer
com.vaadin.ui.AbstractLayout
com.vaadin.ui.GridLayout
public class GridLayout
A layout where the components are laid out on a grid using cell coordinates.
The GridLayout also maintains a cursor for adding components in left-to-right, top-to-bottom order.
Each component in a GridLayout
uses a defined
area
(column1,row1,column2,row2) from the grid. The
components may not overlap with the existing components - if you try to do so
you will get an GridLayout.OverlapsException
. Adding a component with cursor
automatically extends the grid by increasing the grid height.
The grid coordinates, which are specified by a row and column index, always start from 0 for the topmost row and the leftmost column.
Nested Class Summary | |
---|---|
class |
GridLayout.Area
Defines a rectangular area of cells in a GridLayout. |
class |
GridLayout.OutOfBoundsException
An Exception object which is thrown when an area exceeds the
bounds of the grid. |
class |
GridLayout.OverlapsException
Gridlayout does not support laying components on top of each other. |
Nested classes/interfaces inherited from interface com.vaadin.ui.Component |
---|
Component.ErrorEvent, Component.Event, Component.Focusable, Component.Listener |
Nested classes/interfaces inherited from interface com.vaadin.server.ClientConnector |
---|
ClientConnector.AttachEvent, ClientConnector.AttachListener, ClientConnector.ConnectorErrorEvent, ClientConnector.DetachEvent, ClientConnector.DetachListener |
Nested classes/interfaces inherited from interface com.vaadin.server.Sizeable |
---|
Sizeable.Unit |
Nested classes/interfaces inherited from interface com.vaadin.ui.Layout |
---|
Layout.AlignmentHandler, Layout.MarginHandler, Layout.SpacingHandler |
Nested classes/interfaces inherited from interface com.vaadin.ui.HasComponents |
---|
HasComponents.ComponentAttachDetachNotifier, HasComponents.ComponentAttachEvent, HasComponents.ComponentAttachListener, HasComponents.ComponentDetachEvent, HasComponents.ComponentDetachListener |
Field Summary |
---|
Fields inherited from interface com.vaadin.server.Sizeable |
---|
SIZE_UNDEFINED, UNITS_CM, UNITS_EM, UNITS_EX, UNITS_INCH, UNITS_MM, UNITS_PERCENTAGE, UNITS_PICAS, UNITS_PIXELS, UNITS_POINTS |
Constructor Summary | |
---|---|
GridLayout()
Constructs an empty (1x1) grid layout that is extended as needed. |
|
GridLayout(int columns,
int rows)
Constructor for a grid of given size (number of columns and rows). |
|
GridLayout(int columns,
int rows,
Component... children)
Constructs a GridLayout of given size (number of columns and rows) and adds the given components in order to the grid. |
Method Summary | |
---|---|
void |
addComponent(Component component)
Adds the component into this container to the cursor position. |
void |
addComponent(Component component,
int column,
int row)
Adds the component to the grid in cells column1,row1 (NortWest corner of the area.) End coordinates (SouthEast corner of the area) are the same as column1,row1. |
void |
addComponent(Component component,
int column1,
int row1,
int column2,
int row2)
Adds a component to the grid in the specified area. |
void |
addLayoutClickListener(LayoutEvents.LayoutClickListener listener)
Add a click listener to the layout. |
void |
addListener(LayoutEvents.LayoutClickListener listener)
Deprecated. As of 7.0, replaced by #addLayoutClickListener(LayoutClickListener) |
void |
changeVariables(java.lang.Object source,
java.util.Map<java.lang.String,java.lang.Object> variables)
Called when one or more variables handled by the implementing class are changed. |
float |
getColumnExpandRatio(int columnIndex)
Returns the expand ratio of given column |
int |
getColumns()
Get the number of columns in the grid. |
Component |
getComponent(int x,
int y)
Gets the Component at given index. |
Alignment |
getComponentAlignment(Component childComponent)
Returns the current Alignment of given component. |
GridLayout.Area |
getComponentArea(Component component)
Returns information about the area where given component is laid in the GridLayout. |
int |
getComponentCount()
Gets the number of components contained in the layout. |
int |
getCursorX()
Gets the current x-position (column) of the cursor. |
int |
getCursorY()
Gets the current y-position (row) of the cursor. |
Alignment |
getDefaultComponentAlignment()
Returns the alignment used for new components added to this layout |
com.vaadin.shared.ui.MarginInfo |
getMargin()
|
float |
getRowExpandRatio(int rowIndex)
Returns the expand ratio of given row. |
int |
getRows()
Get the number of rows in the grid. |
protected com.vaadin.shared.ui.gridlayout.GridLayoutState |
getState()
Returns the shared state bean with information to be sent from the server to the client. |
void |
insertRow(int row)
Inserts an empty row at the specified position in the grid. |
boolean |
isSpacing()
|
java.util.Iterator<Component> |
iterator()
Gets an Iterator for the components contained in the layout. |
void |
newLine()
Forces the next component to be added at the beginning of the next line. |
void |
paintContent(PaintTarget target)
Paints the contents of this component. |
void |
removeAllComponents()
Removes all components from the container. |
void |
removeComponent(Component component)
Removes the specified component from the layout. |
void |
removeComponent(int column,
int row)
Removes the component specified by its cell coordinates. |
void |
removeLayoutClickListener(LayoutEvents.LayoutClickListener listener)
Removes an LayoutClickListener. |
void |
removeListener(LayoutEvents.LayoutClickListener listener)
Deprecated. As of 7.0, replaced by #removeLayoutClickListener(LayoutClickListener) |
void |
removeRow(int row)
Removes a row and all the components in the row. |
void |
replaceComponent(Component oldComponent,
Component newComponent)
Replaces the component in the container with another one without changing position. |
void |
setColumnExpandRatio(int columnIndex,
float ratio)
Sets the expand ratio of given column. |
void |
setColumns(int columns)
Sets the number of columns in the grid. |
void |
setComponentAlignment(Component childComponent,
Alignment alignment)
Set alignment for one contained component in this layout. |
void |
setCursorX(int cursorX)
Sets the current cursor x-position. |
void |
setCursorY(int cursorY)
Sets the current y-coordinate (row) of the cursor. |
void |
setDefaultComponentAlignment(Alignment defaultAlignment)
Sets the alignment used for new components added to this layout. |
void |
setMargin(boolean enabled)
Enable layout margins. |
void |
setMargin(com.vaadin.shared.ui.MarginInfo marginInfo)
Enable margins for this layout. |
void |
setRowExpandRatio(int rowIndex,
float ratio)
Sets the expand ratio of given row. |
void |
setRows(int rows)
Sets the number of rows in the grid. |
void |
setSpacing(boolean spacing)
Enable spacing between child components within this layout. |
void |
space()
Moves the cursor forward by one. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface com.vaadin.ui.LegacyComponent |
---|
markAsDirty |
Methods inherited from interface com.vaadin.server.VariableOwner |
---|
isEnabled, isImmediate |
Methods inherited from interface com.vaadin.ui.Component |
---|
addListener, addStyleName, attach, getCaption, getDescription, getIcon, getId, getLocale, getParent, getPrimaryStyleName, getStyleName, getUI, isEnabled, isReadOnly, isVisible, removeListener, removeStyleName, setCaption, setEnabled, setIcon, setId, setParent, setPrimaryStyleName, setReadOnly, setStyleName, setVisible |
Methods inherited from interface com.vaadin.server.ClientConnector |
---|
addAttachListener, addDetachListener, beforeClientResponse, detach, encodeState, getErrorHandler, getExtensions, getRpcManager, getStateType, handleConnectorRequest, isAttached, isConnectorEnabled, markAsDirtyRecursive, removeAttachListener, removeDetachListener, removeExtension, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler |
Methods inherited from interface com.vaadin.shared.Connector |
---|
getConnectorId |
Methods inherited from interface com.vaadin.server.Sizeable |
---|
getHeight, getHeightUnits, getWidth, getWidthUnits, setHeight, setHeight, setSizeFull, setSizeUndefined, setWidth, setWidth |
Methods inherited from interface com.vaadin.ui.ComponentContainer |
---|
addComponents, addListener, addListener, getComponentIterator, moveComponentsFrom, removeListener, removeListener |
Methods inherited from interface com.vaadin.ui.HasComponents.ComponentAttachDetachNotifier |
---|
addComponentAttachListener, addComponentDetachListener, removeComponentAttachListener, removeComponentDetachListener |
Constructor Detail |
---|
public GridLayout(int columns, int rows)
columns
- Number of columns in the grid.rows
- Number of rows in the grid.public GridLayout()
public GridLayout(int columns, int rows, Component... children)
columns
- Number of columns in the grid.rows
- Number of rows in the grid.children
- Components to add to the grid.AbstractComponentContainer.addComponents(Component...)
Method Detail |
---|
protected com.vaadin.shared.ui.gridlayout.GridLayoutState getState()
AbstractComponent
getState
in class AbstractLayout
public void addComponent(Component component, int column1, int row1, int column2, int row2) throws GridLayout.OverlapsException, GridLayout.OutOfBoundsException
Adds a component to the grid in the specified area. The area is defined by specifying the upper left corner (column1, row1) and the lower right corner (column2, row2) of the area. The coordinates are zero-based.
If the area overlaps with any of the existing components already present
in the grid, the operation will fail and an GridLayout.OverlapsException
is
thrown.
component
- the component to be added, not null
.column1
- the column of the upper left corner of the area c
is supposed to occupy. The leftmost column has index 0.row1
- the row of the upper left corner of the area c
is
supposed to occupy. The topmost row has index 0.column2
- the column of the lower right corner of the area
c
is supposed to occupy.row2
- the row of the lower right corner of the area c
is supposed to occupy.
GridLayout.OverlapsException
- if the new component overlaps with any of the components
already in the grid.
GridLayout.OutOfBoundsException
- if the cells are outside the grid area.public void addComponent(Component component, int column, int row) throws GridLayout.OverlapsException, GridLayout.OutOfBoundsException
component
- the component to be added, not null
.column
- the column index, starting from 0.row
- the row index, starting from 0.
GridLayout.OverlapsException
- if the new component overlaps with any of the components
already in the grid.
GridLayout.OutOfBoundsException
- if the cell is outside the grid area.public void newLine()
Sets the cursor column to 0 and increments the cursor row by one.
By calling this function you can ensure that no more components are added right of the previous component.
space()
public void space()
newLine()
public void addComponent(Component component)
addComponent
in interface ComponentContainer
addComponent
in class AbstractComponentContainer
component
- the component to be added, not null
.ComponentContainer.addComponent(Component)
public void removeComponent(Component component)
removeComponent
in interface ComponentContainer
removeComponent
in class AbstractComponentContainer
component
- the component to be removed.ComponentContainer.removeComponent(Component)
public void removeComponent(int column, int row)
column
- the component's column, starting from 0.row
- the component's row, starting from 0.public java.util.Iterator<Component> iterator()
iterator
in interface HasComponents
iterator
in interface java.lang.Iterable<Component>
public int getComponentCount()
AbstractComponentContainer.getComponentIterator()
.
getComponentCount
in interface ComponentContainer
public void changeVariables(java.lang.Object source, java.util.Map<java.lang.String,java.lang.Object> variables)
VariableOwner
changeVariables
in interface VariableOwner
source
- the Source of the variable change. This is the origin of the
event. For example in Web Adapter this is the request.variables
- the Mapping from variable names to new variable values.public void paintContent(PaintTarget target) throws PaintException
paintContent
in interface LegacyComponent
target
- the Paint Event.
PaintException
- if the paint operation failed.public Alignment getComponentAlignment(Component childComponent)
Layout.AlignmentHandler
getComponentAlignment
in interface Layout.AlignmentHandler
Alignment
public void setColumns(int columns)
columns
- the new number of columns in the grid.public int getColumns()
public void setRows(int rows)
rows
- the new number of rows in the grid.public int getRows()
public int getCursorX()
The cursor position points the position for the next component that is added without specifying its coordinates (grid cell). When the cursor position is occupied, the next component will be added to first free position after the cursor.
public void setCursorX(int cursorX)
cursorX
- public int getCursorY()
The cursor position points the position for the next component that is added without specifying its coordinates (grid cell). When the cursor position is occupied, the next component will be added to the first free position after the cursor.
public void setCursorY(int cursorY)
cursorY
- the row number, starting from 0 for the topmost row.public void replaceComponent(Component oldComponent, Component newComponent)
ComponentContainer
This method replaces component with another one is such way that the new component overtakes the position of the old component. If the old component is not in the container, the new component is added to the container. If the both component are already in the container, their positions are swapped. Component attach and detach events should be taken care as with add and remove.
replaceComponent
in interface ComponentContainer
oldComponent
- the old component that will be replaced.newComponent
- the new component to be replaced.public void removeAllComponents()
AbstractComponentContainer
removeAllComponents
in interface ComponentContainer
removeAllComponents
in class AbstractComponentContainer
public void setComponentAlignment(Component childComponent, Alignment alignment)
Layout.AlignmentHandler
layout.setComponentAlignment(myComponent, Alignment.TOP_RIGHT);
setComponentAlignment
in interface Layout.AlignmentHandler
childComponent
- the component to align within it's layout cell.alignment
- the Alignment value to be setpublic void setSpacing(boolean spacing)
Layout.SpacingHandler
NOTE: This will only affect the space between
components, not the space around all the components in the layout
(i.e. do not confuse this with the cellspacing attribute of a HTML
Table). Use #setMargin(boolean)
to add space around the
layout.
See the reference manual for more information about CSS rules for defining the amount of spacing to use.
setSpacing
in interface Layout.SpacingHandler
spacing
- true if spacing should be turned on, false if it should be
turned offpublic boolean isSpacing()
isSpacing
in interface Layout.SpacingHandler
public void insertRow(int row)
row
- Index of the row before which the new row will be inserted.
The leftmost row has index 0.public void removeRow(int row)
Components which span over several rows are removed if the selected row is on the first row of such a component.
If the last row is removed then all remaining components will be removed and the grid will be reduced to one row. The cursor will be moved to the upper left cell of the grid.
row
- Index of the row to remove. The leftmost row has index 0.public void setColumnExpandRatio(int columnIndex, float ratio)
The expand ratio defines how excess space is distributed among columns. Excess space means space that is left over from components that are not sized relatively. By default, the excess space is distributed evenly.
Note that the component width of the GridLayout must be defined (fixed or relative, as opposed to undefined) for this method to have any effect.
columnIndex
- ratio
- #setWidth(float, int)
public float getColumnExpandRatio(int columnIndex)
columnIndex
-
setColumnExpandRatio(int, float)
public void setRowExpandRatio(int rowIndex, float ratio)
Expand ratio defines how excess space is distributed among rows. Excess space means the space left over from components that are not sized relatively. By default, the excess space is distributed evenly.
Note, that height needs to be defined (fixed or relative, as opposed to undefined height) for this method to have any effect.
rowIndex
- The row index, starting from 0 for the topmost row.ratio
- #setHeight(float, int)
public float getRowExpandRatio(int rowIndex)
rowIndex
- The row index, starting from 0 for the topmost row.
setRowExpandRatio(int, float)
public Component getComponent(int x, int y)
x
- The column index, starting from 0 for the leftmost column.y
- The row index, starting from 0 for the topmost row.
public GridLayout.Area getComponentArea(Component component)
component
- the component whose area information is requested.
public void addLayoutClickListener(LayoutEvents.LayoutClickListener listener)
LayoutEvents.LayoutClickNotifier
LayoutEvents.LayoutClickEvent
.
Use #removeListener(LayoutClickListener)
to remove the
listener.
addLayoutClickListener
in interface LayoutEvents.LayoutClickNotifier
listener
- The listener to add@Deprecated public void addListener(LayoutEvents.LayoutClickListener listener)
#addLayoutClickListener(LayoutClickListener)
addListener
in interface LayoutEvents.LayoutClickNotifier
public void removeLayoutClickListener(LayoutEvents.LayoutClickListener listener)
LayoutEvents.LayoutClickNotifier
removeLayoutClickListener
in interface LayoutEvents.LayoutClickNotifier
listener
- LayoutClickListener to be removed@Deprecated public void removeListener(LayoutEvents.LayoutClickListener listener)
#removeLayoutClickListener(LayoutClickListener)
removeListener
in interface LayoutEvents.LayoutClickNotifier
public void setMargin(boolean enabled)
Layout.MarginHandler
setMargin
in interface Layout.MarginHandler
enabled
- true if margins should be enabled on all sides, false to
disable all marginspublic void setMargin(com.vaadin.shared.ui.MarginInfo marginInfo)
Layout.MarginHandler
NOTE: This will only affect the space around the
components in the layout, not space between the components in the
layout. Use #setSpacing(boolean)
to add space between the
components in the layout.
See the reference manual for more information about CSS rules for defining the size of the margin.
setMargin
in interface Layout.MarginHandler
marginInfo
- MarginInfo object containing the new margins.public com.vaadin.shared.ui.MarginInfo getMargin()
getMargin
in interface Layout.MarginHandler
public Alignment getDefaultComponentAlignment()
Layout.AlignmentHandler
getDefaultComponentAlignment
in interface Layout.AlignmentHandler
public void setDefaultComponentAlignment(Alignment defaultAlignment)
Layout.AlignmentHandler
Alignment.TOP_LEFT
.
setDefaultComponentAlignment
in interface Layout.AlignmentHandler
defaultAlignment
- The new default alignment
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |