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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to