Package totalcross.ui
Class AlignedLabelsContainer
- java.lang.Object
-
- totalcross.ui.gfx.GfxSurface
-
- totalcross.ui.Control
-
- totalcross.ui.Container
-
- totalcross.ui.AlignedLabelsContainer
-
public class AlignedLabelsContainer extends Container
AlignedLabelsContaineris aContainerused 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: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); c.setFont(font.asBold()); // labels are bold c.childrenFont = font; // but controls are normal 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 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
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class totalcross.ui.Control
Control.TranslucentShape
-
-
Field Summary
Fields Modifier and Type Field Description FontchildrenFontSets this member to the font you want to set to the controls that are added to this container.int[]foreColorsSets an array with the same number of labels and the colors you want to show for each label.intlabelAlignThe alignment of the labels.protected java.lang.String[]labelsThe label captions.protected int[]widthsThe computed widths for the labels.-
Fields inherited from class totalcross.ui.Container
alwaysEraseBackground, BACKGROUND_CYLINDRIC_SHADED, BACKGROUND_SHADED, BACKGROUND_SHADED_INV, BACKGROUND_SOLID, backgroundStyle, BORDER_LOWERED, BORDER_NONE, BORDER_RAISED, BORDER_ROUNDED, BORDER_SIMPLE, BORDER_TOP, borderColor, children, controlFound, finishedStart, ignoreOnAddAgain, ignoreOnRemove, insets, lastH, lastScreenWidth, lastW, lastX, lastY, npback, numChildren, started, tabOrder, tail, TRANSITION_CLOSE, TRANSITION_FADE, TRANSITION_NONE, TRANSITION_OPEN, TRANSITION_TIME, transitionEffect
-
Fields inherited from class totalcross.ui.Control
AFTER, alphaValue, appId, appObj, asContainer, asWindow, backColor, BEFORE, BOTTOM, BOTTOM_OF, BRIGHTER_BACKGROUND, callListenersOnAllTargets, CENTER, CENTER_OF, clearValueInt, clearValueStr, DARKER_BACKGROUND, DP, effect, enableUpdateScreen, esce, eventsEnabled, FILL, fillColor, FIT, floating, fm, fmH, focusHandler, focusLess, focusOnPenDown, focusTraversable, font, FONTSIZE, foreColor, height, ignoreInsets, isHighlighting, isTablet, KEEP, keepDisabled, keepEnabled, LEFT, next, nextTabControl, npParts, offscreen, offscreen0, onEventFirst, parent, PARENTSIZE, PARENTSIZEMAX, PARENTSIZEMIN, PREFERRED, prev, RANGE, repositionAllowed, RIGHT, RIGHT_OF, SAME, SCREENSIZE, SCREENSIZEMAX, SCREENSIZEMIN, setFont, setH, setRel, setW, setX, SETX_NOT_SET, setY, tempW, textShadowColor, TOP, translucentShape, transparentBackground, uiAdjustmentsBasedOnFontHeightIsSupported, uiAndroid, UICONST, uiFlat, uiHolo, uiMaterial, uiVista, visible, width, WILL_RESIZE, x, y
-
-
Constructor Summary
Constructors Constructor Description AlignedLabelsContainer()Creates a newAlignedLabelsContainerwithout labels.AlignedLabelsContainer(java.lang.String[] labels)Creates a newAlignedLabelsContainerwith the given labels.AlignedLabelsContainer(java.lang.String[] labels, int vgap)Creates a newAlignedLabelsContainerwith the given labels.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(Control c)Since this is anAlignedLabelsContainer, use this to add a label.intgetLeftInset()Returns the left inset.intgetLineHeight()Returns the height of a line.intgetLineY(int line)Given a line (staring from 0), returns the y position.intgetPreferredHeight()Returns the preferred height of this control.intgetPreferredWidth()Returns the preferred width of this control.voidonFontChanged()Called after asetFont()voidonPaint(Graphics g)Draws the border (if any).voidsetInsets(int left, int right, int top, int bottom)Sets the insets value to match the given ones.voidsetLabels(java.lang.String[] labels, int vgap)Sets the labels and the extra gap between rows (which may be 0).-
Methods inherited from class totalcross.ui.Container
add, add, add, add, applyTransitionEffect, broadcastEvent, clear, fillBackground, fillBackground, findChild, findNearestChild, findNextFocusControl, getBorderStyle, getChildren, getChildrenCount, getClientRect, getClientRect, getFirstChild, getFocusableControls, getInsets, incLastX, incLastY, initUI, isPressed, moveFocusToNextControl, moveFocusToNextEditable, onAddAgain, onColorsChanged, onRemove, onSwapFinished, paintChildren, remove, removeAll, resize, resizeHeight, resizeWidth, setBorderStyle, setEnabled, setFocusTraversable, setHighlighting, setNextTransitionEffect, setPressColor, setPressed, swapToTopmostWindow
-
Methods inherited from class totalcross.ui.Control
_onEvent, addEnabledStateListener, addFocusListener, addFontChangeHandler, addGridListener, addHandler, addHighlightListener, addKeyListener, addListContainerListener, addMouseListener, addMultiTouchListener, addPenListener, addPressListener, addPushNotificationListener, addSizeChangeHandler, addTimer, addTimer, addTimerListener, addValueChangeHandler, addWindowListener, bringToFront, changeHighlighted, contains, drawTranslucentBackground, getAbsoluteRect, getBackColor, getDoEffect, getEffectH, getEffectW, getEffectX, getEffectY, getEventListeners, getFont, getForeColor, getGap, getGraphics, getHeight, getNext, getParent, getParentWindow, getPos, getPressedEvent, getPrev, getRect, getSize, getTextShadowColor, getWidth, getX, getX2, getY, getY2, hadParentScrolled, handleGeographicalFocusChangeKeys, hasFocus, internalSetEnabled, intXYWH, isActionEvent, isChildOf, isDisplayed, isEnabled, isFloating, isInsideOrNear, isObscured, isTopMost, isVisible, isVisibleAndInside, onBoundsChanged, onEvent, onWindowPaintFinished, post, postEvent, postPressedEvent, releaseScreenShot, removeEnabledStateListener, removeFocusListener, removeGridListener, removeHandler, removeHighlightListener, removeKeyListener, removeListContainerListener, removeMouseListener, removeMultiTouchListener, removePenListener, removePressListener, removePushNotificationListener, removeTimer, removeTimerListener, removeWindowListener, repaint, repaintNow, reposition, reposition, repositionChildren, requestFocus, resetSetPositions, resetStyle, safeRepaintNow, safeUpdateScreen, sendToBack, setBackColor, setBackForeColors, setDoEffect, setFloating, setFocusLess, setFont, setForeColor, setNinePatch, setNinePatch, setRect, setRect, setRect, setRect, setSet, setTextShadowColor, setTranslucent, setVisible, showTip, takeInitialScreenShot, takeScreenShot, translateFromOrigin, uiStyleChanged, updateScreen, updateTemporary, willOpenKeyboard
-
-
-
-
Field Detail
-
labels
protected java.lang.String[] labels
The label captions.
-
widths
protected int[] widths
The computed widths for the labels.
-
childrenFont
public Font childrenFont
Sets this member to the font you want to set to the controls that are added to this container.- Since:
- TotalCross 1.25
-
foreColors
public int[] foreColors
Sets an array with the same number of labels and the colors you want to show for each label. If the number of labels differs, you will get an exception. It can be used to hide a label: just set its foreground color to the background color.- Since:
- TotalCross 1.2
-
labelAlign
public int labelAlign
The alignment of the labels. Defaults toLEFT.- See Also:
Control.LEFT,Control.CENTER,Control.RIGHT
-
-
Constructor Detail
-
AlignedLabelsContainer
public AlignedLabelsContainer()
Creates a newAlignedLabelsContainerwithout labels. You may callsetLabels()to set the labels.
-
AlignedLabelsContainer
public AlignedLabelsContainer(java.lang.String[] labels)
Creates a newAlignedLabelsContainerwith the given labels.- Parameters:
labels- The strings that represents the labels. You may passnull, but be sure to callsetLabels()to set the labels.- See Also:
AlignedLabelsContainer(String[], int),setLabels(String[], int)
-
AlignedLabelsContainer
public AlignedLabelsContainer(java.lang.String[] labels, int vgap)Creates a newAlignedLabelsContainerwith the given labels.- Parameters:
labels- The strings that represents the labels. You may passnull, but be sure to callsetLabels()to set the labels.vgap- The extra gap between rows. May be negative.- See Also:
AlignedLabelsContainer(String[]),setLabels(String[], int)
-
-
Method Detail
-
setLabels
public void setLabels(java.lang.String[] labels, int vgap)Sets the labels and the extra gap between rows (which may be 0).- Parameters:
labels- The strings that represents the labels. You may passnull, but be sure to callsetLabels()again to set the labels with a valid value.vgap- The extra gap between rows. May be negative.- Since:
- TotalCross 1.2
- See Also:
AlignedLabelsContainer(String[]),AlignedLabelsContainer(String[], int)
-
onFontChanged
public void onFontChanged()
Called after asetFont()- Overrides:
onFontChangedin classControl
-
add
public void add(Control c)
Since this is anAlignedLabelsContainer, use this to add a label.
-
setInsets
public void setInsets(int left, int right, int top, int bottom)Sets the insets value to match the given ones.
-
getPreferredWidth
public int getPreferredWidth()
Returns the preferred width of this control.- Overrides:
getPreferredWidthin classControl- Returns:
- The preferred width of this control.
-
getPreferredHeight
public int getPreferredHeight()
Returns the preferred height of this control.- Overrides:
getPreferredHeightin classControl- Returns:
- The preferred height of this control.
-
onPaint
public void onPaint(Graphics g)
Draws the border (if any).
-
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.- 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 this:control.setRect(CENTER-getLeftInset()/2,...);
- Returns:
- The left inset.
-
-