commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Simon Kitching <skitch...@apache.org>
Subject Re: [digester] setting mnemonic on a jmenu
Date Fri, 28 Oct 2005 22:48:28 GMT
On Thu, 2005-10-27 at 13:05 -0700, Dmitry Beransky wrote:
> Hi,
> 
> I'm using the digester to build a swing menu from an xml descriptor and 
> having a hard time getting JMenu.setMnemonic to work.
> 
> Here's an XML sample:
> 
> <menuBar>
>     <menu title="File" hotKey="F"/>
> </menuBar>
> 
> and Digester rules:
> 
>        digester.addObjectCreate("menuBar", JMenuBar.class);
>        digester.addObjectCreate("*/menu", "javax.swing.JMenu", "class");
>        digester.addSetProperties("*/menu", "title", "text");
>        digester.addSetProperties("*/menu", "hotKey", "mnemonic");
> 
>        digester.addObjectCreate("*/item", "javax.swing.JMenuItem", "class");
>        digester.addSetProperties("*/item", "title", "text");
>        digester.addSetProperties("*/item", "enabled", "enabled");
>        digester.addSetNext("*/item", "add");
> 
>        digester.addObjectCreate("*/item/action", null, "class");
>        digester.addSetNext("*/item/action", "setAction");
> 
>        digester.addObjectCreate("*/separator", JSeparator.class);
>        digester.addSetNext("*/separator", "add");
> 
>        digester.addSetNext("*/menu", "add");
> 
> when I run the xml through the rules, the mnemonic key doesn't get set. I 
> think it has to do with the fact that JMenu has two overlaoded 
> setMnemonic() functions: one with an int argument and the other with a char.
> 
> What can I do to get the mnemonic key set?

You can probably confirm what the problem is by enabling logging.
Digester outputs lots of logging info via commons-logging to whatever
logging library your app is using. Just configure that logging lib to
output DEBUG level for category "org.apache.commons.digester" and you
should see whether your guess is right.

If the problem is indeed the overloaded setMnemonic method then you can
use
 Digester.addSetProperties(java.lang.String pattern, 
   java.lang.String[] attributeNames, 
   java.lang.String[] propertyNames)
to explicitly ignore just the "mnemonic" attribute. Just set
attributeNames to an array with one element: "mnemonic", and
propertyNames to null (or an array with one null element).

The CallMethodRule variant that takes an explicit list of parameter
types can then be used to set the problem property.

Regards,

Simon



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message