This fixes up the DefaultHighlighter and adds support for layered highlights, which is a more efficient way to paint highlights.

2006-08-05  Roman Kennke  <[EMAIL PROTECTED]>

        * javax/swing/text/DefaultHighlight.java
        (DefaultHighlightPainter.paintHighlight): Removed method.
        (DefaultHighlightPainter.paintLayer): Implemented.
        (DefaultHighlightPainter.paint): Implemented more efficient
        painting for multiline-highlights.
        (HighlightEntry.p0): Changed to be a Position.
        (HighlightEntry.p1): Changed to be a Position.
        (HighlightEntry.HighlightEntry): Changed to take Position
        arfuments.
        (HighlightEntry.getStartOffset): Changed to return p0.getOffset();
        (HighlightEntry.getEndOffset): Changed to return p1.getOffset();
        (LayerHighlightEntry): New inner class. Extends HighlightEntry
        and tracks the painted rectangle for efficient repainting.
        (addHighlight): Handle layered highlight.
        (changeHighlight): Handle layered highlight.
        (paintLayeredHighlights): Implemented.
        (paint): Paint only non-layered highlights here.
        (removeAllHighlights): Trigger correct repaint.
        (removeHighlight): Handle layered highlight here for
        more efficient repainting.
        * javax/swing/text/GlyphView.java
        (paint): Handle layered highlights.
        * javax/swing/text/PlainView.java
        (paint): Handle layered highlights.
        * javax/swing/text/WrappedPlainView.java
        (WrappedLine.paint): Handle layered highlights.

/Roman
Index: javax/swing/text/DefaultHighlighter.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/text/DefaultHighlighter.java,v
retrieving revision 1.11
diff -u -1 -2 -r1.11 DefaultHighlighter.java
--- javax/swing/text/DefaultHighlighter.java	14 Apr 2006 18:09:43 -0000	1.11
+++ javax/swing/text/DefaultHighlighter.java	8 Aug 2006 10:35:59 -0000
@@ -1,13 +1,13 @@
-/* DefaultHighlighter.java --
+/* DefaultHighlighter.java -- The default highlight for Swing
    Copyright (C) 2004, 2006  Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
 GNU Classpath is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2, or (at your option)
 any later version.
 
 GNU Classpath is distributed in the hope that it will be useful, but
 WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
@@ -29,195 +29,238 @@
 modules, and to copy and distribute the resulting executable under
 terms of your choice, provided that you also meet, for each linked
 independent module, the terms and conditions of the license of that
 module.  An independent module is a module which is not derived from
 or based on this library.  If you modify this library, you may extend
 this exception to your version of the library, but you are not
 obligated to do so.  If you do not wish to do so, delete this
 exception statement from your version. */
 
 
 package javax.swing.text;
 
-import gnu.classpath.NotImplementedException;
-
 import java.awt.Color;
 import java.awt.Graphics;
 import java.awt.Insets;
 import java.awt.Rectangle;
 import java.awt.Shape;
 import java.util.ArrayList;
+import java.util.Iterator;
 
 import javax.swing.SwingUtilities;
 import javax.swing.plaf.TextUI;
 
