1 51 package org.apache.fop.layout; 52 53 import org.apache.fop.datatypes.*; 55 import org.apache.fop.layout.inline.InlineSpace; 57 58 import java.util.ArrayList ; 60 import java.util.Iterator ; 61 62 public abstract class Area extends Box { 63 64 68 protected FontState fontState; 69 protected BorderAndPadding bp = null; 70 71 protected ArrayList children = new ArrayList (); 72 73 74 protected int maxHeight; 75 76 79 protected int currentHeight = 0; 80 81 protected int tableCellXOffset = 0; 83 84 87 private int absoluteYtop = 0; 88 89 protected int contentRectangleWidth; 90 91 protected int allocationWidth; 92 93 94 protected Page page; 95 96 protected BackgroundProps background; 97 98 private IDReferences idReferences; 99 100 102 protected org.apache.fop.fo.FObj generatedBy; 106 protected String areaClass; 108 109 protected boolean isFirst = false; 111 protected boolean isLast = false; 112 113 117 public org.apache.fop.fo.FObj foCreator; 120 121 public Area(FontState fontState) { 122 setFontState(fontState); 123 } 126 127 136 public Area(FontState fontState, int allocationWidth, int maxHeight) { 137 setFontState(fontState); 138 this.allocationWidth = allocationWidth; 139 this.contentRectangleWidth = allocationWidth; 140 this.maxHeight = maxHeight; 141 } 144 145 private void setFontState(FontState fontState) { 146 this.fontState = fontState; 148 } 149 150 public void addChild(Box child) { 151 this.children.add(child); 152 child.parent = this; 153 } 154 155 public void addChildAtStart(Box child) { 156 this.children.add(0, child); 157 child.parent = this; 158 } 159 160 public void addDisplaySpace(int size) { 161 this.addChild(new DisplaySpace(size)); 162 this.currentHeight += size; 163 } 164 165 public void addInlineSpace(int size) { 166 this.addChild(new InlineSpace(size)); 167 } 169 170 public FontInfo getFontInfo() { 171 return this.page.getFontInfo(); 172 } 173 174 public void end() {} 175 176 public int getAllocationWidth() { 177 182 return this.allocationWidth; 183 } 184 185 193 public void setAllocationWidth(int w) { 194 this.allocationWidth = w; 195 this.contentRectangleWidth = this.allocationWidth; 196 } 197 198 public ArrayList getChildren() { 199 return this.children; 200 } 201 202 public boolean hasChildren() { 203 return (this.children.size() != 0); 204 } 205 206 211 public boolean hasNonSpaceChildren() { 212 if (this.children.size() > 0) { 213 Iterator childIter = children.iterator(); 214 while (childIter.hasNext()) { 215 if (! (childIter.next() instanceof DisplaySpace)) { 216 return true; 217 } 218 } 219 } 220 return false; 221 } 222 223 public int getContentWidth() { 224 229 return contentRectangleWidth; 230 } 231 232 public FontState getFontState() { 233 return this.fontState; 234 } 235 236 241 public int getContentHeight() { 242 return this.currentHeight; 243 } 244 245 252 public int getHeight() { 253 return this.currentHeight + getPaddingTop() + getPaddingBottom() 254 + getBorderTopWidth() + getBorderBottomWidth(); 255 } 256 257 public int getMaxHeight() { 258 return this.maxHeight; 260 264 } 265 266 public Page getPage() { 267 return this.page; 268 } 269 270 public BackgroundProps getBackground() { 271 return this.background; 272 } 273 274 public int getPaddingTop() { 276 return (bp == null ? 0 : bp.getPaddingTop(false)); 277 } 278 279 public int getPaddingLeft() { 280 return (bp == null ? 0 : bp.getPaddingLeft(false)); 281 } 282 283 public int getPaddingBottom() { 284 return (bp == null ? 0 : bp.getPaddingBottom(false)); 285 } 286 287 public int getPaddingRight() { 288 return (bp == null ? 0 : bp.getPaddingRight(false)); 289 } 290 291 public int getBorderTopWidth() { 294 return (bp == null ? 0 : bp.getBorderTopWidth(false)); 295 } 296 297 public int getBorderRightWidth() { 298 return (bp == null ? 0 : bp.getBorderRightWidth(false)); 299 } 300 301 public int getBorderLeftWidth() { 302 return (bp == null ? 0 : bp.getBorderLeftWidth(false)); 303 } 304 305 public int getBorderBottomWidth() { 306 return (bp == null ? 0 : bp.getBorderBottomWidth(false)); 307 } 308 309 public int getTableCellXOffset() { 310 return tableCellXOffset; 311 } 312 313 public void setTableCellXOffset(int offset) { 314 tableCellXOffset = offset; 315 } 316 317 325 public int getAbsoluteHeight() { 326 return absoluteYtop + getPaddingTop() + getBorderTopWidth() + 327 currentHeight; 328 } 329 330 338 public void setAbsoluteHeight(int value) { 339 absoluteYtop = value; 340 } 341 342 public void increaseHeight(int amount) { 343 this.currentHeight += amount; 344 } 345 346 public void removeChild(Area area) { 348 this.currentHeight -= area.getHeight(); 349 this.children.remove(area); 350 } 351 352 public void removeChild(DisplaySpace spacer) { 353 this.currentHeight -= spacer.getSize(); 354 this.children.remove(spacer); 355 } 356 357 public void remove() { 358 this.parent.removeChild(this); 359 } 360 361 public void setPage(Page page) { 362 this.page = page; 363 } 364 365 public void setBackground(BackgroundProps bg) { 366 this.background = bg; 367 } 368 369 public void setBorderAndPadding(BorderAndPadding bp) { 370 this.bp = bp; 371 } 372 373 379 public int spaceLeft() { 380 return maxHeight - currentHeight; 381 } 382 383 public void start() {} 384 385 386 394 public void setHeight(int height) { 395 int prevHeight = currentHeight; 396 if (height > currentHeight) { 397 currentHeight = height; 398 } 399 400 if (currentHeight > getMaxHeight()) { 401 currentHeight = getMaxHeight(); 402 } 403 } 404 405 public void setMaxHeight(int height) { 406 this.maxHeight = height; 407 } 408 409 public Area getParent() { 410 return this.parent; 411 } 412 413 public void setParent(Area parent) { 414 this.parent = parent; 415 } 416 417 public void setIDReferences(IDReferences idReferences) { 418 this.idReferences = idReferences; 419 } 420 421 public IDReferences getIDReferences() { 422 return idReferences; 423 } 424 425 426 public org.apache.fop.fo.FObj getfoCreator() { 427 return this.foCreator; 428 } 429 430 432 public AreaContainer getNearestAncestorAreaContainer() { 433 Area area = this.getParent(); 434 while (area != null && !(area instanceof AreaContainer)) { 435 area = area.getParent(); 436 } 437 return (AreaContainer)area; 438 } 439 440 public BorderAndPadding getBorderAndPadding() { 441 return bp; 442 } 443 444 448 452 456 460 public void setGeneratedBy(org.apache.fop.fo.FObj generatedBy) { 461 this.generatedBy = generatedBy; 462 } 463 464 public org.apache.fop.fo.FObj getGeneratedBy() { 465 return generatedBy; 466 } 467 468 public void isFirst(boolean isFirst) { 469 this.isFirst = isFirst; 470 } 471 472 public boolean isFirst() { 473 return isFirst; 474 } 475 476 public void isLast(boolean isLast) { 477 this.isLast = isLast; 478 } 479 480 public boolean isLast() { 481 return isLast; 482 } 483 484 } 485 | Popular Tags |