javax.swing.text.JTextComponent#getDisabledTextColor ( )源码实例Demo

下面列出了javax.swing.text.JTextComponent#getDisabledTextColor ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: netbeans   文件: OutputView.java
@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);
}
 
源代码2 项目: SwingBox   文件: TextBoxView.java
/**
 * 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);

}
 
源代码3 项目: jdk1.8-source-analysis   文件: SynthStyle.java
/**
 * 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;
}
 
源代码4 项目: dragonwell8_jdk   文件: SynthStyle.java
/**
 * 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;
}
 
源代码5 项目: TencentKona-8   文件: SynthStyle.java
/**
 * 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;
}
 
源代码6 项目: jdk8u60   文件: SynthStyle.java
/**
 * 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;
}
 
源代码7 项目: JDKSourceCode1.8   文件: SynthStyle.java
/**
 * 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;
}
 
源代码8 项目: openjdk-jdk8u   文件: SynthStyle.java
/**
 * 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;
}
 
源代码9 项目: openjdk-jdk8u-backup   文件: SynthStyle.java
/**
 * 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;
}
 
源代码10 项目: Bytecoder   文件: SynthStyle.java
/**
 * 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;
}
 
源代码11 项目: openjdk-jdk9   文件: SynthStyle.java
/**
 * 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;
}
 
源代码12 项目: jdk8u-jdk   文件: SynthStyle.java
/**
 * 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;
}
 
源代码13 项目: Java8CN   文件: SynthStyle.java
/**
 * 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;
}
 
源代码14 项目: hottub   文件: SynthStyle.java
/**
 * 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;
}
 
源代码15 项目: openjdk-8-source   文件: SynthStyle.java
/**
 * 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;
}
 
源代码16 项目: openjdk-8   文件: SynthStyle.java
/**
 * 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;
}
 
源代码17 项目: jdk8u_jdk   文件: SynthStyle.java
/**
 * 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;
}
 
源代码18 项目: jdk8u-jdk   文件: SynthStyle.java
/**
 * 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;
}
 
源代码19 项目: jdk8u-dev-jdk   文件: SynthStyle.java
/**
 * 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;
}