KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > css > dom > CSSOMValue


1 /*
2
3    Copyright 2002-2003 The Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16
17  */

18 package org.apache.batik.css.dom;
19
20 import org.apache.batik.css.engine.value.FloatValue;
21 import org.apache.batik.css.engine.value.ListValue;
22 import org.apache.batik.css.engine.value.StringValue;
23 import org.apache.batik.css.engine.value.Value;
24 import org.w3c.dom.DOMException JavaDoc;
25 import org.w3c.dom.css.CSSPrimitiveValue;
26 import org.w3c.dom.css.CSSValue;
27 import org.w3c.dom.css.CSSValueList;
28 import org.w3c.dom.css.Counter;
29 import org.w3c.dom.css.RGBColor;
30 import org.w3c.dom.css.Rect;
31
32 /**
33  * This class implements the {@link org.w3c.dom.css.CSSValue},
34  * {@link org.w3c.dom.css.CSSPrimitiveValue},
35  * {@link org.w3c.dom.css.CSSValueList} interfaces.
36  *
37  * @author <a HREF="mailto:stephane@hillion.org">Stephane Hillion</a>
38  * @version $Id: CSSOMValue.java,v 1.5 2004/08/18 07:12:47 vhardy Exp $
39  */

40 public class CSSOMValue
41     implements CSSPrimitiveValue,
42                CSSValueList,
43                Counter,
44                Rect,
45                RGBColor {
46     
47     /**
48      * The associated value.
49      */

50     protected ValueProvider valueProvider;
51
52     /**
53      * The modifications handler.
54      */

55     protected ModificationHandler handler;
56
57     /**
58      * The left component, if this value is a Rect.
59      */

60     protected LeftComponent leftComponent;
61
62     /**
63      * The right component, if this value is a Rect.
64      */

65     protected RightComponent rightComponent;
66
67     /**
68      * The bottom component, if this value is a Rect.
69      */

70     protected BottomComponent bottomComponent;
71
72     /**
73      * The top component, if this value is a Rect.
74      */

75     protected TopComponent topComponent;
76
77     /**
78      * The red component, if this value is a RGBColor.
79      */

80     protected RedComponent redComponent;
81
82     /**
83      * The green component, if this value is a RGBColor.
84      */

85     protected GreenComponent greenComponent;
86
87     /**
88      * The blue component, if this value is a RGBColor.
89      */

90     protected BlueComponent blueComponent;
91
92     /**
93      * The list items.
94      */

95     protected CSSValue[] items;
96
97     /**
98      * Creates a new CSSOMValue.
99      */

100     public CSSOMValue(ValueProvider vp) {
101         valueProvider = vp;
102     }
103
104     /**
105      * Sets the modification handler of this value.
106      */

107     public void setModificationHandler(ModificationHandler h) {
108         handler = h;
109     }
110
111     /**
112      * <b>DOM</b>: Implements {@link org.w3c.dom.css.CSSValue#getCssText()}.
113      */

114     public String JavaDoc getCssText() {
115         return valueProvider.getValue().getCssText();
116     }
117
118     /**
119      * <b>DOM</b>: Implements {@link
120      * org.w3c.dom.css.CSSValue#setCssText(String)}.
121      */

122     public void setCssText(String JavaDoc cssText) throws DOMException JavaDoc {
123     if (handler == null) {
124             throw new DOMException JavaDoc
125                 (DOMException.NO_MODIFICATION_ALLOWED_ERR, "");
126     } else {
127             handler.textChanged(cssText);
128     }
129     }
130
131     /**
132      * <b>DOM</b>: Implements {@link
133      * org.w3c.dom.css.CSSValue#getCssValueType()}.
134      */

135     public short getCssValueType() {
136         return valueProvider.getValue().getCssValueType();
137     }
138
139     /**
140      * <b>DOM</b>: Implements {@link
141      * org.w3c.dom.css.CSSPrimitiveValue#getPrimitiveType()}.
142      */

143     public short getPrimitiveType() {
144         return valueProvider.getValue().getPrimitiveType();
145     }
146
147     /**
148      * <b>DOM</b>: Implements {@link
149      * org.w3c.dom.css.CSSPrimitiveValue#setFloatValue(short,float)}.
150      */

151     public void setFloatValue(short unitType, float floatValue)
152         throws DOMException JavaDoc {
153     if (handler == null) {
154             throw new DOMException JavaDoc
155                 (DOMException.NO_MODIFICATION_ALLOWED_ERR, "");
156     } else {
157             handler.floatValueChanged(unitType, floatValue);
158     }
159     }
160
161     /**
162      * <b>DOM</b>: Implements {@link
163      * org.w3c.dom.css.CSSPrimitiveValue#getFloatValue(short)}.
164      */

165     public float getFloatValue(short unitType) throws DOMException JavaDoc {
166         return convertFloatValue(unitType, valueProvider.getValue());
167     }
168
169     /**
170      * Converts the actual float value to the given unit type.
171      */

172     public static float convertFloatValue(short unitType, Value value) {
173     switch (unitType) {
174     case CSSPrimitiveValue.CSS_NUMBER:
175     case CSSPrimitiveValue.CSS_PERCENTAGE:
176     case CSSPrimitiveValue.CSS_EMS:
177     case CSSPrimitiveValue.CSS_EXS:
178     case CSSPrimitiveValue.CSS_DIMENSION:
179     case CSSPrimitiveValue.CSS_PX:
180         if (value.getPrimitiveType() == unitType) {
181         return value.getFloatValue();
182         }
183         break;
184     case CSSPrimitiveValue.CSS_CM:
185         return toCentimeters(value);
186     case CSSPrimitiveValue.CSS_MM:
187         return toMillimeters(value);
188     case CSSPrimitiveValue.CSS_IN:
189         return toInches(value);
190     case CSSPrimitiveValue.CSS_PT:
191         return toPoints(value);
192     case CSSPrimitiveValue.CSS_PC:
193         return toPicas(value);
194     case CSSPrimitiveValue.CSS_DEG:
195         return toDegrees(value);
196     case CSSPrimitiveValue.CSS_RAD:
197         return toRadians(value);
198     case CSSPrimitiveValue.CSS_GRAD:
199         return toGradians(value);
200     case CSSPrimitiveValue.CSS_MS:
201         return toMilliseconds(value);
202     case CSSPrimitiveValue.CSS_S:
203         return toSeconds(value);
204     case CSSPrimitiveValue.CSS_HZ:
205         return toHertz(value);
206     case CSSPrimitiveValue.CSS_KHZ:
207         return tokHertz(value);
208     }
209         throw new DOMException JavaDoc(DOMException.INVALID_ACCESS_ERR, "");
210     }
211
212     /**
213      * Converts the current value into centimeters.
214      */

215     protected static float toCentimeters(Value value) {
216     switch (value.getPrimitiveType()) {
217     case CSSPrimitiveValue.CSS_CM:
218         return value.getFloatValue();
219     case CSSPrimitiveValue.CSS_MM:
220         return (value.getFloatValue() / 10);
221     case CSSPrimitiveValue.CSS_IN:
222         return (value.getFloatValue() * 2.54f);
223     case CSSPrimitiveValue.CSS_PT:
224         return (value.getFloatValue() * 2.54f / 72);
225     case CSSPrimitiveValue.CSS_PC:
226         return (value.getFloatValue() * 2.54f / 6);
227     default:
228             throw new DOMException JavaDoc(DOMException.INVALID_ACCESS_ERR, "");
229     }
230     }
231
232     /**
233      * Converts the current value into inches.
234      */

235     protected static float toInches(Value value) {
236     switch (value.getPrimitiveType()) {
237     case CSSPrimitiveValue.CSS_CM:
238         return (value.getFloatValue() / 2.54f);
239     case CSSPrimitiveValue.CSS_MM:
240         return (value.getFloatValue() / 25.4f);
241     case CSSPrimitiveValue.CSS_IN:
242         return value.getFloatValue();
243     case CSSPrimitiveValue.CSS_PT:
244         return (value.getFloatValue() / 72);
245     case CSSPrimitiveValue.CSS_PC:
246         return (value.getFloatValue() / 6);
247     default:
248             throw new DOMException JavaDoc(DOMException.INVALID_ACCESS_ERR, "");
249     }
250     }
251
252     /**
253      * Converts the current value into millimeters.
254      */

255     protected static float toMillimeters(Value value) {
256     switch (value.getPrimitiveType()) {
257     case CSSPrimitiveValue.CSS_CM:
258         return (value.getFloatValue() * 10);
259     case CSSPrimitiveValue.CSS_MM:
260         return value.getFloatValue();
261     case CSSPrimitiveValue.CSS_IN:
262         return (value.getFloatValue() * 25.4f);
263     case CSSPrimitiveValue.CSS_PT:
264         return (value.getFloatValue() * 25.4f / 72);
265     case CSSPrimitiveValue.CSS_PC:
266         return (value.getFloatValue() * 25.4f / 6);
267     default:
268             throw new DOMException JavaDoc(DOMException.INVALID_ACCESS_ERR, "");
269     }
270     }
271
272     /**
273      * Converts the current value into points.
274      */

275     protected static float toPoints(Value value) {
276     switch (value.getPrimitiveType()) {
277     case CSSPrimitiveValue.CSS_CM:
278         return (value.getFloatValue() * 72 / 2.54f);
279     case CSSPrimitiveValue.CSS_MM:
280         return (value.getFloatValue() * 72 / 25.4f);
281     case CSSPrimitiveValue.CSS_IN:
282         return (value.getFloatValue() * 72);
283     case CSSPrimitiveValue.CSS_PT:
284         return value.getFloatValue();
285     case CSSPrimitiveValue.CSS_PC:
286         return (value.getFloatValue() * 12);
287     default:
288             throw new DOMException JavaDoc(DOMException.INVALID_ACCESS_ERR, "");
289     }
290     }
291
292     /**
293      * Converts the current value into picas.
294      */

295     protected static float toPicas(Value value) {
296     switch (value.getPrimitiveType()) {
297     case CSSPrimitiveValue.CSS_CM:
298         return (value.getFloatValue() * 6 / 2.54f);
299     case CSSPrimitiveValue.CSS_MM:
300         return (value.getFloatValue() * 6 / 25.4f);
301     case CSSPrimitiveValue.CSS_IN:
302         return (value.getFloatValue() * 6);
303     case CSSPrimitiveValue.CSS_PT:
304         return (value.getFloatValue() / 12);
305     case CSSPrimitiveValue.CSS_PC:
306         return value.getFloatValue();
307     default:
308             throw new DOMException JavaDoc(DOMException.INVALID_ACCESS_ERR, "");
309     }
310     }
311
312     /**
313      * Converts the current value into degrees.
314      */

315     protected static float toDegrees(Value value) {
316     switch (value.getPrimitiveType()) {
317     case CSSPrimitiveValue.CSS_DEG:
318         return value.getFloatValue();
319     case CSSPrimitiveValue.CSS_RAD:
320         return (float)(value.getFloatValue() * 180 / Math.PI);
321     case CSSPrimitiveValue.CSS_GRAD:
322         return (value.getFloatValue() * 9 / 5);
323     default:
324             throw new DOMException JavaDoc(DOMException.INVALID_ACCESS_ERR, "");
325     }
326     }
327
328     /**
329      * Converts the current value into radians.
330      */

331     protected static float toRadians(Value value) {
332     switch (value.getPrimitiveType()) {
333     case CSSPrimitiveValue.CSS_DEG:
334         return (value.getFloatValue() * 5 / 9);
335     case CSSPrimitiveValue.CSS_RAD:
336         return value.getFloatValue();
337     case CSSPrimitiveValue.CSS_GRAD:
338         return (float)(value.getFloatValue() * 100 / Math.PI);
339     default:
340             throw new DOMException JavaDoc(DOMException.INVALID_ACCESS_ERR, "");
341     }
342     }
343
344     /**
345      * Converts the current value into gradians.
346      */

347     protected static float toGradians(Value value) {
348     switch (value.getPrimitiveType()) {
349     case CSSPrimitiveValue.CSS_DEG:
350         return (float)(value.getFloatValue() * Math.PI / 180);
351     case CSSPrimitiveValue.CSS_RAD:
352         return (float)(value.getFloatValue() * Math.PI / 100);
353     case CSSPrimitiveValue.CSS_GRAD:
354         return value.getFloatValue();
355     default:
356             throw new DOMException JavaDoc(DOMException.INVALID_ACCESS_ERR, "");
357     }
358     }
359
360     /**
361      * Converts the current value into milliseconds.
362      */

363     protected static float toMilliseconds(Value value) {
364     switch (value.getPrimitiveType()) {
365     case CSSPrimitiveValue.CSS_MS:
366         return value.getFloatValue();
367     case CSSPrimitiveValue.CSS_S:
368         return (value.getFloatValue() * 1000);
369     default:
370             throw new DOMException JavaDoc(DOMException.INVALID_ACCESS_ERR, "");
371     }
372     }
373     
374     /**
375      * Converts the current value into seconds.
376      */

377     protected static float toSeconds(Value value) {
378     switch (value.getPrimitiveType()) {
379     case CSSPrimitiveValue.CSS_MS:
380         return (value.getFloatValue() / 1000);
381     case CSSPrimitiveValue.CSS_S:
382         return value.getFloatValue();
383     default:
384             throw new DOMException JavaDoc(DOMException.INVALID_ACCESS_ERR, "");
385     }
386     }
387     
388     /**
389      * Converts the current value into Hertz.
390      */

391     protected static float toHertz(Value value) {
392     switch (value.getPrimitiveType()) {
393     case CSSPrimitiveValue.CSS_HZ:
394         return value.getFloatValue();
395     case CSSPrimitiveValue.CSS_KHZ:
396         return (value.getFloatValue() / 1000);
397     default:
398             throw new DOMException JavaDoc(DOMException.INVALID_ACCESS_ERR, "");
399     }
400     }
401
402     /**
403      * Converts the current value into kHertz.
404      */

405     protected static float tokHertz(Value value) {
406     switch (value.getPrimitiveType()) {
407     case CSSPrimitiveValue.CSS_HZ:
408         return (value.getFloatValue() * 1000);
409     case CSSPrimitiveValue.CSS_KHZ:
410         return value.getFloatValue();
411     default:
412             throw new DOMException JavaDoc(DOMException.INVALID_ACCESS_ERR, "");
413     }
414     }
415
416    /**
417      * <b>DOM</b>: Implements {@link
418      * org.w3c.dom.css.CSSPrimitiveValue#setStringValue(short,String)}.
419      */

420     public void setStringValue(short stringType, String JavaDoc stringValue)
421         throws DOMException JavaDoc {
422     if (handler == null) {
423             throw new DOMException JavaDoc
424                 (DOMException.NO_MODIFICATION_ALLOWED_ERR, "");
425     } else {
426             handler.stringValueChanged(stringType, stringValue);
427     }
428     }
429
430     /**
431      * <b>DOM</b>: Implements {@link
432      * org.w3c.dom.css.CSSPrimitiveValue#getStringValue()}.
433      */

434     public String JavaDoc getStringValue() throws DOMException JavaDoc {
435         return valueProvider.getValue().getStringValue();
436     }
437
438     /**
439      * <b>DOM</b>: Implements {@link
440      * org.w3c.dom.css.CSSPrimitiveValue#getCounterValue()}.
441      */

442     public Counter getCounterValue() throws DOMException JavaDoc {
443         return this;
444     }
445
446     /**
447      * <b>DOM</b>: Implements {@link
448      * org.w3c.dom.css.CSSPrimitiveValue#getRectValue()}.
449      */

450     public Rect getRectValue() throws DOMException JavaDoc {
451         return this;
452     }
453
454     /**
455      * <b>DOM</b>: Implements {@link
456      * org.w3c.dom.css.CSSPrimitiveValue#getRGBColorValue()}.
457      */

458     public RGBColor getRGBColorValue() throws DOMException JavaDoc {
459         return this;
460     }
461
462     // CSSValueList ///////////////////////////////////////////////////////
463

464     /**
465      * <b>DOM</b>: Implements {@link org.w3c.dom.css.CSSValueList#getLength()}.
466      */

467     public int getLength() {
468         return valueProvider.getValue().getLength();
469     }
470
471     /**
472      * <b>DOM</b>: Implements {@link org.w3c.dom.css.CSSValueList#item(int)}.
473      */

474     public CSSValue item(int index) {
475         int len = valueProvider.getValue().getLength();
476         if (index < 0 || index >= len) {
477             return null;
478         }
479         if (items == null) {
480             items = new CSSValue[valueProvider.getValue().getLength()];
481         } else if (items.length < len) {
482             CSSValue[] nitems = new CSSValue[len];
483             for (int i = 0; i < items.length; i++) {
484                 nitems[i] = items[i];
485             }
486             items = nitems;
487         }
488         CSSValue result = items[index];
489         if (result == null) {
490             items[index] = result = new ListComponent(index);
491         }
492         return result;
493     }
494
495     // Counter /////////////////////////////////////////////////////////////
496

497     /**
498      * <b>DOM</b>: Implements {@link org.w3c.dom.css.Counter#getIdentifier()}.
499      */

500     public String JavaDoc getIdentifier() {
501         return valueProvider.getValue().getIdentifier();
502     }
503
504     /**
505      * <b>DOM</b>: Implements {@link org.w3c.dom.css.Counter#getListStyle()}.
506      */

507     public String JavaDoc getListStyle() {
508         return valueProvider.getValue().getListStyle();
509     }
510
511     /**
512      * <b>DOM</b>: Implements {@link org.w3c.dom.css.Counter#getSeparator()}.
513      */

514     public String JavaDoc getSeparator() {
515         return valueProvider.getValue().getSeparator();
516     }
517
518     // Rect ///////////////////////////////////////////////////////////////
519

520     /**
521      * <b>DOM</b>: Implements {@link org.w3c.dom.css.Rect#getTop()}.
522      */

523     public CSSPrimitiveValue getTop() {
524         valueProvider.getValue().getTop();
525         if (topComponent == null) {
526             topComponent = new TopComponent();
527         }
528         return topComponent;
529     }
530
531     /**
532      * <b>DOM</b>: Implements {@link org.w3c.dom.css.Rect#getRight()}.
533      */

534     public CSSPrimitiveValue getRight() {
535         valueProvider.getValue().getRight();
536         if (rightComponent == null) {
537             rightComponent = new RightComponent();
538         }
539         return rightComponent;
540     }
541
542     /**
543      * <b>DOM</b>: Implements {@link org.w3c.dom.css.Rect#getBottom()}.
544      */

545     public CSSPrimitiveValue getBottom() {
546         valueProvider.getValue().getBottom();
547         if (bottomComponent == null) {
548             bottomComponent = new BottomComponent();
549         }
550         return bottomComponent;
551     }
552
553     /**
554      * <b>DOM</b>: Implements {@link org.w3c.dom.css.Rect#getLeft()}.
555      */

556     public CSSPrimitiveValue getLeft() {
557         valueProvider.getValue().getLeft();
558         if (leftComponent == null) {
559             leftComponent = new LeftComponent();
560         }
561         return leftComponent;
562     }
563
564     // RGBColor ///////////////////////////////////////////////////
565

566     /**
567      * <b>DOM</b>: Implements {@link org.w3c.dom.css.RGBColor#getRed()}.
568      */

569     public CSSPrimitiveValue getRed() {
570         valueProvider.getValue().getRed();
571         if (redComponent == null) {
572             redComponent = new RedComponent();
573         }
574         return redComponent;
575     }
576
577     /**
578      * <b>DOM</b>: Implements {@link org.w3c.dom.css.RGBColor#getGreen()}.
579      */

580     public CSSPrimitiveValue getGreen() {
581         valueProvider.getValue().getGreen();
582         if (greenComponent == null) {
583             greenComponent = new GreenComponent();
584         }
585         return greenComponent;
586     }
587
588
589     /**
590      * <b>DOM</b>: Implements {@link org.w3c.dom.css.RGBColor#getBlue()}.
591      */

592     public CSSPrimitiveValue getBlue() {
593         valueProvider.getValue().getBlue();
594         if (blueComponent == null) {
595             blueComponent = new BlueComponent();
596         }
597         return blueComponent;
598     }
599
600     /**
601      * To provides the actual value.
602      */

603     public interface ValueProvider {
604
605         /**
606          * Returns the current value associated with this object.
607          */

608         Value getValue();
609     }
610
611     /**
612      * To manage the modifications on a CSS value.
613      */

614     public interface ModificationHandler {
615
616         /**
617          * Called when the value text has changed.
618          */

619         void textChanged(String JavaDoc text) throws DOMException JavaDoc;
620
621         /**
622          * Called when the float value has changed.
623          */

624         void floatValueChanged(short unit, float value) throws DOMException JavaDoc;
625
626         /**
627          * Called when the string value has changed.
628          */

629         void stringValueChanged(short type, String JavaDoc value) throws DOMException JavaDoc;
630
631         /**
632          * Called when the left value text has changed.
633          */

634         void leftTextChanged(String JavaDoc text) throws DOMException JavaDoc;
635
636         /**
637          * Called when the left float value has changed.
638          */

639         void leftFloatValueChanged(short unit, float value)
640             throws DOMException JavaDoc;
641
642         /**
643          * Called when the top value text has changed.
644          */

645         void topTextChanged(String JavaDoc text) throws DOMException JavaDoc;
646
647         /**
648          * Called when the top float value has changed.
649          */

650         void topFloatValueChanged(short unit, float value)
651             throws DOMException JavaDoc;
652
653         /**
654          * Called when the right value text has changed.
655          */

656         void rightTextChanged(String JavaDoc text) throws DOMException JavaDoc;
657
658         /**
659          * Called when the right float value has changed.
660          */

661         void rightFloatValueChanged(short unit, float value)
662             throws DOMException JavaDoc;
663
664         /**
665          * Called when the bottom value text has changed.
666          */

667         void bottomTextChanged(String JavaDoc text) throws DOMException JavaDoc;
668
669         /**
670          * Called when the bottom float value has changed.
671          */

672         void bottomFloatValueChanged(short unit, float value)
673             throws DOMException JavaDoc;
674
675         /**
676          * Called when the red value text has changed.
677          */

678         void redTextChanged(String JavaDoc text) throws DOMException JavaDoc;
679
680         /**
681          * Called when the red float value has changed.
682          */

683         void redFloatValueChanged(short unit, float value)
684             throws DOMException JavaDoc;
685
686         /**
687          * Called when the green value text has changed.
688          */

689         void greenTextChanged(String JavaDoc text) throws DOMException JavaDoc;
690
691         /**
692          * Called when the green float value has changed.
693          */

694         void greenFloatValueChanged(short unit, float value)
695             throws DOMException JavaDoc;
696
697         /**
698          * Called when the blue value text has changed.
699          */

700         void blueTextChanged(String JavaDoc text) throws DOMException JavaDoc;
701
702         /**
703          * Called when the blue float value has changed.
704          */

705         void blueFloatValueChanged(short unit, float value)
706             throws DOMException JavaDoc;
707
708         /**
709          * Called when the list value text has changed.
710          */

711         void listTextChanged(int idx, String JavaDoc text) throws DOMException JavaDoc;
712
713         /**
714          * Called when the list float value has changed.
715          */

716         void listFloatValueChanged(int idx, short unit, float value)
717             throws DOMException JavaDoc;
718
719         /**
720          * Called when the list string value has changed.
721          */

722         void listStringValueChanged(int idx, short unit, String JavaDoc value)
723             throws DOMException JavaDoc;
724
725     }
726
727     /**
728      * This class provides an abstract implementation of a ModificationHandler.
729      */

730     public abstract class AbstractModificationHandler
731         implements ModificationHandler {
732
733         /**
734          * Returns the associated value.
735          */

736         protected abstract Value getValue();
737
738         /**
739          * Called when the float value has changed.
740          */

741         public void floatValueChanged(short unit, float value)
742             throws DOMException JavaDoc {
743             textChanged(FloatValue.getCssText(unit, value));
744         }
745
746         /**
747          * Called when the string value has changed.
748          */

749         public void stringValueChanged(short type, String JavaDoc value)
750             throws DOMException JavaDoc {
751             textChanged(StringValue.getCssText(type, value));
752         }
753
754         /**
755          * Called when the left value text has changed.
756          */

757         public void leftTextChanged(String JavaDoc text) throws DOMException JavaDoc {
758             text = "rect(" +
759                 getValue().getTop().getCssText() + ", " +
760                 getValue().getRight().getCssText() + ", " +
761                 getValue().getBottom().getCssText() + ", " +
762                 text + ")";
763             textChanged(text);
764         }
765
766         /**
767          * Called when the left float value has changed.
768          */

769         public void leftFloatValueChanged(short unit, float value)
770             throws DOMException JavaDoc {
771             String JavaDoc text = "rect(" +
772                 getValue().getTop().getCssText() + ", " +
773                 getValue().getRight().getCssText() + ", " +
774                 getValue().getBottom().getCssText() + ", " +
775                 FloatValue.getCssText(unit, value) + ")";
776             textChanged(text);
777         }
778
779         /**
780          * Called when the top value text has changed.
781          */

782         public void topTextChanged(String JavaDoc text) throws DOMException JavaDoc {
783             text = "rect(" +
784                 text + ", " +
785                 getValue().getRight().getCssText() + ", " +
786                 getValue().getBottom().getCssText() + ", " +
787                 getValue().getLeft().getCssText() + ")";
788             textChanged(text);
789         }
790
791         /**
792          * Called when the top float value has changed.
793          */

794         public void topFloatValueChanged(short unit, float value)
795             throws DOMException JavaDoc {
796             String JavaDoc text = "rect(" +
797                 FloatValue.getCssText(unit, value) + ", " +
798                 getValue().getRight().getCssText() + ", " +
799                 getValue().getBottom().getCssText() + ", " +
800                 getValue().getLeft().getCssText() + ")";
801             textChanged(text);
802         }
803
804         /**
805          * Called when the right value text has changed.
806          */

807         public void rightTextChanged(String JavaDoc text) throws DOMException JavaDoc {
808             text = "rect(" +
809                 getValue().getTop().getCssText() + ", " +
810                 text + ", " +
811                 getValue().getBottom().getCssText() + ", " +
812                 getValue().getLeft().getCssText() + ")";
813             textChanged(text);
814         }
815
816         /**
817          * Called when the right float value has changed.
818          */

819         public void rightFloatValueChanged(short unit, float value)
820             throws DOMException JavaDoc {
821             String JavaDoc text = "rect(" +
822                 getValue().getTop().getCssText() + ", " +
823                 FloatValue.getCssText(unit, value) + ", " +
824                 getValue().getBottom().getCssText() + ", " +
825                 getValue().getLeft().getCssText() + ")";
826             textChanged(text);
827         }
828
829         /**
830          * Called when the bottom value text has changed.
831          */

832         public void bottomTextChanged(String JavaDoc text) throws DOMException JavaDoc {
833             text = "rect(" +
834                 getValue().getTop().getCssText() + ", " +
835                 getValue().getRight().getCssText() + ", " +
836                 text + ", " +
837                 getValue().getLeft().getCssText() + ")";
838             textChanged(text);
839         }
840
841         /**
842          * Called when the bottom float value has changed.
843          */

844         public void bottomFloatValueChanged(short unit, float value)
845             throws DOMException JavaDoc {
846             String JavaDoc text = "rect(" +
847                 getValue().getTop().getCssText() + ", " +
848                 getValue().getRight().getCssText() + ", " +
849                 FloatValue.getCssText(unit, value) + ", " +
850                 getValue().getLeft().getCssText() + ")";
851             textChanged(text);
852         }
853
854         /**
855          * Called when the red value text has changed.
856          */

857         public void redTextChanged(String JavaDoc text) throws DOMException JavaDoc {
858             text = "rgb(" +
859                 text + ", " +
860                 getValue().getGreen().getCssText() + ", " +
861                 getValue().getBlue().getCssText() + ")";
862             textChanged(text);
863         }
864
865         /**
866          * Called when the red float value has changed.
867          */

868         public void redFloatValueChanged(short unit, float value)
869             throws DOMException JavaDoc {
870             String JavaDoc text = "rgb(" +
871                 FloatValue.getCssText(unit, value) + ", " +
872                 getValue().getGreen().getCssText() + ", " +
873                 getValue().getBlue().getCssText() + ")";
874             textChanged(text);
875         }
876
877         /**
878          * Called when the green value text has changed.
879          */

880         public void greenTextChanged(String JavaDoc text) throws DOMException JavaDoc {
881             text = "rgb(" +
882                 getValue().getRed().getCssText() + ", " +
883                 text + ", " +
884                 getValue().getBlue().getCssText() + ")";
885             textChanged(text);
886         }
887
888         /**
889          * Called when the green float value has changed.
890          */

891         public void greenFloatValueChanged(short unit, float value)
892             throws DOMException JavaDoc {
893             String JavaDoc text = "rgb(" +
894                 getValue().getRed().getCssText() + ", " +
895                 FloatValue.getCssText(unit, value) + ", " +
896                 getValue().getBlue().getCssText() + ")";
897             textChanged(text);
898         }
899
900         /**
901          * Called when the blue value text has changed.
902          */

903         public void blueTextChanged(String JavaDoc text) throws DOMException JavaDoc {
904             text = "rgb(" +
905                 getValue().getRed().getCssText() + ", " +
906                 getValue().getGreen().getCssText() + ", " +
907                 text + ")";
908             textChanged(text);
909         }
910
911         /**
912          * Called when the blue float value has changed.
913          */

914         public void blueFloatValueChanged(short unit, float value)
915             throws DOMException JavaDoc {
916             String JavaDoc text = "rgb(" +
917                 getValue().getRed().getCssText() + ", " +
918                 getValue().getGreen().getCssText() + ", " +
919                 FloatValue.getCssText(unit, value) + ")";
920             textChanged(text);
921         }
922
923         /**
924          * Called when the list value text has changed.
925          */

926         public void listTextChanged(int idx, String JavaDoc text) throws DOMException JavaDoc {
927             ListValue lv = (ListValue)getValue();
928             StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
929             for (int i = 0; i < idx; i++) {
930                 sb.append(lv.item(i).getCssText());
931                 sb.append(lv.getSeparatorChar());
932             }
933             sb.append(text);
934             int len = lv.getLength();
935             for (int i = idx + 1; i < len; i++) {
936                 sb.append(lv.getSeparatorChar());
937                 sb.append(lv.item(i).getCssText());
938             }
939             text = sb.toString();
940             textChanged(text);
941         }
942
943         /**
944          * Called when the list float value has changed.
945          */

946         public void listFloatValueChanged(int idx, short unit, float value)
947             throws DOMException JavaDoc {
948             ListValue lv = (ListValue)getValue();
949             StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
950             for (int i = 0; i < idx; i++) {
951                 sb.append(lv.item(i).getCssText());
952                 sb.append(lv.getSeparatorChar());
953             }
954             sb.append(FloatValue.getCssText(unit, value));
955             int len = lv.getLength();
956             for (int i = idx + 1; i < len; i++) {
957                 sb.append(lv.getSeparatorChar());
958                 sb.append(lv.item(i).getCssText());
959             }
960             textChanged(sb.toString());
961         }
962
963         /**
964          * Called when the list string value has changed.
965          */

966         public void listStringValueChanged(int idx, short unit, String JavaDoc value)
967             throws DOMException JavaDoc {
968             ListValue lv = (ListValue)getValue();
969             StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
970             for (int i = 0; i < idx; i++) {
971                 sb.append(lv.item(i).getCssText());
972                 sb.append(lv.getSeparatorChar());
973             }
974             sb.append(StringValue.getCssText(unit, value));
975             int len = lv.getLength();
976             for (int i = idx + 1; i < len; i++) {
977                 sb.append(lv.getSeparatorChar());
978                 sb.append(lv.item(i).getCssText());
979             }
980             textChanged(sb.toString());
981         }
982     }
983
984     /**
985      * To store a component.
986      */

987     protected abstract class AbstractComponent implements CSSPrimitiveValue {
988
989         /**
990          * The returns the actual value of this component.
991          */

992         protected abstract Value getValue();
993
994         /**
995          * <b>DOM</b>: Implements {@link
996          * org.w3c.dom.css.CSSValue#getCssText()}.
997          */

998         public String JavaDoc getCssText() {
999             return getValue().getCssText();
1000        }
1001
1002        /**
1003         * <b>DOM</b>: Implements {@link
1004         * org.w3c.dom.css.CSSValue#getCssValueType()}.
1005         */

1006        public short getCssValueType() {
1007            return getValue().getCssValueType();
1008        }
1009
1010        /**
1011         * <b>DOM</b>: Implements {@link
1012         * org.w3c.dom.css.CSSPrimitiveValue#getPrimitiveType()}.
1013         */

1014        public short getPrimitiveType() {
1015            return getValue().getPrimitiveType();
1016        }
1017
1018        /**
1019         * <b>DOM</b>: Implements {@link
1020         * org.w3c.dom.css.CSSPrimitiveValue#getFloatValue(short)}.
1021         */

1022        public float getFloatValue(short unitType) throws DOMException JavaDoc {
1023            return convertFloatValue(unitType, getValue());
1024        }
1025
1026        /**
1027         * <b>DOM</b>: Implements {@link
1028         * org.w3c.dom.css.CSSPrimitiveValue#getStringValue()}.
1029         */

1030        public String JavaDoc getStringValue() throws DOMException JavaDoc {
1031            return valueProvider.getValue().getStringValue();
1032        }
1033        
1034        /**
1035         * <b>DOM</b>: Implements {@link
1036         * org.w3c.dom.css.CSSPrimitiveValue#getCounterValue()}.
1037         */

1038        public Counter getCounterValue() throws DOMException JavaDoc {
1039            throw new DOMException JavaDoc(DOMException.INVALID_ACCESS_ERR, "");
1040        }
1041        
1042        /**
1043         * <b>DOM</b>: Implements {@link
1044         * org.w3c.dom.css.CSSPrimitiveValue#getRectValue()}.
1045         */

1046        public Rect getRectValue() throws DOMException JavaDoc {
1047            throw new DOMException JavaDoc(DOMException.INVALID_ACCESS_ERR, "");
1048        }
1049
1050        /**
1051         * <b>DOM</b>: Implements {@link
1052         * org.w3c.dom.css.CSSPrimitiveValue#getRGBColorValue()}.
1053         */

1054        public RGBColor getRGBColorValue() throws DOMException JavaDoc {
1055            throw new DOMException JavaDoc(DOMException.INVALID_ACCESS_ERR, "");
1056        }
1057
1058        // CSSValueList ///////////////////////////////////////////////////////
1059

1060        /**
1061         * <b>DOM</b>: Implements {@link
1062         * org.w3c.dom.css.CSSValueList#getLength()}.
1063         */

1064        public int getLength() {
1065            throw new DOMException JavaDoc(DOMException.INVALID_ACCESS_ERR, "");
1066        }
1067        
1068        /**
1069         * <b>DOM</b>: Implements {@link
1070         * org.w3c.dom.css.CSSValueList#item(int)}.
1071         */

1072        public CSSValue item(int index) {
1073            throw new DOMException JavaDoc(DOMException.INVALID_ACCESS_ERR, "");
1074        }
1075    }
1076
1077    /**
1078     * To store a Float component.
1079     */

1080    protected abstract class FloatComponent extends AbstractComponent {
1081
1082        /**
1083         * <b>DOM</b>: Implements {@link
1084         * org.w3c.dom.css.CSSPrimitiveValue#setStringValue(short,String)}.
1085         */

1086        public void setStringValue(short stringType, String JavaDoc stringValue)
1087            throws DOMException JavaDoc {
1088            throw new DOMException JavaDoc(DOMException.INVALID_ACCESS_ERR, "");
1089        }
1090    }
1091
1092    /**
1093     * To represents a left component.
1094     */

1095    protected class LeftComponent extends FloatComponent {
1096        
1097        /**
1098         * The returns the actual value of this component.
1099         */

1100        protected Value getValue() {
1101            return valueProvider.getValue().getLeft();
1102        }
1103
1104        /**
1105         * <b>DOM</b>: Implements {@link
1106         * org.w3c.dom.css.CSSValue#setCssText(String)}.
1107         */

1108        public void setCssText(String JavaDoc cssText) throws DOMException JavaDoc {
1109            if (handler == null) {
1110                throw new DOMException JavaDoc
1111                    (DOMException.NO_MODIFICATION_ALLOWED_ERR, "");
1112            } else {
1113                getValue();
1114                handler.leftTextChanged(cssText);
1115            }
1116        }
1117
1118        /**
1119         * <b>DOM</b>: Implements {@link
1120         * org.w3c.dom.css.CSSPrimitiveValue#setFloatValue(short,float)}.
1121         */

1122        public void setFloatValue(short unitType, float floatValue)
1123            throws DOMException JavaDoc {
1124            if (handler == null) {
1125                throw new DOMException JavaDoc
1126                    (DOMException.NO_MODIFICATION_ALLOWED_ERR, "");
1127            } else {
1128                getValue();
1129                handler.leftFloatValueChanged(unitType, floatValue);
1130            }
1131        }
1132
1133    }
1134
1135    /**
1136     * To represents a top component.
1137     */

1138    protected class TopComponent extends FloatComponent {
1139        
1140        /**
1141         * The returns the actual value of this component.
1142         */

1143        protected Value getValue() {
1144            return valueProvider.getValue().getTop();
1145        }
1146
1147        /**
1148         * <b>DOM</b>: Implements {@link
1149         * org.w3c.dom.css.CSSValue#setCssText(String)}.
1150         */

1151        public void setCssText(String JavaDoc cssText) throws DOMException JavaDoc {
1152            if (handler == null) {
1153                throw new DOMException JavaDoc
1154                    (DOMException.NO_MODIFICATION_ALLOWED_ERR, "");
1155            } else {
1156                getValue();
1157                handler.topTextChanged(cssText);
1158            }
1159        }
1160
1161        /**
1162         * <b>DOM</b>: Implements {@link
1163         * org.w3c.dom.css.CSSPrimitiveValue#setFloatValue(short,float)}.
1164         */

1165        public void setFloatValue(short unitType, float floatValue)
1166            throws DOMException JavaDoc {
1167            if (handler == null) {
1168                throw new DOMException JavaDoc
1169                    (DOMException.NO_MODIFICATION_ALLOWED_ERR, "");
1170            } else {
1171                getValue();
1172                handler.topFloatValueChanged(unitType, floatValue);
1173            }
1174        }
1175
1176    }
1177
1178    /**
1179     * To represents a right component.
1180     */

1181    protected class RightComponent extends FloatComponent {
1182        
1183        /**
1184         * The returns the actual value of this component.
1185         */

1186        protected Value getValue() {
1187            return valueProvider.getValue().getRight();
1188        }
1189
1190        /**
1191         * <b>DOM</b>: Implements {@link
1192         * org.w3c.dom.css.CSSValue#setCssText(String)}.
1193         */

1194        public void setCssText(String JavaDoc cssText) throws DOMException JavaDoc {
1195            if (handler == null) {
1196                throw new DOMException JavaDoc
1197                    (DOMException.NO_MODIFICATION_ALLOWED_ERR, "");
1198            } else {
1199                getValue();
1200                handler.rightTextChanged(cssText);
1201            }
1202        }
1203
1204        /**
1205         * <b>DOM</b>: Implements {@link
1206         * org.w3c.dom.css.CSSPrimitiveValue#setFloatValue(short,float)}.
1207         */

1208        public void setFloatValue(short unitType, float floatValue)
1209            throws DOMException JavaDoc {
1210            if (handler == null) {
1211                throw new DOMException JavaDoc
1212                    (DOMException.NO_MODIFICATION_ALLOWED_ERR, "");
1213            } else {
1214                getValue();
1215                handler.rightFloatValueChanged(unitType, floatValue);
1216            }
1217        }
1218
1219    }
1220
1221
1222    /**
1223     * To represents a bottom component.
1224     */

1225    protected class BottomComponent extends FloatComponent {
1226        
1227        /**
1228         * The returns the actual value of this component.
1229         */

1230        protected Value getValue() {
1231            return valueProvider.getValue().getBottom();
1232        }
1233
1234        /**
1235         * <b>DOM</b>: Implements {@link
1236         * org.w3c.dom.css.CSSValue#setCssText(String)}.
1237         */

1238        public void setCssText(String JavaDoc cssText) throws DOMException JavaDoc {
1239            if (handler == null) {
1240                throw new DOMException JavaDoc
1241                    (DOMException.NO_MODIFICATION_ALLOWED_ERR, "");
1242            } else {
1243                getValue();
1244                handler.bottomTextChanged(cssText);
1245            }
1246        }
1247
1248        /**
1249         * <b>DOM</b>: Implements {@link
1250         * org.w3c.dom.css.CSSPrimitiveValue#setFloatValue(short,float)}.
1251         */

1252        public void setFloatValue(short unitType, float floatValue)
1253            throws DOMException JavaDoc {
1254            if (handler == null) {
1255                throw new DOMException JavaDoc
1256                    (DOMException.NO_MODIFICATION_ALLOWED_ERR, "");
1257            } else {
1258                getValue();
1259                handler.bottomFloatValueChanged(unitType, floatValue);
1260            }
1261        }
1262
1263    }
1264
1265
1266    /**
1267     * To represents a red component.
1268     */

1269    protected class RedComponent extends FloatComponent {
1270        
1271        /**
1272         * The returns the actual value of this component.
1273         */

1274        protected Value getValue() {
1275            return valueProvider.getValue().getRed();
1276        }
1277
1278        /**
1279         * <b>DOM</b>: Implements {@link
1280         * org.w3c.dom.css.CSSValue#setCssText(String)}.
1281         */

1282        public void setCssText(String JavaDoc cssText) throws DOMException JavaDoc {
1283            if (handler == null) {
1284                throw new DOMException JavaDoc
1285                    (DOMException.NO_MODIFICATION_ALLOWED_ERR, "");
1286            } else {
1287                getValue();
1288                handler.redTextChanged(cssText);
1289            }
1290        }
1291
1292        /**
1293         * <b>DOM</b>: Implements {@link
1294         * org.w3c.dom.css.CSSPrimitiveValue#setFloatValue(short,float)}.
1295         */

1296        public void setFloatValue(short unitType, float floatValue)
1297            throws DOMException JavaDoc {
1298            if (handler == null) {
1299                throw new DOMException JavaDoc
1300                    (DOMException.NO_MODIFICATION_ALLOWED_ERR, "");
1301            } else {
1302                getValue();
1303                handler.redFloatValueChanged(unitType, floatValue);
1304            }
1305        }
1306
1307    }
1308
1309
1310    /**
1311     * To represents a green component.
1312     */

1313    protected class GreenComponent extends FloatComponent {
1314        
1315        /**
1316         * The returns the actual value of this component.
1317         */

1318        protected Value getValue() {
1319            return valueProvider.getValue().getGreen();
1320        }
1321
1322        /**
1323         * <b>DOM</b>: Implements {@link
1324         * org.w3c.dom.css.CSSValue#setCssText(String)}.
1325         */

1326        public void setCssText(String JavaDoc cssText) throws DOMException JavaDoc {
1327            if (handler == null) {
1328                throw new DOMException JavaDoc
1329                    (DOMException.NO_MODIFICATION_ALLOWED_ERR, "");
1330            } else {
1331                getValue();
1332                handler.greenTextChanged(cssText);
1333            }
1334        }
1335
1336        /**
1337         * <b>DOM</b>: Implements {@link
1338         * org.w3c.dom.css.CSSPrimitiveValue#setFloatValue(short,float)}.
1339         */

1340        public void setFloatValue(short unitType, float floatValue)
1341            throws DOMException JavaDoc {
1342            if (handler == null) {
1343                throw new DOMException JavaDoc
1344                    (DOMException.NO_MODIFICATION_ALLOWED_ERR, "");
1345            } else {
1346                getValue();
1347                handler.greenFloatValueChanged(unitType, floatValue);
1348            }
1349        }
1350
1351    }
1352
1353    /**
1354     * To represents a blue component.
1355     */

1356    protected class BlueComponent extends FloatComponent {
1357        
1358        /**
1359         * The returns the actual value of this component.
1360         */

1361        protected Value getValue() {
1362            return valueProvider.getValue().getBlue();
1363        }
1364
1365        /**
1366         * <b>DOM</b>: Implements {@link
1367         * org.w3c.dom.css.CSSValue#setCssText(String)}.
1368         */

1369        public void setCssText(String JavaDoc cssText) throws DOMException JavaDoc {
1370            if (handler == null) {
1371                throw new DOMException JavaDoc
1372                    (DOMException.NO_MODIFICATION_ALLOWED_ERR, "");
1373            } else {
1374                getValue();
1375                handler.blueTextChanged(cssText);
1376            }
1377        }
1378
1379        /**
1380         * <b>DOM</b>: Implements {@link
1381         * org.w3c.dom.css.CSSPrimitiveValue#setFloatValue(short,float)}.
1382         */

1383        public void setFloatValue(short unitType, float floatValue)
1384            throws DOMException JavaDoc {
1385            if (handler == null) {
1386                throw new DOMException JavaDoc
1387                    (DOMException.NO_MODIFICATION_ALLOWED_ERR, "");
1388            } else {
1389                getValue();
1390                handler.blueFloatValueChanged(unitType, floatValue);
1391            }
1392        }
1393
1394    }
1395
1396    /**
1397     * To represents a List component.
1398     */

1399    protected class ListComponent extends AbstractComponent {
1400        
1401        /**
1402         * The index of this component.
1403         */

1404        protected int index;
1405
1406        /**
1407         * Creates a new ListComponent.
1408         */

1409        public ListComponent(int idx) {
1410            index = idx;
1411        }
1412
1413        /**
1414         * The returns the actual value of this component.
1415         */

1416        protected Value getValue() {
1417            if (index >= valueProvider.getValue().getLength()) {
1418                throw new DOMException JavaDoc
1419                    (DOMException.NO_MODIFICATION_ALLOWED_ERR, "");
1420            }
1421            return valueProvider.getValue().item(index);
1422        }
1423
1424        /**
1425         * <b>DOM</b>: Implements {@link
1426         * org.w3c.dom.css.CSSValue#setCssText(String)}.
1427         */

1428        public void setCssText(String JavaDoc cssText) throws DOMException JavaDoc {
1429            if (handler == null) {
1430                throw new DOMException JavaDoc
1431                    (DOMException.NO_MODIFICATION_ALLOWED_ERR, "");
1432            } else {
1433                getValue();
1434                handler.listTextChanged(index, cssText);
1435            }
1436        }
1437
1438        /**
1439         * <b>DOM</b>: Implements {@link
1440         * org.w3c.dom.css.CSSPrimitiveValue#setFloatValue(short,float)}.
1441         */

1442        public void setFloatValue(short unitType, float floatValue)
1443            throws DOMException JavaDoc {
1444            if (handler == null) {
1445                throw new DOMException JavaDoc
1446                    (DOMException.NO_MODIFICATION_ALLOWED_ERR, "");
1447            } else {
1448                getValue();
1449                handler.listFloatValueChanged(index, unitType, floatValue);
1450            }
1451        }
1452
1453        /**
1454         * <b>DOM</b>: Implements {@link
1455         * org.w3c.dom.css.CSSPrimitiveValue#setStringValue(short,String)}.
1456         */

1457        public void setStringValue(short stringType, String JavaDoc stringValue)
1458            throws DOMException JavaDoc {
1459            if (handler == null) {
1460                throw new DOMException JavaDoc
1461                    (DOMException.NO_MODIFICATION_ALLOWED_ERR, "");
1462            } else {
1463                getValue();
1464                handler.listStringValueChanged(index, stringType, stringValue);
1465            }
1466        }
1467    }
1468
1469}
1470
Popular Tags