Class RecentColors

java.lang.Object
com.iizigo.prop.editor.color.swt.RecentColors

public final class RecentColors extends Object
The recently picked colors of the SWT color chooser (CC-COLOR-CHOOSER-SWT-PANELS, 2026-10-10): a bounded list of ARGB values, the most recent first, without duplicates, persisted in the com.iizigo preference store.

The preference key and the string format are those of the Swing chooser's RecentSwatches (CC-FIX-COLOR-CHOOSER): the ARGB values as eight upper-case hex digits, most recent first, separated by commas - so the recents a user picked in the Swing chooser are read unchanged by this one when the callers switch.

No widget dependency: the store is handed in by the caller and the round trip is tested headless.

Author:
Christopher Mindus
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    The preference key in the com.iizigo preference store (instance scope); the Swing chooser's key, kept.
  • Constructor Summary

    Constructors
    Constructor
    Description
    RecentColors(int capacity)
    Creates an empty list.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Gets the bound.
    int
    cellColor(int index)
    Gets a color for a grid cell: the color, or 0 for a cell past the held colors.
    fromPreferenceString(String s, int capacity)
    Parses a preference string written by toPreferenceString() (or by the Swing chooser's RecentSwatches, the same format).
    int
    get(int index)
    Gets a color.
    getRGBA(int index)
    Gets a color as an SWT RGBA.
    load(IPreferenceStore store, int capacity)
    Loads the list from a preference store under PREF_KEY.
    void
    Saves the list to a preference store under PREF_KEY.
    int
    Gets the number of colors held, at most the capacity.
    int[]
    Gets the colors held, most recent first, as a copy.
    Formats the list for the preference store: the ARGB values as eight upper-case hex digits, most recent first, separated by commas.
     
    boolean
    use(int argb)
    Records that a color was picked: it moves to the front; a color already present is moved, not duplicated; the oldest falls off when the list is full.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • PREF_KEY

      public static final String PREF_KEY
      The preference key in the com.iizigo preference store (instance scope); the Swing chooser's key, kept.
      See Also:
  • Constructor Details

    • RecentColors

      public RecentColors(int capacity)
      Creates an empty list.
      Parameters:
      capacity - The bound, at least 1.
      Throws:
      IllegalArgumentException - When the capacity is below 1.
  • Method Details

    • capacity

      public int capacity()
      Gets the bound.
    • size

      public int size()
      Gets the number of colors held, at most the capacity.
    • get

      public int get(int index)
      Gets a color.
      Parameters:
      index - Zero for the most recent, up to size()-1.
      Returns:
      The ARGB value.
      Throws:
      IndexOutOfBoundsException - For an index outside the held colors.
    • getRGBA

      public RGBA getRGBA(int index)
      Gets a color as an SWT RGBA.
      Parameters:
      index - Zero for the most recent, up to size()-1.
    • cellColor

      public int cellColor(int index)
      Gets a color for a grid cell: the color, or 0 for a cell past the held colors.
      Parameters:
      index - The cell.
    • use

      public boolean use(int argb)
      Records that a color was picked: it moves to the front; a color already present is moved, not duplicated; the oldest falls off when the list is full.
      Parameters:
      argb - The color.
      Returns:
      true if the list changed, false when the color already was the most recent.
    • toPreferenceString

      public String toPreferenceString()
      Formats the list for the preference store: the ARGB values as eight upper-case hex digits, most recent first, separated by commas. Empty for no colors.
    • fromPreferenceString

      public static RecentColors fromPreferenceString(String s, int capacity)
      Parses a preference string written by toPreferenceString() (or by the Swing chooser's RecentSwatches, the same format). Entries that are not hex numbers are skipped, duplicates are dropped and the list is cut at the capacity, so a hand-edited or corrupted value yields a usable list rather than an exception.
      Parameters:
      s - The string, null or empty for no colors.
      capacity - The bound of the list returned.
      Returns:
      The list, never null.
    • save

      public void save(IPreferenceStore store)
      Saves the list to a preference store under PREF_KEY.
      Parameters:
      store - The store.
    • load

      public static RecentColors load(IPreferenceStore store, int capacity)
      Loads the list from a preference store under PREF_KEY.
      Parameters:
      store - The store.
      capacity - The bound of the list returned.
      Returns:
      The list, empty when the store holds nothing.
    • toArray

      public int[] toArray()
      Gets the colors held, most recent first, as a copy.
    • toString

      public String toString()
      Overrides:
      toString in class Object