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:
Modifier and Type | Class and Description |
---|---|
static class |
ImagePainter.ScaleType |
AbstractAreaPainter.Style
AbstractLayoutPainter.HorizontalAlignment, AbstractLayoutPainter.VerticalAlignment
AbstractPainter.Interpolation
Modifier and Type | Field and Description |
---|---|
private boolean |
horizontalRepeat |
private double |
imageScale |
private BufferedImage |
img
The image to draw
|
private static Logger |
LOG
Logger to use
|
private boolean |
scaleToFit |
private ImagePainter.ScaleType |
scaleType |
private boolean |
verticalRepeat |
Constructor and Description |
---|
ImagePainter()
Create a new ImagePainter.
|
ImagePainter(BufferedImage image)
Create a new ImagePainter with the specified image and the Style
Style.CENTERED
|
ImagePainter(BufferedImage image,
AbstractLayoutPainter.HorizontalAlignment horizontal,
AbstractLayoutPainter.VerticalAlignment vertical)
Create a new ImagePainter with the specified image and alignment.
|
Modifier and Type | Method and Description |
---|---|
protected void |
doPaint(Graphics2D g,
Object component,
int width,
int height)
Subclasses must implement this method and perform custom painting operations
here.
|
private void |
drawBackground(Graphics2D g,
Shape shape,
int width,
int height) |
private void |
drawBorder(Graphics2D g,
Shape shape,
int width,
int height) |
BufferedImage |
getImage()
Gets the current image used for painting.
|
double |
getImageScale()
Gets the current scaling factor used when drawing an image.
|
ImagePainter.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 image
|
void |
setScaleToFit(boolean scaleToFit) |
void |
setScaleType(ImagePainter.ScaleType scaleType) |
void |
setVerticalRepeat(boolean verticalRepeat)
Sets if the image should be repeated vertically.
|
calculateSnappedPaint, getAreaEffects, getBorderPaint, getBorderWidth, getFillPaint, getStyle, isPaintStretched, setAreaEffects, setBorderPaint, setBorderWidth, setFillPaint, setPaintStretched, setStyle
calculateLayout, getHorizontalAlignment, getInsets, getVerticalAlignment, isFillHorizontal, isFillVertical, setFillHorizontal, setFillVertical, setHorizontalAlignment, setInsets, setVerticalAlignment
clearCache, configureGraphics, getFilters, getInterpolation, isAntialiasing, isCacheable, isCacheCleared, isDirty, isInPaintContext, isVisible, paint, setAntialiasing, setCacheable, setDirty, setFilters, setInPaintContext, setInterpolation, setVisible, shouldUseCache, validate
addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, addVetoableChangeListener, clone, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, fireVetoableChange, getPropertyChangeListeners, getPropertyChangeListeners, getVetoableChangeListeners, getVetoableChangeListeners, hasPropertyChangeListeners, hasVetoableChangeListeners, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, removeVetoableChangeListener
private transient BufferedImage img
private boolean horizontalRepeat
private boolean verticalRepeat
private boolean scaleToFit
private ImagePainter.ScaleType scaleType
private double imageScale
public ImagePainter()
public ImagePainter(BufferedImage image)
image
- the image to be paintedpublic ImagePainter(BufferedImage image, AbstractLayoutPainter.HorizontalAlignment horizontal, AbstractLayoutPainter.VerticalAlignment vertical)
horizontal
- the horizontal alignmentvertical
- the vertical alignmentimage
- the image to be paintedpublic void setImage(BufferedImage image)
image
- if null, clears the image. Otherwise, this will set the
image to be painted.public BufferedImage getImage()
protected void doPaint(Graphics2D g, Object component, int width, int height)
doPaint
in class AbstractPainter<Object>
g
- The Graphics2D object in which to paintprivate void drawBackground(Graphics2D g, Shape shape, int width, int height)
private void drawBorder(Graphics2D g, Shape shape, int width, int height)
public boolean isScaleToFit()
public void setScaleToFit(boolean scaleToFit)
public ImagePainter.ScaleType getScaleType()
public void setScaleType(ImagePainter.ScaleType scaleType)
public double getImageScale()
public void setImageScale(double imageScale)
imageScale
- the new image scaling factorpublic boolean isHorizontalRepeat()
public void setHorizontalRepeat(boolean horizontalRepeat)
horizontalRepeat
- the new horizontal repeat valuepublic boolean isVerticalRepeat()
public void setVerticalRepeat(boolean verticalRepeat)
verticalRepeat
- new value for the vertical repeatprotected Shape provideShape(Graphics2D g, Object comp, int width, int height)
AbstractAreaPainter
provideShape
in class AbstractAreaPainter<Object>
g
- graphicscomp
- The Object this painter will be painted on.width
- the width to paintheight
- the height to paintWebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses