Package org.jdesktop.swingx.painter
Class ImagePainter
- java.lang.Object
-
- org.jdesktop.beans.AbstractBean
-
- org.jdesktop.swingx.painter.AbstractPainter<T>
-
- org.jdesktop.swingx.painter.AbstractLayoutPainter<T>
-
- org.jdesktop.swingx.painter.AbstractAreaPainter<Object>
-
- org.jdesktop.swingx.painter.ImagePainter
-
public class ImagePainter extends AbstractAreaPainter<Object>
A Painter instance that paints an image. Any Image is acceptable. This Painter also allows the developer to specify a "Style" -- CENTERED, TILED, SCALED, POSITIONED, and CSS_POSITIONED; with the following meanings:
- CENTERED: draws the image unscaled and positioned in the center of the component
- TILED: draws the image repeatedly across the component, filling the entire background.
- SCALED: draws the image stretched large enough (or small enough) to cover the entire component. The stretch may not preserve the aspect ratio of the original image.
- POSITIONED: draws the image at the location specified by the imageLocation property. This style of drawing will respect the imageScale property.
- CSS_POSITIONED: draws the image using CSS style background positioning. It will use the location specified by the imageLocation property. This property should contain a point with the x and y values between 0 and 1. 0,0 will put the image in the upper left hand corner, 1,1 in the lower right, and 0.5,0.5 in the center. All other values will be interpolated accordingly. For a more complete definition of the positioning algorithm see the CSS 2.1 spec.
- Author:
- Richard
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ImagePainter.ScaleType
-
Nested classes/interfaces inherited from class org.jdesktop.swingx.painter.AbstractAreaPainter
AbstractAreaPainter.Style
-
Nested classes/interfaces inherited from class org.jdesktop.swingx.painter.AbstractLayoutPainter
AbstractLayoutPainter.HorizontalAlignment, AbstractLayoutPainter.VerticalAlignment
-
Nested classes/interfaces inherited from class org.jdesktop.swingx.painter.AbstractPainter
AbstractPainter.Interpolation
-
-
Constructor Summary
Constructors Constructor Description ImagePainter()
Create a new ImagePainter.ImagePainter(BufferedImage image)
Create a new ImagePainter with the specified image and the Style Style.CENTEREDImagePainter(BufferedImage image, AbstractLayoutPainter.HorizontalAlignment horizontal, AbstractLayoutPainter.VerticalAlignment vertical)
Create a new ImagePainter with the specified image and alignment.ImagePainter(URL url)
Deprecated.(pre-1.6.2) no replacement, see Issue 1023ImagePainter(URL url, AbstractLayoutPainter.HorizontalAlignment horizontal, AbstractLayoutPainter.VerticalAlignment vertical)
Deprecated.(pre-1.6.2) no replacement, see Issue 1023
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected void
doPaint(Graphics2D g, Object component, int width, int height)
Subclasses must implement this method and perform custom painting operations here.BufferedImage
getImage()
Gets the current image used for painting.double
getImageScale()
Gets the current scaling factor used when drawing an image.String
getImageString()
Deprecated.(pre-1.6.2) no replacement, see Issue 1023ImagePainter.ScaleType
getScaleType()
boolean
isHorizontalRepeat()
Indicates if the image will be repeated horizontally.boolean
isScaleToFit()
boolean
isVerticalRepeat()
Indicates if the image will be repeated vertically.protected Shape
provideShape(Graphics2D g, Object comp, int width, int height)
Returns the outline shape of this painter.void
setHorizontalRepeat(boolean horizontalRepeat)
Sets if the image should be repeated horizontally.void
setImage(BufferedImage image)
Sets the image to paint with.void
setImageScale(double imageScale)
Sets the scaling factor used when drawing the imagevoid
setImageString(String imageString)
Deprecated.(pre-1.6.2) no replacement, see Issue 1023void
setScaleToFit(boolean scaleToFit)
void
setScaleType(ImagePainter.ScaleType scaleType)
void
setVerticalRepeat(boolean verticalRepeat)
Sets if the image should be repeated vertically.-
Methods inherited from class org.jdesktop.swingx.painter.AbstractAreaPainter
getAreaEffects, getBorderPaint, getBorderWidth, getFillPaint, getStyle, isPaintStretched, setAreaEffects, setBorderPaint, setBorderWidth, setFillPaint, setPaintStretched, setStyle
-
Methods inherited from class org.jdesktop.swingx.painter.AbstractLayoutPainter
calculateLayout, getHorizontalAlignment, getInsets, getVerticalAlignment, isFillHorizontal, isFillVertical, setFillHorizontal, setFillVertical, setHorizontalAlignment, setInsets, setVerticalAlignment
-
Methods inherited from class org.jdesktop.swingx.painter.AbstractPainter
clearCache, configureGraphics, getFilters, getInterpolation, isAntialiasing, isCacheable, isDirty, isVisible, paint, setAntialiasing, setCacheable, setDirty, setFilters, setInterpolation, setVisible, shouldUseCache, validate
-
Methods inherited from class org.jdesktop.beans.AbstractBean
addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, addVetoableChangeListener, clone, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, fireVetoableChange, getPropertyChangeListeners, getPropertyChangeListeners, getVetoableChangeListeners, getVetoableChangeListeners, hasPropertyChangeListeners, hasVetoableChangeListeners, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, removeVetoableChangeListener
-
-
-
-
Constructor Detail
-
ImagePainter
public ImagePainter()
Create a new ImagePainter. By default there is no image, and the alignment is centered.
-
ImagePainter
public ImagePainter(BufferedImage image)
Create a new ImagePainter with the specified image and the Style Style.CENTERED- Parameters:
image
- the image to be painted
-
ImagePainter
public ImagePainter(BufferedImage image, AbstractLayoutPainter.HorizontalAlignment horizontal, AbstractLayoutPainter.VerticalAlignment vertical)
Create a new ImagePainter with the specified image and alignment.- Parameters:
horizontal
- the horizontal alignmentvertical
- the vertical alignmentimage
- the image to be painted
-
ImagePainter
@Deprecated public ImagePainter(URL url) throws IOException
Deprecated.(pre-1.6.2) no replacement, see Issue 1023- Throws:
IOException
-
ImagePainter
@Deprecated public ImagePainter(URL url, AbstractLayoutPainter.HorizontalAlignment horizontal, AbstractLayoutPainter.VerticalAlignment vertical) throws IOException
Deprecated.(pre-1.6.2) no replacement, see Issue 1023- Throws:
IOException
-
-
Method Detail
-
setImage
public void setImage(BufferedImage image)
Sets the image to paint with.- Parameters:
image
- if null, clears the image. Otherwise, this will set the image to be painted.
-
getImage
public BufferedImage getImage()
Gets the current image used for painting.- Returns:
- the image used for painting
-
doPaint
protected void doPaint(Graphics2D g, Object component, int width, int height)
Subclasses must implement this method and perform custom painting operations here.- Specified by:
doPaint
in classAbstractPainter<Object>
- Parameters:
g
- The Graphics2D object in which to paint
-
setScaleToFit
public void setScaleToFit(boolean scaleToFit)
-
isScaleToFit
public boolean isScaleToFit()
-
setImageScale
public void setImageScale(double imageScale)
Sets the scaling factor used when drawing the image- Parameters:
imageScale
- the new image scaling factor
-
getImageScale
public double getImageScale()
Gets the current scaling factor used when drawing an image.- Returns:
- the current scaling factor
-
getImageString
@Deprecated public String getImageString()
Deprecated.(pre-1.6.2) no replacement, see Issue 1023Used by the persistence mechanism.
-
setImageString
@Deprecated public void setImageString(String imageString)
Deprecated.(pre-1.6.2) no replacement, see Issue 1023Used by the persistence mechanism.
-
isHorizontalRepeat
public boolean isHorizontalRepeat()
Indicates if the image will be repeated horizontally.- Returns:
- if the image will be repeated horizontally
-
setHorizontalRepeat
public void setHorizontalRepeat(boolean horizontalRepeat)
Sets if the image should be repeated horizontally.- Parameters:
horizontalRepeat
- the new horizontal repeat value
-
isVerticalRepeat
public boolean isVerticalRepeat()
Indicates if the image will be repeated vertically.- Returns:
- if the image will be repeated vertically
-
setVerticalRepeat
public void setVerticalRepeat(boolean verticalRepeat)
Sets if the image should be repeated vertically.- Parameters:
verticalRepeat
- new value for the vertical repeat
-
provideShape
protected Shape provideShape(Graphics2D g, Object comp, int width, int height)
Description copied from class:AbstractAreaPainter
Returns the outline shape of this painter. Subclasses must implement this method. This shape will be used for filling, stroking, and clipping.- Specified by:
provideShape
in classAbstractAreaPainter<Object>
- Parameters:
g
- graphicscomp
- The Object this painter will be painted on.width
- the width to paintheight
- the height to paint- Returns:
- the outline shape of this painter
-
getScaleType
public ImagePainter.ScaleType getScaleType()
-
setScaleType
public void setScaleType(ImagePainter.ScaleType scaleType)
-
-