Package javax.swing.text

Examples of javax.swing.text.View


      }
    Element el = doc.getDefaultRootElement();
    TestZoneView zv = new TestZoneView(el, View.Y_AXIS);
    zv.loadChildren(zv.getViewFactory());
    h.check(zv.getViewCount(), 1);
    View child = zv.getView(0);
    h.check(child.getStartOffset(), 0);
    h.check(child.getEndOffset(), el.getEndOffset());
  }
View Full Code Here


    TestZoneView zv = new TestZoneView(el, View.Y_AXIS);
    // Set the maximum zone size somewhere inside the second element.
    zv.setMaximumZoneSize(5);
    zv.loadChildren(zv.getViewFactory());
    h.check(zv.getViewCount(), 3);
    View child = zv.getView(0);
    h.check(child.getStartOffset(), 0);
    h.check(child.getEndOffset(), 3);
    child = zv.getView(1);
    h.check(child.getStartOffset(), 3);
    h.check(child.getEndOffset(), 7);
    child = zv.getView(2);
    h.check(child.getStartOffset(), 7);
    h.check(child.getEndOffset(), 11);
  }
View Full Code Here

      }
    Element el = doc.getDefaultRootElement();
    TestZoneView zv = new TestZoneView(el, View.X_AXIS);

    // Try valid zone.
    View zone = zv.createZone(0, 9);
    h.check(zone instanceof AsyncBoxView);
    h.check(zone.getStartOffset(), 0);
    h.check(zone.getEndOffset(), 9);
    // Check if the zone follows document insertions (via Positions).
    try
      {
        doc.insertString(5, "abcde", null);
      }
    catch (BadLocationException ex)
      {
        RuntimeException rte = new RuntimeException();
        rte.initCause(ex);
        throw rte;
      }
    h.check(zone.getStartOffset(), 0);
    h.check(zone.getEndOffset(), 14);

    // Try invalid zone. No error is thrown and the zone tracks some more
    // or less random positions. This is probably due to a bug in the Content
    // implementation of Sun, but anyway. We don't check the exact positions
    // here as it doesn't really matter anyway. This is unspecified!
View Full Code Here

        };
        boundsListener = new HierarchyBoundsAdapter() {
            @Override
            public void ancestorResized(HierarchyEvent e) {
                if (header == e.getComponent()) {
                    View v = (View) descriptionPane.getClientProperty(BasicHTML.propertyKey);
                    // view might get lost on LAF change ...
                    if (v == null) {
                        descriptionPane.putClientProperty(BasicHTML.propertyKey,
                                descriptionPane.getMultiLineSupport().createView(descriptionPane));
                        v = (View) descriptionPane.getClientProperty(BasicHTML.propertyKey);
                    }
                    if (v != null) {
                        Container tla = header.getTopLevelAncestor();
                        if (tla == null) {
                            tla = header.getParent();
                            while (tla.getParent() != null) {
                                tla = tla.getParent();
                            }
                        }
                        int h = Math.max(descriptionPane.getHeight(), tla.getHeight());
                        int w = Math.min(tla.getWidth(), header.getParent().getWidth());
                        // 35 = description pane insets, TODO: obtain dynamically
                        w -= 35 + header.getInsets().left + header.getInsets().right + descriptionPane.getInsets().left + descriptionPane.getInsets().right + imagePanel.getInsets().left + imagePanel.getInsets().right + imagePanel.getWidth() + descriptionPane.getBounds().x;
                        v.setSize(w, h);
                        descriptionPane.setSize(w, (int) Math.ceil(v.getPreferredSpan(View.Y_AXIS)));
                    }
                }
            }};
        header.addPropertyChangeListener(propListener);
        header.addHierarchyBoundsListener(boundsListener);
View Full Code Here

            try {
                kit.read(r, doc, 0);
            } catch (Throwable e) {
            }
            ViewFactory f = kit.getViewFactory();
            View hview = f.create(doc.getDefaultRootElement());
            View v = new Renderer(c, f, hview, true);
            return v;
        }
View Full Code Here

            View v = new Renderer(c, f, hview, true);
            return v;
        }

        public static void updateRenderer(JXLabel c) {
            View value = null;
            View oldValue = (View) c.getClientProperty(BasicHTML.propertyKey);
            if (oldValue == null || oldValue instanceof Renderer) {
                value = createView(c);
            }
            if (value != oldValue && oldValue != null) {
                for (int i = 0; i < oldValue.getViewCount(); i++) {
                    oldValue.getView(i).setParent(null);
                }
            }
            c.putClientProperty(BasicHTML.propertyKey, value);
        }
