Class Theme

java.lang.Object
io.keikai.axyra.sheets.style.Theme

public final class Theme extends Object
An immutable workbook theme: the 12-slot color scheme plus the major (heading) and minor (body) font names. Color.theme(int) references resolve against these colors. Read it with Workbook.theme(), which returns null when the workbook has no theme. Write it with Workbook.setTheme(Theme).

Color slots are six-digit hex tokens without a leading #, e.g. "4472C4". A system color in the source file (<a:sysClr>) reads back as its last resolved value: "000000" for windowText, "FFFFFF" for window. color(Slot) returns the raw token and rgb(Slot) the parsed Color.

The slot order is the theme-file order (Theme.Slot). It differs from the index that Color.theme(int) takes: there, 0 is light 1 and 1 is dark 1.


 Theme t = workbook.theme().toBuilder()
         .color(Theme.Slot.ACCENT1, Color.rgb(0x1F, 0x4E, 0x79))
         .build();
 workbook.setTheme(t);
 
  • Field Details

    • SLOT_COUNT

      public static final int SLOT_COUNT
      Number of color slots in a theme.
      See Also:
  • Method Details

    • of

      public static Theme of(String[] colors, String majorFont, String minorFont)
      Builds a theme from raw tokens. Prefer builder() in application code.
      Parameters:
      colors - the color tokens in Theme.Slot order; a shorter array leaves the remaining slots null, a longer one is cut to 12, and null leaves every slot null
      majorFont - the heading font name; null becomes ""
      minorFont - the body font name; null becomes ""
      Returns:
      the theme
    • color

      public String color(Theme.Slot slot)
      The raw color token of a slot, e.g. "4472C4".
      Parameters:
      slot - the slot
      Returns:
      the token, or null when the slot is unset
    • rgb

      public Color rgb(Theme.Slot slot)
      The color of a slot as an RGB Color.
      Parameters:
      slot - the slot
      Returns:
      the color, or null when the slot is unset, empty or not a hex token
    • majorFont

      public String majorFont()
      The major (heading) font name, e.g. "Calibri Light"; never null.
    • minorFont

      public String minorFont()
      The minor (body) font name, e.g. "Calibri"; never null. Cells whose font uses the minor scheme render in it.
    • colors

      public String[] colors()
      The 12 raw color tokens in Theme.Slot order.
      Returns:
      a new array on each call; entries may be null
    • toBuilder

      public Theme.Builder toBuilder()
      A builder pre-loaded with this theme's colors and fonts, for changing a few slots.
      Returns:
      a new builder
    • builder

      public static Theme.Builder builder()
      A builder with every color slot unset and the fonts "Calibri Light" (major) and "Calibri" (minor). Set all 12 slots before Workbook.setTheme: an unset slot is saved as an empty, invalid color. To change a few slots, start from workbook.theme().toBuilder().
      Returns:
      a new builder