Search in sources :

Example 66 with View

use of javax.swing.text.View in project Spark by igniterealtime.

the class ChatPrinter method printView.

private boolean printView(Graphics2D graphics2D, Shape allocation, View view) {
    boolean pageExists = false;
    Rectangle clipRectangle = graphics2D.getClipBounds();
    Shape childAllocation;
    View childView;
    if (view.getViewCount() > 0) {
        for (int i = 0; i < view.getViewCount(); i++) {
            childAllocation = view.getChildAllocation(i, allocation);
            if (childAllocation != null) {
                childView = view.getView(i);
                if (printView(graphics2D, childAllocation, childView)) {
                    pageExists = true;
                }
            }
        }
    } else {
        // I
        if (allocation.getBounds().getMaxY() >= clipRectangle.getY()) {
            pageExists = true;
            // II
            if ((allocation.getBounds().getHeight() > clipRectangle.getHeight()) && (allocation.intersects(clipRectangle))) {
                view.paint(graphics2D, allocation);
            } else {
                // III
                if (allocation.getBounds().getY() >= clipRectangle.getY()) {
                    if (allocation.getBounds().getMaxY() <= clipRectangle.getMaxY()) {
                        view.paint(graphics2D, allocation);
                    } else {
                        // IV
                        if (allocation.getBounds().getY() < pageEndY) {
                            pageEndY = allocation.getBounds().getY();
                        }
                    }
                }
            }
        }
    }
    return pageExists;
}
Also used : Shape(java.awt.Shape) Rectangle(java.awt.Rectangle) View(javax.swing.text.View)

Example 67 with View

use of javax.swing.text.View in project freeplane by freeplane.

the class ZoomableLabel method getLink.

public String getLink(Point p) {
    View view = (View) getClientProperty(BasicHTML.propertyKey);
    if (view == null)
        return null;
    Rectangle textR = ((ZoomableLabelUI) getUI()).getTextR(this);
    if (textR == null)
        return null;
    if (!textR.contains(p))
        return null;
    int x = (int) (p.x / getZoom());
    int y = (int) (p.y / getZoom());
    final int pos = view.viewToModel(x, y, textR);
    final HTMLDocument document = (HTMLDocument) view.getDocument();
    final String linkURL = HtmlUtils.getURLOfExistingLink(document, pos);
    return linkURL;
}
Also used : HTMLDocument(javax.swing.text.html.HTMLDocument) Rectangle(java.awt.Rectangle) View(javax.swing.text.View) Point(java.awt.Point)

Example 68 with View

use of javax.swing.text.View in project freeplane by freeplane.

the class ZoomableLabelUI method propertyChange.

@Override
public void propertyChange(PropertyChangeEvent e) {
    String name = e.getPropertyName();
    if (name == "text" || "font" == name || "foreground" == name || "ancestor" == name || "graphicsConfiguration" == name) {
        JLabel lbl = ((JLabel) e.getSource());
        if (getTextRenderingIcon(lbl) != null) {
            ScaledHTML.updateRenderer(lbl, "");
        } else {
            String text = lbl.getText();
            GlyphPainterMetricResetter.resetPainter();
            try {
                ScaledHTML.updateRenderer(lbl, text);
            } finally {
                GlyphPainterMetricResetter.resetPainter();
            }
            View v = (View) lbl.getClientProperty(BasicHTML.propertyKey);
            if (v != null) {
                lbl.putClientProperty("preferredWidth", v.getPreferredSpan(View.X_AXIS));
            }
        }
    } else
        super.propertyChange(e);
}
Also used : JLabel(javax.swing.JLabel) View(javax.swing.text.View)

Example 69 with View

use of javax.swing.text.View in project Zong by Xenoage.

the class TextEditor method computeOptimumSize.

/**
 * Computes the optimum size of this {@link TextEditor} in px.
 */
public Size2f computeOptimumSize() {
    View v = this.getUI().getRootView(this);
    v.setSize(Integer.MAX_VALUE, Integer.MAX_VALUE);
    return new Size2f(v.getPreferredSpan(View.X_AXIS), v.getPreferredSpan(View.Y_AXIS));
}
Also used : Size2f(com.xenoage.utils.math.geom.Size2f) View(javax.swing.text.View)

Example 70 with View

use of javax.swing.text.View in project LauncherV3 by TechnicPack.

the class FixRunDataDialog method getPreferredSize.

private java.awt.Dimension getPreferredSize(String html, int width) {
    resizer.setText(html);
    View view = (View) resizer.getClientProperty(javax.swing.plaf.basic.BasicHTML.propertyKey);
    view.setSize(width, 0);
    float w = view.getPreferredSpan(View.X_AXIS);
    float h = view.getPreferredSpan(View.Y_AXIS);
    return new java.awt.Dimension((int) Math.ceil(w), (int) Math.ceil(h));
}
Also used : View(javax.swing.text.View)

Aggregations

View (javax.swing.text.View)81 Rectangle (java.awt.Rectangle)8 HTMLDocument (javax.swing.text.html.HTMLDocument)6 Dimension (java.awt.Dimension)5 Element (javax.swing.text.Element)5 FontMetrics (java.awt.FontMetrics)4 Insets (java.awt.Insets)4 UIResource (javax.swing.plaf.UIResource)4 Point (java.awt.Point)3 SimpleAttributeSet (javax.swing.text.SimpleAttributeSet)3 Color (java.awt.Color)2 Font (java.awt.Font)2 Graphics2D (java.awt.Graphics2D)2 Reader (java.io.Reader)2 StringReader (java.io.StringReader)2 Border (javax.swing.border.Border)2 BadLocationException (javax.swing.text.BadLocationException)2 ViewFactory (javax.swing.text.ViewFactory)2 JBColor (com.intellij.ui.JBColor)1 JBGradientPaint (com.intellij.ui.JBGradientPaint)1