Allow some styles to be combined (UNDERLINE can be composed with any other
style). git-svn-id: https://samskivert.googlecode.com/svn/trunk@1309 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: Label.java,v 1.32 2003/11/15 02:06:16 mdb Exp $
|
// $Id: Label.java,v 1.33 2003/11/15 02:14:01 mdb Exp $
|
||||||
//
|
//
|
||||||
// samskivert library - useful routines for java programs
|
// samskivert library - useful routines for java programs
|
||||||
// Copyright (C) 2002 Michael Bayne
|
// Copyright (C) 2002 Michael Bayne
|
||||||
@@ -180,7 +180,8 @@ public class Label implements SwingConstants, LabelStyleConstants
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the style of the text within the label to one of the styles
|
* Sets the style of the text within the label to one of the styles
|
||||||
* defined in {@link LabelStyleConstants}.
|
* defined in {@link LabelStyleConstants}. Some styles can be combined
|
||||||
|
* together into a mask, ie. <code>BOLD|UNDERLINE</code>.
|
||||||
*/
|
*/
|
||||||
public void setStyle (int style)
|
public void setStyle (int style)
|
||||||
{
|
{
|
||||||
@@ -452,11 +453,12 @@ public class Label implements SwingConstants, LabelStyleConstants
|
|||||||
// " lwidth: " + getWidth(lbounds) +
|
// " lwidth: " + getWidth(lbounds) +
|
||||||
// " extra: " + extra);
|
// " extra: " + extra);
|
||||||
|
|
||||||
switch (_style) {
|
Color textColor;
|
||||||
case OUTLINE:
|
|
||||||
|
if ((_style & OUTLINE) != 0) {
|
||||||
// render the outline using the hacky, but much nicer than
|
// render the outline using the hacky, but much nicer than
|
||||||
// using "real" outlines (via TextLayout.getOutline), method
|
// using "real" outlines (via TextLayout.getOutline), method
|
||||||
Color textColor = gfx.getColor();
|
textColor = gfx.getColor();
|
||||||
gfx.setColor(_alternateColor);
|
gfx.setColor(_alternateColor);
|
||||||
layout.draw(gfx, rx, y);
|
layout.draw(gfx, rx, y);
|
||||||
layout.draw(gfx, rx, y + 1);
|
layout.draw(gfx, rx, y + 1);
|
||||||
@@ -468,24 +470,20 @@ public class Label implements SwingConstants, LabelStyleConstants
|
|||||||
layout.draw(gfx, rx + 2, y + 2);
|
layout.draw(gfx, rx + 2, y + 2);
|
||||||
gfx.setColor(textColor);
|
gfx.setColor(textColor);
|
||||||
layout.draw(gfx, rx + 1, y + 1);
|
layout.draw(gfx, rx + 1, y + 1);
|
||||||
break;
|
|
||||||
|
|
||||||
case SHADOW:
|
} else if ((_style & SHADOW) != 0) {
|
||||||
textColor = gfx.getColor();
|
textColor = gfx.getColor();
|
||||||
gfx.setColor(_alternateColor);
|
gfx.setColor(_alternateColor);
|
||||||
layout.draw(gfx, rx, y + 1);
|
layout.draw(gfx, rx, y + 1);
|
||||||
gfx.setColor(textColor);
|
gfx.setColor(textColor);
|
||||||
layout.draw(gfx, rx + 1, y);
|
layout.draw(gfx, rx + 1, y);
|
||||||
break;
|
|
||||||
|
|
||||||
case BOLD:
|
} else if ((_style & BOLD) != 0) {
|
||||||
layout.draw(gfx, rx, y);
|
layout.draw(gfx, rx, y);
|
||||||
layout.draw(gfx, rx + 1, y);
|
layout.draw(gfx, rx + 1, y);
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
} else {
|
||||||
layout.draw(gfx, rx, y);
|
layout.draw(gfx, rx, y);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
y += layout.getDescent() + layout.getLeading();
|
y += layout.getDescent() + layout.getLeading();
|
||||||
@@ -503,7 +501,7 @@ public class Label implements SwingConstants, LabelStyleConstants
|
|||||||
Font font = (_font == null) ? gfx.getFont() : _font;
|
Font font = (_font == null) ? gfx.getFont() : _font;
|
||||||
HashMap map = new HashMap();
|
HashMap map = new HashMap();
|
||||||
map.put(TextAttribute.FONT, font);
|
map.put(TextAttribute.FONT, font);
|
||||||
if (_style == UNDERLINE) {
|
if ((_style & UNDERLINE) != 0) {
|
||||||
map.put(TextAttribute.UNDERLINE,
|
map.put(TextAttribute.UNDERLINE,
|
||||||
TextAttribute.UNDERLINE_LOW_ONE_PIXEL);
|
TextAttribute.UNDERLINE_LOW_ONE_PIXEL);
|
||||||
}
|
}
|
||||||
@@ -518,10 +516,12 @@ public class Label implements SwingConstants, LabelStyleConstants
|
|||||||
protected double getWidth (Rectangle2D laybounds)
|
protected double getWidth (Rectangle2D laybounds)
|
||||||
{
|
{
|
||||||
double width = laybounds.getX() + laybounds.getWidth();
|
double width = laybounds.getX() + laybounds.getWidth();
|
||||||
switch (_style) {
|
if ((_style & OUTLINE) != 0) {
|
||||||
case OUTLINE: width += 2; break;
|
width += 2;
|
||||||
case SHADOW: width += 1; break;
|
} else if ((_style & SHADOW) != 0) {
|
||||||
case BOLD: width += 1; break;
|
width += 1;
|
||||||
|
} else if ((_style & BOLD) != 0) {
|
||||||
|
width += 1;
|
||||||
}
|
}
|
||||||
return width;
|
return width;
|
||||||
}
|
}
|
||||||
@@ -535,9 +535,10 @@ public class Label implements SwingConstants, LabelStyleConstants
|
|||||||
{
|
{
|
||||||
float height = layout.getLeading() + layout.getAscent() +
|
float height = layout.getLeading() + layout.getAscent() +
|
||||||
layout.getDescent();
|
layout.getDescent();
|
||||||
switch (_style) {
|
if ((_style & OUTLINE) != 0) {
|
||||||
case OUTLINE: height += 2; break;
|
height += 2;
|
||||||
case SHADOW: height += 1; break;
|
} else if ((_style & SHADOW) != 0) {
|
||||||
|
height += 1;
|
||||||
}
|
}
|
||||||
return height;
|
return height;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: LabelStyleConstants.java,v 1.2 2003/11/15 02:06:16 mdb Exp $
|
// $Id: LabelStyleConstants.java,v 1.3 2003/11/15 02:14:01 mdb Exp $
|
||||||
//
|
//
|
||||||
// samskivert library - useful routines for java programs
|
// samskivert library - useful routines for java programs
|
||||||
// Copyright (C) 2002 Walter Korman
|
// Copyright (C) 2002 Walter Korman
|
||||||
@@ -30,14 +30,14 @@ public interface LabelStyleConstants
|
|||||||
public static final int NORMAL = 0;
|
public static final int NORMAL = 0;
|
||||||
|
|
||||||
/** Constant denoting bold text style. */
|
/** Constant denoting bold text style. */
|
||||||
public static final int BOLD = 1;
|
public static final int BOLD = 0x1 << 1;
|
||||||
|
|
||||||
/** Constant denoting outline text style. */
|
/** Constant denoting outline text style. */
|
||||||
public static final int OUTLINE = 2;
|
public static final int OUTLINE = 0x1 << 2;
|
||||||
|
|
||||||
/** Constant denoting shadow text style. */
|
/** Constant denoting shadow text style. */
|
||||||
public static final int SHADOW = 3;
|
public static final int SHADOW = 0x1 << 3;
|
||||||
|
|
||||||
/** Constant denoting underlined text style. */
|
/** Constant denoting underline text style. */
|
||||||
public static final int UNDERLINE = 4;
|
public static final int UNDERLINE = 0x1 << 4;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user