Package org.apache.pivot.wtk.skin
Class ImageViewSkin
- java.lang.Object
-
- org.apache.pivot.wtk.skin.ComponentSkin
-
- org.apache.pivot.wtk.skin.ImageViewSkin
-
- All Implemented Interfaces:
ComponentKeyListener
,ComponentListener
,ComponentMouseButtonListener
,ComponentMouseListener
,ComponentMouseWheelListener
,ComponentStateListener
,ComponentTooltipListener
,ConstrainedVisual
,ImageViewListener
,Skin
,Visual
public class ImageViewSkin extends ComponentSkin implements ImageViewListener
Image view skin.TODO Add a rotation (float) style.
-
-
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.ImageViewListener
ImageViewListener.Adapter, ImageViewListener.Listeners
-
-
Constructor Summary
Constructors Constructor Description ImageViewSkin()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
asynchronousChanged(ImageView imageView)
Called when an image view's asynchronous flag has changed.java.awt.Color
getBackgroundColor()
int
getBaseline(int width, int height)
Should be implemented in every subclass.boolean
getFill()
HorizontalAlignment
getHorizontalAlignment()
float
getOpacity()
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.boolean
getPreserveAspectRatio()
VerticalAlignment
getVerticalAlignment()
void
imageChanged(ImageView imageView, Image previousImage)
Called when an image view's image has changed.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
paint(java.awt.Graphics2D graphics)
Paints the visual.void
setBackgroundColor(java.awt.Color backgroundColor)
Sets the color that is painted behind the image.void
setBackgroundColor(java.lang.String backgroundColor)
Sets the color that is painted behind the image.void
setFill(boolean fill)
Sets a boolean indicating whether the image will be scaled to fit the space in which it is placed.void
setHorizontalAlignment(HorizontalAlignment horizontalAlignment)
Sets the horizontal alignment of the image.void
setOpacity(float opacity)
Sets the opacity of the image.void
setOpacity(java.lang.Number opacity)
Sets the opacity of the image.void
setPreserveAspectRatio(boolean preserveAspectRatio)
Sets a boolean indicating whether, when the image is scaled, its aspect ratio is preserved.void
setVerticalAlignment(VerticalAlignment verticalAlignment)
Sets the vertical alignment of the image.-
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 final boolean isFocusable()
Description copied from class:ComponentSkin
By default, skins are focusable.- Specified by:
isFocusable
in interfaceSkin
- Overrides:
isFocusable
in classComponentSkin
- Returns:
false
; image views are not focusable.
-
isOpaque
public final 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.
-
getBackgroundColor
public final java.awt.Color getBackgroundColor()
- Returns:
- The color that is painted behind the image.
-
setBackgroundColor
public final void setBackgroundColor(java.awt.Color backgroundColor)
Sets the color that is painted behind the image.- Parameters:
backgroundColor
- The new color for behind the image.
-
setBackgroundColor
public final void setBackgroundColor(java.lang.String backgroundColor)
Sets the color that is painted behind the image.- Parameters:
backgroundColor
- Any of the color values recognized by Pivot.
-
getOpacity
public final float getOpacity()
- Returns:
- The opacity of the image, in [0,1].
-
setOpacity
public final void setOpacity(float opacity)
Sets the opacity of the image.- Parameters:
opacity
- A number between 0 (transparent) and 1 (opaque), inclusive.
-
setOpacity
public final void setOpacity(java.lang.Number opacity)
Sets the opacity of the image.- Parameters:
opacity
- A number between 0 (transparent) and 1 (opaque), inclusive.
-
getHorizontalAlignment
public final HorizontalAlignment getHorizontalAlignment()
- Returns:
- The horizontal alignment of the image.
-
setHorizontalAlignment
public final void setHorizontalAlignment(HorizontalAlignment horizontalAlignment)
Sets the horizontal alignment of the image. Ignored if thefill
style is true.- Parameters:
horizontalAlignment
- The new alignment value.
-
getVerticalAlignment
public final VerticalAlignment getVerticalAlignment()
- Returns:
- The vertical alignment of the image.
-
setVerticalAlignment
public final void setVerticalAlignment(VerticalAlignment verticalAlignment)
Sets the vertical alignment of the image. Ignored if thefill
style is true.- Parameters:
verticalAlignment
- The new alignment value.
-
getFill
public final boolean getFill()
- Returns:
- A boolean indicating whether the image will be scaled to fit the space in which it is placed.
-
setFill
public final void setFill(boolean fill)
Sets a boolean indicating whether the image will be scaled to fit the space in which it is placed. Note that for scaling to occur, the ImageView must specify a preferred size or be placed in a container that constrains its size.- Parameters:
fill
- The new fill flag value.
-
getPreserveAspectRatio
public final boolean getPreserveAspectRatio()
- Returns:
- A boolean indicating whether, when the image is scaled, its aspect ratio is preserved.
-
setPreserveAspectRatio
public final void setPreserveAspectRatio(boolean preserveAspectRatio)
Sets a boolean indicating whether, when the image is scaled, its aspect ratio is preserved. Ignored if thefill
style is false.- Parameters:
preserveAspectRatio
- The new flag value.
-
imageChanged
public void imageChanged(ImageView imageView, Image previousImage)
Description copied from interface:ImageViewListener
Called when an image view's image has changed.- Specified by:
imageChanged
in interfaceImageViewListener
- Parameters:
imageView
- The image view whose image has changed.previousImage
- The previous image associated with this image view.
-
asynchronousChanged
public void asynchronousChanged(ImageView imageView)
Description copied from interface:ImageViewListener
Called when an image view's asynchronous flag has changed.- Specified by:
asynchronousChanged
in interfaceImageViewListener
- Parameters:
imageView
- The image view whose asynchronous flag has changed.
-
-