Package totalcross.ui

Class Control

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  Control.TranslucentShape
      Used when this Control is translucent
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int AFTER
      Constant used in param x/y in setRect.
      int alphaValue
      Alpha to be used in some controls, ranging from 0 to 255.
      int appId
      Application defined constant.
      java.lang.Object appObj
      Application defined object.
      protected Container asContainer
      READ-ONLY property which is not null if this control is a container
      protected Window asWindow
      READ-ONLY property which is not null if this control is a window
      protected int backColor
      Background color of this control.
      static int BEFORE
      Constant used in param x/y in setRect.
      static int BOTTOM
      Constant used in param y in setRect.
      static int BOTTOM_OF
      Constant used in param x/y in setRect.
      static int BRIGHTER_BACKGROUND
      To be used in the setTextShadowColor method.
      boolean callListenersOnAllTargets
      True means that EventListeners for PenEvent and KeyEvent will be called without verifying that the event target is this.
      static int CENTER
      Constant used in params x and y in setRect.
      static int CENTER_OF
      Constant used in param x/y in setRect.
      int clearValueInt
      Default value when calling clear.
      java.lang.String clearValueStr
      Default value when calling clear.
      static int DARKER_BACKGROUND
      To be used in the setTextShadowColor method.
      UIEffects effect
      The current effect used in this control
      static boolean enableUpdateScreen
      Set to false to disallow the screen update.
      protected EnabledStateChangeEvent esce  
      boolean eventsEnabled  
      static int FILL
      Constant used in params width and height in setRect.
      int fillColor
      Color to fill the background in Material UI when its enabled.
      static int FIT
      Constant used in params width and height in setRect.
      FontMetrics fm
      The fontMetrics corresponding to the controls font.
      protected int fmH
      Stores the height of the current font.
      protected boolean focusHandler
      Stores the control that should handle the focus change key for this control
      protected boolean focusLess
      If true, this control will receive pen and key events but will never gain focus.
      boolean focusOnPenDown
      True means this control expects to get focus on a PEN_DOWN event.
      boolean focusTraversable
      Defines if this control can receive focus by using the arrow keys.
      protected Font font
      The font used by the control.
      static int FONTSIZE
      Constant used in param width (will use parent's width) and height (will use the current font size/height) in setRect.
      protected int foreColor
      Foreground color of this control.
      protected int height
      The control's height
      boolean ignoreInsets
      Set to true to ignore parent's insets when placing this control on screen.
      protected static boolean isHighlighting
      If true, the keyboard arrows will be used to highlight the controls until one is selected.
      static boolean isTablet
      Specifies if this device is a tablet, computing the number of text lines.
      static int KEEP
      Constant used in params x/y/width/height in setRect.
      boolean keepDisabled
      Keep the control disabled even if enabled is true.
      boolean keepEnabled
      Keep the control enabled even if enabled is false.
      static int LEFT
      Constant used in param x in setRect.
      Control nextTabControl
      The next control that will receive focus when tab is hit.
      Image offscreen
      The offscreen image taken with takeScreenShot.
      Image offscreen0
      The offscreen image taken with takeScreenShot.
      boolean onEventFirst
      Set to true to call onEvent before calling the event listeners.
      protected Container parent
      The parent of the control.
      static int PARENTSIZE
      Constant used in param width (will use parent's width) and height (will use parent's height) in setRect.
      static int PARENTSIZEMAX
      Constant used in param width or height (will use parent's maximum size between width and height) in setRect.
      static int PARENTSIZEMIN
      Constant used in param width or height (will use parent's minimum size between width and height) in setRect.
      static int PREFERRED
      Constant used in params width and height in setRect.
      static int RANGE  
      protected boolean repositionAllowed  
      static int RIGHT
      Constant used in param x in setRect.
      static int RIGHT_OF
      Constant used in param x/y in setRect.
      static int SAME
      Constant used in params x/y/width/height in setRect.
      static int SCREENSIZE
      Constant used in param width (will use screen's width) and height (will use screen's height) in setRect.
      static int SCREENSIZEMAX
      Constant used in param width or height (will use screen's maximum size between width and height) in setRect.
      static int SCREENSIZEMIN
      Constant used in param width or height (will use screen's minimum size between width and height) in setRect.
      protected Font setFont  
      protected int setH  
      protected Control setRel  
      protected int setW  
      protected int setX  
      protected int setY  
      protected int tempW  
      int textShadowColor
      The shadow color to be applied to this control.
      static int TOP
      Constant used in param y in setRect.
      protected Control.TranslucentShape translucentShape  
      boolean transparentBackground
      Set the background to be transparent, by not filling the control's area with the background color.
      boolean uiAdjustmentsBasedOnFontHeightIsSupported
      Allows to disable the ui adjustments based on font height for a single control.
      protected static boolean uiAndroid
      Shortcuts to test the UI style.
      static int UICONST  
      protected static boolean uiFlat
      Shortcuts to test the UI style.
      protected static boolean uiHolo
      Shortcuts to test the UI style.
      protected static boolean uiMaterial
      Shortcuts to test the UI style.
      protected static boolean uiVista
      Shortcuts to test the UI style.
      protected boolean visible
      True if the control is visible, false otherwise
      protected int width
      The control's width
      static int WILL_RESIZE
      Constant used in params width/height in setRect.
      protected int x
      The control's x location
      protected int y
      The control's y location
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected Control()
      creates the font for this control as the same font of the MainWindow.
    • Field Detail

      • x

        protected int x
        The control's x location
      • y

        protected int y
        The control's y location
      • width

        protected int width
        The control's width
      • height

        protected int height
        The control's height
      • parent

        protected Container parent
        The parent of the control.
      • font

        protected Font font
        The font used by the control.
      • fm

        public FontMetrics fm
        The fontMetrics corresponding to the controls font.
      • visible

        protected boolean visible
        True if the control is visible, false otherwise
      • foreColor

        protected int foreColor
        Foreground color of this control. When the control is added, its foreground is set to be the same of the parent's.
      • backColor

        protected int backColor
        Background color of this control. When the control is added, its background is set to be the same of the parent's.
      • appId

        public int appId
        Application defined constant. This constant is not used; its only a placeholder for the application so it can set to any value it wants
      • appObj

        public java.lang.Object appObj
        Application defined object. This field is not used; its only a placeholder for the application so it can set to any value it wants
      • clearValueStr

        public java.lang.String clearValueStr
        Default value when calling clear. When the control will use a numeric value or a String, depends on the type of control. Defaults to an empty string.
      • clearValueInt

        public int clearValueInt
        Default value when calling clear. When the control will use a numeric value or a String, depends on the type of control. Defaults to zero.
      • nextTabControl

        public Control nextTabControl
        The next control that will receive focus when tab is hit.
      • PREFERRED

        public static final int PREFERRED
        Constant used in params width and height in setRect. You can use this constant added to a number to specify a increment/decrement to the calculated size. EG: PREFERRED+2 or PREFERRED-1.
        See Also:
        Constant Field Values
      • LEFT

        public static final int LEFT
        Constant used in param x in setRect. You can use this constant added to a number to specify a increment/decrement to the calculated size. EG: LEFT+2 or LEFT-1.
        See Also:
        Constant Field Values
      • CENTER

        public static final int CENTER
        Constant used in params x and y in setRect. You can use this constant added to a number to specify a increment/decrement to the calculated size. EG: CENTER+2 or CENTER-1.
        See Also:
        Constant Field Values
      • RIGHT

        public static final int RIGHT
        Constant used in param x in setRect. You can use this constant added to a number to specify a increment/decrement to the calculated size. EG: RIGHT+2 or RIGHT-1.
        See Also:
        Constant Field Values
      • TOP

        public static final int TOP
        Constant used in param y in setRect. You can use this constant added to a number to specify a increment/decrement to the calculated size. EG: TOP+2 or TOP-1.
        See Also:
        Constant Field Values
      • BOTTOM

        public static final int BOTTOM
        Constant used in param y in setRect. You can use this constant added to a number to specify a increment/decrement to the calculated size. EG: BOTTOM+2 or BOTTOM-1.
        See Also:
        Constant Field Values
      • FILL

        public static final int FILL
        Constant used in params width and height in setRect. You can use this constant added to a number to specify a increment/decrement to the calculated size. EG: FILL+2 or FILL-1. Note that FILL cannot be used with other x/y positioning constants.
        See Also:
        Constant Field Values
      • BEFORE

        public static final int BEFORE
        Constant used in param x/y in setRect. You can use this constant added to a number to specify a increment/decrement to the calculated size. EG: BEFORE+2 or BEFORE-1.
        See Also:
        Constant Field Values
      • SAME

        public static final int SAME
        Constant used in params x/y/width/height in setRect. You can use this constant added to a number to specify a increment/decrement to the calculated size. EG: SAME+2 or SAME-1.
        See Also:
        Constant Field Values
      • AFTER

        public static final int AFTER
        Constant used in param x/y in setRect. You can use this constant added to a number to specify a increment/decrement to the calculated size. EG: AFTER+2 or AFTER-1.
        See Also:
        Constant Field Values
      • FIT

        public static final int FIT
        Constant used in params width and height in setRect. You can use this constant added to a number to specify a increment/decrement to the calculated size. EG: FIT+2 or FIT-1. Note that FIT cannot be used with other x/y positioning constants. FIT will make the control fit between the desired position and the last added control position.
        See Also:
        Constant Field Values
      • CENTER_OF

        public static final int CENTER_OF
        Constant used in param x/y in setRect. You can use this constant added to a number to specify a increment/decrement to the calculated size. EG: CENTER_OF+2 or CENTER_OF-1. CENTER_OF is related to a control, while CENTER is related to the screen. CENTER_OF cannot be used with FILL/FIT in the widths.
        See Also:
        Constant Field Values
      • RIGHT_OF

        public static final int RIGHT_OF
        Constant used in param x/y in setRect. You can use this constant added to a number to specify a increment/decrement to the calculated size. EG: RIGHT_OF+2 or RIGHT_OF-1. RIGHT_OF is related to a control, while RIGHT is related to the screen. RIGHT_OF cannot be used with FILL/FIT in the widths.
        See Also:
        Constant Field Values
      • BOTTOM_OF

        public static final int BOTTOM_OF
        Constant used in param x/y in setRect. You can use this constant added to a number to specify a increment/decrement to the calculated size. EG: BOTTOM_OF+2 or BOTTOM_OF-1. BOTTOM_OF is related to a control, while BOTTOM is related to the screen. BOTTOM_OF cannot be used with FILL/FIT in the widths.
        See Also:
        Constant Field Values
      • SCREENSIZE

        public static final int SCREENSIZE
        Constant used in param width (will use screen's width) and height (will use screen's height) in setRect. You can use this constant added or subtracted to a number to specify a increment to the calculated size. There are two ways to use it:
        1. SCREENSIZE + constant: it will use as a PERCENTAGE of the screen's size. For example, SCREENSIZE+20 in width will result in 20% of screen's size.
        2. SCREENSIZE - constant: it will use as a FRACTION of the screen's size. For example, SCREENSIZE-4 in width will result in 1/4 of screen's size.
        If there are no constant number, size will be 100% of the screen's width/height.
        Since:
        TotalCross 1.3
        See Also:
        Constant Field Values
      • KEEP

        public static final int KEEP
        Constant used in params x/y/width/height in setRect. It keeps the current value. Note that it does NOT support increment nor decrement. KEEP differs from SAME in the manner that KEEP applies to the coordinates of this control, while SAME applies to the coordinates of another control.
        Since:
        TotalCross 1.14
        See Also:
        Constant Field Values
      • PARENTSIZE

        public static final int PARENTSIZE
        Constant used in param width (will use parent's width) and height (will use parent's height) in setRect. It can also be used in X or Y, representing the position where to draw it. You can use this constant added or subtracted to a number to specify a increment to the calculated size. There are two ways to use it:
        1. PARENTSIZE + constant: it will use as a PERCENTAGE of the parent's size. For example, PARENTSIZE+20 in width will result in 20% of parent's size.
        2. PARENTSIZE - constant: it will use as a FRACTION of the parent's size. For example, PARENTSIZE-4 in width will result in 1/4 of parent's size.
        If there are no constant number, size will be 100% of the parent's width/height. If the parent is unknown, the screen size will be used instead.
        Since:
        TotalCross 1.52
        See Also:
        Constant Field Values
      • SCREENSIZEMIN

        public static final int SCREENSIZEMIN
        Constant used in param width or height (will use screen's minimum size between width and height) in setRect. You can use this constant added or subtracted to a number to specify a increment to the calculated size. There are two ways to use it:
        1. SCREENSIZEMIN + constant: it will use as a PERCENTAGE of the screen's size. For example, SCREENSIZEMIN+20 in width will result in 20% of screen's minimum size.
        2. SCREENSIZEMIN - constant: it will use as a FRACTION of the screen's size. For example, SCREENSIZEMIN-4 in width will result in 1/4 of screen's minimum size.
        If there are no constant number, size will be 100% of the screen's width/height.
        Since:
        TotalCross 2.0
        See Also:
        Constant Field Values
      • SCREENSIZEMAX

        public static final int SCREENSIZEMAX
        Constant used in param width or height (will use screen's maximum size between width and height) in setRect. You can use this constant added or subtracted to a number to specify a increment to the calculated size. There are two ways to use it:
        1. SCREENSIZEMAX + constant: it will use as a PERCENTAGE of the screen's size. For example, SCREENSIZEMAX+20 in width will result in 20% of screen's maximum size.
        2. SCREENSIZEMAX - constant: it will use as a FRACTION of the screen's size. For example, SCREENSIZEMAX-4 in width will result in 1/4 of screen's maximum size.
        If there are no constant number, size will be 100% of the screen's width/height.
        Since:
        TotalCross 2.0
        See Also:
        Constant Field Values
      • PARENTSIZEMIN

        public static final int PARENTSIZEMIN
        Constant used in param width or height (will use parent's minimum size between width and height) in setRect. You can use this constant added or subtracted to a number to specify a increment to the calculated size. There are two ways to use it:
        1. PARENTSIZEMIN + constant: it will use as a PERCENTAGE of the parent's size. For example, PARENTSIZEMIN+20 in width will result in 20% of parent's size.
        2. PARENTSIZEMIN - constant: it will use as a FRACTION of the parent's size. For example, PARENTSIZEMIN-4 in width will result in 1/4 of parent's size.
        If there are no constant number, size will be 100% of the parent's width/height. If the parent is unknown, the screen size will be used instead.
        Since:
        TotalCross 2.0
        See Also:
        Constant Field Values
      • PARENTSIZEMAX

        public static final int PARENTSIZEMAX
        Constant used in param width or height (will use parent's maximum size between width and height) in setRect. You can use this constant added or subtracted to a number to specify a increment to the calculated size. There are two ways to use it:
        1. PARENTSIZEMAX + constant: it will use as a PERCENTAGE of the parent's size. For example, PARENTSIZEMAX+20 in width will result in 20% of parent's size.
        2. PARENTSIZEMAX - constant: it will use as a FRACTION of the parent's size. For example, PARENTSIZEMAX-4 in width will result in 1/4 of parent's size.
        If there are no constant number, size will be 100% of the parent's width/height. If the parent is unknown, the screen size will be used instead.
        Since:
        TotalCross 2.0
        See Also:
        Constant Field Values
      • FONTSIZE

        public static final int FONTSIZE
        Constant used in param width (will use parent's width) and height (will use the current font size/height) in setRect. You can use this constant added or subtracted to a number to specify a increment to the calculated size. There are two ways to use it:
        1. FONTSIZE + constant: it will use as a PERCENTAGE of the parent's size. For example, FONTSIZE+20 in width will result in 20% of font's size.
        2. FONTSIZE - constant: it will use as a FRACTION of the parent's size. For example, FONTSIZE-4 in width will result in 1/4 of font's size.
        If there are no constant number, size will be 100% of the font's width/height. So, FONTSIZE and FONTSIZE+100 is the same.
        Since:
        TotalCross 1.52
        See Also:
        Constant Field Values
      • WILL_RESIZE

        public static final int WILL_RESIZE
        Constant used in params width/height in setRect. It informs that the parent's last width/height should not be updated now, because it will be resized later. Note that it does NOT support increment nor decrement. Sample:
         Container c;
         add(c = new Container(), LEFT+5, AFTER+5, FILL-5, WILL_RESIZE);
         // add controls to c
         c.resizeHeight();
         
        Since:
        TotalCross 1.14
        See Also:
        Constant Field Values
      • ignoreInsets

        public boolean ignoreInsets
        Set to true to ignore parent's insets when placing this control on screen.
      • uiAdjustmentsBasedOnFontHeightIsSupported

        public boolean uiAdjustmentsBasedOnFontHeightIsSupported
        Allows to disable the ui adjustments based on font height for a single control. Set this flag in the constructor. It is propagated to all child controls.
        Since:
        TotalCross 1.3
      • enableUpdateScreen

        public static boolean enableUpdateScreen
        Set to false to disallow the screen update.
      • fmH

        protected int fmH
        Stores the height of the current font. The same of fm.height.
      • focusHandler

        protected boolean focusHandler
        Stores the control that should handle the focus change key for this control
      • isHighlighting

        protected static boolean isHighlighting
        If true, the keyboard arrows will be used to highlight the controls until one is selected. This will cause the KeyEvent to be intercepted and handled by the method changeHighlighted. When the user press the ACTION (or ENTER) key to use the control, this flag is set to false and the focus will be set to the control, so it be able to use the arrows to navigate inside it. The control must then set this to true when the finish using it or press the ACTION button again (which then sets the flag to true).
        Since:
        SuperWaba 5.5
      • focusTraversable

        public boolean focusTraversable
        Defines if this control can receive focus by using the arrow keys.
        Since:
        SuperWaba 5.5
      • uiFlat

        protected static boolean uiFlat
        Shortcuts to test the UI style. Use the setUIStyle method to change them accordingly.
      • uiVista

        protected static boolean uiVista
        Shortcuts to test the UI style. Use the setUIStyle method to change them accordingly.
      • uiAndroid

        protected static boolean uiAndroid
        Shortcuts to test the UI style. Use the setUIStyle method to change them accordingly.
      • uiHolo

        protected static boolean uiHolo
        Shortcuts to test the UI style. Use the setUIStyle method to change them accordingly.
      • uiMaterial

        protected static boolean uiMaterial
        Shortcuts to test the UI style. Use the setUIStyle method to change them accordingly.
      • focusLess

        protected boolean focusLess
        If true, this control will receive pen and key events but will never gain focus. This is useful to create keypads. See totalcross.ui.Calculator.
      • eventsEnabled

        public boolean eventsEnabled
      • fillColor

        public int fillColor
        Color to fill the background in Material UI when its enabled.
      • isTablet

        public static boolean isTablet
        Specifies if this device is a tablet, computing the number of text lines.
      • setX

        protected int setX
      • setY

        protected int setY
      • setW

        protected int setW
      • setH

        protected int setH
      • setFont

        protected Font setFont
      • repositionAllowed

        protected boolean repositionAllowed
      • tempW

        protected int tempW
      • textShadowColor

        public int textShadowColor
        The shadow color to be applied to this control.
      • onEventFirst

        public boolean onEventFirst
        Set to true to call onEvent before calling the event listeners. By default, the event listener is called before the onEvent.
      • asContainer

        protected Container asContainer
        READ-ONLY property which is not null if this control is a container
      • asWindow

        protected Window asWindow
        READ-ONLY property which is not null if this control is a window
      • BRIGHTER_BACKGROUND

        public static final int BRIGHTER_BACKGROUND
        To be used in the setTextShadowColor method.
        See Also:
        Constant Field Values
      • DARKER_BACKGROUND

        public static final int DARKER_BACKGROUND
        To be used in the setTextShadowColor method.
        See Also:
        Constant Field Values
      • alphaValue

        public int alphaValue
        Alpha to be used in some controls, ranging from 0 to 255.
      • transparentBackground

        public boolean transparentBackground
        Set the background to be transparent, by not filling the control's area with the background color.
        Since:
        TotalCross 1.0
      • focusOnPenDown

        public boolean focusOnPenDown
        True means this control expects to get focus on a PEN_DOWN event. If focusOnPenDown is false, focus will be set on PEN_UP instead. This can be used for things like drag-scrollable list controls that contain controls as list items, to avoid setting focus to an item (and therefore changing the selection) during a drag-scroll.
      • callListenersOnAllTargets

        public boolean callListenersOnAllTargets
        True means that EventListeners for PenEvent and KeyEvent will be called without verifying that the event target is this.
      • offscreen

        public Image offscreen
        The offscreen image taken with takeScreenShot. The onPaint will use this shot until the user calls releaseScreenShot.
      • offscreen0

        public Image offscreen0
        The offscreen image taken with takeScreenShot. The onPaint will use this shot until the user calls releaseScreenShot.
      • keepDisabled

        public boolean keepDisabled
        Keep the control disabled even if enabled is true.
      • keepEnabled

        public boolean keepEnabled
        Keep the control enabled even if enabled is false.
      • effect

        public UIEffects effect
        The current effect used in this control
    • Constructor Detail

      • Control

        protected Control()
        creates the font for this control as the same font of the MainWindow.
    • Method Detail

      • takeInitialScreenShot

        public void takeInitialScreenShot()
        Take a screen shot of this container and stores it in offscreen0.
      • takeScreenShot

        public void takeScreenShot()
        Take a screen shot of this container and stores it in offscreen.
      • releaseScreenShot

        public void releaseScreenShot()
        Releases the screen shot.
      • setTextShadowColor

        public void setTextShadowColor​(int color)
        Call to set the color value to place a shadow around the control's text. The shadow is made drawing the button in (x-1,y-1), (x+1,y-1), (x-1,y+1), (x+1,y+1) positions. Defaults to -1, which means no shadow. You can set pass BRIGHTER_BACKGROUND or DARKER_BACKGROUND as parameter, AFTER calling setBackColor or setForeColor, to compute the color based on the background.

        Example:
         c = new Label(....);
         c.setBackColor(Color.BLUE);
         c.setTextShadowColor(DARKER_BACKGROUND);
         // you may also set it directly to a color: c.setTextShadowColor(Color.BLACK);
         
        Since:
        TotalCross 1.27
        See Also:
        BRIGHTER_BACKGROUND, DARKER_BACKGROUND, UIColors.textShadowColor
      • getTextShadowColor

        public int getTextShadowColor()
        Returns the textShadowColor of this control.
        Since:
        TotalCross 1.27
      • isInsideOrNear

        public boolean isInsideOrNear​(int x,
                                      int y)
        Returns true if the point lies inside this control. If it don't lies, but the device is a finger touch one, checks if the distance is below the touch tolerance.
        Since:
        TotalCross 1.2
        See Also:
        Settings.touchTolerance, Settings.fingerTouch
      • showTip

        public void showTip​(java.lang.String s,
                            int duration,
                            int y)
        Shows a message using a global tip shared by all controls.
      • postPressedEvent

        public void postPressedEvent()
        Posts a ControlEvent.PRESSED event with this control as target.
        Since:
        TotalCross 1.14
      • getPressedEvent

        protected ControlEvent getPressedEvent​(Control target)
        Creates a ControlEvent.PRESSED if not yet created and returns it.
        Since:
        TotalCross 1.14
      • addTimer

        public TimerEvent addTimer​(int millis)
        Adds a timer to a control. Each time the timer ticks, a TIMER event will be posted to the control. The timer does not interrupt the program during its execution at the timer interval, it is scheduled along with application events. The timer object returned from this method can be passed to removeTimer() to remove the timer. Under Windows, the timer has a minimum resolution of 55ms due to the native Windows system clock resolution of 55ms. Under Palm OS and other platforms, the minimum timer resolution is 10ms.

        If the control that holds the timer is removed from screen, the timer is also disabled. Consider using the dispatch-listener event model (addTimerListener) instead of creating a control just to catch the event (if this is the case).

        Parameters:
        millis - the timer tick interval in milliseconds
        See Also:
        TimerEvent
      • addTimer

        public void addTimer​(TimerEvent t,
                             int millis)
        Add a timer to a control. This method allows you to create an instance TimerEvent (or any descendant) ahead of time and add it to the control.
        Parameters:
        t - the TimerEvent instance
        millis - the timer tick interval in milliseconds
        See Also:
        TimerEvent
      • removeTimer

        public boolean removeTimer​(TimerEvent timer)
        Removes a timer from a control. True is returned if the timer was found and removed and false is returned if the timer could not be found (meaning it was not active).
      • setFont

        public void setFont​(Font font)
        Sets the font of this control.
      • getFont

        public Font getFont()
        Gets the font of this control.
      • getPreferredWidth

        public int getPreferredWidth()
        Returns the preferred width of this control.
      • getPreferredHeight

        public int getPreferredHeight()
        Returns the preferred height of this control.
      • setRect

        public void setRect​(int x,
                            int y,
                            int width,
                            int height,
                            Control relative,
                            boolean screenChanged)
        The relative positioning will be made with the given control (relative). Note that in this case, only the SAME,BEFORE,AFTER are affected by the given control. Here is an example of relative positioning:

        Important note: you can't use FILL/FIT with BEFORE/RIGHT/BOTTOM (for x,y).

         add(new Label("1"),CENTER,CENTER);
         add(new Label("2"),AFTER,SAME);
         add(new Label("3"),SAME,AFTER);
         add(new Label("4"),BEFORE,SAME);
         add(new Label("5"),BEFORE,BEFORE);
         
        You will see this on screen:
         512
          43
         
        Note: add(control, x,y) does: add(control); control.setRect(x,y,PREFERRED,PREFERRED);

        Important! Always add the control to the container before doing a setRect.

        The relative positioning does not work well if the control is placed outside screen bounds.

        Parameters:
        x - One of the relative positioning constants: LEFT, RIGHT, SAME, BEFORE, AFTER, CENTER, with a small adjustment. You can also use an absolute value, but this is strongly discouraged.
        y - One of the relative positioning constants: TOP, BOTTOM, SAME, BEFORE, AFTER, CENTER, with a small adjustment. You can also use an absolute value, but this is strongly discouraged.
        width - One of the relative positioning constants: PREFERRED, FILL, FIT, SAME. You can also use an absolute value, but this is strongly discouraged.
        height - One of the relative positioning constants: PREFERRED, FILL, FIT, SAME. You can also use an absolute value, but this is strongly discouraged.
        relative - To whom the position should be relative to; or null to be relative to the last control.
        screenChanged - Indicates that a screen change (resize, collapse) occured and the reposition method is calling this method. Set by the system. If you call this method directly, always pass false to it.
        See Also:
        LEFT, TOP, RIGHT, BOTTOM, BEFORE, AFTER, CENTER, SAME, FILL, PREFERRED, FIT, CENTER_OF, RIGHT_OF, BOTTOM_OF, SCREENSIZE, SCREENSIZEMIN, SCREENSIZEMAX, PARENTSIZE, PARENTSIZEMIN, PARENTSIZEMAX, FONTSIZE, Container.add(Control, int, int), Container.add(Control, int, int, Control)
      • resetSetPositions

        public void resetSetPositions()
        Resets the original points that are set by the first setRect, so if you call setRect again, the old positions are replaced by the new ones. The set positions are used when a rotation occurs.
        Since:
        TotalCross 1.25
      • setSet

        public void setSet​(int x,
                           int y)
        Used internally.
      • updateTemporary

        protected void updateTemporary()
      • getSize

        public Coord getSize()
        Returns the current size (width,height) of this control
      • getPos

        public Coord getPos()
        Returns the current position (x,y) of this control
      • setVisible

        public void setVisible​(boolean visible)
        Shows or "hides" this control. Note that it remains attached to its container. Calls repaint.
      • isVisible

        public boolean isVisible()
        Returns true if this control is visible, false otherwise
      • getRect

        public Rect getRect()
        Returns a copy of the control's rectangle, relative to its parent. A control's rectangle defines its location and size.
      • getAbsoluteRect

        public Rect getAbsoluteRect()
        Returns the absolute coordinates of this control relative to the MainWindow.
      • getParentWindow

        public Window getParentWindow()
        Returns the control's parent Window or null if there's no parent (eg: the control still not added to any container). If this control is a window, will return itself.
      • getParent

        public Container getParent()
        Returns the control's parent container.
      • getNext

        public Control getNext()
        Returns the next child in the parent's list of controls.
      • getPrev

        public Control getPrev()
        Returns the previous child in the parent's list of controls.
      • contains

        public boolean contains​(int x,
                                int y)
        Returns true if the given x and y coordinate in the parent's coordinate system is contained within this control.
      • repaint

        public static void repaint()
        Marks all controls in the screen for repaint. Important note: when you call repaint, a flag is set indicating that the screen must be repainted; then, the next time a event (a keypress, a timer, a pen event) occurs, the screen is updated. If you call repaint and the control isn't effectively repainted, you can use the Control.repaintNow method.

        If you want to avoid a method call, you can do
         Window.needsPaint = true;
         
        See Also:
        repaintNow()
      • repaintNow

        public void repaintNow()
        Redraws the control immediately. If this control is a Window, the whole window area is marked for repaint (useful if you're removing some controls from a container). This method affects only this control, while the repaint method affects the whole screen. If Window.enableUpdateScreen is true, the method returns immediately.
        Since:
        SuperWaba 2.0 beta 4 release 3
        See Also:
        repaint()
      • translateFromOrigin

        public void translateFromOrigin​(Coord z)
        Sets the given Point to the absolute coordinate relative to the origin Window.
        Since:
        SuperWaba 5.5
      • getGraphics

        public Graphics getGraphics()
        Returns a Graphics object which can be used to draw in the control. This method updates the single Graphics object with the current control font and bounds. It sets a clipping rectangle on the graphics, clipping it against all parent areas.
      • postEvent

        public void postEvent​(Event event)
        Posts an event. The event pass will be posted to this control and all the parent controls of this control (all the containers this control is within).
        See Also:
        Event
      • setEnabled

        public void setEnabled​(boolean enabled)
        Sets if this control can or not accept events. It changes the appearance of many controls to indicate they are disabled.
      • internalSetEnabled

        public boolean internalSetEnabled​(boolean enabled,
                                          boolean post)
        For internal use only. Used by derived controls to set the enabled flag.
      • post

        public void post()
        Posts the enable state change event.
      • isEnabled

        public boolean isEnabled()
        Returns if this control can or not accept events
      • onEvent

        public void onEvent​(Event event)
        Called to process key, pen, control and other posted events.
        Parameters:
        event - the event to process
        See Also:
        Event, KeyEvent, PenEvent
      • onPaint

        public void onPaint​(Graphics g)
        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.
        Parameters:
        g - the graphics object for drawing
        See Also:
        Graphics
      • onBoundsChanged

        protected void onBoundsChanged​(boolean screenChanged)
        Called after a setRect.
        Parameters:
        screenChanged - If the bounds were changed due to a screen change (rotation, collapse)
      • onColorsChanged

        protected void onColorsChanged​(boolean colorsChanged)
        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
      • onWindowPaintFinished

        protected void onWindowPaintFinished()
        Called after the window has finished a paint. Only called to the focused control and the parent's window.
      • onFontChanged

        protected void onFontChanged()
        Called after a setFont
      • setBackForeColors

        public void setBackForeColors​(int back,
                                      int fore)
        Set the background and foreground colors at once. Calling this method is faster than calling setBackColor and setForeColor separately.
      • setForeColor

        public void setForeColor​(int c)
        Set the foreground color of this control.
        Since:
        SuperWaba 2.0
      • setBackColor

        public void setBackColor​(int c)
        Set the background color of this control.
        Since:
        SuperWaba 2.0
      • getForeColor

        public int getForeColor()
        Get the desired foreground color of this control.
        Since:
        SuperWaba 2.0
      • getBackColor

        public int getBackColor()
        Get the desired background color of this control.
        Since:
        SuperWaba 2.0
      • isDisplayed

        public boolean isDisplayed()
        Return true if the parent of this Control is added to somewhere. Some containers, like the TabPanel, has n child containers, but only one is added at a time. With this method, you can discover if your container is the one being shown.
      • requestFocus

        public void requestFocus()
        Sets the focus to this control. Note that in penless devices its also needed to set isHighlighting = false.
      • setFocusLess

        public void setFocusLess​(boolean on)
        Sets this control to be focusless. If this control is a container, sets all its children to be focusless too. A focusless control can receive and dispatch events, but cannot receive focus. Here's an example of how to use it to create a keypad:
                 // class fields
                 private PushButtonGroup numericPad;
                 private KeyEvent ke = new KeyEvent();
          
                 // in the initUI method:
                 String []numerics = {"1","2","3","4","5","6","7","8","9","0",".","-"};
                 add(numericPad=new PushButtonGroup(numerics, false, -1, -1, 6, 4, true,
                                                     PushButtonGroup.BUTTON), RIGHT-2, TOP+2);
                 numericPad.setFocusLess(true);
          
                 // in the onEvent method
                 Control focus;
                 if (e.target == numericPad && (focus=getParentWindow().getFocus()) instanceof Edit)
                 {
                    String s = numericPad.getSelectedCaption();
                    if (s != null)
                    {
                       ke.key = s.charAt(0);
                       ke.target = focus;
                       focus.onEvent(ke);
                    }
                 }
         
      • uiStyleChanged

        public static void uiStyleChanged()
        Internal use only
      • changeHighlighted

        public void changeHighlighted​(Container p,
                                      boolean forward)
        Transfers the focus to the next or previous control.
        Since:
        SuperWaba 5.5
      • clear

        public void clear()
        Placeholder for the clear method. The class that inherits control is responsible for cleaning it up.
      • updateScreen

        public static void updateScreen()
        This method causes the immediate screen update. The screen is saved in a buffer and, when this method is called, the buffer is transfered to the screen, using the nextTransitionEffect set. NOTE: for a thread-safe version, use safeUpdateScreen
        Since:
        SuperWaba 5.0
        See Also:
        safeUpdateScreen(), Container.nextTransitionEffect
      • safeUpdateScreen

        public static void safeUpdateScreen()
        This method causes the screen's update. If called at the main thread, the screen is updated immediatly. If not, the updated is schedulled to occur as soon as possible.
        Since:
        TotalCross 3.1
        See Also:
        updateScreen()
      • getWidth

        public int getWidth()
        Returns the control's width.
        Specified by:
        getWidth in class GfxSurface
      • getHeight

        public int getHeight()
        Returns the control's height.
        Specified by:
        getHeight in class GfxSurface
      • getX

        public int getX()
        Returns the control's x position.
        Specified by:
        getX in class GfxSurface
      • getY

        public int getY()
        Returns the control's y position.
        Specified by:
        getY in class GfxSurface
      • getX2

        public int getX2()
        Returns x+width-1
        Since:
        TotalCross 1.14
      • getY2

        public int getY2()
        Returns y+height-1
        Since:
        TotalCross 1.14
      • reposition

        protected void reposition​(boolean recursive)
        Repositions this control, and dives into other controls if this is a container and recursive is true.
      • repositionChildren

        protected void repositionChildren()
        Repositions the children controls. This is usually called from reposition, but you can call by yourself if you are changing this control's position and size by yourself (for example during rotaton)
      • reposition

        public void reposition()
        Reposition this control, calling again setRect with the original parameters.
      • _onEvent

        public void _onEvent​(Event e)
        Calls the event listeners and the onEvent method for this control.
      • addPenListener

        public void addPenListener​(PenListener listener)
        Adds a listener for Pen events.
        See Also:
        PenListener
      • addMouseListener

        public void addMouseListener​(MouseListener listener)
        Adds a listener for mouse events.
        See Also:
        MouseListener
      • addWindowListener

        public void addWindowListener​(WindowListener listener)
        Adds a listener for Window events.
        See Also:
        WindowListener
      • addGridListener

        public void addGridListener​(GridListener listener)
        Adds a listener for Grid events.
        See Also:
        GridListener
      • addFocusListener

        public void addFocusListener​(FocusListener listener)
        Adds a listener for Focus events.
        See Also:
        FocusListener
      • addPressListener

        public void addPressListener​(PressListener listener)
        Adds a listener for Press events.
        See Also:
        PressListener
      • addTimerListener

        public void addTimerListener​(TimerListener listener)
        Adds a listener for Timer events.
        See Also:
        TimerListener
      • addKeyListener

        public void addKeyListener​(KeyListener listener)
        Adds a listener for Key events.
        See Also:
        KeyListener
      • addEnabledStateListener

        public void addEnabledStateListener​(EnabledStateChangeListener listener)
        Adds a listener for enabled state changes.
      • removeEnabledStateListener

        public void removeEnabledStateListener​(EnabledStateChangeListener listener)
        Removes a listener for enabled state changes.
        Since:
        TotalCross 1.67
      • removeMultiTouchListener

        public void removeMultiTouchListener​(MultiTouchListener listener)
        Removes a listener for MultiTouch events.
        Since:
        TotalCross 1.22
        See Also:
        MultiTouchListener
      • removePenListener

        public void removePenListener​(PenListener listener)
        Removes a listener for Pen events.
        Since:
        TotalCross 1.22
        See Also:
        PenListener
      • removeMouseListener

        public void removeMouseListener​(MouseListener listener)
        Removes a listener for mouse events.
        Since:
        TotalCross 1.22
        See Also:
        MouseListener
      • removeWindowListener

        public void removeWindowListener​(WindowListener listener)
        Removes a listener for Window events.
        Since:
        TotalCross 1.22
        See Also:
        WindowListener
      • removeGridListener

        public void removeGridListener​(GridListener listener)
        Removes a listener for Grid events.
        Since:
        TotalCross 1.22
        See Also:
        GridListener
      • removeFocusListener

        public void removeFocusListener​(FocusListener listener)
        Removes a listener for Focus events.
        Since:
        TotalCross 1.22
        See Also:
        FocusListener
      • removePressListener

        public void removePressListener​(PressListener listener)
        Removes a listener for Press events.
        Since:
        TotalCross 1.22
        See Also:
        PressListener
      • removeTimerListener

        public void removeTimerListener​(TimerListener listener)
        Removes a listener for Timer events.
        Since:
        TotalCross 1.22
        See Also:
        TimerListener
      • removeKeyListener

        public void removeKeyListener​(KeyListener listener)
        Removes a listener for Key events.
        Since:
        TotalCross 1.22
        See Also:
        KeyListener
      • removeHighlightListener

        public void removeHighlightListener​(HighlightListener listener)
        Removes a listener for Highlight events.
        Since:
        TotalCross 1.22
        See Also:
        HighlightListener
      • handleGeographicalFocusChangeKeys

        public Control handleGeographicalFocusChangeKeys​(KeyEvent ke)
        Used by the main event loop to give the currently focused control an opportunity to act directly on the KeyEvent.
        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
      • getEventListeners

        public Vector getEventListeners()
        Returns the event listeners array. Note that each element is an instance of Control.Listener.
        See Also:
        Listener
      • isVisibleAndInside

        public boolean isVisibleAndInside​(int x0,
                                          int y0,
                                          int xf,
                                          int yf)
        Returns true of this control is visible and inside these bounds
        Since:
        TotalCross 1.15
      • getGap

        public int getGap​(int gap)
      • bringToFront

        public void bringToFront()
        Send this control to the top of the parent's.
        Since:
        TotalCross 1.3
      • sendToBack

        public void sendToBack()
        Send this control to the last place of the parent's.
        Since:
        TotalCross 1.3
      • hadParentScrolled

        public boolean hadParentScrolled()
        Returns true if the parent of this control is a Scrollable and had scrolled since the last pen down. A scroll occurs before a flick is started.
        Since:
        TotalCross 1.3
      • willOpenKeyboard

        protected boolean willOpenKeyboard()
        Returns true if this is a MultiEdit or an Edit that has a standard keyboard.
      • isActionEvent

        protected boolean isActionEvent​(Event event)
        Returns if this event should be handled as an action.
      • isChildOf

        public boolean isChildOf​(Container p)
        Returns true if this control is added to the given container at some higher level.
        Since:
        TotalCross 1.53
      • isTopMost

        public boolean isTopMost()
        Returns true of the parent window is the top most one.
        Since:
        TotalCross 1.66
      • isObscured

        public boolean isObscured​(Window parentWindow)
        Returns true if this control is obscured by the topmost window. Note: parentWindow is retrieved with getParentWindow.
        Since:
        TotalCross 2.1
      • safeRepaintNow

        protected void safeRepaintNow()
        Called by code that runs on threads to safely repaint now.
        Since:
        TotalCross 3.1
      • intXYWH

        public void intXYWH​(int x,
                            int y,
                            int w,
                            int h)
      • setTranslucent

        public void setTranslucent​(Control.TranslucentShape shape)
        Make this control a translucent one by setting the desired shape instead of NONE. Calling this resets the backColor to BLACK, foreColor to WHITE, and the textShadowColor to 0x444444, but you may change that value later. You can also change the translucentAlpha value. Note that a translucent button does not have a visual DISABLED state. It requires the Android or Holo user interface styles.
      • drawTranslucentBackground

        public boolean drawTranslucentBackground​(Graphics g,
                                                 int alphaValue)
      • getEffectW

        public int getEffectW()
      • getEffectH

        public int getEffectH()
      • getEffectX

        public int getEffectX()
      • getEffectY

        public int getEffectY()
      • hasFocus

        public boolean hasFocus()
        Returns true if this control has focus