KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.ArrayList JavaDoc;
21
22 import org.apache.batik.css.engine.value.FloatValue;
23 import org.apache.batik.css.engine.value.Value;
24 import org.apache.batik.css.engine.value.svg.ICCColor;
25 import org.apache.batik.util.CSSConstants;
26
27 import org.w3c.dom.DOMException JavaDoc;
28 import org.w3c.dom.css.CSSPrimitiveValue;
29 import org.w3c.dom.css.CSSValue;
30 import org.w3c.dom.css.Counter;
31 import org.w3c.dom.css.RGBColor;
32 import org.w3c.dom.css.Rect;
33 import org.w3c.dom.svg.SVGColor;
34 import org.w3c.dom.svg.SVGICCColor;
35 import org.w3c.dom.svg.SVGNumber;
36 import org.w3c.dom.svg.SVGNumberList;
37
38 /**
39  * This class implements the {@link SVGColor} interface.
40  *
41  * @author <a HREF="mailto:stephane@hillion.org">Stephane Hillion</a>
42  * @version $Id: CSSOMSVGColor.java,v 1.8 2005/03/29 02:26:36 cam Exp $
43  */

44 public class CSSOMSVGColor
45     implements SVGColor,
46                RGBColor,
47                SVGICCColor,
48                SVGNumberList {
49     
50     /**
51      * The associated value.
52      */

53     protected ValueProvider valueProvider;
54
55     /**
56      * The modifications handler.
57      */

58     protected ModificationHandler handler;
59
60     /**
61      * The red component, if this value is a RGBColor.
62      */

63     protected RedComponent redComponent;
64
65     /**
66      * The green component, if this value is a RGBColor.
67      */

68     protected GreenComponent greenComponent;
69
70     /**
71      * The blue component, if this value is a RGBColor.
72      */

73     protected BlueComponent blueComponent;
74
75     /**
76      * To store the ICC color list.
77      */

78     protected ArrayList JavaDoc iccColors;
79
80     /**
81      * Creates a new CSSOMSVGColor.
82      */

83     public CSSOMSVGColor(ValueProvider vp) {
84         valueProvider = vp;
85     }
86
87     /**
88      * Sets the modification handler of this value.
89      */

90     public void setModificationHandler(ModificationHandler h) {
91         handler = h;
92     }
93
94     /**
95      * <b>DOM</b>: Implements {@link org.w3c.dom.css.CSSValue#getCssText()}.
96      */

97     public String JavaDoc getCssText() {
98         return valueProvider.getValue().getCssText();
99     }
100
101     /**
102      * <b>DOM</b>: Implements {@link
103      * org.w3c.dom.css.CSSValue#setCssText(String)}.
104      */

105     public void setCssText(String JavaDoc cssText) throws DOMException JavaDoc {
106     if (handler == null) {
107             throw new DOMException JavaDoc
108                 (DOMException.NO_MODIFICATION_ALLOWED_ERR, "");
109     } else {
110             iccColors = null;
111             handler.textChanged(cssText);
112     }
113     }
114
115     /**
116      * <b>DOM</b>: Implements {@link
117      * org.w3c.dom.css.CSSValue#getCssValueType()}.
118      */

119     public short getCssValueType() {
120         return CSS_CUSTOM;
121     }
122
123     /**
124      * <b>DOM</b>: Implements {@link
125      * org.w3c.dom.svg.SVGColor#getColorType()}.
126      */

127     public short getColorType() {
128         Value value = valueProvider.getValue();
129         switch (value.getCssValueType()) {
130         case CSSValue.CSS_PRIMITIVE_VALUE:
131             switch (value.getPrimitiveType()) {
132             case CSSPrimitiveValue.CSS_IDENT: {
133                 if (value.getStringValue().equalsIgnoreCase
134                     (CSSConstants.CSS_CURRENTCOLOR_VALUE))
135                     return SVG_COLORTYPE_CURRENTCOLOR;
136                 return SVG_COLORTYPE_RGBCOLOR;
137             }
138             case CSSPrimitiveValue.CSS_RGBCOLOR:
139                 return SVG_COLORTYPE_RGBCOLOR;
140             }
141             break;
142
143         case CSSValue.CSS_VALUE_LIST:
144             return SVG_COLORTYPE_RGBCOLOR_ICCCOLOR;
145         }
146         throw new InternalError JavaDoc();
147     }
148
149     /**
150      * <b>DOM</b>: Implements {@link
151      * org.w3c.dom.svg.SVGColor#getRGBColor()}.
152      */

153     public RGBColor getRGBColor() {
154         return this;
155     }
156
157     /**
158      * Returns the RGBColor value for this SVGColor.
159      * For the SVG 1.1 ECMAScript binding.
160      */

161     public RGBColor getRgbColor() {
162         return this;
163     }
164
165     /**
166      * <b>DOM</b>: Implements {@link
167      * org.w3c.dom.svg.SVGColor#setRGBColor(String)}.
168      */

169     public void setRGBColor(String JavaDoc color) {
170     if (handler == null) {
171             throw new DOMException JavaDoc
172                 (DOMException.NO_MODIFICATION_ALLOWED_ERR, "");
173     } else {
174             handler.rgbColorChanged(color);
175     }
176     }
177
178     /**
179      * <b>DOM</b>: Implements {@link
180      * org.w3c.dom.svg.SVGColor#getICCColor()}.
181      */

182     public SVGICCColor getICCColor() {
183         return this;
184     }
185
186     /**
187      * Returns the SVGICCColor value of this SVGColor.
188      * For the SVG 1.1 ECMAScript binding.
189      */

190     public SVGICCColor getIccColor() {
191         return this;
192     }
193
194     /**
195      * <b>DOM</b>: Implements {@link
196      * org.w3c.dom.svg.SVGColor#setRGBColorICCColor(String,String)}.
197      */

198     public void setRGBColorICCColor(String JavaDoc rgb, String JavaDoc icc) {
199     if (handler == null) {
200             throw new DOMException JavaDoc
201                 (DOMException.NO_MODIFICATION_ALLOWED_ERR, "");
202     } else {
203             iccColors = null;
204             handler.rgbColorICCColorChanged(rgb, icc);
205     }
206     }
207
208     /**
209      * <b>DOM</b>: Implements {@link
210      * org.w3c.dom.svg.SVGColor#setColor(short,String,String)}.
211      */

212     public void setColor(short type, String JavaDoc rgb, String JavaDoc icc) {
213     if (handler == null) {
214             throw new DOMException JavaDoc
215                 (DOMException.NO_MODIFICATION_ALLOWED_ERR, "");
216     } else {
217             iccColors = null;
218             handler.colorChanged(type, rgb, icc);
219     }
220     }
221
222     // RGBColor ///////////////////////////////////////////////////
223

224     /**
225      * <b>DOM</b>: Implements {@link org.w3c.dom.css.RGBColor#getRed()}.
226      */

227     public CSSPrimitiveValue getRed() {
228         valueProvider.getValue().getRed();
229         if (redComponent == null) {
230             redComponent = new RedComponent();
231         }
232         return redComponent;
233     }
234
235     /**
236      * <b>DOM</b>: Implements {@link org.w3c.dom.css.RGBColor#getGreen()}.
237      */

238     public CSSPrimitiveValue getGreen() {
239         valueProvider.getValue().getGreen();
240         if (greenComponent == null) {
241             greenComponent = new GreenComponent();
242         }
243         return greenComponent;
244     }
245
246
247     /**
248      * <b>DOM</b>: Implements {@link org.w3c.dom.css.RGBColor#getBlue()}.
249      */

250     public CSSPrimitiveValue getBlue() {
251         valueProvider.getValue().getBlue();
252         if (blueComponent == null) {
253             blueComponent = new BlueComponent();
254         }
255         return blueComponent;
256     }
257
258     // SVGICCColor //////////////////////////////////////////////////
259

260     /**
261      * <b>DOM</b>: Implements {@link org.w3c.dom.svg.SVGICCColor#getColorProfile()}.
262      */

263     public String JavaDoc getColorProfile() {
264         if (getColorType() != SVG_COLORTYPE_RGBCOLOR_ICCCOLOR) {
265             throw new DOMException JavaDoc(DOMException.SYNTAX_ERR, "");
266         }
267         Value value = valueProvider.getValue();
268         return ((ICCColor)value.item(1)).getColorProfile();
269     }
270
271     /**
272      * <b>DOM</b>: Implements {@link SVGICCColor#setColorProfile(String)}.
273      */

274     public void setColorProfile(String JavaDoc colorProfile) throws DOMException JavaDoc {
275     if (handler == null) {
276             throw new DOMException JavaDoc
277                 (DOMException.NO_MODIFICATION_ALLOWED_ERR, "");
278     } else {
279             handler.colorProfileChanged(colorProfile);
280     }
281     }
282
283     /**
284      * <b>DOM</b>: Implements {@link SVGICCColor#getColors()}.
285      */

286     public SVGNumberList getColors() {
287         return this;
288     }
289
290     // SVGNumberList ///////////////////////////////////////////////
291

292     /**
293      * <b>DOM</b>: Implements {@link SVGNumberList#getNumberOfItems()}.
294      */

295     public int getNumberOfItems() {
296         if (getColorType() != SVG_COLORTYPE_RGBCOLOR_ICCCOLOR) {
297             throw new DOMException JavaDoc(DOMException.SYNTAX_ERR, "");
298         }
299         Value value = valueProvider.getValue();
300         return ((ICCColor)value.item(1)).getNumberOfColors();
301     }
302
303     /**
304      * <b>DOM</b>: Implements {@link SVGNumberList#clear()}.
305      */

306     public void clear() throws DOMException JavaDoc {
307     if (handler == null) {
308             throw new DOMException JavaDoc
309                 (DOMException.NO_MODIFICATION_ALLOWED_ERR, "");
310     } else {
311             iccColors = null;
312             handler.colorsCleared();
313     }
314     }
315
316     /**
317      * <b>DOM</b>: Implements {@link SVGNumberList#initialize(SVGNumber)}.
318      */

319     public SVGNumber initialize(SVGNumber newItem) throws DOMException JavaDoc {
320     if (handler == null) {
321             throw new DOMException JavaDoc
322                 (DOMException.NO_MODIFICATION_ALLOWED_ERR, "");
323     } else {
324             float f = newItem.getValue();
325             iccColors = new ArrayList JavaDoc();
326             SVGNumber result = new ColorNumber(f);
327             iccColors.add(result);
328             handler.colorsInitialized(f);
329             return result;
330     }
331     }
332
333     /**
334      * <b>DOM</b>: Implements {@link SVGNumberList#getItem(int)}.
335      */

336     public SVGNumber getItem(int index) throws DOMException JavaDoc {
337         if (getColorType() != SVG_COLORTYPE_RGBCOLOR_ICCCOLOR) {
338             throw new DOMException JavaDoc(DOMException.INDEX_SIZE_ERR, "");
339         }
340         int n = getNumberOfItems();
341         if (index < 0 || index >= n) {
342             throw new DOMException JavaDoc(DOMException.INDEX_SIZE_ERR, "");
343         }
344         if (iccColors == null) {
345             iccColors = new ArrayList JavaDoc(n);
346             for (int i = iccColors.size(); i < n; i++) {
347                 iccColors.add(null);
348             }
349         }
350         Value value = valueProvider.getValue().item(1);
351         float f = ((ICCColor)value).getColor(index);
352         SVGNumber result = new ColorNumber(f);
353         iccColors.set(index, result);
354         return result;
355     }
356
357     /**
358      * <b>DOM</b>: Implements {@link
359      * SVGNumberList#insertItemBefore(SVGNumber,int)}.
360      */

361     public SVGNumber insertItemBefore(SVGNumber newItem, int index)
362         throws DOMException JavaDoc {
363     if (handler == null) {
364             throw new DOMException JavaDoc
365                 (DOMException.NO_MODIFICATION_ALLOWED_ERR, "");
366     } else {
367             int n = getNumberOfItems();
368             if (index < 0 || index > n) {
369                 throw new DOMException JavaDoc(DOMException.INDEX_SIZE_ERR, "");
370             }
371             if (iccColors == null) {
372                 iccColors = new ArrayList JavaDoc(n);
373                 for (int i = iccColors.size(); i < n; i++) {
374                     iccColors.add(null);
375                 }
376             }
377             float f = newItem.getValue();
378             SVGNumber result = new ColorNumber(f);
379             iccColors.add(index, result);
380             handler.colorInsertedBefore(f, index);
381             return result;
382     }
383     }
384
385     /**
386      * <b>DOM</b>: Implements {@link
387      * SVGNumberList#replaceItem(SVGNumber,int)}.
388      */

389     public SVGNumber replaceItem(SVGNumber newItem, int index)
390         throws DOMException JavaDoc {
391     if (handler == null) {
392             throw new DOMException JavaDoc
393                 (DOMException.NO_MODIFICATION_ALLOWED_ERR, "");
394     } else {
395             int n = getNumberOfItems();
396             if (index < 0 || index >= n) {
397                 throw new DOMException JavaDoc(DOMException.INDEX_SIZE_ERR, "");
398             }
399             if (iccColors == null) {
400                 iccColors = new ArrayList JavaDoc(n);
401                 for (int i = iccColors.size(); i < n; i++) {
402                     iccColors.add(null);
403                 }
404             }
405             float f = newItem.getValue();
406             SVGNumber result = new ColorNumber(f);
407             iccColors.set(index, result);
408             handler.colorReplaced(f, index);
409             return result;
410     }
411     }
412
413     /**
414      * <b>DOM</b>: Implements {@link SVGNumberList#removeItem(int)}.
415      */

416     public SVGNumber removeItem(int index) throws DOMException JavaDoc {
417     if (handler == null) {
418             throw new DOMException JavaDoc
419                 (DOMException.NO_MODIFICATION_ALLOWED_ERR, "");
420     } else {
421             int n = getNumberOfItems();
422             if (index < 0 || index >= n) {
423                 throw new DOMException JavaDoc(DOMException.INDEX_SIZE_ERR, "");
424             }
425             SVGNumber result = null;
426             if (iccColors != null) {
427                 result = (ColorNumber)iccColors.get(index);
428             }
429             if (result == null) {
430                 Value value = valueProvider.getValue().item(1);
431                 result =
432                     new ColorNumber(((ICCColor)value).getColor(index));
433             }
434             handler.colorRemoved(index);
435             return result;
436     }
437     }
438
439     /**
440      * <b>DOM</b>: Implements {@link SVGNumberList#appendItem(SVGNumber)}.
441      */

442     public SVGNumber appendItem (SVGNumber newItem) throws DOMException JavaDoc {
443     if (handler == null) {
444             throw new DOMException JavaDoc
445                 (DOMException.NO_MODIFICATION_ALLOWED_ERR, "");
446     } else {
447             if (iccColors == null) {
448                 int n = getNumberOfItems();
449                 iccColors = new ArrayList JavaDoc(n);
450                 for (int i = 0; i < n; i++) {
451                     iccColors.add(null);
452                 }
453             }
454             float f = newItem.getValue();
455             SVGNumber result = new ColorNumber(f);
456             iccColors.add(result);
457             handler.colorAppend(f);
458             return result;
459     }
460     }
461
462     /**
463      * To represent a SVGNumber which is part of a color list.
464      */

465     protected class ColorNumber implements SVGNumber {
466
467         /**
468          * The value of this number, when detached.
469          */

470         protected float value;
471
472         /**
473          * Creates a new ColorNumber.
474          */

475         public ColorNumber(float f) {
476             value = f;
477         }
478
479         /**
480          * Implements {@link SVGNumber#getValue()}.
481          */

482         public float getValue() {
483             if (iccColors == null) {
484                 return value;
485             }
486             int idx = iccColors.indexOf(this);
487             if (idx == -1) {
488                 return value;
489             }
490             Value value = valueProvider.getValue().item(1);
491             return ((ICCColor)value).getColor(idx);
492         }
493
494         /**
495          * Implements {@link SVGNumber#setValue(float)}.
496          */

497         public void setValue(float f) {
498             value = f;
499             if (iccColors == null) {
500                 return;
501             }
502             int idx = iccColors.indexOf(this);
503             if (idx == -1) {
504                 return;
505             }
506             if (handler == null) {
507                 throw new DOMException JavaDoc
508                     (DOMException.NO_MODIFICATION_ALLOWED_ERR, "");
509             } else {
510                 handler.colorReplaced(f, idx);
511             }
512         }
513     }
514
515     /**
516      * To provides the actual value.
517      */

518     public interface ValueProvider {
519
520         /**
521          * Returns the current value associated with this object.
522          */

523         Value getValue();
524     }
525
526     /**
527      * To manage the modifications on a CSS value.
528      */

529     public interface ModificationHandler {
530
531         /**
532          * Called when the value text has changed.
533          */

534         void textChanged(String JavaDoc text) throws DOMException JavaDoc;
535
536         /**
537          * Called when the red value text has changed.
538          */

539         void redTextChanged(String JavaDoc text) throws DOMException JavaDoc;
540
541         /**
542          * Called when the red float value has changed.
543          */

544         void redFloatValueChanged(short unit, float value)
545             throws DOMException JavaDoc;
546
547         /**
548          * Called when the green value text has changed.
549          */

550         void greenTextChanged(String JavaDoc text) throws DOMException JavaDoc;
551
552         /**
553          * Called when the green float value has changed.
554          */

555         void greenFloatValueChanged(short unit, float value)
556             throws DOMException JavaDoc;
557
558         /**
559          * Called when the blue value text has changed.
560          */

561         void blueTextChanged(String JavaDoc text) throws DOMException JavaDoc;
562
563         /**
564          * Called when the blue float value has changed.
565          */

566         void blueFloatValueChanged(short unit, float value)
567             throws DOMException JavaDoc;
568         
569         /**
570          * Called when the RGBColor text has changed.
571          */

572         void rgbColorChanged(String JavaDoc text) throws DOMException JavaDoc;
573
574         /**
575          * Called when the RGBColor and the ICCColor text has changed.
576          */

577         void rgbColorICCColorChanged(String JavaDoc rgb, String JavaDoc icc)
578             throws DOMException JavaDoc;
579
580         /**
581          * Called when the SVGColor has changed.
582          */

583         void colorChanged(short type, String JavaDoc rgb, String JavaDoc icc)
584             throws DOMException JavaDoc;
585
586         /**
587          * Called when the ICC color profile has changed.
588          */

589         void colorProfileChanged(String JavaDoc cp) throws DOMException JavaDoc;
590
591         /**
592          * Called when the ICC colors has changed.
593          */

594         void colorsCleared() throws DOMException JavaDoc;
595
596         /**
597          * Called when the ICC colors has been initialized.
598          */

599         void colorsInitialized(float f) throws DOMException JavaDoc;
600
601         /**
602          * Called when the ICC color has been inserted.
603          */

604         void colorInsertedBefore(float f, int idx) throws DOMException JavaDoc;
605
606         /**
607          * Called when the ICC color has been replaced.
608          */

609         void colorReplaced(float f, int idx) throws DOMException JavaDoc;
610
611         /**
612          * Called when the ICC color has been removed.
613          */

614         void colorRemoved(int idx) throws DOMException JavaDoc;
615
616         /**
617          * Called when the ICC color has been append.
618          */

619         void colorAppend(float f) throws DOMException JavaDoc;
620     }
621
622     /**
623      * Provides an abstract implementation of a ModificationHandler.
624      */

625     public abstract class AbstractModificationHandler
626         implements ModificationHandler {
627
628         /**
629          * Returns the associated value.
630          */

631         protected abstract Value getValue();
632
633         /**
634          * Called when the red value text has changed.
635          */

636         public void redTextChanged(String JavaDoc text) throws DOMException JavaDoc {
637             switch (getColorType()) {
638             case SVG_COLORTYPE_RGBCOLOR:
639                 text = "rgb(" +
640                     text + ", " +
641                     getValue().getGreen().getCssText() + ", " +
642                     getValue().getBlue().getCssText() + ")";
643                 break;
644
645             case SVG_COLORTYPE_RGBCOLOR_ICCCOLOR:
646                 text = "rgb(" +
647                     text + ", " +
648                     getValue().item(0).getGreen().getCssText() + ", " +
649                     getValue().item(0).getBlue().getCssText() + ") " +
650                     getValue().item(1).getCssText();
651                 break;
652
653             default:
654                 throw new DOMException JavaDoc
655                     (DOMException.NO_MODIFICATION_ALLOWED_ERR, "");
656             }
657             textChanged(text);
658         }
659
660         /**
661          * Called when the red float value has changed.
662          */

663         public void redFloatValueChanged(short unit, float value)
664             throws DOMException JavaDoc {
665             String JavaDoc text;
666             switch (getColorType()) {
667             case SVG_COLORTYPE_RGBCOLOR:
668                 text = "rgb(" +
669                     FloatValue.getCssText(unit, value) + ", " +
670                     getValue().getGreen().getCssText() + ", " +
671                     getValue().getBlue().getCssText() + ")";
672                 break;
673
674             case SVG_COLORTYPE_RGBCOLOR_ICCCOLOR:
675                 text = "rgb(" +
676                     FloatValue.getCssText(unit, value) + ", " +
677                     getValue().item(0).getGreen().getCssText() + ", " +
678                     getValue().item(0).getBlue().getCssText() + ") " +
679                     getValue().item(1).getCssText();
680                 break;
681
682             default:
683                 throw new DOMException JavaDoc
684                     (DOMException.NO_MODIFICATION_ALLOWED_ERR, "");
685             }
686             textChanged(text);
687         }
688
689         /**
690          * Called when the green value text has changed.
691          */

692         public void greenTextChanged(String JavaDoc text) throws DOMException JavaDoc {
693             switch (getColorType()) {
694             case SVG_COLORTYPE_RGBCOLOR:
695                 text = "rgb(" +
696                     getValue().getRed().getCssText() + ", " +
697                     text + ", " +
698                     getValue().getBlue().getCssText() + ")";
699                 break;
700
701             case SVG_COLORTYPE_RGBCOLOR_ICCCOLOR:
702                 text = "rgb(" +
703                     getValue().item(0).getRed().getCssText() + ", " +
704                     text + ", " +
705                     getValue().item(0).getBlue().getCssText() + ") " +
706                     getValue().item(1).getCssText();
707                 break;
708
709             default:
710                 throw new DOMException JavaDoc
711                     (DOMException.NO_MODIFICATION_ALLOWED_ERR, "");
712             }
713             textChanged(text);
714         }
715
716         /**
717          * Called when the green float value has changed.
718          */

719         public void greenFloatValueChanged(short unit, float value)
720             throws DOMException JavaDoc {
721             String JavaDoc text;
722             switch (getColorType()) {
723             case SVG_COLORTYPE_RGBCOLOR:
724                 text = "rgb(" +
725                     getValue().getRed().getCssText() + ", " +
726                     FloatValue.getCssText(unit, value) + ", " +
727                     getValue().getBlue().getCssText() + ")";
728                 break;
729
730             case SVG_COLORTYPE_RGBCOLOR_ICCCOLOR:
731                 text = "rgb(" +
732                     getValue().item(0).getRed().getCssText() + ", " +
733                     FloatValue.getCssText(unit, value) + ", " +
734                     getValue().item(0).getBlue().getCssText() + ") " +
735                     getValue().item(1).getCssText();
736                 break;
737
738             default:
739                 throw new DOMException JavaDoc
740                     (DOMException.NO_MODIFICATION_ALLOWED_ERR, "");
741             }
742             textChanged(text);
743         }
744
745         /**
746          * Called when the blue value text has changed.
747          */

748         public void blueTextChanged(String JavaDoc text) throws DOMException JavaDoc {
749             switch (getColorType()) {
750             case SVG_COLORTYPE_RGBCOLOR:
751                 text = "rgb(" +
752                     getValue().getRed().getCssText() + ", " +
753                     getValue().getGreen().getCssText() + ", " +
754                     text + ")";
755                 break;
756
757             case SVG_COLORTYPE_RGBCOLOR_ICCCOLOR:
758                 text = "rgb(" +
759                     getValue().item(0).getRed().getCssText() + ", " +
760                     getValue().item(0).getGreen().getCssText() + ", " +
761                     text + ") " +
762                     getValue().item(1).getCssText();
763
764             default:
765                 throw new DOMException JavaDoc
766                     (DOMException.NO_MODIFICATION_ALLOWED_ERR, "");
767             }
768             textChanged(text);
769         }
770
771         /**
772          * Called when the blue float value has changed.
773          */

774         public void blueFloatValueChanged(short unit, float value)
775             throws DOMException JavaDoc {
776             String JavaDoc text;
777             switch (getColorType()) {
778             case SVG_COLORTYPE_RGBCOLOR:
779                 text = "rgb(" +
780                     getValue().getRed().getCssText() + ", " +
781                     getValue().getGreen().getCssText() + ", " +
782                     FloatValue.getCssText(unit, value) + ")";
783                 break;
784
785             case SVG_COLORTYPE_RGBCOLOR_ICCCOLOR:
786                 text = "rgb(" +
787                     getValue().item(0).getRed().getCssText() + ", " +
788                     getValue().item(0).getGreen().getCssText() + ", " +
789                     FloatValue.getCssText(unit, value) + ") " +
790                     getValue().item(1).getCssText();
791                 break;
792
793             default:
794                 throw new DOMException JavaDoc
795                     (DOMException.NO_MODIFICATION_ALLOWED_ERR, "");
796             }
797             textChanged(text);
798         }
799         
800         /**
801          * Called when the RGBColor text has changed.
802          */

803         public void rgbColorChanged(String JavaDoc text) throws DOMException JavaDoc {
804             switch (getColorType()) {
805             case SVG_COLORTYPE_RGBCOLOR:
806                 break;
807
808             case SVG_COLORTYPE_RGBCOLOR_ICCCOLOR:
809                 text += getValue().item(1).getCssText();
810                 break;
811
812             default:
813                 throw new DOMException JavaDoc
814                     (DOMException.NO_MODIFICATION_ALLOWED_ERR, "");
815             }
816             textChanged(text);
817         }
818
819         /**
820          * Called when the RGBColor and the ICCColor text has changed.
821          */

822         public void rgbColorICCColorChanged(String JavaDoc rgb, String JavaDoc icc)
823             throws DOMException JavaDoc {
824             switch (getColorType()) {
825             case SVG_COLORTYPE_RGBCOLOR_ICCCOLOR:
826                 textChanged(rgb + " " + icc);
827                 break;
828
829             default:
830                 throw new DOMException JavaDoc
831                     (DOMException.NO_MODIFICATION_ALLOWED_ERR, "");
832             }
833         }
834
835         /**
836          * Called when the SVGColor has changed.
837          */

838         public void colorChanged(short type, String JavaDoc rgb, String JavaDoc icc)
839             throws DOMException JavaDoc {
840             switch (type) {
841             case SVG_COLORTYPE_CURRENTCOLOR:
842                 textChanged(CSSConstants.CSS_CURRENTCOLOR_VALUE);
843                 break;
844
845             case SVG_COLORTYPE_RGBCOLOR:
846                 textChanged(rgb);
847                 break;
848
849             case SVG_COLORTYPE_RGBCOLOR_ICCCOLOR:
850                 textChanged(rgb + " " + icc);
851                 break;
852
853             default:
854                 throw new DOMException JavaDoc(DOMException.NOT_SUPPORTED_ERR, "");
855             }
856         }
857
858         /**
859          * Called when the ICC color profile has changed.
860          */

861         public void colorProfileChanged(String JavaDoc cp) throws DOMException JavaDoc {
862             switch (getColorType()) {
863             case SVG_COLORTYPE_RGBCOLOR_ICCCOLOR:
864                 StringBuffer JavaDoc sb =
865                     new StringBuffer JavaDoc(getValue().item(0).getCssText());
866                 sb.append(" icc-color(");
867                 sb.append(cp);
868                 ICCColor iccc = (ICCColor)getValue().item(1);
869                 for (int i = 0; i < iccc.getLength(); i++) {
870                     sb.append(",");
871                     sb.append(iccc.getColor(i));
872                 }
873                 sb.append(")");
874                 textChanged(sb.toString());
875                 break;
876
877             default:
878                 throw new DOMException JavaDoc
879                     (DOMException.NO_MODIFICATION_ALLOWED_ERR, "");
880             }
881         }
882
883         /**
884          * Called when the ICC colors has changed.
885          */

886         public void colorsCleared() throws DOMException JavaDoc {
887             switch (getColorType()) {
888             case SVG_COLORTYPE_RGBCOLOR_ICCCOLOR:
889                 StringBuffer JavaDoc sb =
890                     new StringBuffer JavaDoc(getValue().item(0).getCssText());
891                 sb.append(" icc-color(");
892                 ICCColor iccc = (ICCColor)getValue().item(1);
893                 sb.append(iccc.getColorProfile());
894                 sb.append(")");
895                 textChanged(sb.toString());
896                 break;
897
898             default:
899                 throw new DOMException JavaDoc
900                     (DOMException.NO_MODIFICATION_ALLOWED_ERR, "");
901             }
902         }
903
904         /**
905          * Called when the ICC colors has been initialized.
906          */

907         public void colorsInitialized(float f) throws DOMException JavaDoc {
908             switch (getColorType()) {
909             case SVG_COLORTYPE_RGBCOLOR_ICCCOLOR:
910                 StringBuffer JavaDoc sb =
911                     new StringBuffer JavaDoc(getValue().item(0).getCssText());
912                 sb.append(" icc-color(");
913                 ICCColor iccc = (ICCColor)getValue().item(1);
914                 sb.append(iccc.getColorProfile());
915                 sb.append(",");
916                 sb.append(f);
917                 sb.append(")");
918                 textChanged(sb.toString());
919                 break;
920
921             default:
922                 throw new DOMException JavaDoc
923                     (DOMException.NO_MODIFICATION_ALLOWED_ERR, "");
924             }
925         }
926
927         /**
928          * Called when the ICC color has been inserted.
929          */

930         public void colorInsertedBefore(float f, int idx) throws DOMException JavaDoc {
931             switch (getColorType()) {
932             case SVG_COLORTYPE_RGBCOLOR_ICCCOLOR:
933                 StringBuffer JavaDoc sb =
934                     new StringBuffer JavaDoc(getValue().item(0).getCssText());
935                 sb.append(" icc-color(");
936                 ICCColor iccc = (ICCColor)getValue().item(1);
937                 sb.append(iccc.getColorProfile());
938                 for (int i = 0; i < idx; i++) {
939                     sb.append(",");
940                     sb.append(iccc.getColor(i));
941                 }
942                 sb.append(",");
943                 sb.append(f);
944                 for (int i = idx; i < iccc.getLength(); i++) {
945                     sb.append(",");
946                     sb.append(iccc.getColor(i));
947                 }
948                 sb.append(")");
949                 textChanged(sb.toString());
950                 break;
951
952             default:
953                 throw new DOMException JavaDoc
954                     (DOMException.NO_MODIFICATION_ALLOWED_ERR, "");
955             }
956         }
957
958         /**
959          * Called when the ICC color has been replaced.
960          */

961         public void colorReplaced(float f, int idx) throws DOMException JavaDoc {
962             switch (getColorType()) {
963             case SVG_COLORTYPE_RGBCOLOR_ICCCOLOR:
964                 StringBuffer JavaDoc sb =
965                     new StringBuffer JavaDoc(getValue().item(0).getCssText());
966                 sb.append(" icc-color(");
967                 ICCColor iccc = (ICCColor)getValue().item(1);
968                 sb.append(iccc.getColorProfile());
969                 for (int i = 0; i < idx; i++) {
970                     sb.append(",");
971                     sb.append(iccc.getColor(i));
972                 }
973                 sb.append(",");
974                 sb.append(f);
975                 for (int i = idx + 1; i < iccc.getLength(); i++) {
976                     sb.append(",");
977                     sb.append(iccc.getColor(i));
978                 }
979                 sb.append(")");
980                 textChanged(sb.toString());
981                 break;
982
983             default:
984                 throw new DOMException JavaDoc
985                     (DOMException.NO_MODIFICATION_ALLOWED_ERR, "");
986             }
987         }
988
989         /**
990          * Called when the ICC color has been removed.
991          */

992         public void colorRemoved(int idx) throws DOMException JavaDoc {
993             switch (getColorType()) {
994             case SVG_COLORTYPE_RGBCOLOR_ICCCOLOR:
995                 StringBuffer JavaDoc sb =
996                     new StringBuffer JavaDoc(getValue().item(0).getCssText());
997                 sb.append(" icc-color(");
998                 ICCColor iccc = (ICCColor)getValue().item(1);
999                 sb.append(iccc.getColorProfile());
1000                for (int i = 0; i < idx; i++) {
1001                    sb.append(",");
1002                    sb.append(iccc.getColor(i));
1003                }
1004                for (int i = idx + 1; i < iccc.getLength(); i++) {
1005                    sb.append(",");
1006                    sb.append(iccc.getColor(i));
1007                }
1008                sb.append(")");
1009                textChanged(sb.toString());
1010                break;
1011
1012            default:
1013                throw new DOMException JavaDoc
1014                    (DOMException.NO_MODIFICATION_ALLOWED_ERR, "");
1015            }
1016        }
1017
1018        /**
1019         * Called when the ICC color has been append.
1020         */

1021        public void colorAppend(float f) throws DOMException JavaDoc {
1022            switch (getColorType()) {
1023            case SVG_COLORTYPE_RGBCOLOR_ICCCOLOR:
1024                StringBuffer JavaDoc sb =
1025                    new StringBuffer JavaDoc(getValue().item(0).getCssText());
1026                sb.append(" icc-color(");
1027                ICCColor iccc = (ICCColor)getValue().item(1);
1028                sb.append(iccc.getColorProfile());
1029                for (int i = 0; i < iccc.getLength(); i++) {
1030                    sb.append(",");
1031                    sb.append(iccc.getColor(i));
1032                }
1033                sb.append(",");
1034                sb.append(f);
1035                sb.append(")");
1036                textChanged(sb.toString());
1037                break;
1038
1039            default:
1040                throw new DOMException JavaDoc
1041                    (DOMException.NO_MODIFICATION_ALLOWED_ERR, "");
1042            }
1043        }
1044    }
1045
1046    /**
1047     * To store a component.
1048     */

1049    protected abstract class AbstractComponent implements CSSPrimitiveValue {
1050
1051        /**
1052         * The returns the actual value of this component.
1053         */

1054        protected abstract Value getValue();
1055
1056        /**
1057         * <b>DOM</b>: Implements {@link
1058         * org.w3c.dom.css.CSSValue#getCssText()}.
1059         */

1060        public String JavaDoc getCssText() {
1061            return getValue().getCssText();
1062        }
1063
1064        /**
1065         * <b>DOM</b>: Implements {@link
1066         * org.w3c.dom.css.CSSValue#getCssValueType()}.
1067         */

1068        public short getCssValueType() {
1069            return getValue().getCssValueType();
1070        }
1071
1072        /**
1073         * <b>DOM</b>: Implements {@link
1074         * org.w3c.dom.css.CSSPrimitiveValue#getPrimitiveType()}.
1075         */

1076        public short getPrimitiveType() {
1077            return getValue().getPrimitiveType();
1078        }
1079
1080        /**
1081         * <b>DOM</b>: Implements {@link
1082         * org.w3c.dom.css.CSSPrimitiveValue#getFloatValue(short)}.
1083         */

1084        public float getFloatValue(short unitType) throws DOMException JavaDoc {
1085            return CSSOMValue.convertFloatValue(unitType, getValue());
1086        }
1087
1088        /**
1089         * <b>DOM</b>: Implements {@link
1090         * org.w3c.dom.css.CSSPrimitiveValue#getStringValue()}.
1091         */

1092        public String JavaDoc getStringValue() throws DOMException JavaDoc {
1093            return valueProvider.getValue().getStringValue();
1094        }
1095        
1096        /**
1097         * <b>DOM</b>: Implements {@link
1098         * org.w3c.dom.css.CSSPrimitiveValue#getCounterValue()}.
1099         */

1100        public Counter getCounterValue() throws DOMException JavaDoc {
1101            throw new DOMException JavaDoc(DOMException.INVALID_ACCESS_ERR, "");
1102        }
1103        
1104        /**
1105         * <b>DOM</b>: Implements {@link
1106         * org.w3c.dom.css.CSSPrimitiveValue#getRectValue()}.
1107         */

1108        public Rect getRectValue() throws DOMException JavaDoc {
1109            throw new DOMException JavaDoc(DOMException.INVALID_ACCESS_ERR, "");
1110        }
1111
1112        /**
1113         * <b>DOM</b>: Implements {@link
1114         * org.w3c.dom.css.CSSPrimitiveValue#getRGBColorValue()}.
1115         */

1116        public RGBColor getRGBColorValue() throws DOMException JavaDoc {
1117            throw new DOMException JavaDoc(DOMException.INVALID_ACCESS_ERR, "");
1118        }
1119
1120        // CSSValueList ///////////////////////////////////////////////////////
1121

1122        /**
1123         * <b>DOM</b>: Implements {@link
1124         * org.w3c.dom.css.CSSValueList#getLength()}.
1125         */

1126        public int getLength() {
1127            throw new DOMException JavaDoc(DOMException.INVALID_ACCESS_ERR, "");
1128        }
1129        
1130        /**
1131         * <b>DOM</b>: Implements {@link
1132         * org.w3c.dom.css.CSSValueList#item(int)}.
1133         */

1134        public CSSValue item(int index) {
1135            throw new DOMException JavaDoc(DOMException.INVALID_ACCESS_ERR, "");
1136        }
1137    }
1138
1139    /**
1140     * To store a Float component.
1141     */

1142    protected abstract class FloatComponent extends AbstractComponent {
1143
1144        /**
1145         * <b>DOM</b>: Implements {@link
1146         * org.w3c.dom.css.CSSPrimitiveValue#setStringValue(short,String)}.
1147         */

1148        public void setStringValue(short stringType, String JavaDoc stringValue)
1149            throws DOMException JavaDoc {
1150            throw new DOMException JavaDoc(DOMException.INVALID_ACCESS_ERR, "");
1151        }
1152    }
1153
1154    /**
1155     * To represents a red component.
1156     */

1157    protected class RedComponent extends FloatComponent {
1158        
1159        /**
1160         * The returns the actual value of this component.
1161         */

1162        protected Value getValue() {
1163            return valueProvider.getValue().getRed();
1164        }
1165
1166        /**
1167         * <b>DOM</b>: Implements {@link
1168         * org.w3c.dom.css.CSSValue#setCssText(String)}.
1169         */

1170        public void setCssText(String JavaDoc cssText) throws DOMException JavaDoc {
1171            if (handler == null) {
1172                throw new DOMException JavaDoc
1173                    (DOMException.NO_MODIFICATION_ALLOWED_ERR, "");
1174            } else {
1175                getValue();
1176                handler.redTextChanged(cssText);
1177            }
1178        }
1179
1180        /**
1181         * <b>DOM</b>: Implements {@link
1182         * org.w3c.dom.css.CSSPrimitiveValue#setFloatValue(short,float)}.
1183         */

1184        public void setFloatValue(short unitType, float floatValue)
1185            throws DOMException JavaDoc {
1186            if (handler == null) {
1187                throw new DOMException JavaDoc
1188                    (DOMException.NO_MODIFICATION_ALLOWED_ERR, "");
1189            } else {
1190                getValue();
1191                handler.redFloatValueChanged(unitType, floatValue);
1192            }
1193        }
1194
1195    }
1196
1197
1198    /**
1199     * To represents a green component.
1200     */

1201    protected class GreenComponent extends FloatComponent {
1202        
1203        /**
1204         * The returns the actual value of this component.
1205         */

1206        protected Value getValue() {
1207            return valueProvider.getValue().getGreen();
1208        }
1209
1210        /**
1211         * <b>DOM</b>: Implements {@link
1212         * org.w3c.dom.css.CSSValue#setCssText(String)}.
1213         */

1214        public void setCssText(String JavaDoc cssText) throws DOMException JavaDoc {
1215            if (handler == null) {
1216                throw new DOMException JavaDoc
1217                    (DOMException.NO_MODIFICATION_ALLOWED_ERR, "");
1218            } else {
1219                getValue();
1220                handler.greenTextChanged(cssText);
1221            }
1222        }
1223
1224        /**
1225         * <b>DOM</b>: Implements {@link
1226         * org.w3c.dom.css.CSSPrimitiveValue#setFloatValue(short,float)}.
1227         */

1228        public void setFloatValue(short unitType, float floatValue)
1229            throws DOMException JavaDoc {
1230            if (handler == null) {
1231                throw new DOMException JavaDoc
1232                    (DOMException.NO_MODIFICATION_ALLOWED_ERR, "");
1233            } else {
1234                getValue();
1235                handler.greenFloatValueChanged(unitType, floatValue);
1236            }
1237        }
1238
1239    }
1240
1241    /**
1242     * To represents a blue component.
1243     */

1244    protected class BlueComponent extends FloatComponent {
1245        
1246        /**
1247         * The returns the actual value of this component.
1248         */

1249        protected Value getValue() {
1250            return valueProvider.getValue().getBlue();
1251        }
1252
1253        /**
1254         * <b>DOM</b>: Implements {@link
1255         * org.w3c.dom.css.CSSValue#setCssText(String)}.
1256         */

1257        public void setCssText(String JavaDoc cssText) throws DOMException JavaDoc {
1258            if (handler == null) {
1259                throw new DOMException JavaDoc
1260                    (DOMException.NO_MODIFICATION_ALLOWED_ERR, "");
1261            } else {
1262                getValue();
1263                handler.blueTextChanged(cssText);
1264            }
1265        }
1266
1267        /**
1268         * <b>DOM</b>: Implements {@link
1269         * org.w3c.dom.css.CSSPrimitiveValue#setFloatValue(short,float)}.
1270         */

1271        public void setFloatValue(short unitType, float floatValue)
1272            throws DOMException JavaDoc {
1273            if (handler == null) {
1274                throw new DOMException JavaDoc
1275                    (DOMException.NO_MODIFICATION_ALLOWED_ERR, "");
1276            } else {
1277                getValue();
1278                handler.blueFloatValueChanged(unitType, floatValue);
1279            }
1280        }
1281
1282    }
1283
1284}
1285
Popular Tags