Class LookAndFeel

java.lang.Object
com.codename1.ui.plaf.LookAndFeel
Direct Known Subclasses:
DefaultLookAndFeel

public abstract class LookAndFeel extends Object
Allows a UI developer to completely customize the look of the application by overriding drawing/sizing methods appropriately.
  • Constructor Details

    • LookAndFeel

      public LookAndFeel(UIManager manager)
  • Method Details

    • bind

      public void bind(Component cmp)

      Every component binds itself to the look and feel thus allowing the look and feel to customize the component. Binding occurs at the end of the constructor when the component is in a valid state and ready to be used. Notice that a component might be bound twice or more and it is the responsibility of the LookAndFeel to protect against that.

      Parameters
      • cmp: component instance that may be customized by the look and feel
    • uninstall

      public void uninstall()

      Invoked when a look and feel is removed, allows a look and feel to release resources related to binding components.

      See also
      • #bind(Component)
    • drawButton

      public abstract void drawButton(Graphics g, Button b)

      Invoked for drawing a button widget

      Parameters
      • g: graphics context

      • b: component to draw

      Deprecated

      this method is no longer used by the implementation, we shifted code away to improve performance

    • drawCheckBox

      public abstract void drawCheckBox(Graphics g, Button cb)

      Invoked for drawing a checkbox widget

      Parameters
      • g: graphics context

      • cb: component to draw

    • drawComboBox

      public abstract void drawComboBox(Graphics g, List cb)

      Invoked for drawing a combo box widget

      Parameters
      • g: graphics context

      • cb: component to draw

    • drawLabel

      public abstract void drawLabel(Graphics g, Label l)

      Invoked for drawing a label widget

      Parameters
      • g: graphics context

      • l: component to draw

      Deprecated

      this method is no longer used by the implementation, we shifted code away to improve performance

    • calculateLabelSpan

      public abstract TextSelection.Span calculateLabelSpan(TextSelection sel, Label l)

      Calculates the text selection spans for a given label

      Parameters
      • sel: TextSelection instance

      • l: Label

      Returns

      A span representing the positions of characters in the label

      Since

      7.0

      See also
      • TextSelection
    • drawList

      public abstract void drawList(Graphics g, List l)

      Invoked for drawing a list widget

      Parameters
      • g: graphics context

      • l: component to draw

    • drawRadioButton

      public abstract void drawRadioButton(Graphics g, Button rb)

      Invoked for drawing the radio button widget

      Parameters
      • g: graphics context

      • rb: component to draw

    • drawTextArea

      public abstract void drawTextArea(Graphics g, TextArea ta)

      Draw the given text area

      Parameters
      • g: graphics context

      • ta: component to draw

    • calculateTextAreaSpan

      public abstract TextSelection.Spans calculateTextAreaSpan(TextSelection sel, TextArea ta)

      Calculates the Spans used in text selection for a given text area.

      Parameters
      • sel: The current TextSelection instance.

      • ta: The TextArea to calculate spans for.

      Returns

      The spans for the given text field.

      Since

      7.0

    • drawTextField

      public abstract void drawTextField(Graphics g, TextArea ta)

      Draws the text field without its cursor which is drawn in a separate method input mode indication can also be drawn using this method.

      Parameters
      • g: graphics context

      • ta: component to draw

    • calculateTextFieldSpan

      public abstract TextSelection.Spans calculateTextFieldSpan(TextSelection sel, TextArea ta)

      Calculates the Spans used in text selection for a given text field.

      Parameters
      • sel: The current TextSelection instance.

      • ta: The textfield to calculate spans for.

      Returns

      The spans for the given text field.

      Since

      7.0

    • drawTextFieldCursor

      public abstract void drawTextFieldCursor(Graphics g, TextArea ta)

      Draws the cursor of the text field, blinking is handled simply by avoiding a call to this method.

      Parameters
      • g: graphics context

      • ta: component to draw

    • getButtonPreferredSize

      public abstract Dimension getButtonPreferredSize(Button b)

      Calculate the preferred size of the component

      Parameters
      • b: component whose size should be calculated
      Returns

      the preferred size for the button

    • getCheckBoxPreferredSize

      public abstract Dimension getCheckBoxPreferredSize(Button cb)

      Calculate the preferred size of the component

      Parameters
      • cb: component whose size should be calculated
      Returns

      the preferred size for the component

    • getLabelPreferredSize

      public abstract Dimension getLabelPreferredSize(Label l)

      Calculate the preferred size of the component

      Parameters
      • l: component whose size should be calculated
      Returns

      the preferred size for the component

    • getListPreferredSize

      public abstract Dimension getListPreferredSize(List l)

      Calculate the preferred size of the component

      Parameters
      • l: component whose size should be calculated
      Returns

      the preferred size for the component

    • getRadioButtonPreferredSize

      public abstract Dimension getRadioButtonPreferredSize(Button rb)

      Calculate the preferred size of the component

      Parameters
      • rb: component whose size should be calculated
      Returns

      the preferred size for the component

    • getTextAreaSize

      public abstract Dimension getTextAreaSize(TextArea ta, boolean pref)

      Calculate the preferred size of the component

      Parameters
      • ta: component whose size should be calculated

      • pref: indicates whether preferred or scroll size should be returned

      Returns

      the preferred size for the component

    • getTextFieldPreferredSize

      public abstract Dimension getTextFieldPreferredSize(TextArea ta)

      Calculate the preferred size of the component

      Parameters
      • ta: component whose size should be calculated
      Returns

      the preferred size for the component

    • getComboBoxPreferredSize

      public abstract Dimension getComboBoxPreferredSize(List box)

      Calculate the preferred size of the component

      Parameters
      • box: component whose size should be calculated
      Returns

      the preferred size for the component

    • drawVerticalScroll

      public void drawVerticalScroll(Graphics g, Component c, float offsetRatio, float blockSizeRatio)

      Draws a vertical scroll bar in the given component

      Parameters
      • g: graphics context

      • c: component to draw on

      • offsetRatio: ratio of the scroll bar from 0 to 1

      • blockSizeRatio: block size for the scroll from 0 to 1

    • drawHorizontalScroll

      public void drawHorizontalScroll(Graphics g, Component c, float offsetRatio, float blockSizeRatio)

      Draws a horizontal scroll bar in the given component

      Parameters
      • g: graphics context

      • c: component to draw on

      • offsetRatio: ratio of the scroll bar from 0 to 1

      • blockSizeRatio: block size for the scroll from 0 to 1

    • setFG

      public void setFG(Graphics g, Component c)

      Sets the foreground color and font for a generic component, reuse-able by most component drawing code

      Parameters
      • g: graphics context

      • c: component from which fg styles should be set

    • getVerticalScrollWidth

      public int getVerticalScrollWidth()

      Returns the default width of a vertical scroll bar

      Returns

      default width of a vertical scroll bar

    • getHorizontalScrollHeight

      public int getHorizontalScrollHeight()

      Returns the default height of a horizontal scroll bar

      Returns

      default height of a horizontal scroll bar

    • getDefaultFormTransitionIn

      public Transition getDefaultFormTransitionIn()

      Allows us to define a default animation that will draw the transition for entering a form

      Returns

      default transition

    • setDefaultFormTransitionIn

      public void setDefaultFormTransitionIn(Transition defaultFormTransitionIn)

      Allows us to define a default animation that will draw the transition for entering a form

      Parameters
      • defaultFormTransitionIn: the default transition
    • getDefaultFormTransitionOut

      public Transition getDefaultFormTransitionOut()

      Allows us to define a default animation that will draw the transition for exiting a form

      Returns

      default transition

    • setDefaultFormTransitionOut

      public void setDefaultFormTransitionOut(Transition defaultFormTransitionOut)

      Allows us to define a default animation that will draw the transition for exiting a form

      Parameters
      • defaultFormTransitionOut: the default transition
    • getDefaultMenuTransitionIn

      public Transition getDefaultMenuTransitionIn()

      Allows us to define a default animation that will draw the transition for entering a Menu

      Returns

      default transition

    • setDefaultMenuTransitionIn

      public void setDefaultMenuTransitionIn(Transition defaultMenuTransitionIn)

      Allows us to define a default animation that will draw the transition for entering a Menu

      Parameters
      • defaultMenuTransitionIn: the default transition
    • getDefaultMenuTransitionOut

      public Transition getDefaultMenuTransitionOut()

      Allows us to define a default animation that will draw the transition for exiting a Menu

      Returns

      default transition

    • setDefaultMenuTransitionOut

      public void setDefaultMenuTransitionOut(Transition defaultMenuTransitionOut)

      Allows us to define a default animation that will draw the transition for exiting a Menu

      Parameters
      • defaultMenuTransitionOut: the default transition
    • getDefaultDialogTransitionIn

      public Transition getDefaultDialogTransitionIn()

      Allows us to define a default animation that will draw the transition for entering a dialog

      Returns

      default transition

    • setDefaultDialogTransitionIn

      public void setDefaultDialogTransitionIn(Transition defaultDialogTransitionIn)

      Allows us to define a default animation that will draw the transition for entering a dialog

      Parameters
      • defaultDialogTransitionIn: the default transition
    • getDefaultDialogTransitionOut

      public Transition getDefaultDialogTransitionOut()

      Allows us to define a default animation that will draw the transition for exiting a dialog

      Returns

      default transition

    • setDefaultDialogTransitionOut

      public void setDefaultDialogTransitionOut(Transition defaultDialogTransitionOut)

      Allows us to define a default animation that will draw the transition for exiting a dialog

      Parameters
      • defaultDialogTransitionOut: the default transition
    • getDefaultFormTintColor

      public int getDefaultFormTintColor()

      Tint color is set when a form is partially covered be it by a menu or by a dialog. A look and feel can override this default value.

      Returns

      default tint color

    • setDefaultFormTintColor

      public void setDefaultFormTintColor(int defaultFormTintColor)

      Tint color is set when a form is partially covered be it by a menu or by a dialog. A look and feel can override this default value.

      Parameters
      • defaultFormTintColor: the default tint color
    • getDisableColor

      public int getDisableColor()

      This color is used to paint disable mode text color.

      Returns

      the color value

    • setDisableColor

      public void setDisableColor(int disableColor)

      Simple setter to disable color

      Parameters
      • disableColor: the disable color value
    • isDefaultSmoothScrolling

      public boolean isDefaultSmoothScrolling()

      Indicates whether lists and containers should have smooth scrolling by default

      Returns

      true if smooth scrolling should be on by default

    • setDefaultSmoothScrolling

      public void setDefaultSmoothScrolling(boolean defaultSmoothScrolling)

      Indicates whether lists and containers should have smooth scrolling by default

      Parameters
      • defaultSmoothScrolling: true if smooth scrolling should be on by default
    • getDefaultSmoothScrollingSpeed

      public int getDefaultSmoothScrollingSpeed()

      Indicates the default speed for smooth scrolling

      Returns

      speed for smooth scrollin

    • setDefaultSmoothScrollingSpeed

      public void setDefaultSmoothScrollingSpeed(int defaultSmoothScrollingSpeed)

      Indicates the default speed for smooth scrolling

      Parameters
      • defaultSmoothScrollingSpeed: speed for smooth scrollin
    • isReverseSoftButtons

      public boolean isReverseSoftButtons()

      Indicates whether softbuttons should be reversed from their default orientation

      Returns

      true if softbuttons should be reversed

    • setReverseSoftButtons

      public void setReverseSoftButtons(boolean reverseSoftButtons)

      Indicates whether softbuttons should be reversed from their default orientation

      Parameters
      • reverseSoftButtons: true if softbuttons should be reversed
    • getMenuBarClass

      public Class getMenuBarClass()

      This method returns the MenuBar class.

      Returns

      the MenuBar class.

      Deprecated
    • setMenuBarClass

      public void setMenuBarClass(Class menuBar)

      Simple setter for the MenuBar Class

      Parameters
      • menuBar
      Deprecated
    • getMenuRenderer

      public ListCellRenderer getMenuRenderer()

      Returns the Menu default renderer

      Returns

      default renderer for the menu

    • setMenuRenderer

      public void setMenuRenderer(ListCellRenderer menuRenderer)

      Sets the Menu default renderer

      Parameters
      • menuRenderer: default renderer for the menu
    • setMenuIcons

      public void setMenuIcons(Image select, Image cancel, Image menu)

      Sets globally the Menu icons

      Parameters
      • select: select icon

      • cancel: cancel icon

      • menu: menu icon

    • getMenuIcons

      public Image[] getMenuIcons()

      Simple getter for the menu icons

      Returns
      Returns:
      an Image array at size of 3, where the first is the select image the second is the cancel image and the last is the menu image.
    • getTickerSpeed

      public long getTickerSpeed()

      Gets the ticker speed

      Returns

      ticker speed in milliseconds

    • setTickerSpeed

      public void setTickerSpeed(long tickerSpeed)

      Sets the ticker speed

      Parameters
      • tickerSpeed: the speed in milliseconds
    • refreshTheme

      public void refreshTheme(boolean completeClear)

      This method is a callback to the LookAndFeel when a theme is being changed in the UIManager

      Parameters
      • completeClear: indicates that the theme is set and not added
    • isTouchMenus

      public boolean isTouchMenus()

      Indicates whether the menu UI should target a touch based device or a standard cell phone

      Returns

      true for touch menus

      Deprecated

      use Display.getCommandBehavior() == Display.COMMAND_BEHAVIOR_TOUCH_MENU

    • setTouchMenus

      public void setTouchMenus(boolean touchMenus)

      Indicates whether the menu UI should target a touch based device or a standard cell phone

      Parameters
      • touchMenus: true to enable touch menus false to disable
      Deprecated

      use Display.setCommandBehavior(Display.COMMAND_BEHAVIOR_TOUCH_MENU)

    • isRTL

      public boolean isRTL()

      Use this to check if the LookAndFeel is in RTL mode

      Returns

      true if the LookAndFeel is in right-to-left mode, false otherwise

    • setRTL

      public void setRTL(boolean rtl)

      Sets this LookAndFeel to operate in right-to-left mode.

      Parameters
      • rtl: - true if right-to-left, false if left-to-right
    • getTactileTouchDuration

      public int getTactileTouchDuration()

      Allows defining a tactile touch device that vibrates when the user presses a component that should respond with tactile feedback on a touch device (e.g. vibrate). Setting this to 0 disables tactile feedback completely

      Returns

      the tactileTouchDuration

    • setTactileTouchDuration

      public void setTactileTouchDuration(int tactileTouchDuration)

      Allows defining a tactile touch device that vibrates when the user presses a component that should respond with tactile feedback on a touch device (e.g. vibrate). Setting this to 0 disables tactile feedback completely

      Parameters
      • tactileTouchDuration: the duration of vibration
    • isDefaultEndsWith3Points

      public boolean isDefaultEndsWith3Points()

      Indicates whether labels should end with 3 points by default

      Returns

      whether labels should end with 3 points by default

    • setDefaultEndsWith3Points

      public void setDefaultEndsWith3Points(boolean defaultEndsWith3Points)

      Indicates whether labels should end with 3 points by default

      Parameters
      • defaultEndsWith3Points: True to indicates that labels should end with 3 points by default
    • isDefaultTensileDrag

      public boolean isDefaultTensileDrag()

      Indicates whether tensile drag should be active by default

      Returns

      whether tensile drag should be active by default

    • setDefaultTensileDrag

      public void setDefaultTensileDrag(boolean defaultTensileDrag)

      Indicates whether tensile drag should be active by default

      Parameters
      • defaultTensileDrag: true if tensile drag should be active by default
    • isFocusScrolling

      public boolean isFocusScrolling()

      Indicates whether lists and containers should scroll only via focus and thus "jump" when moving to a larger component as was the case in older versions of Codename One.

      Returns

      true if focus scrolling is enabled

    • setFocusScrolling

      public void setFocusScrolling(boolean focusScrolling)

      Indicates whether lists and containers should scroll only via focus and thus "jump" when moving to a larger component as was the case in older versions of Codename One.

      Parameters
      • focusScrolling: true to enable focus scrolling
    • isFadeScrollEdge

      public boolean isFadeScrollEdge()

      Indicates whether the edge of a scrollable area should fade out

      Returns

      the fadeScrollEdge

    • setFadeScrollEdge

      public void setFadeScrollEdge(boolean fadeScrollEdge)

      Indicates whether the edge of a scrollable area should fade out

      Parameters
      • fadeScrollEdge: the fadeScrollEdge to set
    • isFadeScrollBar

      public boolean isFadeScrollBar()

      Indicates whether the scrollbar should fade when unused

      Returns

      the fadeScrollBar

    • setFadeScrollBar

      public void setFadeScrollBar(boolean fadeScrollBar)

      Indicates whether the scrollbar should fade when unused

      Parameters
      • fadeScrollBar: the fadeScrollBar to set
    • getFadeScrollEdgeLength

      public int getFadeScrollEdgeLength()

      Indicates the width/height of the fading edge to indicate scrolling

      Returns

      the fadeScrollEdgeLength

    • setFadeScrollEdgeLength

      public void setFadeScrollEdgeLength(int fadeScrollEdgeLength)

      Indicates the width/height of the fading edge to indicate scrolling

      Parameters
      • fadeScrollEdgeLength: the fadeScrollEdgeLength to set
    • getTextFieldCursorColor

      public int getTextFieldCursorColor()

      The color of the text field cursor

      Returns

      the textFieldCursorColor

    • setTextFieldCursorColor

      public void setTextFieldCursorColor(int textFieldCursorColor)

      The color of the text field cursor

      Parameters
      • textFieldCursorColor: the textFieldCursorColor to set
    • isDefaultSnapToGrid

      public boolean isDefaultSnapToGrid()

      Indicates whether scrolling this component should jump to a specific location in a grid

      Returns

      the defaultSnapToGrid

    • setDefaultSnapToGrid

      public void setDefaultSnapToGrid(boolean defaultSnapToGrid)

      Indicates whether scrolling this component should jump to a specific location in a grid

      Parameters
      • defaultSnapToGrid: the defaultSnapToGrid to set
    • isDefaultAlwaysTensile

      public boolean isDefaultAlwaysTensile()

      Enable the tensile drag to work even when a component doesn't have a scroll showable (scrollable flag still needs to be set to true)

      Returns

      the defaultAlwaysTensile

    • setDefaultAlwaysTensile

      public void setDefaultAlwaysTensile(boolean defaultAlwaysTensile)

      Enable the tensile drag to work even when a component doesn't have a scroll showable (scrollable flag still needs to be set to true)

      Parameters
      • defaultAlwaysTensile: the defaultAlwaysTensile to set
    • isDefaultTensileHighlight

      public boolean isDefaultTensileHighlight()

      Indicates whether tensile highlight should be active by default

      Returns

      the defaultTensileHighlight

    • paintTensileHighlight

      public void paintTensileHighlight(Component t, Graphics g, boolean top, int opacity)

      Paints the tensile hightlight image

      Parameters
      • g: graphics destination for the tensile highlight image

      • top: destination of the tensile highlight image

      • opacity: the opacity of the image

    • getFadeScrollBarSpeed

      public int getFadeScrollBarSpeed()
      Returns

      the fadeScrollBarSpeed

    • setFadeScrollBarSpeed

      public void setFadeScrollBarSpeed(int fadeScrollBarSpeed)
      Parameters
      • fadeScrollBarSpeed: the fadeScrollBarSpeed to set
    • isScrollVisible

      public boolean isScrollVisible()
      Returns

      scrollVisible

    • isBackgroundImageDetermineSize

      public boolean isBackgroundImageDetermineSize()

      Indicates if the bg image of a style should determine the minimum preferred size according to the theme

      Returns

      the backgroundImageDetermineSize

    • setBackgroundImageDetermineSize

      public void setBackgroundImageDetermineSize(boolean backgroundImageDetermineSize)

      Indicates if the bg image of a style should determine the minimum preferred size according to the theme

      Parameters
      • backgroundImageDetermineSize: the backgroundImageDetermineSize to set
    • drawPullToRefresh

      public abstract void drawPullToRefresh(Graphics g, Component cmp, boolean taskExecuted)

      Paints the pull to refresh

      Parameters
      • g: graphics context

      • cmp: the Component which we draw the pull to refresh beneath it

      • taskExecuted: an indication if the refresh task is currently running

    • getPullToRefreshHeight

      public abstract int getPullToRefreshHeight()
      Returns the required height of the pull to refresh feature