Esempio n. 1
0
 /* (non-Javadoc)
  * @see javax.swing.JComponent#paintComponent(java.awt.Graphics)
  */
 public void paint(Graphics g) {
   g.setColor(Color.BLACK);
   HTMLElementImpl rootElement = this.rootElement;
   String type = rootElement.getAttribute("type");
   int bulletType = 0;
   boolean numbered = rootElement instanceof HTMLOListElement;
   FontMetrics fm = null;
   int bulletNumber = 0;
   if (numbered) {
     HTMLOListElementImpl oList = (HTMLOListElementImpl) rootElement;
     bulletNumber = oList.getStart();
     Font f = g.getFont();
     fm = Toolkit.getDefaultToolkit().getFontMetrics(f);
   } else {
     if ("disc".equalsIgnoreCase(type)) {
       bulletType = 0;
     } else if ("circle".equalsIgnoreCase(type)) {
       bulletType = 1;
     } else if ("square".equals(type)) {
       bulletType = 2;
     } else {
       bulletType = this.nesting;
     }
   }
   Iterator i = this.blocks.iterator();
   while (i.hasNext()) {
     Object c = i.next();
     if (c instanceof RBlock) {
       RBlock hp = (RBlock) c;
       Rectangle bounds = hp.getBounds();
       Graphics newG = g.create(bounds.x, bounds.y, bounds.width, bounds.height);
       hp.paint(newG);
       int lineHeight = hp.getFirstLineHeight();
       int bulletRight = bounds.x - BULLET_SPACING;
       int bulletBottom = bounds.y + lineHeight;
       if (numbered) {
         // TODO: value attribute from LI element
         // TODO: type attribute from LI element
         String numberText = bulletNumber + ".";
         int bulletLeft = bulletRight - fm.stringWidth(numberText);
         int bulletY = bulletBottom - fm.getDescent();
         g.drawString(numberText, bulletLeft, bulletY);
       } else {
         bulletBottom -= BULLET_BOTTOM_PADDING;
         int bulletTop = bulletBottom - BULLET_HEIGHT;
         int bulletLeft = bulletRight - BULLET_WIDTH;
         if (bulletType == 0) {
           g.fillOval(bulletLeft, bulletTop, BULLET_WIDTH, BULLET_HEIGHT);
         } else if (bulletType == 1) {
           g.drawOval(bulletLeft, bulletTop, BULLET_WIDTH, BULLET_HEIGHT);
         } else {
           g.fillRect(bulletLeft, bulletTop, BULLET_WIDTH, BULLET_HEIGHT);
         }
       }
       bulletNumber++;
     }
   }
 }
Esempio n. 2
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;
   }
 }
Esempio n. 3
0
 public boolean paintSelection(
     Graphics g, boolean inSelection, RenderablePoint startPoint, RenderablePoint endPoint) {
   Iterator i = this.blocks.iterator();
   while (i.hasNext()) {
     Object c = i.next();
     if (c instanceof RBlock) {
       RBlock hp = (RBlock) c;
       Rectangle bounds = hp.getBounds();
       Graphics subG = g.create(bounds.x, bounds.y, bounds.width, bounds.height);
       boolean newInSelection = hp.paintSelection(subG, inSelection, startPoint, endPoint);
       if (inSelection && !newInSelection) {
         return false;
       }
       inSelection = newInSelection;
     }
   }
   return inSelection;
 }
Esempio n. 4
0
 public boolean extractSelectionText(
     StringBuffer buffer,
     boolean inSelection,
     RenderablePoint startPoint,
     RenderablePoint endPoint) {
   Iterator i = this.blocks.iterator();
   while (i.hasNext()) {
     Object c = i.next();
     if (c instanceof RBlock) {
       RBlock hp = (RBlock) c;
       boolean newInSelection = hp.extractSelectionText(buffer, inSelection, startPoint, endPoint);
       if (inSelection && !newInSelection) {
         return false;
       }
       inSelection = newInSelection;
     }
   }
   return inSelection;
 }