1 14 package org.wings.plaf.css; 15 16 17 import java.io.IOException ; 18 19 import org.wings.SComponent; 20 import org.wings.SIcon; 21 import org.wings.SLabel; 22 import org.wings.io.Device; 23 24 public class LabelCG extends AbstractComponentCG implements 25 org.wings.plaf.LabelCG { 26 public LabelCG() { 27 } 28 29 public void writeContent(final Device device, final SComponent component) 30 throws IOException { 31 final SLabel label = (SLabel) component; 32 final String text = label.getText(); 33 final SIcon icon = label.isEnabled() ? label.getIcon() : label.getDisabledIcon(); 34 final int horizontalTextPosition = label.getHorizontalTextPosition(); 35 final int verticalTextPosition = label.getVerticalTextPosition(); 36 if (icon == null && text != null) { 37 writeText(device, text); 38 } 39 else if (icon != null && text == null) 40 writeIcon(device, icon); 41 else if (icon != null && text != null) { 42 new IconTextCompound() { 43 protected void text(Device d) throws IOException { 44 writeText(d, text); 45 } 46 protected void icon(Device d) throws IOException { 47 writeIcon(d, icon); 48 } 49 }.writeCompound(device, component, horizontalTextPosition, verticalTextPosition); 50 } 51 } 52 53 protected void writeText(Device device, String text) throws IOException { 54 Utils.write(device, text); 55 } 56 57 protected void writeIcon(Device device, SIcon icon) throws IOException { 58 device.print("<img"); 59 Utils.optAttribute(device, "src", icon.getURL()); 60 Utils.optAttribute(device, "width", icon.getIconWidth()); 61 Utils.optAttribute(device, "height", icon.getIconHeight()); 62 device.print(" alt=\""); 63 device.print(icon.getIconTitle()); 64 device.print("\"/>"); 65 } 66 } 67 | Popular Tags |