Class CalendarPalette

java.lang.Object
org.exoplatform.caldav.utils.CalendarPalette

public final class CalendarPalette extends Object
Gives every remote calendar a colour, deterministically.

A port of the browser connector's derivation, arithmetic included, because the colour is what a user recognises a calendar by. Changing it would silently repaint everyone's agenda on the day this ships — the same events, the same calendars, different colours, with nothing to explain it.

The server's own colour wins when it publishes one. Only when it does not is a colour derived, from the collection path rather than from its position in a listing: a calendar added or removed elsewhere must not shift the colours of the others.

  • Method Details

    • inStableOrder

      public static List<String> inStableOrder(List<String> hrefs)
      The calendars in the order colours are derived from, which is not the order a server happens to list them in.

      Sorted by href so that a position is a property of the account rather than of one response: a server free to reorder its listing would otherwise repaint the calendars between two reads.

      Parameters:
      hrefs - the collection hrefs
      Returns:
      the same hrefs, in a stable order
    • colourOf

      public static String colourOf(String publishedColour, String href, int position, int total)
      The colour a calendar is shown in.
      Parameters:
      publishedColour - what the server published, possibly absent
      href - the collection href
      position - the calendar's index in the stable order
      total - how many calendars the account holds
      Returns:
      a hex colour that is always usable
    • normalise

      public static String normalise(String value)
      A published colour reduced to the form eXo uses, or null when it is not a colour at all.
      Parameters:
      value - what the server published
      Returns:
      #RRGGBB upper case, or null