This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
[gui] Patch: javax.swing.text
- From: Michael Koch <konqueror at gmx dot de>
- To: java-patches at gcc dot gnu dot org
- Date: Wed, 25 Aug 2004 15:00:42 +0200
- Subject: [gui] Patch: javax.swing.text
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi list,
I commited the attached patch in preparation for the caret support and
to fix tab stop handling in JTextField.
Michael
2004-08-25 Michael Koch <konqueror@gmx.de>
* javax/swing/text/AbstractDocument.java
(createBranchElement): Use new constructor of BranchElement.
(createLeafElement): Renamed arguments.
(getRootElements): Implemented.
(BranchElement.start): Removed.
(BranchElement.end): Likewise.
(BranchElement.BranchElement): Fixed arguments.
(BranchElement.getEndOffset): Reimplemented.
(BranchElement.getStartOffset): Likewis.
* javax/swing/text/DefaultCaret.java
(paint): Draw simple vertical line as caret instead of a rectangle.
* javax/swing/text/JTextComponent.java
(setText): Use doc directly.
* javax/swing/text/PlainView.java
(nextTabStop): Implemented.
* javax/swing/text/Utilities.java
(drawTabbedText): nextTabStop() returns an absolute x position.
(getTabbedTextWidth): Likewise.
- --
Homepage: http://www.worldforge.org/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
iD8DBQFBLI2CWSOgCCdjSDsRAsMoAJ99DUHl85KqUO/WOjnW8VBuGUEcyACgjP9x
NMH98DRV/IVYkGwY7IPvrnc=
=/RC9
-----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.17
diff -u -r1.3.8.17 AbstractDocument.java
--- javax/swing/text/AbstractDocument.java 24 Aug 2004 22:00:29 -0000 1.3.8.17
+++ javax/swing/text/AbstractDocument.java 25 Aug 2004 12:53:44 -0000
@@ -85,15 +85,16 @@
public abstract Element getDefaultRootElement();
- protected Element createBranchElement(Element parent, AttributeSet a)
+ protected Element createBranchElement(Element parent,
+ AttributeSet attributes)
{
- return new BranchElement(parent, a, 0, 0);
+ return new BranchElement(parent, attributes);
}
- protected Element createLeafElement(Element parent, AttributeSet a, int p0,
- int p1)
+ protected Element createLeafElement(Element parent, AttributeSet attributes,
+ int start, int end)
{
- return new LeafElement(parent, a, p0, p1 - p0);
+ return new LeafElement(parent, attributes, start, end);
}
public Position createPosition(final int offset) throws BadLocationException
@@ -200,7 +201,9 @@
public Element[] getRootElements()
{
- return null;
+ Element[] elements = new Element[1];
+ elements[0] = getDefaultRootElement();
+ return elements;
}
public Position getStartPosition()
@@ -577,16 +580,12 @@
public class BranchElement extends AbstractElement
{
private static final long serialVersionUID = -8595176318868717313L;
- private int start;
- private int end;
+
private Vector children = new Vector();
- public BranchElement(Element parent, AttributeSet attributes, int start,
- int end)
+ public BranchElement(Element parent, AttributeSet attributes)
{
super(parent, attributes);
- this.start = start;
- this.end = end;
}
public Enumeration children()
@@ -616,7 +615,7 @@
public int getEndOffset()
{
- return end;
+ return ((Element) children.lastElement()).getEndOffset();
}
public String getName()
@@ -626,7 +625,7 @@
public int getStartOffset()
{
- return start;
+ return ((Element) children.firstElement()).getStartOffset();
}
public boolean isLeaf()
Index: javax/swing/text/DefaultCaret.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/text/DefaultCaret.java,v
retrieving revision 1.3.8.7
diff -u -r1.3.8.7 DefaultCaret.java
--- javax/swing/text/DefaultCaret.java 13 Aug 2004 15:20:12 -0000 1.3.8.7
+++ javax/swing/text/DefaultCaret.java 25 Aug 2004 12:53:44 -0000
@@ -191,7 +191,7 @@
if (visible)
{
g.setColor(textComponent.getCaretColor());
- g.drawRect(rect.x, rect.y, 2, rect.height);
+ g.drawLine(rect.x, rect.y, rect.x, rect.y + rect.height);
}
}
Index: javax/swing/text/JTextComponent.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/text/JTextComponent.java,v
retrieving revision 1.4.2.19
diff -u -r1.4.2.19 JTextComponent.java
--- javax/swing/text/JTextComponent.java 24 Aug 2004 22:00:29 -0000 1.4.2.19
+++ javax/swing/text/JTextComponent.java 25 Aug 2004 12:53:44 -0000
@@ -873,8 +873,8 @@
{
try
{
- getDocument().remove(0, doc.getLength());
- getDocument().insertString(0, text, null);
+ doc.remove(0, doc.getLength());
+ doc.insertString(0, text, null);
}
catch (BadLocationException e)
{
Index: javax/swing/text/PlainView.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/text/PlainView.java,v
retrieving revision 1.1.2.2
diff -u -r1.1.2.2 PlainView.java
--- javax/swing/text/PlainView.java 14 Aug 2004 07:43:23 -0000 1.1.2.2
+++ javax/swing/text/PlainView.java 25 Aug 2004 12:53:44 -0000
@@ -170,10 +170,18 @@
return 8;
}
+ /**
+ * Returns the next tab stop position after a given reference position.
+ *
+ * This implementation ignores the <code>tabStop</code> argument.
+ *
+ * @param x the current x position in pixels
+ * @param tabStop the position within the text stream that the tab occured at
+ */
public float nextTabStop(float x, int tabStop)
{
- System.out.println("Michael: PlainView.nextTabpStop: missing implementation");
- return x;
+ float tabSizePixels = getTabSize() + metrics.charWidth('m');
+ return (float) (Math.floor(x / tabSizePixels) + 1) * tabSizePixels;
}
public float getPreferredSpan(int axis)
Index: javax/swing/text/Utilities.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/text/Attic/Utilities.java,v
retrieving revision 1.1.2.3
diff -u -r1.1.2.3 Utilities.java
--- javax/swing/text/Utilities.java 24 Aug 2004 22:00:29 -0000 1.1.2.3
+++ javax/swing/text/Utilities.java 25 Aug 2004 12:53:44 -0000
@@ -99,8 +99,8 @@
// In case we have a tab, we just 'jump' over the tab.
// When we have no tab expander we just use the width of 'm'.
if (e != null)
- pixelX += (int) e.nextTabStop((float) pixelX,
- startOffset + offset - s.offset);
+ pixelX = (int) e.nextTabStop((float) pixelX,
+ startOffset + offset - s.offset);
else
pixelX += metrics.charWidth('m');
break;
@@ -155,8 +155,8 @@
// In case we have a tab, we just 'jump' over the tab.
// When we have no tab expander we just use the width of 'm'.
if (e != null)
- pixelX += (int) e.nextTabStop((float) pixelX,
- startOffset + offset - s.offset);
+ pixelX = (int) e.nextTabStop((float) pixelX,
+ startOffset + offset - s.offset);
else
pixelX += metrics.charWidth('m');
break;