1 51 package org.apache.fop.fo; 52 53 import java.util.ArrayList ; 54 55 public class MarginShorthandParser implements ShorthandParser { 56 57 protected ArrayList list; 59 public MarginShorthandParser(ListProperty listprop) { 60 this.list = listprop.getList(); 61 } 62 63 protected Property getElement(int index) { 64 if (list.size() > index) 65 return (Property)list.get(index); 66 else 67 return null; 68 } 69 70 protected int count() { 71 return list.size(); 72 } 73 74 public Property getValueForProperty(String propName, 76 Property.Maker maker, 77 PropertyList propertyList) { 78 Property prop = null; 79 if (count() == 1) { 81 String sval = ((Property)list.get(0)).getString(); 82 if (sval != null && sval.equals("inherit")) { 83 return propertyList.getFromParent(propName); 84 } 85 } 86 return convertValueForProperty(propName, maker, propertyList); 87 } 88 89 90 protected Property convertValueForProperty(String propName, 91 Property.Maker maker, 92 PropertyList propertyList) { 93 Property prop = null; 94 int idx = 0; 95 96 switch (count()) 97 { 98 case 1: idx = 0; 100 break; 101 case 2: if (propName.equals("margin-top") || 103 propName.equals("margin-bottom")) 104 idx = 0; 105 else 106 idx = 1; 107 break; 108 case 3: if (propName == "margin-top") 110 idx = 0; 111 else if (propName.equals("margin-bottom")) 112 idx = 2; 113 else 114 idx = 1; 115 break; 116 case 4: if (propName.equals("margin-top")) 118 idx = 0; 119 else if (propName.equals("margin-right")) 120 idx = 1; 121 else if (propName.equals("margin-bottom")) 122 idx = 2; 123 else if (propName.equals("margin-left")) 124 idx = 3; 125 break; 126 default: 127 return null; 129 } 130 131 Property p = getElement(idx); 132 prop = maker.convertShorthandProperty(propertyList, p, null); 133 return prop; 134 } 135 136 } 137 138 | Popular Tags |