Package org.apache.pivot.wtk.skin
Class LabelSkin
- java.lang.Object
-
- org.apache.pivot.wtk.skin.ComponentSkin
-
- org.apache.pivot.wtk.skin.LabelSkin
-
- All Implemented Interfaces:
ComponentKeyListener
,ComponentListener
,ComponentMouseButtonListener
,ComponentMouseListener
,ComponentMouseWheelListener
,ComponentStateListener
,ComponentTooltipListener
,ConstrainedVisual
,LabelListener
,Skin
,Visual
- Direct Known Subclasses:
TerraLabelSkin
public class LabelSkin extends ComponentSkin implements LabelListener
Label skin.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.pivot.wtk.ComponentKeyListener
ComponentKeyListener.Adapter, ComponentKeyListener.Listeners
-
Nested classes/interfaces inherited from interface org.apache.pivot.wtk.ComponentListener
ComponentListener.Adapter, ComponentListener.Listeners
-
Nested classes/interfaces inherited from interface org.apache.pivot.wtk.ComponentMouseButtonListener
ComponentMouseButtonListener.Adapter, ComponentMouseButtonListener.Listeners
-
Nested classes/interfaces inherited from interface org.apache.pivot.wtk.ComponentMouseListener
ComponentMouseListener.Adapter, ComponentMouseListener.Listeners
-
Nested classes/interfaces inherited from interface org.apache.pivot.wtk.ComponentMouseWheelListener
ComponentMouseWheelListener.Listeners
-
Nested classes/interfaces inherited from interface org.apache.pivot.wtk.ComponentStateListener
ComponentStateListener.Adapter, ComponentStateListener.Listeners
-
Nested classes/interfaces inherited from interface org.apache.pivot.wtk.ComponentTooltipListener
ComponentTooltipListener.Listeners
-
Nested classes/interfaces inherited from interface org.apache.pivot.wtk.LabelListener
LabelListener.Adapter, LabelListener.Listeners
-
-
Constructor Summary
Constructors Constructor Description LabelSkin()
Default constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.awt.Color
getBackgroundColor()
int
getBaseline(int width, int height)
Should be implemented in every subclass.java.awt.Color
getColor()
java.awt.Color
getDisabledColor()
java.awt.Font
getFont()
HorizontalAlignment
getHorizontalAlignment()
Insets
getPadding()
int
getPreferredHeight(int width)
Returns the visual's preferred height given the provided width constraint.Dimensions
getPreferredSize()
Returns the visual's unconstrained preferred size.int
getPreferredWidth(int height)
Returns the visual's preferred width given the provided height constraint.TextDecoration
getTextDecoration()
VerticalAlignment
getVerticalAlignment()
boolean
getWrapText()
void
install(Component component)
Must be implemented in every subclass in order to do component-specific operations at instantiation time, but every subclass must call this superclass method to setup the necessary listeners, etc.boolean
isFocusable()
By default, skins are focusable.boolean
isOpaque()
By default, skins are assumed to be opaque.void
layout()
If the component on which the skin is installed is a container, lays out the container's children.void
maximumLengthChanged(Label label, int previousMaximumLength)
Called when a label text maximum length has changed.void
paint(java.awt.Graphics2D graphics)
Paints the visual.void
setBackgroundColor(java.lang.Object colorValue)
Sets the background color of the label.void
setColor(java.lang.Object colorValue)
Sets the foreground color of the text of the label.void
setDisabledColor(java.lang.Object colorValue)
Sets the foreground color of the text of the label when disabled.void
setFont(java.lang.Object fontValue)
Sets the font used in rendering the Label's text.void
setHorizontalAlignment(HorizontalAlignment horizontalAlignmentValue)
Set the horizontal alignment for the text inside the label's total width.void
setPadding(java.lang.Object paddingValues)
Sets the amount of space to leave between the edge of the Label and its text.void
setTextDecoration(TextDecoration textDecorationValue)
Sets the text decoration (eg, strikethrough, underline, etc) for this label.void
setVerticalAlignment(VerticalAlignment verticalAlignmentValue)
Set the new vertical alignment value for the text inside the label's height.void
setWrapText(boolean wrapTextValue)
Sets whether the text of the label will be wrapped to fit the Label's width.void
textChanged(Label label, java.lang.String previousText)
Called when a label's text has changed.-
Methods inherited from class org.apache.pivot.wtk.skin.ComponentSkin
colorFromObject, colorFromObject, colorFromObject, colorFromObject, currentTheme, cursorChanged, decodeFont, defaultBackgroundColor, defaultForegroundColor, dragSourceChanged, dropTargetChanged, enabledChanged, focusedChanged, fontFromObject, getBaseline, getColor, getComponent, getFocusRectangleStroke, getHeight, getSize, getTextInputMethodListener, getThemeFont, getWidth, heightLimitsChanged, invalidateComponent, keyPressed, keyReleased, keyTyped, locationChanged, menuHandlerChanged, mouseClick, mouseDown, mouseMove, mouseOut, mouseOver, mouseUp, mouseWheel, nameChanged, parentChanged, preferredSizeChanged, repaintComponent, repaintComponent, repaintComponent, repaintComponent, repaintComponent, setDefaultStyles, setSize, sizeChanged, themeHasThickFocusRectangle, themeHasTransitionEnabled, themeIsDark, themeIsFlat, tooltipDelayChanged, tooltipTextChanged, tooltipTriggered, visibleChanged, widthLimitsChanged
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.pivot.wtk.ConstrainedVisual
setSize
-
-
-
-
Method Detail
-
install
public void install(Component component)
Description copied from class:ComponentSkin
Must be implemented in every subclass in order to do component-specific operations at instantiation time, but every subclass must call this superclass method to setup the necessary listeners, etc.- Specified by:
install
in interfaceSkin
- Overrides:
install
in classComponentSkin
- Parameters:
component
- The component to which the skin is being attached.
-
getPreferredWidth
public int getPreferredWidth(int height)
Description copied from interface:ConstrainedVisual
Returns the visual's preferred width given the provided height constraint.- Specified by:
getPreferredWidth
in interfaceConstrainedVisual
- Parameters:
height
- The height by which to constrain the preferred width, or-1
for no constraint.- Returns:
- The preferred width given the height constraint.
-
getPreferredHeight
public int getPreferredHeight(int width)
Description copied from interface:ConstrainedVisual
Returns the visual's preferred height given the provided width constraint.- Specified by:
getPreferredHeight
in interfaceConstrainedVisual
- Parameters:
width
- The width by which to constrain the preferred height, or-1
for no constraint.- Returns:
- The preferred height given the width constraint.
-
getPreferredSize
public Dimensions getPreferredSize()
Description copied from interface:ConstrainedVisual
Returns the visual's unconstrained preferred size.- Specified by:
getPreferredSize
in interfaceConstrainedVisual
- Overrides:
getPreferredSize
in classComponentSkin
- Returns:
- The preferred size (width and height) of this component.
Depending on the component this can be a static value or derived (as for a container) from its subcomponents, etc.
The default implementation simply calls
ConstrainedVisual.getPreferredWidth(int)
andConstrainedVisual.getPreferredHeight(int)
.
-
getBaseline
public int getBaseline(int width, int height)
Description copied from class:ComponentSkin
Should be implemented in every subclass.The default implementation here simply returns -1 (no baseline).
- Specified by:
getBaseline
in interfaceConstrainedVisual
- Overrides:
getBaseline
in classComponentSkin
- Parameters:
width
- Constrained width to compute the baseline for.height
- Constrained height to compute the baseline for.- Returns:
- The baseline relative to the origin of this visual, or
-1
if this visual does not have a baseline.
-
layout
public void layout()
Description copied from interface:Skin
If the component on which the skin is installed is a container, lays out the container's children.
-
paint
public void paint(java.awt.Graphics2D graphics)
Description copied from interface:Visual
Paints the visual.
-
isFocusable
public boolean isFocusable()
Description copied from class:ComponentSkin
By default, skins are focusable.- Specified by:
isFocusable
in interfaceSkin
- Overrides:
isFocusable
in classComponentSkin
- Returns:
false
; labels are not focusable.
-
isOpaque
public boolean isOpaque()
Description copied from class:ComponentSkin
By default, skins are assumed to be opaque.- Specified by:
isOpaque
in interfaceSkin
- Overrides:
isOpaque
in classComponentSkin
- Returns:
true
if this skin is opaque;false
if any part of it is transparent or translucent.
-
getFont
public java.awt.Font getFont()
- Returns:
- The font used in rendering the Label's text.
-
setFont
public void setFont(java.lang.Object fontValue)
Sets the font used in rendering the Label's text.- Parameters:
fontValue
- The new font to use to render the text of a type supported byComponentSkin.fontFromObject(java.lang.Object)
.
-
getColor
public java.awt.Color getColor()
- Returns:
- The foreground color of the text of the label.
-
setColor
public void setColor(java.lang.Object colorValue)
Sets the foreground color of the text of the label.- Parameters:
colorValue
- The new foreground color for the label text, which can be interpreted byComponentSkin.colorFromObject(java.lang.Object)
.
-
getDisabledColor
public java.awt.Color getDisabledColor()
- Returns:
- The foreground color of the text of the label when disabled.
-
setDisabledColor
public void setDisabledColor(java.lang.Object colorValue)
Sets the foreground color of the text of the label when disabled.- Parameters:
colorValue
- The new disabled text color, which can be interpreted byComponentSkin.colorFromObject(java.lang.Object)
.
-
getBackgroundColor
public java.awt.Color getBackgroundColor()
- Returns:
- The background color of the label.
-
setBackgroundColor
public final void setBackgroundColor(java.lang.Object colorValue)
Sets the background color of the label.- Parameters:
colorValue
- The new background color for the label (can benull
to let the parent background show through), or a value that can be interpreted byComponentSkin.colorFromObject(java.lang.Object)
.
-
getTextDecoration
public TextDecoration getTextDecoration()
- Returns:
- The current text decoration (strikethrough, underline, etc) for the label
(can be
null
).
-
setTextDecoration
public void setTextDecoration(TextDecoration textDecorationValue)
Sets the text decoration (eg, strikethrough, underline, etc) for this label.- Parameters:
textDecorationValue
- The new setting (can benull
to cancel any decoration for the label).
-
getHorizontalAlignment
public HorizontalAlignment getHorizontalAlignment()
- Returns:
- The horizontal alignment for the label to use when drawing the text inside the label's total width.
-
setHorizontalAlignment
public void setHorizontalAlignment(HorizontalAlignment horizontalAlignmentValue)
Set the horizontal alignment for the text inside the label's total width.- Parameters:
horizontalAlignmentValue
- The new setting.- Throws:
java.lang.IllegalArgumentException
- if the value isnull
.
-
getVerticalAlignment
public VerticalAlignment getVerticalAlignment()
- Returns:
- The vertical alignment used to draw the text inside the label's total height.
-
setVerticalAlignment
public void setVerticalAlignment(VerticalAlignment verticalAlignmentValue)
Set the new vertical alignment value for the text inside the label's height.- Parameters:
verticalAlignmentValue
- The new setting.- Throws:
java.lang.IllegalArgumentException
- if the new value isnull
.
-
getPadding
public Insets getPadding()
- Returns:
- The amount of space to leave between the edge of the Label and its text.
-
setPadding
public void setPadding(java.lang.Object paddingValues)
Sets the amount of space to leave between the edge of the Label and its text.- Parameters:
paddingValues
- The new value of the padding for each edge, of any type supported byInsets.fromObject(java.lang.Object)
.
-
getWrapText
public boolean getWrapText()
- Returns:
true
if the text of the label will be wrapped to fit the Label's width.
-
setWrapText
public void setWrapText(boolean wrapTextValue)
Sets whether the text of the label will be wrapped to fit the Label's width. Note that for wrapping to occur, the Label must specify a preferred width or be placed in a container that constrains its width.Also note that newline characters (if wrapping is set true) will cause a hard line break.
- Parameters:
wrapTextValue
- Whether or not to wrap the Label's text within its width.
-
textChanged
public void textChanged(Label label, java.lang.String previousText)
Description copied from interface:LabelListener
Called when a label's text has changed.- Specified by:
textChanged
in interfaceLabelListener
- Parameters:
label
- The label that has changed.previousText
- The previous text associated with the label.
-
maximumLengthChanged
public void maximumLengthChanged(Label label, int previousMaximumLength)
Description copied from interface:LabelListener
Called when a label text maximum length has changed.- Specified by:
maximumLengthChanged
in interfaceLabelListener
- Parameters:
label
- The label that has changed.previousMaximumLength
- The previous maximum text length for the label.
-
-