KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > fo > properties > BoxPropShorthandParser


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. 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 /* $Id: BoxPropShorthandParser.java 426576 2006-07-28 15:44:37Z jeremias $ */
19
20 package org.apache.fop.fo.properties;
21
22 import org.apache.fop.fo.FOPropertyMapping;
23 import org.apache.fop.fo.PropertyList;
24 import org.apache.fop.fo.expr.PropertyException;
25
26 /**
27  * Shorthand property parser for Box properties
28  */

29 public class BoxPropShorthandParser extends GenericShorthandParser {
30
31     /**
32      * Default constructor.
33      */

34     public BoxPropShorthandParser() {
35     }
36
37     /**
38      * Stores 1 to 4 values of same type.
39      * Set the given property based on the number of values set.
40      * Example: padding, border-width, border-color, border-style, margin
41      * @see org.apache.fop.fo.properties.GenericShorthandParser#convertValueForProperty(
42      * int, Property, PropertyMaker, PropertyList)
43      */

44     protected Property convertValueForProperty(int propId,
45                                                Property property,
46                                                PropertyMaker maker,
47                                                PropertyList propertyList)
48                 throws PropertyException {
49         String JavaDoc name = FOPropertyMapping.getPropertyName(propId);
50         Property p = null;
51         int count = property.getList().size();
52         if (name.indexOf("-top") >= 0) {
53             p = getElement(property, 0);
54         } else if (name.indexOf("-right") >= 0) {
55             p = getElement(property, count > 1 ? 1 : 0);
56         } else if (name.indexOf("-bottom") >= 0) {
57             p = getElement(property, count > 2 ? 2 : 0);
58         } else if (name.indexOf("-left") >= 0) {
59             p = getElement(property, count > 3 ? 3 : (count > 1 ? 1 : 0));
60         }
61         // if p not null, try to convert it to a value of the correct type
62
if (p != null) {
63             return maker.convertShorthandProperty(propertyList, p, null);
64         }
65         return p;
66     }
67
68 }
69
Popular Tags