KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > wings > plaf > css > LabelCG


1 /*
2  * $Id: LabelCG.java,v 1.14 2005/06/07 12:55:59 neurolabs Exp $
3  * Copyright 2000,2005 wingS development team.
4  *
5  * This file is part of wingS (http://www.j-wings.org).
6  *
7  * wingS is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU Lesser General Public License
9  * as published by the Free Software Foundation; either version 2.1
10  * of the License, or (at your option) any later version.
11  *
12  * Please see COPYING for the complete licence.
13  */

14 package org.wings.plaf.css;
15
16
17 import java.io.IOException JavaDoc;
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 JavaDoc {
31         final SLabel label = (SLabel) component;
32         final String JavaDoc 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 JavaDoc {
44                     writeText(d, text);
45                 }
46                 protected void icon(Device d) throws IOException JavaDoc {
47                     writeIcon(d, icon);
48                 }
49             }.writeCompound(device, component, horizontalTextPosition, verticalTextPosition);
50         }
51     }
52
53     protected void writeText(Device device, String JavaDoc text) throws IOException JavaDoc {
54         Utils.write(device, text);
55     }
56
57     protected void writeIcon(Device device, SIcon icon) throws IOException JavaDoc {
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