[izpack-devel] patch: use intance number to customize strings
Stefan Wachter
stefan.wachter at gmx.de
Thu Nov 16 14:52:40 CET 2006
Hi all,
I have several UserInputPanels that should have different headlines. I looked into the code and
recognized that only a single headline can be configured that is used for all UserInputPanels.
Therefore I patched the getI18nStringForClass(String subkey) method in the IzPanel class to consider
instance numbers and added the method getInstanceNumber() with a default implementation that returns -1:
// start code
public String getI18nStringForClass(String subkey)
{
String retval = null;
Class clazz = this.getClass();
while (retval == null && !clazz.getName().endsWith(".IzPanel"))
{
int instanceNumber = getInstanceNumber();
if (instanceNumber != -1) {
retval = getI18nStringForClass(clazz.getName(), subkey + "." + instanceNumber, null);
if (retval != null) return retval;
}
retval = getI18nStringForClass(clazz.getName(), subkey, null);
clazz = clazz.getSuperclass();
}
return (retval);
}
protected int getInstanceNumber() { return -1; }
// end code
In order to make use of this new flexibility, I overloaded the getInstanceNumber() method in the
UserInputPanel class returning the instance number of the UserInputPanel:
// start code
protected int getInstanceNumber() { return instanceNumber; }
// end code
Now different headlines can be configured for the various UserInputPanels. For example:
<langpack>
<str id="UserInputPanel.headline.0" txt="Rechnername und Port"/>
<str id="UserInputPanel.headline.1" txt="Shortcuts"/>
<str id="UserInputPanel.headline.2" txt="PolFHa-Server starten"/>
</langpack>
Is this code of public interest? Will someone integrate it into IzPack?
Cheers,
--Stefan
More information about the izpack-devel
mailing list