01: package fr.aliacom.form.swt.maker;
02:
03: import org.eclipse.swt.SWT;
04: import org.eclipse.swt.graphics.Image;
05: import org.eclipse.swt.widgets.Menu;
06: import org.eclipse.swt.widgets.MenuItem;
07: import org.w3c.dom.Element;
08:
09: import fr.aliacom.common.ui.IconFactory;
10: import fr.aliacom.form.common.FormLoader;
11: import fr.aliacom.form.common.IFormComponent;
12: import fr.aliacom.form.swt.BuilderFactory;
13: import fr.aliacom.form.swt.SWTCommandBuilder;
14: import fr.aliacom.form.swt.SWTMenuItem;
15: import fr.aliacom.form.swt.utils.SWTUtils;
16:
17: /**
18: * Menu Item, leaf node
19: *
20: * @author tom
21: *
22: * (C) 2001, 2002 Thomas Cataldo
23: */
24: public final class MenuItemBuilder extends SWTCommandBuilder {
25:
26: /**
27: * @see fr.aliacom.form.swt.SWTBuilder#build(Element, IFormComponent, FormLoader, BuilderFactory)
28: */
29: public IFormComponent build(Element elem, IFormComponent parent,
30: FormLoader loader, BuilderFactory factory) {
31: Menu menu = (Menu) parent.getNativeWidget();
32: MenuItem item = new MenuItem(menu, SWT.PUSH);
33: if (elem.hasAttribute("icon")) {
34: Image img = (Image) IconFactory.get(
35: elem.getAttribute("icon")).getNativeWidget();
36: /* Transparent .gif does not work for menuitems on a winxp test setup
37: * Or maybe I'm to lame to set it up correctly :-(
38: */
39: img.setBackground(item.getParent().getParent()
40: .getBackground());
41: item.setImage(img);
42: SWTUtils.addDisposeHandler(item, img);
43: }
44: if (elem.hasAttribute("javaAction")) {
45: initFromJavaAction(new SWTMenuItem(item), elem, loader
46: .getForm());
47: } else {
48: initFromPythonAction(new SWTMenuItem(item), elem, loader
49: .getForm(), loader.getCtx());
50: }
51: return null;
52: }
53:
54: }
|