This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
[gui] Patch: javax.swing.text.AbstractDocument
- From: Michael Koch <konqueror at gmx dot de>
- To: java-patches at gcc dot gnu dot org
- Date: Mon, 28 Jun 2004 12:57:32 +0200
- Subject: [gui] Patch: javax.swing.text.AbstractDocument
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi list,
I just commited the attached patch to java-gui-branch to reformat
javax.swing.text.AbstractDocument.
Michael
2004-06-28 Michael Koch <konqueror@gmx.de>
* javax/swing/text/AbstractDocument.java:
Reformatted.
- --
Homepage: http://www.worldforge.org/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
iD8DBQFA3/mfWSOgCCdjSDsRAt1mAJ9s8uYQEWw2lxX3g2/hn1plZfH6lQCbBX2h
wDjfm0rr3C8Msr7FIcq31L8=
=XiIm
-----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.9
diff -u -b -B -r1.3.8.9 AbstractDocument.java
--- javax/swing/text/AbstractDocument.java 24 Jun 2004 05:31:37 -0000 1.3.8.9
+++ javax/swing/text/AbstractDocument.java 28 Jun 2004 10:53:50 -0000
@@ -57,608 +56,608 @@
public abstract class AbstractDocument
implements Document, Serializable
{
- public abstract class AbstractElement
- implements Element, TreeNode, Serializable
- {
- private static final long serialVersionUID = 1265312733007397733L;
-
- int count;
- int offset;
- AttributeSet attr;
- Vector elts = new Vector();
- String name;
- Element parent;
- Vector kids = new Vector();
- TreeNode tree_parent;
+ private static final long serialVersionUID = -116069779446114664L;
+ protected static final String BAD_LOCATION = "document location failure";
+ public static final String BidiElementName = "bidi level";
+ public static final String ContentElementName = "content";
+ public static final String ParagraphElementName = "paragraph";
+ public static final String SectionElementName = "section";
+ public static final String ElementNameAttribute = "$ename";
+ Content content;
+ protected EventListenerList listenerList = new EventListenerList();
- public AbstractElement(Element p, AttributeSet s)
+ protected AbstractDocument(Content doc)
{
- parent = p;
- attr = s;
+ this(doc, null);
}
- public Enumeration children()
+ protected AbstractDocument(Content doc, AttributeContext context)
{
- return kids.elements();
+ content = doc;
}
- public boolean getAllowsChildren()
- {
- return true;
- }
+ // these still need to be implemented by a derived class:
+ public abstract Element getParagraphElement(int pos);
- public TreeNode getChildAt(int index)
- {
- return (TreeNode) kids.elementAt(index);
- }
+ public abstract Element getDefaultRootElement();
- public int getChildCount()
+ protected Element createBranchElement(Element parent, AttributeSet a)
{
- return kids.size();
+ return new BranchElement(parent, a, 0, 0);
}
- public int getIndex(TreeNode node)
+ protected Element createLeafElement(Element parent, AttributeSet a, int p0,
+ int p1)
{
- return kids.indexOf(node);
+ return new LeafElement(parent, a, p0, p1 - p0);
}
- public TreeNode getParent()
+ public Position createPosition(int offs)
{
- return tree_parent;
- }
+ final int a = offs;
- public AttributeSet getAttributes()
+ return new Position()
{
- return attr;
- }
-
- public Document getDocument()
+ public int getOffset()
{
- return AbstractDocument.this;
+ return a;
}
-
- public Element getElement(int index)
- {
- return (Element) elts.elementAt(index);
+ };
}
- public String getName()
+ protected void fireChangedUpdate(DocumentEvent event)
{
- return name;
+ DocumentListener[] listeners = getDocumentListeners();
+
+ for (int index = 0; index < listeners.length; ++index)
+ listeners[index].changedUpdate(event);
}
- public Element getParentElement()
+ protected void fireInsertUpdate(DocumentEvent event)
{
- return parent;
- }
+ DocumentListener[] listeners = getDocumentListeners();
- public abstract boolean isLeaf();
+ for (int index = 0; index < listeners.length; ++index)
+ listeners[index].insertUpdate(event);
+ }
- public abstract int getEndOffset();
+ protected void fireRemoveUpdate(DocumentEvent event)
+ {
+ DocumentListener[] listeners = getDocumentListeners();
- public abstract int getElementCount();
+ for (int index = 0; index < listeners.length; ++index)
+ listeners[index].removeUpdate(event);
+ }
- public abstract int getElementIndex(int offset);
+ protected void fireUndoableEditUpdate(UndoableEditEvent event)
+ {
+ UndoableEditListener[] listeners = getUndoableEditListeners();
- public abstract int getStartOffset();
+ for (int index = 0; index < listeners.length; ++index)
+ listeners[index].undoableEditHappened(event);
}
- public interface AttributeContext
+ public int getAsynchronousLoadPriority()
{
- AttributeSet addAttribute(AttributeSet old, Object name, Object value);
- AttributeSet addAttributes(AttributeSet old, AttributeSet attributes);
- AttributeSet getEmptySet();
- void reclaim(AttributeSet attributes);
- AttributeSet removeAttribute(AttributeSet old, Object name);
- AttributeSet removeAttributes(AttributeSet old, AttributeSet attributes);
- AttributeSet removeAttributes(AttributeSet old, Enumeration names);
+ return 0;
}
- public class BranchElement extends AbstractElement
+ protected AttributeContext getAttributeContext()
{
- private static final long serialVersionUID = -8595176318868717313L;
-
- private int start;
- private int end;
- private Vector children = new Vector();
+ return null;
+ }
- public BranchElement(Element parent, AttributeSet attributes,
- int start, int end)
+ public Element getBidiRootElement()
{
- super(parent, attributes);
- this.start = start;
- this.end = end;
+ return null;
}
- public Enumeration children()
+ protected Content getContent()
{
- return children.elements();
+ return content;
}
- public boolean getAllowsChildren()
+ protected Thread getCurrentWriter()
{
- return true;
+ return null;
}
- public Element getElement(int index)
+ public Dictionary getDocumentProperties()
{
- return (Element) children.get(index);
+ return null;
}
- public int getElementCount()
+ public Position getEndPosition()
{
- return children.size();
+ return null;
}
- public int getElementIndex(int offset)
+ public int getLength()
{
- return children.indexOf(positionToElement(offset));
+ return content.length();
}
- public int getEndOffset()
+ public EventListener[] getListeners(Class listenerType)
{
- return end;
+ return listenerList.getListeners(listenerType);
}
- public String getName()
+ public Object getProperty(Object key)
{
- return "AbstractDocument.BranchElement";
+ return null;
}
- public int getStartOffset()
+ public Element[] getRootElements()
{
- return start;
+ return null;
}
- public boolean isLeaf()
+ public Position getStartPosition()
{
- return false;
+ return null;
}
- public Element positionToElement(int position)
+ public String getText(int offset, int length)
{
- // XXX: There is surely a better algorithm
- // as beginning from first element each time.
-
- for (int index = 0; index < children.size(); ++index)
+ try
{
- Element elem = (Element) children.get(index);
-
- if (elem.getStartOffset() <= position
- && position < elem.getEndOffset())
- return elem;
+ return content.getString(offset, length);
}
+ catch (Exception e)
+ {
+ System.out.println("Hmmm, fail to getText: " + offset + " -> "
+ + length);
return null;
}
-
- public void replace(int offset, int length, Element[] elems)
- {
- for (int index = 0 ; index < length; ++index)
- children.removeElementAt(offset);
-
- for (int index = 0 ; index < elems.length; ++index)
- children.add(offset + index, elems[index]);
}
- public String toString()
+ public void getText(int offset, int length, Segment txt)
{
- return getName() + ": " + "content";
- }
- }
+ String a = getText(offset, length);
- public interface Content
+ if (a == null)
{
- Position createPosition(int offset) throws BadLocationException;
+ txt.offset = 0;
+ txt.count = 0;
+ txt.array = new char[0];
- int length();
+ return;
+ }
- UndoableEdit insertString(int where, String str)
- throws BadLocationException;
+ txt.offset = offset;
+ txt.count = length;
- UndoableEdit remove(int where, int nitems) throws BadLocationException;
+ char[] chars = new char[a.length()];
- String getString(int where, int len) throws BadLocationException;
+ a.getChars(0, a.length(), chars, 0);
- void getChars(int where, int len, Segment txt) throws BadLocationException;
+ txt.array = chars;
}
- public class DefaultDocumentEvent extends CompoundEdit
- implements DocumentEvent
- {
- private static final long serialVersionUID = -7406103236022413522L;
-
- public int len;
- public int off;
-
- public Document getDocument()
+ public void insertString(int offs, String str, AttributeSet a)
+ throws BadLocationException
{
- return AbstractDocument.this;
+ content.insertString(offs, str);
}
- public int getLength()
+ protected void insertUpdate(DefaultDocumentEvent chng, AttributeSet attr)
{
- return len;
}
- public int getOffset()
+ protected void postRemoveUpdate(DefaultDocumentEvent chng)
{
- return off;
}
- public DocumentEvent.EventType getType()
+ public void putProperty(Object key, Object value)
{
- return null;
}
- public DocumentEvent.ElementChange getChange(Element elem)
+ public void readLock()
{
- return null;
- }
}
- public static class ElementEdit extends AbstractUndoableEdit
+ public void readUnlock()
{
- private static final long serialVersionUID = -1216620962142928304L;
}
- public class LeafElement extends AbstractElement
+ public void remove(int offs, int len)
{
- private static final long serialVersionUID = 5115368706941283802L;
-
- private int start;
- private int end;
+ }
- public LeafElement(Element parent, AttributeSet attributes,
- int start, int end)
+ /**
+ * Adds a <code>DocumentListener</code> object to this document.
+ *
+ * @param listener the listener to add
+ */
+ public void addDocumentListener(DocumentListener listener)
{
- super(parent, attributes);
- this.start = start;
- this.end = end;
+ listenerList.add(DocumentListener.class, listener);
}
- public Enumeration children()
- {
- return null;
+ /**
+ * Removes a <code>DocumentListener</code> object from this document.
+ *
+ * @param listener the listener to remove
+ */
+ public void removeDocumentListener(DocumentListener listener)
+ {
+ listenerList.remove(DocumentListener.class, listener);
}
- public boolean getAllowsChildren()
+ /**
+ * Returns add added <code>DocumentListener</code> objects.
+ *
+ * @return an array of listeners
+ */
+ public DocumentListener[] getDocumentListeners()
{
- return false;
+ return (DocumentListener[]) getListeners(DocumentListener.class);
}
- public Element getElement()
+ /**
+ * Adds a <code>UndoableEditListener</code> object to this document.
+ *
+ * @param listener the listener to add
+ */
+ public void addUndoableEditListener(UndoableEditListener listener)
{
- return null;
+ listenerList.add(UndoableEditListener.class, listener);
}
- public int getElementCount()
+ /**
+ * Removes a <code>UndoableEditListener</code> object from this document.
+ *
+ * @param listener the listener to remove
+ */
+ public void removeUndoableEditListener(UndoableEditListener listener)
{
- return 0;
+ listenerList.remove(UndoableEditListener.class, listener);
}
- public int getElementIndex(int offset)
+ /**
+ * Returns add added <code>UndoableEditListener</code> objects.
+ *
+ * @return an array of listeners
+ */
+ public UndoableEditListener[] getUndoableEditListeners()
{
- return -1;
+ return (UndoableEditListener[]) getListeners(UndoableEditListener.class);
}
- public int getEndOffset()
+ protected void removeUpdate(DefaultDocumentEvent chng)
{
- return end;
}
- public String getName()
+ public void render(Runnable r)
{
- return "AbstractDocument.LeafElement";
}
- public int getStartOffset()
+ public void setAsynchronousLoadPriority(int p)
{
- return start;
}
- public boolean isLeaf()
+ public void setDocumentProperties(Dictionary x)
{
- return true;
}
- public String toString()
+ protected void writeLock()
{
- return getName() + ": " + "content";
}
+
+ protected void writeUnlock()
+ {
}
- private static final long serialVersionUID = -116069779446114664L;
+ public interface AttributeContext
+ {
+ AttributeSet addAttribute(AttributeSet old, Object name, Object value);
- protected static final String BAD_LOCATION = "document location failure";
+ AttributeSet addAttributes(AttributeSet old, AttributeSet attributes);
- public static final String BidiElementName = "bidi level";
- public static final String ContentElementName = "content";
- public static final String ParagraphElementName = "paragraph";
- public static final String SectionElementName = "section";
- public static final String ElementNameAttribute = "$ename";
+ AttributeSet getEmptySet();
- Content content;
+ void reclaim(AttributeSet attributes);
- protected AbstractDocument(Content doc)
- {
- this(doc, null);
+ AttributeSet removeAttribute(AttributeSet old, Object name);
+
+ AttributeSet removeAttributes(AttributeSet old, AttributeSet attributes);
+
+ AttributeSet removeAttributes(AttributeSet old, Enumeration names);
}
- protected AbstractDocument(Content doc, AttributeContext context)
+ public interface Content
{
- content = doc;
- }
+ Position createPosition(int offset) throws BadLocationException;
- protected EventListenerList listenerList = new EventListenerList();
+ int length();
- // these still need to be implemented by a derived class:
- public abstract Element getParagraphElement(int pos);
+ UndoableEdit insertString(int where, String str)
+ throws BadLocationException;
- public abstract Element getDefaultRootElement();
+ UndoableEdit remove(int where, int nitems) throws BadLocationException;
- protected Element createBranchElement(Element parent, AttributeSet a)
- {
- return new BranchElement(parent, a, 0, 0);
- }
+ String getString(int where, int len) throws BadLocationException;
- protected Element createLeafElement(Element parent, AttributeSet a, int p0,
- int p1)
- {
- return new LeafElement(parent, a, p0, p1 - p0);
+ void getChars(int where, int len, Segment txt) throws BadLocationException;
}
- public Position createPosition(int offs)
- {
- final int a = offs;
- return new Position()
+ public abstract class AbstractElement
+ implements Element, TreeNode, Serializable
{
- public int getOffset()
+ private static final long serialVersionUID = 1265312733007397733L;
+ int count;
+ int offset;
+ AttributeSet attr;
+ Vector elts = new Vector();
+ String name;
+ Element parent;
+ Vector kids = new Vector();
+ TreeNode tree_parent;
+
+ public AbstractElement(Element p, AttributeSet s)
{
- return a;
- }
- };
+ parent = p;
+ attr = s;
}
- protected void fireChangedUpdate(DocumentEvent event)
+ public Enumeration children()
{
- DocumentListener[] listeners = getDocumentListeners();
-
- for (int index = 0; index < listeners.length; ++index)
- listeners[index].changedUpdate(event);
+ return kids.elements();
}
- protected void fireInsertUpdate(DocumentEvent event)
+ public boolean getAllowsChildren()
{
- DocumentListener[] listeners = getDocumentListeners();
-
- for (int index = 0; index < listeners.length; ++index)
- listeners[index].insertUpdate(event);
+ return true;
}
- protected void fireRemoveUpdate(DocumentEvent event)
+ public TreeNode getChildAt(int index)
{
- DocumentListener[] listeners = getDocumentListeners();
-
- for (int index = 0; index < listeners.length; ++index)
- listeners[index].removeUpdate(event);
+ return (TreeNode) kids.elementAt(index);
}
- protected void fireUndoableEditUpdate(UndoableEditEvent event)
+ public int getChildCount()
{
- UndoableEditListener[] listeners = getUndoableEditListeners();
-
- for (int index = 0; index < listeners.length; ++index)
- listeners[index].undoableEditHappened(event);
+ return kids.size();
}
- public int getAsynchronousLoadPriority()
+ public int getIndex(TreeNode node)
{
- return 0;
+ return kids.indexOf(node);
}
- protected AttributeContext getAttributeContext()
+ public TreeNode getParent()
{
- return null;
+ return tree_parent;
}
- public Element getBidiRootElement()
+ public AttributeSet getAttributes()
{
- return null;
+ return attr;
}
- protected Content getContent()
+ public Document getDocument()
{
- return content;
+ return AbstractDocument.this;
}
- protected Thread getCurrentWriter()
+ public Element getElement(int index)
{
- return null;
+ return (Element) elts.elementAt(index);
}
- public Dictionary getDocumentProperties()
+ public String getName()
{
- return null;
+ return name;
}
- public Position getEndPosition()
+ public Element getParentElement()
{
- return null;
+ return parent;
}
- public int getLength()
- {
- return content.length();
+ public abstract boolean isLeaf();
+
+ public abstract int getEndOffset();
+
+ public abstract int getElementCount();
+
+ public abstract int getElementIndex(int offset);
+
+ public abstract int getStartOffset();
}
- public EventListener[] getListeners(Class listenerType)
+ public class BranchElement extends AbstractElement
{
- return listenerList.getListeners(listenerType);
- }
+ private static final long serialVersionUID = -8595176318868717313L;
+ private int start;
+ private int end;
+ private Vector children = new Vector();
- public Object getProperty(Object key)
+ public BranchElement(Element parent, AttributeSet attributes, int start,
+ int end)
{
- return null;
+ super(parent, attributes);
+ this.start = start;
+ this.end = end;
}
- public Element[] getRootElements()
+ public Enumeration children()
{
- return null;
+ return children.elements();
}
- public Position getStartPosition()
+ public boolean getAllowsChildren()
{
- return null;
+ return true;
}
- public String getText(int offset, int length)
+ public Element getElement(int index)
{
- try
+ return (Element) children.get(index);
+ }
+
+ public int getElementCount()
{
- return content.getString(offset, length);
+ return children.size();
}
- catch (Exception e)
+
+ public int getElementIndex(int offset)
{
- System.out.println("Hmmm, fail to getText: " + offset + " -> "
- + length);
- return null;
+ return children.indexOf(positionToElement(offset));
}
+
+ public int getEndOffset()
+ {
+ return end;
}
- public void getText(int offset, int length, Segment txt)
+ public String getName()
{
- String a = getText(offset, length);
+ return "AbstractDocument.BranchElement";
+ }
- if (a == null)
+ public int getStartOffset()
{
- txt.offset = 0;
- txt.count = 0;
- txt.array = new char[0];
- return;
+ return start;
}
- txt.offset = offset;
- txt.count = length;
+ public boolean isLeaf()
+ {
+ return false;
+ }
- char[] chars = new char[a.length()];
+ public Element positionToElement(int position)
+ {
+ // XXX: There is surely a better algorithm
+ // as beginning from first element each time.
+ for (int index = 0; index < children.size(); ++index)
+ {
+ Element elem = (Element) children.get(index);
- a.getChars(0, a.length(), chars, 0);
+ if ((elem.getStartOffset() <= position)
+ && (position < elem.getEndOffset()))
+ return elem;
+ }
- txt.array = chars;
+ return null;
}
- public void insertString(int offs, String str, AttributeSet a)
- throws BadLocationException
+ public void replace(int offset, int length, Element[] elems)
{
- content.insertString(offs, str);
+ for (int index = 0; index < length; ++index)
+ children.removeElementAt(offset);
+
+ for (int index = 0; index < elems.length; ++index)
+ children.add(offset + index, elems[index]);
}
- protected void insertUpdate(DefaultDocumentEvent chng, AttributeSet attr)
+ public String toString()
{
+ return getName() + ": " + "content";
+ }
}
- protected void postRemoveUpdate(DefaultDocumentEvent chng)
+ public class DefaultDocumentEvent extends CompoundEdit
+ implements DocumentEvent
+ {
+ private static final long serialVersionUID = -7406103236022413522L;
+ public int len;
+ public int off;
+
+ public Document getDocument()
{
+ return AbstractDocument.this;
}
- public void putProperty(Object key, Object value)
+ public int getLength()
{
+ return len;
}
- public void readLock()
+ public int getOffset()
{
+ return off;
}
- public void readUnlock()
+ public DocumentEvent.EventType getType()
{
+ return null;
}
- public void remove(int offs, int len)
+ public DocumentEvent.ElementChange getChange(Element elem)
{
+ return null;
+ }
}
- /**
- * Adds a <code>DocumentListener</code> object to this document.
- *
- * @param listener the listener to add
- */
- public void addDocumentListener(DocumentListener listener)
+ public static class ElementEdit extends AbstractUndoableEdit
{
- listenerList.add(DocumentListener.class, listener);
+ private static final long serialVersionUID = -1216620962142928304L;
}
- /**
- * Removes a <code>DocumentListener</code> object from this document.
- *
- * @param listener the listener to remove
- */
- public void removeDocumentListener(DocumentListener listener)
+ public class LeafElement extends AbstractElement
{
- listenerList.remove(DocumentListener.class, listener);
+ private static final long serialVersionUID = 5115368706941283802L;
+ private int start;
+ private int end;
+
+ public LeafElement(Element parent, AttributeSet attributes, int start,
+ int end)
+ {
+ super(parent, attributes);
+ this.start = start;
+ this.end = end;
}
- /**
- * Returns add added <code>DocumentListener</code> objects.
- *
- * @return an array of listeners
- */
- public DocumentListener[] getDocumentListeners()
+ public Enumeration children()
{
- return (DocumentListener[]) getListeners(DocumentListener.class);
+ return null;
}
- /**
- * Adds a <code>UndoableEditListener</code> object to this document.
- *
- * @param listener the listener to add
- */
- public void addUndoableEditListener(UndoableEditListener listener)
+ public boolean getAllowsChildren()
{
- listenerList.add(UndoableEditListener.class, listener);
+ return false;
}
- /**
- * Removes a <code>UndoableEditListener</code> object from this document.
- *
- * @param listener the listener to remove
- */
- public void removeUndoableEditListener(UndoableEditListener listener)
+ public Element getElement()
{
- listenerList.remove(UndoableEditListener.class, listener);
+ return null;
}
- /**
- * Returns add added <code>UndoableEditListener</code> objects.
- *
- * @return an array of listeners
- */
- public UndoableEditListener[] getUndoableEditListeners()
+ public int getElementCount()
{
- return (UndoableEditListener[]) getListeners(UndoableEditListener.class);
+ return 0;
}
- protected void removeUpdate(DefaultDocumentEvent chng)
+ public int getElementIndex(int offset)
{
+ return -1;
}
- public void render(Runnable r)
+ public int getEndOffset()
{
+ return end;
}
- public void setAsynchronousLoadPriority(int p)
+ public String getName()
{
+ return "AbstractDocument.LeafElement";
}
- public void setDocumentProperties(Dictionary x)
+ public int getStartOffset()
{
+ return start;
}
- protected void writeLock()
+ public boolean isLeaf()
{
+ return true;
}
- protected void writeUnlock()
+ public String toString()
{
+ return getName() + ": " + "content";
+ }
}
}