001: package org.wingx.plaf.css;
002:
003: import org.wings.plaf.css.*;
004: import org.wings.plaf.CGManager;
005: import org.wings.io.Device;
006: import org.wings.SComponent;
007: import org.wings.SIcon;
008: import org.wings.session.SessionManager;
009: import org.wingx.XDivision;
010:
011: import java.io.IOException;
012: import java.awt.*;
013:
014: import org.wings.style.Style;
015:
016: public class DivisionCG extends AbstractComponentCG implements
017: org.wingx.plaf.DivisionCG {
018: private SIcon openIcon;
019: private SIcon closedIcon;
020:
021: public DivisionCG() {
022: final CGManager manager = SessionManager.getSession()
023: .getCGManager();
024:
025: setOpenIcon((SIcon) manager.getObject("DivisionCG.openIcon",
026: SIcon.class));
027: setClosedIcon((SIcon) manager.getObject(
028: "DivisionCG.closedIcon", SIcon.class));
029: }
030:
031: public void setOpenIcon(SIcon openIcon) {
032: this .openIcon = openIcon;
033: }
034:
035: public void setClosedIcon(SIcon closedIcon) {
036: this .closedIcon = closedIcon;
037: }
038:
039: public void writeInternal(Device device, SComponent component)
040: throws IOException {
041: XDivision division = (XDivision) component;
042:
043: device.print("<table");
044: Utils.writeAllAttributes(device, component);
045: Utils.writeEvents(device, component, null);
046: device
047: .print("><colgroup><col width=\"0*\"/><col width=\"1*\"></colgroup><tr ");
048: if (division.isTitleClickable() && division.isEnabled()) {
049: Utils.printClickability(device, division, "t", division
050: .isEnabled(), true);
051: }
052: device.print("><td class=\"DivisionControl\"");
053: SIcon icon = division.isShaded() ? closedIcon : openIcon;
054: if (!division.isTitleClickable() && division.isEnabled()) {
055: Utils.printClickability(device, division, "t", division
056: .isEnabled(), true);
057: }
058:
059: if (isMSIE(component)
060: && PaddingVoodoo.hasPaddingInsets(division)) {
061: final Insets patchedInsets = new Insets(0, 0, 0, 0);
062: PaddingVoodoo.doBorderPaddingsWorkaround(division
063: .getBorder(), patchedInsets, true, true, false,
064: false);
065: Utils.optAttribute(device, "style", Utils
066: .createInlineStylesForInsets(patchedInsets)
067: .toString());
068: }
069:
070: device.print(">");
071: writeIcon(device, icon, null);
072: device.print("</td><td class=\"DivisionTitle\"");
073: Style style = component
074: .getDynamicStyle(XDivision.SELECTOR_TITLE);
075: if (isMSIE(component)
076: && PaddingVoodoo.hasPaddingInsets(division)) {
077: final Insets patchedInsets = new Insets(0, 0, 0, 0);
078: PaddingVoodoo.doBorderPaddingsWorkaround(division
079: .getBorder(), patchedInsets, true, false, true,
080: false);
081: Utils.optAttribute(device, "style", Utils
082: .createInlineStylesForInsets(patchedInsets)
083: .toString());
084: } else
085: Utils.optAttribute(device, "style", style);
086:
087: device.print(">");
088: if (division.getIcon() != null) {
089: writeIcon(device, division.getIcon(), null);
090: device.print(" ");
091: }
092: if (division.getTitle() != null)
093: writeTitle(device, division.getTitle());
094: device.print("</td></tr>");
095:
096: if (!division.isShaded() && division.isEnabled()) {
097: device
098: .print("<tr><td></td><td class=\"DivisionContent\"><table class=\"DivisionContent\">");
099: Utils.renderContainer(device, division);
100: device.print("</table></td></tr>");
101: }
102: device.print("</table>");
103: }
104:
105: private void writeTitle(Device device, String text)
106: throws IOException {
107: if ((text.length() > 5)
108: && (text.substring(0, 6).equalsIgnoreCase("<html>")))
109: Utils.writeRaw(device, text.substring(6));
110: else
111: Utils.quote(device, text, true, true, false);
112: }
113:
114: protected void writeIcon(Device device, SIcon icon, String cssClass)
115: throws IOException {
116: device.print("<img");
117: if (cssClass != null) {
118: device.print(" class=\"");
119: device.print(cssClass);
120: device.print("\"");
121: }
122: Utils.optAttribute(device, "src", icon.getURL());
123: Utils.optAttribute(device, "width", icon.getIconWidth());
124: Utils.optAttribute(device, "height", icon.getIconHeight());
125: device.print(" alt=\"");
126: device.print(icon.getIconTitle());
127: device.print("\"/>");
128: }
129: }
|