public class DefaultLookAndFeel

  1. Object
  2. LookAndFeel
  3. DefaultLookAndFeel

ImplementsFocusListener

Deprecated. this class is still crucial for some features in Codename One. The deprecation is here to indicate our desire to reduce usage/reliance on this class.
Used to render the default look of Codename One

Constructors

public DefaultLookAndFeel(UIManager manager)Creates a new instance of DefaultLookAndFeel

Methods

public static int reverseAlignForBidi(Component c, int align)Reverses alignment in the case of bidi
public void bind(Component cmp)Every component binds itself to the look and feel thus allowing the look and feel to customize the component.
public boolean isTickWhenFocused()This method allows to set all Labels, Buttons, CheckBoxes, RadioButtons to start ticking when the text is too long.
public void setTickWhenFocused(boolean tickWhenFocused)This method allows to set all Labels, Buttons, CheckBoxes, RadioButtons to start ticking when the text is too long.
public void setCheckBoxImages(Image checkedX, Image uncheckedX)Sets images for checkbox checked/unchecked modes
public void setCheckBoxImages(Image checkedX, Image uncheckedX, Image disabledChecked, Image disabledUnchecked)Sets images for checkbox checked/unchecked modes
public void setCheckBoxFocusImages(Image checkedX, Image uncheckedX, Image disabledChecked, Image disabledUnchecked)Sets images for checkbox when in focused mode
public void setComboBoxImage(Image picker)Sets image for the combo box dropdown drawing
public void setRadioButtonImages(Image selected, Image unselected)Sets images for radio button selected/unselected modes
public void setRadioButtonImages(Image selected, Image unselected, Image disabledSelected, Image disabledUnselected)Sets images for radio button selected/unselected modes
public void setRadioButtonFocusImages(Image selected, Image unselected, Image disabledSelected, Image disabledUnselected)Sets images for radio button selected/unselected and disabled modes, when the radio button has focus, these are entirely optional
public void setPasswordChar(char c)Sets the password character to display in the TextArea and the TextField
public Image[] getRadioButtonImages()Returns the images used to represent the radio button (selected followed by unselected).
public Image[] getRadioButtonFocusImages()Returns the images used to represent the radio button when in focused mode
public Image[] getCheckBoxImages()Returns the images used to represent the checkbox (selected followed by unselected).
public Image[] getCheckBoxFocusImages()Returns the images used to represent the checkbox when focused
public void drawButton(Graphics g, Button b)Deprecated Invoked for drawing a button widget
public void drawCheckBox(Graphics g, Button cb)Invoked for drawing a checkbox widget
public void drawLabel(Graphics g, Label l)Deprecated Invoked for drawing a label widget
public TextSelection.Span calculateLabelSpan(TextSelection sel, Label l)Calculates the text selection spans for a given label
public void drawRadioButton(Graphics g, Button rb)Invoked for drawing the radio button widget
public void drawComboBox(Graphics g, List cb)Invoked for drawing a combo box widget
public void drawList(Graphics g, List l)Invoked for drawing a list widget
public TextSelection.Spans calculateTextAreaSpan(TextSelection sel, TextArea ta)Calculates the Spans used in text selection for a given text area.
public void drawTextArea(Graphics g, TextArea ta)Draw the given text area
public Dimension getButtonPreferredSize(Button b)Calculate the preferred size of the component
public Dimension getCheckBoxPreferredSize(Button cb)Calculate the preferred size of the component
public Dimension getLabelPreferredSize(Label l)Calculate the preferred size of the component
public Dimension getListPreferredSize(List l)Calculate the preferred size of the component
public Dimension getRadioButtonPreferredSize(Button rb)Calculate the preferred size of the component
public Dimension getTextAreaSize(TextArea ta, boolean pref)Calculate the preferred size of the component
protected int drawLabelText(Graphics g, Label l, String text, int x, int y, int textSpaceW)Draws the text of a label
public Dimension getComboBoxPreferredSize(List cb)Calculate the preferred size of the component
protected String getTextFieldString(TextArea ta)Similar to getText() but works properly with password fields
public TextSelection.Spans calculateTextFieldSpan(TextSelection sel, TextArea ta)Calculates the Spans used in text selection for a given text field.
public 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.
public Dimension getTextFieldPreferredSize(TextArea ta)Calculate the preferred size of the component
public void drawTextFieldCursor(Graphics g, TextArea ta)Draws the cursor of the text field, blinking is handled simply by avoiding a call to this method.
public void drawPullToRefresh(Graphics g, Component cmp, boolean taskExecuted)Paints the pull to refresh
public void drawModernPullToRefresh(Graphics g, Component cmp, boolean taskExecuted)
public int getPullToRefreshHeight()Returns the required height of the pull to refresh feature
public void focusGained(Component cmp)Invoked when component gains focus
public void focusLost(Component cmp)Invoked when component loses focus
public void refreshTheme(boolean b)This method is a callback to the LookAndFeel when a theme is being changed in the UIManager
public TextSelection.Span calculateSpanForLabelText(TextSelection sel, Label l, String text, int x, int y, int textSpaceW)

