diff options
author | Mark Wielaard <mark@gcc.gnu.org> | 2006-03-10 21:46:48 +0000 |
---|---|---|
committer | Mark Wielaard <mark@gcc.gnu.org> | 2006-03-10 21:46:48 +0000 |
commit | 8aa540d2f783474d1d2e06f16744bf67b9c1facc (patch) | |
tree | ea38c56431c5d4528fb54254c3f8e50f517bede3 /libjava/classpath/javax/swing/text/GlyphView.java | |
parent | 27079765d00123f8e53d0e1ef7f9d46559266e6d (diff) | |
download | gcc-8aa540d2f783474d1d2e06f16744bf67b9c1facc.zip gcc-8aa540d2f783474d1d2e06f16744bf67b9c1facc.tar.gz gcc-8aa540d2f783474d1d2e06f16744bf67b9c1facc.tar.bz2 |
Imported GNU Classpath 0.90
Imported GNU Classpath 0.90
* scripts/makemake.tcl: Set gnu/java/awt/peer/swing to ignore.
* gnu/classpath/jdwp/VMFrame.java (SIZE): New constant.
* java/lang/VMCompiler.java: Use gnu.java.security.hash.MD5.
* java/lang/Math.java: New override file.
* java/lang/Character.java: Merged from Classpath.
(start, end): Now 'int's.
(canonicalName): New field.
(CANONICAL_NAME, NO_SPACES_NAME, CONSTANT_NAME): New constants.
(UnicodeBlock): Added argument.
(of): New overload.
(forName): New method.
Updated unicode blocks.
(sets): Updated.
* sources.am: Regenerated.
* Makefile.in: Likewise.
From-SVN: r111942
Diffstat (limited to 'libjava/classpath/javax/swing/text/GlyphView.java')
-rw-r--r-- | libjava/classpath/javax/swing/text/GlyphView.java | 126 |
1 files changed, 72 insertions, 54 deletions
diff --git a/libjava/classpath/javax/swing/text/GlyphView.java b/libjava/classpath/javax/swing/text/GlyphView.java index 47deb50..d505274 100644 --- a/libjava/classpath/javax/swing/text/GlyphView.java +++ b/libjava/classpath/javax/swing/text/GlyphView.java @@ -277,38 +277,41 @@ public class GlyphView extends View implements TabableView, Cloneable 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()) + if (view.isStrikeThrough()) { int strikeHeight = (int) (getAscent(view) / 2); g.drawLine(bounds.x, bounds.y + strikeHeight, bounds.height + width, @@ -320,6 +323,7 @@ public class GlyphView extends View implements TabableView, Cloneable g.drawLine(bounds.x, bounds.y + lineHeight, bounds.height + width, bounds.y + lineHeight); } + g.setColor(oldColor); } /** @@ -470,12 +474,12 @@ public class GlyphView extends View implements TabableView, Cloneable /** * The start offset within the document for this view. */ - int startOffset; + private int startOffset; /** * The end offset within the document for this view. */ - int endOffset; + private int endOffset; /** * Creates a new <code>GlyphView</code> for the given <code>Element</code>. @@ -485,8 +489,8 @@ public class GlyphView extends View implements TabableView, Cloneable public GlyphView(Element element) { super(element); - startOffset = element.getStartOffset(); - endOffset = element.getEndOffset(); + startOffset = -1; + endOffset = -1; } /** @@ -534,8 +538,7 @@ public class GlyphView extends View implements TabableView, Cloneable { Element el = getElement(); checkPainter(); - getGlyphPainter().paint(this, g, a, el.getStartOffset(), - el.getEndOffset()); + getGlyphPainter().paint(this, g, a, getStartOffset(), getEndOffset()); } @@ -563,7 +566,8 @@ public class GlyphView extends View implements TabableView, Cloneable tabEx, 0.F); } else - span = painter.getHeight(this); + span = painter.getHeight(this); + return span; } @@ -682,7 +686,10 @@ public class GlyphView extends View implements TabableView, Cloneable */ public int getStartOffset() { - return startOffset; + int start = startOffset; + if (start < 0) + start = super.getStartOffset(); + return start; } /** @@ -694,7 +701,10 @@ public class GlyphView extends View implements TabableView, Cloneable */ public int getEndOffset() { - return endOffset; + int end = endOffset; + if (end < 0) + end = super.getEndOffset(); + return end; } /** @@ -771,7 +781,11 @@ public class GlyphView extends View implements TabableView, Cloneable { 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); } /** @@ -782,7 +796,7 @@ public class GlyphView extends View implements TabableView, Cloneable * * @return whether the text should be rendered strike-through or not */ - public boolean isStikeThrough() + public boolean isStrikeThrough() { Element el = getElement(); AttributeSet atts = el.getAttributes(); @@ -876,13 +890,15 @@ public class GlyphView extends View implements TabableView, Cloneable checkPainter(); GlyphPainter painter = getGlyphPainter(); - int breakLocation = painter.getBoundedPosition(this, p0, pos, len); + // Try to find a suitable line break. BreakIterator lineBreaker = BreakIterator.getLineInstance(); Segment txt = new Segment(); try { - getDocument().getText(getStartOffset(), getEndOffset(), txt); + int start = getStartOffset(); + int length = getEndOffset() - start; + getDocument().getText(start, length, txt); } catch (BadLocationException ex) { @@ -891,11 +907,10 @@ public class GlyphView extends View implements TabableView, Cloneable err.initCause(ex); throw err; } - lineBreaker.setText(txt); - int goodBreakLocation = lineBreaker.previous(); - if (goodBreakLocation != BreakIterator.DONE) - breakLocation = goodBreakLocation; - + int breakLocation = + Utilities.getBreakLocation(txt, getContainer().getFontMetrics(getFont()), + (int) pos, (int) (pos + len), + getTabExpander(), p0); View brokenView = createFragment(p0, breakLocation); return brokenView; } @@ -922,23 +937,24 @@ public class GlyphView extends View implements TabableView, Cloneable weight = super.getBreakWeight(axis, pos, len); else { - // Determine the model locations at pos and pos + len. - int spanX = (int) getPreferredSpan(X_AXIS); - int spanY = (int) getPreferredSpan(Y_AXIS); - Rectangle dummyAlloc = new Rectangle(0, 0, spanX, spanY); - Position.Bias[] biasRet = new Position.Bias[1]; - int offset1 = viewToModel(pos, spanY / 2, dummyAlloc, biasRet); - int offset2 = viewToModel(pos, spanY / 2, dummyAlloc, biasRet); - Segment txt = getText(offset1, offset2); - BreakIterator lineBreaker = BreakIterator.getLineInstance(); - lineBreaker.setText(txt); - int breakLoc = lineBreaker.previous(); - if (breakLoc == offset1) - weight = View.BadBreakWeight; - else if(breakLoc == BreakIterator.DONE) - weight = View.GoodBreakWeight; - else - weight = View.ExcellentBreakWeight; + // FIXME: Commented out because the Utilities.getBreakLocation method + // is still buggy. The GoodBreakWeight is a reasonable workaround for + // now. +// int startOffset = getStartOffset(); +// int endOffset = getEndOffset() - 1; +// Segment s = getText(startOffset, endOffset); +// Container c = getContainer(); +// FontMetrics fm = c.getFontMetrics(c.getFont()); +// int x0 = (int) pos; +// int x = (int) (pos + len); +// int breakLoc = Utilities.getBreakLocation(s, fm, x0, x, +// getTabExpander(), +// startOffset); +// if (breakLoc == startOffset || breakLoc == endOffset) +// weight = GoodBreakWeight; +// else +// weight = ExcellentBreakWeight; + weight = GoodBreakWeight; } return weight; } @@ -955,14 +971,14 @@ public class GlyphView extends View implements TabableView, Cloneable */ public void changedUpdate(DocumentEvent e, Shape a, ViewFactory vf) { - getParent().preferenceChanged(this, true, true); + preferenceChanged(this, true, true); } /** * Receives notification that some text has been inserted within the * text fragment that this view is responsible for. This calls - * {@link View#preferenceChanged(View, boolean, boolean)} on the parent for - * width. + * {@link View#preferenceChanged(View, boolean, boolean)} for the + * direction in which the glyphs are rendered. * * @param e the document event describing the change; not used here * @param a the view allocation on screen; not used here @@ -970,7 +986,7 @@ public class GlyphView extends View implements TabableView, Cloneable */ public void insertUpdate(DocumentEvent e, Shape a, ViewFactory vf) { - getParent().preferenceChanged(this, true, false); + preferenceChanged(this, true, false); } /** @@ -985,7 +1001,7 @@ public class GlyphView extends View implements TabableView, Cloneable */ public void removeUpdate(DocumentEvent e, Shape a, ViewFactory vf) { - getParent().preferenceChanged(this, true, false); + preferenceChanged(this, true, false); } /** @@ -1000,8 +1016,10 @@ public class GlyphView extends View implements TabableView, Cloneable public View createFragment(int p0, int p1) { GlyphView fragment = (GlyphView) clone(); - fragment.startOffset = p0; - fragment.endOffset = p1; + if (p0 != getStartOffset()) + fragment.startOffset = p0; + if (p1 != getEndOffset()) + fragment.endOffset = p1; return fragment; } |