From 80ab33b62e554badc83bfdd60110bf0def31eb2c Mon Sep 17 00:00:00 2001 From: shaper Date: Fri, 15 Mar 2002 17:34:48 +0000 Subject: [PATCH] Added setTextColor() to allow specifying a color in which the label text is to be rendered. git-svn-id: https://samskivert.googlecode.com/svn/trunk@653 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- .../src/java/com/samskivert/swing/Label.java | 27 ++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/projects/samskivert/src/java/com/samskivert/swing/Label.java b/projects/samskivert/src/java/com/samskivert/swing/Label.java index 9249c659..5335f9a5 100644 --- a/projects/samskivert/src/java/com/samskivert/swing/Label.java +++ b/projects/samskivert/src/java/com/samskivert/swing/Label.java @@ -1,5 +1,5 @@ // -// $Id: Label.java,v 1.6 2002/03/11 22:07:00 shaper Exp $ +// $Id: Label.java,v 1.7 2002/03/15 17:34:48 shaper Exp $ package com.samskivert.swing; @@ -82,6 +82,16 @@ public class Label implements SwingConstants _font = font; } + /** + * Sets the color used to render the text. Setting the text color to + * null will render the label in the graphics context + * color (which is the default). + */ + public void setTextColor (Color color) + { + _textColor = color; + } + /** * Instructs the label to render the text outlined in the specified * color when rendering. The text itself will be rendered in whatever @@ -240,6 +250,11 @@ public class Label implements SwingConstants return; } + Color old = gfx.getColor(); + if (_textColor != null) { + gfx.setColor(_textColor); + } + // render our text for (int i = 0; i < _layouts.length; i++) { TextLayout layout = _layouts[i]; @@ -257,13 +272,13 @@ public class Label implements SwingConstants // render the outline using the hacky, but much nicer than // using "real" outlines (via TextLayout.getOutline), method if (_outlineColor != null) { - Color old = gfx.getColor(); + Color textColor = gfx.getColor(); gfx.setColor(_outlineColor); layout.draw(gfx, x + dx - 1, y - 1); layout.draw(gfx, x + dx - 1, y + 1); layout.draw(gfx, x + dx + 1, y + 1); layout.draw(gfx, x + dx + 1, y - 1); - gfx.setColor(old); + gfx.setColor(textColor); } // and draw the text itself @@ -271,6 +286,8 @@ public class Label implements SwingConstants y += layout.getDescent() + layout.getLeading(); } + + gfx.setColor(old); } /** @@ -318,4 +335,8 @@ public class Label implements SwingConstants /** The color in which to outline the text when rendering or null if * the text should not be outlined. */ protected Color _outlineColor = null; + + /** The color in which to render the text or null if the text should + * be rendered with the graphics context color. */ + protected Color _textColor = null; }