Java Code Examples for javax.swing.text.JTextComponent#getDisabledTextColor()

The following examples show how to use javax.swing.text.JTextComponent#getDisabledTextColor() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OutputView.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public void paint(Graphics g, Shape a) {
    ((Graphics2D) g).addRenderingHints(getHints());

    Container container = getContainer();
    if (container instanceof JTextComponent) {
        final JTextComponent textComp = (JTextComponent) container;
        selStart = textComp.getSelectionStart();
        selEnd = textComp.getSelectionEnd();
        unselectedFg = textComp.isEnabled()
                ? textComp.getForeground()
                : textComp.getDisabledTextColor();
        selectedFg = textComp.getCaret().isSelectionVisible()
                ? textComp.getSelectedTextColor()
                : unselectedFg;
    }
    super.paint(g, a);
}
 
Example 2
Source File: TextBoxView.java    From SwingBox with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Process paint.
 * 
 * @param gg
 *            the graphics context
 * @param a
 *            the allocation
 */
protected void processPaint(Graphics gg, Shape a)
{
    Graphics2D g = (Graphics2D) gg;
    AffineTransform tmpTransform = g.getTransform();
    if (!tmpTransform.equals(transform))
    {
        transform = tmpTransform;
        invalidateTextLayout();
    }

    Component c = container;
    int p0 = getStartOffset();
    int p1 = getEndOffset();
    Color fg = getForeground();

    if (c instanceof JTextComponent)
    {
        JTextComponent tc = (JTextComponent) c;
        if (!tc.isEnabled())
        {
            fg = tc.getDisabledTextColor();
        }

        // javax.swing.plaf.basic.BasicTextUI $ BasicHighlighter
        // >> DefaultHighlighter
        // >> DefaultHighlightPainter

        Highlighter highLighter = tc.getHighlighter();
        if (highLighter instanceof LayeredHighlighter)
        {
            ((LayeredHighlighter) highLighter).paintLayeredHighlights(g, p0, p1, box.getAbsoluteContentBounds(), tc, this);
            // (g, p0, p1, a, tc, this);
        }
    }
    // nothing is selected
    if (!box.isEmpty() && !getText().isEmpty())
        renderContent(g, a, fg, p0, p1);

}
 
Example 3
Source File: SynthStyle.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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) {
        //This component is disabled, so return the disabled color.
        //In some cases this means ignoring the color specified by the
        //developer on the component. In other cases it means using a
        //specified disabledTextColor, such as on JTextComponents.
        //For example, JLabel doesn't specify a disabled color that the
        //developer can set, yet it should have a disabled color to the
        //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 || c instanceof JMenuItem) &&
                        (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;
}
 
Example 4
Source File: SynthStyle.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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) {
        //This component is disabled, so return the disabled color.
        //In some cases this means ignoring the color specified by the
        //developer on the component. In other cases it means using a
        //specified disabledTextColor, such as on JTextComponents.
        //For example, JLabel doesn't specify a disabled color that the
        //developer can set, yet it should have a disabled color to the
        //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;
}
 
Example 5
Source File: SynthStyle.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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) {
        //This component is disabled, so return the disabled color.
        //In some cases this means ignoring the color specified by the
        //developer on the component. In other cases it means using a
        //specified disabledTextColor, such as on JTextComponents.
        //For example, JLabel doesn't specify a disabled color that the
        //developer can set, yet it should have a disabled color to the
        //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;
}
 
Example 6
Source File: SynthStyle.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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) {
        //This component is disabled, so return the disabled color.
        //In some cases this means ignoring the color specified by the
        //developer on the component. In other cases it means using a
        //specified disabledTextColor, such as on JTextComponents.
        //For example, JLabel doesn't specify a disabled color that the
        //developer can set, yet it should have a disabled color to the
        //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;
}
 
Example 7
Source File: SynthStyle.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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) {
        //This component is disabled, so return the disabled color.
        //In some cases this means ignoring the color specified by the
        //developer on the component. In other cases it means using a
        //specified disabledTextColor, such as on JTextComponents.
        //For example, JLabel doesn't specify a disabled color that the
        //developer can set, yet it should have a disabled color to the
        //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;
}
 
Example 8
Source File: SynthStyle.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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) {
        //This component is disabled, so return the disabled color.
        //In some cases this means ignoring the color specified by the
        //developer on the component. In other cases it means using a
        //specified disabledTextColor, such as on JTextComponents.
        //For example, JLabel doesn't specify a disabled color that the
        //developer can set, yet it should have a disabled color to the
        //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;
}
 
