KickJava   Java API By Example, From Geeks To Geeks.

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


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.Value;
22 import org.apache.batik.css.engine.value.svg.ICCColor;
23 import org.apache.batik.util.CSSConstants;
24
25 import org.w3c.dom.DOMException JavaDoc;
26 import org.w3c.dom.css.CSSPrimitiveValue;
27 import org.w3c.dom.css.CSSValue;
28 import org.w3c.dom.svg.SVGPaint;
29
30 /**
31  * This class implements the {@link SVGPaint} interface.
32  *
33  * @author <a HREF="mailto:stephane@hillion.org">Stephane Hillion</a>
34  * @version $Id: CSSOMSVGPaint.java,v 1.6 2005/03/15 11:24:35 deweese Exp $
35  */

36 public class CSSOMSVGPaint extends CSSOMSVGColor implements SVGPaint {
37     
38     /**
39      * Creates a new CSSOMSVGPaint.
40      */

41     public CSSOMSVGPaint(ValueProvider vp) {
42         super(vp);
43     }
44
45     /**
46      * Sets the modification handler of this value.
47      */

48     public void setModificationHandler(ModificationHandler h) {
49         if (!(h instanceof PaintModificationHandler)) {
50             throw new IllegalArgumentException JavaDoc();
51         }
52         super.setModificationHandler(h);
53     }
54
55     /**
56      * <b>DOM</b>: Implements {@link
57      * org.w3c.dom.svg.SVGColor#getColorType()}.
58      */

59     public short getColorType() {
60         throw new DOMException JavaDoc(DOMException.INVALID_ACCESS_ERR, "");
61     }
62
63     /**
64      * <b>DOM</b>: Implements {@link
65      * org.w3c.dom.svg.SVGPaint#getPaintType()}.
66      */

67     public short getPaintType() {
68         Value value = valueProvider.getValue();
69         switch (value.getCssValueType()) {
70         case CSSValue.CSS_PRIMITIVE_VALUE:
71             switch (value.getPrimitiveType()) {
72             case CSSPrimitiveValue.CSS_IDENT: {
73                 String JavaDoc str = value.getStringValue();
74                 if (str.equalsIgnoreCase(CSSConstants.CSS_NONE_VALUE)) {
75                     return SVG_PAINTTYPE_NONE;
76                 } else if (str.equalsIgnoreCase
77                            (CSSConstants.CSS_CURRENTCOLOR_VALUE)) {
78                     return SVG_PAINTTYPE_CURRENTCOLOR;
79                 }
80                 return SVG_PAINTTYPE_RGBCOLOR;
81             }
82             case CSSPrimitiveValue.CSS_RGBCOLOR:
83                 return SVG_PAINTTYPE_RGBCOLOR;
84
85             case CSSPrimitiveValue.CSS_URI:
86                 return SVG_PAINTTYPE_URI;
87             }
88             break;
89
90         case CSSValue.CSS_VALUE_LIST:
91             Value v0 = value.item(0);
92             Value v1 = value.item(1);
93             switch (v0.getPrimitiveType()) {
94             case CSSPrimitiveValue.CSS_IDENT:
95                 return SVG_PAINTTYPE_RGBCOLOR_ICCCOLOR;
96             case CSSPrimitiveValue.CSS_URI:
97                 if (v1.getCssValueType() == CSSValue.CSS_VALUE_LIST)
98                     // Should probably check this more deeply...
99
return SVG_PAINTTYPE_URI_RGBCOLOR_ICCCOLOR;
100
101                 switch (v1.getPrimitiveType()) {
102                 case CSSPrimitiveValue.CSS_IDENT: {
103                     String JavaDoc str = v1.getStringValue();
104                     if (str.equalsIgnoreCase(CSSConstants.CSS_NONE_VALUE)) {
105                         return SVG_PAINTTYPE_URI_NONE;
106                     } else if (str.equalsIgnoreCase
107                                (CSSConstants.CSS_CURRENTCOLOR_VALUE)) {
108                         return SVG_PAINTTYPE_URI_CURRENTCOLOR;
109                     }
110                     return SVG_PAINTTYPE_URI_RGBCOLOR;
111                 }
112                 case CSSPrimitiveValue.CSS_RGBCOLOR:
113                     return SVG_PAINTTYPE_URI_RGBCOLOR;
114                 }
115
116             case CSSPrimitiveValue.CSS_RGBCOLOR:
117                 return SVG_PAINTTYPE_RGBCOLOR_ICCCOLOR;
118             }
119         }
120         return SVG_PAINTTYPE_UNKNOWN;
121     }
122
123     /**
124      * <b>DOM</b>: Implements {@link org.w3c.dom.svg.SVGPaint#getUri()}.
125      */

126     public String JavaDoc getUri() {
127         switch (getPaintType()) {
128         case SVG_PAINTTYPE_URI:
129             return valueProvider.getValue().getStringValue();
130
131         case SVG_PAINTTYPE_URI_NONE:
132         case SVG_PAINTTYPE_URI_CURRENTCOLOR:
133         case SVG_PAINTTYPE_URI_RGBCOLOR:
134         case SVG_PAINTTYPE_URI_RGBCOLOR_ICCCOLOR:
135             return valueProvider.getValue().item(0).getStringValue();
136         }
137         throw new InternalError JavaDoc();
138     }
139
140     /**
141      * <b>DOM</b>: Implements {@link org.w3c.dom.svg.SVGPaint#setUri(String)}.
142      */

143     public void setUri(String JavaDoc uri) {
144     if (handler == null) {
145             throw new DOMException JavaDoc
146                 (DOMException.NO_MODIFICATION_ALLOWED_ERR, "");
147     } else {
148             ((PaintModificationHandler)handler).uriChanged(uri);
149     }
150     }
151
152     /**
153      * <b>DOM</b>: Implements {@link
154      * org.w3c.dom.svg.SVGPaint#setPaint(short,String,String,String)}.
155      */

156     public void setPaint(short paintType, String JavaDoc uri,
157                          String JavaDoc rgbColor, String JavaDoc iccColor) {
158     if (handler == null) {
159             throw new DOMException JavaDoc
160                 (DOMException.NO_MODIFICATION_ALLOWED_ERR, "");
161     } else {
162             ((PaintModificationHandler)handler).paintChanged
163                 (paintType, uri, rgbColor, iccColor);
164     }
165     }
166
167     /**
168      * To manage the modifications on a SVGPaint value.
169      */

170     public interface PaintModificationHandler extends ModificationHandler {
171         
172         /**
173          * Called when the URI has been modified.
174          */

175         void uriChanged(String JavaDoc uri);
176
177         /**
178          * Called when the paint value has beem modified.
179          */

180         void paintChanged(short type, String JavaDoc uri, String JavaDoc rgb, String JavaDoc icc);
181     }
182
183     /**
184      * Provides an abstract implementation of a PaintModificationHandler.
185      */

186     public abstract class AbstractModificationHandler
187         implements PaintModificationHandler {
188
189         /**
190          * Returns the associated value.
191          */

192         protected abstract Value getValue();
193
194         /**
195          * Called when the red value text has changed.
196          */

197         public void redTextChanged(String JavaDoc text) throws DOMException JavaDoc {
198             switch (getPaintType()) {
199             case SVG_PAINTTYPE_RGBCOLOR:
200                 text = "rgb(" +
201                     text + ", " +
202                     getValue().getGreen().getCssText() + ", " +
203                     getValue().getBlue().getCssText() + ")";
204                 break;
205
206             case SVG_PAINTTYPE_RGBCOLOR_ICCCOLOR:
207                 text = "rgb(" +
208                     text + ", " +
209                     getValue().item(0).getGreen().getCssText() + ", " +
210                     getValue().item(0).getBlue().getCssText() + ") " +
211                     getValue().item(1).getCssText();
212                 break;
213
214             case SVG_PAINTTYPE_URI_RGBCOLOR:
215                 text = getValue().item(0) +
216                     " rgb(" +
217                     text + ", " +
218                     getValue().item(1).getGreen().getCssText() + ", " +
219                     getValue().item(1).getBlue().getCssText() + ")";
220                 break;
221
222             case SVG_PAINTTYPE_URI_RGBCOLOR_ICCCOLOR:
223                 text = getValue().item(0) +
224                     " rgb(" +
225                     text + ", " +
226                     getValue().item(1).getGreen().getCssText() + ", " +
227                     getValue().item(1).getBlue().getCssText() + ") " +
228                     getValue().item(2).getCssText();
229                 break;
230
231             default:
232                 throw new DOMException JavaDoc
233                     (DOMException.NO_MODIFICATION_ALLOWED_ERR, "");
234             }
235             textChanged(text);
236         }
237
238         /**
239          * Called when the red float value has changed.
240          */

241         public void redFloatValueChanged(short unit, float value)
242             throws DOMException JavaDoc {
243             String JavaDoc text;
244             switch (getPaintType()) {
245             case SVG_PAINTTYPE_RGBCOLOR:
246                 text = "rgb(" +
247                     FloatValue.getCssText(unit, value) + ", " +
248                     getValue().getGreen().getCssText() + ", " +
249                     getValue().getBlue().getCssText() + ")";
250                 break;
251
252             case SVG_PAINTTYPE_RGBCOLOR_ICCCOLOR:
253                 text = "rgb(" +
254                     FloatValue.getCssText(unit, value) + ", " +
255                     getValue().item(0).getGreen().getCssText() + ", " +
256                     getValue().item(0).getBlue().getCssText() + ") " +
257                     getValue().item(1).getCssText();
258                 break;
259
260             case SVG_PAINTTYPE_URI_RGBCOLOR:
261                 text = getValue().item(0) +
262                     " rgb(" +
263                     FloatValue.getCssText(unit, value) + ", " +
264                     getValue().item(1).getGreen().getCssText() + ", " +
265                     getValue().item(1).getBlue().getCssText() + ")";
266                 break;
267
268             case SVG_PAINTTYPE_URI_RGBCOLOR_ICCCOLOR:
269                 text = getValue().item(0) +
270                     " rgb(" +
271                     FloatValue.getCssText(unit, value) + ", " +
272                     getValue().item(1).getGreen().getCssText() + ", " +
273                     getValue().item(1).getBlue().getCssText() + ") " +
274                     getValue().item(2).getCssText();
275                 break;
276
277             default:
278                 throw new DOMException JavaDoc
279                     (DOMException.NO_MODIFICATION_ALLOWED_ERR, "");
280             }
281             textChanged(text);
282         }
283
284         /**
285          * Called when the green value text has changed.
286          */

287         public void greenTextChanged(String JavaDoc text) throws DOMException JavaDoc {
288             switch (getPaintType()) {
289             case SVG_PAINTTYPE_RGBCOLOR:
290                 text = "rgb(" +
291                     getValue().getRed().getCssText() + ", " +
292                     text + ", " +
293                     getValue().getBlue().getCssText() + ")";
294                 break;
295
296             case SVG_PAINTTYPE_RGBCOLOR_ICCCOLOR:
297                 text = "rgb(" +
298                     getValue().item(0).getRed().getCssText() + ", " +
299                     text + ", " +
300                     getValue().item(0).getBlue().getCssText() + ") " +
301                     getValue().item(1).getCssText();
302                 break;
303
304             case SVG_PAINTTYPE_URI_RGBCOLOR:
305                 text = getValue().item(0) +
306                     " rgb(" +
307                     getValue().item(1).getRed().getCssText() + ", " +
308                     text + ", " +
309                     getValue().item(1).getBlue().getCssText() + ")";
310                 break;
311
312             case SVG_PAINTTYPE_URI_RGBCOLOR_ICCCOLOR:
313                 text = getValue().item(0) +
314                     " rgb(" +
315                     getValue().item(1).getRed().getCssText() + ", " +
316                     text + ", " +
317                     getValue().item(1).getBlue().getCssText() + ") " +
318                     getValue().item(2).getCssText();
319                 break;
320
321             default:
322                 throw new DOMException JavaDoc
323                     (DOMException.NO_MODIFICATION_ALLOWED_ERR, "");
324             }
325             textChanged(text);
326         }
327
328         /**
329          * Called when the green float value has changed.
330          */

331         public void greenFloatValueChanged(short unit, float value)
332             throws DOMException JavaDoc {
333             String JavaDoc text;
334             switch (getPaintType()) {
335             case SVG_PAINTTYPE_RGBCOLOR:
336                 text = "rgb(" +
337                     getValue().getRed().getCssText() + ", " +
338                     FloatValue.getCssText(unit, value) + ", " +
339                     getValue().getBlue().getCssText() + ")";
340                 break;
341
342             case SVG_PAINTTYPE_RGBCOLOR_ICCCOLOR:
343                 text = "rgb(" +
344                     getValue().item(0).getRed().getCssText() + ", " +
345                     FloatValue.getCssText(unit, value) + ", " +
346                     getValue().item(0).getBlue().getCssText() + ") " +
347                     getValue().item(1).getCssText();
348                 break;
349
350             case SVG_PAINTTYPE_URI_RGBCOLOR:
351                 text = getValue().item(0) +
352                     " rgb(" +
353                     getValue().item(1).getRed().getCssText() + ", " +
354                     FloatValue.getCssText(unit, value) + ", " +
355                     getValue().item(1).getBlue().getCssText() + ")";
356                 break;
357
358             case SVG_PAINTTYPE_URI_RGBCOLOR_ICCCOLOR:
359                 text = getValue().item(0) +
360                     " rgb(" +
361                     getValue().item(1).getRed().getCssText() + ", " +
362                     FloatValue.getCssText(unit, value) + ", " +
363                     getValue().item(1).getBlue().getCssText() + ") " +
364                     getValue().item(2).getCssText();
365                 break;
366
367             default:
368                 throw new DOMException JavaDoc
369                     (DOMException.NO_MODIFICATION_ALLOWED_ERR, "");
370             }
371             textChanged(text);
372         }
373
374         /**
375          * Called when the blue value text has changed.
376          */

377         public void blueTextChanged(String JavaDoc text) throws DOMException JavaDoc {
378             switch (getPaintType()) {
379             case SVG_PAINTTYPE_RGBCOLOR:
380                 text = "rgb(" +
381                     getValue().getRed().getCssText() + ", " +
382                     getValue().getGreen().getCssText() + ", " +
383                     text + ")";
384                 break;
385
386             case SVG_PAINTTYPE_RGBCOLOR_ICCCOLOR:
387                 text = "rgb(" +
388                     getValue().item(0).getRed().getCssText() + ", " +
389                     getValue().item(0).getGreen().getCssText() + ", " +
390                     text + ") " +
391                     getValue().item(1).getCssText();
392                 break;
393
394             case SVG_PAINTTYPE_URI_RGBCOLOR:
395                 text = getValue().item(0) +
396                     " rgb(" +
397                     getValue().item(1).getRed().getCssText() + ", " +
398                     getValue().item(1).getGreen().getCssText() + ", " +
399                     text + ")";
400                 break;
401
402             case SVG_PAINTTYPE_URI_RGBCOLOR_ICCCOLOR:
403                 text = getValue().item(0) +
404                     " rgb(" +
405                     getValue().item(1).getRed().getCssText() + ", " +
406                     getValue().item(1).getGreen().getCssText() + ", " +
407                     text + ") " +
408                     getValue().item(2).getCssText();
409                 break;
410
411             default:
412                 throw new DOMException JavaDoc
413                     (DOMException.NO_MODIFICATION_ALLOWED_ERR, "");
414             }
415             textChanged(text);
416         }
417
418         /**
419          * Called when the blue float value has changed.
420          */

421         public void blueFloatValueChanged(short unit, float value)
422             throws DOMException JavaDoc {
423             String JavaDoc text;
424             switch (getPaintType()) {
425             case SVG_PAINTTYPE_RGBCOLOR:
426                 text = "rgb(" +
427                     getValue().getRed().getCssText() + ", " +
428                     getValue().getGreen().getCssText() + ", " +
429                     FloatValue.getCssText(unit, value) + ")";
430                 break;
431
432             case SVG_PAINTTYPE_RGBCOLOR_ICCCOLOR:
433                 text = "rgb(" +
434                     getValue().item(0).getRed().getCssText() + ", " +
435                     getValue().item(0).getGreen().getCssText() + ", " +
436                     FloatValue.getCssText(unit, value) + ") " +
437                     getValue().item(1).getCssText();
438                 break;
439
440             case SVG_PAINTTYPE_URI_RGBCOLOR:
441                 text = getValue().item(0) +
442                     " rgb(" +
443                     getValue().item(1).getRed().getCssText() + ", " +
444                     getValue().item(1).getGreen().getCssText() + ", " +
445                     FloatValue.getCssText(unit, value) + ")";
446                 break;
447
448             case SVG_PAINTTYPE_URI_RGBCOLOR_ICCCOLOR:
449                 text = getValue().item(0) +
450                     " rgb(" +
451                     getValue().item(1).getRed().getCssText() + ", " +
452                     getValue().item(1).getGreen().getCssText() + ", " +
453                     FloatValue.getCssText(unit, value) + ") " +
454                     getValue().item(2).getCssText();
455                 break;
456
457             default:
458                 throw new DOMException JavaDoc
459                     (DOMException.NO_MODIFICATION_ALLOWED_ERR, "");
460             }
461             textChanged(text);
462         }
463         
464         /**
465          * Called when the RGBColor text has changed.
466          */

467         public void rgbColorChanged(String JavaDoc text) throws DOMException JavaDoc {
468             switch (getPaintType()) {
469             case SVG_PAINTTYPE_RGBCOLOR:
470                 break;
471
472             case SVG_PAINTTYPE_RGBCOLOR_ICCCOLOR:
473                 text += getValue().item(1).getCssText();
474                 break;
475
476             case SVG_PAINTTYPE_URI_RGBCOLOR:
477                 text = getValue().item(0).getCssText() + " " + text;
478                 break;
479
480             case SVG_PAINTTYPE_URI_RGBCOLOR_ICCCOLOR:
481                 text = getValue().item(0).getCssText() + " " + text + " " +
482                     getValue().item(2).getCssText();
483                 break;
484
485             default:
486                 throw new DOMException JavaDoc
487                     (DOMException.NO_MODIFICATION_ALLOWED_ERR, "");
488             }
489             textChanged(text);
490         }
491
492         /**
493          * Called when the RGBColor and the ICCColor text has changed.
494          */

495         public void rgbColorICCColorChanged(String JavaDoc rgb, String JavaDoc icc)
496             throws DOMException JavaDoc {
497             switch (getPaintType()) {
498             case SVG_PAINTTYPE_RGBCOLOR_ICCCOLOR:
499                 textChanged(rgb + " " + icc);
500                 break;
501
502             case SVG_PAINTTYPE_URI_RGBCOLOR_ICCCOLOR:
503                 textChanged(getValue().item(0).getCssText() + " " +
504                             rgb + " " + icc);
505                 break;
506
507             default:
508                 throw new DOMException JavaDoc
509                     (DOMException.NO_MODIFICATION_ALLOWED_ERR, "");
510             }
511         }
512
513         /**
514          * Called when the SVGColor has changed.
515          */

516         public void colorChanged(short type, String JavaDoc rgb, String JavaDoc icc)
517             throws DOMException JavaDoc {
518             switch (type) {
519             case SVG_PAINTTYPE_CURRENTCOLOR:
520                 textChanged("currentcolor");
521                 break;
522
523             case SVG_PAINTTYPE_RGBCOLOR:
524                 textChanged(rgb);
525                 break;
526
527             case SVG_PAINTTYPE_RGBCOLOR_ICCCOLOR:
528                 textChanged(rgb + " " + icc);
529                 break;
530
531             default:
532                 throw new DOMException JavaDoc(DOMException.NOT_SUPPORTED_ERR, "");
533             }
534         }
535
536         /**
537          * Called when the ICC color profile has changed.
538          */

539         public void colorProfileChanged(String JavaDoc cp) throws DOMException JavaDoc {
540             switch (getPaintType()) {
541             case SVG_PAINTTYPE_RGBCOLOR_ICCCOLOR:
542                 StringBuffer JavaDoc sb =
543                     new StringBuffer JavaDoc(getValue().item(0).getCssText());
544                 sb.append(" icc-color(");
545                 sb.append(cp);
546                 ICCColor iccc = (ICCColor)getValue().item(1);
547                 for (int i = 0; i < iccc.getLength(); i++) {
548                     sb.append(",");
549                     sb.append(iccc.getColor(i));
550                 }
551                 sb.append(")");
552                 textChanged(sb.toString());
553                 break;
554
555             case SVG_PAINTTYPE_URI_RGBCOLOR_ICCCOLOR:
556                 sb = new StringBuffer JavaDoc(getValue().item(0).getCssText());
557                 sb.append(" ");
558                 sb.append(getValue().item(1).getCssText());
559                 sb.append(" icc-color(");
560                 sb.append(cp);
561                 iccc = (ICCColor)getValue().item(1);
562                 for (int i = 0; i < iccc.getLength(); i++) {
563                     sb.append(",");
564                     sb.append(iccc.getColor(i));
565                 }
566                 sb.append(")");
567                 textChanged(sb.toString());
568                 break;
569
570             default:
571                 throw new DOMException JavaDoc
572                     (DOMException.NO_MODIFICATION_ALLOWED_ERR, "");
573             }
574         }
575
576         /**
577          * Called when the ICC colors has changed.
578          */

579         public void colorsCleared() throws DOMException JavaDoc {
580             switch (getPaintType()) {
581             case SVG_PAINTTYPE_RGBCOLOR_ICCCOLOR:
582                 StringBuffer JavaDoc sb =
583                     new StringBuffer JavaDoc(getValue().item(0).getCssText());
584                 sb.append(" icc-color(");
585                 ICCColor iccc = (ICCColor)getValue().item(1);
586                 sb.append(iccc.getColorProfile());
587                 sb.append(")");
588                 textChanged(sb.toString());
589                 break;
590
591             case SVG_PAINTTYPE_URI_RGBCOLOR_ICCCOLOR:
592                 sb = new StringBuffer JavaDoc(getValue().item(0).getCssText());
593                 sb.append(" ");
594                 sb.append(getValue().item(1).getCssText());
595                 sb.append(" icc-color(");
596                 iccc = (ICCColor)getValue().item(1);
597                 sb.append(iccc.getColorProfile());
598                 sb.append(")");
599                 textChanged(sb.toString());
600                 break;
601
602             default:
603                 throw new DOMException JavaDoc
604                     (DOMException.NO_MODIFICATION_ALLOWED_ERR, "");
605             }
606         }
607
608         /**
609          * Called when the ICC colors has been initialized.
610          */

611         public void colorsInitialized(float f) throws DOMException JavaDoc {
612             switch (getPaintType()) {
613             case SVG_PAINTTYPE_RGBCOLOR_ICCCOLOR:
614                 StringBuffer JavaDoc sb =
615                     new StringBuffer JavaDoc(getValue().item(0).getCssText());
616                 sb.append(" icc-color(");
617                 ICCColor iccc = (ICCColor)getValue().item(1);
618                 sb.append(iccc.getColorProfile());
619                 sb.append(",");
620                 sb.append(f);
621                 sb.append(")");
622                 textChanged(sb.toString());
623                 break;
624
625             case SVG_PAINTTYPE_URI_RGBCOLOR_ICCCOLOR:
626                 sb = new StringBuffer JavaDoc(getValue().item(0).getCssText());
627                 sb.append(" ");
628                 sb.append(getValue().item(1).getCssText());
629                 sb.append(" icc-color(");
630                 iccc = (ICCColor)getValue().item(1);
631                 sb.append(iccc.getColorProfile());
632                 sb.append(",");
633                 sb.append(f);
634                 sb.append(")");
635                 textChanged(sb.toString());
636                 break;
637
638             default:
639                 throw new DOMException JavaDoc
640                     (DOMException.NO_MODIFICATION_ALLOWED_ERR, "");
641             }
642         }
643
644         /**
645          * Called when the ICC color has been inserted.
646          */

647         public void colorInsertedBefore(float f, int idx) throws DOMException JavaDoc {
648             switch (getPaintType()) {
649             case SVG_PAINTTYPE_RGBCOLOR_ICCCOLOR:
650                 StringBuffer JavaDoc sb =
651                     new StringBuffer JavaDoc(getValue().item(0).getCssText());
652                 sb.append(" icc-color(");
653                 ICCColor iccc = (ICCColor)getValue().item(1);
654                 sb.append(iccc.getColorProfile());
655                 for (int i = 0; i < idx; i++) {
656                     sb.append(",");
657                     sb.append(iccc.getColor(i));
658                 }
659                 sb.append(",");
660                 sb.append(f);
661                 for (int i = idx; i < iccc.getLength(); i++) {
662                     sb.append(",");
663                     sb.append(iccc.getColor(i));
664                 }
665                 sb.append(")");
666                 textChanged(sb.toString());
667                 break;
668
669             case SVG_PAINTTYPE_URI_RGBCOLOR_ICCCOLOR:
670                 sb = new StringBuffer JavaDoc(getValue().item(0).getCssText());
671                 sb.append(" ");
672                 sb.append(getValue().item(1).getCssText());
673                 sb.append(" icc-color(");
674                 iccc = (ICCColor)getValue().item(1);
675                 sb.append(iccc.getColorProfile());
676                 for (int i = 0; i < idx; i++) {
677                     sb.append(",");
678                     sb.append(iccc.getColor(i));
679                 }
680                 sb.append(",");
681                 sb.append(f);
682                 for (int i = idx; i < iccc.getLength(); i++) {
683                     sb.append(",");
684                     sb.append(iccc.getColor(i));
685                 }
686                 sb.append(")");
687                 textChanged(sb.toString());
688                 break;
689
690             default:
691                 throw new DOMException JavaDoc
692                     (DOMException.NO_MODIFICATION_ALLOWED_ERR, "");
693             }
694         }
695
696         /**
697          * Called when the ICC color has been replaced.
698          */

699         public void colorReplaced(float f, int idx) throws DOMException JavaDoc {
700             switch (getPaintType()) {
701             case SVG_PAINTTYPE_RGBCOLOR_ICCCOLOR:
702                 StringBuffer JavaDoc sb =
703                     new StringBuffer JavaDoc(getValue().item(0).getCssText());
704                 sb.append(" icc-color(");
705                 ICCColor iccc = (ICCColor)getValue().item(1);
706                 sb.append(iccc.getColorProfile());
707                 for (int i = 0; i < idx; i++) {
708                     sb.append(",");
709                     sb.append(iccc.getColor(i));
710                 }
711                 sb.append(",");
712                 sb.append(f);
713                 for (int i = idx + 1; i < iccc.getLength(); i++) {
714                     sb.append(",");
715                     sb.append(iccc.getColor(i));
716                 }
717                 sb.append(")");
718                 textChanged(sb.toString());
719                 break;
720
721             case SVG_PAINTTYPE_URI_RGBCOLOR_ICCCOLOR:
722                 sb = new StringBuffer JavaDoc(getValue().item(0).getCssText());
723                 sb.append(" ");
724                 sb.append(getValue().item(1).getCssText());
725                 sb.append(" icc-color(");
726                 iccc = (ICCColor)getValue().item(1);
727                 sb.append(iccc.getColorProfile());
728                 for (int i = 0; i < idx; i++) {
729                     sb.append(",");
730                     sb.append(iccc.getColor(i));
731                 }
732                 sb.append(",");
733                 sb.append(f);
734                 for (int i = idx + 1; i < iccc.getLength(); i++) {
735                     sb.append(",");
736                     sb.append(iccc.getColor(i));
737                 }
738                 sb.append(")");
739                 textChanged(sb.toString());
740                 break;
741
742             default:
743                 throw new DOMException JavaDoc
744                     (DOMException.NO_MODIFICATION_ALLOWED_ERR, "");
745             }
746         }
747
748         /**
749          * Called when the ICC color has been removed.
750          */

751         public void colorRemoved(int idx) throws DOMException JavaDoc {
752             switch (getPaintType()) {
753             case SVG_PAINTTYPE_RGBCOLOR_ICCCOLOR:
754                 StringBuffer JavaDoc sb =
755                     new StringBuffer JavaDoc(getValue().item(0).getCssText());
756                 sb.append(" icc-color(");
757                 ICCColor iccc = (ICCColor)getValue().item(1);
758                 sb.append(iccc.getColorProfile());
759                 for (int i = 0; i < idx; i++) {
760                     sb.append(",");
761                     sb.append(iccc.getColor(i));
762                 }
763                 for (int i = idx + 1; i < iccc.getLength(); i++) {
764                     sb.append(",");
765                     sb.append(iccc.getColor(i));
766                 }
767                 sb.append(")");
768                 textChanged(sb.toString());
769                 break;
770
771             case SVG_PAINTTYPE_URI_RGBCOLOR_ICCCOLOR:
772                 sb = new StringBuffer JavaDoc(getValue().item(0).getCssText());
773                 sb.append(" ");
774                 sb.append(getValue().item(1).getCssText());
775                 sb.append(" icc-color(");
776                 iccc = (ICCColor)getValue().item(1);
777                 sb.append(iccc.getColorProfile());
778                 for (int i = 0; i < idx; i++) {
779                     sb.append(",");
780                     sb.append(iccc.getColor(i));
781                 }
782                 for (int i = idx + 1; i < iccc.getLength(); i++) {
783                     sb.append(",");
784                     sb.append(iccc.getColor(i));
785                 }
786                 sb.append(")");
787                 textChanged(sb.toString());
788                 break;
789
790             default:
791                 throw new DOMException JavaDoc
792                     (DOMException.NO_MODIFICATION_ALLOWED_ERR, "");
793             }
794         }
795
796         /**
797          * Called when the ICC color has been append.
798          */

799         public void colorAppend(float f) throws DOMException JavaDoc {
800             switch (getPaintType()) {
801             case SVG_PAINTTYPE_RGBCOLOR_ICCCOLOR:
802                 StringBuffer JavaDoc sb =
803                     new StringBuffer JavaDoc(getValue().item(0).getCssText());
804                 sb.append(" icc-color(");
805                 ICCColor iccc = (ICCColor)getValue().item(1);
806                 sb.append(iccc.getColorProfile());
807                 for (int i = 0; i < iccc.getLength(); i++) {
808                     sb.append(",");
809                     sb.append(iccc.getColor(i));
810                 }
811                 sb.append(",");
812                 sb.append(f);
813                 sb.append(")");
814                 textChanged(sb.toString());
815                 break;
816
817             case SVG_PAINTTYPE_URI_RGBCOLOR_ICCCOLOR:
818                 sb = new StringBuffer JavaDoc(getValue().item(0).getCssText());
819                 sb.append(" ");
820                 sb.append(getValue().item(1).getCssText());
821                 sb.append(" icc-color(");
822                 iccc = (ICCColor)getValue().item(1);
823                 sb.append(iccc.getColorProfile());
824                 for (int i = 0; i < iccc.getLength(); i++) {
825                     sb.append(",");
826                     sb.append(iccc.getColor(i));
827                 }
828                 sb.append(",");
829                 sb.append(f);
830                 sb.append(")");
831                 textChanged(sb.toString());
832                 break;
833
834             default:
835                 throw new DOMException JavaDoc
836                     (DOMException.NO_MODIFICATION_ALLOWED_ERR, "");
837             }
838         }
839
840         /**
841          * Called when the URI has been modified.
842          */

843         public void uriChanged(String JavaDoc uri) {
844             textChanged("url(" + uri + ") none");
845         }
846
847         /**
848          * Called when the paint value has beem modified.
849          */

850         public void paintChanged(short type, String JavaDoc uri,
851                                  String JavaDoc rgb, String JavaDoc icc) {
852             switch (type) {
853             case SVG_PAINTTYPE_NONE:
854                 textChanged("none");
855                 break;
856
857             case SVG_PAINTTYPE_CURRENTCOLOR:
858                 textChanged("currentcolor");
859                 break;
860
861             case SVG_PAINTTYPE_RGBCOLOR:
862                 textChanged(rgb);
863                 break;
864
865             case SVG_PAINTTYPE_RGBCOLOR_ICCCOLOR:
866                 textChanged(rgb + " " + icc);
867                 break;
868
869             case SVG_PAINTTYPE_URI:
870                 textChanged("url(" + uri + ")");
871                 break;
872
873             case SVG_PAINTTYPE_URI_NONE:
874                 textChanged("url(" + uri + ") none");
875                 break;
876
877             case SVG_PAINTTYPE_URI_CURRENTCOLOR:
878                 textChanged("url(" + uri + ") currentcolor");
879                 break;
880
881             case SVG_PAINTTYPE_URI_RGBCOLOR:
882                 textChanged("url(" + uri + ") " + rgb);
883                 break;
884
885             case SVG_PAINTTYPE_URI_RGBCOLOR_ICCCOLOR:
886                 textChanged("url(" + uri + ") " + rgb + " " + icc);
887             }
888         }
889     }
890
891 }
892
Popular Tags