Search in sources :

Example 1 with ListValues

use of org.loboevolution.html.ListValues in project LoboEvolution by LoboEvolution.

the class BaseRListElement method applyStyle.

/**
 * {@inheritDoc}
 */
@Override
protected void applyStyle(int availWidth, int availHeight) {
    this.listStyle = null;
    super.applyStyle(availWidth, availHeight);
    final Object rootNode = this.modelNode;
    if (rootNode instanceof HTMLElementImpl) {
        final HTMLElementImpl rootElement = (HTMLElementImpl) rootNode;
        final AbstractCSSProperties props = rootElement.getCurrentStyle();
        if (props != null) {
            ListStyle listStyle = null;
            final String listStyleText = props.getListStyle();
            if (listStyleText != null) {
                listStyle = HtmlValues.getListStyle(listStyleText);
            }
            final String listStyleTypeText = props.getListStyleType();
            if (listStyleTypeText != null) {
                final ListValues listType = HtmlValues.getListStyleType(listStyleTypeText);
                if (listType != ListValues.TYPE_UNSET) {
                    if (listStyle == null) {
                        listStyle = new ListStyle();
                    }
                    listStyle.setType(listType.getValue());
                }
            }
            final String listStyleImage = props.getListStyleImage();
            if (listStyleImage != null && HtmlValues.isUrl(listStyleImage)) {
                final Image img = HtmlValues.getListStyleImage(listStyleImage);
                if (listStyle == null) {
                    listStyle = new ListStyle();
                }
                listStyle.setType(ListValues.TYPE_URL.getValue());
                listStyle.setImage(img);
            }
            if (listStyle == null || ListValues.get(listStyle.getType()) == ListValues.TYPE_UNSET) {
                final String typeAttributeText = rootElement.getAttribute("type");
                if (typeAttributeText != null) {
                    final ListValues newStyleType = HtmlValues.getListStyleType(typeAttributeText);
                    if (newStyleType != ListValues.TYPE_UNSET) {
                        if (listStyle == null) {
                            listStyle = new ListStyle();
                            this.listStyle = listStyle;
                        }
                        listStyle.setType(newStyleType.getValue());
                    }
                }
            }
            this.listStyle = listStyle;
        }
    }
}
Also used : HTMLElementImpl(org.loboevolution.html.dom.domimpl.HTMLElementImpl) ListStyle(org.loboevolution.html.style.ListStyle) ListValues(org.loboevolution.html.ListValues) AbstractCSSProperties(org.loboevolution.html.style.AbstractCSSProperties)

Example 2 with ListValues

use of org.loboevolution.html.ListValues in project LoboEvolution by LoboEvolution.

the class RListItem method paint.

/**
 * {@inheritDoc}
 */
