Search in sources :

Example 36 with View

use of javax.swing.text.View in project Botnak by Gocnak.

the class BaseToggleButtonUI method paint.

public void paint(Graphics g, JComponent c) {
    Graphics2D g2D = (Graphics2D) g;
    AbstractButton b = (AbstractButton) c;
    Font f = c.getFont();
    g.setFont(f);
    FontMetrics fm = g.getFontMetrics();
    Insets insets = c.getInsets();
    viewRect.x = insets.left;
    viewRect.y = insets.top;
    viewRect.width = b.getWidth() - (insets.right + viewRect.x);
    viewRect.height = b.getHeight() - (insets.bottom + viewRect.y);
    textRect.x = textRect.y = textRect.width = textRect.height = 0;
    iconRect.x = iconRect.y = iconRect.width = iconRect.height = 0;
    String text = SwingUtilities.layoutCompoundLabel(c, fm, b.getText(), b.getIcon(), b.getVerticalAlignment(), b.getHorizontalAlignment(), b.getVerticalTextPosition(), b.getHorizontalTextPosition(), viewRect, iconRect, textRect, b.getText() == null ? 0 : defaultTextIconGap);
    paintBackground(g, b);
    if (b.getIcon() != null) {
        if (!b.isEnabled()) {
            Composite savedComposite = g2D.getComposite();
            AlphaComposite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f);
            g2D.setComposite(alpha);
            paintIcon(g, c, iconRect);
            g2D.setComposite(savedComposite);
        } else {
            paintIcon(g, c, iconRect);
        }
    }
    if (text != null && !text.equals("") && textRect != null) {
        View v = (View) c.getClientProperty(BasicHTML.propertyKey);
        if (v != null) {
            Object savedRenderingHint = null;
            if (AbstractLookAndFeel.getTheme().isTextAntiAliasingOn()) {
                savedRenderingHint = g2D.getRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING);
                g2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, AbstractLookAndFeel.getTheme().getTextAntiAliasingHint());
            }
            v.paint(g, textRect);
            if (AbstractLookAndFeel.getTheme().isTextAntiAliasingOn()) {
                g2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, savedRenderingHint);
            }
        } else {
            paintText(g, b, textRect, text);
        }
    }
    if (b.isFocusPainted() && b.hasFocus()) {
        paintFocus(g, b, viewRect, textRect, iconRect);
    }
}
Also used : View(javax.swing.text.View)

Example 37 with View

use of javax.swing.text.View in project Botnak by Gocnak.

the class BaseButtonUI method paint.

public void paint(Graphics g, JComponent c) {
    Graphics2D g2D = (Graphics2D) g;
    AbstractButton b = (AbstractButton) c;
    Font f = c.getFont();
    g.setFont(f);
    FontMetrics fm = g.getFontMetrics();
    Insets insets = c.getInsets();
    viewRect.x = insets.left;
    viewRect.y = insets.top;
    viewRect.width = b.getWidth() - (insets.right + viewRect.x);
    viewRect.height = b.getHeight() - (insets.bottom + viewRect.y);
    textRect.x = textRect.y = textRect.width = textRect.height = 0;
    iconRect.x = iconRect.y = iconRect.width = iconRect.height = 0;
    int iconTextGap = defaultTextIconGap;
    if (JTattooUtilities.getJavaVersion() >= 1.4) {
        iconTextGap = b.getIconTextGap();
    }
    String text = SwingUtilities.layoutCompoundLabel(c, fm, b.getText(), b.getIcon(), b.getVerticalAlignment(), b.getHorizontalAlignment(), b.getVerticalTextPosition(), b.getHorizontalTextPosition(), viewRect, iconRect, textRect, b.getText() == null ? 0 : iconTextGap);
    paintBackground(g, b);
    if (b.getIcon() != null) {
        if (!b.isEnabled()) {
            Composite savedComposite = g2D.getComposite();
            AlphaComposite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f);
            g2D.setComposite(alpha);
            paintIcon(g, c, iconRect);
            g2D.setComposite(savedComposite);
        } else {
            if (b.getModel().isPressed() && b.getModel().isRollover()) {
                iconRect.x++;
                iconRect.y++;
            }
            paintIcon(g, c, iconRect);
        }
    }
    if (text != null && !text.equals("")) {
        View v = (View) c.getClientProperty(BasicHTML.propertyKey);
        if (v != null) {
            Object savedRenderingHint = null;
            if (AbstractLookAndFeel.getTheme().isTextAntiAliasingOn()) {
                savedRenderingHint = g2D.getRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING);
                g2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
            }
            v.paint(g, textRect);
            if (AbstractLookAndFeel.getTheme().isTextAntiAliasingOn()) {
                g2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, savedRenderingHint);
            }
        } else {
            paintText(g, b, textRect, text);
        }
    }
    if (b.isFocusPainted() && b.hasFocus()) {
        paintFocus(g, b, viewRect, textRect, iconRect);
    }
}
Also used : View(javax.swing.text.View)

Example 38 with View

use of javax.swing.text.View in project Botnak by Gocnak.

the class BaseRadioButtonUI method paintText.

