Package muntjac :: Package ui :: Module grid_layout :: Class GridLayout
[hide private]
[frames] | no frames]

Class GridLayout

source code

                             object --+                        
                                      |                        
                    util.IEventListener --+                    
                                          |                    
              terminal.paintable.IPaintable --+                
                                              |                
                                 object --+   |                
                                          |   |                
     terminal.variable_owner.IVariableOwner --+                
                                              |                
                                 object --+   |                
                                          |   |                
                terminal.sizeable.ISizeable --+                
                                              |                
                           component.IComponent --+            
                                                  |            
                                     object --+   |            
                                              |   |            
   event.method_event_source.IMethodEventSource --+            
                                                  |            
               abstract_component.AbstractComponent --+        
                                                      |        
                             object --+               |        
                                      |               |        
                    util.IEventListener --+           |        
                                          |           |        
              terminal.paintable.IPaintable --+       |        
                                              |       |        
                                 object --+   |       |        
                                          |   |       |        
     terminal.variable_owner.IVariableOwner --+       |        
                                              |       |        
                                 object --+   |       |        
                                          |   |       |        
                terminal.sizeable.ISizeable --+       |        
                                              |       |        
                           component.IComponent --+   |        
                                                  |   |        
            component_container.IComponentContainer --+        
                                                      |        
abstract_component_container.AbstractComponentContainer --+    
                                                          |    
                             object --+                   |    
                                      |                   |    
                    util.IEventListener --+               |    
                                          |               |    
              terminal.paintable.IPaintable --+           |    
                                              |           |    
                                 object --+   |           |    
                                          |   |           |    
     terminal.variable_owner.IVariableOwner --+           |    
                                              |           |    
                                 object --+   |           |    
                                          |   |           |    
                terminal.sizeable.ISizeable --+           |    
                                              |           |    
                           component.IComponent --+       |    
                                                  |       |    
            component_container.IComponentContainer --+   |    
                                                      |   |    
                                         layout.ILayout --+    
                                                          |    
                                             object --+   |    
                                                      |   |    
                                  layout.IMarginHandler --+    
                                                          |    
                             abstract_layout.AbstractLayout --+
                                                              |
                                                 object --+   |
                                                          |   |
                                   layout.IAlignmentHandler --+
                                                              |
                                                 object --+   |
                                                          |   |
                                     layout.ISpacingHandler --+
                                                              |
                                                 object --+   |
                                                          |   |
                   event.layout_events.ILayoutClickNotifier --+
                                                              |
                                                             GridLayout

A container that consists of components with certain coordinates (cell position) on a grid. It also maintains cursor for adding component in left to right, top to bottom order.

Each component in a GridLayout uses a certain area (column1,row1,column2,row2) from the grid. One should not add components that would overlap with the existing components because in such case an OverlapsException is thrown. Adding component with cursor automatically extends the grid by increasing the grid height.


Authors:
Vaadin Ltd., Richard Lincoln

Version: 1.1.2

Instance Methods [hide private]
 
__init__(self, columns=1, rows=1)
Constructor for grid of given size (number of cells).
source code
 
addComponent(self, *args)
Adds a component with a specified area to the grid.
source code
 
checkExistingOverlaps(self, area)
Tests if the given area overlaps with any of the items already on the grid.
source code
 
newLine(self)
Force the next component to be added to the beginning of the next line.
source code
 
space(self)
Moves the cursor forwards by one.
source code
 
removeComponent(self, *args)
Removes the given component from this container or removes the component specified with it's cell index.
source code
 
getComponentIterator(self)
Gets an iterator to the component container contents.
source code
 
getComponentCount(self)
Gets the number of contained components.
source code
 
paintContent(self, target)
Paints the contents of this component.
source code
 
getExpandRatioSum(self, ratioMap) source code
 
getComponentAlignment(self, childComponent)
Returns the current Alignment of given component.
source code
 
setColumns(self, columns)
Sets the number of columns in the grid.
source code
 
getColumns(self)
Get the number of columns in the grid.
source code
 
setRows(self, rows)
Sets the number of rows in the grid.
source code
 
getRows(self)
Get the number of rows in the grid.
source code
 
getCursorX(self)
Gets the current cursor x-position.
source code
 
setCursorX(self, cursorX)
Sets the current cursor x-position.
source code
 
getCursorY(self)
Gets the current cursor y-position.
source code
 
setCursorY(self, cursorY)
Sets the current cursor y-position.
source code
 