Inherited methods

From LookAndFeel

uninstall, drawVerticalScroll, drawHorizontalScroll, setFG, getVerticalScrollWidth, getHorizontalScrollHeight, getDefaultFormTransitionIn, setDefaultFormTransitionIn, getDefaultFormTransitionOut, setDefaultFormTransitionOut, getDefaultMenuTransitionIn, setDefaultMenuTransitionIn, getDefaultMenuTransitionOut, setDefaultMenuTransitionOut, getDefaultDialogTransitionIn, setDefaultDialogTransitionIn, getDefaultDialogTransitionOut, setDefaultDialogTransitionOut, getDefaultFormTintColor, setDefaultFormTintColor, getDisableColor, setDisableColor, isDefaultSmoothScrolling, setDefaultSmoothScrolling, getDefaultSmoothScrollingSpeed, setDefaultSmoothScrollingSpeed, isReverseSoftButtons, setReverseSoftButtons, getMenuBarClass, setMenuBarClass, getMenuRenderer, setMenuRenderer, setMenuIcons, getMenuIcons, getTickerSpeed, setTickerSpeed, isTouchMenus, setTouchMenus, isRTL, setRTL, getTactileTouchDuration, setTactileTouchDuration, isDefaultEndsWith3Points, setDefaultEndsWith3Points, isDefaultTensileDrag, setDefaultTensileDrag, isFocusScrolling, setFocusScrolling, isFadeScrollEdge, setFadeScrollEdge, isFadeScrollBar, setFadeScrollBar, getFadeScrollEdgeLength, setFadeScrollEdgeLength, getTextFieldCursorColor, setTextFieldCursorColor, isDefaultSnapToGrid, setDefaultSnapToGrid, isDefaultAlwaysTensile, setDefaultAlwaysTensile, isDefaultTensileHighlight, paintTensileHighlight, getFadeScrollBarSpeed, setFadeScrollBarSpeed, isScrollVisible, isInteractiveScroll, isBackgroundImageDetermineSize, setBackgroundImageDetermineSize

Constructor details

DefaultLookAndFeel

public DefaultLookAndFeel(UIManager manager)
Creates a new instance of DefaultLookAndFeel

Method details

reverseAlignForBidi

public static int reverseAlignForBidi(Component c, int align)
Reverses alignment in the case of bidi

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
component instance that may be customized by the look and feel

isTickWhenFocused

public boolean isTickWhenFocused()
This method allows to set all Labels, Buttons, CheckBoxes, RadioButtons to start ticking when the text is too long.

Returns

tickWhenFocused

setTickWhenFocused

public void setTickWhenFocused(boolean tickWhenFocused)
This method allows to set all Labels, Buttons, CheckBoxes, RadioButtons to start ticking when the text is too long.

setCheckBoxImages

public void setCheckBoxImages(Image checkedX, Image uncheckedX)
Sets images for checkbox checked/unchecked modes

Parameters

checkedX Image
the image to draw in order to represent a checked checkbox
uncheckedX Image
the image to draw in order to represent an uncheck checkbox

setCheckBoxImages

public void setCheckBoxImages(Image checkedX, Image uncheckedX, Image disabledChecked, Image disabledUnchecked)
Sets images for checkbox checked/unchecked modes

Parameters

