Class MacUtilities

java.lang.Object
org.tentackle.fx.MacUtilities

@Service(MacUtilities.class) public class MacUtilities extends Object
Utilities for Mac OS X.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates the MacUtilities.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected javafx.scene.image.ImageView
    createImageView(org.kordamp.ikonli.javafx.FontIcon fontIcon)
    Creates an ImageView from a FontIcon.
    The font icon is modified and must not be used anymore.
    protected javafx.scene.paint.Color
    Gets the color to render the system menu icons with.
    The singleton.
    protected void
    observeTheme(javafx.scene.control.MenuBar menuBar)
    Updates the system menu bars whenever the theme changes.
    Registers the menu bar and subscribes to the theme properties on first invocation.
    protected javafx.scene.Node
    toSystemGraphic(javafx.scene.Node graphic)
    Converts a menu graphic for the system menu.
    FontIcons are rendered to an ImageView.
    protected void
    toSystemMenu(javafx.scene.control.Menu menu)
    Converts FontIcons to ImageViews.
    void
    toSystemMenuBar(javafx.scene.control.MenuBar menuBar)
    Installs a menubar as a system menu bar.
    Used on macOS to convert FontIcons to ImageViews since font icons cannot be displayed in the system menu.
    The menu bar is kept up to date: since the images are rendered for the current theme, they are re-created whenever the light/dark mode or the theme changes.
    protected String
    toWebColor(javafx.scene.paint.Color color)
    Converts a color to its CSS representation.
    protected void
    Re-creates the images of all system menu bars for the current theme.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • MacUtilities

      public MacUtilities()
      Creates the MacUtilities.
  • Method Details

    • getInstance

      public static MacUtilities getInstance()
      The singleton.
      Returns:
      the singleton
    • toSystemMenuBar

      public void toSystemMenuBar(javafx.scene.control.MenuBar menuBar)
      Installs a menubar as a system menu bar.
      Used on macOS to convert FontIcons to ImageViews since font icons cannot be displayed in the system menu.
      The menu bar is kept up to date: since the images are rendered for the current theme, they are re-created whenever the light/dark mode or the theme changes.
      Parameters:
      menuBar - the menu bar
    • toSystemMenu

      protected void toSystemMenu(javafx.scene.control.Menu menu)
      Converts FontIcons to ImageViews.
      Parameters:
      menu - the menu
    • toSystemGraphic

      protected javafx.scene.Node toSystemGraphic(javafx.scene.Node graphic)
      Converts a menu graphic for the system menu.
      FontIcons are rendered to an ImageView. An image view created by a former invocation is rendered again, since the color depends on the current theme. All other graphics are left unchanged.
      Parameters:
      graphic - the menu graphic, null if none
      Returns:
      the graphic to display in the system menu, null if none
    • observeTheme

      protected void observeTheme(javafx.scene.control.MenuBar menuBar)
      Updates the system menu bars whenever the theme changes.
      Registers the menu bar and subscribes to the theme properties on first invocation.
      Parameters:
      menuBar - the system menu bar
    • updateSystemMenuBars

      protected void updateSystemMenuBars()
      Re-creates the images of all system menu bars for the current theme.
    • createImageView

      protected javafx.scene.image.ImageView createImageView(org.kordamp.ikonli.javafx.FontIcon fontIcon)
      Creates an ImageView from a FontIcon.
      The font icon is modified and must not be used anymore.
      Parameters:
      fontIcon - the font icon
      Returns:
      the image view
    • getIconColor

      protected javafx.scene.paint.Color getIconColor()
      Gets the color to render the system menu icons with.
      Returns:
      the icon color
    • toWebColor

      protected String toWebColor(javafx.scene.paint.Color color)
      Converts a color to its CSS representation.
      Parameters:
      color - the color
      Returns:
      the CSS color function