replaceComponent(self, oldComponent, newComponent)
Replaces the component in the container with another one without changing position.
source code
 
removeAllComponents(self)
Removes all components from the container.
source code
 
setComponentAlignment(self, *args)
Sets the component alignment using a short hand string notation.
source code
 
setSpacing(self, enabled)
Enable spacing between child components within this layout.
source code
 
isSpacingEnabled(self)
Returns: true if spacing between child components within this layout is enabled, false otherwise
source code
 
isSpacing(self)
Returns: true if spacing between child components within this layout is enabled, false otherwise
source code
 
insertRow(self, row)
Inserts an empty row at the chosen position in the grid.
source code
 
removeRow(self, row)
Removes row and all components in the row.
source code
 
setColumnExpandRatio(self, columnIndex, ratio)
Sets the expand ratio of given column.
source code
 
getColumnExpandRatio(self, columnIndex)
Returns the expand ratio of given column
source code
 
setRowExpandRatio(self, rowIndex, ratio)
Sets the expand ratio of given row.
source code
 
getRowExpandRatio(self, rowIndex)
Returns the expand ratio of given row.
source code
 
getComponent(self, x, y)
Gets the Component at given index.
source code
 
getComponentArea(self, component)
Returns information about the area where given component is layed in the GridLayout.
source code
 
addListener(self, listener, iface=None)
Registers a new (generic) component event listener for the component:
source code
 
addCallback(self, callback, eventType=None, *args) source code
 
removeListener(self, listener, iface=None)
Removes a previously registered component event listener from this component.
source code
 
removeCallback(self, callback, eventType=None) source code

Inherited from abstract_layout.AbstractLayout: changeVariables, fireClick, getMargin, setMargin

Inherited from abstract_component_container.AbstractComponentContainer: attach, detach, fireComponentAttachEvent, fireComponentDetachEvent, getInvalidSizedChildren, moveComponentsFrom, repaintChangedChildTrees, repaintChildTrees, requestRepaintAll, setEnabled, setHeight, setWidth

Inherited from abstract_component.AbstractComponent: __getstate__, __setstate__, addStyleName, childRequestedRepaint, fireComponentErrorEvent, fireComponentEvent, fireEvent, fireRequestRepaintEvent, focus, getApplication, getCSSHeight, getCSSWidth, getCaption, getComponentError, getData, getDebugId, getDescription, getErrorHandler, getErrorMessage, getHeight, getHeightUnits, getIcon, getListeners, getLocale, getParent, getStyle, getStyleName, getWidth, getWidthUnits, getWindow, handleError, hasListeners, isEnabled, isImmediate, isReadOnly, isVisible, paint, parseStringSize, registerCallback, registerListener, removeStyleName, requestRepaint, requestRepaintRequests, setCaption, setComponentError, setData, setDebugId, setDescription, setErrorHandler, setHeightUnits, setIcon, setImmediate, setLocale, setParent, setReadOnly, setSizeFull, setSizeUndefined, setStyle, setStyleName, setVisible, setWidthUnits, withdrawCallback, withdrawListener

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Variables [hide private]
  CLIENT_WIDGET = None
hash(x)
  _CLICK_EVENT = 'layout_click'
  _ALIGNMENT_DEFAULT = Alignment.TOP_LEFT

Inherited from abstract_component.AbstractComponent: SIZE_PATTERN

Inherited from terminal.sizeable.ISizeable: SIZE_UNDEFINED, UNITS_CM, UNITS_EM, UNITS_EX, UNITS_INCH, UNITS_MM, UNITS_PERCENTAGE, UNITS_PICAS, UNITS_PIXELS, UNITS_POINTS, UNIT_SYMBOLS

Inherited from layout.IAlignmentHandler: ALIGNMENT_BOTTOM, ALIGNMENT_HORIZONTAL_CENTER, ALIGNMENT_LEFT, ALIGNMENT_RIGHT, ALIGNMENT_TOP, ALIGNMENT_VERTICAL_CENTER

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, columns=1, rows=1)
(Constructor)

source code 

Constructor for grid of given size (number of cells). Note that grid's final size depends on the items that are added into the grid. Grid grows if you add components outside the grid's area.

Parameters:
  • columns - Number of columns in the grid.
  • rows - Number of rows in the grid.
Overrides: object.__init__

addComponent(self, *args)

source code 