checkedX Image
the image to draw in order to represent a checked checkbox
uncheckedX Image
the image to draw in order to represent an uncheck checkbox
disabledChecked Image
same as checked for the disabled state
disabledUnchecked Image
same as unchecked for the disabled state

setCheckBoxFocusImages

public void setCheckBoxFocusImages(Image checkedX, Image uncheckedX, Image disabledChecked, Image disabledUnchecked)
Sets images for checkbox when in focused mode

Parameters

checkedX Image
the image to draw in order to represent a checked checkbox
uncheckedX Image
the image to draw in order to represent an uncheck checkbox
disabledChecked Image
same as checked for the disabled state
disabledUnchecked Image
same as unchecked for the disabled state

setComboBoxImage

public void setComboBoxImage(Image picker)
Sets image for the combo box dropdown drawing

Parameters

picker Image
picker image

setRadioButtonImages

public void setRadioButtonImages(Image selected, Image unselected)
Sets images for radio button selected/unselected modes

Parameters

selected Image
the image to draw in order to represent a selected radio button
unselected Image
the image to draw in order to represent an unselected radio button

setRadioButtonImages

public void setRadioButtonImages(Image selected, Image unselected, Image disabledSelected, Image disabledUnselected)
Sets images for radio button selected/unselected modes

Parameters

selected Image
the image to draw in order to represent a selected radio button
unselected Image
the image to draw in order to represent an unselected radio button
disabledSelected Image
same as selected for the disabled state
disabledUnselected Image
same as unselected for the disabled state

setRadioButtonFocusImages

public void setRadioButtonFocusImages(Image selected, Image unselected, Image disabledSelected, Image disabledUnselected)
Sets images for radio button selected/unselected and disabled modes, when the radio button has focus, these are entirely optional

Parameters

selected Image
the image to draw in order to represent a selected radio button
unselected Image
the image to draw in order to represent an unselected radio button
disabledSelected Image
same as selected for the disabled state
disabledUnselected Image
same as unselected for the disabled state

setPasswordChar

public void setPasswordChar(char c)
Sets the password character to display in the TextArea and the TextField

getRadioButtonImages

public Image[] getRadioButtonImages()
Returns the images used to represent the radio button (selected followed by unselected).

Returns

images representing the radio button or null for using the default drawing

getRadioButtonFocusImages

public Image[] getRadioButtonFocusImages()
Returns the images used to represent the radio button when in focused mode

Returns

images representing the radio button or null for using the default drawing

getCheckBoxImages

public Image[] getCheckBoxImages()
Returns the images used to represent the checkbox (selected followed by unselected).

Returns

images representing the check box or null for using the default drawing

getCheckBoxFocusImages

public Image[] getCheckBoxFocusImages()
Returns the images used to represent the checkbox when focused

Returns

images representing the check box or null for using the default drawing

drawButton

public void drawButton(Graphics g, Button b)
Deprecated. this method is no longer used by the implementation, we shifted code away to improve performance
Invoked for drawing a button widget

Parameters

g Graphics
graphics context
b Button
component to draw

drawCheckBox

public void drawCheckBox(Graphics g, Button cb)
Invoked for drawing a checkbox widget

Parameters

g Graphics
graphics context
cb Button
component to draw

drawLabel

public void drawLabel(Graphics g, Label l)
Deprecated. this method is no longer used by the implementation, we shifted code away to improve performance
Invoked for drawing a label widget

Parameters

g Graphics
graphics context
l Label
component to draw

calculateLabelSpan

public TextSelection.Span calculateLabelSpan(TextSelection sel, Label l)
Calculates the text selection spans for a given label

Parameters

sel TextSelection
TextSelection instance
l Label
Label

Returns

A span representing the positions of characters in the label

drawRadioButton

public void drawRadioButton(Graphics g, Button rb)
Invoked for drawing the radio button widget

Parameters

g Graphics
graphics context
rb Button
component to draw

drawComboBox

public void drawComboBox(Graphics g, List cb)
Invoked for drawing a combo box widget

Parameters

g Graphics
graphics context
cb List
component to draw

drawList

public void drawList(Graphics g, List l)
Invoked for drawing a list widget

Parameters

