001: /*
002: ItsNat Java Web Application Framework
003: Copyright (C) 2007 Innowhere Software Services S.L., Spanish Company
004: Author: Jose Maria Arranz Santamaria
005:
006: This program is free software: you can redistribute it and/or modify
007: it under the terms of the GNU Affero General Public License as published by
008: the Free Software Foundation, either version 3 of the License, or
009: (at your option) any later version. See the GNU Affero General Public
010: License for more details. See the copy of the GNU Affero General Public License
011: included in this program. If not, see <http://www.gnu.org/licenses/>.
012: */
013: package org.itsnat.impl.comp.html.ui;
014:
015: import org.itsnat.comp.ItsNatTextField;
016: import org.itsnat.comp.html.ItsNatHTMLInput;
017: import org.itsnat.comp.html.ItsNatHTMLInputTextBased;
018: import org.itsnat.comp.ui.ItsNatTextFieldUI;
019: import org.itsnat.core.ItsNatDOMException;
020: import org.itsnat.impl.comp.html.ItsNatHTMLInputTextBasedImpl;
021: import org.w3c.dom.html.HTMLInputElement;
022:
023: /**
024: *
025: * @author jmarranz
026: */
027: public class ItsNatHTMLInputTextBasedUIImpl extends
028: ItsNatHTMLTextBasedUIImpl implements ItsNatTextFieldUI {
029:
030: /**
031: * Creates a new instance of ItsNatHTMLInputTextBasedUIImpl
032: */
033: public ItsNatHTMLInputTextBasedUIImpl(
034: ItsNatHTMLInputTextBasedImpl parentComp) {
035: super (parentComp);
036:
037: HTMLInputElement element = getHTMLInputElement();
038:
039: String type = element.getAttribute("type");
040: type = type.toLowerCase();
041: if (!type.equals("text") && !type.equals("password")
042: && !type.equals("file") && !type.equals("hidden"))
043: throw new ItsNatDOMException(
044: "HTMLInputElement type property must be text, password, file of hidden: "
045: + type, element);
046: }
047:
048: public ItsNatHTMLInputTextBased getItsNatHTMLInputTextBased() {
049: return (ItsNatHTMLInputTextBased) parentComp;
050: }
051:
052: public ItsNatHTMLInput getItsNatHTMLInput() {
053: return (ItsNatHTMLInput) parentComp;
054: }
055:
056: public ItsNatTextField getItsNatTextField() {
057: return (ItsNatTextField) parentComp;
058: }
059:
060: public HTMLInputElement getHTMLInputElement() {
061: return getItsNatHTMLInputTextBased().getHTMLInputElement();
062: }
063:
064: public String getDOMValueProperty() {
065: HTMLInputElement elem = getHTMLInputElement();
066: return elem.getValue();
067: }
068:
069: public void setDOMValueProperty(String str) {
070: // No es necesario considerar la desactivación de los mutation
071: // events porque este método es llamado por código de la clase
072: // base que ya controla eso.
073: HTMLInputElement elem = getHTMLInputElement();
074: elem.setValue(str);
075: }
076:
077: public boolean isEditable() {
078: HTMLInputElement element = getHTMLInputElement();
079: return element.getReadOnly();
080: }
081:
082: public void setEditable(boolean b) {
083: if (b == isEditable())
084: return; // No hacer nada
085:
086: HTMLInputElement element = getHTMLInputElement();
087: element.setReadOnly(!b);
088: }
089:
090: public int getColumns() {
091: HTMLInputElement element = getHTMLInputElement();
092: String value = element.getSize();
093: if (value.equals(""))
094: return -1; // Desconocido
095: else
096: return Integer.parseInt(value);
097: }
098:
099: public void setColumns(int cols) {
100: HTMLInputElement element = getHTMLInputElement();
101: element.setSize(Integer.toString(cols));
102: }
103:
104: public boolean isEnabled() {
105: HTMLInputElement element = getHTMLInputElement();
106: return !element.getDisabled();
107: }
108:
109: public void setEnabled(boolean b) {
110: HTMLInputElement element = getHTMLInputElement();
111: element.setDisabled(!b);
112: }
113: }
|