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.Update;
018: import org.wings.script.JavaScriptEvent;
019: import org.wings.script.JavaScriptListener;
020:
021: import java.io.IOException;
022:
023: public final class TextAreaCG extends AbstractComponentCG implements
024: org.wings.plaf.TextAreaCG {
025:
026: private static final long serialVersionUID = 1L;
027:
028: int horizontalOversize = 4;
029:
030: public int getHorizontalOversize() {
031: return horizontalOversize;
032: }
033:
034: public void setHorizontalOversize(int horizontalOversize) {
035: this .horizontalOversize = horizontalOversize;
036: }
037:
038: public void installCG(SComponent component) {
039: super .installCG(component);
040: if (isMSIE(component))
041: component.putClientProperty("horizontalOversize",
042: new Integer(horizontalOversize));
043: }
044:
045: public void writeInternal(final Device device, final SComponent _c)
046: throws IOException {
047: final STextArea component = (STextArea) _c;
048:
049: Object clientProperty = component
050: .getClientProperty("onChangeSubmitListener");
051: // If the application developer attached any SDocumentListeners to this
052: // STextArea, the surrounding form gets submitted as soon as the content
053: // of this STextArea changed.
054: if (component.getDocumentListeners().length > 1) {
055: // We need to test if there are at least 2 document
056: // listeners because each text component registers
057: // itself as a listener of its document as well.
058: if (clientProperty == null) {
059: String event = JavaScriptEvent.ON_CHANGE;
060: String code = "wingS.request.sendEvent(event, true, "
061: + !component.isReloadForced() + ");";
062: JavaScriptListener javaScriptListener = new JavaScriptListener(
063: event, code);
064: component.addScriptListener(javaScriptListener);
065: component.putClientProperty("onChangeSubmitListener",
066: javaScriptListener);
067: }
068: } else if (clientProperty != null
069: && clientProperty instanceof JavaScriptListener) {
070: component
071: .removeScriptListener((JavaScriptListener) clientProperty);
072: component.putClientProperty("onChangeSubmitListener", null);
073: }
074:
075: SDimension preferredSize = component.getPreferredSize();
076: boolean tableWrapping = Utils.isMSIE(component)
077: && preferredSize != null
078: && "%".equals(preferredSize.getWidthUnit());
079: String actualWidth = null;
080: if (tableWrapping) {
081: actualWidth = preferredSize.getWidth();
082: preferredSize.setWidth("100%");
083: device.print("<table style=\"table-layout: fixed; width: "
084: + actualWidth + "\"><tr>");
085: device.print("<td style=\"padding-right: "
086: + Utils
087: .calculateHorizontalOversize(component,
088: true) + "px\">");
089: }
090: device.print("<textarea");
091: Utils.writeAllAttributes(device, component);
092: if (tableWrapping)
093: device.print(" wrapping=\"4\"");
094:
095: Utils.optAttribute(device, "tabindex", component
096: .getFocusTraversalIndex());
097: Utils.optAttribute(device, "cols", component.getColumns());
098: Utils.optAttribute(device, "rows", component.getRows());
099: Utils.writeEvents(device, component, null);
100:
101: switch (component.getLineWrap()) {
102: case STextArea.VIRTUAL_WRAP:
103: device.print(" wrap=\"virtual\"");
104: break;
105: case STextArea.PHYSICAL_WRAP:
106: device.print(" wrap=\"physical\"");
107: break;
108: }
109:
110: if (!component.isEditable() || !component.isEnabled()) {
111: device.print(" readonly=\"true\"");
112: }
113:
114: if (component.isEnabled()) {
115: device.print(" name=\"");
116: Utils.write(device, Utils.event(component));
117: device.print("\"");
118: } else {
119: device.print(" disabled=\"true\"");
120: }
121:
122: if (component.isFocusOwner())
123: Utils.optAttribute(device, "foc", component.getName());
124:
125: device.print(">");
126: Utils.quote(device, component.getText(), false, false, false);
127: device.print("</textarea>\n");
128: if (tableWrapping) {
129: preferredSize.setWidth(actualWidth);
130: device.print("</td></tr></table>");
131: }
132: }
133:
134: public Update getTextUpdate(STextArea textArea, String text) {
135: return new TextUpdate(textArea, text);
136: }
137:
138: protected class TextUpdate extends AbstractUpdate {
139:
140: private String text;
141:
142: public TextUpdate(SComponent component, String text) {
143: super (component);
144: this .text = text;
145: }
146:
147: public Handler getHandler() {
148: String exception = null;
149:
150: UpdateHandler handler = new UpdateHandler("value");
151: handler.addParameter(component.getName());
152: handler.addParameter(text == null ? "" : text);
153: if (exception != null) {
154: handler.addParameter(exception);
155: }
156: return handler;
157: }
158:
159: }
160:
161: }
|