1 18 package org.apache.batik.css.dom; 19 20 import java.util.ArrayList ; 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 ; 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 44 public class CSSOMSVGColor 45 implements SVGColor, 46 RGBColor, 47 SVGICCColor, 48 SVGNumberList { 49 50 53 protected ValueProvider valueProvider; 54 55 58 protected ModificationHandler handler; 59 60 63 protected RedComponent redComponent; 64 65 68 protected GreenComponent greenComponent; 69 70 73 protected BlueComponent blueComponent; 74 75 78 protected ArrayList iccColors; 79 80 83 public CSSOMSVGColor(ValueProvider vp) { 84 valueProvider = vp; 85 } 86 87 90 public void setModificationHandler(ModificationHandler h) { 91 handler = h; 92 } 93 94 97 public String getCssText() { 98 return valueProvider.getValue().getCssText(); 99 } 100 101 105 public void setCssText(String cssText) throws DOMException { 106 if (handler == null) { 107 throw new DOMException 108 (DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); 109 } else { 110 iccColors = null; 111 handler.textChanged(cssText); 112 } 113 } 114 115 119 public short getCssValueType() { 120 return CSS_CUSTOM; 121 } 122 123 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 (); 147 } 148 149 153 public RGBColor getRGBColor() { 154 return this; 155 } 156 157 161 public RGBColor getRgbColor() { 162 return this; 163 } 164 165 169 public void setRGBColor(String color) { 170 if (handler == null) { 171 throw new DOMException 172 (DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); 173 } else { 174 handler.rgbColorChanged(color); 175 } 176 } 177 178 182 public SVGICCColor getICCColor() { 183 return this; 184 } 185 186 190 public SVGICCColor getIccColor() { 191 return this; 192 } 193 194 198 public void setRGBColorICCColor(String rgb, String icc) { 199 if (handler == null) { 200 throw new DOMException 201 (DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); 202 } else { 203 iccColors = null; 204 handler.rgbColorICCColorChanged(rgb, icc); 205 } 206 } 207 208 212 public void setColor(short type, String rgb, String icc) { 213 if (handler == null) { 214 throw new DOMException 215 (DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); 216 } else { 217 iccColors = null; 218 handler.colorChanged(type, rgb, icc); 219 } 220 } 221 222 224 227 public CSSPrimitiveValue getRed() { 228 valueProvider.getValue().getRed(); 229 if (redComponent == null) { 230 redComponent = new RedComponent(); 231 } 232 return redComponent; 233 } 234 235 238 public CSSPrimitiveValue getGreen() { 239 valueProvider.getValue().getGreen(); 240 if (greenComponent == null) { 241 greenComponent = new GreenComponent(); 242 } 243 return greenComponent; 244 } 245 246 247 250 public CSSPrimitiveValue getBlue() { 251 valueProvider.getValue().getBlue(); 252 if (blueComponent == null) { 253 blueComponent = new BlueComponent(); 254 } 255 return blueComponent; 256 } 257 258 260 263 public String getColorProfile() { 264 if (getColorType() != SVG_COLORTYPE_RGBCOLOR_ICCCOLOR) { 265 throw new DOMException (DOMException.SYNTAX_ERR, ""); 266 } 267 Value value = valueProvider.getValue(); 268 return ((ICCColor)value.item(1)).getColorProfile(); 269 } 270 271 274 public void setColorProfile(String colorProfile) throws DOMException { 275 if (handler == null) { 276 throw new DOMException 277 (DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); 278 } else { 279 handler.colorProfileChanged(colorProfile); 280 } 281 } 282 283 286 public SVGNumberList getColors() { 287 return this; 288 } 289 290 292 295 public int getNumberOfItems() { 296 if (getColorType() != SVG_COLORTYPE_RGBCOLOR_ICCCOLOR) { 297 throw new DOMException (DOMException.SYNTAX_ERR, ""); 298 } 299 Value value = valueProvider.getValue(); 300 return ((ICCColor)value.item(1)).getNumberOfColors(); 301 } 302 303 306 public void clear() throws DOMException { 307 if (handler == null) { 308 throw new DOMException 309 (DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); 310 } else { 311 iccColors = null; 312 handler.colorsCleared(); 313 } 314 } 315 316 319 public SVGNumber initialize(SVGNumber newItem) throws DOMException { 320 if (handler == null) { 321 throw new DOMException 322 (DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); 323 } else { 324 float f = newItem.getValue(); 325 iccColors = new ArrayList (); 326 SVGNumber result = new ColorNumber(f); 327 iccColors.add(result); 328 handler.colorsInitialized(f); 329 return result; 330 } 331 } 332 333 336 public SVGNumber getItem(int index) throws DOMException { 337 if (getColorType() != SVG_COLORTYPE_RGBCOLOR_ICCCOLOR) { 338 throw new DOMException (DOMException.INDEX_SIZE_ERR, ""); 339 } 340 int n = getNumberOfItems(); 341 if (index < 0 || index >= n) { 342 throw new DOMException (DOMException.INDEX_SIZE_ERR, ""); 343 } 344 if (iccColors == null) { 345 iccColors = new ArrayList (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 361 public SVGNumber insertItemBefore(SVGNumber newItem, int index) 362 throws DOMException { 363 if (handler == null) { 364 throw new DOMException 365 (DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); 366 } else { 367 int n = getNumberOfItems(); 368 if (index < 0 || index > n) { 369 throw new DOMException (DOMException.INDEX_SIZE_ERR, ""); 370 } 371 if (iccColors == null) { 372 iccColors = new ArrayList (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 389 public SVGNumber replaceItem(SVGNumber newItem, int index) 390 throws DOMException { 391 if (handler == null) { 392 throw new DOMException 393 (DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); 394 } else { 395 int n = getNumberOfItems(); 396 if (index < 0 || index >= n) { 397 throw new DOMException (DOMException.INDEX_SIZE_ERR, ""); 398 } 399 if (iccColors == null) { 400 iccColors = new ArrayList (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 416 public SVGNumber removeItem(int index) throws DOMException { 417 if (handler == null) { 418 throw new DOMException 419 (DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); 420 } else { 421 int n = getNumberOfItems(); 422 if (index < 0 || index >= n) { 423 throw new DOMException (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 442 public SVGNumber appendItem (SVGNumber newItem) throws DOMException { 443 if (handler == null) { 444 throw new DOMException 445 (DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); 446 } else { 447 if (iccColors == null) { 448 int n = getNumberOfItems(); 449 iccColors = new ArrayList (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 465 protected class ColorNumber implements SVGNumber { 466 467 470 protected float value; 471 472 475 public ColorNumber(float f) { 476 value = f; 477 } 478 479 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 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 508 (DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); 509 } else { 510 handler.colorReplaced(f, idx); 511 } 512 } 513 } 514 515 518 public interface ValueProvider { 519 520 523 Value getValue(); 524 } 525 526 529 public interface ModificationHandler { 530 531 534 void textChanged(String text) throws DOMException ; 535 536 539 void redTextChanged(String text) throws DOMException ; 540 541 544 void redFloatValueChanged(short unit, float value) 545 throws DOMException ; 546 547 550 void greenTextChanged(String text) throws DOMException ; 551 552 555 void greenFloatValueChanged(short unit, float value) 556 throws DOMException ; 557 558 561 void blueTextChanged(String text) throws DOMException ; 562 563 566 void blueFloatValueChanged(short unit, float value) 567 throws DOMException ; 568 569 572 void rgbColorChanged(String text) throws DOMException ; 573 574 577 void rgbColorICCColorChanged(String rgb, String icc) 578 throws DOMException ; 579 580 583 void colorChanged(short type, String rgb, String icc) 584 throws DOMException ; 585 586 589 void colorProfileChanged(String cp) throws DOMException ; 590 591 594 void colorsCleared() throws DOMException ; 595 596 599 void colorsInitialized(float f) throws DOMException ; 600 601 604 void colorInsertedBefore(float f, int idx) throws DOMException ; 605 606 609 void colorReplaced(float f, int idx) throws DOMException ; 610 611 614 void colorRemoved(int idx) throws DOMException ; 615 616 619 void colorAppend(float f) throws DOMException ; 620 } 621 622 625 public abstract class AbstractModificationHandler 626 implements ModificationHandler { 627 628 631 protected abstract Value getValue(); 632 633 636 public void redTextChanged(String text) throws DOMException { 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 655 (DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); 656 } 657 textChanged(text); 658 } 659 660 663 public void redFloatValueChanged(short unit, float value) 664 throws DOMException { 665 String 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 684 (DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); 685 } 686 textChanged(text); 687 } 688 689 692 public void greenTextChanged(String text) throws DOMException { 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 711 (DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); 712 } 713 textChanged(text); 714 } 715 716 719 public void greenFloatValueChanged(short unit, float value) 720 throws DOMException { 721 String 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 740 (DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); 741 } 742 textChanged(text); 743 } 744 745 748 public void blueTextChanged(String text) throws DOMException { 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 766 (DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); 767 } 768 textChanged(text); 769 } 770 771 774 public void blueFloatValueChanged(short unit, float value) 775 throws DOMException { 776 String 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 795 (DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); 796 } 797 textChanged(text); 798 } 799 800 803 public void rgbColorChanged(String text) throws DOMException { 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 814 (DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); 815 } 816 textChanged(text); 817 } 818 819 822 public void rgbColorICCColorChanged(String rgb, String icc) 823 throws DOMException { 824 switch (getColorType()) { 825 case SVG_COLORTYPE_RGBCOLOR_ICCCOLOR: 826 textChanged(rgb + " " + icc); 827 break; 828 829 default: 830 throw new DOMException 831 (DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); 832 } 833 } 834 835 838 public void colorChanged(short type, String rgb, String icc) 839 throws DOMException { 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 (DOMException.NOT_SUPPORTED_ERR, ""); 855 } 856 } 857 858 861 public void colorProfileChanged(String cp) throws DOMException { 862 switch (getColorType()) { 863 case SVG_COLORTYPE_RGBCOLOR_ICCCOLOR: 864 StringBuffer sb = 865 new StringBuffer (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 879 (DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); 880 } 881 } 882 883 886 public void colorsCleared() throws DOMException { 887 switch (getColorType()) { 888 case SVG_COLORTYPE_RGBCOLOR_ICCCOLOR: 889 StringBuffer sb = 890 new StringBuffer (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 900 (DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); 901 } 902 } 903 904 907 public void colorsInitialized(float f) throws DOMException { 908 switch (getColorType()) { 909 case SVG_COLORTYPE_RGBCOLOR_ICCCOLOR: 910 StringBuffer sb = 911 new StringBuffer (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 923 (DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); 924 } 925 } 926 927 930 public void colorInsertedBefore(float f, int idx) throws DOMException { 931 switch (getColorType()) { 932 case SVG_COLORTYPE_RGBCOLOR_ICCCOLOR: 933 StringBuffer sb = 934 new StringBuffer (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 954 (DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); 955 } 956 } 957 958 961 public void colorReplaced(float f, int idx) throws DOMException { 962 switch (getColorType()) { 963 case SVG_COLORTYPE_RGBCOLOR_ICCCOLOR: 964 StringBuffer sb = 965 new StringBuffer (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 985 (DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); 986 } 987 } 988 989 992 public void colorRemoved(int idx) throws DOMException { 993 switch (getColorType()) { 994 case SVG_COLORTYPE_RGBCOLOR_ICCCOLOR: 995 StringBuffer sb = 996 new StringBuffer (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 1014 (DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); 1015 } 1016 } 1017 1018 1021 public void colorAppend(float f) throws DOMException { 1022 switch (getColorType()) { 1023 case SVG_COLORTYPE_RGBCOLOR_ICCCOLOR: 1024 StringBuffer sb = 1025 new StringBuffer (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 1041 (DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); 1042 } 1043 } 1044 } 1045 1046 1049 protected abstract class AbstractComponent implements CSSPrimitiveValue { 1050 1051 1054 protected abstract Value getValue(); 1055 1056 1060 public String getCssText() { 1061 return getValue().getCssText(); 1062 } 1063 1064 1068 public short getCssValueType() { 1069 return getValue().getCssValueType(); 1070 } 1071 1072 1076 public short getPrimitiveType() { 1077 return getValue().getPrimitiveType(); 1078 } 1079 1080 1084 public float getFloatValue(short unitType) throws DOMException { 1085 return CSSOMValue.convertFloatValue(unitType, getValue()); 1086 } 1087 1088 1092 public String getStringValue() throws DOMException { 1093 return valueProvider.getValue().getStringValue(); 1094 } 1095 1096 1100 public Counter getCounterValue() throws DOMException { 1101 throw new DOMException (DOMException.INVALID_ACCESS_ERR, ""); 1102 } 1103 1104 1108 public Rect getRectValue() throws DOMException { 1109 throw new DOMException (DOMException.INVALID_ACCESS_ERR, ""); 1110 } 1111 1112 1116 public RGBColor getRGBColorValue() throws DOMException { 1117 throw new DOMException (DOMException.INVALID_ACCESS_ERR, ""); 1118 } 1119 1120 1122 1126 public int getLength() { 1127 throw new DOMException (DOMException.INVALID_ACCESS_ERR, ""); 1128 } 1129 1130 1134 public CSSValue item(int index) { 1135 throw new DOMException (DOMException.INVALID_ACCESS_ERR, ""); 1136 } 1137 } 1138 1139 1142 protected abstract class FloatComponent extends AbstractComponent { 1143 1144 1148 public void setStringValue(short stringType, String stringValue) 1149 throws DOMException { 1150 throw new DOMException (DOMException.INVALID_ACCESS_ERR, ""); 1151 } 1152 } 1153 1154 1157 protected class RedComponent extends FloatComponent { 1158 1159 1162 protected Value getValue() { 1163 return valueProvider.getValue().getRed(); 1164 } 1165 1166 1170 public void setCssText(String cssText) throws DOMException { 1171 if (handler == null) { 1172 throw new DOMException 1173 (DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); 1174 } else { 1175 getValue(); 1176 handler.redTextChanged(cssText); 1177 } 1178 } 1179 1180 1184 public void setFloatValue(short unitType, float floatValue) 1185 throws DOMException { 1186 if (handler == null) { 1187 throw new DOMException 1188 (DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); 1189 } else { 1190 getValue(); 1191 handler.redFloatValueChanged(unitType, floatValue); 1192 } 1193 } 1194 1195 } 1196 1197 1198 1201 protected class GreenComponent extends FloatComponent { 1202 1203 1206 protected Value getValue() { 1207 return valueProvider.getValue().getGreen(); 1208 } 1209 1210 1214 public void setCssText(String cssText) throws DOMException { 1215 if (handler == null) { 1216 throw new DOMException 1217 (DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); 1218 } else { 1219 getValue(); 1220 handler.greenTextChanged(cssText); 1221 } 1222 } 1223 1224 1228 public void setFloatValue(short unitType, float floatValue) 1229 throws DOMException { 1230 if (handler == null) { 1231 throw new DOMException 1232 (DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); 1233 } else { 1234 getValue(); 1235 handler.greenFloatValueChanged(unitType, floatValue); 1236 } 1237 } 1238 1239 } 1240 1241 1244 protected class BlueComponent extends FloatComponent { 1245 1246 1249 protected Value getValue() { 1250 return valueProvider.getValue().getBlue(); 1251 } 1252 1253 1257 public void setCssText(String cssText) throws DOMException { 1258 if (handler == null) { 1259 throw new DOMException 1260 (DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); 1261 } else { 1262 getValue(); 1263 handler.blueTextChanged(cssText); 1264 } 1265 } 1266 1267 1271 public void setFloatValue(short unitType, float floatValue) 1272 throws DOMException { 1273 if (handler == null) { 1274 throw new DOMException 1275 (DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); 1276 } else { 1277 getValue(); 1278 handler.blueFloatValueChanged(unitType, floatValue); 1279 } 1280 } 1281 1282 } 1283 1284} 1285 | Popular Tags |