The attached patch makes the BeanShell JConsole work quite well (ok, slow
and ugly, but anyway ;-) ). Thanks to Lillian and Anthony for making
this possible with their work on DefaultStyledDocument.
2006-02-06 Roman Kennke <[EMAIL PROTECTED]>
* javax/swing/text/GlyphView.java:
(DefaultGlyphPainter.paint): Store/restore Graphics color setting.
Only fill background if there is a background set on the view.
Call Utilities.drawTabbedText with the baseline height, rather
than
the upper left corner of the view rectangle.
(getBackground): Return null if no background is set.
* javax/swing/text/GlyphView.java:
(setPropertiesFromAttributes): Use null for background when no
background is set. StyleConstants.getBackground() doesn't work
for this, because it returns Color.BLACK in that case.
/Roman
Index: javax/swing/text/GlyphView.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/text/GlyphView.java,v
retrieving revision 1.13
diff -u -r1.13 GlyphView.java
--- javax/swing/text/GlyphView.java 23 Nov 2005 14:23:14 -0000 1.13
+++ javax/swing/text/GlyphView.java 6 Feb 2006 16:32:46 -0000
@@ -277,35 +277,38 @@
public void paint(GlyphView view, Graphics g, Shape a, int p0,
int p1)
{
+ Color oldColor = g.getColor();
int height = (int) getHeight(view);
Segment txt = view.getText(p0, p1);
Rectangle bounds = a.getBounds();
-
TabExpander tabEx = null;
View parent = view.getParent();
if (parent instanceof TabExpander)
tabEx = (TabExpander) parent;
- // Fill the background of the text run.
- Color background = view.getBackground();
- g.setColor(background);
int width = Utilities.getTabbedTextWidth(txt, g.getFontMetrics(),
bounds.x, tabEx, txt.offset);
- g.fillRect(bounds.x, bounds.y, width, height);
-
+ // Fill the background of the text run.
+ Color background = view.getBackground();
+ if (background != null)
+ {
+ g.setColor(background);
+ g.fillRect(bounds.x, bounds.y, width, height);
+ }
// Draw the actual text.
g.setColor(view.getForeground());
g.setFont(view.getFont());
+ int ascent = g.getFontMetrics().getAscent();
if (view.isSuperscript())
// TODO: Adjust font for superscripting.
- Utilities.drawTabbedText(txt, bounds.x, bounds.y - height / 2, g, tabEx,
- txt.offset);
+ Utilities.drawTabbedText(txt, bounds.x, bounds.y + ascent - height / 2,
+ g, tabEx, txt.offset);
else if (view.isSubscript())
// TODO: Adjust font for subscripting.
- Utilities.drawTabbedText(txt, bounds.x, bounds.y + height / 2, g, tabEx,
- txt.offset);
+ Utilities.drawTabbedText(txt, bounds.x, bounds.y + ascent + height / 2,
+ g, tabEx, txt.offset);
else
- Utilities.drawTabbedText(txt, bounds.x, bounds.y, g, tabEx,
+ Utilities.drawTabbedText(txt, bounds.x, bounds.y + ascent, g, tabEx,
txt.offset);
if (view.isStikeThrough())
@@ -320,6 +323,7 @@
g.drawLine(bounds.x, bounds.y + lineHeight, bounds.height + width,
bounds.y + lineHeight);
}
+ g.setColor(oldColor);
}
/**
@@ -771,7 +775,11 @@
{
Element el = getElement();
AttributeSet atts = el.getAttributes();
- return StyleConstants.getBackground(atts);
+ // We cannot use StyleConstants.getBackground() here, because that returns
+ // BLACK as default (when background == null). What we need is the
+ // background setting of the text component instead, which is what we get
+ // when background == null anyway.
+ return (Color) atts.getAttribute(StyleConstants.Background);
}
/**
Index: javax/swing/text/LabelView.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/text/LabelView.java,v
retrieving revision 1.2
diff -u -r1.2 LabelView.java
--- javax/swing/text/LabelView.java 5 Oct 2005 15:03:46 -0000 1.2
+++ javax/swing/text/LabelView.java 6 Feb 2006 16:32:46 -0000
@@ -109,7 +109,11 @@
{
Element el = getElement();
AttributeSet atts = el.getAttributes();
- background = StyleConstants.getBackground(atts);
+ // We cannot use StyleConstants.getBackground() here, because that returns
+ // BLACK as default (when background == null). What we need is the
+ // background setting of the text component instead, which is what we get
+ // when background == null anyway.
+ background = (Color) atts.getAttribute(StyleConstants.Background);
foreground = StyleConstants.getForeground(atts);
strikeThrough = StyleConstants.isStrikeThrough(atts);
subscript = StyleConstants.isSubscript(atts);