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 ResizableIconfit(ResizableIcon icon, int size) Convert given icon to a scaled icon which fits to a square of given size.static ResizableIconfitOrCenter(ResizableIcon icon, int size) Convert given icon to a scaled icon which fits to a square of given size.intintgetScale()static doubleUtility method to calculate a scale factor of given icon if it needs to be fit into a square of given size.static DimensiongetScaleSize(Icon icon, int size) Utility method to calculate dimension of given icon if it needs to be fit into a square of given size.voidvoidDraw the icon in the given bounds.static ResizableIconscale(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, toImageIconMethods 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:ResizableIconDraw 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:
paintIconin interfaceResizableIcon- Overrides:
paintIconin 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:
paintIconin interfaceIcon- Overrides:
paintIconin classScalableImageIcon
-
getIconWidth
public int getIconWidth()- Specified by:
getIconWidthin interfaceIcon- Overrides:
getIconWidthin classScalableImageIcon
-
getIconHeight
public int getIconHeight()- Specified by:
getIconHeightin interfaceIcon- Overrides:
getIconHeightin classScalableImageIcon
-
getScale
- Returns:
- icon scale factor
-