+/**
+ * The default highlight for Swing text components. It highlights text
+ * by filling the background with a rectangle. 
+ */
 public class DefaultHighlighter extends LayeredHighlighter
 {
   public static class DefaultHighlightPainter
     extends LayerPainter
   {
     private Color color;
     
     public DefaultHighlightPainter(Color c)
     {
       super();
       color = c;
     }
 
     public Color getColor()
     {
       return color;
     }
 
-    private void paintHighlight(Graphics g, Rectangle rect)
-    {
-      g.fillRect(rect.x, rect.y, rect.width, rect.height);
-    }
-    
     public void paint(Graphics g, int p0, int p1, Shape bounds,
 		      JTextComponent t)
     {
       if (p0 == p1)
         return;
       
       Rectangle rect = bounds.getBounds();
 
-      if (color == null)
-        g.setColor(t.getSelectionColor());
-      else
-        g.setColor(color);
+      Color col = getColor();
+      if (col == null)
+        col = t.getSelectionColor();
+      g.setColor(col);
 
       TextUI ui = t.getUI();
       
       try
-      {
-        
-        Rectangle l0 = ui.modelToView(t, p0, null);
-        Rectangle l1 = ui.modelToView(t, p1, null);
-        
-        // Note: The computed locations may lie outside of the allocation
-        // area if the text is scrolled.
+        {
+
+          Rectangle l0 = ui.modelToView(t, p0, null);
+          Rectangle l1 = ui.modelToView(t, p1, null);
         
-        if (l0.y == l1.y)
+          // Note: The computed locations may lie outside of the allocation
+          // area if the text is scrolled.
+
+          if (l0.y == l1.y)
           {
             SwingUtilities.computeUnion(l0.x, l0.y, l0.width, l0.height, l1);
 
             // Paint only inside the allocation area.
-            SwingUtilities.computeIntersection(rect.x, rect.y, rect.width, rect.height, l1);
+            SwingUtilities.computeIntersection(rect.x, rect.y, rect.width,
+					       rect.height, l1);
         
-            paintHighlight(g, l1);
+            g.fillRect(l1.x, l1.y, l1.width, l1.height);
           }
         else
           {
             // 1. The line of p0 is painted from the position of p0
             // to the right border.
             // 2. All lines between the ones where p0 and p1 lie on
             // are completely highlighted. The allocation area is used to find
             // out the bounds.
             // 3. The final line is painted from the left border to the
             // position of p1.
-            
-            // Highlight first line until the end.
-            // If rect.x is non-zero the calculation will properly adjust the
-            // area to be painted.
-            l0.x -= rect.x;
-            l0.width = rect.width - l0.x - rect.x;
-            
-            paintHighlight(g, l0);
-            
-            int posBelow = Utilities.getPositionBelow(t, p0, l0.x);
-            int p1RowStart = Utilities.getRowStart(t, p1);
-            if (posBelow != -1
-                && posBelow != p0
-                && Utilities.getRowStart(t, posBelow)
-                   != p1RowStart)
-              {
-                Rectangle grow = ui.modelToView(t, posBelow);
-                grow.x = rect.x;
-                grow.width = rect.width;
-                
-                // Find further lines which have to be highlighted completely.
-                int nextPosBelow = posBelow;
-                while (nextPosBelow != -1
-                       && Utilities.getRowStart(t, nextPosBelow) != p1RowStart)
-                  {
-                    posBelow = nextPosBelow;
-                    nextPosBelow = Utilities.getPositionBelow(t, posBelow, l0.x);
-                    
-                    if (nextPosBelow == posBelow)
-                      break;
-                  }
-                // Now posBelow is an offset on the last line which has to be painted
-                // completely. (newPosBelow is on the same line as p1)
-                 
-                // Retrieve the rectangle of posBelow and use its y and height
-                // value to calculate the final height of the multiple line
-                // spanning rectangle.
-                Rectangle end = ui.modelToView(t, posBelow);
-                grow.height = end.y + end.height - grow.y;
-                
-                paintHighlight(g, grow);
-              }
-            
-            // Paint last line from its beginning to the position of p1.
-            l1.width = l1.x + l1.width - rect.x;
-            l1.x = rect.x;
-            paintHighlight(g, l1);
-          }
+
+	    int firstLineWidth = rect.x + rect.width - l0.x;
+	    g.fillRect(l0.x, l0.y, firstLineWidth, l0.height);
+	    if (l0.y + l0.height != l1.y)
+	      {
+		g.fillRect(rect.x, l0.y + l0.height, rect.width,
+			   l1.y - l0.y - l0.height);
+	      }
+	    g.fillRect(rect.x, l1.y, l1.x - rect.x, l1.height);
+	  }
       }
     catch (BadLocationException ex)
       {
-        AssertionError err = new AssertionError("Unexpected bad location exception");
-        err.initCause(ex);
-        throw err;
+	// Can't render. Comment out for debugging.
+	// ex.printStackTrace();
       }
     }
 
     public Shape paintLayer(Graphics g, int p0, int p1, Shape bounds,
 			    JTextComponent c, View view)
     {
-      throw new InternalError();
+      Color col = getColor();
+      if (col == null)
+	col = c.getSelectionColor();
+      g.setColor(col);
+
+      Rectangle rect = null;
+      if (p0 == view.getStartOffset() && p1 == view.getEndOffset())
+	{
+	  // Paint complete bounds region.
+          rect = bounds instanceof Rectangle ? (Rectangle) bounds
+	                                     : bounds.getBounds();
+	}
+      else
+	{
+	  // Only partly inside the view.
+          try
+	    {
+              Shape s = view.modelToView(p0, Position.Bias.Forward,
+					 p1, Position.Bias.Backward,
+					 bounds);
+	      rect = s instanceof Rectangle ? (Rectangle) s : s.getBounds();
+	    }
+	  catch (BadLocationException ex)
+	    {
+	      // Can't render the highlight.
+	    }
+	}
+
+      if (rect != null)
+	{
+          g.fillRect(rect.x, rect.y, rect.width, rect.height);
+	}
+      return rect;
     }
   }
   
   private class HighlightEntry implements Highlighter.Highlight
   {
-    int p0;
-    int p1;
+    Position p0;
+    Position p1;
     Highlighter.HighlightPainter painter;
 
-    public HighlightEntry(int p0, int p1, Highlighter.HighlightPainter painter)
+    public HighlightEntry(Position p0, Position p1, HighlightPainter painter)
     {
       this.p0 = p0;
       this.p1 = p1;
       this.painter = painter;
     }
 
     public int getStartOffset()
     {
-      return p0;
+      return p0.getOffset();
     }
 
     public int getEndOffset()
     {
-      return p1;
+      return p1.getOffset();
     }
 
     public Highlighter.HighlightPainter getPainter()
     {
       return painter;
     }
   }
 
   /**
+   * A HighlightEntry that is used for LayerPainter painters. In addition
+   * to the info maintained by the HighlightEntry, this class maintains
+   * a painting rectangle. This is used as repaint region when the
+   * highlight changes and the text component needs repainting.
+   */
+  private class LayerHighlightEntry
+    extends HighlightEntry
+  {
+
+    /**
+     * The paint rectangle.
+     */
+    Rectangle paintRect = new Rectangle();
+
+    LayerHighlightEntry(Position p0, Position p1, HighlightPainter p)
+    {
+      super(p0, p1, p);
+    }
+
+    /**
+     * Paints the highlight by calling the LayerPainter. This
+     * restricts the area to be painted by startOffset and endOffset
+     * and manages the paint rectangle.
+     */
+    void paintLayeredHighlight(Graphics g, int p0, int p1, Shape bounds,
+			       JTextComponent tc, View view)
+    {
+      p0 = Math.max(getStartOffset(), p0);
+      p1 = Math.min(getEndOffset(), p1);
+
+      HighlightPainter painter = getPainter();
+      if (painter instanceof LayerPainter)
+	{
+	  LayerPainter layerPainter = (LayerPainter) painter;
+	  Shape area = layerPainter.paintLayer(g, p0, p1, bounds, tc, view);
+	  Rectangle rect;
+	  if (area instanceof Rectangle && paintRect != null)
+	    rect = (Rectangle) area;
+	  else
+	    rect = area.getBounds();
+
+	  if (paintRect.width == 0 || paintRect.height == 0)
+	    paintRect = rect.getBounds();
+	  else
+	    paintRect = SwingUtilities.computeUnion(rect.x, rect.y, rect.width,
+						    rect.height, paintRect);
+	}
+    }
+  }
+
+  /**
    * @specnote final as of 1.4
    */
   public static final LayeredHighlighter.LayerPainter DefaultPainter =
     new DefaultHighlightPainter(null);
   
   private JTextComponent textComponent;
   private ArrayList highlights = new ArrayList();
   private boolean drawsLayeredHighlights = true;
   
   public DefaultHighlighter()
   {
     // Nothing to do here.
@@ -245,161 +288,188 @@
 
   public void install(JTextComponent c)
   {
     textComponent = c;
     removeAllHighlights();
   }
 
   public void deinstall(JTextComponent c)
   {
     textComponent = null;
   }
 
-  public Object addHighlight(int p0, int p1, Highlighter.HighlightPainter painter)
+  public Object addHighlight(int p0, int p1, HighlightPainter painter)
     throws BadLocationException
   {
     checkPositions(p0, p1);
-    HighlightEntry entry = new HighlightEntry(p0, p1, painter);
+    HighlightEntry entry;
+    Document doc = textComponent.getDocument();
+    Position pos0 = doc.createPosition(p0);
+    Position pos1 = doc.createPosition(p1);
+    if (getDrawsLayeredHighlights() && painter instanceof LayerPainter)
+      entry = new LayerHighlightEntry(pos0, pos1, painter);
+    else
+      entry = new HighlightEntry(pos0, pos1, painter);
     highlights.add(entry);
     
     textComponent.getUI().damageRange(textComponent, p0, p1);
     
     return entry;
   }
 
   public void removeHighlight(Object tag)
   {
+    HighlightEntry entry = (HighlightEntry) tag;
+    if (entry instanceof LayerHighlightEntry)
+      {
+	LayerHighlightEntry lEntry = (LayerHighlightEntry) entry;
+	Rectangle paintRect = lEntry.paintRect;
+	textComponent.repaint(paintRect.x, paintRect.y, paintRect.width,
+			      paintRect.height);
+      }
+    else
+      {
+	textComponent.getUI().damageRange(textComponent,
+					  entry.getStartOffset(),
+					  entry.getEndOffset());
+      }
     highlights.remove(tag);
 
-    HighlightEntry entry = (HighlightEntry) tag;
-    textComponent.getUI().damageRange(textComponent,
-                                      entry.p0,
-                                      entry.p1);
   }
 
   public void removeAllHighlights()
   {
+    // Repaint damaged region.
+    int minX = 0;
+    int maxX = 0;
+    int minY = 0;
+    int maxY = 0;
+    int p0 = -1;
+    int p1 = -1;
+    for (Iterator i = highlights.iterator(); i.hasNext();)
+      {
+        HighlightEntry e = (HighlightEntry) i.next();
+        if (e instanceof LayerHighlightEntry)
+          {
+            LayerHighlightEntry le = (LayerHighlightEntry) e;
+            Rectangle r = le.paintRect;
+            minX = Math.min(r.x, minX);
+            maxX = Math.max(r.x + r.width, maxX);
+            minY = Math.min(r.y, minY);
+            maxY = Math.max(r.y + r.height, maxY);
+          }
+        else
+          {
+            if (p0 == -1 || p1 == -1)
+              {
+                p0 = e.getStartOffset();
+                p1 = e.getEndOffset();
+              }
+            else
+              {
+                p0 = Math.min(p0, e.getStartOffset());
+                p1 = Math.max(p1, e.getEndOffset());
+              }
+          }
+        if (minX != maxX && minY != maxY)
+          textComponent.repaint(minX, minY, maxX - minX, maxY - minY);
+        if (p0 != -1 && p1 != -1)
+          {
+            TextUI ui = textComponent.getUI();
+            ui.damageRange(textComponent, p0, p1);
+          }
+        
+      }
     highlights.clear();
   }
 
   public Highlighter.Highlight[] getHighlights()
   {
     return (Highlighter.Highlight[]) 
       highlights.toArray(new Highlighter.Highlight[highlights.size()]);
   }
 
   public void changeHighlight(Object tag, int n0, int n1)
     throws BadLocationException
   {
-    int o0, o1;
-    
-    checkPositions(n0, n1);
-    HighlightEntry entry = (HighlightEntry) tag;
-    o0 = entry.p0;
-    o1 = entry.p1;
-    
-    // Prevent useless write & repaint operations.
-    if (o0 == n0 && o1 == n1)
-      return;
-    
-    entry.p0 = n0;
-    entry.p1 = n1;
-    
+    Document doc = textComponent.getDocument();
     TextUI ui = textComponent.getUI();
-    
-    // Special situation where the old area has to be cleared simply.
-    if (n0 == n1)
-      ui.damageRange(textComponent, o0, o1);
-    // Calculates the areas where a change is really neccessary
-    else if ((o1 > n0 && o1 <= n1)
-        || (n1 > o0 && n1 <= o1))
+    if (tag instanceof LayerHighlightEntry)
       {
-        // [fds, fde) - the first damage region
-        // [sds, sde] - the second damage region
-        int fds, sds;
-        int fde, sde;
-
-        // Calculate first damaged region.
-        if(o0 < n0)
-          {
-            // Damaged region will be cleared as
-            // the old highlight region starts first.
-            fds = o0;
-            fde = n0;
-          }
-        else
-          {
-            // Damaged region will be painted as
-            // the new highlight region starts first.
-            fds = n0;
-            fde = o0;
-          }
-
-        if (o1 < n1)
+        LayerHighlightEntry le = (LayerHighlightEntry) tag;
+        Rectangle r = le.paintRect;
+        if (r.width > 0 && r.height > 0)
+          textComponent.repaint(r.x, r.y, r.width, r.height);
+        r.width = 0;
+        r.height = 0;
+        le.p0 = doc.createPosition(n0);
+        le.p1 = doc.createPosition(n1);
+        ui.damageRange(textComponent, Math.min(n0, n1), Math.max(n0, n1));
+      }
+    else if (tag instanceof HighlightEntry)
+      {
+        HighlightEntry e = (HighlightEntry) tag;
+        int p0 = e.getStartOffset();
+        int p1 = e.getEndOffset();
+        if (p0 == n0)
           {
-            // Final region will be painted as the
-            // old highlight region finishes first
-            sds = o1;
-            sde = n1;
+            ui.damageRange(textComponent, Math.min(p1, n1),
+                           Math.max(p1, n1));
           }
-        else
+        else if (n1 == p1)
           {
-            // Final region will be cleared as the
-            // new highlight region finishes first.
-            sds = n1;
-            sde = o1;
+            ui.damageRange(textComponent, Math.min(p0, n0),
+                           Math.max(p0, n0));
           }
-        
-        // If there is no undamaged region in between
-        // call damageRange only once.
-        if (fde == sds)
-          ui.damageRange(textComponent, fds, sde);
         else
           {
-            if (fds != fde)
-              ui.damageRange(textComponent, fds, fde);
-        
-            if (sds != sde)
-              ui.damageRange(textComponent, sds, sde);
+            ui.damageRange(textComponent, p0, p1);
+            ui.damageRange(textComponent, n0, n1);
           }
+        e.p0 = doc.createPosition(n0);
+        e.p1 = doc.createPosition(n1);
       }
-    else
-      {
-        // The two regions do not overlap. So mark
-        // both areas as damaged.
-        ui.damageRange(textComponent, o0, o1);
-        ui.damageRange(textComponent, n0, n1);
-      }
-    
   }
 
   public void paintLayeredHighlights(Graphics g, int p0, int p1,
                                      Shape viewBounds, JTextComponent editor,
                                      View view)
-  throws NotImplementedException
   {
-    // TODO: Implement this properly.
+    for (Iterator i = highlights.iterator(); i.hasNext();)
+      {
+	Object o = i.next();
+	if (o instanceof LayerHighlightEntry)
+	  {
+	    LayerHighlightEntry entry = (LayerHighlightEntry) o;
+	    int start = entry.getStartOffset();
+	    int end = entry.getEndOffset();
+	    if ((p0 < start && p1 > start) || (p0 >= start && p0 < end))
+	      entry.paintLayeredHighlight(g, p0, p1, viewBounds, editor, view);
+	  }
+      }
   }
 
   public void paint(Graphics g)
   {
     int size = highlights.size();
     
     // Check if there are any highlights.
     if (size == 0)
       return;
 
     // Prepares the rectangle of the inner drawing area.
     Insets insets = textComponent.getInsets();
     Shape bounds =
       new Rectangle(insets.left,
                     insets.top,
                     textComponent.getWidth() - insets.left - insets.right,
                     textComponent.getHeight() - insets.top - insets.bottom);
     
     for (int index = 0; index < size; ++index)
       {
 	HighlightEntry entry = (HighlightEntry) highlights.get(index);
-	entry.painter.paint(g, entry.p0, entry.p1, bounds, textComponent);
+	if (! (entry instanceof LayerHighlightEntry))
+          entry.painter.paint(g, entry.getStartOffset(), entry.getEndOffset(),
+                              bounds, textComponent);
       }
   }
 }
Index: javax/swing/text/GlyphView.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/text/GlyphView.java,v
retrieving revision 1.17
diff -u -1 -2 -r1.17 GlyphView.java
--- javax/swing/text/GlyphView.java	21 Feb 2006 13:56:15 -0000	1.17
+++ javax/swing/text/GlyphView.java	8 Aug 2006 10:35:59 -0000
@@ -30,24 +30,25 @@
 terms of your choice, provided that you also meet, for each linked
 independent module, the terms and conditions of the license of that
 module.  An independent module is a module which is not derived from
 or based on this library.  If you modify this library, you may extend
 this exception to your version of the library, but you are not
 obligated to do so.  If you do not wish to do so, delete this
 exception statement from your version. */
 
 
 package javax.swing.text;
 
 import java.awt.Color;
+import java.awt.Container;
 import java.awt.Font;
 import java.awt.FontMetrics;
 import java.awt.Graphics;
 import java.awt.Rectangle;
 import java.awt.Shape;
 import java.awt.Toolkit;
 import java.text.BreakIterator;
 
 import javax.swing.SwingConstants;
 import javax.swing.event.DocumentEvent;
 import javax.swing.text.Position.Bias;
 
@@ -527,27 +528,42 @@
       glyphPainter = new DefaultGlyphPainter();
   }
 
   /**
    * Renders the <code>Element</code> that is associated with this
    * <code>View</code>.
    *
    * @param g the <code>Graphics</code> context to render to
    * @param a the allocated region for the <code>Element</code>
    */
   public void paint(Graphics g, Shape a)
   {
-    Element el = getElement();
     checkPainter();
-    getGlyphPainter().paint(this, g, a, getStartOffset(), getEndOffset());
+    int p0 = getStartOffset();
+    int p1 = getEndOffset();
+
+    Container c = getContainer();
+    // Paint layered highlights if there are any.
+    if (c instanceof JTextComponent)
+      {
+        JTextComponent tc = (JTextComponent) c;
+        Highlighter h = tc.getHighlighter();
+        if (h instanceof LayeredHighlighter)
+          {
+            LayeredHighlighter lh = (LayeredHighlighter) h;
+            lh.paintLayeredHighlights(g, p0, p1, a, tc, this);
+          }
+      }
+
+    getGlyphPainter().paint(this, g, a, p0, p1);
   }
 
 
   /**
    * Returns the preferred span of the content managed by this
    * <code>View</code> along the specified <code>axis</code>.
    *
    * @param axis the axis
    *
    * @return the preferred span of this <code>View</code>.
    */
   public float getPreferredSpan(int axis)
