Search in sources :

Example 16 with UIResource

use of javax.swing.plaf.UIResource in project jdk8u_jdk by JetBrains.

the class SynthStyle method installDefaults.

void installDefaults(SynthContext context, SynthUI ui) {
    // can have more control over this.
    if (!context.isSubregion()) {
        JComponent c = context.getComponent();
        Border border = c.getBorder();
        if (border == null || border instanceof UIResource) {
            c.setBorder(new SynthBorder(ui, getInsets(context, null)));
        }
    }
    installDefaults(context);
}
Also used : Border(javax.swing.border.Border) UIResource(javax.swing.plaf.UIResource)

Example 17 with UIResource

use of javax.swing.plaf.UIResource in project jdk8u_jdk by JetBrains.

the class AquaButtonLabeledUI method setThemeBorder.

protected void setThemeBorder(final AbstractButton b) {
    super.setThemeBorder(b);
    Border border = b.getBorder();
    if (border == null || border instanceof UIResource) {
        // Set the correct border
        b.setBorder(AquaButtonBorder.getBevelButtonBorder());
    }
}
Also used : Border(javax.swing.border.Border) UIResource(javax.swing.plaf.UIResource)

Example 18 with UIResource

use of javax.swing.plaf.UIResource in project android by JetBrains.

the class SimpleTabUI method paintText.

// Appears to be based on http://stackoverflow.com/questions/7903657/basictabbedpaneui-paint-html-text
@Override
protected void paintText(Graphics g, int tabPlacement, Font font, FontMetrics metrics, int tabIndex, String title, Rectangle textRect, boolean isSelected) {
    g.setFont(font);
    View v = getTextViewForTab(tabIndex);
    if (v != null) {
        // html
        v.paint(g, textRect);
    } else {
        // plain text
        int mnemIndex = tabPane.getDisplayedMnemonicIndexAt(tabIndex);
        if (tabPane.isEnabled() && tabPane.isEnabledAt(tabIndex)) {
            Color fg = tabPane.getForegroundAt(tabIndex);
            if (isSelected && (fg instanceof UIResource)) {
                // CHANGE FROM DEFAULT
                Color selectedFG = JBColor.BLUE;
                if (selectedFG != null) {
                    fg = selectedFG;
                }
            }
            g.setColor(fg);
            SwingUtilities2.drawStringUnderlineCharAt(tabPane, g, title, mnemIndex, textRect.x, textRect.y + metrics.getAscent());
        } else {
            // tab disabled
            g.setColor(tabPane.getBackgroundAt(tabIndex).brighter());
            SwingUtilities2.drawStringUnderlineCharAt(tabPane, g, title, mnemIndex, textRect.x, textRect.y + metrics.getAscent());
            g.setColor(tabPane.getBackgroundAt(tabIndex).darker());
            SwingUtilities2.drawStringUnderlineCharAt(tabPane, g, title, mnemIndex, textRect.x - 1, textRect.y + metrics.getAscent() - 1);
        }
    }
}
Also used : JBColor(com.intellij.ui.JBColor) View(javax.swing.text.View) UIResource(javax.swing.plaf.UIResource)

Example 19 with UIResource

use of javax.swing.plaf.UIResource in project jdk8u_jdk by JetBrains.

the class SynthStyle method uninstallDefaults.

/**
     * Uninstalls any state that this style installed on
     * the <code>JComponent</code> from <code>context</code>.
     * <p>
     * Styles should NOT depend upon this being called, in certain cases
     * it may never be called.
     *
     * @param context SynthContext identifying component to install properties
     *        to.
     */
public void uninstallDefaults(SynthContext context) {
    if (!context.isSubregion()) {
        // NOTE: because getForeground, getBackground and getFont will look
        // at the parent Container, if we set them to null it may
        // mean we they return a non-null and non-UIResource value
        // preventing install from correctly settings its colors/font. For
        // this reason we do not uninstall the fg/bg/font.
        JComponent c = context.getComponent();
        Border border = c.getBorder();
        if (border instanceof UIResource) {
            c.setBorder(null);
        }
    }
}
Also used : Border(javax.swing.border.Border) UIResource(javax.swing.plaf.UIResource)

Example 20 with UIResource

use of javax.swing.plaf.UIResource in project jdk8u_jdk by JetBrains.

the class SynthStyle method getColor.

/**
     * Returns the color for the specified state. This gives precedence to
     * foreground and background of the <code>JComponent</code>. If the
     * <code>Color</code> from the <code>JComponent</code> is not appropriate,
     * or not used, this will invoke <code>getColorForState</code>. Subclasses
     * should generally not have to override this, instead override
     * {@link #getColorForState}.
     *
     * @param context SynthContext identifying requester
     * @param type Type of color being requested.
     * @return Color
     */
public Color getColor(SynthContext context, ColorType type) {
    JComponent c = context.getComponent();
    Region id = context.getRegion();
    if ((context.getComponentState() & SynthConstants.DISABLED) != 0) {
        //text when the label is disabled. This code allows for that.
        if (c instanceof JTextComponent) {
            JTextComponent txt = (JTextComponent) c;
            Color disabledColor = txt.getDisabledTextColor();
            if (disabledColor == null || disabledColor instanceof UIResource) {
                return getColorForState(context, type);
            }
        } else if (c instanceof JLabel && (type == ColorType.FOREGROUND || type == ColorType.TEXT_FOREGROUND)) {
            return getColorForState(context, type);
        }
    }
    // If the developer has specified a color, prefer it. Otherwise, get
    // the color for the state.
    Color color = null;
    if (!id.isSubregion()) {
        if (type == ColorType.BACKGROUND) {
            color = c.getBackground();
        } else if (type == ColorType.FOREGROUND) {
            color = c.getForeground();
        } else if (type == ColorType.TEXT_FOREGROUND) {
            color = c.getForeground();
        }
    }
    if (color == null || color instanceof UIResource) {
        // Then use what we've locally defined
        color = getColorForState(context, type);
    }
    if (color == null) {
        // No color, fallback to that of the widget.
        if (type == ColorType.BACKGROUND || type == ColorType.TEXT_BACKGROUND) {
            return c.getBackground();
        } else if (type == ColorType.FOREGROUND || type == ColorType.TEXT_FOREGROUND) {
            return c.getForeground();
        }
    }
    return color;
}
Also used : JTextComponent(javax.swing.text.JTextComponent) UIResource(javax.swing.plaf.UIResource)

Aggregations

UIResource (javax.swing.plaf.UIResource)33 Border (javax.swing.border.Border)16 FocusEvent (java.awt.event.FocusEvent)6 FocusListener (java.awt.event.FocusListener)6 EmptyBorder (javax.swing.border.EmptyBorder)4 View (javax.swing.text.View)4 JBColor (com.intellij.ui.JBColor)3 Color (java.awt.Color)3 ColorUIResource (javax.swing.plaf.ColorUIResource)3 Area (java.awt.geom.Area)2 FontUIResource (javax.swing.plaf.FontUIResource)2 JTextComponent (javax.swing.text.JTextComponent)2 JRSUIState (apple.laf.JRSUIState)1 DumbAwareAction (com.intellij.openapi.project.DumbAwareAction)1 GraphicsConfig (com.intellij.openapi.ui.GraphicsConfig)1 RelativePoint (com.intellij.ui.awt.RelativePoint)1 Component (java.awt.Component)1 Dimension (java.awt.Dimension)1 Insets (java.awt.Insets)1 StringSelection (java.awt.datatransfer.StringSelection)1