Package com.nomagic.magicdraw.ui.zoom
Class ZoomHelper
java.lang.Object
com.nomagic.magicdraw.ui.zoom.ZoomHelper
Helper functions to display zoomed GUI components
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final float
static final float
min scale factor for diagrams, that display table componentsstatic final float
Common scale factor rangestatic final int[]
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic float
calculateZoom
(float currentZoomFactor, int mouseWheelRotation, float zoomStep) static Point
calculateZoomedScrollPosition
(Point zoomAtPoint, Point currentScrollPosition, float zoomChange) static float
calculateZoomFactorToFit
(Dimension componentSize, Dimension windowSize, boolean max1) static Font
getOriginalFont
(JLabel label) static Icon
getOriginalIcon
(JLabel label) static int
getOriginalSize
(int scaledSize, float zoomFactor) Opposite method togetScaledSize(int, float)
.static Font
getScaledFont
(Font font, float zoomFactor) Takes the provided font and scales it's size by the given zoomFactor.static Icon
getScaledIcon
(Icon icon, float zoomFactor) Takes the provided icon and scales it's size by the given zoomFactor.static int
getScaledSize
(int size, float zoomFactor) Takes the provided integer and scales (multiplies) it by the given zoomFactor.static int
getScaledSizeRounded
(int size, float zoomFactor) static Graphics
Modify graphics to provide increased readability of very small fontsstatic boolean
isScalingRequired
(float zoomFactor) Checks if zoomFactor is positive and not equal to onestatic float
roundZoom
(double zoomFactor) Fix float precision problems by rounding zoomFactor to 4 decimal placesstatic float
validateZoom
(float zoomFactor) Validates given zoom value by the default min max valuesstatic float
validateZoom
(float zoomFactor, float minZoom, float maxZoom) static boolean
zoomComponent
(Component component, float zoomFactor) If component implementsZoomable
interface, zooms the component by the given factor.static boolean
zoomComponents
(Container container, float zoomFactor) Iterates through inner components recursively and zooms all components that implementZoomable
interface.
-
Field Details
-
MIN_ZOOM
public static final float MIN_ZOOMCommon scale factor range- See Also:
-
MAX_ZOOM
public static final float MAX_ZOOM- See Also:
-
MIN_TABLE_ZOOM
public static final float MIN_TABLE_ZOOMmin scale factor for diagrams, that display table components- See Also:
-
TABLE_ZOOM_CHOICES
public static final int[] TABLE_ZOOM_CHOICES
-
-
Constructor Details
-
ZoomHelper
public ZoomHelper()
-
-
Method Details
-
getScaledSize
@OpenApi public static int getScaledSize(int size, float zoomFactor) Takes the provided integer and scales (multiplies) it by the given zoomFactor. Trims the floating part of the result down.- Returns:
- scaled size
-
getOriginalSize
@OpenApi public static int getOriginalSize(int scaledSize, float zoomFactor) Opposite method togetScaledSize(int, float)
. Takes the provided scaledSize, which is already scaled by the given zoomFactor and returns the original not scaled size, by dividing the scaledSize from zoomFactor.- Returns:
- not scaled size
-
getScaledFont
Takes the provided font and scales it's size by the given zoomFactor.- Returns:
- scaled font
-
getScaledIcon
Takes the provided icon and scales it's size by the given zoomFactor. Icon caching is used to prevent repeated scaling of the same icon and zoomFactor.- Returns:
- scaled icon
-
zoomComponent
If component implementsZoomable
interface, zooms the component by the given factor. If component does not implement Zoomable, but it is a Container, then looks for Zoomable inner components recursively and zooms each of them.- Returns:
- true if component or at least one of it's sub components was zoomed
- See Also:
-
zoomComponents
Iterates through inner components recursively and zooms all components that implementZoomable
interface.- Returns:
- true if at least one of Container's inner components is Zoomable
-
isScalingRequired
public static boolean isScalingRequired(float zoomFactor) Checks if zoomFactor is positive and not equal to one- Returns:
- false if original size should be used
-
roundZoom
public static float roundZoom(double zoomFactor) Fix float precision problems by rounding zoomFactor to 4 decimal places- Returns:
- zoomFactor rounded with 0.001 precision
-
validateZoom
public static float validateZoom(float zoomFactor) Validates given zoom value by the default min max values- Parameters:
zoomFactor
- given zoom value- Returns:
- valid zoom value
-
validateZoom
public static float validateZoom(float zoomFactor, float minZoom, float maxZoom) -
getScaledSizeRounded
public static int getScaledSizeRounded(int size, float zoomFactor) -
calculateZoomedScrollPosition
public static Point calculateZoomedScrollPosition(@CheckForNull Point zoomAtPoint, Point currentScrollPosition, float zoomChange) - Parameters:
zoomAtPoint
- mouse point at which zooming action occurredcurrentScrollPosition
- current view position of the scroll panezoomChange
- new zoom factor divided from the old (current) zoom factor- Returns:
- new point to set as view position of the scroll pane
-
calculateZoomFactorToFit
-
increaseSmallFontReadability
Modify graphics to provide increased readability of very small fonts -
getOriginalIcon
-
getOriginalFont
-
calculateZoom
public static float calculateZoom(float currentZoomFactor, int mouseWheelRotation, float zoomStep)
-