Index: javax/swing/text/PlainView.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/text/PlainView.java,v
retrieving revision 1.44
diff -u -1 -2 -r1.44 PlainView.java
--- javax/swing/text/PlainView.java	3 Jun 2006 15:18:28 -0000	1.44
+++ javax/swing/text/PlainView.java	8 Aug 2006 10:35:59 -0000
@@ -257,31 +257,52 @@
     JTextComponent textComponent = (JTextComponent) getContainer();
 
     selectedColor = textComponent.getSelectedTextColor();
     unselectedColor = textComponent.getForeground();
     disabledColor = textComponent.getDisabledTextColor();
     selectionStart = textComponent.getSelectionStart();
     selectionEnd = textComponent.getSelectionEnd();
 
     Rectangle rect = s.getBounds();
 
     // FIXME: Text may be scrolled.
     Document document = textComponent.getDocument();
-    Element root = document.getDefaultRootElement();
+    Element root = getElement();
     int y = rect.y + metrics.getAscent();
     int height = metrics.getHeight();
-    
+
+    // For layered highlighters we need to paint the layered highlights
+    // before painting any text.
+    LayeredHighlighter hl = null;
+    Highlighter h = textComponent.getHighlighter();
+    if (h instanceof LayeredHighlighter)
+      hl = (LayeredHighlighter) h;
+
     int count = root.getElementCount();
