Search in sources :

Example 21 with View

use of javax.swing.text.View in project jdk8u_jdk by JetBrains.

the class SynthButtonUI method getBaseline.

/**
     * {@inheritDoc}
     */
@Override
public int getBaseline(JComponent c, int width, int height) {
    if (c == null) {
        throw new NullPointerException("Component must be non-null");
    }
    if (width < 0 || height < 0) {
        throw new IllegalArgumentException("Width and height must be >= 0");
    }
    AbstractButton b = (AbstractButton) c;
    String text = b.getText();
    if (text == null || "".equals(text)) {
        return -1;
    }
    Insets i = b.getInsets();
    Rectangle viewRect = new Rectangle();
    Rectangle textRect = new Rectangle();
    Rectangle iconRect = new Rectangle();
    viewRect.x = i.left;
    viewRect.y = i.top;
    viewRect.width = width - (i.right + viewRect.x);
    viewRect.height = height - (i.bottom + viewRect.y);
    // layout the text and icon
    SynthContext context = getContext(b);
    FontMetrics fm = context.getComponent().getFontMetrics(context.getStyle().getFont(context));
    context.getStyle().getGraphicsUtils(context).layoutText(context, fm, b.getText(), b.getIcon(), b.getHorizontalAlignment(), b.getVerticalAlignment(), b.getHorizontalTextPosition(), b.getVerticalTextPosition(), viewRect, iconRect, textRect, b.getIconTextGap());
    View view = (View) b.getClientProperty(BasicHTML.propertyKey);
    int baseline;
    if (view != null) {
        baseline = BasicHTML.getHTMLBaseline(view, textRect.width, textRect.height);
        if (baseline >= 0) {
            baseline += textRect.y;
        }
    } else {
        baseline = textRect.y + fm.getAscent();
    }
    context.dispose();
    return baseline;
}
Also used : View(javax.swing.text.View)

Example 22 with View

use of javax.swing.text.View in project jdk8u_jdk by JetBrains.

the class SynthLabelUI method getBaseline.

/**
     * {@inheritDoc}
     */
@Override
public int getBaseline(JComponent c, int width, int height) {
    if (c == null) {
        throw new NullPointerException("Component must be non-null");
    }
    if (width < 0 || height < 0) {
        throw new IllegalArgumentException("Width and height must be >= 0");
    }
    JLabel label = (JLabel) c;
    String text = label.getText();
    if (text == null || "".equals(text)) {
        return -1;
    }
    Insets i = label.getInsets();
    Rectangle viewRect = new Rectangle();
    Rectangle textRect = new Rectangle();
    Rectangle iconRect = new Rectangle();
    viewRect.x = i.left;
    viewRect.y = i.top;
    viewRect.width = width - (i.right + viewRect.x);
    viewRect.height = height - (i.bottom + viewRect.y);
    // layout the text and icon
    SynthContext context = getContext(label);
    FontMetrics fm = context.getComponent().getFontMetrics(context.getStyle().getFont(context));
    context.getStyle().getGraphicsUtils(context).layoutText(context, fm, label.getText(), label.getIcon(), label.getHorizontalAlignment(), label.getVerticalAlignment(), label.getHorizontalTextPosition(), label.getVerticalTextPosition(), viewRect, iconRect, textRect, label.getIconTextGap());
    View view = (View) label.getClientProperty(BasicHTML.propertyKey);
    int baseline;
    if (view != null) {
        baseline = BasicHTML.getHTMLBaseline(view, textRect.width, textRect.height);
        if (baseline >= 0) {
            baseline += textRect.y;
        }
    } else {
        baseline = textRect.y + fm.getAscent();
    }
    context.dispose();
    return baseline;
}
Also used : Insets(java.awt.Insets) FontMetrics(java.awt.FontMetrics) Rectangle(java.awt.Rectangle) View(javax.swing.text.View)

Example 23 with View

use of javax.swing.text.View in project jdk8u_jdk by JetBrains.

the class SynthTabbedPaneUI method layoutLabel.

private void layoutLabel(SynthContext ss, int tabPlacement, FontMetrics metrics, int tabIndex, String title, Icon icon, Rectangle tabRect, Rectangle iconRect, Rectangle textRect, boolean isSelected) {
    View v = getTextViewForTab(tabIndex);
    if (v != null) {
        tabPane.putClientProperty("html", v);
    }
    textRect.x = textRect.y = iconRect.x = iconRect.y = 0;
    ss.getStyle().getGraphicsUtils(ss).layoutText(ss, metrics, title, icon, SwingUtilities.CENTER, SwingUtilities.CENTER, SwingUtilities.LEADING, SwingUtilities.CENTER, tabRect, iconRect, textRect, textIconGap);
    tabPane.putClientProperty("html", null);
    int xNudge = getTabLabelShiftX(tabPlacement, tabIndex, isSelected);
    int yNudge = getTabLabelShiftY(tabPlacement, tabIndex, isSelected);
    iconRect.x += xNudge;
    iconRect.y += yNudge;
    textRect.x += xNudge;
    textRect.y += yNudge;
}
Also used : View(javax.swing.text.View)