@Override
public void paint(final Graphics g) {
    super.paint(g);
    final RenderState rs = this.modelNode.getRenderState();
    final Insets marginInsets = this.marginInsets;
    final RBlockViewport layout = this.bodyLayout;
    if (layout != null) {
        final ListStyle listStyle = this.listStyle;
        ListValues bulletType = listStyle == null ? ListValues.TYPE_UNSET : ListValues.get(listStyle.getType());
        if (bulletType != ListValues.TYPE_NONE) {
            if (bulletType == ListValues.TYPE_UNSET) {
                RCollection parent = getOriginalOrCurrentParent();
                if (!(parent instanceof RList)) {
                    parent = parent.getOriginalOrCurrentParent();
                }
                if (parent instanceof RList) {
                    final ListStyle parentListStyle = ((RList) parent).listStyle;
                    bulletType = parentListStyle == null ? ListValues.TYPE_DECIMAL : ListValues.get(parentListStyle.getType());
                } else {
                    bulletType = ListValues.TYPE_DECIMAL;
                }
            }
            final Color prevColor = g.getColor();
            g.setColor(rs.getColor());
            try {
                final Insets insets = getInsets(this.hasHScrollBar, this.hasVScrollBar);
                final Insets paddingInsets = this.paddingInsets;
                final int baselineOffset = layout.getFirstBaselineOffset();
                final int bulletRight = (marginInsets == null ? 0 : marginInsets.left) - BULLET_RMARGIN;
                final int bulletBottom = insets.top + baselineOffset + (paddingInsets == null ? 0 : paddingInsets.top);
                final int bulletTop = bulletBottom - BULLET_HEIGHT;
                final int bulletLeft = bulletRight - BULLET_WIDTH;
                final int bulletNumber = this.count;
                String numberText = null;
                switch(bulletType) {
                    case TYPE_DECIMAL:
                        numberText = bulletNumber + ".";
                        break;
                    case TYPE_DECIMAL_LEADING_ZERO:
                        if (bulletNumber < 10)
                            numberText = "0" + bulletNumber + ".";
                        else
                            numberText = bulletNumber + ".";
                        break;
                    case TYPE_LOWER_ALPHA:
                        numberText = ((char) ('a' + (bulletNumber - 1))) + ".";
                        break;
                    case TYPE_UPPER_ALPHA:
                        numberText = ((char) ('A' + (bulletNumber - 1))) + ".";
                        break;
                    case TYPE_DISC:
                        g.fillOval(bulletLeft, bulletTop, BULLET_WIDTH, BULLET_HEIGHT);
                        break;
                    case TYPE_CIRCLE:
                        g.drawOval(bulletLeft, bulletTop, BULLET_WIDTH, BULLET_HEIGHT);
                        break;
                    case TYPE_SQUARE:
                        g.fillRect(bulletLeft, bulletTop, BULLET_WIDTH, BULLET_HEIGHT);
                        break;
                    case TYPE_LOWER_ROMAN:
                        numberText = ListStyle.getRomanNumerals(bulletNumber).toLowerCase() + ".";
                        break;
                    case TYPE_UPPER_ROMAN:
                        numberText = ListStyle.getRomanNumerals(bulletNumber).toUpperCase() + ".";
                        break;
                    case TYPE_URL:
                        g.drawImage(listStyle.getImage(), bulletLeft, bulletTop, null);
                        break;
                    default:
                        numberText = null;
                        break;
                }
                if (numberText != null) {
                    final FontMetrics fm = g.getFontMetrics();
                    final int numberLeft = bulletRight - fm.stringWidth(numberText);
                    final int numberY = bulletBottom;
                    g.drawString(numberText, numberLeft, numberY);
                }
            } finally {
                g.setColor(prevColor);
            }
        }
    }
}
Also used : ListStyle(org.loboevolution.html.style.ListStyle) ListValues(org.loboevolution.html.ListValues) RenderState(org.loboevolution.html.renderstate.RenderState)

Example 3 with ListValues

use of org.loboevolution.html.ListValues in project LoboEvolution by LoboEvolution.

the class HtmlValues method getListStyle.

/**
 * <p>getListStyle.</p>
 *
 * @param listStyleText a {@link java.lang.String} object.
 * @return a {@link org.loboevolution.html.style.ListStyle} object.
 */
public static ListStyle getListStyle(String listStyleText) {
    final ListStyle listStyle = new ListStyle();
    final String[] tokens = HtmlValues.splitCssValue(listStyleText);
    for (final String token : tokens) {
        final ListValues listStyleType = HtmlValues.getListStyleType(token);
        if (listStyleType != ListValues.TYPE_UNSET && listStyleType != ListValues.NONE && listStyle.getType() < 1) {
            listStyle.setType(listStyleType.getValue());
        } else if (HtmlValues.isUrl(token)) {
            listStyle.setType(ListValues.TYPE_URL.getValue());
            listStyle.setImage(getListStyleImage(token));
        } else {
            final ListValues listStylePosition = HtmlValues.getListStylePosition(token);
            if (listStylePosition != ListValues.POSITION_UNSET && listStylePosition != ListValues.NONE) {
                listStyle.setPosition(listStylePosition.getValue());
            }
        }
    }
    return listStyle;
}
Also used : ListValues(org.loboevolution.html.ListValues)

Aggregations

ListValues (org.loboevolution.html.ListValues)3 ListStyle (org.loboevolution.html.style.ListStyle)2 HTMLElementImpl (org.loboevolution.html.dom.domimpl.HTMLElementImpl)1 RenderState (org.loboevolution.html.renderstate.RenderState)1 AbstractCSSProperties (org.loboevolution.html.style.AbstractCSSProperties)1