1 14 package org.wings.plaf.css; 15 16 17 import java.io.IOException ; 18 19 import org.wings.SClickable; 20 import org.wings.SComponent; 21 import org.wings.SIcon; 22 import org.wings.io.Device; 23 24 public class ClickableCG extends LabelCG implements org.wings.plaf.ButtonCG { 25 26 public void writeContent(final Device device, final SComponent component) 27 throws IOException { 28 final SClickable button = (SClickable) component; 29 30 if (button.getShowAsFormComponent()) { 31 writeButtonStart(device, button); 32 device.print(" name=\""); 33 Utils.write(device, button.getEventTarget().getEncodedLowLevelEventId()); 34 device.print("\" value=\""); 35 Utils.write(device, button.getEvent()); 36 device.print("\""); 37 Utils.optAttribute(device, "tabindex", button.getFocusTraversalIndex()); 38 } else { 39 device.print("<a HREF=\""); 40 Utils.write(device, button.getURL()); 41 device.print("\""); 42 } 43 44 if (!button.isEnabled()) 45 device.print(" disabled=\"true\""); 46 47 Utils.writeEvents(device, button); 48 device.print(">"); 49 50 final String text = button.getText(); 51 final SIcon icon = getIcon(button); 52 53 if (icon == null && text != null) 54 writeText(device, text); 55 else if (icon != null && text == null) 56 writeIcon(device, icon); 57 else if (icon != null && text != null) { 58 new IconTextCompound() { 59 protected void text(Device d) throws IOException { 60 writeText(d, text); 61 } 62 63 protected void icon(Device d) throws IOException { 64 writeIcon(d, icon); 65 } 66 }.writeCompound(device, component, button.getHorizontalTextPosition(), button.getVerticalTextPosition()); 67 } 68 69 if (button.getShowAsFormComponent()) 70 device.print("</button>"); 71 else 72 device.print("</a>"); 73 } 74 75 protected void writeButtonStart(Device device, SClickable button) throws IOException { 76 device.print("<button"); 77 } 78 79 protected SIcon getIcon(SClickable abstractButton) { 80 if (abstractButton.isSelected()) { 81 return abstractButton.isEnabled() 82 ? abstractButton.getSelectedIcon() 83 : abstractButton.getDisabledSelectedIcon(); 84 } else { 85 return abstractButton.isEnabled() 86 ? abstractButton.getIcon() 87 : abstractButton.getDisabledIcon(); 88 } 89 } 90 } 91 | Popular Tags |