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()
    • uiManagerColor

      protected Color uiManagerColor(String... names)
    • toConcreteColor

      public Color toConcreteColor(Color c)
    • getLabelForeground

      public Color getLabelForeground()
    • getLabelBackground

      public Color getLabelBackground()
    • getLabelDisabledForeground

      public Color getLabelDisabledForeground()
    • getTextPaneSelectionBackground

      public Color getTextPaneSelectionBackground()
    • getTextPaneSelectionForeground

      public Color getTextPaneSelectionForeground()
    • getTextPaneForeground

      public Color getTextPaneForeground()
      (changed to use TextField.foreground from TextPane.foreground due to getTextPaneBackground())
      Returns:
      the text pane foreground
      Since:
      1.2
    • getTextPaneBackground

      public Color getTextPaneBackground()
      (changed to use TextField.background from TextPane.background due to GTK always returns white)
      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 => rewrite the param by selectLookAndFeelFromProperty(String, boolean) with (p,true); the method sets the property with #none for preventing multiple installation of same LAF. Continues with the following steps.
      2. #special:v => rewrite the param by selectLookAndFeelFromSpecialName(String) with (v). Continues with the following steps.
      3. #default, default or default-no-darklaf => selectLookAndFeelDefault(boolean) with (false if default-no-darklaf, otherwise true )
      4. darklaf or flatlaf=> installLookAndFeelFlatlaf()
      5. #none => nothing to do
      6. null => nothing to do
      7. otherwise => treats the value as a LAF class-name; loading by UIManager.setLookAndFeel(String). If the class-name is UIManager.getSystemLookAndFeelClassName(), setLookAndFeelSystemFix().
      After the above steps, setLookAndFeelFix().
      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 sets the prop to #none
      Returns:
      a resolved class-name or a special value 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
      See Also:
    • selectLookAndFeelDefault

      public String selectLookAndFeelDefault(boolean tryDarklaf)
      process default behavior for the "#default" configuration
      1. try to load Flatlaf by installLookAndFeelFlatlaf() if the parameter is true
      2. if macOS environment and UIManagerUtil.OsVersion.isDarkTheme()=false, use UIManager.getSystemLookAndFeelClassName(),
      3. otherwise, selectLookAndFeelFromSpecialName(String) with "nimbus-flat"
      Parameters:
      tryDarklaf - if true, call installLookAndFeelFlatlaf()
      Returns:
      a resolved LAF class-name or null
      Since:
      1.3
    • installLookAndFeelDarklaf

      public boolean installLookAndFeelDarklaf()
      See Also:
    • installLookAndFeelFlatlaf

      public boolean installLookAndFeelFlatlaf()
      install com.formdev.flatlaf.FlatDarkLaf or .FlatLightLaf by reflection. Note: currently supporting flatlaf:2.0.1--3.1.1 Since v3, flatlaf supports com.formdev.flatlaf.themes.{FlatMacDarkLaf, FlatMacLightLaf}.
      Returns:
      true if the flatlaf is installed
      Since:
      1.3
    • getLookAndFeelDarkLafClass

      protected Class<?> getLookAndFeelDarkLafClass() throws ClassNotFoundException
      Throws:
      ClassNotFoundException
    • 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