totalcross.ui
Class AlignedLabelsContainer

totalcross.lang.Object
  extended by totalcross.ui.gfx.GfxSurface
      extended by totalcross.ui.Control
          extended by totalcross.ui.Container
              extended by totalcross.ui.AlignedLabelsContainer

public class AlignedLabelsContainer
extends Container

LabelContainer is a Container used to align all controls to the maximum width of a set of labels. You can define the label alignment. The controls that you add to this container are placed at the right of the labels. Here's a sample of how to use it:

   totalcross.lang.String[] labels =
   {
      "Name",
      "Born date",
      "Telephone",
      "Address",
      "City",
      "Country",
      "",
   };
   AlignedLabelsContainer c = new AlignedLabelsContainer(labels);
   c.setBorderStyle(BORDER_LOWERED);
   c.labelAlign = RIGHT;
   c.foreColors = new int[]{Color.RED,Color.BLACK,Color.BLACK,Color.BLACK,Color.BLACK,Color.BLACK,Color.BLACK,};
   c.setInsets(2,2,2,2);
   add(c,LEFT+2,TOP+2,FILL-2,PREFERRED+4);
   for (int i =0; i < labels.length-2; i++)
      c.add(new Edit(),LEFT+2,AFTER+(i==0?2:0));
   c.add(new ComboBox(new totalcross.lang.String[]{"Brazil","France"}),LEFT+2,AFTER);
   c.add(new Button("Insert data"),RIGHT,SAME);
   c.add(new Button("Clear data"),RIGHT,AFTER,SAME,PREFERRED);
 

Since:
TotalCross 1.01

Field Summary
 int[] foreColors
          Set an array with the same number of labels and the colors you want to show for each label.
 int labelAlign
          The alignment of the labels.
protected  String[] labels
          The label captions
protected  int[] widths
          The computed widths for the labels.
 
Fields inherited from class totalcross.ui.Container
alwaysEraseBackground, BORDER_LOWERED, BORDER_NONE, BORDER_RAISED, BORDER_SIMPLE, children, controlFound, finishedStart, ignoreOnAddAgain, ignoreOnRemove, insets, lastH, lastScreenWidth, lastW, lastX, lastY, nextTransitionEffect, started, tabOrder, tail, TRANSITION_CLOSE, TRANSITION_NONE, TRANSITION_OPEN, transitionEffect
 
Fields inherited from class totalcross.ui.Control
AFTER, appId, appObj, asContainer, asWindow, backColor, BEFORE, BOTTOM, BOTTOM_OF, CENTER, CENTER_OF, clearValueInt, clearValueStr, enabled, enableUpdateScreen, FILL, FIT, fm, fmH, focusHandler, focusLess, focusOnPenDown, focusTraversable, font, foreColor, height, isHighlighting, KEEP, LEFT, onEventFirst, parent, PREFERRED, RANGE, repositionAllowed, RIGHT, RIGHT_OF, SAME, setFont, setH, setRel, setW, setX, setY, TOP, transparentBackground, uiCE, uiFlat, uiPalm, uiVista, visible, width, WILL_RESIZE, x, y
 
Constructor Summary
AlignedLabelsContainer()
          Creates a new AlignedLabelsContainer without labels.
AlignedLabelsContainer(String[] labels)
          Creates a new AlignedLabelsContainer with the given labels.
AlignedLabelsContainer(String[] labels, int vgap)
          Creates a new AlignedLabelsContainer with the given labels.
 
Method Summary
 int getLeftInset()
          Returns the left inset.
 int getLineHeight()
          Returns the height of a line.
 int getLineY(int line)
          Given a line (staring from 0), returns the y position.
 int getPreferredHeight()
          Returns the preferred height of this control.
 int getPreferredWidth()
          Returns the preferred width of this control.
 void onFontChanged()
          Called after a setFont
 void onPaint(Graphics g)
          Draws the border (if any).
 void setInsets(int left, int right, int top, int bottom)
          Sets the insets value to match the given ones.
 void setLabels(String[] labels, int vgap)
          Sets the labels and the vgap (which may be 0).
 
Methods inherited from class totalcross.ui.Container
add, add, add, add, add, broadcastEvent, clear, findChild, findNearestChild, findNextFocusControl, getBorderStyle, getChildren, getClientRect, getClientRect, getFocusableControls, getInsets, incLastX, incLastY, initUI, onAddAgain, onColorsChanged, onRemove, paintChildren, remove, removeAll, resize, resizeHeight, resizeWidth, setBorderStyle, setEnabled, setHighlighting, swapToTopmostWindow
 
