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.*;
16: import org.wings.io.Device;
17:
18: import java.io.IOException;
19:
20: public final class PasswordFieldCG extends AbstractComponentCG
21: implements org.wings.plaf.PasswordFieldCG {
22:
23: private static final long serialVersionUID = 1L;
24:
25: int horizontalOversize = 4;
26:
27: public int getHorizontalOversize() {
28: return horizontalOversize;
29: }
30:
31: public void setHorizontalOversize(int horizontalOversize) {
32: this .horizontalOversize = horizontalOversize;
33: }
34:
35: public void installCG(SComponent component) {
36: super .installCG(component);
37: if (isMSIE(component))
38: component.putClientProperty("horizontalOversize",
39: new Integer(horizontalOversize));
40: }
41:
42: public void writeInternal(final Device device, final SComponent _c)
43: throws IOException {
44: final SPasswordField component = (SPasswordField) _c;
45:
46: SDimension preferredSize = component.getPreferredSize();
47: boolean tableWrapping = Utils.isMSIE(component)
48: && preferredSize != null
49: && "%".equals(preferredSize.getWidthUnit());
50: String actualWidth = null;
51: if (tableWrapping) {
52: actualWidth = preferredSize.getWidth();
53: preferredSize.setWidth("100%");
54: device.print("<table style=\"table-layout: fixed; width: "
55: + actualWidth + "\"><tr>");
56: device.print("<td style=\"padding-right: "
57: + Utils
58: .calculateHorizontalOversize(component,
59: true) + "px\">");
60: }
61:
62: device.print("<input type=\"password\"");
63: Utils.writeAllAttributes(device, component);
64: if (tableWrapping)
65: device.print(" wrapping=\"4\"");
66:
67: Utils.optAttribute(device, "size", component.getColumns());
68: Utils.optAttribute(device, "tabindex", component
69: .getFocusTraversalIndex());
70: Utils.optAttribute(device, "maxlength", component
71: .getMaxColumns());
72: Utils.writeEvents(device, component, null);
73: if (component.isFocusOwner())
74: Utils.optAttribute(device, "foc", component.getName());
75:
76: if (!component.isEditable() || !component.isEnabled()) {
77: device.print(" readonly=\"true\"");
78: }
79: if (component.isEnabled()) {
80: device.print(" name=\"");
81: Utils.write(device, Utils.event(component));
82: device.print("\"");
83: } else {
84: device.print(" disabled=\"true\"");
85: }
86:
87: Utils.optAttribute(device, "value", component.getText());
88: device.print("/>");
89: if (tableWrapping) {
90: preferredSize.setWidth(actualWidth);
91: device.print("</td></tr></table>");
92: }
93: }
94: }
|