This fixes GlyphView to return the correct indices for endOffset and
startOffset. This makes it possible to remove text in styled text panes
(BeanShell! yay ;-) ) without throwing loads of exceptions.

2006-02-07  Roman Kennke  <[EMAIL PROTECTED]>

        * javax/swing/text/GlyphView.java
        (GlyphView): Initialize startOffset and endOffset with -1
(indicating
        element boundary).
        (getStartOffset): Return element boundary if startOffset < 0.
        (getEndOffset): Return element boundary if endOffset < 0.
        (createFragment): Set startOffset and endOffset fields of fragment
        if one of p0 or p1 is not at the element boundary.

/Roman
Index: javax/swing/text/GlyphView.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/text/GlyphView.java,v
retrieving revision 1.14
diff -u -r1.14 GlyphView.java
--- javax/swing/text/GlyphView.java	6 Feb 2006 16:36:13 -0000	1.14
+++ javax/swing/text/GlyphView.java	7 Feb 2006 15:51:44 -0000
@@ -489,8 +489,8 @@
   public GlyphView(Element element)
   {
     super(element);
-    startOffset = element.getStartOffset();
-    endOffset = element.getEndOffset();
+    startOffset = -1;
+    endOffset = -1;
   }
 
   /**
@@ -686,7 +686,10 @@
    */
   public int getStartOffset()
   {
-    return startOffset;
+    int start = startOffset;
+    if (start < 0)
+      start = super.getStartOffset();
+    return start;
   }
 
   /**
@@ -698,7 +701,10 @@
    */
   public int getEndOffset()
   {
-    return endOffset;
+    int end = endOffset;
+    if (end < 0)
+      end = super.getEndOffset();
+    return end;
   }
 
   /**
@@ -1008,8 +1014,10 @@
   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;
   }
 

Reply via email to