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:
014: package org.itsnat.impl.core.css;
015:
016: import org.w3c.dom.DOMException;
017: import org.w3c.dom.css.CSSPrimitiveValue;
018: import org.w3c.dom.css.Rect;
019: import org.itsnat.impl.core.css.lex.Comma;
020: import org.itsnat.impl.core.css.lex.SourceCode;
021: import org.itsnat.impl.core.css.lex.Space;
022:
023: /**
024: * rect (<top> <right> <bottom> <left>)
025: *
026: * @author jmarranz
027: */
028: public class RectImpl extends CSSPrimitiveValueLiteralImpl implements
029: Rect {
030: protected CSSPrimitiveValueImpl parent;
031: protected CSSPrimitiveValueImpl top;
032: protected CSSPrimitiveValueImpl right;
033: protected CSSPrimitiveValueImpl bottom;
034: protected CSSPrimitiveValueImpl left;
035:
036: /** Creates a new instance of RectImpl */
037: public RectImpl(SourceCode cssTextCode, CSSPrimitiveValueImpl parent) {
038: this .parent = parent;
039: SourceCode[] rectList = cssTextCode.split(Comma.getSingleton());
040: if (rectList.length != 4) {
041: rectList = cssTextCode.split(new Space(' '));
042: if (rectList.length != 4)
043: throw new DOMException(DOMException.INVALID_ACCESS_ERR,
044: "Rect syntax error, property: "
045: + getPropertyName() + " value: "
046: + cssTextCode.toString());
047: }
048:
049: this .top = new CSSPrimitiveValueImpl(rectList[0], 0, this );
050: this .right = new CSSPrimitiveValueImpl(rectList[1], 1, this );
051: this .bottom = new CSSPrimitiveValueImpl(rectList[2], 2, this );
052: this .left = new CSSPrimitiveValueImpl(rectList[3], 3, this );
053: }
054:
055: public int getCode() {
056: return RECT;
057: }
058:
059: public CSSPrimitiveValue getTop() {
060: return top;
061: }
062:
063: public CSSPrimitiveValue getRight() {
064: return right;
065: }
066:
067: public CSSPrimitiveValue getBottom() {
068: return bottom;
069: }
070:
071: public CSSPrimitiveValue getLeft() {
072: return left;
073: }
074:
075: public String getPropertyName() {
076: return parent.getPropertyName();
077: }
078:
079: public Object getUpdatedChildObjectValueFromElement(
080: Object requester, int requesterCode) {
081: Rect current = (Rect) parent
082: .getUpdatedChildObjectValueFromElement(this , getCode());
083: if (current != this ) {
084: if (requesterCode == 0)
085: return current.getTop();
086: else if (requesterCode == 1)
087: return current.getRight();
088: else if (requesterCode == 2)
089: return current.getBottom();
090: else if (requesterCode == 3)
091: return current.getLeft();
092: throw new DOMException(DOMException.INVALID_ACCESS_ERR,
093: "Internal Error");
094: } else
095: return requester;
096: }
097:
098: public void notifyToElementChangedCSSText(SourceCode cssText,
099: Object requester) {
100: // Una de las partes se ha actualizado (da igual cual sea), hay que notificar el cambio
101: // de toda la estructura Rect.
102: String topValue = top.getCssTextSourceCode(false).toString();
103: String rightValue = right.getCssTextSourceCode(false)
104: .toString();
105: String bottomValue = bottom.getCssTextSourceCode(false)
106: .toString();
107: String leftValue = left.getCssTextSourceCode(false).toString();
108:
109: String cssTextRect = "rect(" + topValue + "," + rightValue
110: + "," + bottomValue + "," + leftValue + ")";
111: SourceCode cssTextRectCode = new SourceCode(cssTextRect);
112: parent.setCssTextSourceCode(cssTextRectCode, true);
113: }
114:
115: }
|