1 14 package org.wings.plaf.css; 15 16 17 import org.wings.*; 18 import org.wings.io.Device; 19 import org.wings.session.SessionManager; 20 21 import java.io.IOException ; 22 23 public class MenuCG extends org.wings.plaf.css.MenuItemCG implements 24 org.wings.plaf.MenuCG { 25 26 public void installCG(final SComponent comp) { 27 super.installCG(comp); 28 } 29 30 public void uninstallCG(final SComponent comp) { 31 } 32 33 public void writePopup(final Device device, SMenu menu) 34 throws IOException { 35 String componentId = menu.getName(); 36 if (menu.isEnabled()) { 37 device.print("<ul"); 38 writeListAttributes(device, menu); 39 device.print(" class=\"SMenu\">"); 40 for (int i = 0; i < menu.getMenuComponentCount(); i++) { 41 SComponent menuItem = menu.getMenuComponent(i); 42 43 if (menuItem.isVisible()) { 44 device.print("<li"); 45 if (menuItem instanceof SMenu) { 46 if (menuItem.isEnabled()) { 47 device.print(" class=\"SMenu\""); 48 } else { 49 device.print(" class=\"SMenu_Disabled\""); 50 } 51 } else { 52 if (menuItem.isEnabled()) { 53 device.print(" class=\"SMenuItem\""); 54 } else { 55 device.print(" class=\"SMenuItem_Disabled\""); 56 } 57 } 58 device.print(">"); 59 if (menuItem instanceof SMenuItem) { 60 device.print("<a"); 61 if (menuItem.isEnabled()) { 62 device.print(" HREF=\""); 63 writeAnchorAddress(device, (SMenuItem) menuItem); 64 device.print("\""); 65 } 66 if (menuItem instanceof SMenu) { 67 if (menuItem.isEnabled()) { 68 device.print(" class=\"x\""); 69 } else { 70 device.print(" class=\"y\""); 71 } 72 } 73 device.print(">"); 74 } 75 menuItem.write(device); 76 if (menuItem instanceof SMenuItem) { 77 device.print("</a>"); 78 } 79 if (menuItem.isEnabled() && menuItem instanceof SMenu) { 80 ((SMenu)menuItem).writePopup(device); 81 } 82 device.print("</li>\n"); 83 } 84 } 85 device.print("</ul>"); 86 } 87 device.print("\n"); 88 } 89 90 97 protected void writeListAttributes(final Device device, SMenu menu) throws IOException { 98 if (menu.getParentMenu() != null) { 99 int maxLength = 0; 101 for (int i = 0; i < menu.getMenuComponentCount(); i++) { 102 if (!(menu.getMenuComponent(i) instanceof SMenuItem)) 103 continue; 104 String text = ((SMenuItem)menu.getMenuComponent(i)).getText(); 105 if (text != null && text.length() > maxLength) { 106 maxLength = text.length(); 107 if (menu.getMenuComponent(i) instanceof SMenu) { 108 maxLength = maxLength + 2; } 110 } 111 } 112 device.print(" style=\"width:"); 113 String stringLength = String.valueOf(maxLength * menu.getWidthScaleFactor()); 114 device.print(stringLength.substring(0,stringLength.lastIndexOf('.')+2)); 115 device.print("em;\""); 116 } else { 117 device.print(" id=\""); 118 device.print(menu.getName()); 119 device.print("_pop\""); 120 } 121 } 122 123 protected void writeItem(final Device device, SMenuItem menu) 124 throws IOException { 125 writeItemContent(device, menu); 126 } 127 128 protected void writeAnchorAddress(Device d, SAbstractButton abstractButton) 129 throws IOException { 130 RequestURL addr = abstractButton.getRequestURL(); 131 addr.addParameter(abstractButton, 132 abstractButton.getToggleSelectionParameter()); 133 addr.write(d); 134 } 135 136 public void writeContent(final Device device, 137 final SComponent _c) 138 throws IOException { 139 SMenu menu = (SMenu) _c; 140 boolean hasParent = menu.getParentMenu() != null; 141 if (hasParent) { 142 writeItem(device, menu); 143 } else { 144 SessionManager.getSession().getCGManager().getPrefixSuffixDelegate().writePrefix(device, _c); 145 writePopup(device, menu); 146 SessionManager.getSession().getCGManager().getPrefixSuffixDelegate().writeSuffix(device, _c); 147 } 148 149 } 150 } 151 | Popular Tags |