Class ColorRefRefactor
java.lang.Object
com.iizix.prop.ColorRefRefactor
The refactoring of
% color references (THEME-DESIGN section 5, phase B3): when a palette color, or a folder of palette colors, is renamed or moved in the Designer, every GColor reference that named it - in a panel's or a style's ColorProp, a FillProp's solid fill or a StrokeProp's stroke, in any loaded module - is rewritten to the new path, in the form the holder wrote it: a module-qualified reference stays qualified, a module-relative one stays relative while the color stays in the holder's module, and a bare name stays bare while the color stays at the top of that module's style folder. A pointer held as a ColorReference needs none of this: it listens to its target and rewrites itself.The rewrite is a value change on each holder (GProp.setPropValue(Object)), so the file that holds it goes dirty and the undo of the rename - which renames back and arrives here as another rename - rewrites the references back. The Designer's hook that turns a rename or move event into the two canonical paths is com.iizigo.color.ColorRefactoring; this class is the tree walk and the rewriting, headless and testable.
A canonical path is Module:/style/..., the module being the one GProp.getReferencePropName() names for the holder.
- Author:
- Christopher Mindus
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordOne rewritten reference.Method Summary
Modifier and TypeMethodDescriptionstatic StringGets the canonical form of a reference as a holder wrote it:Module:/style/....static StringGets the module of a holder: what its reference name starts with, before the colon.static StringpreferredForm(GProp<?> holder, String current, String canonical) Gets the reference a holder should write for a canonical path, in the form of the reference it holds now.static List<ColorRefRefactor.Rewritten> rename(Collection<? extends PropCnr> roots, String oldCanonical, String newCanonical) Rewrites every%reference under the roots that names a canonical path, or a path under it, to the same path under a new canonical path.
Method Details
moduleOf
canonical
Gets the canonical form of a reference as a holder wrote it:Module:/style/....- Parameters:
holder- The property holding the reference.ref- The reference, without the leading%: module-qualified, module-relative, or a bare name.- Returns:
- The canonical path; a module-relative or bare reference of a holder without a module is returned module-relative.
preferredForm
Gets the reference a holder should write for a canonical path, in the form of the reference it holds now.- Parameters:
holder- The property holding the reference.current- The reference it holds now, without the leading%.canonical- The canonical path the reference should now name.- Returns:
- The new reference: qualified when the current one is, or when the path is in another module; bare when the current one is bare and the path is at the top of the holder's module's style folder; module-relative otherwise.
rename
public static List<ColorRefRefactor.Rewritten> rename(Collection<? extends PropCnr> roots, String oldCanonical, String newCanonical) Rewrites every%reference under the roots that names a canonical path, or a path under it, to the same path under a new canonical path.- Parameters:
roots- The trees to walk: the loaded module roots.oldCanonical- The canonical path of the palette color or folder as it was.newCanonical- The canonical path as it is now.- Returns:
- What was rewritten, possibly empty, never null.