01: /*
02: * This file is not part of the ItsNat framework.
03: *
04: * Original source code use and closed source derivatives are authorized
05: * to third parties with no restriction or fee.
06: * The original source code is owned by the author.
07: *
08: * This program is distributed AS IS in the hope that it will be useful,
09: * but WITHOUT ANY WARRANTY; without even the implied warranty of
10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11: *
12: * Author: Jose Maria Arranz Santamaria
13: * (C) Innowhere Software Services S.L., Spanish company, year 2007
14: */
15:
16: package org.itsnat.feashow.features.core.domutils;
17:
18: import org.itsnat.core.ItsNatDocument;
19: import org.itsnat.feashow.FeatureTreeNode;
20: import org.w3c.dom.Document;
21: import org.w3c.dom.Element;
22: import org.w3c.dom.css.CSS2Properties;
23: import org.w3c.dom.css.CSSPrimitiveValue;
24: import org.w3c.dom.css.CSSStyleDeclaration;
25: import org.w3c.dom.css.CSSValue;
26: import org.w3c.dom.css.CSSValueList;
27: import org.w3c.dom.css.ElementCSSInlineStyle;
28: import org.w3c.dom.css.RGBColor;
29: import org.w3c.dom.events.Event;
30: import org.w3c.dom.events.EventListener;
31: import org.w3c.dom.events.EventTarget;
32:
33: public class ElementCSSInlineStyleTreeNode extends FeatureTreeNode
34: implements EventListener {
35: protected Element linkToStart;
36:
37: public ElementCSSInlineStyleTreeNode() {
38: }
39:
40: public void startExamplePanel() {
41: ItsNatDocument itsNatDoc = getItsNatDocument();
42: Document doc = itsNatDoc.getDocument();
43:
44: this .linkToStart = doc.getElementById("linkToStartId");
45:
46: itsNatDoc.addEventListener((EventTarget) linkToStart, "click",
47: this , false);
48: }
49:
50: public void endExamplePanel() {
51: ItsNatDocument itsNatDoc = getItsNatDocument();
52: itsNatDoc.removeEventListener((EventTarget) linkToStart,
53: "click", this , false);
54:
55: this .linkToStart = null;
56: }
57:
58: public void handleEvent(Event evt) {
59: Element currTarget = (Element) evt.getCurrentTarget();
60:
61: ItsNatDocument itsNatDoc = getItsNatDocument();
62: ElementCSSInlineStyle style = (ElementCSSInlineStyle) itsNatDoc
63: .getItsNatNode(currTarget);
64: CSSStyleDeclaration cssDec = (CSSStyleDeclaration) style
65: .getStyle();
66:
67: CSSValueList border = (CSSValueList) cssDec
68: .getPropertyCSSValue("border");
69: int len = border.getLength();
70: String cssText = "";
71: for (int i = 0; i < len; i++) {
72: CSSValue value = border.item(i);
73: if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
74: CSSPrimitiveValue primValue = (CSSPrimitiveValue) value;
75: if (primValue.getPrimitiveType() == CSSPrimitiveValue.CSS_RGBCOLOR) {
76: RGBColor rgb = primValue.getRGBColorValue();
77: log("Current border color: rgb("
78: + rgb.getRed().getCssText() + ","
79: + rgb.getGreen().getCssText() + ","
80: + rgb.getBlue().getCssText() + ")");
81: } else
82: cssText += primValue.getCssText() + " ";
83: } else
84: cssText += value.getCssText() + " ";
85: }
86: cssDec.setProperty("border", cssText, null); // Removed border color
87:
88: CSS2Properties cssDec2 = (CSS2Properties) style.getStyle();
89: String newColor = "rgb(255,100,150)";
90: cssDec2.setBorderColor(newColor);// border-color property
91: log("New border color: " + cssDec2.getBorderColor());
92: }
93:
94: }
|