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,java.io.Serializable,java.lang.Cloneable,javax.accessibility.Accessible,javax.swing.Icon
@OpenApiAll public final class SquareIcon extends ResizableIconImageIcon
An icon which fits another icon into a square of given size.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classSquareIcon.ScaledIconLoader-
Nested classes/interfaces inherited from class com.nomagic.ui.ResizableIconImageIcon
ResizableIconImageIcon.ResizableIconLoader
-
Nested classes/interfaces inherited from class com.nomagic.ui.ScalableImageIcon
ScalableImageIcon.AbstractImageLoader
-
-
Field Summary
Fields Modifier and Type Field Description private ResizableIconiconToScaleprivate java.lang.DoublemaxScaleprivate java.lang.Doublescaleprivate java.lang.Integersize
-
Constructor Summary
Constructors Modifier Constructor Description privateSquareIcon(ResizableIcon icon, double scale)privateSquareIcon(ResizableIcon icon, int size, double maxScale)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidcalculateScale()private voidcalculateSize()(package private) static ResizableIconcreate(ResizableIcon icon, int size, double maxScale)Convert given icon to a scaled icon which fits to a square of given size.static 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.intgetIconHeight()intgetIconWidth()java.lang.DoublegetScale()static doublegetScale(javax.swing.Icon icon, int size)Utility method to calculate a scale factor of given icon if it needs to be fit into a square of given size.static java.awt.DimensiongetScaleSize(javax.swing.Icon icon, int size)Utility method to calculate dimension of given icon if it needs to be fit into a square of given size.voidpaintIcon(java.awt.Component c, java.awt.Graphics g, int x, int y)voidpaintIcon(java.awt.Component c, java.awt.Graphics g, int x, int y, int w, int h)Draw 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, internalGetIcon, internalSetLoader, internalSuperGetImage, setImage, toImageIcon, toImageIcon, toImageIcon
-
-
-
-
Field Detail
-
size
private java.lang.Integer size
-
scale
private java.lang.Double scale
-
maxScale
private java.lang.Double maxScale
-
iconToScale
private final ResizableIcon iconToScale
-
-
Constructor Detail
-
SquareIcon
private SquareIcon(ResizableIcon icon, int size, double maxScale)
-
SquareIcon
private SquareIcon(ResizableIcon icon, double scale)
-
-
Method Detail
-
fit
public static ResizableIcon fit(ResizableIcon icon, int size)
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
public static ResizableIcon fitOrCenter(ResizableIcon icon, int size)
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
-
create
static ResizableIcon create(ResizableIcon icon, int size, double maxScale)
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 middle of the square. Icon will not be zoomed more than given max scale.- Parameters:
icon- iconsize- square sizemaxScale- max icon scale factor.- Returns:
- scaled icon
-
scale
public static ResizableIcon scale(ResizableIcon icon, double scale)
Convert given icon to a scaled icon with given scale(zoom) factor.- Parameters:
icon- iconscale- scale factor- Returns:
- scaled icon
-
getScaleSize
public static java.awt.Dimension getScaleSize(javax.swing.Icon icon, int size)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
public static double getScale(javax.swing.Icon icon, int size)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
public void paintIcon(@CheckForNull java.awt.Component c, java.awt.Graphics g, int x, int y, int w, int h)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
public void paintIcon(java.awt.Component c, java.awt.Graphics g, int x, int y)- Specified by:
paintIconin interfacejavax.swing.Icon- Overrides:
paintIconin classScalableImageIcon
-
calculateScale
private void calculateScale()
-
calculateSize
private void calculateSize()
-
getIconWidth
public int getIconWidth()
- Specified by:
getIconWidthin interfacejavax.swing.Icon- Overrides:
getIconWidthin classScalableImageIcon
-
getIconHeight
public int getIconHeight()
- Specified by:
getIconHeightin interfacejavax.swing.Icon- Overrides:
getIconHeightin classScalableImageIcon
-
getScale
public java.lang.Double getScale()
- Returns:
- icon scale factor
-
-