org.millstone.base.ui
Class GridLayout

java.lang.Object
  |
  +--org.millstone.base.ui.AbstractComponent
        |
        +--org.millstone.base.ui.AbstractComponentContainer
              |
              +--org.millstone.base.ui.GridLayout
All Implemented Interfaces:
Component, ComponentContainer, java.util.EventListener, Layout, MethodEventSource, Paintable, VariableOwner

public class GridLayout
extends AbstractComponentContainer
implements Layout

A container that consists of components with certain coordinates 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 (x1,y1,x2,y2) from the grid. One should not add components that would overlap with the existing components because in such case an GridLayout.OverlapsException is thrown. Adding component with cursor automatically extends the grid by increasing the grid height.

Since:
3.0
Version:
3.0.3
Author:
IT Mill Ltd.

Nested Class Summary
 class GridLayout.Area
          This class defines an area on a grid.
 class GridLayout.OutOfBoundsException
          An Exception object which is thrown when an area exceeds the bounds of the grid.
 class GridLayout.OverlapsException
          An Exception object which is thrown when two Items occupy the same space on a grid.
 
Nested classes inherited from class org.millstone.base.ui.ComponentContainer
ComponentContainer.ComponentAttachEvent, ComponentContainer.ComponentAttachListener, ComponentContainer.ComponentDetachEvent, ComponentContainer.ComponentDetachListener
 
Nested classes inherited from class org.millstone.base.ui.Component
Component.Event, Component.Listener
 
Nested classes inherited from class org.millstone.base.terminal.Paintable
Paintable.RepaintRequestEvent, Paintable.RepaintRequestListener
 
Constructor Summary
GridLayout()
          Constructs an empty grid layout that is extended as needed.
GridLayout(int width, int height)
          Constructor for grid of given size.
 
Method Summary
 void addComponent(Component component)
          Add a component into this container to the cursor position.
 void addComponent(Component c, int x, int y)
          Add component into this container to coordinates x1,y1 (NortWest corner of the area.)
 void addComponent(Component component, int x1, int y1, int x2, int y2)
          Adds a component with a specified area to the grid.
 java.util.Iterator getComponentIterator()
          Gets an Iterator to the component container contents.
 int getCursorX()
          Get the current cursor x-position.
 int getCursorY()
          Get the current cursor y-position.
 int getHeight()
          Get the height of the grid.
 java.lang.String getTag()
          Gets the components UIDL tag.
 int getWidth()
          Get the width of the grids.
 void newLine()
          Force the next component to be added to the beginning of the next line.
 void paintContent(PaintTarget target)
          Paints the contents of this component.
 void removeComponent(Component component)
          Removes the given component from this container.
 void removeComponent(int x, int y)
          Removes a component specified with it's top-left corner coordinates from this grid.
 void replaceComponent(Component oldComponent, Component newComponent)
          Replace a component in the container with another one without changing position.
 void setHeight(int height)
          Set the height of the grid.
 void setWidth(int width)
          Set the width of the grid.
 void space()
          Move cursor forwards by one.
 
Methods inherited from class org.millstone.base.ui.AbstractComponentContainer
addListener, addListener, attach, detach, fireComponentAttachEvent, fireComponentDetachEvent, moveComponentsFrom, removeAllComponents, removeListener, removeListener
 
Methods inherited from class org.millstone.base.ui.AbstractComponent
addListener, addListener, addListener, addListener, changeVariables, childRequestedRepaint, dependsOn, fireComponentEvent, fireEvent, getApplication, getCaption, getComponentError, getDescription, getDirectDependencies, getErrorMessage, getIcon, getLocale, getParent, getStyle, getWindow, isEnabled, isImmediate, isReadOnly, isVisible, paint, removeDirectDependency, removeListener, removeListener, removeListener, removeListener, removeListener, requestRepaint, requestRepaintRequests, setCaption, setComponentError, setDescription, setEnabled, setIcon, setImmediate, setLocale, setParent, setReadOnly, setStyle, setVisible
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.millstone.base.ui.ComponentContainer
addListener, addListener, moveComponentsFrom, removeAllComponents, removeListener, removeListener
 
Methods inherited from interface org.millstone.base.ui.Component
addListener, attach, childRequestedRepaint, detach, getApplication, getCaption, getIcon, getLocale, getParent, getStyle, getWindow, isEnabled, isImmediate, isReadOnly, isVisible, removeListener, setEnabled, setParent, setReadOnly, setStyle, setVisible
 
Methods inherited from interface org.millstone.base.terminal.Paintable
addListener, paint, removeListener, requestRepaint, requestRepaintRequests
 
