- /** adds a theme mapping, retemplatizing as needed */
- public static void retheme(String from, String to) {
- if (Log.on) Log.log(Template.class, "retheming from " + from + " to " + to);
- XWF.flushXWFs();
- Resources.mapFrom.addElement(from);
- Resources.mapTo.addElement(to);
-
- // clear changed marker and relink
- Template[] t = new Template[cache.size()];
- Enumeration e = cache.elements();
- for(int i=0; e.hasMoreElements(); i++) t[i] = (Template)e.nextElement();
- for(int i=0; i<t.length; i++) {
- t[i].changed = false;
- t[i].numunits = -1;
- t[i].link(true);
- }
-
- for(int i=0; i<Surface.allSurfaces.size(); i++) {
- Box b = ((Surface)Surface.allSurfaces.elementAt(i)).root;
- if (b != null) reapply(b);
- }
- }
-
- /** template reapplication procedure */
- private static void reapply(Box b) {
-
- // Ref 7.5.1: check if we need to retemplatize
- boolean retemplatize = false;
- if (b.templatename != null) {
- Template t = getTemplate(b.templatename, b.importlist);
- if (t != b.template) retemplatize = true;
- b.template = t;
- }
- if (b.template != null && b.template.changed)
- retemplatize = true;
-
- if (retemplatize) {
-
- // Ref 7.5.2: "Preserve all properties on the box mentioned in the <preserve> elements of any
- // of the templates which would be applied in step 7."
- Vec keys = new Vec();
- b.template.gatherPreserves(keys);
- Object[] vals = new Object[keys.size()];
- for(int i=0; i<keys.size(); i++) vals[i] = b.get(((String)keys.elementAt(i)), null);
-
- // Ref 7.5.3: "Remove and save all children of the box, or its redirect target, if it has one"
- Box[] kids = null;
- if (b.redirect != null) {
- kids = new Box[b.redirect.numChildren()];
- for(int i=b.redirect.numChildren() - 1; i >= 0; i--) {
- kids[i] = b.redirect.getChild(i);
- kids[i].remove();