This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[gui] Patch: javax.swing.text.Segment and its handling


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi list,


I just commited the attached patch to improve javax.swing.text.Segment 
and its handling in javax.swing.text.AbstractDocument.


Michael


2004-08-12  Michael Koch  <konqueror@gmx.de>

	* javax/swing/text/AbstractDocument.java
	(getText): Simplified.
	* javax/swing/text/Segment.java
	(current): New field.
	(current): Reimplemented.
	(first): Likewise.
	(getIndex): Likewise.
	(last): Likewise.
	(next): Likewise.
	(previous): Likewise.
	(setIndex): Likewise.
- -- 
Homepage: http://www.worldforge.org/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFBG5Z7WSOgCCdjSDsRAkKLAJwPjlVvpXegzrtktu9+Ud57gHQA3wCfVRLm
4OQFr3tEuP/e2utSd0E0CPc=
=Osug
-----END PGP SIGNATURE-----
Index: javax/swing/text/AbstractDocument.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/text/AbstractDocument.java,v
retrieving revision 1.3.8.14
diff -u -r1.3.8.14 AbstractDocument.java
--- javax/swing/text/AbstractDocument.java	12 Aug 2004 10:10:29 -0000	1.3.8.14
+++ javax/swing/text/AbstractDocument.java	12 Aug 2004 16:04:45 -0000
@@ -207,28 +207,10 @@
     return content.getString(offset, length);
   }
 
-  public void getText(int offset, int length, Segment txt)
+  public void getText(int offset, int length, Segment segment)
     throws BadLocationException
   {
-    String a = getText(offset, length);
-
-    if (a == null)
-      {
-	txt.offset = 0;
-	txt.count = 0;
-	txt.array = new char[0];
-
-	return;
-      }
-
-    txt.offset = offset;
-    txt.count = length;
-
-    char[] chars = new char[a.length()];
-
-    a.getChars(0, a.length(), chars, 0);
-
-    txt.array = chars;
+    content.getChars(offset, length, segment);
   }
 
   public void insertString(int offset, String text, AttributeSet attributes)
Index: javax/swing/text/Segment.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/text/Segment.java,v
retrieving revision 1.2.8.4
diff -u -r1.2.8.4 Segment.java
--- javax/swing/text/Segment.java	21 Jul 2004 09:05:19 -0000	1.2.8.4
+++ javax/swing/text/Segment.java	12 Aug 2004 16:04:45 -0000
@@ -39,11 +39,11 @@
 
 import java.text.CharacterIterator;
 
-
 public class Segment
   implements Cloneable, CharacterIterator
 {
   private boolean partialReturn;
+  private int current;
   
   public char[] array;
   public int count;
@@ -74,13 +74,20 @@
 
   public char current()
   {
-    return array[getIndex()];
+    if (count == 0
+	|| current >= getEndIndex())
+      return DONE;
+    
+    return array[current];
   }
 
   public char first()
   {
-    offset = getBeginIndex();
-    return array[offset];
+    if (count == 0)
+      return DONE;
+
+    current = getBeginIndex();
+    return array[current];
   }
 
   public int getBeginIndex()
@@ -95,31 +102,55 @@
 
   public int getIndex()
   {
-    return offset;
+    return current;
   }
 
   public char last()
   {
-    offset = getEndIndex() - 1;
-    return array[offset];
+    if (count == 0)
+      return DONE;
+    
+    current = getEndIndex() - 1;
+    return array[current];
   }
 
   public char next()
   {
-    offset++;
-    return array[offset];
+    if (count == 0)
+      return DONE;
+
+    if ((current + 1) >= getEndIndex())
+      {
+	current = getEndIndex();
+	return DONE;
+      }
+    
+    current++;
+    return array[current];
   }
 
   public char previous()
   {
-    offset--;
-    return array[offset];
+    if (count == 0
+	|| current == getBeginIndex())
+      return DONE;
+    
+    current--;
+    return array[current];
   }
 
   public char setIndex(int position)
   {
-    offset = position;
-    return array[offset];
+    if (position < getBeginIndex()
+	|| position > getEndIndex())
+      throw new IllegalArgumentException();
+
+    current = position;
+
+    if (position == getEndIndex())
+      return DONE;
+    
+    return array[current];
   }
 
   public String toString()

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]