Methods inherited from interface org.millstone.base.terminal.VariableOwner
changeVariables, dependsOn, getDirectDependencies, removeDirectDependency
 

Constructor Detail

GridLayout

public GridLayout(int width,
                  int height)
Constructor for grid of given size. 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:
width - Width of the grid.
height - Height of the grid.

GridLayout

public GridLayout()
Constructs an empty grid layout that is extended as needed.

Method Detail

addComponent

public void addComponent(Component component,
                         int x1,
                         int y1,
                         int x2,
                         int y2)
                  throws GridLayout.OverlapsException,
                         GridLayout.OutOfBoundsException

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 (x1, y1) and the lower right corner (x2, y2) 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 GridLayout.OverlapsException is thrown.

Parameters:
x1 - The X-coordinate of the upper left corner of the area c is supposed to occupy
y1 - The Y-coordinate of the upper left corner of the area c is supposed to occupy
x2 - The X-coordinate of the lower right corner of the area c is supposed to occupy
y2 - The Y-coordinate of the lower right corner of the area c is supposed to occupy
Throws:
GridLayout.OverlapsException - if the new component overlaps with any of the components already in the grid
GridLayout.OutOfBoundsException - if the coordinates are outside of the grid area.

addComponent

public void addComponent(Component c,
                         int x,
                         int y)
Add component into this container to coordinates x1,y1 (NortWest corner of the area.) End coordinates (SouthEast corner of the area) are the same as x1,y1. Component width and height is 1.

Parameters:
c - The component to be added.
x - X-coordinate
y - Y-coordinate

newLine

public void newLine()
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

public void space()
Move cursor forwards by one. If the cursor goes out of the right grid border, move it to next line.

See Also:
newLine()

addComponent

public void addComponent(Component component)
Add a 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 automaticly extended.

Specified by:
addComponent in interface ComponentContainer
Overrides:
addComponent in class AbstractComponentContainer
Parameters:
component - the component to be added

removeComponent

public void removeComponent(Component component)
Removes the given component from this container.

Specified by:
removeComponent in interface ComponentContainer
Overrides:
removeComponent in class AbstractComponentContainer
Parameters:
component - the component to be added

removeComponent

public void removeComponent(int x,
                            int y)
Removes a component specified with it's top-left corner coordinates from this grid.

Parameters:
x - Component's top-left corner's X-coordinate
y - Component's top-left corner's Y-coordinate

getComponentIterator

public java.util.Iterator getComponentIterator()
Gets an Iterator to the component container contents. Using the Iterator it's possible to step through the contents of the container.

Specified by:
getComponentIterator in interface ComponentContainer
Returns:
Iterator of the components inside the container.

paintContent

public void paintContent(PaintTarget target)
                  throws PaintException
Paints the contents of this component.

Overrides:
paintContent in class AbstractComponent
Parameters:
target - target UIDL stream where the component should paint itself to
Throws:
PaintException - The paint operation failed.

getTag

public java.lang.String getTag()
Gets the components UIDL tag.

Specified by:
getTag in class AbstractComponent
Returns:
Component UIDL tag as string.
See Also:
AbstractComponent.getTag()

setWidth

public void setWidth(int width)
Set the width of the grid. The width can not be reduced if there are any areas that would be outside of the shrunk grid.

Parameters:
width - New width of the grid.
Throws:
GridLayout.OutOfBoundsException - if the one of the areas would exceed the bounds of the grid after the modification of the grid size.

getWidth

public final int getWidth()
Get the width of the grids.

Returns:
The width of the grid

setHeight

public void setHeight(int height)
Set the height of the grid. The width can not be reduced if there are any areas that would be outside of the shrunk grid.


getHeight

public final int getHeight()
Get the height of the grid.

Returns:
int - how many cells high the grid is

getCursorX

public int getCursorX()
Get the current cursor x-position. The cursor position points the position for the next component that is added without specifying its coordinates. When the cursor position is occupied, the next component will be added to first free position after the cursor.

Returns:
Cursor x-coordinate.

getCursorY

public int getCursorY()
Get the current cursor y-position. The cursor position points the position for the next component that is added without specifying its coordinates. When the cursor position is occupied, the next component will be added to first free position after the cursor.

Returns:
Cursor y-coordinate.

replaceComponent

public void replaceComponent(Component oldComponent,
                             Component newComponent)
Description copied from interface: ComponentContainer
Replace a 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. Component attach and detach events should be taken care as with add and remove.

Specified by:
replaceComponent in interface ComponentContainer
Parameters:
oldComponent - The old component that will be replaced.
newComponent - The new component to be replaced


Copyright © 2000,2001,2002 IT Mill Ltd. All Rights Reserved.