commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <simon.kitch...@xtra.co.nz>
Subject Re: [digester] converting resource uri to an object
Date Thu, 01 Jan 1970 00:00:00 GMT
It looks pretty good to me; I don't think I'd do anything different.

---- Dmitry Beransky <db01@dembel.org> wrote: 
> Hi,
> 
> Could you guys tell me if I'm doing this right?..
> 
> for the following fragment:
> 
> <menu>
>    <item>
>       <action class="csaswing.action.MoveToFirstRowAction">
>          <icon>/resources/pics/top.png</icon>
>       </action>
>    </item>
> </menu>
> 
> I need to end up with roughly this sequence:
> 
> 1. JMenu menu = new JMenu();
> 2. JMenuItem item = new JMenuItem();
> 3. Action action = new MoveToFirstRowAction();
> 4. Icon icon = new ImageIcon(getClass().getResource("/resources/pics/top.png"));
> 5. action.putValue(Action.SMALL_ICON, icon);
> 6. item.setAction(action);
> 7. menu.add(item);
> 
> and here's how I've implemented it:
> 
>    digester.addObjectCreate("*/menu/item", "javax.swing.JMenuItem", "class");
>    digester.addObjectCreate("*/menu/item/action", null, "class");
> 
>    digester.addCallMethod("*/menu/item/action/title", "putValue", 2,
> new Class[] {String.class, Object.class});
>    digester.addObjectParam("*/menu/item/action/title", 0, Action.NAME);
>    digester.addCallParam("*/menu/item/action/title", 1);
>    digester.addRule("*/menu/item/action/icon", new IconRule());
> 
>    digester.addSetNext("*/menu/item/action", "setAction");
> 
> where IconRule is:
> 
> class IconRule extends Rule {
>      Icon icon;
> 
>      public void body(String ns, String name, String text) throws Exception {
>          icon = new ImageIcon(MenuBuilder.class.getResource(text));
>      }
> 
>      public void end(String string, String string1) throws Exception {
>          ((Action)getDigester().peek()).putValue(Action.SMALL_ICON, icon);
>      }
> }
> 
> My custom icon rule bugs me a little bit, but I'm not sure why.  Is
> there a better, cleaner way of implementing this whole thing?
> 
> Thanks
> Dmitry
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 


---------------------------------------------------------------------
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