Remove weird feature to allow overriding subskins via mainskin, making skin lookup code much simpler. Fix bug to find base skin in skinpath from extended skin in prototype repository.

This commit is contained in:
hns 2009-04-17 20:41:00 +00:00
parent 1af914b6b1
commit 4875a85fce
2 changed files with 38 additions and 60 deletions

View file

@ -333,39 +333,25 @@ public final class Prototype {
* other locations or database stored skins. If parentName and * other locations or database stored skins. If parentName and
* subName are defined, the skin may be a subskin of another skin. * subName are defined, the skin may be a subskin of another skin.
*/ */
public Skin getSkin(String skinName, String parentName, String subName) public Skin getSkin(Prototype proto, String skinname, String subskin, Object[] skinpath)
throws IOException { throws IOException {
Skin skin = null; Resource res = skinMap.getResource(skinname);
Resource res = skinMap.getResource(skinName);
while (res != null) { while (res != null) {
skin = Skin.getSkin(res, app); Skin skin = Skin.getSkin(res, app);
if (skin.hasMainskin()) if (subskin == null && skin.hasMainskin()) {
break; return skin;
String extendz = skin.getExtends(); } else if (subskin != null && skin.hasSubskin(subskin)) {
if (extendz != null && extendz != skinName) return skin.getSubskin(subskin);
return getSkin(extendz, null, null); }
String baseskin = skin.getExtends();
if (baseskin != null && !baseskin.equalsIgnoreCase(skinname)) {
// we need to call SkinManager.getSkin() to fetch overwritten
// base skins from skinpath
return app.skinmgr.getSkin(proto, baseskin, subskin, skinpath);
}
res = res.getOverloadedResource(); res = res.getOverloadedResource();
} }
if (parentName != null) { return null;
Skin parentSkin = null;
Resource parentResource = skinMap.getResource(parentName);
while (parentResource != null) {
parentSkin = Skin.getSkin(parentResource, app);
if (parentSkin.hasSubskin(subName))
break;
String extendz = parentSkin.getExtends();
if (extendz != null && extendz != parentName)
return getSkin(extendz, extendz, subName);
parentResource = parentResource.getOverloadedResource();
}
if (parentResource != null) {
if (res != null && app.getResourceComparator().compare(res, parentResource) > 0)
return skin;
else
return parentSkin.getSubskin(subName);
}
}
return skin;
} }
/** /**

View file

@ -42,50 +42,43 @@ public final class SkinManager implements FilenameFilter {
skinExtension = ".skin"; skinExtension = ".skin";
} }
protected Skin getSkin(Prototype prototype, String skinname, Object[] skinpath) public Skin getSkin(Prototype prototype, String skinname, Object[] skinpath)
throws IOException { throws IOException {
if (prototype == null) { if (prototype == null) {
return null; return null;
} }
Skin skin; // if name contains '#' split name into mainskin and subskin
Prototype proto = prototype; String subskin = null;
// if name contains #, this may be a subskin of some other skin
String parentName = null, subskinName = null;
int hash = skinname.indexOf('#'); int hash = skinname.indexOf('#');
if (hash > -1) { if (hash > -1) {
parentName = skinname.substring(0, hash); subskin = skinname.substring(hash + 1);
subskinName = skinname.substring(hash + 1); skinname = skinname.substring(0, hash);
}
return getSkin(prototype, skinname, subskin, skinpath);
} }
// First check if the skin has been already used within the execution of this request public Skin getSkin(Prototype prototype, String skinname,
// check for skinsets set via res.skinpath property String subskin, Object[] skinpath)
do { throws IOException {
Prototype proto = prototype;
// Loop over prototype chain and check skinpath and prototype skin resources
while (proto != null) {
Skin skin;
if (skinpath != null) { if (skinpath != null) {
for (int i = 0; i < skinpath.length; i++) { for (int i = 0; i < skinpath.length; i++) {
skin = getSkinInPath(skinpath[i], proto.getName(), skinname); skin = getSkinInPath(skinpath[i], proto.getName(), skinname);
if (skin != null) { if (skin != null) {
// check if skin skin contains main skin // check if skin skin contains main skin
if (skin.hasMainskin()) { if (subskin == null && skin.hasMainskin()) {
return skin; return skin;
} else if (subskin != null && skin.hasSubskin(subskin)) {
return skin.getSubskin(subskin);
} }
String extendz = skin.getExtends(); String baseskin = skin.getExtends();
if (extendz != null && !extendz.equals(skinname)) { if (baseskin != null && !baseskin.equals(skinname)) {
return getSkin(prototype, extendz, skinpath); return getSkin(prototype, baseskin, subskin, skinpath);
}
} else if (parentName != null) {
// get parent skin
skin = getSkinInPath(skinpath[i], proto.getName(), parentName);
// check if it contains subskin
if (skin != null) {
if (skin.hasSubskin(subskinName)) {
return skin.getSubskin(subskinName);
}
String extendz = skin.getExtends();
if (extendz != null && !extendz.equals(skinname)) {
return getSkin(prototype, extendz + "#" + subskinName, skinpath);
}
} }
} }
} }
@ -93,15 +86,14 @@ public final class SkinManager implements FilenameFilter {
// skin for this prototype wasn't found in the skinsets. // skin for this prototype wasn't found in the skinsets.
// the next step is to look if it is defined as skin file in the application directory // the next step is to look if it is defined as skin file in the application directory
skin = proto.getSkin(skinname, parentName, subskinName); skin = proto.getSkin(prototype, skinname, subskin, skinpath);
if (skin != null) { if (skin != null) {
return skin; return skin;
} }
// still not found. See if there is a parent prototype which might define the skin. // still not found. See if there is a parent prototype which might define the skin.
proto = proto.getParentPrototype(); proto = proto.getParentPrototype();
} while (proto != null); }
// looked every where, nothing to be found // looked every where, nothing to be found
return null; return null;