Search in sources :

Example 1 with View

use of javax.swing.text.View in project intellij-community by JetBrains.

the class DarculaCheckBoxUI method drawText.

protected void drawText(JComponent c, Graphics2D g, JCheckBox b, FontMetrics fm, Rectangle textRect, String text) {
    //text
    if (text != null) {
        View view = (View) c.getClientProperty(BasicHTML.propertyKey);
        if (view != null) {
            view.paint(g, textRect);
        } else {
            g.setColor(b.isEnabled() ? b.getForeground() : getDisabledTextColor());
            SwingUtilities2.drawStringUnderlineCharAt(c, g, text, b.getDisplayedMnemonicIndex(), textRect.x, textRect.y + fm.getAscent());
        }
    }
}
Also used : View(javax.swing.text.View)

Example 2 with View

use of javax.swing.text.View in project intellij-community by JetBrains.

the class MacIntelliJButtonUI method paint.

@Override
public void paint(Graphics g, JComponent c) {
    if (!(c.getBorder() instanceof MacIntelliJButtonBorder) && !isComboButton(c)) {
        super.paint(g, c);
        return;
    }
    int w = c.getWidth();
    int h = c.getHeight();
    if (isHelpButton(c)) {
        Icon icon = MacIntelliJIconCache.getIcon("helpButton", false, c.hasFocus());
        int x = (w - icon.getIconWidth()) / 2;
        int y = (h - icon.getIconHeight()) / 2;
        icon.paintIcon(c, g, x, y);
    } else {
        AbstractButton b = (AbstractButton) c;
        String text = layout(b, SwingUtilities2.getFontMetrics(b, g), b.getWidth(), b.getHeight());
        boolean isFocused = c.hasFocus();
        if (isSquare(c)) {
            Icon icon = MacIntelliJIconCache.getIcon("browseButton");
            int x = (c.getWidth() - icon.getIconWidth()) / 2;
            int y = (c.getHeight() - icon.getIconHeight()) / 2;
            icon.paintIcon(c, g, x, y);
            return;
        } else {
            int x = isFocused ? 0 : 2;
            int y = isFocused ? 0 : (h - viewRect.height) / 2;
            Icon icon;
            icon = getLeftIcon(b);
            icon.paintIcon(b, g, x, y);
            x += icon.getIconWidth();
            int stop = w - (isFocused ? 0 : 2) - (getRightIcon(b).getIconWidth());
            Graphics gg = g.create(0, 0, w, h);
            gg.setClip(x, y, stop - x, h);
            icon = getMiddleIcon(b);
            while (x < stop) {
                icon.paintIcon(b, gg, x, y);
                x += icon.getIconWidth();
            }
            gg.dispose();
            icon = getRightIcon(b);
            icon.paintIcon(b, g, stop, y);
            clearTextShiftOffset();
        }
        // Paint the Icon
        if (b.getIcon() != null) {
            paintIcon(g, c, iconRect);
        }
        if (text != null && !text.isEmpty()) {
            View v = (View) c.getClientProperty(BasicHTML.propertyKey);
            if (v != null) {
                v.paint(g, textRect);
            } else {
                UISettings.setupAntialiasing(g);
                paintText(g, b, textRect, text);
            }
        }
    }
}
Also used : View(javax.swing.text.View)

Example 3 with View

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

the class HTMLRenderer method get.

/**
	 * 	Get View from HTML String
	 *	@param html html string
	 *	@return renderer view
	 */
public static HTMLRenderer get(String html) {
    HTMLEditorKit kit = new HTMLEditorKit();
    HTMLDocument doc = (HTMLDocument) kit.createDefaultDocument();
    try {
        doc.remove(0, doc.getLength());
        Reader r = new StringReader(html);
        kit.read(r, doc, 0);
    } catch (Exception e) {
        log.log(Level.SEVERE, "", e);
    }
    //	Create Renderer
    Element element = doc.getDefaultRootElement();
    ViewFactory factory = kit.getViewFactory();
    //	Y_AXIS is main
    View view = factory.create(element);
    HTMLRenderer renderer = new HTMLRenderer(factory, view);
    renderer.preferenceChanged(null, true, true);
    return renderer;
}
Also used : HTMLDocument(javax.swing.text.html.HTMLDocument) Element(javax.swing.text.Element) ViewFactory(javax.swing.text.ViewFactory) StringReader(java.io.StringReader) Reader(java.io.Reader) StringReader(java.io.StringReader) HTMLEditorKit(javax.swing.text.html.HTMLEditorKit) View(javax.swing.text.View) BadLocationException(javax.swing.text.BadLocationException)

Example 4 with View

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

the class AquaTabbedPaneContrastUI method paintTitle.

protected void paintTitle(final Graphics2D g2d, final Font font, final FontMetrics metrics, final Rectangle textRect, final int tabIndex, final String title) {
    final View v = getTextViewForTab(tabIndex);
    if (v != null) {
        v.paint(g2d, textRect);
        return;
    }
    if (title == null)
        return;
    final Color color = tabPane.getForegroundAt(tabIndex);
    if (color instanceof UIResource) {
        g2d.setColor(getNonSelectedTabTitleColor());
        if (tabPane.getSelectedIndex() == tabIndex) {
            boolean pressed = isPressedAt(tabIndex);
            boolean enabled = tabPane.isEnabled() && tabPane.isEnabledAt(tabIndex);
            Color textColor = getSelectedTabTitleColor(enabled, pressed);
            Color shadowColor = getSelectedTabTitleShadowColor(enabled);
            AquaUtils.paintDropShadowText(g2d, tabPane, font, metrics, textRect.x, textRect.y, 0, 1, textColor, shadowColor, title);
            return;
        }
    } else {
        g2d.setColor(color);
    }
    g2d.setFont(font);
    SwingUtilities2.drawString(tabPane, g2d, title, textRect.x, textRect.y + metrics.getAscent());
}
Also used : Color(java.awt.Color) View(javax.swing.text.View) UIResource(javax.swing.plaf.UIResource)

Example 5 with View

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

the class AquaTabbedPaneCopyFromBasicUI method calculateTabHeight.

protected int calculateTabHeight(final int tabPlacement, final int tabIndex, final int fontHeight) {
    int height = 0;
    final Component c = tabPane.getTabComponentAt(tabIndex);
    if (c != null) {
        height = c.getPreferredSize().height;
    } else {
        final View v = getTextViewForTab(tabIndex);
        if (v != null) {
            // html
            height += (int) v.getPreferredSpan(View.Y_AXIS);
        } else {
            // plain text
            height += fontHeight;
        }
        final Icon icon = getIconForTab(tabIndex);
        if (icon != null) {
            height = Math.max(height, icon.getIconHeight());
        }
    }
    final Insets tabInsets = getTabInsets(tabPlacement, tabIndex);
    height += tabInsets.top + tabInsets.bottom + 2;
    return height;
}
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