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 CheckBoxCG extends ButtonCG implements org.wings.plaf.CheckBoxCG { 24 private static final SIcon ICON_DISABLEDSELECTED = (SIcon) SessionManager 25 .getSession().getCGManager().getObject("SCheckBox.disabledSelectedIcon", SIcon.class); 26 27 private static final SIcon ICON_DISABLED = (SIcon) SessionManager 28 .getSession().getCGManager().getObject("SCheckBox.disabledIcon", SIcon.class); 29 30 private static final SIcon ICON_PRESSED = (SIcon) SessionManager 31 .getSession().getCGManager().getObject("SCheckBox.pressedIcon", SIcon.class); 32 33 private static final SIcon ICON_ROLLOVERSELECTED = (SIcon) SessionManager 34 .getSession().getCGManager().getObject("SCheckBox.rolloverSelectedIcon", SIcon.class); 35 36 private static final SIcon ICON_ROLLOVER = (SIcon) SessionManager 37 .getSession().getCGManager().getObject("SCheckBox.rolloverIcon", SIcon.class); 38 39 private static final SIcon ICON_DEFAULT = (SIcon) SessionManager 40 .getSession().getCGManager().getObject("SCheckBox.icon", SIcon.class); 41 42 private static final SIcon ICON_SELECTED = (SIcon) SessionManager 43 .getSession().getCGManager().getObject("SCheckBox.selectedIcon", SIcon.class); 44 45 protected boolean useIconsInForms = false; 46 47 48 public boolean isUseIconsInForm() { 49 return useIconsInForms; 50 } 51 52 public void setUseIconsInForm(boolean useIconsInForm) { 53 this.useIconsInForms = useIconsInForm; 54 } 55 56 public void installCG(SComponent component) { 57 super.installCG(component); 58 final SAbstractButton button = (SAbstractButton) component; 59 installIcons(button); 60 } 61 62 protected void installIcons(final SAbstractButton button) { 63 org.wings.plaf.CGManager manager = button.getSession().getCGManager(); 64 button.setIcon(ICON_DEFAULT); 65 button.setSelectedIcon(ICON_SELECTED); 66 button.setRolloverIcon(ICON_ROLLOVER); 67 button.setRolloverSelectedIcon(ICON_ROLLOVERSELECTED); 68 button.setPressedIcon(ICON_PRESSED); 69 button.setDisabledIcon(ICON_DISABLED); 70 button.setDisabledSelectedIcon(ICON_DISABLEDSELECTED); 71 } 72 73 public void writeContent(final Device device, final SComponent component) 74 throws IOException { 75 final SAbstractButton button = (SAbstractButton) component; 76 77 final boolean showAsFormComponent = button.getShowAsFormComponent(); 78 final String text = button.getText(); 79 final SIcon icon = getIcon(button); 80 81 92 93 if (showAsFormComponent && useIconsInForms) { 94 writeButtonStart(device, button); 95 device.print(" type=\"submit\" name=\""); 96 Utils.write(device, Utils.event(button)); 97 device.print("\""); 98 Utils.optAttribute(device, "tabindex", button.getFocusTraversalIndex()); 99 Utils.optAttribute(device, "accesskey", button.getMnemonic()); 100 Utils.writeEvents(device, button); 101 } else if (showAsFormComponent && !useIconsInForms) { 102 device.print("<span"); 103 } else { 104 RequestURL addr = button.getRequestURL(); 105 addr.addParameter(button, button.getToggleSelectionParameter()); 106 writeLinkStart(device, addr); 107 108 Utils.optAttribute(device, "accesskey", button.getMnemonic()); 109 Utils.writeEvents(device, button); 110 } 111 Utils.printCSSInlineFullSize(device, component.getPreferredSize()); 112 113 if (!button.isEnabled()) 114 device.print(" disabled=\"true\""); 115 if (button.isSelected()) 116 device.print(" checked=\"true\""); 117 if (component.isFocusOwner()) 118 Utils.optAttribute(device, "focus", component.getName()); 119 120 device.print(">"); 121 122 if (showAsFormComponent && !useIconsInForms && text == null) 123 inputTypeCheckbox(device, button); 124 else if (icon != null && text == null) 125 writeIcon(device, icon); 126 else if (text != null && icon == null) 127 writeText(device, text); 128 else if (text != null) { 129 new IconTextCompound() { 130 protected void text(Device device) throws IOException { 131 writeText(device, text); 132 } 133 134 protected void icon(Device device) throws IOException { 135 if (showAsFormComponent && !useIconsInForms) 136 inputTypeCheckbox(device, button); 137 else 138 writeIcon(device, icon); 139 } 140 }.writeCompound(device, component, button.getHorizontalTextPosition(), button.getVerticalTextPosition()); 141 } 142 143 if (showAsFormComponent && useIconsInForms) 144 device.print("</button>"); 145 else if (showAsFormComponent && !useIconsInForms) 146 device.print("</span>"); 147 else 148 device.print("</a>"); 149 } 150 151 155 protected void writeButtonStart(final Device device, final SAbstractButton comp) throws IOException { 156 device.print("<button"); 157 } 158 159 166 protected void writeLinkStart(final Device device, RequestURL addr) throws IOException { 167 device.print("<a HREF=\""); 168 addr.write(device); 169 device.print("\""); 170 } 171 172 protected void inputTypeCheckbox(Device device, SAbstractButton button) throws IOException { 173 device.print("<input type=\"hidden\" name=\""); 174 Utils.write(device, Utils.event(button)); 175 device.print("\" value=\"hidden_reset\"/>"); 176 177 device.print("<input type=\"checkbox\" name=\""); 178 Utils.write(device, Utils.event(button)); 179 device.print("\""); 180 Utils.optAttribute(device, "tabindex", button.getFocusTraversalIndex()); 181 182 if (!button.isEnabled()) 183 device.print(" disabled=\"true\""); 184 if (button.isSelected()) 185 device.print(" checked=\"true\""); 186 187 Utils.writeEvents(device, button); 188 device.print("/>"); 189 } 190 } 191 | Popular Tags |