waba.ui
Class Container

java.lang.Object
  |
  +--waba.ui.Control
        |
        +--waba.ui.Container
Direct Known Subclasses:
ComboBox, Grid, HtmlContainer, JustifiedContainer, ListBox, MultiEdit, ScrollBar, TabPanel, Window

public class Container
extends Control

Container is a control that contains child controls.


Field Summary
static byte BORDER_LOWERED
          used in the setBorderStyle method
static byte BORDER_NONE
          used in the setBorderStyle method
static byte BORDER_RAISED
          used in the setBorderStyle method
static byte BORDER_SIMPLE
          used in the setBorderStyle method
protected  Control children
          The children of the container.
protected  int lastH
           
protected  int lastW
           
protected  int lastX
           
protected  int lastY
           
protected  Window parentWindow
           
protected  boolean started
           
 Vector tabOrder
          Holds the controls that will be used to transfer focus when the tab key is pressed.
protected  Control tail
          The tail of the children list.
 
Fields inherited from class waba.ui.Control
AFTER, appId, appObj, asContainer, asWindow, backColor, backDis, BEFORE, BOTTOM, CENTER, clearValueInt, clearValueStr, enabled, FILL, FIT, fm, fmH, focusLess, focusTraversable, font, foreColor, foreDis, height, highlightRectsCount, isHighlighting, LEFT, parent, PREFERRED, RANGE, RIGHT, SAME, TOP, uiCE, uiFlat, uiPalm, uiVista, visible, width, x, x2, y, y2
 
Constructor Summary
Container()
          Creates a container with the default colors.
 
Method Summary
 void add(Control control)
          Adds a child control to this container.
 void add(Control control, int x, int y)
          Add the control to this container and set its rect to be the given x,y and PREFERRED as width/height relative to the last control added
 void add(Control control, int x, int y, Control relative)
          Add the control to this container and set its rect to be the given x,y and PREFERRED as width/height relative to the given control
 void broadcastEvent(Event e)
          posts a event to the children of this container and to all containers inside this containers; recursively.
 void clear()
          Clears all controls focusTraversable inside this container, recursively.
 Control findChild(int x, int y)
          Returns the child located at the given x and y coordinates.
 Control[] getChildren()
          Return an array of Controls that are added to this Container.
 Rect getClientRect()
          Returns the client rect for this Container, in relative coords.
 void getClientRect(Rect r)
          Returns the client rect for this Container, in relative coords.
protected  void onAdd()
          Called when this container is added to the parent.
protected  void onColorsChanged(boolean colorsChanged)
          Called after a setEnabled, setForeColor and setBackColor and when a control has been added to a Container.
 void onPaint(Graphics g)
          Draws the border (if any).
protected  void onRemove()
          Called when this container is removed from the parent.
protected  void onStart()
          Called when this container can be initialized.
 void paintChildren(Graphics g, int x, int y, int width, int height)
          Called by the system to draw the children of the container.
 void remove(Control control)
          Removes a child control from the container.
 void setBorderStyle(byte border)
          Sets the border for this container.
 void setEnabled(boolean enabled)
          sets if this container and all childrens can or not accept events
 void setHighlighting()
          Called by the event dispatcher to sets highlighting back to true.
 void swapToTopmostWindow()
          Call this method to swap this Container to the topmost window.
 
Methods inherited from class waba.ui.Control
addTimer, changeHighlighted, contains, createGraphics, drawHighlight, getAbsoluteRect, getBackColor, getFont, getFontMetrics, getForeColor, getNext, getParent, getParentWindow, getPos, getPreferredHeight, getPreferredWidth, getRect, getSize, isDisplayed, isEnabled, isVisible, onBoundsChanged, onEvent, onFontChanged, onWindowPaintFinished, postEvent, removeTimer, repaint, repaintNow, requestFocus, setBackColor, setBackForeColors, setFocusLess, setFont, setForeColor, setRect, setRect, setRect, setVisible, translateFromOrigin, uiStyleChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

children

protected Control children
The children of the container.

tail

protected Control tail
The tail of the children list.

BORDER_NONE

public static final byte BORDER_NONE
used in the setBorderStyle method

BORDER_LOWERED

public static final byte BORDER_LOWERED
used in the setBorderStyle method

BORDER_RAISED

public static final byte BORDER_RAISED
used in the setBorderStyle method

BORDER_SIMPLE

public static final byte BORDER_SIMPLE
used in the setBorderStyle method

parentWindow

protected Window parentWindow

lastX

protected int lastX

lastY

protected int lastY

lastW

protected int lastW

