< prev index next >

src/java.desktop/share/classes/javax/swing/plaf/synth/SynthParser.java

Print this page
8201328: SynthParser should use Boolean.parseBoolean
Reviewed-by: serb


 729                     iType = 5;
 730                 }
 731                 else {
 732                     throw new SAXException(property + " unknown type, use" +
 733                         "idref, boolean, dimension, insets or integer");
 734                 }
 735             }
 736             else if (aName.equals(ATTRIBUTE_VALUE)) {
 737                 aValue = attributes.getValue(i);
 738             }
 739             else if (aName.equals(ATTRIBUTE_KEY)) {
 740                 key = attributes.getValue(i);
 741             }
 742         }
 743         if (aValue != null) {
 744             switch (iType) {
 745             case 0: // idref
 746                 value = lookup(aValue, Object.class);
 747                 break;
 748             case 1: // boolean
 749                 if (aValue.toUpperCase().equals("TRUE")) {
 750                     value = Boolean.TRUE;
 751                 }
 752                 else {
 753                     value = Boolean.FALSE;
 754                 }
 755                 break;
 756             case 2: // dimension
 757                 StringTokenizer tok = new StringTokenizer(aValue);
 758                 value = new DimensionUIResource(
 759                     nextInt(tok, "Invalid dimension"),
 760                     nextInt(tok, "Invalid dimension"));
 761                 break;
 762             case 3: // insets
 763                 value = parseInsets(aValue, property + " invalid insets");
 764                 break;
 765             case 4: // integer
 766                 try {
 767                     value = Integer.valueOf(aValue);
 768                 } catch (NumberFormatException nfe) {
 769                     throw new SAXException(property + " invalid value");
 770                 }
 771                 break;
 772             case 5: //string
 773                 value = aValue;
 774                 break;


 922                 id = value;
 923             }
 924             else if (key.equals(ATTRIBUTE_METHOD)) {
 925                 method = value.toLowerCase(Locale.ENGLISH);
 926             }
 927             else if (key.equals(ATTRIBUTE_IDREF)) {
 928                 painter = (SynthPainter)lookup(value, SynthPainter.class);
 929             }
 930             else if (key.equals(ATTRIBUTE_PATH)) {
 931                 path = value;
 932             }
 933             else if (key.equals(ATTRIBUTE_SOURCE_INSETS)) {
 934                 sourceInsets = parseInsets(value, type +
 935                    ": sourceInsets must be top left bottom right");
 936             }
 937             else if (key.equals(ATTRIBUTE_DEST_INSETS)) {
 938                 destInsets = parseInsets(value, type +
 939                   ": destinationInsets must be top left bottom right");
 940             }
 941             else if (key.equals(ATTRIBUTE_PAINT_CENTER)) {
 942                 paintCenter = value.toLowerCase().equals("true");
 943                 paintCenterSpecified = true;
 944             }
 945             else if (key.equals(ATTRIBUTE_STRETCH)) {
 946                 stretch = value.toLowerCase().equals("true");
 947                 stretchSpecified = true;
 948             }
 949             else if (key.equals(ATTRIBUTE_DIRECTION)) {
 950                 value = value.toUpperCase().intern();
 951                 if (value == "EAST") {
 952                     direction = SwingConstants.EAST;
 953                 }
 954                 else if (value == "NORTH") {
 955                     direction = SwingConstants.NORTH;
 956                 }
 957                 else if (value == "SOUTH") {
 958                     direction = SwingConstants.SOUTH;
 959                 }
 960                 else if (value == "WEST") {
 961                     direction = SwingConstants.WEST;
 962                 }
 963                 else if (value == "TOP") {
 964                     direction = SwingConstants.TOP;
 965                 }
 966                 else if (value == "LEFT") {


 972                 else if (value == "RIGHT") {
 973                     direction = SwingConstants.RIGHT;
 974                 }
 975                 else if (value == "HORIZONTAL") {
 976                     direction = SwingConstants.HORIZONTAL;
 977                 }
 978                 else if (value == "VERTICAL") {
 979                     direction = SwingConstants.VERTICAL;
 980                 }
 981                 else if (value == "HORIZONTAL_SPLIT") {
 982                     direction = JSplitPane.HORIZONTAL_SPLIT;
 983                 }
 984                 else if (value == "VERTICAL_SPLIT") {
 985                     direction = JSplitPane.VERTICAL_SPLIT;
 986                 }
 987                 else {
 988                     throw new SAXException(type + ": unknown direction");
 989                 }
 990             }
 991             else if (key.equals(ATTRIBUTE_CENTER)) {
 992                 center = value.toLowerCase().equals("true");
 993             }
 994         }
 995         if (painter == null) {
 996             if (type == ELEMENT_PAINTER) {
 997                 throw new SAXException(type +
 998                              ": you must specify an idref");
 999             }
1000             if (sourceInsets == null && !center) {
1001                 throw new SAXException(
1002                              "property: you must specify sourceInsets");
1003             }
1004             if (path == null) {
1005                 throw new SAXException("property: you must specify a path");
1006             }
1007             if (center && (sourceInsets != null || destInsets != null ||
1008                            paintCenterSpecified || stretchSpecified)) {
1009                 throw new SAXException("The attributes: sourceInsets, " +
1010                                        "destinationInsets, paintCenter and stretch " +
1011                                        " are not legal when center is true");
1012             }




 729                     iType = 5;
 730                 }
 731                 else {
 732                     throw new SAXException(property + " unknown type, use" +
 733                         "idref, boolean, dimension, insets or integer");
 734                 }
 735             }
 736             else if (aName.equals(ATTRIBUTE_VALUE)) {
 737                 aValue = attributes.getValue(i);
 738             }
 739             else if (aName.equals(ATTRIBUTE_KEY)) {
 740                 key = attributes.getValue(i);
 741             }
 742         }
 743         if (aValue != null) {
 744             switch (iType) {
 745             case 0: // idref
 746                 value = lookup(aValue, Object.class);
 747                 break;
 748             case 1: // boolean
 749                 value = Boolean.parseBoolean(aValue);





 750                 break;
 751             case 2: // dimension
 752                 StringTokenizer tok = new StringTokenizer(aValue);
 753                 value = new DimensionUIResource(
 754                     nextInt(tok, "Invalid dimension"),
 755                     nextInt(tok, "Invalid dimension"));
 756                 break;
 757             case 3: // insets
 758                 value = parseInsets(aValue, property + " invalid insets");
 759                 break;
 760             case 4: // integer
 761                 try {
 762                     value = Integer.valueOf(aValue);
 763                 } catch (NumberFormatException nfe) {
 764                     throw new SAXException(property + " invalid value");
 765                 }
 766                 break;
 767             case 5: //string
 768                 value = aValue;
 769                 break;


 917                 id = value;
 918             }
 919             else if (key.equals(ATTRIBUTE_METHOD)) {
 920                 method = value.toLowerCase(Locale.ENGLISH);
 921             }
 922             else if (key.equals(ATTRIBUTE_IDREF)) {
 923                 painter = (SynthPainter)lookup(value, SynthPainter.class);
 924             }
 925             else if (key.equals(ATTRIBUTE_PATH)) {
 926                 path = value;
 927             }
 928             else if (key.equals(ATTRIBUTE_SOURCE_INSETS)) {
 929                 sourceInsets = parseInsets(value, type +
 930                    ": sourceInsets must be top left bottom right");
 931             }
 932             else if (key.equals(ATTRIBUTE_DEST_INSETS)) {
 933                 destInsets = parseInsets(value, type +
 934                   ": destinationInsets must be top left bottom right");
 935             }
 936             else if (key.equals(ATTRIBUTE_PAINT_CENTER)) {
 937                 paintCenter = Boolean.parseBoolean(value);
 938                 paintCenterSpecified = true;
 939             }
 940             else if (key.equals(ATTRIBUTE_STRETCH)) {
 941                 stretch = Boolean.parseBoolean(value);
 942                 stretchSpecified = true;
 943             }
 944             else if (key.equals(ATTRIBUTE_DIRECTION)) {
 945                 value = value.toUpperCase().intern();
 946                 if (value == "EAST") {
 947                     direction = SwingConstants.EAST;
 948                 }
 949                 else if (value == "NORTH") {
 950                     direction = SwingConstants.NORTH;
 951                 }
 952                 else if (value == "SOUTH") {
 953                     direction = SwingConstants.SOUTH;
 954                 }
 955                 else if (value == "WEST") {
 956                     direction = SwingConstants.WEST;
 957                 }
 958                 else if (value == "TOP") {
 959                     direction = SwingConstants.TOP;
 960                 }
 961                 else if (value == "LEFT") {


 967                 else if (value == "RIGHT") {
 968                     direction = SwingConstants.RIGHT;
 969                 }
 970                 else if (value == "HORIZONTAL") {
 971                     direction = SwingConstants.HORIZONTAL;
 972                 }
 973                 else if (value == "VERTICAL") {
 974                     direction = SwingConstants.VERTICAL;
 975                 }
 976                 else if (value == "HORIZONTAL_SPLIT") {
 977                     direction = JSplitPane.HORIZONTAL_SPLIT;
 978                 }
 979                 else if (value == "VERTICAL_SPLIT") {
 980                     direction = JSplitPane.VERTICAL_SPLIT;
 981                 }
 982                 else {
 983                     throw new SAXException(type + ": unknown direction");
 984                 }
 985             }
 986             else if (key.equals(ATTRIBUTE_CENTER)) {
 987                 center = Boolean.parseBoolean(value);
 988             }
 989         }
 990         if (painter == null) {
 991             if (type == ELEMENT_PAINTER) {
 992                 throw new SAXException(type +
 993                              ": you must specify an idref");
 994             }
 995             if (sourceInsets == null && !center) {
 996                 throw new SAXException(
 997                              "property: you must specify sourceInsets");
 998             }
 999             if (path == null) {
1000                 throw new SAXException("property: you must specify a path");
1001             }
1002             if (center && (sourceInsets != null || destInsets != null ||
1003                            paintCenterSpecified || stretchSpecified)) {
1004                 throw new SAXException("The attributes: sourceInsets, " +
1005                                        "destinationInsets, paintCenter and stretch " +
1006                                        " are not legal when center is true");
1007             }


< prev index next >