+
     for (int i = 0; i < count; i++)
       {
+        if (hl != null)
+          {
+            Element lineEl = root.getElement(i);
+            // Exclude the trailing newline from beeing highlighted.
+            if (i == count)
+              hl.paintLayeredHighlights(g, lineEl.getStartOffset(),
+                                        lineEl.getEndOffset(), s, textComponent,
+                                        this);
+            else
+              hl.paintLayeredHighlights(g, lineEl.getStartOffset(),
+                                        lineEl.getEndOffset() - 1, s,
+                                        textComponent, this);
+          }
         drawLine(i, g, rect.x, y);
         y += height;
       }
   }
 
   /**
    * Returns the tab size of a tab.  Checks the Document's
    * properties for PlainDocument.tabSizeAttribute and returns it if it is
    * defined, otherwise returns 8.
    * 
    * @return the tab size.
    */
Index: javax/swing/text/WrappedPlainView.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/text/WrappedPlainView.java,v
retrieving revision 1.21
diff -u -1 -2 -r1.21 WrappedPlainView.java
--- javax/swing/text/WrappedPlainView.java	3 May 2006 18:11:05 -0000	1.21
+++ javax/swing/text/WrappedPlainView.java	8 Aug 2006 10:35:59 -0000
@@ -440,28 +440,52 @@
     /**
      * Renders this (possibly wrapped) line using the given Graphics object
      * and on the given rendering surface.
      */
     public void paint(Graphics g, Shape s)
     {
       Rectangle rect = s.getBounds();
 
       int end = getEndOffset();
       int currStart = getStartOffset();
       int currEnd;
       int count = 0;
+
+      // Determine layered highlights.
+      Container c = getContainer();
+      LayeredHighlighter lh = null;
+      JTextComponent tc = null;
+      if (c instanceof JTextComponent)
+        {
+          tc = (JTextComponent) c;
+          Highlighter h = tc.getHighlighter();
+          if (h instanceof LayeredHighlighter)
+            lh = (LayeredHighlighter) h;
+        }
+
       while (currStart < end)
         {
           currEnd = calculateBreakPosition(currStart, end);
 
+          // Paint layered highlights, if any.
+          if (lh != null)
+            {
+              // Exclude trailing newline in last line.
+              if (currEnd == end)
+                lh.paintLayeredHighlights(g, currStart, currEnd - 1, s, tc,
+                                          this);
+              else
+                lh.paintLayeredHighlights(g, currStart, currEnd, s, tc, this);
+                
+            }
           drawLine(currStart, currEnd, g, rect.x, rect.y + metrics.getAscent());
           
           rect.y += lineHeight;          
           if (currEnd == currStart)
             currStart ++;
           else
             currStart = currEnd;
           
           count++;
           
         }
       

Reply via email to