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.ColorgetBackgroundColor()intgetBaseline(int width, int height)Should be implemented in every subclass.java.awt.ColorgetColor()java.awt.ColorgetDisabledColor()java.awt.FontgetFont()HorizontalAlignmentgetHorizontalAlignment()InsetsgetPadding()intgetPreferredHeight(int width)Returns the visual's preferred height given the provided width constraint.DimensionsgetPreferredSize()Returns the visual's unconstrained preferred size.intgetPreferredWidth(int height)Returns the visual's preferred width given the provided height constraint.TextDecorationgetTextDecoration()VerticalAlignmentgetVerticalAlignment()booleangetWrapText()voidinstall(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.booleanisFocusable()By default, skins are focusable.booleanisOpaque()By default, skins are assumed to be opaque.voidlayout()If the component on which the skin is installed is a container, lays out the container's children.voidmaximumLengthChanged(Label label, int previousMaximumLength)Called when a label text maximum length has changed.voidpaint(java.awt.Graphics2D graphics)Paints the visual.voidsetBackgroundColor(java.lang.Object colorValue)Sets the background color of the label.voidsetColor(java.lang.Object colorValue)Sets the foreground color of the text of the label.voidsetDisabledColor(java.lang.Object colorValue)Sets the foreground color of the text of the label when disabled.voidsetFont(java.lang.Object fontValue)Sets the font used in rendering the Label's text.voidsetHorizontalAlignment(HorizontalAlignment horizontalAlignmentValue)Set the horizontal alignment for the text inside the label's total width.voidsetPadding(java.lang.Object paddingValues)Sets the amount of space to leave between the edge of the Label and its text.voidsetTextDecoration(TextDecoration textDecorationValue)Sets the text decoration (eg, strikethrough, underline, etc) for this label.voidsetVerticalAlignment(VerticalAlignment verticalAlignmentValue)Set the new vertical alignment value for the text inside the label's height.voidsetWrapText(boolean wrapTextValue)Sets whether the text of the label will be wrapped to fit the Label's width.voidtextChanged(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:ComponentSkinMust 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:
installin interfaceSkin- Overrides:
installin classComponentSkin- Parameters:
component- The component to which the skin is being attached.
-
getPreferredWidth
public int getPreferredWidth(int height)
Description copied from interface:ConstrainedVisualReturns the visual's preferred width given the provided height constraint.- Specified by:
getPreferredWidthin interfaceConstrainedVisual- Parameters:
height- The height by which to constrain the preferred width, or-1for no constraint.- Returns:
- The preferred width given the height constraint.
-
getPreferredHeight
public int getPreferredHeight(int width)
Description copied from interface:ConstrainedVisualReturns the visual's preferred height given the provided width constraint.- Specified by:
getPreferredHeightin interfaceConstrainedVisual- Parameters:
width- The width by which to constrain the preferred height, or-1for no constraint.- Returns:
- The preferred height given the width constraint.
-
getPreferredSize
public Dimensions getPreferredSize()
Description copied from interface:ConstrainedVisualReturns the visual's unconstrained preferred size.- Specified by:
getPreferredSizein interfaceConstrainedVisual- Overrides:
getPreferredSizein 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:ComponentSkinShould be implemented in every subclass.The default implementation here simply returns -1 (no baseline).
- Specified by:
getBaselinein interfaceConstrainedVisual- Overrides:
getBaselinein 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
-1if this visual does not have a baseline.
-
layout
public void layout()
Description copied from interface:SkinIf 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:VisualPaints the visual.
-
isFocusable
public boolean isFocusable()
Description copied from class:ComponentSkinBy default, skins are focusable.- Specified by:
isFocusablein interfaceSkin- Overrides:
isFocusablein classComponentSkin- Returns:
false; labels are not focusable.
-
isOpaque
public boolean isOpaque()
Description copied from class:ComponentSkinBy default, skins are assumed to be opaque.- Specified by:
isOpaquein interfaceSkin- Overrides:
isOpaquein classComponentSkin- Returns:
trueif this skin is opaque;falseif 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 benullto 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 benullto 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:
trueif 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:LabelListenerCalled when a label's text has changed.- Specified by:
textChangedin 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:LabelListenerCalled when a label text maximum length has changed.- Specified by:
maximumLengthChangedin interfaceLabelListener- Parameters:
label- The label that has changed.previousMaximumLength- The previous maximum text length for the label.
-
-