Package javax.swing.text

Examples of javax.swing.text.View


    private View getWrappingView() {
        if (super.getTopLevelAncestor() == null) {
            return null;
        }
        View view = (View) getClientProperty(BasicHTML.propertyKey);
        if (!(view instanceof Renderer)) {
            return null;
        }
        return view;
    }
View Full Code Here


            // fits in, math proof available upon request)

            dontIgnoreRepaint = false;
            double square = Math.min(getHeight(), getWidth()) * Math.cos(Math.PI / 4d);

            View v = (View) getClientProperty(BasicHTML.propertyKey);
            if (v == null) {
                // no html and no wrapline enabled means no view
                // ... find another way to figure out the heigh
                ty = getFontMetrics(getFont()).getHeight();
                double cw = (getWidth() - Math.abs(ty * Math.sin(textRotation)))
                        / Math.abs(Math.cos(textRotation));
                double ch = (getHeight() - Math.abs(ty * Math.cos(textRotation)))
                        / Math.abs(Math.sin(textRotation));
                // min of whichever is above 0 (!!! no min of abs values)
                tx = cw < 0 ? ch : ch > 0 ? Math.min(cw, ch) : cw;
            } else {
                float w = v.getPreferredSpan(View.X_AXIS);
                float h = v.getPreferredSpan(View.Y_AXIS);
                double c = w;
                double alpha = textRotation;// % (Math.PI/2d);
                boolean ready = false;
                while (!ready) {
                    // shorten the view len until line break is forced
                    while (h == v.getPreferredSpan(View.Y_AXIS)) {
                        w -= 10;
                        v.setSize(w, h);
                    }
                    if (w < square || h > square) {
                        // text is too long to fit no matter what. Revert shape to square since that is the
                        // best option (1st derivation for area size of rotated rect in rect is equal 0 for
                        // rotated rect with equal w and h i.e. for square)
                        w = h = (float) square;
                        // set view height to something big to prevent recursive resize/repaint requests
                        v.setSize(w, 100000);
                        break;
                    }
                    // calc avail width with new view height
                    h = v.getPreferredSpan(View.Y_AXIS);
                    double cw = (getWidth() - Math.abs(h * Math.sin(alpha))) / Math.abs(Math.cos(alpha));
                    double ch = (getHeight() - Math.abs(h * Math.cos(alpha))) / Math.abs(Math.sin(alpha));
                    // min of whichever is above 0 (!!! no min of abs values)
                    c = cw < 0 ? ch : ch > 0 ? Math.min(cw, ch) : cw;
                    // make it one pix smaller to ensure text is not cut on the left
                    c--;
                    if (c > w) {
                        v.setSize((float) c, 10 * h);
                        ready = true;
                    } else {
                        v.setSize((float) c, 10 * h);
                        if (v.getPreferredSpan(View.Y_AXIS) > h) {
                            // set size back to figure out new line break and height after
                            v.setSize(w, 10 * h);
                        } else {
                            w = (float) c;
                            ready = true;
                        }
                    }
View Full Code Here

      public ViewFactory getViewFactory() {

        return new HTMLFactory() {
          @Override
          public View create(Element e) {
            View v = super.create(e);
            if (v instanceof InlineView) {
              // FOR br TAG
              if (v.getBreakWeight(InlineView.X_AXIS, 0f, 0f) == InlineView.ForcedBreakWeight) {
                return v;
              }

              return new InlineView(e) {
                @Override
View Full Code Here

        }

        public void paint(final Graphics g, final float x, final float y,
                          final float w, final float h,
                          final View v, final int item) {
            final View child = v.getView(item);
            if (!(child instanceof BlockView)) {
                return;
            }

            final AttributeSet attr = child.getAttributes();
            final StyleSheet ss = ((BlockView)child).getStyleSheet();
            Font font = ss.getFont(attr);
            final Color color = ss.getForeground(attr);
            final CSS.ListStyleType listStyle =
                (CSS.ListStyleType)attr.getAttribute(Attribute.LIST_STYLE_TYPE);

            String decorator = null;

            int index;
            if (listStyle == null) {
                final String name = v.getElement().getName();
                if (HTML.Tag.OL.toString().equals(name)) {
                    index = CSS.ListStyleType.LIST_STYLE_DECIMAL;
                } else if (HTML.Tag.UL.toString().equals(name)) {
                    index = CSS.ListStyleType.LIST_STYLE_DISC;
                } else {
                    index = CSS.ListStyleType.LIST_STYLE_NONE;
                }
            } else {
                index = listStyle.getIndex();
            }

            switch (index) {
            case CSS.ListStyleType.LIST_STYLE_DISC:
                decorator = DISC;
                font = font.deriveFont(font.getSize2D() * 0.7f);
                break;

            case CSS.ListStyleType.LIST_STYLE_CIRCLE:
                decorator = CIRCLE;
                font = font.deriveFont(font.getSize2D() * 0.7f);
                break;

            case CSS.ListStyleType.LIST_STYLE_SQUARE:
                decorator = SQUARE;
                font = font.deriveFont(font.getSize2D() * 0.7f);
                break;


            case CSS.ListStyleType.LIST_STYLE_DECIMAL:
                decorator = Integer.toString(item + 1) + ".";
                break;


            case CSS.ListStyleType.LIST_STYLE_LOWER_ROMAN:
                decorator = Integer.toString(item + 1) + "r.";
                break;
            case CSS.ListStyleType.LIST_STYLE_UPPER_ROMAN:
                decorator = Integer.toString(item + 1) + "R.";
                break;

            case CSS.ListStyleType.LIST_STYLE_LOWER_ALPHA:
                decorator = (char)('a' + item) + ".";
                break;
            case CSS.ListStyleType.LIST_STYLE_UPPER_ALPHA:
                decorator = (char)('A' + item) + ".";
                break;

            case CSS.ListStyleType.LIST_STYLE_NONE:
            default:
            }

            if (decorator == null) {
                return;
            }

            Color oldColor = g.getColor();
            Font oldFont = g.getFont();

            g.setColor(color);
            g.setFont(font);
            FontMetrics metrics = g.getFontMetrics(font);
            int width = metrics.stringWidth(decorator);

            Rectangle pAlloc = new Rectangle((int)x, (int)y, (int)w, (int)h);
            pAlloc = (Rectangle)child.getChildAllocation(0, pAlloc);

            g.drawString(decorator,
                         (int)(x - width - DECORATOR_MARGIN),
                         (int)(pAlloc.y
                               + pAlloc.height * child.getView(0)
                                                 .getAlignment(View.Y_AXIS)
                               + metrics.getHeight() / 2f
                               - metrics.getDescent()));

            g.setFont(oldFont);
View Full Code Here

        Object resolveRelativeValue(final View view) {
            if (view == null) {
                return getDefaultValue();
            }
            final View parent = view.getParent();
            if (parent == null) {
                return getDefaultValue();
            }

            final AttributeSet attr = parent.getAttributes();
            final Object fs = attr.getAttribute(Attribute.FONT_SIZE);
            final int fontSize = fs != null ? ((Length)fs).intValue(parent)
                                            : getDefaultValue().intValue();
            int sizeValueIndex;
View Full Code Here

                    result /= 2;
                }
                return new Float(result);

            case RELATIVE_UNITS_PERCENTAGE:
                View parent = view.getParent();
                if (!(parent instanceof BoxView)) {
                    return ZERO;
                }
                float width = ((BoxView)parent).getWidth();
                if (width >= Integer.MAX_VALUE) {
View Full Code Here

    /**
     * Creates default plain view
     */
    View createView() {
        TextFactory factory = TextFactory.getTextFactory();
        View v = factory.createPlainView(document.getDefaultRootElement());
        return v;
    }
View Full Code Here

     * part of text fits this width)
     */
    Rectangle getModelRect() {
        Rectangle clientRect = getClient();
        clientRect.translate(scrollPosition.x, scrollPosition.y);
        View view = rootViewContext.getView();
        int ySpan = (int) view.getPreferredSpan(View.Y_AXIS);
        clientRect.height = ySpan;
        return clientRect;
    }
View Full Code Here

     * Necessary to be able to set echo character.
     */
    @Override
    View createView() {
        TextFactory factory = TextFactory.getTextFactory();
        View v = factory.createPasswordView(document.getDefaultRootElement());
        return v;
    }
View Full Code Here

     * to get word-wrapping behavior of TextArea without
     * horizontal scrollbar
     */
    private void replaceView() {
        TextFactory factory = TextFactory.getTextFactory();
        View view = factory.createWrappedPlainView(document.getDefaultRootElement());
        rootViewContext.getView().replace(0, 1, new View[] { view });
    }
View Full Code Here

TOP

Related Classes of javax.swing.text.View

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.