This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
[gui] Patch: javax.swing.text enhancement
- From: Michael Koch <konqueror at gmx dot de>
- To: java-patches at gcc dot gnu dot org
- Date: Sun, 20 Jun 2004 17:30:18 +0200
- Subject: [gui] Patch: javax.swing.text enhancement
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi list,
I just commited the attached patch to fix more issues with
javax.swing.text.
Michael
2004-06-20 Michael Koch <konqueror@gmx.de>
* javax/swing/text/AbstractDocument.java
(BranchElement): Implemented.
(LeafElement): Implemented.
* javax/swing/text/DefaultCaret.java:
Import used classes.
(serialVersionUID): New constant.
* javax/swing/text/JTextComponent.java
(AccessibleJTextComponent): Removed dead declaration.
(caretPos): Removed.
(setCaret): New method.
* javax/swing/text/PlainDocument.java
(rootElement): New field.
(PlainDocument): Initialize rootElement.
(createDefaultRoot): New method.
(getDefaultRootElement): Implemented.
* javax/swing/text/View.java: Reformatted.
* javax/swing/text/ViewFactory.java
(create): Added javadoc.
- --
Homepage: http://www.worldforge.org/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
iD8DBQFA1a2MWSOgCCdjSDsRAtlIAJ44w3LcuQXKGYNb1ySA4M4ma6NNkQCeNXgv
QyDE8amRjLYa8e3x00g+Hgo=
=D9qc
-----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.6
diff -u -b -B -r1.3.8.6 AbstractDocument.java
--- javax/swing/text/AbstractDocument.java 18 Jun 2004 10:23:14 -0000 1.3.8.6
+++ javax/swing/text/AbstractDocument.java 20 Jun 2004 15:26:06 -0000
@@ -158,34 +158,91 @@
{
private static final long serialVersionUID = -8595176318868717313L;
- public BranchElement(Element e, AttributeSet a, int s, int end)
+ private int start;
+ private int end;
+ private Vector children = new Vector();
+
+ public BranchElement(Element parent, AttributeSet attributes,
+ int start, int end)
{
- super(e, a);
+ super(parent, attributes);
+ this.start = start;
+ this.end = end;
}
- public boolean isLeaf()
+ public Enumeration children()
{
- return false;
+ return children.elements();
}
- public int getEndOffset()
+ public boolean getAllowsChildren()
{
- return 0;
+ return true;
+ }
+
+ public Element getElement(int index)
+ {
+ return (Element) children.get(index);
}
public int getElementCount()
{
- return 0;
+ return children.size();
}
public int getElementIndex(int offset)
{
- return 0;
+ return children.indexOf(positionToElement(offset));
+ }
+
+ public int getEndOffset()
+ {
+ return end;
+ }
+
+ public String getName()
+ {
+ return "AbstractDocument.BranchElement";
}
public int getStartOffset()
{
- return 0;
+ return start;
+ }
+
+ public boolean isLeaf()
+ {
+ return false;
+ }
+
+ 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);
+
+ if (elem.getStartOffset() <= position
+ && position < elem.getEndOffset())
+ return elem;
+ }
+
+ return null;
+ }
+
+ public void replace(int offset, int length, Element[] elems)
+ {
+ children.removeRange(offset, offset + length);
+
+ for (int index = 0 ; index < length; ++index)
+ children.add(offset + index, elems[index]);
+ }
+
+ public String toString()
+ {
+ return getName() + ": " + "content";
}
}
@@ -248,19 +305,30 @@
{
private static final long serialVersionUID = 5115368706941283802L;
- public LeafElement(Element e, AttributeSet a, int s, int end)
+ private int start;
+ private int end;
+
+ public LeafElement(Element parent, AttributeSet attributes,
+ int start, int end)
{
- super(e, a);
+ super(parent, attributes);
+ this.start = start;
+ this.end = end;
}
- public boolean isLeaf()
+ public Enumeration children()
{
- return true;
+ return null;
}
- public int getEndOffset()
+ public boolean getAllowsChildren()
{
- return 0;
+ return false;
+ }
+
+ public Element getElement()
+ {
+ return null;
}
public int getElementCount()
@@ -270,12 +338,32 @@
public int getElementIndex(int offset)
{
- return 0;
+ return -1;
+ }
+
+ public int getEndOffset()
+ {
+ return end;
+ }
+
+ public String getName()
+ {
+ return "AbstractDocument.LeafElement";
}
public int getStartOffset()
{
- return 0;
+ return start;
+ }
+
+ public boolean isLeaf()
+ {
+ return true;
+ }
+
+ public String toString()
+ {
+ return getName() + ": " + "content";
}
}
Index: javax/swing/text/DefaultCaret.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/text/DefaultCaret.java,v
retrieving revision 1.3.8.3
diff -u -b -B -r1.3.8.3 DefaultCaret.java
--- javax/swing/text/DefaultCaret.java 16 Jun 2004 10:06:47 -0000 1.3.8.3
+++ javax/swing/text/DefaultCaret.java 20 Jun 2004 15:26:06 -0000
@@ -41,7 +41,9 @@
import java.awt.Graphics;
import java.awt.Point;
import java.awt.Rectangle;
+import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
+import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.util.EventListener;
@@ -54,6 +56,8 @@
public class DefaultCaret extends Rectangle
implements Caret, FocusListener, MouseListener, MouseMotionListener
{
+ private static final long serialVersionUID = 228155774675466193L;
+
protected ChangeEvent changeEvent = new ChangeEvent(this);
protected EventListenerList listenerList = new EventListenerList();
@@ -67,39 +71,39 @@
boolean vis = true;
- public void mouseDragged(java.awt.event.MouseEvent evt)
+ public void mouseDragged(MouseEvent evt)
{
}
- public void mouseMoved(java.awt.event.MouseEvent evt)
+ public void mouseMoved(MouseEvent evt)
{
}
- public void mouseClicked(java.awt.event.MouseEvent evt)
+ public void mouseClicked(MouseEvent evt)
{
}
- public void mouseEntered(java.awt.event.MouseEvent evt)
+ public void mouseEntered(MouseEvent evt)
{
}
- public void mouseExited(java.awt.event.MouseEvent evt)
+ public void mouseExited(MouseEvent evt)
{
}
- public void mousePressed(java.awt.event.MouseEvent evt)
+ public void mousePressed(MouseEvent evt)
{
}
- public void mouseReleased(java.awt.event.MouseEvent evt)
+ public void mouseReleased(MouseEvent evt)
{
}
- public void focusGained(java.awt.event.FocusEvent evt)
+ public void focusGained(FocusEvent evt)
{
}
- public void focusLost(java.awt.event.FocusEvent evt)
+ public void focusLost(FocusEvent evt)
{
}
Index: javax/swing/text/JTextComponent.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/text/JTextComponent.java,v
retrieving revision 1.4.2.8
diff -u -b -B -r1.4.2.8 JTextComponent.java
--- javax/swing/text/JTextComponent.java 18 Jun 2004 10:23:14 -0000 1.4.2.8
+++ javax/swing/text/JTextComponent.java 20 Jun 2004 15:26:06 -0000
@@ -67,12 +67,6 @@
public abstract class JTextComponent extends JComponent
implements Scrollable, Accessible
{
-// public class AccessibleJTextComponent extends AccessibleJComponent
-// implements AccessibleText, CaretListener, DocumentListener,
-// AccessibleAction, AccessibleEditableText
-// {
-// }
-
/**
* AccessibleJTextComponent
*/
@@ -82,11 +76,6 @@
private static final long serialVersionUID = 7664188944091413696L;
/**
- * caretPos
- */
- int caretPos;
-
- /**
* Constructor AccessibleJTextComponent
* @param component TODO
*/
@@ -461,6 +450,17 @@
}
/**
+ * Sets a new <code>Caret</code> for this text component.
+ *
+ * @param newCaret the new <code>Caret</code> to set
+ */
+ public void setCaret(Caret newCaret)
+ {
+ firePropertyChange("caret", caret, newCaret);
+ caret = newCaret;
+ }
+
+ /**
* Retrisves the current caret position.
*
* @return the current position
Index: javax/swing/text/PlainDocument.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/text/PlainDocument.java,v
retrieving revision 1.1.52.2
diff -u -b -B -r1.1.52.2 PlainDocument.java
--- javax/swing/text/PlainDocument.java 16 Jun 2004 10:32:00 -0000 1.1.52.2
+++ javax/swing/text/PlainDocument.java 20 Jun 2004 15:26:06 -0000
@@ -44,6 +44,7 @@
public static final String lineLimitAttribute = "lineLimit";
public static final String tabSizeAttribute = "tabSize";
+ private Element rootElement;
private int tabSize;
public PlainDocument()
@@ -55,11 +56,22 @@
{
super(content);
tabSize = 8;
+ rootElement = createDefaultRoot();
+ }
+
+ protected AbstractDocument.AbstractElement createDefaultRoot()
+ {
+ BranchElement rootElement =
+ (BranchElement) createBranchElement(null, null);
+ Element[] lines = new Element[1];
+ lines[0] = createLeafElement(rootElement, null, 0, 1);
+ rootElement.replace(0, 0, lines);
+ return rootElement;
}
public Element getDefaultRootElement()
{
- return null;
+ return rootElement;
}
public Element getParagraphElement(int pos)
Index: javax/swing/text/View.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/text/View.java,v
retrieving revision 1.2
diff -u -b -B -r1.2 View.java
--- javax/swing/text/View.java 10 Jan 2004 21:07:44 -0000 1.2
+++ javax/swing/text/View.java 20 Jun 2004 15:26:06 -0000
@@ -37,6 +37,7 @@
package javax.swing.text;
+import java.awt.Container;
import java.awt.Graphics;
import java.awt.Shape;
import java.util.Vector;
@@ -44,97 +45,119 @@
public abstract class View implements SwingConstants
{
- static int BadBreakWeight;
- static int ExcellentBreakWeight;
- static int ForcedBreakWeight;
- static int GoodBreakWeight;
-
- public final static int X_AXIS = 0;
- public final static int Y_AXIS = 1;
-
- float width, height;
- Element elt;
- View parent;
-
- /**
- * this vector contains the views ordered at offsets...
- */
- Vector v = new Vector();
-
+ public static final int BadBreakWeight = 0;
+ public static final int ExcellentBreakWeight = 2000;
+ public static final int ForcedBreakWeight = 3000;
+ public static final int GoodBreakWeight = 1000;
+
+ public static final int X_AXIS = 0;
+ public static final int Y_AXIS = 1;
+
+ private float width, height;
+ private Element elt;
+ private View parent;
public View(Element elem)
{
elt = elem;
}
- public int getViewCount()
+ public abstract void paint(Graphics g, Shape s);
+
+ public void setParent(View a)
{
- return v.size();
+ parent = a;
}
- public View getView(int a)
+ public View getParent()
{
- return (View) v.get(a);
+ return parent;
}
- public void remove(int i)
+ public void setSize(int w, int h)
{
- v.removeElementAt(i);
+ width = w;
+ height = h;
}
- public void insert(int off, View view)
+ public Container getContainer()
{
- v.insertElementAt(view, off);
+ return parent.getContainer();
}
- public void append(View view)
+ public Document getDocument()
{
- v.addElement(view);
+ return getElement().getDocument();
}
- public void paint(Graphics g, Shape allocation)
+ public Element getElement()
{
- System.out.println("view.paint() !!!!");
+ return elt;
}
- public void setParent(View a)
+ public abstract float getPreferredSpan(int axis);
+
+ public float getAlignment(int axis)
{
- parent = a;
+ return 0.5f;
}
- public View getParent()
+ public AttributeSet getAttributes()
{
- return parent;
+ return elt.getAttributes();
}
- public void setSize(int w, int h)
+ public boolean isVisible()
{
- width = w;
- height = h;
+ return true;
}
- public Document getDocument()
+ public int getViewCount()
{
- return getElement().getDocument();
+ return 0;
}
- public Element getElement()
+ public View getView(int index)
{
- return elt;
+ return null;
}
- public float getPreferredSpan(int a)
+ public ViewFactory getViewFactory()
{
- switch (a)
+ return parent != null ? parent.getViewFactory() : null;
+ }
+
+ public void replace(int offset, int length, View[] views)
{
- case X_AXIS: return width;
- case Y_AXIS: return height;
- default:
+ // Default implementation does nothing.
+ }
+
+ public void insert(int offset, View view)
{
- System.err.println("I sure wish Java had enums !!! ");
- return 0;
+ View[] array = { view };
+ replace(offset, 1, array);
}
+
+ public void append(View view)
+ {
+ View[] array = { view };
+ replace(getViewCount(), 1, array);
+ }
+
+ public void removeAll()
+ {
+ replace(0, getViewCount(), null);
}
+
+ public void remove(int index)
+ {
+ replace(index, 1, null);
+ }
+
+ public View createFragment(int p0, int p1)
+ {
+ // The default implementation doesnt support fragmentation.
+ return this;
}
}
Index: javax/swing/text/ViewFactory.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/text/ViewFactory.java,v
retrieving revision 1.2
diff -u -b -B -r1.2 ViewFactory.java
--- javax/swing/text/ViewFactory.java 12 Oct 2003 13:33:32 -0000 1.2
+++ javax/swing/text/ViewFactory.java 20 Jun 2004 15:26:06 -0000
@@ -1,5 +1,5 @@
/* ViewFactory.java --
- Copyright (C) 2002 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -39,5 +39,12 @@
public interface ViewFactory
{
- View create (Element elem);
+ /**
+ * Creates a view for a given element.
+ *
+ * @param elem them element to create view for
+ *
+ * @return a new created view
+ */
+ View create(Element elem);
}