Module org.autogui

Class UIManagerUtil

java.lang.Object
org.autogui.swing.util.UIManagerUtil

public class UIManagerUtil extends Object
a support class with UIManager. the main purpose of the class is providing default settings of UI resources and sizes in order to support HiDPI environments.
          int size = UIManager.getInstance().getScaledSizeForInt(12);
          ...
  
  • Field Details

  • Constructor Details

    • UIManagerUtil

      public UIManagerUtil()
  • Method Details

    • getInstance

      public static UIManagerUtil getInstance()
    • getConsoleFont

      public Font getConsoleFont()
    • getLabelFont

      public Font getLabelFont()
    • getEditorPaneFont

      public Font getEditorPaneFont()
    • getTableFocusCellHighlightBorder

      public Border getTableFocusCellHighlightBorder()
    • getLabelForeground

      public Color getLabelForeground()
    • getLabelBackground

      public Color getLabelBackground()
    • getLabelDisabledForeground

      public Color getLabelDisabledForeground()
    • getTextPaneSelectionBackground

      public Color getTextPaneSelectionBackground()
    • getTextPaneSelectionForeground

      public Color getTextPaneSelectionForeground()
    • getTextPaneForeground

      public Color getTextPaneForeground()
      Returns:
      the text pane foreground
      Since:
      1.2
    • getTextPaneBackground

      public Color getTextPaneBackground()
      Returns:
      the text pane background
      Since:
      1.2
    • getFocusColor

      public Color getFocusColor()
    • getMenuDisabledForeground

      public Color getMenuDisabledForeground()
    • getTableAlternateRowColor

      public Color getTableAlternateRowColor()
      Returns:
      Table.alternateRowColor or null
      Since:
      1.2
    • getTableDropCellBackground

      public Color getTableDropCellBackground()
      Returns:
      Table.dropCellBackground or null
      Since:
      1.2
    • getTableDropCellForeground

      public Color getTableDropCellForeground()
      Returns:
      Table.dropCellForeground or null
      Since:
      1.2
    • getTableFocusCellBackground

      public Color getTableFocusCellBackground()
      Returns:
      Table.focusCellBackground or null
      Since:
      1.2
    • getTableBackground

      public Color getTableBackground()
      Returns:
      Table.background or null
      Since:
      1.2
    • getTableFocusCellForeground

      public Color getTableFocusCellForeground()
      Returns:
      Table.focusCellForeground or null
      Since:
      1.2
    • getListAlternateRowColor

      public Color getListAlternateRowColor()
      Returns:
      List.alternateRowColor or null
      Since:
      1.2
    • getListDropCellBackground

      public Color getListDropCellBackground()
      Returns:
      List.dropCellBackground or null
      Since:
      1.2
    • getListDropCellForeground

      public Color getListDropCellForeground()
      Returns:
      List.dropCellForeground or null
      Since:
      1.2
    • getListFocusCellBackground

      public Color getListFocusCellBackground()
      Returns:
      List.focusCellBackground or null
      Since:
      1.2
    • getListFocusCellForeground

      public Color getListFocusCellForeground()
      Returns:
      List.focusCellForeground or null
      Since:
      1.2
    • getIconSize

      public int getIconSize()
      Returns:
      32 or label font height x2.1
    • setIconSize

      public void setIconSize(int iconSize)
      Parameters:
      iconSize - the new icon size: font height x2.1
      Since:
      1.2
    • getScaledSizeInt

      public int getScaledSizeInt(int n)
    • getScaledSizeFloat

      public float getScaledSizeFloat(float n)
    • setLookAndFeel

      public void setLookAndFeel(String lookAndFeelClass)
      1. #prop:p => selectLookAndFeelFromProperty(String, boolean) with (p,true)
      2. #special:v => selectLookAndFeelFromSpecialName(String) with (v)
      3. #default or default => selectLookAndFeelDefault(boolean)
      4. darklaf => installLookAndFeelDarkLaf()
      5. #none => nothing to do. it also clears the "autogui.laf" property for preventing changing LAF by the user
      6. null => nothing to do
      7. otherwise => treats the value as a LAF class-name
      Parameters:
      lookAndFeelClass - the LAF class name or a special configuration name starting from #prop:, #none or #default
      Since:
      1.2
    • selectLookAndFeelFromProperty

      public String selectLookAndFeelFromProperty(String prop, boolean updateProp)
      process LAF resolution for "#prop:p". it reads a LAF class-name from the system property "p". The value of p can be a special name resolved by selectLookAndFeelFromSpecialName(String) or a concrete LAF class-name .

      The default prop is "autogui.laf". This means that the system accepts the property with a special name like "-Dautogui.laf=system" and it can resolve the property with an actual class-name which will be read by the swing system.

      Parameters:
      prop - a nullable property name
      updateProp - if true it updates the prop specified by the laf with the resolved concrete class-name For "darklaf", it clears the property
      Returns:
      a resolved class-name from the property or null
      Since:
      1.3
    • selectLookAndFeelFromSpecialName

      public String selectLookAndFeelFromSpecialName(String name)
      Parameters:
      name - a special name or a class-name
      Returns:
      resolved class name or still special name for some names
      Since:
      1.3
    • selectLookAndFeelDefault

      public String selectLookAndFeelDefault(boolean tryDarklaf)
      process default behavior for the "#default" configuration
      1. try to load Darklaf by installLookAndFeelDarkLaf() if the parameter is true
      2. if macOS environment, use UIManager.getSystemLookAndFeelClassName()
      3. if Windows environment, use "nimbus" (due to failure of size on HiDPI)
      4. if the GDK_SCALE env is set, use "metal"
      5. otherwise, nothing to do
      Parameters:
      tryDarklaf - if true, call installLookAndFeelDarkLaf()
      Returns:
      a resolved LAF class-name or null
      Since:
      1.3
    • installLookAndFeelDarkLaf

      public boolean installLookAndFeelDarkLaf()
      install com.formdev.flatlaf.FlatDarkLaf or .FlatLightLaf by reflection. Note: currently supporting flatlaf:2.0.1--2.1
      Returns:
      true if the darklaf is installed
      Since:
      1.3
    • getLookAndFeelProp

      public static String getLookAndFeelProp(String prop)
      Parameters:
      prop - a property name
      Returns:
      "#prop:"+prop
      Since:
      1.3
    • getLookAndFeelSpecial

      public static String getLookAndFeelSpecial(String value)
      Parameters:
      value - a special name
      Returns:
      "#special:"+value
      Since:
      1.4
    • setLookAndFeelSystemFix

      public void setLookAndFeelSystemFix()
      called from setLookAndFeel(String) and apply some customization
      Since:
      1.2
    • setLookAndFeelFix

      public void setLookAndFeelFix()
      called from setLookAndFeel(String) and apply some customization not depending on LAF.
      Since:
      1.6
    • isTableCustomHighlighting

      public boolean isTableCustomHighlighting()
      Returns:
      if macOS native UI, true for enabling table-view custom highlighting
      Since:
      1.2
    • isTabbedPaneAllowOpaqueComponent

      public boolean isTabbedPaneAllowOpaqueComponent()
      Returns:
      if macOS native UI, true for allowing transparent tab-component
      Since:
      1.2
    • initOsVersion

      public static UIManagerUtil.OsVersion initOsVersion()
      Returns:
      a created OS version of the runtime
      Since:
      1.2
    • getOsVersion

      public UIManagerUtil.OsVersion getOsVersion()
      Returns:
      the OS version of the runtime
      Since:
      1.2
    • command

      public static String command(String... args)
      run a process with the arguments. The timeout for waiting outputs is 10 secs.
      Parameters:
      args - the command arguments
      Returns:
      the standard output of the process. the method throws an exception if failed
      Since:
      1.4