001: /*
002: * Copyright 2000,2005 wingS development team.
003: *
004: * This file is part of wingS (http://wingsframework.org).
005: *
006: * wingS is free software; you can redistribute it and/or modify
007: * it under the terms of the GNU Lesser General Public License
008: * as published by the Free Software Foundation; either version 2.1
009: * of the License, or (at your option) any later version.
010: *
011: * Please see COPYING for the complete licence.
012: */
013: package org.wings.plaf.css;
014:
015: import org.wings.*;
016: import org.wings.io.Device;
017: import org.wings.plaf.css.script.LayoutFillScript;
018: import org.wings.plaf.css.script.OnPageRenderedScript;
019: import org.wings.plaf.Update;
020:
021: import java.io.IOException;
022:
023: /**
024: * CG for a scrollbar.
025: *
026: * @author holger
027: */
028: public final class ScrollBarCG extends
029: org.wings.plaf.css.AbstractComponentCG<SScrollBar> implements
030: org.wings.plaf.ScrollBarCG {
031: private static final long serialVersionUID = 1L;
032:
033: public void writeInternal(final Device d, final SScrollBar scrollBar)
034: throws IOException {
035: final String style = scrollBar.getStyle();
036: if (scrollBar.getOrientation() == SConstants.VERTICAL) {
037: scrollBar.setStyle(style + " SScrollBar_vertical");
038: writeVerticalScrollbar(d, scrollBar);
039: } else {
040: scrollBar.setStyle(style + " SScrollBar_horizontal");
041: writeHorizontalScrollbar(d, scrollBar);
042: }
043: scrollBar.setStyle(style);
044: }
045:
046: private void writeVerticalScrollbar(Device device, SScrollBar sb)
047: throws IOException {
048: SDimension preferredSize = sb.getPreferredSize();
049: String height = preferredSize != null ? preferredSize
050: .getHeight() : null;
051: boolean clientLayout = isMSIE(sb) && height != null
052: && !"auto".equals(height);
053:
054: Utils.printNewline(device, sb);
055: device.print("<table");
056:
057: if (clientLayout) {
058: Utils.optAttribute(device, "layoutHeight", height);
059: preferredSize.setHeight(null);
060: }
061:
062: Utils.writeAllAttributes(device, sb);
063:
064: if (clientLayout) {
065: preferredSize.setHeight(height);
066: sb.getSession().getScriptManager().addScriptListener(
067: new LayoutFillScript(sb.getName()));
068: }
069:
070: device.print("><tbody><tr><td>\n");
071: device
072: .print("<div class=\"outer\"><div class=\"inner\"/></div>\n");
073: device.print("</td></tr></tbody></table>");
074:
075: sb.getSession().getScriptManager().addScriptListener(
076: new VerticalScrollBarLayoutScript(sb));
077: sb.getSession().getScriptManager().addScriptListener(
078: new VerticalScrollBarSetScript(sb));
079: }
080:
081: private void writeHorizontalScrollbar(Device device, SScrollBar sb)
082: throws IOException {
083: device.print("<table");
084: Utils.writeAllAttributes(device, sb);
085: device.print("><tbody><tr><td>\n");
086: device
087: .print("<div class=\"outer\"><div class=\"inner\"/></div>\n");
088: device.print("</td></tr></tbody></table>");
089:
090: sb.getSession().getScriptManager().addScriptListener(
091: new HorizontalScrollBarLayoutScript(sb));
092: sb.getSession().getScriptManager().addScriptListener(
093: new HorizontalScrollBarSetScript(sb));
094: }
095:
096: public Update getAdjustmentUpdate(SScrollBar scrollBar, int value,
097: int extent, int size) {
098: if (scrollBar.isChangeFromEvent())
099: return null;
100: return new ComponentUpdate<SScrollBar>(this , scrollBar);
101: }
102:
103: private static class VerticalScrollBarLayoutScript extends
104: OnPageRenderedScript {
105: public VerticalScrollBarLayoutScript(SScrollBar sb) {
106: super ("wingS.scrollbar.layout_vertical(\"" + sb.getName()
107: + "\");");
108: }
109: }
110:
111: private static class HorizontalScrollBarLayoutScript extends
112: OnPageRenderedScript {
113: public HorizontalScrollBarLayoutScript(SScrollBar sb) {
114: super ("wingS.scrollbar.layout_horizontal(\"" + sb.getName()
115: + "\");");
116: }
117: }
118:
119: private static class VerticalScrollBarSetScript extends
120: OnPageRenderedScript {
121: public VerticalScrollBarSetScript(SScrollBar sb) {
122: super ("wingS.scrollbar.set_vertical(\"" + sb.getName()
123: + "\"" + params(sb) + ");");
124: }
125: }
126:
127: private static class HorizontalScrollBarSetScript extends
128: OnPageRenderedScript {
129: public HorizontalScrollBarSetScript(SScrollBar sb) {
130: super ("wingS.scrollbar.set_horizontal(\"" + sb.getName()
131: + "\"" + params(sb) + ");");
132: }
133: }
134:
135: static String params(SScrollBar sb) {
136: final int value = sb.getValue();
137: final int extent = sb.getExtent();
138: final int minimum = sb.getMinimum();
139: final int maximum = sb.getMaximum();
140: final int size = maximum - minimum;
141: return ", " + value + ", " + extent + ", " + size;
142: }
143: }
|