Package ca.cgjennings.graphics.shapes
Class VectorIcon
- java.lang.Object
-
- ca.cgjennings.graphics.shapes.VectorIcon
-
- All Implemented Interfaces:
javax.swing.Icon
public class VectorIcon extends java.lang.Object implements javax.swing.Icon
An icon that is drawn from aVectorImage
.- Since:
- 3.0
- Author:
- Chris Jennings
-
-
Constructor Summary
Constructors Constructor Description VectorIcon(VectorImage vectorImage, int iconWidth, int iconHeight, boolean fitToSize)
VectorIcon(java.net.URL imageURL)
VectorIcon(java.net.URL imageURL, int iconWidth, int iconHeight)
VectorIcon(java.net.URL imageURL, int iconWidth, int iconHeight, boolean fitToSize)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description VectorIcon
derive(int newWidth, int newHeight)
Returns a new vector icon for the same image as this icon, but with a different icon size.int
getIconHeight()
Returns the height of this icon.int
getIconWidth()
Returns the width of this icon.VectorImage
getImage()
Returns the vector image painted by this icon.boolean
isImageFittingEnabled()
Returnstrue
if the image's aspect ratio will be maintained by fitting it within the icon width and height.void
paintIcon(java.awt.Component c, java.awt.Graphics g, int x, int y)
void
setIconHeight(int height)
Sets the height of this icon.void
setIconWidth(int width)
Sets the width of this icon.void
setImageFittingEnabled(boolean fit)
Sets whether the image's aspect ratio will be maintained by fitting it within the icon width and height.java.lang.String
toString()
-
-
-
Constructor Detail
-
VectorIcon
public VectorIcon(java.net.URL imageURL)
-
VectorIcon
public VectorIcon(java.net.URL imageURL, int iconWidth, int iconHeight)
-
VectorIcon
public VectorIcon(java.net.URL imageURL, int iconWidth, int iconHeight, boolean fitToSize)
-
VectorIcon
public VectorIcon(VectorImage vectorImage, int iconWidth, int iconHeight, boolean fitToSize)
-
-
Method Detail
-
paintIcon
public void paintIcon(java.awt.Component c, java.awt.Graphics g, int x, int y)
- Specified by:
paintIcon
in interfacejavax.swing.Icon
-
getIconWidth
public final int getIconWidth()
Returns the width of this icon. This is the width occupied by the icon in an interface layout.- Specified by:
getIconWidth
in interfacejavax.swing.Icon
- Returns:
- the width of the icon
- See Also:
setIconWidth(int)
-
setIconWidth
public final void setIconWidth(int width)
Sets the width of this icon. This is the width occupied by the icon in an interface layout.- Parameters:
width
- the new icon width- See Also:
getIconWidth()
-
getIconHeight
public final int getIconHeight()
Returns the height of this icon. This is the height occupied by the icon in an interface layout.- Specified by:
getIconHeight
in interfacejavax.swing.Icon
- Returns:
- the height of the icon
- See Also:
setIconHeight(int)
-
setIconHeight
public final void setIconHeight(int height)
Sets the height of this icon. This is the height occupied by the icon in an interface layout.- Parameters:
height
- the new icon width- See Also:
getIconHeight()
-
isImageFittingEnabled
public final boolean isImageFittingEnabled()
Returnstrue
if the image's aspect ratio will be maintained by fitting it within the icon width and height.- Returns:
true
if the painted area will pad one dimension, if necessary, to maintain the original image's aspect ratio- See Also:
setImageFittingEnabled(boolean)
-
setImageFittingEnabled
public final void setImageFittingEnabled(boolean fit)
Sets whether the image's aspect ratio will be maintained by fitting it within the icon width and height.- Parameters:
fit
- iftrue
the painted area will be padded in one dimension, if necessary, to maintain the original image's aspect ratio- See Also:
setImageFittingEnabled(boolean)
-
getImage
public final VectorImage getImage()
Returns the vector image painted by this icon.- Returns:
- the vector image used to create the icon
-
derive
public final VectorIcon derive(int newWidth, int newHeight)
Returns a new vector icon for the same image as this icon, but with a different icon size. A new icon is always returned, even if the new size is equal to this icon's size.- Parameters:
newWidth
- the new icon widthnewHeight
- the new icon height- Returns:
- an icon identical to this icon, except for having the newly specified icon dimensions
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-