g Graphics
graphics context
l List
component to draw

calculateTextAreaSpan

public TextSelection.Spans calculateTextAreaSpan(TextSelection sel, TextArea ta)
Calculates the Spans used in text selection for a given text area.

Parameters

sel TextSelection
The current TextSelection instance.
ta TextArea
The TextArea to calculate spans for.

Returns

The spans for the given text field.

drawTextArea

public void drawTextArea(Graphics g, TextArea ta)
Draw the given text area

Parameters

g Graphics
graphics context
ta TextArea
component to draw

getButtonPreferredSize

public Dimension getButtonPreferredSize(Button b)
Calculate the preferred size of the component

Parameters

b Button
component whose size should be calculated

Returns

the preferred size for the button

getCheckBoxPreferredSize

public Dimension getCheckBoxPreferredSize(Button cb)
Calculate the preferred size of the component

Parameters

cb Button
component whose size should be calculated

Returns

the preferred size for the component

getLabelPreferredSize

public Dimension getLabelPreferredSize(Label l)
Calculate the preferred size of the component

Parameters

l Label
component whose size should be calculated

Returns

the preferred size for the component

getListPreferredSize

public Dimension getListPreferredSize(List l)
Calculate the preferred size of the component

Parameters

l List
component whose size should be calculated

Returns

the preferred size for the component

getRadioButtonPreferredSize

public Dimension getRadioButtonPreferredSize(Button rb)
Calculate the preferred size of the component

Parameters

rb Button
component whose size should be calculated

Returns

the preferred size for the component

getTextAreaSize

public Dimension getTextAreaSize(TextArea ta, boolean pref)
Calculate the preferred size of the component

Parameters

ta TextArea
component whose size should be calculated
pref boolean
indicates whether preferred or scroll size should be returned

Returns

the preferred size for the component

drawLabelText

protected int drawLabelText(Graphics g, Label l, String text, int x, int y, int textSpaceW)
Draws the text of a label

Parameters

g Graphics
graphics context
l Label
label component
text String
the text for the label
x int
position for the label
y int
position for the label
textSpaceW int
the width available for the component

Returns

the space used by the drawing

getComboBoxPreferredSize

public Dimension getComboBoxPreferredSize(List cb)
Calculate the preferred size of the component

Parameters

cb List
component whose size should be calculated

Returns

the preferred size for the component

getTextFieldString

protected String getTextFieldString(TextArea ta)
Similar to getText() but works properly with password fields

calculateTextFieldSpan

public TextSelection.Spans calculateTextFieldSpan(TextSelection sel, TextArea ta)
Calculates the Spans used in text selection for a given text field.

Parameters

sel TextSelection
The current TextSelection instance.
ta TextArea
The textfield to calculate spans for.

Returns

The spans for the given text field.

drawTextField

public 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
graphics context
ta TextArea
component to draw

getTextFieldPreferredSize

public Dimension getTextFieldPreferredSize(TextArea ta)
Calculate the preferred size of the component

Parameters

ta TextArea
component whose size should be calculated

Returns

the preferred size for the component

drawTextFieldCursor

public 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
graphics context
ta TextArea
component to draw

drawPullToRefresh

public void drawPullToRefresh(Graphics g, Component cmp, boolean taskExecuted)
Paints the pull to refresh

Parameters

g Graphics
graphics context
cmp Component
the Component which we draw the pull to refresh beneath it
taskExecuted boolean
an indication if the refresh task is currently running

drawModernPullToRefresh

public void drawModernPullToRefresh(Graphics g, Component cmp, boolean taskExecuted)

getPullToRefreshHeight

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

focusGained

public void focusGained(Component cmp)
Invoked when component gains focus

Parameters

cmp Component
the component that gains focus

focusLost

public void focusLost(Component cmp)
Invoked when component loses focus

Parameters

cmp Component
the component that lost focus

refreshTheme

public void refreshTheme(boolean b)
This method is a callback to the LookAndFeel when a theme is being changed in the UIManager

Parameters

b boolean
indicates that the theme is set and not added

calculateSpanForLabelText

public TextSelection.Span calculateSpanForLabelText(TextSelection sel, Label l, String text, int x, int y, int textSpaceW)