Methods inherited from class totalcross.ui.Control
_onEvent, addFocusListener, addGridListener, addHighlightListener, addKeyListener, addPenListener, addPressListener, addTimer, addTimer, addTimerListener, addWindowListener, changeHighlighted, contains, getAbsoluteRect, getBackColor, getEventListeners, getFont, getForeColor, getGraphics, getHeight, getNext, getParent, getParentWindow, getPos, getPressedEvent, getPrev, getRect, getSize, getWidth, getX, getX2, getY, getY2, handleGeographicalFocusChangeKeys, isDisplayed, isEnabled, isInsideOrNear, isVisible, isVisibleAndInside, onBoundsChanged, onEvent, onWindowPaintFinished, postEvent, postPressedEvent, removeFocusListener, removeGridListener, removeHighlightListener, removeKeyListener, removePenListener, removePressListener, removeTimer, removeTimerListener, removeWindowListener, repaint, repaintNow, reposition, reposition, requestFocus, setBackColor, setBackForeColors, setFocusLess, setFont, setForeColor, setRect, setRect, setRect, setRect, setVisible, translateFromOrigin, uiStyleChanged, updateScreen, updateTemporary
 
Methods inherited from class totalcross.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

labels

protected String[] labels
The label captions


widths

protected int[] widths
The computed widths for the labels.


foreColors

public int[] foreColors
Set an array with the same number of labels and the colors you want to show for each label. If the number of labels differ, you will get an Exception.

Since:
TotalCross 1.2

labelAlign

public int labelAlign
The alignment of the labels. Defaults to LEFT.

See Also:
Control.LEFT, Control.CENTER, Control.RIGHT
Constructor Detail

AlignedLabelsContainer

public AlignedLabelsContainer()
Creates a new AlignedLabelsContainer without labels. You may call setLabels to set the labels.

See Also:
AlignedLabelsContainer(totalcross.lang.String[]), AlignedLabelsContainer(totalcross.lang.String[], int), setLabels(totalcross.lang.String[], int)

AlignedLabelsContainer

public AlignedLabelsContainer(String[] labels)
Creates a new AlignedLabelsContainer with the given labels.

Parameters:
labels - The strings that represents the labels. You may pass null, but be sure to call setLabels to set the labels.
See Also:
AlignedLabelsContainer(totalcross.lang.String[], int), setLabels(totalcross.lang.String[], int)

AlignedLabelsContainer

public AlignedLabelsContainer(String[] labels,
                              int vgap)
Creates a new AlignedLabelsContainer with the given labels.

Parameters:
labels - The strings that represents the labels. You may pass null, but be sure to call setLabels to set the labels.
vgap - The extra gap between rows. May be negative.
See Also:
AlignedLabelsContainer(totalcross.lang.String[]), setLabels(totalcross.lang.String[], int)
Method Detail

setLabels

public void setLabels(String[] labels,
                      int vgap)
Sets the labels and the vgap (which may be 0).

Parameters:
labels - The strings that represents the labels. You may pass null, but be sure to call setLabels to set the labels.
vgap - The extra gap between rows. May be negative.
Since:
TotalCross 1.2
See Also:
AlignedLabelsContainer(totalcross.lang.String[]), AlignedLabelsContainer(totalcross.lang.String[], int)

onFontChanged

public void onFontChanged()
Description copied from class: Control
Called after a setFont

Overrides:
onFontChanged in class Control

setInsets

public void setInsets(int left,
                      int right,
                      int top,
                      int bottom)
Description copied from class: Container
Sets the insets value to match the given ones.

Overrides:
setInsets in class Container

getPreferredWidth

public int getPreferredWidth()
Description copied from class: Control
Returns the preferred width of this control.

Overrides:
getPreferredWidth in class Control

getPreferredHeight

public int getPreferredHeight()
Description copied from class: Control
Returns the preferred height of this control.

Overrides:
getPreferredHeight in class Control

onPaint

public void onPaint(Graphics g)
Description copied from class: Container
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 Container
Parameters:
g - the graphics object for drawing
See Also:
Graphics

getLineY

public int getLineY(int line)
Given a line (staring from 0), returns the y position. Can be used to easily align the controls. Note that the line number may be greater than the number of assigned Labels.
 add(chCasado = new Check("Married"),LEFT,getLineY(4)+2);
 

Since:
TotalCross 1.14

getLineHeight

public int getLineHeight()
Returns the height of a line.

Since:
TotalCross 1.14

getLeftInset

public int getLeftInset()
Returns the left inset. To be able to center a control, you have to do like
 control.setRect(CENTER-getLeftInset()/2,...);