You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

BoxPropShorthandParser.java 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * Copyright 1999-2004 The Apache Software Foundation.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /* $Id$ */
  17. package org.apache.fop.fo;
  18. import org.apache.fop.fo.properties.ListProperty;
  19. import org.apache.fop.fo.properties.Property;
  20. import org.apache.fop.fo.properties.PropertyMaker;
  21. /**
  22. * Shorthand property parser for Box properties
  23. */
  24. public class BoxPropShorthandParser extends GenericShorthandParser {
  25. /**
  26. * @see org.apache.fop.fo.GenericShorthandParser#GenericShorthandParser()
  27. */
  28. public BoxPropShorthandParser() {
  29. }
  30. /**
  31. * Stores 1 to 4 values of same type.
  32. * Set the given property based on the number of values set.
  33. * Example: padding, border-width, border-color, border-style, margin
  34. * @see org.apache.fop.fo.GenericShorthandParser#convertValueForProperty(
  35. * int, ListProperty, PropertyMaker, PropertyList)
  36. */
  37. protected Property convertValueForProperty(int propId,
  38. ListProperty listProperty,
  39. PropertyMaker maker,
  40. PropertyList propertyList) {
  41. String name = FOPropertyMapping.getPropertyName(propId);
  42. Property p = null;
  43. int count = listProperty.getList().size();
  44. if (name.indexOf("-top") >= 0) {
  45. p = getElement(listProperty, 0);
  46. } else if (name.indexOf("-right") >= 0) {
  47. p = getElement(listProperty, count > 1 ? 1 : 0);
  48. } else if (name.indexOf("-bottom") >= 0) {
  49. p = getElement(listProperty, count > 2 ? 2 : 0);
  50. } else if (name.indexOf("-left") >= 0) {
  51. p = getElement(listProperty, count > 3 ? 3 : (count > 1 ? 1 : 0));
  52. }
  53. // if p not null, try to convert it to a value of the correct type
  54. if (p != null) {
  55. return maker.convertShorthandProperty(propertyList, p, null);
  56. }
  57. return p;
  58. }
  59. }