Example #1
0
 public Dimension layout(int availWidth, int availHeight) {
   if (this.layoutSize == null
       || availHeight != this.lastAvailHeight
       || availWidth != this.lastAvailWidth) {
     this.lastAvailHeight = availHeight;
     this.lastAvailWidth = availWidth;
     Insets insets = this.getInsets();
     int extraWidth = insets.right + insets.left;
     int blockWidth = availWidth - INDENT - extraWidth;
     int maxBlockWidth = blockWidth;
     ArrayList liDescendents = this.rootElement.getDescendents(new LiFilter());
     int size = liDescendents.size();
     int y = insets.top;
     int newNesting = this.nesting + 1;
     this.blocks.clear();
     for (int i = 0; i < size; i++) {
       HTMLElementImpl liElement = (HTMLElementImpl) liDescendents.get(i);
       RBlock block =
           new RBlock(newNesting, this.parserContext, this.frameContext, this.container, this);
       block.setParent(this);
       this.blocks.add(block);
       block.setRootNode(liElement);
       Dimension renderSize = block.layout(blockWidth, 0);
       int actualBlockWidth;
       if (renderSize.width > blockWidth) {
         actualBlockWidth = renderSize.width;
       } else {
         actualBlockWidth = blockWidth;
       }
       int blockHeight = renderSize.height;
       block.setBounds(insets.left + INDENT, y, actualBlockWidth, blockHeight);
       y += blockHeight + ITEM_SPACING;
       if (actualBlockWidth > maxBlockWidth) {
         maxBlockWidth = actualBlockWidth;
       }
     }
     int ph = y - ITEM_SPACING + insets.bottom;
     int pw = maxBlockWidth + INDENT + insets.left + insets.right;
     Dimension newSize = new Dimension(pw, ph);
     this.layoutSize = newSize;
     this.markValidated();
     return newSize;
   } else {
     return this.layoutSize;
   }
 }