View Full Code Here

    private static class BasicViewFactory implements ViewFactory {
        public View create(Element elem) {

            String kind = elem.getName();
            View view = null;
            if (kind == null) {
                // default to text display
                view = new LabelView(elem);
            } else if (kind.equals(AbstractDocument.ContentElementName)) {
                view = new LabelView(elem);
View Full Code Here

                // if one of the parents is viewport, resized events will not be propagated down unless viewport is changing visibility of scrollbars.
                // To make sure Label is able to re-wrap text when viewport size changes, initiate re-wrapping here by changing size of view
                if (e.getChanged() instanceof JViewport) {
                    Rectangle viewportBounds = e.getChanged().getBounds();
                    if (viewportBounds.getWidth() < getWidth()) {
                        View view = getWrappingView();
                        if (view != null) {
                            view.setSize(viewportBounds.width, viewportBounds.height);
                        }
                    }
                }
            }});
    }
View Full Code Here

            return;
        }
        if (w > getVisibleRect().width) {
            w = getVisibleRect().width;
        }
        View view = (View) getClientProperty(BasicHTML.propertyKey);
        if (view != null && view instanceof Renderer) {
            view.setSize(w - occupiedWidth, h);
        }

    }
View Full Code Here

            double theta = getTextRotation();
            size.setSize(rotateWidth(size, theta), rotateHeight(size,
            theta));
        } else {
            // #swingx-780 preferred size is not set properly when parent container doesn't enforce the width
            View view = getWrappingView();
            if (view == null) {
                if (isLineWrap() && !MultiLineSupport.isHTML(getText())) {
                    // view might get lost on LAF change ...
                    putClientProperty(BasicHTML.propertyKey,
                            getMultiLineSupport().createView(this));
                    view = (View) getClientProperty(BasicHTML.propertyKey);
                } else {
                    return size;
                }
            }
            Insets insets = getInsets();
            int dx = insets.left + insets.right;
            int dy = insets.top + insets.bottom;
            //log.fine("INSETS:" + insets);
            //log.fine("BORDER:" + this.getBorder());
            Rectangle textR = new Rectangle();
            Rectangle viewR = new Rectangle();
            textR.x = textR.y = textR.width = textR.height = 0;
            viewR.x = dx;
            viewR.y = dy;
            viewR.width = viewR.height = Short.MAX_VALUE;
            // layout label
            // 1) icon
            Rectangle iconR = calculateIconRect();
            // 2) init textR
            boolean textIsEmpty = (getText() == null) || (getText().length() < 1);
            int lsb = 0;
            /* Unless both text and icon are non-null, we effectively ignore
             * the value of textIconGap.
             */
            int gap;
            if (textIsEmpty) {
                textR.width = textR.height = 0;
                gap = 0;
            }
            else {
                int availTextWidth;
                gap = (iconR.width == 0) ? 0 : getIconTextGap();

                occupiedWidth = dx + iconR.width + gap;
                Object parent = getParent();
                if (parent != null && (parent instanceof JPanel)) {
                    JPanel panel = ((JPanel) parent);
                    Border b = panel.getBorder();
                    if (b != null) {
                        Insets in = b.getBorderInsets(panel);
                        occupiedWidth += in.left + in.right;
                    }
                }
                if (getHorizontalTextPosition() == CENTER) {
                    availTextWidth = viewR.width;
                }
                else {
                    availTextWidth = viewR.width - (iconR.width + gap);
                }
                float xPrefSpan = view.getPreferredSpan(View.X_AXIS);
                //log.fine("atw:" + availTextWidth + ", vps:" + xPrefSpan);
                textR.width = Math.min(availTextWidth, (int) xPrefSpan);
                if (maxLineSpan > 0) {
                    textR.width = Math.min(textR.width, maxLineSpan);
                    if (xPrefSpan > maxLineSpan) {
                        view.setSize(maxLineSpan, textR.height);
                    }
                }
                textR.height = (int) view.getPreferredSpan(View.Y_AXIS);
                if (textR.height == 0) {
                    textR.height = getFont().getSize();
                }
                //log.fine("atw:" + availTextWidth + ", vps:" + xPrefSpan + ", h:" + textR.height);

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.