Class UiUtils


  • public class UiUtils
    extends java.lang.Object
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int CTRL_BNT_KEY  
      static java.lang.Runnable EMPTY_RUNNABLE  
      static boolean JADX_GUI_DEBUG  
      static long MIN_FREE_MEMORY
      The minimum about of memory in bytes we are trying to keep free, otherwise the application may run out of heap which ends up in a Java garbage collector running "amok" (CPU utilization 100% for each core and the UI is not responsive).
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T extends java.awt.Window & javax.swing.RootPaneContainer>
      void
      addEscapeShortCutToDispose​(T window)  
      static void addKeyBinding​(javax.swing.JComponent comp, javax.swing.KeyStroke key, java.lang.String id, java.lang.Runnable action)  
      static void addKeyBinding​(javax.swing.JComponent comp, javax.swing.KeyStroke key, java.lang.String id, javax.swing.Action action)  
      static java.awt.Color adjustBrightness​(java.awt.Color color, float factor)
      Adjusts the brightness of a given Color object without altering its hue or saturation.
      static void bgRun​(java.lang.Runnable runnable)
      Run task in background thread.
      static int calcProgress​(long done, long total)  
      static int calcProgress​(ITaskProgress taskProgress)  
      static long calculateMinFreeMemory()  
      static void copyToClipboard​(java.lang.String text)  
      static int ctrlButton()  
      static void debugTimer​(int periodInSeconds, java.lang.Runnable action)  
      static void errorMessage​(java.awt.Component parent, java.lang.String message)  
      static java.lang.String escapeHtml​(java.lang.String str)  
      static java.lang.String fadeHtml​(java.lang.String htmlStr)  
      static java.awt.Point getMousePosition​(java.awt.Component comp)  
      static int getOffsetAtMousePosition​(AbstractCodeArea codeArea)
      Get closest offset at mouse position
      static javax.swing.tree.TreeNode getTreeNodeUnderMouse​(javax.swing.JTree tree, java.awt.event.MouseEvent mouseEvent)  
      static void highlightAsErrorField​(javax.swing.JTextField field, boolean isError)  
      static boolean isCtrlDown​(java.awt.event.KeyEvent keyEvent)  
      static boolean isDarkTheme​(java.awt.Color background)  
      static boolean isFreeMemoryAvailable()  
      static OverlayIcon makeIcon​(jadx.core.dex.info.AccessInfo af, javax.swing.Icon pub, javax.swing.Icon pri, javax.swing.Icon pro, javax.swing.Icon def)  
      static java.lang.String memoryInfo()  
      static void notUiThreadGuard()  
      static javax.swing.ImageIcon openIcon​(java.lang.String name)  
      static java.awt.Image openImage​(java.lang.String path)  
      static com.formdev.flatlaf.extras.FlatSVGIcon openSvgIcon​(java.lang.String name)  
      static void printStackTrace​(java.lang.String label)  
      static void removeKeyBinding​(javax.swing.JComponent comp, javax.swing.KeyStroke key, java.lang.String id)  
      static void resetClipboardOwner()
      Owner field in Clipboard class can store reference to CodeArea.
      static void setClipboardString​(java.lang.String text)  
      static void setWindowIcons​(java.awt.Window window)  
      static void showMessageBox​(java.awt.Component parent, java.lang.String msg)  
      static void sleep​(int ms)  
      static java.lang.String typeFormat​(java.lang.String name, jadx.core.dex.instructions.args.ArgType type)  
      static java.lang.String typeFormatHtml​(java.lang.String name, jadx.core.dex.instructions.args.ArgType type)  
      static java.lang.String typeStr​(jadx.core.dex.instructions.args.ArgType type)  
      static void uiRun​(java.lang.Runnable runnable)  
      static void uiRunAndWait​(java.lang.Runnable runnable)  
      static void uiThreadGuard()  
      static java.lang.String wrapHtml​(java.lang.String htmlStr)  
      • Methods inherited from class java.lang.Object

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

      • JADX_GUI_DEBUG

        public static final boolean JADX_GUI_DEBUG
      • MIN_FREE_MEMORY

        public static final long MIN_FREE_MEMORY
        The minimum about of memory in bytes we are trying to keep free, otherwise the application may run out of heap which ends up in a Java garbage collector running "amok" (CPU utilization 100% for each core and the UI is not responsive).

        We can calculate and store this value here as the maximum heap is fixed for each JVM instance and can't be changed at runtime.

      • EMPTY_RUNNABLE

        public static final java.lang.Runnable EMPTY_RUNNABLE
      • CTRL_BNT_KEY

        public static final int CTRL_BNT_KEY
    • Method Detail

      • openSvgIcon

        public static com.formdev.flatlaf.extras.FlatSVGIcon openSvgIcon​(java.lang.String name)
      • openIcon

        public static javax.swing.ImageIcon openIcon​(java.lang.String name)
      • openImage

        public static java.awt.Image openImage​(java.lang.String path)
      • addKeyBinding

        public static void addKeyBinding​(javax.swing.JComponent comp,
                                         javax.swing.KeyStroke key,
                                         java.lang.String id,
                                         java.lang.Runnable action)
      • addKeyBinding

        public static void addKeyBinding​(javax.swing.JComponent comp,
                                         javax.swing.KeyStroke key,
                                         java.lang.String id,
                                         javax.swing.Action action)
      • removeKeyBinding

        public static void removeKeyBinding​(javax.swing.JComponent comp,
                                            javax.swing.KeyStroke key,
                                            java.lang.String id)
      • typeFormat

        public static java.lang.String typeFormat​(java.lang.String name,
                                                  jadx.core.dex.instructions.args.ArgType type)
      • typeFormatHtml

        public static java.lang.String typeFormatHtml​(java.lang.String name,
                                                      jadx.core.dex.instructions.args.ArgType type)
      • fadeHtml

        public static java.lang.String fadeHtml​(java.lang.String htmlStr)
      • wrapHtml

        public static java.lang.String wrapHtml​(java.lang.String htmlStr)
      • escapeHtml

        public static java.lang.String escapeHtml​(java.lang.String str)
      • typeStr

        public static java.lang.String typeStr​(jadx.core.dex.instructions.args.ArgType type)
      • makeIcon

        public static OverlayIcon makeIcon​(jadx.core.dex.info.AccessInfo af,
                                           javax.swing.Icon pub,
                                           javax.swing.Icon pri,
                                           javax.swing.Icon pro,
                                           javax.swing.Icon def)
      • calculateMinFreeMemory

        public static long calculateMinFreeMemory()
        Returns:
        20% of the maximum heap size limited to 512 MB (bytes)
      • isFreeMemoryAvailable

        public static boolean isFreeMemoryAvailable()
      • memoryInfo

        public static java.lang.String memoryInfo()
      • setClipboardString

        public static void setClipboardString​(java.lang.String text)
      • setWindowIcons

        public static void setWindowIcons​(java.awt.Window window)
      • ctrlButton

        @MagicConstant(flagsFromClass=java.awt.event.InputEvent.class)
        public static int ctrlButton()
      • isCtrlDown

        public static boolean isCtrlDown​(java.awt.event.KeyEvent keyEvent)
      • addEscapeShortCutToDispose

        public static <T extends java.awt.Window & javax.swing.RootPaneContainer> void addEscapeShortCutToDispose​(T window)
      • getOffsetAtMousePosition

        public static int getOffsetAtMousePosition​(AbstractCodeArea codeArea)
        Get closest offset at mouse position
        Returns:
        -1 on error
      • getMousePosition

        public static java.awt.Point getMousePosition​(java.awt.Component comp)
      • getTreeNodeUnderMouse

        public static javax.swing.tree.TreeNode getTreeNodeUnderMouse​(javax.swing.JTree tree,
                                                                      java.awt.event.MouseEvent mouseEvent)
      • showMessageBox

        public static void showMessageBox​(java.awt.Component parent,
                                          java.lang.String msg)
      • errorMessage

        public static void errorMessage​(java.awt.Component parent,
                                        java.lang.String message)
      • copyToClipboard

        public static void copyToClipboard​(java.lang.String text)
      • resetClipboardOwner

        public static void resetClipboardOwner()
        Owner field in Clipboard class can store reference to CodeArea. This prevents from garbage collection whole jadx object tree and cause memory leak. Trying to lost ownership by new empty selection.
      • calcProgress

        public static int calcProgress​(ITaskProgress taskProgress)
      • calcProgress

        public static int calcProgress​(long done,
                                       long total)
      • sleep

        public static void sleep​(int ms)
      • uiRun

        public static void uiRun​(java.lang.Runnable runnable)
      • uiRunAndWait

        public static void uiRunAndWait​(java.lang.Runnable runnable)
      • bgRun

        public static void bgRun​(java.lang.Runnable runnable)
        Run task in background thread. Uses single thread, so all tasks are ordered.
      • uiThreadGuard

        public static void uiThreadGuard()
      • notUiThreadGuard

        public static void notUiThreadGuard()
      • debugTimer

        @TestOnly
        public static void debugTimer​(int periodInSeconds,
                                      java.lang.Runnable action)
      • printStackTrace

        @TestOnly
        public static void printStackTrace​(java.lang.String label)
      • isDarkTheme

        public static boolean isDarkTheme​(java.awt.Color background)
      • adjustBrightness

        public static java.awt.Color adjustBrightness​(java.awt.Color color,
                                                      float factor)
        Adjusts the brightness of a given Color object without altering its hue or saturation.

        This method converts the input RGB color to the HSB (Hue, Saturation, Brightness) color model, multiplies its brightness component by the specified factor, and then converts it back to a new RGB Color object.

        The new brightness value is capped at 1.0f (maximum HSB brightness) to prevent colors from becoming invalid or exceeding full brightness.

        How to use:
        • To make a color **brighter**: Use a factor greater than 1.0f (e.g., 1.2f, 1.5f).
        • To make a color **darker**: Use a factor less than 1.0f (e.g., 0.8f, 0.5f).
        • To keep the brightness **unchanged**: Use a factor of 1.0f.
        
         // Example usage:
         Color originalColor = Color.BLUE;
        
         // Make the blue color 50% brighter (factor 1.5)
         Color brighterBlue = adjustBrightness(originalColor, 1.5f);
        
         // Make the blue color 30% darker (factor 0.7)
         Color darkerBlue = adjustBrightness(originalColor, 0.7f);
        
         // Get the brightest possible version of the color (will cap at 1.0 brightness)
         Color maxBrightnessBlue = adjustBrightness(originalColor, 10.0f);
        
         // Get a very dark, almost black version
         Color veryDarkBlue = adjustBrightness(originalColor, 0.1f);
         
        Parameters:
        color - The original Color object whose brightness needs to be adjusted.
        factor - The multiplier for the brightness.
        Returns:
        A new Color object with the adjusted brightness.
        See Also:
        Color.RGBtoHSB(int, int, int, float[]), Color.getHSBColor(float, float, float)
      • highlightAsErrorField

        public static void highlightAsErrorField​(javax.swing.JTextField field,
                                                 boolean isError)