Example 24 with View

use of javax.swing.text.View in project jdk8u_jdk by JetBrains.

the class ParagraphView method isVisible.

/**
     * Indicates whether or not this view should be
     * displayed.  If none of the children wish to be
     * displayed and the only visible child is the
     * break that ends the paragraph, the paragraph
     * will not be considered visible.  Otherwise,
     * it will be considered visible and return true.
     *
     * @return true if the paragraph should be displayed
     */
public boolean isVisible() {
    int n = getLayoutViewCount() - 1;
    for (int i = 0; i < n; i++) {
        View v = getLayoutView(i);
        if (v.isVisible()) {
            return true;
        }
    }
    if (n > 0) {
        View v = getLayoutView(n);
        if ((v.getEndOffset() - v.getStartOffset()) == 1) {
            return false;
        }
    }
    // be visible.
    if (getStartOffset() == getDocument().getLength()) {
        boolean editable = false;
        Component c = getContainer();
        if (c instanceof JTextComponent) {
            editable = ((JTextComponent) c).isEditable();
        }
        if (!editable) {
            return false;
        }
    }
    return true;
}
Also used : JTextComponent(javax.swing.text.JTextComponent) JTextComponent(javax.swing.text.JTextComponent) View(javax.swing.text.View)

Example 25 with View

use of javax.swing.text.View in project jdk8u_jdk by JetBrains.

the class AquaButtonUI method paint.

// Paint Methods
public void paint(final Graphics g, final JComponent c) {
    final AbstractButton b = (AbstractButton) c;
    final ButtonModel model = b.getModel();
    final Insets i = c.getInsets();
    Rectangle viewRect = new Rectangle(b.getWidth(), b.getHeight());
    Rectangle iconRect = new Rectangle();
    Rectangle textRect = new Rectangle();
    // a darkening effect. How can we avoid it. Try clear rect?
    if (b.isOpaque()) {
        g.setColor(c.getBackground());
        g.fillRect(viewRect.x, viewRect.y, viewRect.width, viewRect.height);
    }
    AquaButtonBorder aquaBorder = null;
    if (((AbstractButton) c).isBorderPainted()) {
        final Border border = c.getBorder();
        if (border instanceof AquaButtonBorder) {
            // only do this if borders are on!
            // this also takes care of focus painting.
            aquaBorder = (AquaButtonBorder) border;
            aquaBorder.paintButton(c, g, viewRect.x, viewRect.y, viewRect.width, viewRect.height);
        }
    } else {
        if (b.isOpaque()) {
            viewRect.x = i.left - 2;
            viewRect.y = i.top - 2;
            viewRect.width = b.getWidth() - (i.right + viewRect.x) + 4;
            viewRect.height = b.getHeight() - (i.bottom + viewRect.y) + 4;
            if (b.isContentAreaFilled() || model.isSelected()) {
                if (// Toggle buttons
                model.isSelected())
                    g.setColor(c.getBackground().darker());
                else
                    g.setColor(c.getBackground());
                g.fillRect(viewRect.x, viewRect.y, viewRect.width, viewRect.height);
            }
        }
        // for now we don't know exactly what to do...we'll see!
        if (b.isFocusPainted() && b.hasFocus()) {
            // paint UI specific focus
            paintFocus(g, b, viewRect, textRect, iconRect);
        }
    }
    // performs icon and text rect calculations
    final String text = layoutAndGetText(g, b, aquaBorder, i, viewRect, iconRect, textRect);
    // Paint the Icon
    if (b.getIcon() != null) {
        paintIcon(g, b, iconRect);
    }
    if (textRect.width == 0) {
        textRect.width = 50;
    }
    if (text != null && !text.equals("")) {
        final View v = (View) c.getClientProperty(BasicHTML.propertyKey);
        if (v != null) {
            v.paint(g, textRect);
        } else {
            paintText(g, b, textRect, text);
        }
    }
}
Also used : Border(javax.swing.border.Border) View(javax.swing.text.View)

Aggregations

View (javax.swing.text.View)66 Dimension (java.awt.Dimension)4 Rectangle (java.awt.Rectangle)4 UIResource (javax.swing.plaf.UIResource)4 FontMetrics (java.awt.FontMetrics)3 Insets (java.awt.Insets)3 Color (java.awt.Color)2 Border (javax.swing.border.Border)2 JBColor (com.intellij.ui.JBColor)1 JBGradientPaint (com.intellij.ui.JBGradientPaint)1 Container (java.awt.Container)1 Font (java.awt.Font)1 Graphics2D (java.awt.Graphics2D)1 Point (java.awt.Point)1 UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)1 PrinterException (java.awt.print.PrinterException)1 IOException (java.io.IOException)1 Reader (java.io.Reader)1 StringReader (java.io.StringReader)1 ColorUIResource (javax.swing.plaf.ColorUIResource)1