@XStreamConverter(value=NinePatchIconConverter.class) public class NinePatchIcon extends java.lang.Object implements javax.swing.Icon
Basically it parses nine-patch image data (patches at the side of .9.png image) into understandable values and uses them to stretch the image properly when it is painted anywhere.
NinePatchIconPainter,
NinePatchStatePainter| Modifier and Type | Field and Description |
|---|---|
protected java.lang.Integer |
cachedHeight0
Cached fixed areas height of the nine-patch image with additional 1px for each stretchable area.
|
protected java.lang.Integer |
cachedHeight1
Cached fixed areas height of the nine-patch image.
|
protected java.lang.Integer |
cachedWidth0
Cached fixed areas width of the nine-patch image with additional 1px for each stretchable area.
|
protected java.lang.Integer |
cachedWidth1
Cached fixed areas width of the nine-patch image.
|
protected java.awt.Component |
component
Component onto which this nine-patch icon will be stretched.
|
protected java.util.List<NinePatchInterval> |
horizontalStretch
Horizontal stretch intervals taken from image patches (top image patches).
|
protected java.awt.Insets |
margin
Content margin taken from image patches (right and bottom patches).
|
protected java.awt.image.BufferedImage |
rawImage
Raw image without patches.
|
protected java.util.List<NinePatchInterval> |
verticalStretch
Vertical stretch intervals taken from image patches (left image patches).
|
| Modifier | Constructor and Description |
|---|---|
|
NinePatchIcon(java.awt.image.BufferedImage bufferedImage)
Constructs new NinePatchIcon using the specified nine-patch image.
|
|
NinePatchIcon(java.awt.image.BufferedImage bufferedImage,
java.awt.Component component)
Constructs new NinePatchIcon using the specified nine-patch image.
|
protected |
NinePatchIcon(java.awt.image.BufferedImage bufferedImage,
java.awt.Component component,
boolean parsePatches)
Constructs new NinePatchIcon using the specified nine-patch image.
|
|
NinePatchIcon(java.awt.Image image)
Constructs new NinePatchIcon using the specified nine-patch image.
|
|
NinePatchIcon(java.awt.Image image,
java.awt.Component component)
Constructs new NinePatchIcon using the specified nine-patch image.
|
|
NinePatchIcon(javax.swing.ImageIcon imageIcon)
Constructs new NinePatchIcon using the specified nine-patch image.
|
|
NinePatchIcon(javax.swing.ImageIcon imageIcon,
java.awt.Component component)
Constructs new NinePatchIcon using the specified nine-patch image.
|
|
NinePatchIcon(java.lang.String iconSrc)
Constructs new NinePatchIcon using the nine-patch image from the specified path.
|
|
NinePatchIcon(java.lang.String iconSrc,
java.awt.Component component)
Constructs new NinePatchIcon using the nine-patch image from the specified path.
|
|
NinePatchIcon(java.net.URL url)
Constructs new NinePatchIcon using the nine-patch image from the specified URL.
|
|
NinePatchIcon(java.net.URL url,
java.awt.Component component)
Constructs new NinePatchIcon using the nine-patch image from the specified URL.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addHorizontalStretch(int start,
int end,
boolean pixel)
Adds horizontal stretch interval.
|
void |
addHorizontalStretch(NinePatchInterval interval)
Adds horizontal stretch interval.
|
void |
addVerticalStretch(int start,
int end,
boolean pixel)
Adds vertical stretch interval.
|
void |
addVerticalStretch(NinePatchInterval interval)
Adds vertical stretch interval.
|
protected int |
calculateFixedPixelsHeight(boolean addUnfixedSpaces)
Returns fixed minimum height for this icon.
|
protected int |
calculateFixedPixelsWidth(boolean addUnfixedSpaces)
Returns fixed minimum width for this icon.
|
static NinePatchIcon |
create(java.awt.image.BufferedImage rawImage)
Returns newly created NinePatchIcon with empty patches.
|
java.awt.Component |
getComponent()
Returns component atop of which icon will be stretched.
|
int |
getFixedPixelsHeight(boolean addUnfixedSpaces)
Returns cached fixed minimum height for this icon.
|
int |
getFixedPixelsWidth(boolean addUnfixedSpaces)
Returns cached fixed minimum width for this icon.
|
java.util.List<NinePatchInterval> |
getHorizontalStretch()
Returns list of horizontal stretch intervals taken from image patches.
|
int |
getIconHeight() |
int |
getIconHeight(java.awt.Component component)
Returns icon height for the specified component.
|
int |
getIconWidth() |
int |
getIconWidth(java.awt.Component component)
Returns icon width for the specified component.
|
java.awt.Insets |
getMargin()
Returns margin taken from image content patches.
|
java.awt.Dimension |
getPreferredSize()
Returns preferred icon size.
|
java.awt.image.BufferedImage |
getRawImage()
Returns raw image without patches.
|
java.awt.Dimension |
getRealImageSize()
Returns raw image size.
|
java.awt.Insets |
getStretchMargin()
Returns margin taken from image stretch patches.
|
java.util.List<NinePatchInterval> |
getVerticalStretch()
Returns list of vertical stretch intervals taken from image patches.
|
void |
paintIcon(java.awt.Component c,
java.awt.Graphics g)
Paints icon for the specified component.
|
void |
paintIcon(java.awt.Component c,
java.awt.Graphics g,
int x,
int y)
Paints icon for the specified component at the specified location.
|
void |
paintIcon(java.awt.Graphics2D g2d,
int x,
int y,
int width,
int height)
Paints icon at the specified bounds.
|
void |
paintIcon(java.awt.Graphics2D g2d,
java.awt.Rectangle bounds)
Paints icon at the specified bounds.
|
void |
setComponent(java.awt.Component component)
Sets component atop of which icon will be stretched.
|
void |
setHorizontalStretch(java.util.List<NinePatchInterval> horizontalStretch)
Sets list of horizontal stretch intervals.
|
void |
setMargin(java.awt.Insets margin)
Sets content margin.
|
void |
setMargin(int spacing)
Sets content margin.
|
void |
setMargin(int top,
int left,
int bottom,
int right)
Sets content margin.
|
void |
setVerticalStretch(java.util.List<NinePatchInterval> verticalStretch)
Sets list of vertical stretch intervals.
|
protected void |
updateCachedHeightData()
Clears fixed pixels height caches.
|
protected void |
updateCachedWidthData()
Clears fixed pixels width caches.
|
protected java.awt.Component component
protected java.awt.image.BufferedImage rawImage
protected java.util.List<NinePatchInterval> horizontalStretch
protected java.util.List<NinePatchInterval> verticalStretch
protected java.awt.Insets margin
protected java.lang.Integer cachedWidth0
protected java.lang.Integer cachedWidth1
protected java.lang.Integer cachedHeight0
protected java.lang.Integer cachedHeight1
public NinePatchIcon(java.net.URL url)
url - nine-patch image URLpublic NinePatchIcon(java.net.URL url,
java.awt.Component component)
url - nine-patch image URLcomponent - component atop of which icon will be stretchedpublic NinePatchIcon(java.lang.String iconSrc)
iconSrc - nine-patch image pathpublic NinePatchIcon(java.lang.String iconSrc,
java.awt.Component component)
iconSrc - nine-patch image pathcomponent - component atop of which icon will be stretchedpublic NinePatchIcon(javax.swing.ImageIcon imageIcon)
imageIcon - nine-patch imagepublic NinePatchIcon(javax.swing.ImageIcon imageIcon,
java.awt.Component component)
imageIcon - nine-patch imagecomponent - component atop of which icon will be stretchedpublic NinePatchIcon(java.awt.Image image)
image - nine-patch imagepublic NinePatchIcon(java.awt.Image image,
java.awt.Component component)
image - nine-patch imagecomponent - component atop of which icon will be stretchedpublic NinePatchIcon(java.awt.image.BufferedImage bufferedImage)
bufferedImage - nine-patch imagepublic NinePatchIcon(java.awt.image.BufferedImage bufferedImage,
java.awt.Component component)
bufferedImage - nine-patch imagecomponent - component atop of which icon will be stretchedprotected NinePatchIcon(java.awt.image.BufferedImage bufferedImage,
java.awt.Component component,
boolean parsePatches)
bufferedImage - nine-patch imagecomponent - component atop of which icon will be stretchedparsePatches - whether should parse image patches or notpublic static NinePatchIcon create(java.awt.image.BufferedImage rawImage)
rawImage - raw image without patchespublic java.awt.image.BufferedImage getRawImage()
public java.awt.Component getComponent()
public void setComponent(java.awt.Component component)
component - component atop of which icon will be stretchedpublic java.util.List<NinePatchInterval> getHorizontalStretch()
public void setHorizontalStretch(java.util.List<NinePatchInterval> horizontalStretch)
horizontalStretch - list of horizontal stretch intervalspublic void addHorizontalStretch(NinePatchInterval interval)
interval - horizontal stretch interval to addpublic void addHorizontalStretch(int start,
int end,
boolean pixel)
start - interval startend - interval endpixel - whether fixed interval or notpublic java.util.List<NinePatchInterval> getVerticalStretch()
public void setVerticalStretch(java.util.List<NinePatchInterval> verticalStretch)
verticalStretch - list of vertical stretch intervalspublic void addVerticalStretch(NinePatchInterval interval)
interval - vertical stretch interval to addpublic void addVerticalStretch(int start,
int end,
boolean pixel)
start - interval startend - interval endpixel - whether fixed interval or notpublic java.awt.Insets getMargin()
public java.awt.Insets getStretchMargin()
public void setMargin(java.awt.Insets margin)
margin - content marginpublic void setMargin(int top,
int left,
int bottom,
int right)
top - top marginleft - left marginbottom - bottom marginright - right marginpublic void setMargin(int spacing)
spacing - sides marginpublic void paintIcon(java.awt.Component c,
java.awt.Graphics g)
c - component to processg - graphics contextpublic void paintIcon(java.awt.Component c,
java.awt.Graphics g,
int x,
int y)
paintIcon in interface javax.swing.Iconc - component to processg - graphics contextx - location X coordinatey - location Y coordinatepublic void paintIcon(java.awt.Graphics2D g2d,
java.awt.Rectangle bounds)
g2d - graphics contextbounds - icon boundspublic void paintIcon(java.awt.Graphics2D g2d,
int x,
int y,
int width,
int height)
g2d - graphics contextx - location X coordinatey - location Y coordinatewidth - icon widthheight - icon heightpublic int getFixedPixelsWidth(boolean addUnfixedSpaces)
addUnfixedSpaces - whether to add 1px for each stretchable area or notprotected int calculateFixedPixelsWidth(boolean addUnfixedSpaces)
addUnfixedSpaces - whether to add 1px for each stretchable area or notprotected void updateCachedWidthData()
public int getFixedPixelsHeight(boolean addUnfixedSpaces)
addUnfixedSpaces - whether to add 1px for each stretchable area or notprotected int calculateFixedPixelsHeight(boolean addUnfixedSpaces)
addUnfixedSpaces - swhether to add 1px for each stretchable area or notprotected void updateCachedHeightData()
public int getIconWidth()
getIconWidth in interface javax.swing.Iconpublic int getIconWidth(java.awt.Component component)
component - component atop of which icon will be stretchedpublic int getIconHeight()
getIconHeight in interface javax.swing.Iconpublic int getIconHeight(java.awt.Component component)
component - component atop of which icon will be stretchedpublic java.awt.Dimension getPreferredSize()
public java.awt.Dimension getRealImageSize()