Class UIThemeChooser

All Implemented Interfaces:
EventListener, IFocusComp, IMessageBox, IComponent, ICustomDataProvider, IGProp<GProp<?>[]>, IPropCnr, IUIComp, IUIFocusComp, IVSComponentListener, IVSComponentState, IVSFieldListener, Cloneable
Direct Known Subclasses:
EUIThemeChooser

public class UIThemeChooser extends UIComp implements IUIFocusComp
Theme chooser UI component: the user-facing control of the appearance of an application in v5 (CC-THEME-CHOOSER-UI, ruled 2026-10-18 and 2026-10-19): an icon button an application developer places where he likes - the headers of Test2 and ServerAdmin at the far right - that cycles the mode of the client's theme scheme, light, dark and auto, with one click, and shows the current mode in its icon and its tooltip.

The client does the work. The component carries no state of its own: the client widget (iz/ui/UIThemeChooser.js) applies the choice through the one existing mechanism, izUIScheme.set() of iz/uischeme.js - the same code path as the theme= entry URL member and the Java API IClientSessionGyro.setUIScheme(UISchemes.Family,UISchemes.Mode), with the same persistence (localStorage in a Browser or an installed PWA, the launcher's settings in iiziRun) and the same report to the server (IClientSessionGyro.getUIScheme(), IClientSessionGyro.getUISchemeChoice(), the listeners). Nothing is sent to the server by the component itself. The three texts the tooltip shows, one per mode, are the component's properties PN_LIGHT_TEXT, PN_DARK_TEXT and PN_AUTO_TEXT, each a plain KString that an application binds to its text tables; when a text is not set, the client's own string table (strings_en.js: THEME_LIGHT, THEME_DARK, THEME_AUTO) gives the English default.

Hidden where the application allows one mode only. An application whose App page pins the appearance (ModuleApp.getUIModes(): light only or dark only) has nothing to choose: the component is then hidden (UIComp.setVisible(boolean), no space taken) when the panel is virtualized for a client session, from the modes the session carries (IClientSessionGyro.getUIModes()). In the Designer, where no client session exists, the component is always shown. The rule is isShownFor(int).

Families (IIZI, Graphite, Contrast) are not offered by the component in v5: an application has no allowance of families today, so the ruled "where the application allows more than one" cannot be read; the family drop-down is v5.1 through this same component.

Author:
Christopher Mindus
  • Field Details

    • PN_LIGHT_TEXT

      public static final String PN_LIGHT_TEXT
      The property name of the text shown for the light mode: lightText, a plain KString, absent for the client's default.
      See Also:
    • PN_DARK_TEXT

      public static final String PN_DARK_TEXT
      The property name of the text shown for the dark mode: darkText, a plain KString, absent for the client's default.
      See Also:
    • PN_AUTO_TEXT

      public static final String PN_AUTO_TEXT
      The property name of the text shown for the auto mode (follow the system): autoText, a plain KString, absent for the client's default.
      See Also:
  • Constructor Details

    • UIThemeChooser

      public UIThemeChooser()
      Creates the component without a name. The name must be set in all cases using the setPropertyAtom call.
    • UIThemeChooser

      public UIThemeChooser(Atom propertyAtom)
      Creates the component with the specified name. All system-reserved names for components begins with "$".
      Parameters:
      propertyAtom - the name of the component, unique within it's parent.
    • UIThemeChooser

      public UIThemeChooser(Atom propertyAtom, GProp<?>[] newValue) throws PropException
      Creates the component with the specified name, initialized to contain the GProp items. All system-reserved names for components begins with "$".
      Parameters:
      propertyAtom - The name of the component, unique within it's parent.
      newValue - The array of all properties the component should have.
      Throws:
      PropException - when at least one of the properties to initialize the component with is invalid.
  • Method Details

    • clone

      public UIThemeChooser clone()
      Clones the component.

      Cloning is used for "virtualization" of a property tree in the server.

      Overrides:
      clone in class UIComp
      Returns:
      A cloned instance of the component.
    • getDeviceType

      public final int getDeviceType()
      Gets the device type: -1=mobile, 0=both, 1=desktop.
      Specified by:
      getDeviceType in interface IUIComp
    • isShownFor

      public static boolean isShownFor(int uiModes)
      Checks if the chooser is shown for the modes an application allows: it is shown when the user has a choice, light and dark (UISchemes.MODES_BOTH), and hidden when the application pins one mode (UISchemes.MODES_LIGHT or UISchemes.MODES_DARK). A stored value outside the three (an ERROR of the App page's verification) pins nothing and leaves the chooser shown.
      Parameters:
      uiModes - The modes the application allows, ModuleApp.getUIModes().
      Returns:
      true when the chooser is shown, false when it is hidden.
    • hideWhenOneMode

      public boolean hideWhenOneMode(int uiModes)
      Hides the component when the application allows one mode only, see isShownFor(int).
      Parameters:
      uiModes - The modes the application allows, ModuleApp.getUIModes().
      Returns:
      true when the component was hidden by this call, false when it is shown or was hidden already.
    • onVirtualizationCompleted

      protected void onVirtualizationCompleted(IAppSessionGyro appGyro, IClientSessionGyro clientGyro, VirtualSpace virtualSpace, boolean isPostResolve)
      Called when virtualization completed: the component is hidden when the client session's application allows one mode only (IClientSessionGyro.getUIModes()), before the tree is sent to the client, so that no space is taken for it.

      This method is called to the entire tree of the newly virtualized property container.

      Overrides:
      onVirtualizationCompleted in class PropCnr
      Parameters:
      appGyro - The application gyro instance performing the virtualization.
      clientGyro - The client gyro session, can be null if not initialized from the client gyro.
      virtualSpace - The virtualized VirtualSpace.
      isPostResolve - Flag indicating this call is done after references are attempted to be resolved.
    • getLightText

      public PlainKString getLightText()
      Gets the text shown for the light mode.
      Returns:
      The text replacing the client's default 'Light', null for the default.
    • setLightText

      public boolean setLightText(String text)
      Sets the text shown for the light mode.
      Parameters:
      text - The text replacing the client's default 'Light', null for the default.
      Returns:
      true if changed, false for no change.
    • getDarkText

      public PlainKString getDarkText()
      Gets the text shown for the dark mode.
      Returns:
      The text replacing the client's default 'Dark', null for the default.
    • setDarkText

      public boolean setDarkText(String text)
      Sets the text shown for the dark mode.
      Parameters:
      text - The text replacing the client's default 'Dark', null for the default.
      Returns:
      true if changed, false for no change.
    • getAutoText

      public PlainKString getAutoText()
      Gets the text shown for the auto mode (follow the system).
      Returns:
      The text replacing the client's default 'Auto', null for the default.
    • setAutoText

      public boolean setAutoText(String text)
      Sets the text shown for the auto mode (follow the system).
      Parameters:
      text - The text replacing the client's default 'Auto', null for the default.
      Returns:
      true if changed, false for no change.
    • getApproximateSize

      public Size getApproximateSize()
      Returns the size of the component in pixels: the 16 x 16 icon box of its button, the size of a menu item's icon node in the shipped desktop themes.
      Specified by:
      getApproximateSize in class UIComp
      Returns:
      The size 16x16.