01: /*
02: * Copyright 2000,2005 wingS development team.
03: *
04: * This file is part of wingS (http://wingsframework.org).
05: *
06: * wingS is free software; you can redistribute it and/or modify
07: * it under the terms of the GNU Lesser General Public License
08: * as published by the Free Software Foundation; either version 2.1
09: * of the License, or (at your option) any later version.
10: *
11: * Please see COPYING for the complete licence.
12: */
13: package org.wings.plaf.css;
14:
15: import org.wings.SComponent;
16: import org.wings.SIcon;
17: import org.wings.SMenuItem;
18: import org.wings.io.Device;
19: import org.wings.plaf.Update;
20: import org.wings.util.KeystrokeUtil;
21:
22: import javax.swing.*;
23: import java.io.IOException;
24:
25: public class MenuItemCG extends ButtonCG implements
26: org.wings.plaf.MenuItemCG {
27:
28: private static final long serialVersionUID = 1L;
29:
30: protected void writeItemContent(final Device device,
31: SMenuItem menuItem) throws IOException {
32: SIcon icon = getIcon(menuItem);
33: if (icon != null) {
34: device.print("<img align=\"middle\"");
35: Utils.optAttribute(device, "src", icon.getURL());
36: Utils.optAttribute(device, "width", icon.getIconWidth());
37: Utils.optAttribute(device, "height", icon.getIconHeight());
38: Utils.attribute(device, "alt", icon.getIconTitle());
39: device.print("/>");
40: }
41: String text = menuItem.getText();
42: if (text != null) {
43: Utils.write(device, text);
44: }
45: KeyStroke acc = menuItem.getAccelerator();
46: if (acc != null) {
47: device.print(" <span class=\"accelerator\">");
48: Utils.write(device, KeystrokeUtil.keyStroke2String(acc));
49: device.print("</span>");
50: }
51: }
52:
53: public void writeInternal(final Device device,
54: final SComponent component) throws IOException {
55: final SMenuItem menuItem = (SMenuItem) component;
56: writeItemContent(device, menuItem);
57: }
58:
59: public Update getComponentUpdate(SComponent component) {
60: SComponent parentMenu = ((SMenuItem) component).getParentMenu();
61: if (parentMenu != null)
62: return parentMenu.getCG().getComponentUpdate(parentMenu);
63: else
64: return super.getComponentUpdate(component);
65: }
66:
67: }
|