lastH

protected int lastH

started

protected boolean started

tabOrder

public Vector tabOrder
Holds the controls that will be used to transfer focus when the tab key is pressed. You can add or remove controls from here, but be careful not to add repeated controls.
Since:
SuperWaba 5.5
Constructor Detail

Container

public Container()
Creates a container with the default colors. Important note: this container has no default size. If adding to the MainWindow as another container, you may set its size as MainWindow.getMainWindow().getClientRect().

If you're extending the Container class and adding controls in its constructor, you may come into problems if you don't set the bounds as the first thing.

Method Detail

add

public void add(Control control,
                int x,
                int y)
Add the control to this container and set its rect to be the given x,y and PREFERRED as width/height relative to the last control added

add

public void add(Control control,
                int x,
                int y,
                Control relative)
Add the control to this container and set its rect to be the given x,y and PREFERRED as width/height relative to the given control

add

public void add(Control control)
Adds a child control to this container. Important: If you're swapping containers from the MainWindow, be sure that you set the focus on the new container after calling this add method. Otherwise, a MenuBar will not work. Or, use the handy method Window.swap

remove

public void remove(Control control)
Removes a child control from the container.

findChild

public Control findChild(int x,
                         int y)
Returns the child located at the given x and y coordinates.

getChildren

public Control[] getChildren()
Return an array of Controls that are added to this Container. If there are no Controls, returns null.

setEnabled

public void setEnabled(boolean enabled)
sets if this container and all childrens can or not accept events
Overrides:
setEnabled in class Control

broadcastEvent

public void broadcastEvent(Event e)
posts a event to the children of this container and to all containers inside this containers; recursively.
Since:
SuperWaba2.0beta4

paintChildren

public void paintChildren(Graphics g,
                          int x,
                          int y,
                          int width,
                          int height)
Called by the system to draw the children of the container.

setBorderStyle

public void setBorderStyle(byte border)
Sets the border for this container. Use BORDER_NONE,BORDER_LOWERED,BORDER_RAISED,BORDER_SIMPLE.

getClientRect

public Rect getClientRect()
Returns the client rect for this Container, in relative coords. The client rectangle usually excludes the title (if applicable) and the border.

getClientRect

public void getClientRect(Rect r)
Returns the client rect for this Container, in relative coords. In this version, you provide the instantiated Rect to be filled with the coords.

onColorsChanged

protected void onColorsChanged(boolean colorsChanged)
Description copied from class: Control
Called after a setEnabled, setForeColor and setBackColor and when a control has been added to a Container. If colorsChanged is true, it was called from setForeColor/setBackColor/Container.add; otherwise, it was called from setEnabled
Overrides:
onColorsChanged in class Control

onPaint

public void onPaint(Graphics g)
Draws the border (if any). If you override this method, be sure to call super.onPaint(g);, or the border will not be drawn.
Overrides:
onPaint in class Control
Tags copied from class: Control
Parameters:
g - the graphics object for drawing
See Also:
Graphics

onAdd

protected void onAdd()
Called when this container is added to the parent. Note that, if this container is a window, this method is not called when the window is popped up. When the container is being setup, the onStart method is called; then, the onAdd is called every time the container is added again.
Since:
SuperWaba 4.1

onRemove

protected void onRemove()
Called when this container is removed from the parent. Note that, if this container is a window, this method is not called when the window is popped up.
Since:
SuperWaba 4.1

onStart

protected void onStart()
Called when this container can be initialized. This differs from the onAdd method by that this method is called only once. When the container is being setup, the onStart method is called, followed by onAdd; then, the onAdd is called every time the container is added again.
Since:
SuperWaba 3.4

setHighlighting

public void setHighlighting()
Called by the event dispatcher to sets highlighting back to true. A class may extend this to decide when its time to turn it on again or not.

swapToTopmostWindow

public void swapToTopmostWindow()
Call this method to swap this Container to the topmost window. Note that since we have no idea who is our future parent window, we just use the topmost window. The topmost window is the one that is currently visible.
This method is useful if you have containers that are SINGLETONS and wish to set them as the current container. E.G.:
 public class MainMenu extends Container // create a Singleton from MainMenu
 {
    private static instance;
    public static getInstance()
    {
       return instance != null ? instance : (instance=new MainMenu());
    }
    private MainMenu()
    {
    }
  }
  // then at some other class, you can do:
  MainMenu.getInstance().swapToTopmostWindow();
  
Since:
SuperWaba 5.7

clear

public void clear()
Clears all controls focusTraversable inside this container, recursively.
Overrides:
clear in class Control