Package com.nomagic.ui
Class SquareIcon
java.lang.Object
javax.swing.ImageIcon
com.nomagic.ui.ScalableImageIcon
com.nomagic.ui.ResizableIconImageIcon
com.nomagic.ui.SquareIcon
- All Implemented Interfaces:
ResizableIcon
,Serializable
,Cloneable
,Accessible
,Icon
An icon which fits another icon into a square of given size.
- See Also:
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic ResizableIcon
fit
(ResizableIcon icon, int size) Convert given icon to a scaled icon which fits to a square of given size.static ResizableIcon
fitOrCenter
(ResizableIcon icon, int size) Convert given icon to a scaled icon which fits to a square of given size.int
int
getScale()
static double
Utility method to calculate a scale factor of given icon if it needs to be fit into a square of given size.static Dimension
getScaleSize
(Icon icon, int size) Utility method to calculate dimension of given icon if it needs to be fit into a square of given size.void
void
Draw the icon in the given bounds.static ResizableIcon
scale
(ResizableIcon icon, double scale) Convert given icon to a scaled icon with given scale(zoom) factor.Methods inherited from class com.nomagic.ui.ScalableImageIcon
clone, create, doNotScale, getImage, getLocation, getURL, setImage, toImageIcon, toImageIcon, toImageIcon
Methods inherited from class javax.swing.ImageIcon
getAccessibleContext, getDescription, getImageLoadStatus, getImageObserver, loadImage, setDescription, setImageObserver, toString
-
Method Details
-
fit
Convert given icon to a scaled icon which fits to a square of given size. Wrapped icon is zoomed in if icon is smaller than square.- Parameters:
icon
- iconsize
- square size- Returns:
- scaled icon
-
fitOrCenter
Convert given icon to a scaled icon which fits to a square of given size. Wrapped icon is not zoomed in if icon is smaller than square. Icon is zoomed out if it is larger than square. Icon will be painted in the center of the square.- Parameters:
icon
- iconsize
- square size- Returns:
- scaled icon
-
scale
Convert given icon to a scaled icon with given scale(zoom) factor.- Parameters:
icon
- iconscale
- scale factor- Returns:
- scaled icon
-
getScaleSize
Utility method to calculate dimension of given icon if it needs to be fit into a square of given size.- Parameters:
icon
- iconsize
- square size- Returns:
- dimensions of icon to fit into a square
-
getScale
Utility method to calculate a scale factor of given icon if it needs to be fit into a square of given size.- Parameters:
icon
- iconsize
- square size- Returns:
- scale factor of icon to fit into a square
-
paintIcon
Description copied from interface:ResizableIcon
Draw the icon in the given bounds. Icon implementations may use the Component argument to get properties useful for painting, e.g. the foreground or background color.- Specified by:
paintIcon
in interfaceResizableIcon
- Overrides:
paintIcon
in classScalableImageIcon
- Parameters:
c
- the given component.g
- the graphics to paint on.x
- x coordinate.y
- y coordinate.w
- width to paint.h
- height to paint.
-
paintIcon
- Specified by:
paintIcon
in interfaceIcon
- Overrides:
paintIcon
in classScalableImageIcon
-
getIconWidth
public int getIconWidth()- Specified by:
getIconWidth
in interfaceIcon
- Overrides:
getIconWidth
in classScalableImageIcon
-
getIconHeight
public int getIconHeight()- Specified by:
getIconHeight
in interfaceIcon
- Overrides:
getIconHeight
in classScalableImageIcon
-
getScale
- Returns:
- icon scale factor
-