Adds a component with a specified area to the grid. The area the new component should take is defined by specifying the upper left corner (column1, row1) and the lower right corner (column2, row2) of the area.

If the new component overlaps with any of the existing components already present in the grid the operation will fail and an OverlapsException is thrown.

Alternatively, adds the component into this container to cells column1,row1 (NortWest corner of the area.) End coordinates (SouthEast corner of the area) are the same as column1,row1. Component width and height is 1.

Finally, adds the component into this container to the cursor position. If the cursor position is already occupied, the cursor is moved forwards to find free position. If the cursor goes out from the bottom of the grid, the grid is automatically extended.

Parameters:
  • args - tuple of the form
    • (c, column1, row1, column2, row2)
      1. the component to be added.
      2. the column of the upper left corner of the area c is supposed to occupy.
      3. the row of the upper left corner of the area c is supposed to occupy.
      4. the column of the lower right corner of the area c is supposed to occupy.
      5. the row of the lower right corner of the area c is supposed to occupy.
    • (c, column, row)
      1. the component to be added.
      2. the column index.
      3. the row index.
    • (c)
      1. the component to be added.
Raises:
Overrides: component_container.IComponentContainer.addComponent

checkExistingOverlaps(self, area)

source code 

Tests if the given area overlaps with any of the items already on the grid.

Parameters:
  • area - the Area to be checked for overlapping.
Raises:

newLine(self)

source code 

Force the next component to be added to the beginning of the next line. By calling this function user can ensure that no more components are added to the right of the previous component.

See Also: space

space(self)

source code 

Moves the cursor forwards by one. If the cursor goes out of the right grid border, move it to next line.

See Also: newLine

removeComponent(self, *args)

source code 

Removes the given component from this container or removes the component specified with it's cell index.

Parameters:
  • args - tuple of the form
    • (c)
      1. the component to be removed.
    • (column, row)
      1. the component's column.
      2. the component's row.
Overrides: component_container.IComponentContainer.removeComponent

getComponentIterator(self)

source code 

Gets an iterator to the component container contents. Using the Iterator it's possible to step through the contents of the container.

Returns:
the iterator of the components inside the container.
Overrides: component_container.IComponentContainer.getComponentIterator

getComponentCount(self)

source code 

Gets the number of contained components. Consistent with the iterator returned by getComponentIterator.

Returns:
the number of contained components

paintContent(self, target)

source code 

Paints the contents of this component.

Parameters:
  • target - the Paint Event.
Raises:
Overrides: abstract_component.AbstractComponent.paintContent

getComponentAlignment(self, childComponent)

source code 

Returns the current Alignment of given component.

Returns:
the Alignment
Overrides: layout.IAlignmentHandler.getComponentAlignment
(inherited documentation)

setColumns(self, columns)

source code 

Sets the number of columns in the grid. The column count can not be reduced if there are any areas that would be outside of the shrunk grid.

Parameters:
  • columns - the new number of columns in the grid.

getColumns(self)

source code 

Get the number of columns in the grid.

Returns:
the number of columns in the grid.

setRows(self, rows)

source code 

Sets the number of rows in the grid. The number of rows can not be reduced if there are any areas that would be outside of the shrunk grid.

Parameters:
  • rows - the new number of rows in the grid.

getRows(self)

source code 

Get the number of rows in the grid.

Returns:
the number of rows in the grid.

getCursorX(self)

source code 

Gets the current cursor x-position. 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.

Returns:
the grid column the Cursor is on.

setCursorX(self, cursorX)

source code 

Sets the current cursor x-position. This is usually handled automatically by GridLayout.

getCursorY(self)

source code 

Gets the current cursor y-position. 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.

Returns:
the grid row the Cursor is on.

setCursorY(self, cursorY)

source code 

Sets the current cursor y-position. This is usually handled automatically by GridLayout.

replaceComponent(self, oldComponent, newComponent)

source code 

Replaces the component in the container with another one without changing position.

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. IComponent attach and detach events should be taken care as with add and remove.

Parameters:
  • oldComponent - the old component that will be replaced.
  • newComponent - the new component to be replaced.
Overrides: component_container.IComponentContainer.replaceComponent
(inherited documentation)

removeAllComponents(self)

source code 

Removes all components from the container. This should probably be re-implemented in extending classes for a more powerful implementation.

Overrides: component_container.IComponentContainer.removeAllComponents
(inherited documentation)

setComponentAlignment(self, *args)

source code 

Sets the component alignment using a short hand string notation.

