com.miginfocom.util.gfx
Class SlicedImage

java.lang.Object
  extended by com.miginfocom.util.gfx.ScaleableImage
      extended by com.miginfocom.util.gfx.SlicedImage
All Implemented Interfaces:
java.awt.Transparency, java.io.Serializable, javax.swing.Icon
Direct Known Subclasses:
ImageBorder

public class SlicedImage
extends ScaleableImage
implements java.io.Serializable

Slices an image into 9 parts (3x3), normally seen in themes for painting borders and such. The middle slice can optionally be painted. Supports differents slice draw modes, e.g. TYPE_STRETCH, and draw optimizations, e.g. OPT_BOTTOM_RIGHT.

See Also:
Serialized Form

Nested Class Summary
protected static class SlicedImage.ImageSlice
           
 
Field Summary
protected  SlicedImage.ImageSlice[] slices
          The slices.
 
Fields inherited from interface java.awt.Transparency
BITMASK, OPAQUE, TRANSLUCENT
 
Constructor Summary
SlicedImage(SliceSpec spec)
          Constructor
SlicedImage(SliceSpec spec, XtdImage image)
          Constructor
 
Method Summary
protected  void createSlices(java.awt.image.BufferedImage image)
          Creates the slices and store the in slices.
 void drawImage(java.awt.Graphics2D g2, int x, int y, int width, int height)
          Draws the image by drawing the slices.
 boolean equals(java.lang.Object o)
           
 void flush()
          Releases the source image.
 java.awt.Dimension getCenterSize()
          Returns the size of the center slice.
 int getIconHeight()
           
 int getIconWidth()
           
protected  int[] getSliceDimSz(int bnds, int stI, int enI)
          Returns the sizes of the slices in one dimension
 SliceSpec getSliceSpec()
          Returns the slice specification.
 int getTransparency()
          Returns the transparency of the contained image or Transparency.TRANSLUCENT if the image is currently set to null.
 XtdImage getXtdImage()
          Returns the source image, it it hasn't been flushed in which case null is returned.
 void paintIcon(java.awt.Component c, java.awt.Graphics g, int x, int y)
           
 void setXtdImage(XtdImage xtdImage)
          Sets the image to cut in slices.
 
Methods inherited from class com.miginfocom.util.gfx.ScaleableImage
drawImage
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

slices

protected transient SlicedImage.ImageSlice[] slices
The slices. If no image it's null. Slices not to paint will be null.

Constructor Detail

SlicedImage

public SlicedImage(SliceSpec spec)
Constructor

Parameters:
spec - The spicifiaction on how the image, that is set later, will be sliced and painted.
The image can be set later with setXtdImage(XtdImage). Not null.

SlicedImage

public SlicedImage(SliceSpec spec,
                   XtdImage image)
Constructor

Parameters:
spec - The spicifiaction on how the image, that is set later, will be sliced and painted. Not null.
image - The image to slice.
Method Detail

drawImage

public void drawImage(java.awt.Graphics2D g2,
                      int x,
                      int y,
                      int width,
                      int height)
Draws the image by drawing the slices.

Specified by:
drawImage in class ScaleableImage
Parameters:
g2 - The graphics object to draw the image in. Properties will not be chaged.
x - Upper left corner.
y - Upper left corner.
width - The width
height - The height
See Also:
Icon.paintIcon(java.awt.Component, java.awt.Graphics, int, int)

paintIcon

public void paintIcon(java.awt.Component c,
                      java.awt.Graphics g,
                      int x,
                      int y)
Specified by:
paintIcon in interface javax.swing.Icon

getIconWidth

public int getIconWidth()
Specified by:
getIconWidth in interface javax.swing.Icon

getIconHeight

public int getIconHeight()
Specified by:
getIconHeight in interface javax.swing.Icon

setXtdImage

public void setXtdImage(XtdImage xtdImage)
Sets the image to cut in slices.

Parameters:
xtdImage - The image. May be null and the image/border will be transparent if so.

flush

public void flush()
Releases the source image. Saves memory but the object can't be serialized anymore.


createSlices

protected void createSlices(java.awt.image.BufferedImage image)
Creates the slices and store the in slices. Elements that shoud not be drawn will be null;

Parameters:
image - The image to slice. Not null.

getSliceDimSz

protected int[] getSliceDimSz(int bnds,
                              int stI,
                              int enI)
Returns the sizes of the slices in one dimension

Parameters:
bnds - The total bounds. I.e. width or height,
stI - AtStart instes (left/top)
enI - AtEnd instes (right/bottom)
Returns:
An array of sizez. Length 3. No negative sizes but may be 0.

getCenterSize

public java.awt.Dimension getCenterSize()
Returns the size of the center slice. The sizeof this slice can, which can be negative, can be used to decide how much of an image in in the "slice cache" and how much has been cut away.

Returns:
A dimension containing the size of the center slice. The object is not cloned and should not be changed. Can be negative if insets is greater that image size. null if there is no image contained.

getSliceSpec

public SliceSpec getSliceSpec()
Returns the slice specification.

Returns:
The slice specification. The actual object that is contained so don't change it.

getXtdImage

public XtdImage getXtdImage()
Returns the source image, it it hasn't been flushed in which case null is returned.

Returns:
The source image.

getTransparency

public int getTransparency()
Returns the transparency of the contained image or Transparency.TRANSLUCENT if the image is currently set to null.

Specified by:
getTransparency in interface java.awt.Transparency
Returns:
The transparency of the contained image. E.g Transparency.OPAQUE

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object


Copyright © 2009 MiG InfoCom AB. All Rights Reserved.