Class TextPaneSkin
- java.lang.Object
-
- org.apache.pivot.wtk.skin.ComponentSkin
-
- org.apache.pivot.wtk.skin.ContainerSkin
-
- org.apache.pivot.wtk.skin.TextPaneSkin
-
- All Implemented Interfaces:
ComponentKeyListener
,ComponentListener
,ComponentMouseButtonListener
,ComponentMouseListener
,ComponentMouseWheelListener
,ComponentStateListener
,ComponentTooltipListener
,ConstrainedVisual
,ContainerListener
,ContainerMouseListener
,Skin
,TextPane.Skin
,TextPaneListener
,TextPaneSelectionListener
,Visual
- Direct Known Subclasses:
TerraTextPaneSkin
public class TextPaneSkin extends ContainerSkin implements TextPane.Skin, TextPaneListener, TextPaneSelectionListener
Text pane skin.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.apache.pivot.wtk.skin.ContainerSkin
ContainerSkin.IndexFocusTraversalPolicy
-
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.ContainerListener
ContainerListener.Adapter, ContainerListener.Listeners
-
Nested classes/interfaces inherited from interface org.apache.pivot.wtk.ContainerMouseListener
ContainerMouseListener.Adapter, ContainerMouseListener.Listeners
-
Nested classes/interfaces inherited from interface org.apache.pivot.wtk.TextPaneListener
TextPaneListener.Adapter, TextPaneListener.Listeners
-
Nested classes/interfaces inherited from interface org.apache.pivot.wtk.TextPaneSelectionListener
TextPaneSelectionListener.Listeners
-
-
Constructor Summary
Constructors Constructor Description TextPaneSkin()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
documentChanged(TextPane textPane, Document previousDocument)
Called when a text pane's document has changed.void
editableChanged(TextPane textPane)
Called when a text pane's editable state has changed.void
enabledChanged(Component component)
Called when a component's enabled state has changed.void
focusedChanged(Component component, Component obverseComponent)
Called when a component's focused state has changed.boolean
getAcceptsTab()
Gets current value of style that determines the behavior ofTAB
andCtrl-TAB
characters.int
getBaseline(int width, int height)
Should be implemented in every subclass.Bounds
getCharacterBounds(int offset)
Returns the bounds of the character at a given offset within the document.java.awt.Color
getColor()
boolean
getDoingCaretCalculations()
java.awt.Font
getFont()
java.awt.Color
getInactiveColor()
java.awt.Color
getInactiveSelectionBackgroundColor()
java.awt.Color
getInactiveSelectionColor()
int
getInsertionPoint(int x, int y)
Returns the insertion point for a given location.Insets
getMargin()
int
getNextInsertionPoint(int x, int from, TextPane.ScrollDirection direction)
Returns the next insertion point given an x coordinate and a character offset.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.int
getRowAt(int offset)
Returns the row index of the character at a given offset within the document.int
getRowCount()
java.awt.Color
getSelectionBackgroundColor()
java.awt.Color
getSelectionColor()
int
getTabWidth()
TextInputMethodListener
getTextInputMethodListener()
Returns the input method listener for this component.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
keyPressed(Component component, int keyCode, Keyboard.KeyLocation keyLocation)
Keyboard handling (Tab key or Shift Tab).boolean
keyTyped(Component component, char character)
Called when a key has been typed.void
layout()
If the component on which the skin is installed is a container, lays out the container's children.boolean
mouseClick(Component component, Mouse.Button button, int x, int y, int count)
Called when a mouse button is clicked over a component.boolean
mouseDown(Component component, Mouse.Button button, int x, int y)
Called when a mouse button is pressed over a component.boolean
mouseMove(Component component, int x, int y)
Called when the mouse is moved over a component.boolean
mouseUp(Component component, Mouse.Button button, int x, int y)
Called when a mouse button is released over a component.void
paint(java.awt.Graphics2D graphics)
Paints the visual.void
selectionChanged(TextPane textPane, int previousSelectionStart, int previousSelectionLength)
Called when a text pane's selection state has changed.void
setAcceptsTab(boolean acceptsTabValue)
Sets current value of style that determines the behavior ofTAB
andCtrl-TAB
characters.void
setColor(java.awt.Color colorValue)
Sets the foreground color of the text.void
setColor(java.lang.String colorString)
Sets the foreground color of the text.void
setFont(java.awt.Font newFont)
Sets the font of the text.void
setFont(java.lang.String fontString)
Sets the font of the text.void
setFont(Dictionary<java.lang.String,?> fontDictionary)
Sets the font of the text.void
setInactiveColor(java.awt.Color inactiveColorValue)
void
setInactiveColor(java.lang.String inactiveColorString)
void
setInactiveSelectionBackgroundColor(java.awt.Color inactiveSelectionBackgroundColorValue)
void
setInactiveSelectionBackgroundColor(java.lang.String inactiveSelectionBackgroundColorString)
void
setInactiveSelectionColor(java.awt.Color inactiveSelectionColorValue)
void
setInactiveSelectionColor(java.lang.String inactiveSelectionColorString)
void
setMargin(int marginValue)
Sets the amount of space between the edge of the TextPane and its Document.void
setMargin(java.lang.Number marginValue)
Sets the amount of space between the edge of the TextPane and its Document.void
setMargin(java.lang.String marginString)
Sets the amount of space between the edge of the TextPane and its Document.void
setMargin(Dictionary<java.lang.String,?> marginDictionary)
Sets the amount of space between the edge of the TextPane and its Document.void
setMargin(Sequence<?> marginSequence)
Sets the amount of space between the edge of the TextPane and its Document.void
setMargin(Insets marginValue)
Sets the amount of space between the edge of the TextPane and its Document.void
setSelectionBackgroundColor(java.awt.Color selectionBackgroundColorValue)
void
setSelectionBackgroundColor(java.lang.String selectionBackgroundColorString)
void
setSelectionColor(java.awt.Color selectionColorValue)
void
setSelectionColor(java.lang.String selectionColorString)
void
setTabWidth(int tabWidthValue)
void
setWrapText(boolean wrapTextValue)
-
Methods inherited from class org.apache.pivot.wtk.skin.ContainerSkin
componentInserted, componentMoved, componentsRemoved, focusTraversalPolicyChanged, getBackgroundColor, getBackgroundPaint, isOpaque, mouseDown, mouseMove, mouseUp, mouseWheel, setBackgroundColor, setBackgroundColor, setBackgroundColor, setBackgroundPaint, setBackgroundPaint, setBackgroundPaint
-
Methods inherited from class org.apache.pivot.wtk.skin.ComponentSkin
colorFromObject, colorFromObject, colorFromObject, colorFromObject, currentTheme, cursorChanged, decodeFont, defaultBackgroundColor, defaultForegroundColor, dragSourceChanged, dropTargetChanged, fontFromObject, getBaseline, getColor, getComponent, getFocusRectangleStroke, getHeight, getSize, getThemeFont, getWidth, heightLimitsChanged, invalidateComponent, keyReleased, locationChanged, menuHandlerChanged, mouseOut, mouseOver, 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 classContainerSkin
- Parameters:
component
- The component to which the skin is being attached.
-
isFocusable
public boolean isFocusable()
Description copied from class:ComponentSkin
By default, skins are focusable.- Specified by:
isFocusable
in interfaceSkin
- Overrides:
isFocusable
in classContainerSkin
- Returns:
false
; by default, containers are not focusable.
-
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
- Overrides:
getPreferredWidth
in classContainerSkin
- 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
- Overrides:
getPreferredHeight
in classContainerSkin
- 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.- Specified by:
paint
in interfaceVisual
- Overrides:
paint
in classContainerSkin
- Parameters:
graphics
- The graphics context in which to paint the visual.
-
getInsertionPoint
public int getInsertionPoint(int x, int y)
Description copied from interface:TextPane.Skin
Returns the insertion point for a given location.- Specified by:
getInsertionPoint
in interfaceTextPane.Skin
- Parameters:
x
- The X-coordinate of the location to check.y
- The Y-coordinate of the location.- Returns:
- The insertion point for the given location.
-
getNextInsertionPoint
public int getNextInsertionPoint(int x, int from, TextPane.ScrollDirection direction)
Description copied from interface:TextPane.Skin
Returns the next insertion point given an x coordinate and a character offset.- Specified by:
getNextInsertionPoint
in interfaceTextPane.Skin
- Parameters:
x
- The current X-coordinate to move from.from
- The current character offset to move from.direction
- The direction to move from the current location.- Returns:
- The next insertion point.
-
getRowAt
public int getRowAt(int offset)
Description copied from interface:TextPane.Skin
Returns the row index of the character at a given offset within the document.- Specified by:
getRowAt
in interfaceTextPane.Skin
- Parameters:
offset
- The character offset to check.- Returns:
- The row index of the character at the given offset.
-
getRowCount
public int getRowCount()
- Specified by:
getRowCount
in interfaceTextPane.Skin
- Returns:
- The total number of rows in the document.
-
getCharacterBounds
public Bounds getCharacterBounds(int offset)
Description copied from interface:TextPane.Skin
Returns the bounds of the character at a given offset within the document.- Specified by:
getCharacterBounds
in interfaceTextPane.Skin
- Parameters:
offset
- The index of the character we want the bounds for.- Returns:
- The bounds of the character at the given offset.
-
getDoingCaretCalculations
public boolean getDoingCaretCalculations()
- Returns:
- Current flag value that indicates we are doing caret location calculations.
-
getAcceptsTab
public boolean getAcceptsTab()
Gets current value of style that determines the behavior ofTAB
andCtrl-TAB
characters.- Returns:
true
ifTAB
inserts an appropriate number of spaces, whileCtrl-TAB
shifts focus to next component.false
(default) meansTAB
shifts focus andCtrl-TAB
inserts spaces.
-
setAcceptsTab
public void setAcceptsTab(boolean acceptsTabValue)
Sets current value of style that determines the behavior ofTAB
andCtrl-TAB
characters.- Parameters:
acceptsTabValue
-true
ifTAB
inserts an appropriate number of spaces, whileCtrl-TAB
shifts focus to next component.false
(default) meansTAB
shifts focus andCtrl-TAB
inserts spaces.
-
getTabWidth
public int getTabWidth()
- Specified by:
getTabWidth
in interfaceTextPane.Skin
- Returns:
- The current setting of the "tabWidth" style (so "setText" uses the same value as Ctrl-Tab from user).
-
setTabWidth
public void setTabWidth(int tabWidthValue)
-
getFont
public java.awt.Font getFont()
- Returns:
- The font of the text.
-
setFont
public void setFont(java.awt.Font newFont)
Sets the font of the text.- Parameters:
newFont
- The new font for all the text.
-
setFont
public final void setFont(java.lang.String fontString)
Sets the font of the text.- Parameters:
fontString
- Afont specification
-
setFont
public final void setFont(Dictionary<java.lang.String,?> fontDictionary)
Sets the font of the text.- Parameters:
fontDictionary
- A dictionarydescribing a font
-
getColor
public java.awt.Color getColor()
- Returns:
- The foreground color of the text.
-
setColor
public void setColor(java.awt.Color colorValue)
Sets the foreground color of the text.- Parameters:
colorValue
- The new text color.
-
setColor
public final void setColor(java.lang.String colorString)
Sets the foreground color of the text.- Parameters:
colorString
- Any of the color values recognized by Pivot.
-
getInactiveColor
public java.awt.Color getInactiveColor()
-
setInactiveColor
public void setInactiveColor(java.awt.Color inactiveColorValue)
-
setInactiveColor
public final void setInactiveColor(java.lang.String inactiveColorString)
-
getSelectionColor
public java.awt.Color getSelectionColor()
-
setSelectionColor
public void setSelectionColor(java.awt.Color selectionColorValue)
-
setSelectionColor
public final void setSelectionColor(java.lang.String selectionColorString)
-
getSelectionBackgroundColor
public java.awt.Color getSelectionBackgroundColor()
-
setSelectionBackgroundColor
public void setSelectionBackgroundColor(java.awt.Color selectionBackgroundColorValue)
-
setSelectionBackgroundColor
public final void setSelectionBackgroundColor(java.lang.String selectionBackgroundColorString)
-
getInactiveSelectionColor
public java.awt.Color getInactiveSelectionColor()
-
setInactiveSelectionColor
public void setInactiveSelectionColor(java.awt.Color inactiveSelectionColorValue)
-
setInactiveSelectionColor
public final void setInactiveSelectionColor(java.lang.String inactiveSelectionColorString)
-
getInactiveSelectionBackgroundColor
public java.awt.Color getInactiveSelectionBackgroundColor()
-
setInactiveSelectionBackgroundColor
public void setInactiveSelectionBackgroundColor(java.awt.Color inactiveSelectionBackgroundColorValue)
-
setInactiveSelectionBackgroundColor
public final void setInactiveSelectionBackgroundColor(java.lang.String inactiveSelectionBackgroundColorString)
-
getMargin
public Insets getMargin()
- Returns:
- The amount of space between the edge of the TextPane and its Document.
-
setMargin
public void setMargin(Insets marginValue)
Sets the amount of space between the edge of the TextPane and its Document.- Parameters:
marginValue
- The new set of margin values.
-
setMargin
public final void setMargin(Dictionary<java.lang.String,?> marginDictionary)
Sets the amount of space between the edge of the TextPane and its Document.- Parameters:
marginDictionary
- A dictionary with keys in the set {top, left, bottom, right}.
-
setMargin
public final void setMargin(Sequence<?> marginSequence)
Sets the amount of space between the edge of the TextPane and its Document.- Parameters:
marginSequence
- A sequence with values in the order [top, left, bottom, right].
-
setMargin
public final void setMargin(int marginValue)
Sets the amount of space between the edge of the TextPane and its Document.- Parameters:
marginValue
- The single margin value for all edges.
-
setMargin
public final void setMargin(java.lang.Number marginValue)
Sets the amount of space between the edge of the TextPane and its Document.- Parameters:
marginValue
- The new single margin value for all the edges.
-
setMargin
public final void setMargin(java.lang.String marginString)
Sets the amount of space between the edge of the TextPane and its Document.- Parameters:
marginString
- A string containing an integer or a JSON dictionary with keys left, top, bottom, and/or right.
-
getWrapText
public boolean getWrapText()
-
setWrapText
public void setWrapText(boolean wrapTextValue)
-
mouseMove
public boolean mouseMove(Component component, int x, int y)
Description copied from interface:ComponentMouseListener
Called when the mouse is moved over a component.- Specified by:
mouseMove
in interfaceComponentMouseListener
- Overrides:
mouseMove
in classComponentSkin
- Parameters:
component
- Component that is under the mouse.x
- X position of the mouse.y
- Y position of the mouse.- Returns:
true
to consume the event;false
to allow it to propagate (default return).
-
mouseDown
public boolean mouseDown(Component component, Mouse.Button button, int x, int y)
Description copied from interface:ComponentMouseButtonListener
Called when a mouse button is pressed over a component.- Specified by:
mouseDown
in interfaceComponentMouseButtonListener
- Overrides:
mouseDown
in classComponentSkin
- Parameters:
component
- Component that is under the mouse pointer.button
- Which mouse button was pressed.x
- X position of the mouse.y
- Y position of the mouse.- Returns:
true
to consume the event;false
to allow it to propagate (default).
-
mouseUp
public boolean mouseUp(Component component, Mouse.Button button, int x, int y)
Description copied from interface:ComponentMouseButtonListener
Called when a mouse button is released over a component.- Specified by:
mouseUp
in interfaceComponentMouseButtonListener
- Overrides:
mouseUp
in classComponentSkin
- Parameters:
component
- Component user the mouse pointer.button
- Which mouse button that was released.x
- X position of the mouse.y
- Y position of the mouse.- Returns:
true
to consume the event;false
to allow it to propagate (default).
-
mouseClick
public boolean mouseClick(Component component, Mouse.Button button, int x, int y, int count)
Description copied from interface:ComponentMouseButtonListener
Called when a mouse button is clicked over a component.- Specified by:
mouseClick
in interfaceComponentMouseButtonListener
- Overrides:
mouseClick
in classComponentSkin
- Parameters:
component
- Component user the mouse pointer.button
- Which mouse button was clicked.x
- X position of the mouse.y
- Y position of the mouse.count
- Number of clicks (1 = single click, 2 = double click, etc.).- Returns:
true
to consume the event;false
to allow it to propagate (default).
-
keyTyped
public boolean keyTyped(Component component, char character)
Description copied from interface:ComponentKeyListener
Called when a key has been typed.- Specified by:
keyTyped
in interfaceComponentKeyListener
- Overrides:
keyTyped
in classComponentSkin
- Parameters:
component
- Component that has the focus, that is receiving this key.character
- The decoded character that was typed.- Returns:
true
to consume the event;false
to allow it to propagate.
-
keyPressed
public boolean keyPressed(Component component, int keyCode, Keyboard.KeyLocation keyLocation)
Description copied from class:ComponentSkin
Keyboard handling (Tab key or Shift Tab).- Specified by:
keyPressed
in interfaceComponentKeyListener
- Overrides:
keyPressed
in classComponentSkin
- Parameters:
component
- Component that has the focus.keyCode
- The key code for the key that was pressed.keyLocation
- Location value for the key (left or right for shift keys, etc.).- Returns:
true
to consume the event;false
to allow it to propagate.
-
enabledChanged
public void enabledChanged(Component component)
Description copied from interface:ComponentStateListener
Called when a component's enabled state has changed.Called both when the component is enabled and when it is disabled. The component's
enabled
flag has already been set when this method is called so the new state can be determined by calling theComponent.isEnabled()
method.- Specified by:
enabledChanged
in interfaceComponentStateListener
- Overrides:
enabledChanged
in classComponentSkin
- Parameters:
component
- The component whose enabled state is changing.
-
focusedChanged
public void focusedChanged(Component component, Component obverseComponent)
Description copied from interface:ComponentStateListener
Called when a component's focused state has changed.This will be called both when a component gains focus and when it loses focus. The currently focused component has already been set when this method is called, so that the new state of the component can be determined by calling the
Component.isFocused()
method.- Specified by:
focusedChanged
in interfaceComponentStateListener
- Overrides:
focusedChanged
in classComponentSkin
- Parameters:
component
- The component that is either gaining focus or the one that previously had focus and is now losing it.obverseComponent
- If the component is gaining focus, this is the component that is losing focus. If the component is losing focus this is the component that is gaining the focus instead.
-
documentChanged
public void documentChanged(TextPane textPane, Document previousDocument)
Description copied from interface:TextPaneListener
Called when a text pane's document has changed.- Specified by:
documentChanged
in interfaceTextPaneListener
- Parameters:
textPane
- The text pane that changed.previousDocument
- What the document used to be.
-
editableChanged
public void editableChanged(TextPane textPane)
Description copied from interface:TextPaneListener
Called when a text pane's editable state has changed.- Specified by:
editableChanged
in interfaceTextPaneListener
- Parameters:
textPane
- The source of this event.
-
selectionChanged
public void selectionChanged(TextPane textPane, int previousSelectionStart, int previousSelectionLength)
Description copied from interface:TextPaneSelectionListener
Called when a text pane's selection state has changed.- Specified by:
selectionChanged
in interfaceTextPaneSelectionListener
- Parameters:
textPane
- The source of this event.previousSelectionStart
- The offset where the selection used to start.previousSelectionLength
- What the selection length was previously.
-
getTextInputMethodListener
public TextInputMethodListener getTextInputMethodListener()
Description copied from class:ComponentSkin
Returns the input method listener for this component.Should be overridden by any component's skin that wants to handle Input Method events (such as
TextInput
).- Overrides:
getTextInputMethodListener
in classComponentSkin
- Returns:
- The input method listener (if any) for this component.
-
-