protected void paintText(Graphics g, JComponent c, String text, Rectangle textRect) {
    View v = (View) c.getClientProperty(BasicHTML.propertyKey);
    if (v != null) {
        Graphics2D g2D = (Graphics2D) g;
        Object savedRenderingHint = null;
        if (AbstractLookAndFeel.getTheme().isTextAntiAliasingOn()) {
            savedRenderingHint = g2D.getRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING);
            g2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, AbstractLookAndFeel.getTheme().getTextAntiAliasingHint());
        }
        v.paint(g, textRect);
        if (AbstractLookAndFeel.getTheme().isTextAntiAliasingOn()) {
            g2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, savedRenderingHint);
        }
    } else {
        AbstractButton b = (AbstractButton) c;
        ButtonModel model = b.getModel();
        Font f = c.getFont();
        g.setFont(f);
        FontMetrics fm = g.getFontMetrics();
        int mnemIndex = -1;
        if (JTattooUtilities.getJavaVersion() >= 1.4) {
            mnemIndex = b.getDisplayedMnemonicIndex();
        } else {
            mnemIndex = JTattooUtilities.findDisplayedMnemonicIndex(b.getText(), model.getMnemonic());
        }
        if (model.isEnabled()) {
            g.setColor(b.getForeground());
            JTattooUtilities.drawStringUnderlineCharAt(c, g, text, mnemIndex, textRect.x, textRect.y + fm.getAscent());
        } else {
            g.setColor(Color.white);
            JTattooUtilities.drawStringUnderlineCharAt(c, g, text, mnemIndex, textRect.x + 1, textRect.y + 1 + fm.getAscent());
            g.setColor(AbstractLookAndFeel.getDisabledForegroundColor());
            JTattooUtilities.drawStringUnderlineCharAt(c, g, text, mnemIndex, textRect.x, textRect.y + fm.getAscent());
        }
    }
}
Also used : View(javax.swing.text.View)

Example 39 with View

use of javax.swing.text.View in project Botnak by Gocnak.

the class HiFiTabbedPaneUI method paintText.

protected void paintText(Graphics g, int tabPlacement, Font font, FontMetrics metrics, int tabIndex, String title, Rectangle textRect, boolean isSelected) {
    Color backColor = tabPane.getBackgroundAt(tabIndex);
    if (!(backColor instanceof UIResource)) {
        super.paintText(g, tabPlacement, font, metrics, tabIndex, title, textRect, isSelected);
        return;
    }
    g.setFont(font);
    View v = getTextViewForTab(tabIndex);
    if (v != null) {
        // html
        Graphics2D g2D = (Graphics2D) g;
        Object savedRenderingHint = null;
        if (AbstractLookAndFeel.getTheme().isTextAntiAliasingOn()) {
            savedRenderingHint = g2D.getRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING);
            g2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, AbstractLookAndFeel.getTheme().getTextAntiAliasingHint());
        }
        v.paint(g, textRect);
        if (AbstractLookAndFeel.getTheme().isTextAntiAliasingOn()) {
            g2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, savedRenderingHint);
        }
    } else {
        // plain text
        int mnemIndex = -1;
        if (JTattooUtilities.getJavaVersion() >= 1.4) {
            mnemIndex = tabPane.getDisplayedMnemonicIndexAt(tabIndex);
        }
        Graphics2D g2D = (Graphics2D) g;
        Composite composite = g2D.getComposite();
        AlphaComposite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.6f);
        g2D.setComposite(alpha);
        Color fc = tabPane.getForegroundAt(tabIndex);
        if (isSelected) {
            fc = AbstractLookAndFeel.getTheme().getTabSelectionForegroundColor();
        }
        if (!tabPane.isEnabled() || !tabPane.isEnabledAt(tabIndex)) {
            fc = AbstractLookAndFeel.getTheme().getDisabledForegroundColor();
        }
        if (ColorHelper.getGrayValue(fc) > 128) {
            g2D.setColor(Color.black);
        } else {
            g2D.setColor(Color.white);
        }
        JTattooUtilities.drawStringUnderlineCharAt(tabPane, g, title, mnemIndex, textRect.x + 1, textRect.y + 1 + metrics.getAscent());
        g2D.setComposite(composite);
        g2D.setColor(fc);
        JTattooUtilities.drawStringUnderlineCharAt(tabPane, g, title, mnemIndex, textRect.x, textRect.y + metrics.getAscent());
    }
}
Also used : View(javax.swing.text.View) UIResource(javax.swing.plaf.UIResource)

Example 40 with View

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

the class BegTabbedPaneUI method layoutLabel.

protected void layoutLabel(int tabPlacement, FontMetrics metrics, int tabIndex, String title, Icon icon, Rectangle tabRect, Rectangle iconRect, Rectangle textRect, boolean isSelected) {
    metrics = (myLayoutMetrics != null) ? myLayoutMetrics : metrics;
    textRect.x = textRect.y = iconRect.x = iconRect.y = 0;
    View v = getTextViewForTab(tabIndex);
    if (v != null) {
        tabPane.putClientProperty("html", v);
    }
    SwingUtilities.layoutCompoundLabel(tabPane, metrics, title, icon, SwingUtilities.CENTER, // left align title on LEFT/RIGHT placed tab
    tabPlacement == RIGHT || tabPlacement == LEFT ? SwingUtilities.LEFT : SwingUtilities.CENTER, SwingUtilities.CENTER, SwingUtilities.TRAILING, 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;
//super.layoutLabel(tabPlacement, _metrics, tabIndex, title, icon, tabRect, iconRect, textRect, isSelected);
}
Also used : 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