1 17 18 19 20 package org.apache.fop.area; 21 22 import java.io.Serializable ; 23 import java.util.Map ; 24 25 import org.apache.commons.logging.Log; 26 import org.apache.commons.logging.LogFactory; 27 import org.apache.fop.traits.BorderProps; 28 29 37 40 public class Area extends AreaTreeObject implements Serializable { 41 45 public static final int LR = 0; 46 47 50 public static final int RL = 1; 51 52 55 public static final int TB = 2; 56 57 60 public static final int BT = 3; 61 62 66 public static final int ORIENT_0 = 0; 67 68 71 public static final int ORIENT_90 = 1; 72 73 76 public static final int ORIENT_180 = 2; 77 78 81 public static final int ORIENT_270 = 3; 82 83 85 88 public static final int CLASS_NORMAL = 0; 89 90 93 public static final int CLASS_FIXED = 1; 94 95 98 public static final int CLASS_ABSOLUTE = 2; 99 100 103 public static final int CLASS_BEFORE_FLOAT = 3; 104 105 108 public static final int CLASS_FOOTNOTE = 4; 109 110 113 public static final int CLASS_SIDE_FLOAT = 5; 114 115 119 public static final int CLASS_MAX = CLASS_SIDE_FLOAT + 1; 120 121 private int areaClass = CLASS_NORMAL; 122 123 protected int ipd; 124 125 protected int bpd; 126 127 130 protected Map props = null; 131 132 135 protected static Log log = LogFactory.getLog(Area.class); 136 137 138 143 public int getAreaClass() { 144 return areaClass; 145 } 146 147 152 public void setAreaClass(int areaClass) { 153 this.areaClass = areaClass; 154 } 155 156 163 public void setIPD(int i) { 164 ipd = i; 165 } 166 167 174 public int getIPD() { 175 return ipd; 176 } 177 178 185 public void setBPD(int b) { 186 bpd = b; 187 } 188 189 196 public int getBPD() { 197 return bpd; 198 } 199 200 207 public int getAllocIPD() { 208 return getBorderAndPaddingWidthStart() + getIPD() + getBorderAndPaddingWidthEnd(); 209 } 210 211 218 public int getAllocBPD() { 219 return getSpaceBefore() + getBorderAndPaddingWidthBefore() + getBPD() 220 + getBorderAndPaddingWidthAfter() + getSpaceAfter(); 221 } 222 223 228 public int getBorderAndPaddingWidthBefore() { 229 int margin = 0; 230 BorderProps bps = (BorderProps) getTrait(Trait.BORDER_BEFORE); 231 if (bps != null) { 232 margin = bps.width; 233 } 234 235 Integer padWidth = (Integer ) getTrait(Trait.PADDING_BEFORE); 236 if (padWidth != null) { 237 margin += padWidth.intValue(); 238 } 239 240 return margin; 241 } 242 243 248 public int getBorderAndPaddingWidthAfter() { 249 int margin = 0; 250 251 BorderProps bps = (BorderProps) getTrait(Trait.BORDER_AFTER); 252 if (bps != null) { 253 margin = bps.width; 254 } 255 256 Integer padWidth = (Integer ) getTrait(Trait.PADDING_AFTER); 257 if (padWidth != null) { 258 margin += padWidth.intValue(); 259 } 260 261 return margin; 262 } 263 264 269 public int getBorderAndPaddingWidthStart() { 270 int margin = 0; 271 BorderProps bps = (BorderProps) getTrait(Trait.BORDER_START); 272 if (bps != null) { 273 margin = bps.width; 274 } 275 276 Integer padWidth = (Integer ) getTrait(Trait.PADDING_START); 277 if (padWidth != null) { 278 margin += padWidth.intValue(); 279 } 280 281 return margin; 282 } 283 284 289 public int getBorderAndPaddingWidthEnd() { 290 int margin = 0; 291 BorderProps bps = (BorderProps) getTrait(Trait.BORDER_END); 292 if (bps != null) { 293 margin = bps.width; 294 } 295 296 Integer padWidth = (Integer ) getTrait(Trait.PADDING_END); 297 if (padWidth != null) { 298 margin += padWidth.intValue(); 299 } 300 301 return margin; 302 } 303 304 309 public int getSpaceBefore() { 310 int margin = 0; 311 Integer space = (Integer ) getTrait(Trait.SPACE_BEFORE); 312 if (space != null) { 313 margin = space.intValue(); 314 } 315 return margin; 316 } 317 318 323 public int getSpaceAfter() { 324 int margin = 0; 325 Integer space = (Integer ) getTrait(Trait.SPACE_AFTER); 326 if (space != null) { 327 margin = space.intValue(); 328 } 329 return margin; 330 } 331 332 337 public int getSpaceStart() { 338 int margin = 0; 339 Integer space = (Integer ) getTrait(Trait.SPACE_START); 340 if (space != null) { 341 margin = space.intValue(); 342 } 343 return margin; 344 } 345 346 351 public int getSpaceEnd() { 352 int margin = 0; 353 Integer space = (Integer ) getTrait(Trait.SPACE_END); 354 if (space != null) { 355 margin = space.intValue(); 356 } 357 return margin; 358 } 359 360 367 public void addChildArea(Area child) { 368 } 369 370 375 public void addTrait(Trait prop) { 376 if (props == null) { 377 props = new java.util.HashMap (20); 378 } 379 props.put(prop.getPropType(), prop.getData()); 380 } 381 382 388 public void addTrait(Object traitCode, Object prop) { 389 if (props == null) { 390 props = new java.util.HashMap (20); 391 } 392 props.put(traitCode, prop); 393 } 394 395 400 public Map getTraits() { 401 return this.props; 402 } 403 404 405 public boolean hasTraits() { 406 return (this.props != null); 407 } 408 409 415 public Object getTrait(Object oTraitCode) { 416 return (props != null ? props.get(oTraitCode) : null); 417 } 418 419 424 public boolean hasTrait(Object oTraitCode) { 425 return (getTrait(oTraitCode) != null); 426 } 427 428 433 public boolean getBooleanTrait(Object oTraitCode) { 434 final Object obj = getTrait(oTraitCode); 435 if (obj instanceof Boolean ) { 436 return ((Boolean )obj).booleanValue(); 437 } else { 438 return false; 439 } 440 } 441 442 448 public int getTraitAsInteger(Object oTraitCode) { 449 final Object obj = getTrait(oTraitCode); 450 if (obj instanceof Integer ) { 451 return ((Integer )obj).intValue(); 452 } else { 453 throw new IllegalArgumentException ("Trait " 454 + oTraitCode.getClass().getName() 455 + " could not be converted to an integer"); 456 } 457 } 458 459 463 public String toString() { 464 StringBuffer sb = new StringBuffer (super.toString()); 465 sb.append(" {ipd=").append(Integer.toString(getIPD())); 466 sb.append(", bpd=").append(Integer.toString(getBPD())); 467 sb.append("}"); 468 return sb.toString(); 469 } 470 } 471 472 | Popular Tags |