Class ZoomHelper


  • @OpenApi
    public class ZoomHelper
    extends java.lang.Object
    Helper functions to display zoomed GUI components
    • Constructor Summary

      Constructors 
      Constructor Description
      ZoomHelper()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.awt.Point calculateZoomedScrollPosition​(java.awt.Point zoomAtPoint, java.awt.Point currentScrollPosition, float zoomChange)  
      static float calculateZoomFactorToFit​(java.awt.Dimension componentSize, java.awt.Dimension windowSize, boolean max1)  
      static int getOriginalSize​(int scaledSize, float zoomFactor)
      Opposite method to getScaledSize(int, float).
      static java.awt.Font getScaledFont​(java.awt.Font font, float zoomFactor)
      Takes the provided font and scales it's size by the given zoomFactor.
      static javax.swing.Icon getScaledIcon​(javax.swing.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 java.awt.Graphics increaseSmallFontReadability​(java.awt.Graphics g)
      Modify graphics to provide increased readability of very small fonts
      static boolean isScalingRequired​(float zoomFactor)
      Checks if zoomFactor is positive and not equal to one
      static float roundZoom​(double zoomFactor)
      Fix float precision problems by rounding zoomFactor to 4 decimal places
      static float validateZoom​(float zoomFactor)
      Validates given zoom value by the default min max values
      static float validateZoom​(float zoomFactor, float minZoom, float maxZoom)  
      static boolean zoomComponent​(java.awt.Component component, float zoomFactor)
      If component implements Zoomable interface, zooms the component by the given factor.
      static boolean zoomComponents​(java.awt.Container container, float zoomFactor)
      Iterates through inner components recursively and zooms all components that implement Zoomable interface.
      private static boolean zoomSelf​(java.awt.Component component, float zoomFactor)  
      private static void zoomSferyxEditor​(sferyx.administration.editors.CustomEditorPane editorPane, float zoomFactor)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • SCALED_ICONS_CACHE

        private static final java.util.Map<com.nomagic.ui.IconSizeKey,​ResizableIcon> SCALED_ICONS_CACHE
      • MIN_TABLE_ZOOM

        public static final float MIN_TABLE_ZOOM
        min scale factor for diagrams, that display table components
        See Also:
        Constant Field Values
      • TABLE_ZOOM_CHOICES

        public static final int[] TABLE_ZOOM_CHOICES
    • Constructor Detail

      • ZoomHelper

        public ZoomHelper()
    • Method Detail

      • 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 to getScaledSize(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

        @OpenApi
        @CheckForNull
        public static java.awt.Font getScaledFont​(@CheckForNull
                                                  java.awt.Font font,
                                                  float zoomFactor)
        Takes the provided font and scales it's size by the given zoomFactor.
        Returns:
        scaled font
      • getScaledIcon

        @OpenApi
        @CheckForNull
        public static javax.swing.Icon getScaledIcon​(@CheckForNull
                                                     javax.swing.Icon icon,
                                                     float zoomFactor)
        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

        @OpenApi
        public static boolean zoomComponent​(java.awt.Component component,
                                            float zoomFactor)
        If component implements Zoomable 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(java.awt.Container, float)
      • zoomComponents

        @OpenApi
        public static boolean zoomComponents​(java.awt.Container container,
                                             float zoomFactor)
        Iterates through inner components recursively and zooms all components that implement Zoomable interface.
        Returns:
        true if at least one of Container's inner components is Zoomable
      • zoomSelf

        private static boolean zoomSelf​(java.awt.Component component,
                                        float zoomFactor)
      • zoomSferyxEditor

        private static void zoomSferyxEditor​(sferyx.administration.editors.CustomEditorPane editorPane,
                                             float zoomFactor)
      • 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 java.awt.Point calculateZoomedScrollPosition​(@CheckForNull
                                                                   java.awt.Point zoomAtPoint,
                                                                   java.awt.Point currentScrollPosition,
                                                                   float zoomChange)
        Parameters:
        zoomAtPoint - mouse point at which zooming action occurred
        currentScrollPosition - current view position of the scroll pane
        zoomChange - new zoom factor divided from the old (current) zoom factor
        Returns:
        new point to set as view position of the scroll pane
      • calculateZoomFactorToFit

        public static float calculateZoomFactorToFit​(java.awt.Dimension componentSize,
                                                     java.awt.Dimension windowSize,
                                                     boolean max1)
      • increaseSmallFontReadability

        public static java.awt.Graphics increaseSmallFontReadability​(java.awt.Graphics g)
        Modify graphics to provide increased readability of very small fonts