extra.ui
Class RelativeContainer

java.lang.Object
  |
  +--waba.ui.Control
        |
        +--waba.ui.Container
              |
              +--extra.ui.RelativeContainer

public class RelativeContainer
extends Container

A Container extension that supports relative placement. ie you can specify you want to place a Control to the RIGHT of the last one, or in the center of the Container. The ExtraMainWindow has a RelativeContainer built in so you can use all the methods here directly on your app if you extend it instead of MainWindow. See the RelativeTest program for an example of it's use.


Field Summary
static int ABOVE
          above the last component added
static int AUTO
          use the preferred size of the control
static int BELOW
          below the last component added
static int BOTTOM
          on the bottom of the screen
static int CENTER
          in the center of the screen
static int FILL
          fill the whole width or height
static int LEFT
          the far left of the screen
static int LEFTOF
          to the left of the last component added
static int REST
          use the rest of the space from the current position to the right of the container (or bottom)
static int RIGHT
          on the far right of the screen
static int RIGHTOF
          to the right of the last component added
static int SAME
          the same as the relative Control (centered if different widths)
static int SAME_BOTTOM
          the same as the relative Control (bottom aligned if different widths)
static int SAME_LEFT
          the same as the relative Control (left aligned if different widths)
static int SAME_RIGHT
          the same as the relative Control (right aligned if different widths)
static int SAME_TOP
          the same as the relative Control (top aligned if different widths)
static int TOP
          at the top of the screen
 
Constructor Summary
RelativeContainer()
          Construct a new component that will fill to space provided
 
Method Summary
 void add(Control control, int x, int y)
          Adds a control to this container at the specified position using the last added Control for relative placement, if required.
 void add(Control control, int x, int y, Control relative)
          Adds a control to this container at the specified position relative to the given Control.
 void add(Control control, int x, int y, int width, int height)
          Adds a control to this container at the specified position using the last added Control for relative placement, if required.
 void add(Control control, int x, int y, int width, int height, Control relative)
          Adds a component to this container at the specified position relative to the given Control.
 Control findChild(int x, int y)
          Returns the child located at the given x and y coordinates.
 void layout()
          Layout all the Controls in this container
 void removePermanently(Control control)
          Remove this control permanently from this container.
 void setGaps(int x, int y)
          Sets the standard gap between components when added with the LEFTOF, RIGHTOF, ABOVE and BELOW settings.
 void setRect(int x, int y, int width, int height)
          Sets the bounds of this container and redoes the layout.
 
Methods inherited from class waba.ui.Container
add, paintChildren, remove
 
Methods inherited from class waba.ui.Control
addTimer, contains, createGraphics, getFontMetrics, getNext, getParent, getRect, onEvent, onPaint, postEvent, removeTimer, repaint
 
Methods inherited from class java.lang.Object
equals, hashCode, toString
 

Field Detail

LEFT

public static final int LEFT
the far left of the screen

LEFTOF

public static final int LEFTOF
to the left of the last component added

CENTER

public static final int CENTER
in the center of the screen

RIGHTOF

public static final int RIGHTOF
to the right of the last component added

RIGHT

public static final int RIGHT
on the far right of the screen

SAME

public static final int SAME
the same as the relative Control (centered if different widths)

SAME_LEFT

public static final int SAME_LEFT
the same as the relative Control (left aligned if different widths)

SAME_RIGHT

public static final int SAME_RIGHT
the same as the relative Control (right aligned if different widths)

TOP

public static final int TOP
at the top of the screen

ABOVE

public static final int ABOVE
above the last component added

BELOW

public static final int BELOW
below the last component added

BOTTOM

public static final int BOTTOM
on the bottom of the screen

SAME_TOP

public static final int SAME_TOP
the same as the relative Control (top aligned if different widths)

SAME_BOTTOM

public static final int SAME_BOTTOM
the same as the relative Control (bottom aligned if different widths)

AUTO

public static final int AUTO
use the preferred size of the control

FILL

public static final int FILL
fill the whole width or height

REST

public static final int REST
use the rest of the space from the current position to the right of the container (or bottom)
Constructor Detail

RelativeContainer

public RelativeContainer()
Construct a new component that will fill to space provided
Method Detail

setGaps

public void setGaps(int x,
                    int y)
Sets the standard gap between components when added with the LEFTOF, RIGHTOF, ABOVE and BELOW settings.
Parameters:
x - the x gap in pixels
y - the y gap in pixels

setRect

public void setRect(int x,
                    int y,
                    int width,
                    int height)
Sets the bounds of this container and redoes the layout.
Overrides:
setRect in class Control
Parameters:
x - the x coord of the bounding box
y - the y coord of the bounding box
width - the width of the bounding box
height - the height of the bounding box

add

public void add(Control control,
                int x,
                int y)
Adds a control to this container at the specified position using the last added Control for relative placement, if required. The preferred size, or the size set by setRect() is used.
Parameters:
control - the control to add
x - the x coordinate to add the control, or a placement constant.
x - the y coordinate to add the control, or a placement consrant.
See Also:
add(Control,int,int,int,int,Control)

add

public void add(Control control,
                int x,
                int y,
                Control relative)
Adds a control to this container at the specified position relative to the given Control. The preferred size, or the size set by setRect() is used.
Parameters:
control - the control to add
x - the x coordinate to add the control, or a placement constant.
x - the y coordinate to add the control, or a placement consrant.
relative - the control this one is to be placed relative to
See Also:
add(Control,int,int,int,int,Control)

add

public void add(Control control,
                int x,
                int y,
                int width,
                int height)
Adds a control to this container at the specified position using the last added Control for relative placement, if required. The size is also specified and can be absolute values or constants too.
Parameters:
control - the control to add
x - the x coordinate to add the control, or a placement constant.
x - the y coordinate to add the control, or a placement consrant.
width - the width of the control, or a size constant
height - the height of the control, or a size constant
See Also:
add(Control,int,int,int,int,Control)

add

public void add(Control control,
                int x,
                int y,
                int width,
                int height,
                Control relative)
Adds a component to this container at the specified position relative to the given Control. The available relative constants for the x coordinate are: The available relative constants for the y coordinate are: The size is also specified and can be either absolute values or one of the following constants:
Parameters:
control - the control to add
x - the x coordinate to place it, or one of the constants for relative placement.
y - the y coordinate to place it, or one of the constants for relative placement.
width - the width of the control, or a size constant
height - the height of the control, or a size constant
relative - the control this one is to be placed relative to

removePermanently

public void removePermanently(Control control)
Remove this control permanently from this container. If the straight remove(Control) method is used the layout is saved and the control can be re-added with add(Control). This is useful for Popup and temporarily hiding Controls. This method, however, is to be used when you never plan to add the Control again.
Parameters:
control - the control to remove

layout

public void layout()
Layout all the Controls in this container

findChild

public Control findChild(int x,
                         int y)
Returns the child located at the given x and y coordinates.
Overrides:
findChild in class Container