下面列出了javax.swing.text.JTextComponent#getDisabledTextColor ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@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);
}
/**
* 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);
}
/**
* 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;
}
/**
* 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;
}
/**
* 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;
}
/**
* 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;
}
/**
* 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;
}
/**
* 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;
}
/**
* 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;
}
/**
* 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;
}
/**
* 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;
}
/**
* 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;
}
/**
* 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;
}
/**
* 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;
}
/**
* 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;
}
/**
* 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;
}
/**
* 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;
}
/**
* 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;
}
/**
* 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;
}