Parameters:
  • args - tuple of the form
    • (component, alignment)
      1. A child component in this layout
      2. A short hand notation described in AlignmentUtils
    • (childComponent, horizontalAlignment, verticalAlignment)
Overrides: layout.IAlignmentHandler.setComponentAlignment

Deprecated: Replaced by setComponentAlignment

setSpacing(self, enabled)

source code 

Enable spacing between child components within this layout.

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 to add space around the layout.

See the reference manual for more information about CSS rules for defining the amount of spacing to use.

Parameters:
  • enabled - true if spacing should be turned on, false if it should be turned off
Overrides: layout.ISpacingHandler.setSpacing
(inherited documentation)

isSpacingEnabled(self)

source code 
Returns:
true if spacing between child components within this layout is enabled, false otherwise
Overrides: layout.ISpacingHandler.isSpacingEnabled
(inherited documentation)

isSpacing(self)

source code 
Returns:
true if spacing between child components within this layout is enabled, false otherwise
Overrides: layout.ISpacingHandler.isSpacing
(inherited documentation)

insertRow(self, row)

source code 

Inserts an empty row at the chosen position in the grid.

Parameters:
  • row - Number of the row the new row will be inserted before

removeRow(self, row)

source code 

Removes row and all components in the row. Components which span over several rows are removed if the selected row is the component's first row.

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.

Parameters:
  • row - The row number to remove

setColumnExpandRatio(self, columnIndex, ratio)

source code 

Sets the expand ratio of given column. Expand ratio defines how excess space is distributed among columns. Excess space means the space not consumed by non relatively sized components.

By default excess space is distributed evenly.

Note, that width needs to be defined for this method to have any effect.

See Also: setWidth

getColumnExpandRatio(self, columnIndex)

source code 

Returns the expand ratio of given column

Returns:
the expand ratio, 0.0 by default

setRowExpandRatio(self, rowIndex, ratio)

source code 

Sets the expand ratio of given row. Expand ratio defines how excess space is distributed among rows. Excess space means the space not consumed by non relatively sized components.

By default excess space is distributed evenly.

Note, that height needs to be defined for this method to have any effect.

See Also: setHeight

getRowExpandRatio(self, rowIndex)

source code 

Returns the expand ratio of given row.

Returns:
the expand ratio, 0.0 by default

See Also: setRowExpandRatio

getComponent(self, x, y)

source code 

Gets the Component at given index.

Parameters:
  • x - x-index
  • y - y-index
Returns:
Component in given cell or null if empty

getComponentArea(self, component)

source code 

Returns information about the area where given component is layed in the GridLayout.

Parameters:
  • component - the component whose area information is requested.
Returns:
an Area object that contains information how component is layed in the grid

addListener(self, listener, iface=None)

source code 

Registers a new (generic) component event listener for the component:

 class Listening(CustomComponent, IListener):

     # Stored for determining the source of an event
     ok = None

     status = None  # For displaying info about the event

     def __init__(self):
         layout = VerticalLayout()

         # Some miscellaneous component
         name = TextField("Say it all here")
         name.addListener(self)
         name.setImmediate(true)
         layout.addComponent(name)

         # Handle button clicks as generic events instead
         # of Button.ClickEvent events
         ok = new Button("OK")
         ok.addListener(self)
         layout.addComponent(ok)

         # For displaying information about an event
         status = new Label("")
         layout.addComponent(status)

         setCompositionRoot(layout)


     def componentEvent(event):
         # Act according to the source of the event
         if (event.getSource() == ok):
             getWindow().showNotification("Click!")

         status.setValue("Event from " +
                 event.getSource().__class__.__name__
                 + ": " + event.__class__.__name__)


 listening = Listening()
 layout.addComponent(listening)
Parameters:
  • listener - the new IListener to be registered.
Raises:
  • ValueError - unless method has a match in object
Overrides: event.layout_events.ILayoutClickNotifier.addListener
(inherited documentation)

addCallback(self, callback, eventType=None, *args)

source code 
Overrides: event.layout_events.ILayoutClickNotifier.addCallback

removeListener(self, listener, iface=None)

source code 

Removes a previously registered component event listener from this component.

Parameters:
  • listener - the listener to be removed.
Overrides: event.layout_events.ILayoutClickNotifier.removeListener
(inherited documentation)

removeCallback(self, callback, eventType=None)

source code 
Overrides: event.layout_events.ILayoutClickNotifier.removeCallback