Class RecentColors
java.lang.Object
com.iizigo.prop.editor.color.swt.RecentColors
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
FieldsConstructor Summary
ConstructorsMethod Summary
Modifier and TypeMethodDescriptionintcapacity()Gets the bound.intcellColor(int index) Gets a color for a grid cell: the color, or 0 for a cell past the held colors.static RecentColorsfromPreferenceString(String s, int capacity) Parses a preference string written bytoPreferenceString()(or by the Swing chooser'sRecentSwatches, the same format).intget(int index) Gets a color.getRGBA(int index) Gets a color as an SWT RGBA.static RecentColorsload(IPreferenceStore store, int capacity) Loads the list from a preference store underPREF_KEY.voidsave(IPreferenceStore store) Saves the list to a preference store underPREF_KEY.intsize()Gets the number of colors held, at most the capacity.int[]toArray()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.toString()booleanuse(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.
Field Details
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 tosize()-1.- Returns:
- The ARGB value.
- Throws:
IndexOutOfBoundsException- For an index outside the held colors.
getRGBA
Gets a color as an SWT RGBA.- Parameters:
index- Zero for the most recent, up tosize()-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
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
Parses a preference string written bytoPreferenceString()(or by the Swing chooser'sRecentSwatches, 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
Saves the list to a preference store underPREF_KEY.- Parameters:
store- The store.
load
Loads the list from a preference store underPREF_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