Package totalcross.ui
Class PushButtonGroup
- java.lang.Object
-
- totalcross.ui.gfx.GfxSurface
-
- totalcross.ui.Control
-
- totalcross.ui.PushButtonGroup
-
public class PushButtonGroup extends Control
Group or matrix of pushbuttons in a single control. Is one of the most versatiles controls of TotalCross. Here is an example of constructor:new PushButtonGroup(new String[]{"Button1","Button2","Button3"},false,-1,-1,4,0,false,PushButtonGroup.NORMAL)The width of each button is calculated based on its caption size plus the insideGap, if you use PREFERRED as the width; otherwise, it uses the size you specified (E.G.: FILL, FIT, etc). The height is calculated based on the font's size or on the height you specified.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class totalcross.ui.Control
Control.TranslucentShape
-
-
Field Summary
Fields Modifier and Type Field Description intAUTO_DELAYThe frequency in which the PRESSED event will be posted after the INITIAL_DELAY was reached.booleanautoRepeatSet to true to enable auto-repeat feature for this button.static byteBUTTONThe button will be selected and unselected immediately, acting like a real buttonstatic byteCHECKOne click in the button will select it and another click will unselect it.booleancheckAppearsRaisedSet to true to make the CHECK mode appear as raised by default (default is: button lowered when not selected).int[]colspanSpan across multiple columns and rows.boolean[]hiddenThe boolean array that defines which buttons are hidden.intINITIAL_DELAYThe initial delay to start the auto-repeat.intinsideGapSpace between the text and the button border.java.lang.String[]namesstatic byteNORMALNormal: only one selected at a timeRect[]rectsThe bounds of each of the buttons.int[]rowspanSpan across multiple columns and rows.-
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 PushButtonGroup(java.lang.String[] names, boolean atLeastOne, int selected, int gap, int insideGap, int rows, boolean allSameWidth, byte type)Create the button matrix.PushButtonGroup(java.lang.String[] names, int gap, int rows)Create the button matrix, with insideGap = 4, selected = -1, atLeastOne = false, allSameWidth = true and type = BUTTON.PushButtonGroup(java.lang.String[] names, int gap, int insideGap, int rows)Create the button matrix, with selected = -1, atLeastOne = false, allSameWidth = false and type = BUTTON.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Clears this control, selecting index clearValueInt.intgetEffectH()intgetEffectW()intgetEffectX()intgetEffectY()intgetHighlightColor()booleangetHighlightEmptyValues()booleangetHighlightSelected()intgetPreferredHeight()Returns the preferred height of this control.intgetPreferredWidth()Returns the preferred width of this control.intgetSelectedIndex()Returns the index of the selected button, or -1 if none is selected.java.lang.StringgetSelectedItem()Returns the caption of the selected button, ornullif no button is selectedControlhandleGeographicalFocusChangeKeys(KeyEvent ke)Used by the main event loop to give the currently focused control an opportunity to act directly on the KeyEvent.protected voidonBoundsChanged(boolean screenChanged)Called after a setRect.protected voidonColorsChanged(boolean colorsChanged)Called after a setEnabled, setForeColor and setBackColor and when a control has been added to a Container.voidonEvent(Event event)Called to process key, pen, control and other posted events.protected voidonFontChanged()Called after a setFontvoidonPaint(Graphics g)Called to draw the control.voidsetBorder(boolean border)Sets the border.voidsetColor(int index, int foreColor, int backColor)Sets a button's index color.voidsetCursorColor(int color)Sets the cursor color for this PushButtonGroup.voidsetHighlightColor(int highlightColor)voidsetHighlightEmptyValues(boolean highlightEmptyValues)voidsetHighlightSelected(boolean highlightSelected)voidsetNames(java.lang.String[] newNames)Sets the names.voidsetSelectedIndex(int ind)Sets the selected button index.voidsetSimpleBorder(boolean simple)Uses a border with a single line (not 3d and not Android's)-
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, getEventListeners, getFont, getForeColor, getGap, getGraphics, getHeight, getNext, getParent, getParentWindow, getPos, getPressedEvent, getPrev, getRect, getSize, getTextShadowColor, getWidth, getX, getX2, getY, getY2, hadParentScrolled, hasFocus, internalSetEnabled, intXYWH, isActionEvent, isChildOf, isDisplayed, isEnabled, isFloating, isInsideOrNear, isObscured, isTopMost, isVisible, isVisibleAndInside, 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, setEnabled, setFloating, setFocusLess, setFont, setForeColor, setNinePatch, setNinePatch, setRect, setRect, setRect, setRect, setSet, setTextShadowColor, setTranslucent, setVisible, showTip, takeInitialScreenShot, takeScreenShot, translateFromOrigin, uiStyleChanged, updateScreen, updateTemporary, willOpenKeyboard
-
-
-
-
Field Detail
-
NORMAL
public static final byte NORMAL
Normal: only one selected at a time- See Also:
- Constant Field Values
-
BUTTON
public static final byte BUTTON
The button will be selected and unselected immediately, acting like a real button- See Also:
- Constant Field Values
-
CHECK
public static final byte CHECK
One click in the button will select it and another click will unselect it. However, only one button can be selected at a time- See Also:
- Constant Field Values
-
checkAppearsRaised
public boolean checkAppearsRaised
Set to true to make the CHECK mode appear as raised by default (default is: button lowered when not selected).
-
names
public java.lang.String[] names
-
insideGap
public int insideGap
Space between the text and the button border. The ideal is 4. If allSameWidth is true, it is only used to compute the preferred width and may be overriden; otherwise, it is used as the internal gap.
-
rects
public Rect[] rects
The bounds of each of the buttons. Never change this directly.
-
autoRepeat
public boolean autoRepeat
Set to true to enable auto-repeat feature for this button. The PRESSED event will be sent while this button is held. Works only when the type is BUTTON.- Since:
- TotalCross 1.53
- See Also:
INITIAL_DELAY,AUTO_DELAY
-
INITIAL_DELAY
public int INITIAL_DELAY
The initial delay to start the auto-repeat. Defaults to 600ms.
-
AUTO_DELAY
public int AUTO_DELAY
The frequency in which the PRESSED event will be posted after the INITIAL_DELAY was reached. Defaults to 150ms.
-
hidden
public boolean[] hidden
The boolean array that defines which buttons are hidden. If you want to hide a button, just access this and set an array index to true. Note that you must also explicitly call the repaint function to update the control. Sample:pbg.hidden[5] = true; // hides button 5 repaint();
- Since:
- SuperWaba 5.0
-
colspan
public int[] colspan
Span across multiple columns and rows. These cells that will be overriden must be null and the allSameWidth must be true. This sample:String []numerics = {"1","2","3","4","5","6","7","clear",null,"0",null,null}; PushButtonGroup pbg=new PushButtonGroup(numerics,false,-1,4,0,4,true,PushButtonGroup.BUTTON); pbg.colspan[7] = 2; pbg.rowspan[7] = 2; add(pbg, LEFT+50,AFTER+50,FILL-50,FILL-50);... will show this:1 2 3 4 5 6 7 clear 0- Since:
- TotalCross 1.3
-
rowspan
public int[] rowspan
Span across multiple columns and rows. These cells that will be overriden must be null and the allSameWidth must be true. This sample:String []numerics = {"1","2","3","4","5","6","7","clear",null,"0",null,null}; PushButtonGroup pbg=new PushButtonGroup(numerics,false,-1,4,0,4,true,PushButtonGroup.BUTTON); pbg.colspan[7] = 2; pbg.rowspan[7] = 2; add(pbg, LEFT+50,AFTER+50,FILL-50,FILL-50);... will show this:1 2 3 4 5 6 7 clear 0- Since:
- TotalCross 1.3
-
-
Constructor Detail
-
PushButtonGroup
public PushButtonGroup(java.lang.String[] names, boolean atLeastOne, int selected, int gap, int insideGap, int rows, boolean allSameWidth, byte type)Create the button matrix.- Parameters:
names- captions of the buttons. You can specify some names as null so the button is not displayed. This is good if you're creating a button matrix and want to hide some buttons definetively (you can hide some buttons temporarily setting the hiden array). You can also use thehiddenproperty to dynamically show/hide buttons.atLeastOne- if true, at least one button must be selectedselected- default index to appear selected, or -1 if nonegap- space between the buttons, -1 glue them.insideGap- Space between the text and the button border. The ideal is 4. If allSameWidth is true, it is only used to compute the preferred width and may be overriden; otherwise, it is used as the internal gap.rows- if > 1, creates a button matrixallSameWidth- if true, all the buttons will have the width of the most large one.type- can be NORMAL, BUTTON or CHECK
-
PushButtonGroup
public PushButtonGroup(java.lang.String[] names, int gap, int rows)Create the button matrix, with insideGap = 4, selected = -1, atLeastOne = false, allSameWidth = true and type = BUTTON.- Parameters:
names- captions of the buttons. You can specify some names as null so the button is not displayed. This is good if you're creating a button matrix and want to hide some buttons definetively (you can hide some buttons temporarily setting the hiden array). You can also use thehiddenproperty to dynamically show/hide buttons.gap- space between the buttons, -1 glue them.rows- if > 1, creates a button matrix
-
PushButtonGroup
public PushButtonGroup(java.lang.String[] names, int gap, int insideGap, int rows)Create the button matrix, with selected = -1, atLeastOne = false, allSameWidth = false and type = BUTTON.- Parameters:
names- captions of the buttons. You can specify some names as null so the button is not displayed. This is good if you're creating a button matrix and want to hide some buttons definetively (you can hide some buttons temporarily setting the hiden array). You can also use thehiddenproperty to dynamically show/hide buttons.gap- space between the buttons, -1 glue them.insideGap- Space between the text and the button border. The ideal is 4. If allSameWidth is true, it is only used to compute the preferred width and may be overriden; otherwise, it is used as the internal gap.rows- if > 1, creates a button matrix
-
-
Method Detail
-
setBorder
public void setBorder(boolean border)
Sets the border. Setting it to false will make the buttons borderless.- Parameters:
border-
-
setNames
public void setNames(java.lang.String[] newNames)
Sets the names. Note that it must have the same number of elements passed in the constructor, and that the bounds are NOT recomputed. Repaint is called.
-
setColor
public void setColor(int index, int foreColor, int backColor)Sets a button's index color. The other buttons will remain with the default color. Pass -1 to restore the default color.
-
setSimpleBorder
public void setSimpleBorder(boolean simple)
Uses a border with a single line (not 3d and not Android's)
-
getSelectedIndex
public int getSelectedIndex()
Returns the index of the selected button, or -1 if none is selected.
-
getSelectedItem
public java.lang.String getSelectedItem()
Returns the caption of the selected button, ornullif no button is selected- Since:
- SuperWaba 4.01
-
setCursorColor
public void setCursorColor(int color)
Sets the cursor color for this PushButtonGroup. The default is equal to the background slightly darker.
-
getPreferredWidth
public int getPreferredWidth()
Description copied from class:ControlReturns the preferred width of this control.- Overrides:
getPreferredWidthin classControl
-
getPreferredHeight
public int getPreferredHeight()
Description copied from class:ControlReturns the preferred height of this control.- Overrides:
getPreferredHeightin classControl
-
onFontChanged
protected void onFontChanged()
Description copied from class:ControlCalled after a setFont- Overrides:
onFontChangedin classControl
-
onColorsChanged
protected void onColorsChanged(boolean colorsChanged)
Description copied from class:ControlCalled 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:
onColorsChangedin classControl
-
onBoundsChanged
protected void onBoundsChanged(boolean screenChanged)
Description copied from class:ControlCalled after a setRect.- Overrides:
onBoundsChangedin classControl- Parameters:
screenChanged- If the bounds were changed due to a screen change (rotation, collapse)
-
onPaint
public void onPaint(Graphics g)
Description copied from class:ControlCalled to draw the control. When this method is called, the graphics object passed has been translated into the coordinate system of the control and the area behind the control has already been painted.
-
getEffectW
public int getEffectW()
- Overrides:
getEffectWin classControl
-
getEffectH
public int getEffectH()
- Overrides:
getEffectHin classControl
-
getEffectX
public int getEffectX()
- Overrides:
getEffectXin classControl
-
getEffectY
public int getEffectY()
- Overrides:
getEffectYin classControl
-
setSelectedIndex
public void setSelectedIndex(int ind)
Sets the selected button index. Note. if there are any null or hidden buttons, you must consider them too to compute the correct index.
-
onEvent
public void onEvent(Event event)
Description copied from class:ControlCalled to process key, pen, control and other posted events.
-
getHighlightSelected
public boolean getHighlightSelected()
-
setHighlightSelected
public void setHighlightSelected(boolean highlightSelected)
-
getHighlightColor
public int getHighlightColor()
-
setHighlightColor
public void setHighlightColor(int highlightColor)
-
getHighlightEmptyValues
public boolean getHighlightEmptyValues()
-
setHighlightEmptyValues
public void setHighlightEmptyValues(boolean highlightEmptyValues)
-
clear
public void clear()
Clears this control, selecting index clearValueInt. Note that if atLeastOne is true, setting clearValueInt to -1 will have no effect.
-
handleGeographicalFocusChangeKeys
public Control handleGeographicalFocusChangeKeys(KeyEvent ke)
Description copied from class:ControlUsed by the main event loop to give the currently focused control an opportunity to act directly on the KeyEvent.- Overrides:
handleGeographicalFocusChangeKeysin classControl- Parameters:
ke- The KeyEvent to be processed- Returns:
- The control that should get focus as a result of this KeyEvent. Null if this control did not handle the KeyEvent.
- See Also:
Settings.geographicalFocus
-
-