Package totalcross.ui

Class 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.

    • 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 final 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 the hidden property to dynamically show/hide buttons.
        atLeastOne - if true, at least one button must be selected
        selected - default index to appear selected, or -1 if none
        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
        allSameWidth - 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 the hidden property 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 the hidden property 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, or null if 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: 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
      • onFontChanged

        protected void onFontChanged()
        Description copied from class: Control
        Called after a setFont
        Overrides:
        onFontChanged in class Control
      • 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
      • onBoundsChanged

        protected void onBoundsChanged​(boolean screenChanged)
        Description copied from class: Control
        Called after a setRect.
        Overrides:
        onBoundsChanged in class Control
        Parameters:
        screenChanged - If the bounds were changed due to a screen change (rotation, collapse)
      • onPaint

        public void onPaint​(Graphics g)
        Description copied from class: Control
        Called 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.
        Overrides:
        onPaint in class Control
        Parameters:
        g - the graphics object for drawing
        See Also:
        Graphics
      • 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: Control
        Called to process key, pen, control and other posted events.
        Overrides:
        onEvent in class Control
        Parameters:
        event - the event to process
        See Also:
        Event, KeyEvent, PenEvent
      • 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.
        Overrides:
        clear in class Control
      • handleGeographicalFocusChangeKeys

        public Control handleGeographicalFocusChangeKeys​(KeyEvent ke)
        Description copied from class: Control
        Used by the main event loop to give the currently focused control an opportunity to act directly on the KeyEvent.
        Overrides:
        handleGeographicalFocusChangeKeys in class Control
        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