01: /*
02: * Copyright 2000,2005 wingS development team.
03: *
04: * This file is part of wingS (http://wingsframework.org).
05: *
06: * wingS is free software; you can redistribute it and/or modify
07: * it under the terms of the GNU Lesser General Public License
08: * as published by the Free Software Foundation; either version 2.1
09: * of the License, or (at your option) any later version.
10: *
11: * Please see COPYING for the complete licence.
12: */
13: package org.wings.plaf.css;
14:
15: import org.wings.SClickable;
16: import org.wings.SComponent;
17: import org.wings.SIcon;
18: import org.wings.io.Device;
19: import org.wings.plaf.Update;
20:
21: import java.io.IOException;
22:
23: public final class ClickableCG extends AbstractLabelCG implements
24: org.wings.plaf.ClickableCG {
25:
26: private static final long serialVersionUID = 1L;
27:
28: public void writeInternal(final Device device,
29: final SComponent component) throws IOException {
30: final SClickable button = (SClickable) component;
31:
32: final String text = button.getText();
33: final SIcon icon = getIcon(button);
34:
35: if (icon == null && text != null) {
36: device.print("<table");
37: tableAttributes(device, button);
38: device.print("><tr><td>");
39: writeText(device, text, false);
40: device.print("</td></tr></table>");
41: } else if (icon != null && text == null) {
42: device.print("<table");
43: tableAttributes(device, button);
44: device.print("><tr><td>");
45: writeIcon(device, icon, Utils.isMSIE(component));
46: device.print("</td></tr></table>");
47: } else if (icon != null && text != null) {
48: new IconTextCompound() {
49: protected void text(Device d) throws IOException {
50: writeText(d, text, false);
51: }
52:
53: protected void icon(Device d) throws IOException {
54: writeIcon(d, icon, Utils.isMSIE(component));
55: }
56:
57: protected void tableAttributes(Device d)
58: throws IOException {
59: ClickableCG.this .tableAttributes(d, button);
60: }
61: }.writeCompound(device, component, button
62: .getHorizontalTextPosition(), button
63: .getVerticalTextPosition(), false);
64: }
65: }
66:
67: protected void tableAttributes(Device device, SClickable button)
68: throws IOException {
69: Utils.printClickability(device, button, button.getEvent(),
70: true, button.getShowAsFormComponent());
71: Utils.writeAllAttributes(device, button);
72:
73: if (button.isFocusOwner())
74: Utils.optAttribute(device, "foc", button.getName());
75:
76: Utils.optAttribute(device, "tabindex", button
77: .getFocusTraversalIndex());
78: }
79:
80: protected SIcon getIcon(SClickable abstractButton) {
81: if (abstractButton.isSelected()) {
82: return abstractButton.isEnabled() ? abstractButton
83: .getSelectedIcon() : abstractButton
84: .getDisabledSelectedIcon();
85: } else {
86: return abstractButton.isEnabled() ? abstractButton
87: .getIcon() : abstractButton.getDisabledIcon();
88: }
89: }
90:
91: public Update getTextUpdate(SClickable clickable, String text) {
92: return text == null ? null : new TextUpdate(clickable, text);
93: }
94:
95: public Update getIconUpdate(SClickable clickable, SIcon icon) {
96: return icon == null ? null : new IconUpdate(clickable, icon);
97: }
98:
99: }
|