This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
[GUI] Patch: javax.swing.text - little improvements.
- From: Michael Koch <konqueror at gmx dot de>
- To: java-patches at gcc dot gnu dot org
- Date: Wed, 16 Jun 2004 12:09:53 +0200
- Subject: [GUI] Patch: javax.swing.text - little improvements.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi list,
I just commited the attached patch to improve javax.swing.text more.
Michael
2004-06-16 Michael Koch <konqueror@gmx.de>
* javax/swing/event/UndoableEditListener.java: Reformatted.
* javax/swing/text/AbstractDocument.java
(AbstractDocument): Implements java.io.Serializable.
(doc_list): Removed.
(undo_list): Removed.
(AbstractElement.serialVerionUID): New field.
(BranchElement.serialVerionUID): Likewise.
(DefaultDocumentEvent.serialVerionUID): Likewise.
(ElementEdit.serialVerionUID): Likewise.
(LeafElement.serialVerionUID): Likewise.
(serialVerionUID): Likewise.
(BAD_LOCATION): New constant.
(BidiElementName): Likewise.
(ContentElementName): Likewise.
(ParagraphElementName): Likewise.
(SectionElementName): Likewise.
(ElementNameAttribute): Likewise.
(AbstractDocument): Made protected.
(AbstractDocument): New construtor.
(listenerList): New field.
(fireChangedUpdate): Implemented.
(fireInsertUpdate): Likewise.
(fireRemoveUpdate): Likewise.
(fireUndoableEditUpdate): Likewise.
(getListeners): Likewise.
(addDocumentListener): Likewise.
(removeDocumentListener): Likewise.
(addUndoableEditListener): Likewise.
(removeUndoableEditListener): Likewise.
(getDocumentListeners): New method.
(getUndoableEditListeners): Likewise.
(getAsynchronousLoadPriority): Made public.
(getBidiRootElement): Likewise.
(setAsynchronousLoadPriority): Likewise.
(setDocumentProperties): Likewise.
* javax/swing/text/BadLocationException.java
(serialVerionUID): New field.
* javax/swing/text/DefaultCaret.java
(changeEvent): New field.
(listenerList): Likewise.
(changes): Removed.
(addChangeListener): Reimplemented.
(removeChangeListener): Likewise.
(getListeners): New method.
(getChangeListeners): Likwise.
(getComponent): Likewise.
* javax/swing/text/GapContent.java
(GapContent): Implements java.io.Serializable.
(serialVerionUID): New field.
- --
Homepage: http://www.worldforge.org/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
iD8DBQFA0Bx5WSOgCCdjSDsRAqmcAKCOOi32bA8lKU/FRI2lcoYak5DpEQCfSkII
JD/XymcyJXW7E3GYnAp8UC4=
=Zrnl
-----END PGP SIGNATURE-----
Index: javax/swing/event/UndoableEditListener.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/event/UndoableEditListener.java,v
retrieving revision 1.2
diff -u -b -B -r1.2 UndoableEditListener.java
--- javax/swing/event/UndoableEditListener.java 12 Oct 2003 13:25:59 -0000 1.2
+++ javax/swing/event/UndoableEditListener.java 16 Jun 2004 10:04:30 -0000
@@ -1,5 +1,5 @@
/* UndoableEditListener.java --
- Copyright (C) 2002 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -37,9 +37,9 @@
package javax.swing.event;
-// Imports
import java.util.EventListener;
+
/**
* UndoableEditListener public interface
* @author Andrew Selkirk
@@ -45,13 +45,12 @@
* @author Andrew Selkirk
* @author Ronald Veldema
*/
-public interface UndoableEditListener extends EventListener {
-
+public interface UndoableEditListener extends EventListener
+{
/**
* Undoable edit has happened
+ *
* @param event Undoable Edit Event
*/
void undoableEditHappened(UndoableEditEvent event);
-
-
-} // UndoableEditListener
+}
Index: javax/swing/text/AbstractDocument.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/text/AbstractDocument.java,v
retrieving revision 1.3.8.2
diff -u -b -B -r1.3.8.2 AbstractDocument.java
--- javax/swing/text/AbstractDocument.java 11 Jun 2004 08:05:18 -0000 1.3.8.2
+++ javax/swing/text/AbstractDocument.java 16 Jun 2004 10:04:30 -0000
@@ -37,6 +37,7 @@
package javax.swing.text;
+import java.io.Serializable;
import java.util.Dictionary;
import java.util.Enumeration;
import java.util.EventListener;
@@ -41,8 +42,10 @@
import java.util.Enumeration;
import java.util.EventListener;
import java.util.Vector;
+
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
+import javax.swing.event.EventListenerList;
import javax.swing.event.UndoableEditEvent;
import javax.swing.event.UndoableEditListener;
import javax.swing.tree.TreeNode;
@@ -50,20 +53,14 @@
public abstract class AbstractDocument
- implements Document
+ implements Document, Serializable
{
- Vector doc_list = new Vector();
- Vector undo_list = new Vector();
-
- // these still need to be implemented by a derived class:
- public abstract Element getParagraphElement(int pos);
-
- public abstract Element getDefaultRootElement();
-
// some inner classes sun says I should have:
abstract class AbstractElement
implements Element, TreeNode
{
+ private static final long serialVersionUID = 1265312733007397733L;
+
int count;
int offset;
AttributeSet attr;
@@ -151,6 +148,8 @@
class BranchElement extends AbstractElement
{
+ private static final long serialVersionUID = -8595176318868717313L;
+
public BranchElement(Element e, AttributeSet a, int s, int end)
{
super(e, a);
@@ -201,6 +200,8 @@
class DefaultDocumentEvent
implements DocumentEvent
{
+ private static final long serialVersionUID = -7406103236022413522L;
+
public int len;
public int off;
@@ -232,10 +233,13 @@
static class ElementEdit
{
+ private static final long serialVersionUID = -1216620962142928304L;
}
class LeafElement extends AbstractElement
{
+ private static final long serialVersionUID = 5115368706941283802L;
+
LeafElement(Element e, AttributeSet a, int s, int end)
{
super(e, a);
@@ -267,27 +271,34 @@
}
}
+ 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;
- AbstractDocument(Content doc)
+ protected AbstractDocument(Content doc)
{
- content = doc;
+ this(doc, null);
}
- /********************************************************
- *
- * the meat:
- *
- ***********/
- public void addDocumentListener(DocumentListener listener)
+ protected AbstractDocument(Content doc, AttributeContext context)
{
- doc_list.addElement(listener);
+ content = doc;
}
- public void addUndoableEditListener(UndoableEditListener listener)
- {
- undo_list.addElement(listener);
- }
+ protected EventListenerList listenerList = new EventListenerList();
+
+ // these still need to be implemented by a derived class:
+ public abstract Element getParagraphElement(int pos);
+
+ public abstract Element getDefaultRootElement();
protected Element createBranchElement(Element parent, AttributeSet a)
{
@@ -312,23 +323,39 @@
};
}
- protected void fireChangedUpdate(DocumentEvent e)
+ protected void fireChangedUpdate(DocumentEvent event)
{
+ DocumentListener[] listeners = getDocumentListeners();
+
+ for (int index = 0; index < listeners.length; ++index)
+ listeners[index].changedUpdate(event);
}
- protected void fireInsertUpdate(DocumentEvent e)
+ protected void fireInsertUpdate(DocumentEvent event)
{
+ DocumentListener[] listeners = getDocumentListeners();
+
+ for (int index = 0; index < listeners.length; ++index)
+ listeners[index].insertUpdate(event);
}
- protected void fireRemoveUpdate(DocumentEvent e)
+ protected void fireRemoveUpdate(DocumentEvent event)
{
+ DocumentListener[] listeners = getDocumentListeners();
+
+ for (int index = 0; index < listeners.length; ++index)
+ listeners[index].removeUpdate(event);
}
- protected void fireUndoableEditUpdate(UndoableEditEvent e)
+ protected void fireUndoableEditUpdate(UndoableEditEvent event)
{
+ UndoableEditListener[] listeners = getUndoableEditListeners();
+
+ for (int index = 0; index < listeners.length; ++index)
+ listeners[index].undoableEditHappened(event);
}
- int getAsynchronousLoadPriority()
+ public int getAsynchronousLoadPriority()
{
return 0;
}
@@ -338,7 +365,7 @@
return null;
}
- Element getBidiRootElement()
+ public Element getBidiRootElement()
{
return null;
}
@@ -370,7 +397,7 @@
public EventListener[] getListeners(Class listenerType)
{
- return null;
+ return listenerList.getListeners(listenerType);
}
public Object getProperty(Object key)
@@ -460,12 +487,64 @@
{
}
+ /**
+ * Adds a <code>DocumentListener</code> object to this document.
+ *
+ * @param listener the listener to add
+ */
+ public void addDocumentListener(DocumentListener listener)
+ {
+ listenerList.add(DocumentListener.class, listener);
+ }
+
+ /**
+ * 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);
+ }
+
+ /**
+ * Returns add added <code>DocumentListener</code> objects.
+ *
+ * @return an array of listeners
+ */
+ public DocumentListener[] getDocumentListeners()
+ {
+ return (DocumentListener[]) getListeners(DocumentListener.class);
}
+ /**
+ * Adds a <code>UndoableEditListener</code> object to this document.
+ *
+ * @param listener the listener to add
+ */
+ public void addUndoableEditListener(UndoableEditListener listener)
+ {
+ listenerList.add(UndoableEditListener.class, listener);
+ }
+
+ /**
+ * Removes a <code>UndoableEditListener</code> object from this document.
+ *
+ * @param listener the listener to remove
+ */
public void removeUndoableEditListener(UndoableEditListener listener)
{
+ listenerList.remove(UndoableEditListener.class, listener);
+ }
+
+ /**
+ * Returns add added <code>UndoableEditListener</code> objects.
+ *
+ * @return an array of listeners
+ */
+ public UndoableEditListener[] getUndoableEditListeners()
+ {
+ return (UndoableEditListener[]) getListeners(UndoableEditListener.class);
}
protected void removeUpdate(DefaultDocumentEvent chng)
@@ -476,11 +555,11 @@
{
}
- void setAsynchronousLoadPriority(int p)
+ public void setAsynchronousLoadPriority(int p)
{
}
- void setDocumentProperties(Dictionary x)
+ public void setDocumentProperties(Dictionary x)
{
}
Index: javax/swing/text/BadLocationException.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/text/BadLocationException.java,v
retrieving revision 1.2.20.1
diff -u -b -B -r1.2.20.1 BadLocationException.java
--- javax/swing/text/BadLocationException.java 13 Jun 2004 07:21:44 -0000 1.2.20.1
+++ javax/swing/text/BadLocationException.java 16 Jun 2004 10:04:30 -0000
@@ -39,6 +39,8 @@
public class BadLocationException extends Exception
{
+ private static final long serialVersionUID = -7712259886815656766L;
+
int offset;
/**
Index: javax/swing/text/DefaultCaret.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/text/DefaultCaret.java,v
retrieving revision 1.3.8.2
diff -u -b -B -r1.3.8.2 DefaultCaret.java
--- javax/swing/text/DefaultCaret.java 13 Jun 2004 07:21:44 -0000 1.3.8.2
+++ javax/swing/text/DefaultCaret.java 16 Jun 2004 10:04:30 -0000
@@ -44,15 +44,28 @@
import java.awt.event.FocusListener;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
-import java.util.Vector;
+import java.util.EventListener;
+
+import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
+import javax.swing.event.EventListenerList;
public class DefaultCaret extends Rectangle
implements Caret, FocusListener, MouseListener, MouseMotionListener
{
+ protected ChangeEvent changeEvent = new ChangeEvent(this);
+ protected EventListenerList listenerList = new EventListenerList();
+
Color color = new Color(0, 0, 0);
JTextComponent parent;
+ Point magic = null;
+ int mark = 0;
+ boolean vis_sel = true;
+ int blink = 500;
+ int dot = 0;
+ boolean vis = true;
+
public void mouseDragged(java.awt.event.MouseEvent evt)
{
@@ -90,7 +103,6 @@
{
}
- // caret methods:
public void deinstall(JTextComponent c)
{
parent.removeFocusListener(this);
@@ -107,8 +118,6 @@
repaint();
}
- Point magic = null;
-
public void setMagicCaretPosition(Point p)
{
magic = p;
@@ -119,15 +128,11 @@
return magic;
}
- int mark = 0;
-
public int getMark()
{
return mark;
}
- boolean vis_sel = true;
-
public void setSelectionVisible(boolean v)
{
vis_sel = v;
@@ -151,19 +156,38 @@
g.drawLine(x, y, x, y + height);
}
- Vector changes = new Vector();
+ public EventListener[] getListeners(Class listenerType)
+ {
+ return listenerList.getListeners(listenerType);
+ }
- public void addChangeListener(ChangeListener l)
+ public void addChangeListener(ChangeListener listener)
{
- changes.addElement(l);
+ listenerList.add(ChangeListener.class, listener);
}
- public void removeChangeListener(ChangeListener l)
+ public void removeChangeListener(ChangeListener listener)
{
- changes.removeElement(l);
+ listenerList.remove(ChangeListener.class, listener);
}
- int blink = 500;
+ public ChangeListener[] getChangeListeners()
+ {
+ return (ChangeListener[]) getListeners(ChangeListener.class);
+ }
+
+ protected void fireStateChanged()
+ {
+ ChangeListener[] listeners = getChangeListeners();
+
+ for (int index = 0; index < listeners.length; ++index)
+ listeners[index].stateChanged(changeEvent);
+ }
+
+ protected final JTextComponent getComponent()
+ {
+ return parent;
+ }
public int getBlinkRate()
{
@@ -175,8 +199,6 @@
blink = rate;
}
- int dot = 0;
-
public int getDot()
{
return dot;
@@ -193,8 +215,6 @@
repaint();
}
- boolean vis = true;
-
public boolean isVisible()
{
return vis;
Index: javax/swing/text/GapContent.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/text/GapContent.java,v
retrieving revision 1.2.8.1
diff -u -b -B -r1.2.8.1 GapContent.java
--- javax/swing/text/GapContent.java 11 Jun 2004 08:05:18 -0000 1.2.8.1
+++ javax/swing/text/GapContent.java 16 Jun 2004 10:04:30 -0000
@@ -37,6 +37,7 @@
package javax.swing.text;
+import java.io.Serializable;
// too lazy to make a real gapcontent.
// lets just use a stringbuffer instead.
@@ -42,10 +43,11 @@
// lets just use a stringbuffer instead.
import javax.swing.undo.UndoableEdit;
-
public class GapContent
- implements AbstractDocument.Content
+ implements AbstractDocument.Content, Serializable
{
+ private static final long serialVersionUID = 8374645204155842629L;
+
StringBuffer buf = new StringBuffer();
public GapContent()