Example 9
Source File: SynthStyle.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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) {
        //This component is disabled, so return the disabled color.
        //In some cases this means ignoring the color specified by the
        //developer on the component. In other cases it means using a
        //specified disabledTextColor, such as on JTextComponents.
        //For example, JLabel doesn't specify a disabled color that the
        //developer can set, yet it should have a disabled color to the
        //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;
}
 
Example 10
Source File: SynthStyle.java    From Java8CN with Apache License 2.0 4 votes vote down vote up
/**
 * 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) {
        //This component is disabled, so return the disabled color.
        //In some cases this means ignoring the color specified by the
        //developer on the component. In other cases it means using a
        //specified disabledTextColor, such as on JTextComponents.
        //For example, JLabel doesn't specify a disabled color that the
        //developer can set, yet it should have a disabled color to the
        //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;
}
 
Example 11
Source File: SynthStyle.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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) {
        //This component is disabled, so return the disabled color.
        //In some cases this means ignoring the color specified by the
        //developer on the component. In other cases it means using a
        //specified disabledTextColor, such as on JTextComponents.
        //For example, JLabel doesn't specify a disabled color that the
        //developer can set, yet it should have a disabled color to the
        //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;
}
 
Example 12
Source File: SynthStyle.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
/**
 * 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) {
        //This component is disabled, so return the disabled color.
        //In some cases this means ignoring the color specified by the
        //developer on the component. In other cases it means using a
        //specified disabledTextColor, such as on JTextComponents.
        //For example, JLabel doesn't specify a disabled color that the
        //developer can set, yet it should have a disabled color to the
        //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;
}
 
Example 13
Source File: SynthStyle.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
/**
 * 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) {
        //This component is disabled, so return the disabled color.
        //In some cases this means ignoring the color specified by the
        //developer on the component. In other cases it means using a
        //specified disabledTextColor, such as on JTextComponents.
        //For example, JLabel doesn't specify a disabled color that the
        //developer can set, yet it should have a disabled color to the
        //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 || c instanceof JMenuItem) &&
                        (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;
}
 
Example 14
Source File: SynthStyle.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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) {
        //This component is disabled, so return the disabled color.
        //In some cases this means ignoring the color specified by the
        //developer on the component. In other cases it means using a
        //specified disabledTextColor, such as on JTextComponents.
        //For example, JLabel doesn't specify a disabled color that the
        //developer can set, yet it should have a disabled color to the
        //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;
}
 
Example 15
Source File: SynthStyle.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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) {
        //This component is disabled, so return the disabled color.
        //In some cases this means ignoring the color specified by the
        //developer on the component. In other cases it means using a
        //specified disabledTextColor, such as on JTextComponents.
        //For example, JLabel doesn't specify a disabled color that the
        //developer can set, yet it should have a disabled color to the
        //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;
}
 
Example 16
Source File: SynthStyle.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
/**
 * 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) {
        //This component is disabled, so return the disabled color.
        //In some cases this means ignoring the color specified by the
        //developer on the component. In other cases it means using a
        //specified disabledTextColor, such as on JTextComponents.
        //For example, JLabel doesn't specify a disabled color that the
        //developer can set, yet it should have a disabled color to the
        //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;
}
 
Example 17
Source File: SynthStyle.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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) {
        //This component is disabled, so return the disabled color.
        //In some cases this means ignoring the color specified by the
        //developer on the component. In other cases it means using a
        //specified disabledTextColor, such as on JTextComponents.
        //For example, JLabel doesn't specify a disabled color that the
        //developer can set, yet it should have a disabled color to the
        //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;
}
 
Example 18
Source File: SynthStyle.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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) {
        //This component is disabled, so return the disabled color.
        //In some cases this means ignoring the color specified by the
        //developer on the component. In other cases it means using a
        //specified disabledTextColor, such as on JTextComponents.
        //For example, JLabel doesn't specify a disabled color that the
        //developer can set, yet it should have a disabled color to the
        //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;
}
 
Example 19
Source File: SynthStyle.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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) {
        //This component is disabled, so return the disabled color.
        //In some cases this means ignoring the color specified by the
        //developer on the component. In other cases it means using a
        //specified disabledTextColor, such as on JTextComponents.
        //For example, JLabel doesn't specify a disabled color that the
        //developer can set, yet it should have a disabled color to the
        //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;
}