org.jdesktop.swingx.painter
Class ImagePainter<T>

java.lang.Object
  extended by org.jdesktop.beans.AbstractBean
      extended by org.jdesktop.swingx.painter.AbstractPainter<T>
          extended by org.jdesktop.swingx.painter.AbstractLayoutPainter<T>
              extended by org.jdesktop.swingx.painter.AbstractAreaPainter<T>
                  extended by org.jdesktop.swingx.painter.ImagePainter<T>
All Implemented Interfaces:
Painter<T>

public class ImagePainter<T>
extends AbstractAreaPainter<T>

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:


Nested Class Summary
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
ImagePainter()
          Create a new ImagePainter.
ImagePainter(java.awt.image.BufferedImage image)
          Create a new ImagePainter with the specified image and the Style Style.CENTERED
ImagePainter(java.awt.image.BufferedImage image, AbstractLayoutPainter.HorizontalAlignment horizontal, AbstractLayoutPainter.VerticalAlignment vertical)
          Create a new ImagePainter with the specified image and alignment.
ImagePainter(java.net.URL url)
           
ImagePainter(java.net.URL url, AbstractLayoutPainter.HorizontalAlignment horizontal, AbstractLayoutPainter.VerticalAlignment vertical)
           
 
Method Summary
 void doPaint(java.awt.Graphics2D g, T component, int width, int height)
          Subclasses must implement this method and perform custom painting operations here.
 java.awt.image.BufferedImage getImage()
          Gets the current image used for painting.
 double getImageScale()
          Gets the current scaling factor used when drawing an image.
 java.lang.String getImageString()
          Used by the persistence mechanism.
 ImagePainter.ScaleType getScaleType()
           
 boolean isHorizontalRepeat()
          Indicates if the image will be repeated horizontally.
 boolean isVerticalRepeat()
          Indicates if the image will be repeated vertically.
 java.awt.Shape provideShape(java.awt.Graphics2D g, T 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(java.awt.image.BufferedImage image)
          Sets the image to paint with.
 void setImageScale(double imageScale)
          Sets the scaling factor used when drawing the image
 void setImageString(java.lang.String imageString)
          Used by the persistence mechanism.
 void 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
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ImagePainter

public ImagePainter()
Create a new ImagePainter. By default there is no image, and the alignment is centered.


ImagePainter

public ImagePainter(java.awt.image.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(java.awt.image.BufferedImage image,
                    AbstractLayoutPainter.HorizontalAlignment horizontal,
                    AbstractLayoutPainter.VerticalAlignment vertical)
Create a new ImagePainter with the specified image and alignment.

Parameters:
horizontal - the horizontal alignment
vertical - the vertical alignment
image - the image to be painted

ImagePainter

public ImagePainter(java.net.URL url)
             throws java.io.IOException
Throws:
java.io.IOException

ImagePainter

public ImagePainter(java.net.URL url,
                    AbstractLayoutPainter.HorizontalAlignment horizontal,
                    AbstractLayoutPainter.VerticalAlignment vertical)
             throws java.io.IOException
Throws:
java.io.IOException
Method Detail

setImage

public void setImage(java.awt.image.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 java.awt.image.BufferedImage getImage()
Gets the current image used for painting.

Returns:
the image used for painting

doPaint

public void doPaint(java.awt.Graphics2D g,
                    T component,
                    int width,
                    int height)
Description copied from class: AbstractPainter
Subclasses must implement this method and perform custom painting operations here.

Specified by:
doPaint in class AbstractPainter<T>
Parameters:
g - The Graphics2D object in which to paint

setScaleToFit

public void setScaleToFit(boolean scaleToFit)

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

public java.lang.String getImageString()
Used by the persistence mechanism.


setImageString

public void setImageString(java.lang.String imageString)
Used 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

public java.awt.Shape provideShape(java.awt.Graphics2D g,
                                   T 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 class AbstractAreaPainter<T>
Parameters:
g - graphics
comp - The Object this painter will be painted on.
width - the width to paint
height - the height to paint
Returns:
the outline shape of this painter

getScaleType

public ImagePainter.ScaleType getScaleType()

setScaleType

public void setScaleType(ImagePainter.ScaleType scaleType)