001: package org.wings.plaf.css;
002:
003: import org.wings.io.Device;
004: import org.wings.*;
005: import org.wings.header.Header;
006: import org.wings.header.SessionHeaders;
007: import org.wings.plaf.css.script.OnPageRenderedScript;
008:
009: import java.io.IOException;
010: import java.util.List;
011: import java.util.ArrayList;
012:
013: public class SplitPaneCG extends AbstractComponentCG implements
014: org.wings.plaf.SplitPaneCG {
015: public static final String CSS_EXT_CORE = "CSS.extCoreCSS";
016: public static final String JS_EXT_EXT = "JS.extExt";
017: public static final String JS_EXT_YUI_BRIDGE = "JS.extYuiBridge";
018: public static final String JS_EXT_DOM_QUERY = "JS.extDomQuery";
019: public static final String JS_EXT_OBSERVABLE = "JS.extObservable";
020: public static final String JS_EXT_EVENT_MANAGER = "JS.extEventManager";
021: public static final String JS_EXT_DOM_HELPER = "JS.extDomHelper";
022: public static final String JS_EXT_ELEMENT = "JS.extElement";
023: public static final String JS_EXT_DD_CORE = "JS.extDDCore";
024: public static final String JS_EXT_SPLITBAR = "JS.extSplitBar";
025:
026: protected final List<Header> headers = new ArrayList<Header>();
027:
028: public SplitPaneCG() {
029: headers.add(Utils
030: .createExternalizedCSSHeaderFromProperty(CSS_EXT_CORE));
031: headers.add(Utils
032: .createExternalizedJSHeaderFromProperty(JS_EXT_EXT));
033: headers
034: .add(Utils
035: .createExternalizedJSHeaderFromProperty(JS_EXT_DOM_QUERY));
036: headers
037: .add(Utils
038: .createExternalizedJSHeaderFromProperty(JS_EXT_YUI_BRIDGE));
039: headers
040: .add(Utils
041: .createExternalizedJSHeaderFromProperty(JS_EXT_OBSERVABLE));
042: headers
043: .add(Utils
044: .createExternalizedJSHeaderFromProperty(JS_EXT_EVENT_MANAGER));
045: headers
046: .add(Utils
047: .createExternalizedJSHeaderFromProperty(JS_EXT_DOM_HELPER));
048: headers
049: .add(Utils
050: .createExternalizedJSHeaderFromProperty(JS_EXT_ELEMENT));
051:
052: headers
053: .add(Utils
054: .createExternalizedJSHeaderFromProperty(JS_EXT_DD_CORE));
055: headers
056: .add(Utils
057: .createExternalizedJSHeaderFromProperty(JS_EXT_SPLITBAR));
058: }
059:
060: public void installCG(final SComponent comp) {
061: super .installCG(comp);
062: SessionHeaders.getInstance().registerHeaders(headers);
063: }
064:
065: public void uninstallCG(SComponent component) {
066: super .uninstallCG(component);
067: SessionHeaders.getInstance().deregisterHeaders(headers);
068: }
069:
070: public void writeInternal(final Device device,
071: final SComponent component) throws java.io.IOException {
072: final SSplitPane splitPane = (SSplitPane) component;
073: String name = splitPane.getName();
074:
075: device.print("<table");
076: Utils.writeAllAttributes(device, component);
077: Utils.writeEvents(device, component, null);
078: device.print(">");
079:
080: StringBuilder scriptBuilder = STRING_BUILDER.get();
081: scriptBuilder.setLength(0);
082:
083: if (splitPane.getOrientation() == SSplitPane.VERTICAL_SPLIT) {
084: String topPaneName = name + "_t";
085: String bottomPaneName = name + "_b";
086: String splitBarName = name + "_tb";
087:
088: writeSplitterScript(scriptBuilder, splitBarName,
089: topPaneName, splitPane.getDividerLocation(),
090: "Ext.SplitBar.VERTICAL", "Ext.SplitBar.TOP");
091: splitPane.getSession().getScriptManager()
092: .addScriptListener(
093: new OnPageRenderedScript(scriptBuilder
094: .toString()));
095:
096: writeVertical(device, topPaneName, splitPane
097: .getTopComponent());
098: writeVerticalSplitter(device, splitBarName, splitPane
099: .getDividerSize());
100: writeVertical(device, bottomPaneName, splitPane
101: .getBottomComponent());
102: } else {
103: String leftPaneName = name + "_l";
104: String rightPaneName = name + "_r";
105: String splitBarName = name + "_lr";
106:
107: writeSplitterScript(scriptBuilder, splitBarName,
108: leftPaneName, splitPane.getDividerLocation(),
109: "Ext.SplitBar.HORIZONTAL", "Ext.SplitBar.LEFT");
110: splitPane.getSession().getScriptManager()
111: .addScriptListener(
112: new OnPageRenderedScript(scriptBuilder
113: .toString()));
114:
115: device.print("<tr>");
116: writeHorizontal(device, leftPaneName, splitPane
117: .getLeftComponent());
118: writeHorizontalSplitter(device, splitBarName, splitPane
119: .getDividerSize());
120: writeHorizontal(device, rightPaneName, splitPane
121: .getRightComponent());
122: device.print("</tr>");
123: }
124:
125: device.print("</table>");
126: }
127:
128: protected void writeSplitterScript(StringBuilder scriptBuilder,
129: String splitBarName, String paneName, int location,
130: String orientation, String placement) {
131: scriptBuilder.append("var ");
132: scriptBuilder.append(splitBarName);
133: scriptBuilder.append(" = new Ext.SplitBar('");
134: scriptBuilder.append(splitBarName);
135: scriptBuilder.append("', '");
136: scriptBuilder.append(paneName);
137: scriptBuilder.append("', ");
138: scriptBuilder.append(orientation);
139: scriptBuilder.append(", ");
140: scriptBuilder.append(placement);
141: scriptBuilder.append(");\n");
142: if (location != -1) {
143: scriptBuilder.append(splitBarName);
144: scriptBuilder.append(".setCurrentSize(");
145: scriptBuilder.append(location);
146: scriptBuilder.append(");\n");
147: }
148: scriptBuilder.append(splitBarName);
149: scriptBuilder
150: .append(".on('moved', wingS.component.splitPaneResized);");
151: }
152:
153: protected void writeVertical(Device device, String paneName,
154: SComponent paneComponent) throws IOException {
155: device.print("<tr><td id=\"");
156: device.print(paneName);
157: device.print("\">");
158: paneComponent.write(device);
159: device.print("</td></tr>");
160: }
161:
162: protected void writeVerticalSplitter(Device device, String name,
163: int dividerSize) throws IOException {
164: device.print("<tr><td style=\"height: ");
165: device.print(dividerSize);
166: device.print("px\" class=\"splitter\" id=\"");
167: device.print(name);
168: device.print("\"></td></tr>");
169: }
170:
171: protected void writeHorizontal(Device device, String paneName,
172: SComponent paneComponent) throws IOException {
173: device.print("<td id=\"");
174: device.print(paneName);
175: device.print("\">");
176: paneComponent.write(device);
177: device.print("</td>");
178: }
179:
180: protected void writeHorizontalSplitter(Device device, String name,
181: int dividerSize) throws IOException {
182: device.print("<td style=\"width: ");
183: device.print(dividerSize);
184: device.print("px\" class=\"splitter\" id=\"");
185: device.print(name);
186: device.print("\"></td>");
187: }
188: }
|