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.AbstractDocument


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

Hi list,


I just commited the attached patch to improve AbstractDocument.


Michael


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

	* javax/swing/text/AbstractDocument.java:
	Fixed some typos in comments.
	(insertString): Reimplemented.
	(remove): Likewise.
	(replace): New method.
	(children): Dont use fully qualified class name.
	(DefaultDocumentEvent.offset): Renamed from off.
	(DefaultDocumentEvent.length): Renamed from len.
	(DefaultDocumentEvent.type): New field.
	(DefaultDocumentEvent.DefaultDocumentEvent): New constructor.
	(DefaultDocumentEvent.getType): Implemented.
- -- 
Homepage: http://www.worldforge.org/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFBG0MxWSOgCCdjSDsRAkAEAJ47I7mFI4xtDmyTFnv2t5Cjm40OnwCeMP0L
2A86EnUPozr3imO+lwg2t5w=
=o+Ku
-----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.13
diff -u -r1.3.8.13 AbstractDocument.java
--- javax/swing/text/AbstractDocument.java	10 Aug 2004 23:24:26 -0000	1.3.8.13
+++ javax/swing/text/AbstractDocument.java	12 Aug 2004 10:08:19 -0000
@@ -38,6 +38,7 @@
 package javax.swing.text;
 
 import java.io.Serializable;
+import java.util.Collections;
 import java.util.Dictionary;
 import java.util.Enumeration;
 import java.util.EventListener;
@@ -79,7 +80,7 @@
     context = ctx;
   }
 
-  // these still need to be implemented by a derived class:
+  // These still need to be implemented by a derived class:
   public abstract Element getParagraphElement(int pos);
 
   public abstract Element getDefaultRootElement();
@@ -230,10 +231,19 @@
     txt.array = chars;
   }
 
-  public void insertString(int offs, String str, AttributeSet a)
+  public void insertString(int offset, String text, AttributeSet attributes)
     throws BadLocationException
   {
-    content.insertString(offs, str);
+    // Just return when no text to insert was given.
+    if (text == null || text.length() == 0)
+      return;
+    
+    DefaultDocumentEvent event =
+      new DefaultDocumentEvent(offset, text.length(),
+			       DocumentEvent.EventType.INSERT);
+    content.insertString(offset, text);
+    insertUpdate(event, attributes);
+    fireInsertUpdate(event);
   }
 
   protected void insertUpdate(DefaultDocumentEvent chng, AttributeSet attr)
@@ -258,6 +268,26 @@
 
   public void remove(int offset, int length) throws BadLocationException
   {
+    DefaultDocumentEvent event =
+      new DefaultDocumentEvent(offset, length,
+			       DocumentEvent.EventType.REMOVE);
+    removeUpdate(event);
+    content.remove(offset, length);
+    postRemoveUpdate(event);
+    fireRemoveUpdate(event);
+  }
+
+  /**
+   * Replaces some text in the document.
+   *
+   * @since 1.4
+   */
+  public void replace(int offset, int length, String text,
+		      AttributeSet attributes)
+    throws BadLocationException
+  {
+    remove(offset, length);
+    insertString(offset, text, attributes);
   }
 
   /**
@@ -402,7 +432,7 @@
 
     public Enumeration children()
     {
-      return java.util.Collections.enumeration(tree_children);
+      return Collections.enumeration(tree_children);
     }
       
     public boolean getAllowsChildren()
@@ -433,7 +463,7 @@
     public abstract boolean isLeaf();
 
 
-    // MutableAttributeSet suppoer
+    // MutableAttributeSet support
 
     public void addAttribute(Object name, Object value)
     {
@@ -645,8 +675,18 @@
     implements DocumentEvent
   {
     private static final long serialVersionUID = -7406103236022413522L;
-    public int len;
-    public int off;
+    
+    private int offset;
+    private int length;
+    private DocumentEvent.EventType type;
+
+    public DefaultDocumentEvent(int offset, int length,
+				DocumentEvent.EventType type)
+    {
+      this.offset = offset;
+      this.length = length;
+      this.type = type;
+    }
 
     public Document getDocument()
     {
@@ -655,17 +695,17 @@
 
     public int getLength()
     {
-      return len;
+      return length;
     }
 
     public int getOffset()
     {
-      return off;
+      return offset;
     }
 
     public DocumentEvent.EventType getType()
     {
-      return null;
+      return type;
     }
 
     public DocumentEvent.ElementChange getChange(Element elem)

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