summaryrefslogtreecommitdiffstats
path: root/libjava/javax/swing/text
diff options
context:
space:
mode:
Diffstat (limited to 'libjava/javax/swing/text')
-rw-r--r--libjava/javax/swing/text/AbstractDocument.java684
-rw-r--r--libjava/javax/swing/text/BadLocationException.java17
-rw-r--r--libjava/javax/swing/text/DefaultCaret.java300
-rw-r--r--libjava/javax/swing/text/Document.java25
-rw-r--r--libjava/javax/swing/text/GapContent.java124
-rw-r--r--libjava/javax/swing/text/JTextComponent.java833
-rw-r--r--libjava/javax/swing/text/MutableAttributeSet.java84
-rw-r--r--libjava/javax/swing/text/PlainDocument.java47
-rw-r--r--libjava/javax/swing/text/Style.java25
9 files changed, 1287 insertions, 852 deletions
diff --git a/libjava/javax/swing/text/AbstractDocument.java b/libjava/javax/swing/text/AbstractDocument.java
index 6408b22cdfb..18a8ea9e541 100644
--- a/libjava/javax/swing/text/AbstractDocument.java
+++ b/libjava/javax/swing/text/AbstractDocument.java
@@ -1,4 +1,4 @@
-/* AbstractDocument.java --
+/* AbstractDocument.java --
Copyright (C) 2002, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -37,6 +37,7 @@ exception statement from your version. */
package javax.swing.text;
+import java.io.Serializable;
import java.util.Dictionary;
import java.util.Enumeration;
import java.util.EventListener;
@@ -47,321 +48,520 @@ import javax.swing.event.DocumentListener;
import javax.swing.event.UndoableEditEvent;
import javax.swing.event.UndoableEditListener;
import javax.swing.tree.TreeNode;
+import javax.swing.undo.AbstractUndoableEdit;
+import javax.swing.undo.CompoundEdit;
import javax.swing.undo.UndoableEdit;
-public abstract class AbstractDocument implements Document
-{
- 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();
+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;
- // some inner classes sun says I should have:
- abstract class AbstractElement implements Element, TreeNode
+ public AbstractElement(Element p, AttributeSet s)
{
- int count, offset;
- AttributeSet attr;
- Vector elts = new Vector();
- String name;
- Element parent;
- Vector kids = new Vector();
- TreeNode tree_parent;
-
- public AbstractElement(Element p, AttributeSet s)
- { parent = p; attr = s; }
-
- public Enumeration children() { return kids.elements(); }
- public boolean getAllowsChildren() { return true; }
- public TreeNode getChildAt(int index) { return (TreeNode) kids.elementAt(index); }
- public int getChildCount() { return kids.size(); }
- public int getIndex(TreeNode node) { return kids.indexOf(node); }
- public TreeNode getParent() { return tree_parent; }
-
- public AttributeSet getAttributes() { return attr; }
- public Document getDocument() { return AbstractDocument.this; }
- public Element getElement(int index) { return (Element)elts.elementAt(index); }
- public String getName() { return name; }
- public Element getParentElement() { return parent; }
-
- public abstract boolean isLeaf();
- public abstract int getEndOffset();
- public abstract int getElementCount();
- public abstract int getElementIndex(int offset);
- public abstract int getStartOffset();
+ parent = p;
+ attr = s;
}
- interface AttributeContext
+ public Enumeration children()
{
+ return kids.elements();
}
-
- class BranchElement extends AbstractElement
+ public boolean getAllowsChildren()
{
- public BranchElement(Element e, AttributeSet a, int s, int end)
- { super(e, a); }
-
- public boolean isLeaf() { return false; }
- public int getEndOffset() { return 0; }
- public int getElementCount() { return 0; }
- public int getElementIndex(int offset) { return 0; }
- public int getStartOffset() { return 0; }
+ return true;
}
-
- interface Content
- {
- Position createPosition(int offset) throws BadLocationException;
- int length();
- UndoableEdit insertString(int where, String str) throws BadLocationException;
- UndoableEdit remove(int where, int nitems) throws BadLocationException;
- String getString(int where, int len) throws BadLocationException;
- void getChars(int where, int len, Segment txt) throws BadLocationException;
- }
-
- class DefaultDocumentEvent implements DocumentEvent
- {
- public int len, off;
- public Document getDocument() { return AbstractDocument.this; }
- public int getLength() { return len; }
- public int getOffset() { return off; }
- public DocumentEvent.EventType getType() { return null; }
- public DocumentEvent.ElementChange getChange(Element elem) { return null; }
- }
-
- static class ElementEdit
- {
- }
-
- class LeafElement extends AbstractElement
+
+ public TreeNode getChildAt(int index)
{
- LeafElement(Element e, AttributeSet a, int s, int end)
- { super(e, a); }
-
- public boolean isLeaf() { return true; }
- public int getEndOffset() { return 0; }
- public int getElementCount() { return 0; }
- public int getElementIndex(int offset) { return 0; }
- public int getStartOffset() { return 0; }
+ return (TreeNode) kids.elementAt(index);
}
-
- Content content;
-
- AbstractDocument(Content doc)
+ public int getChildCount()
{
- content = doc;
+ return kids.size();
}
-
- /********************************************************
- *
- * the meat:
- *
- ***********/
-
- public void addDocumentListener(DocumentListener listener)
+ public int getIndex(TreeNode node)
{
- doc_list.addElement(listener);
+ return kids.indexOf(node);
}
-
- public void addUndoableEditListener(UndoableEditListener listener)
+
+ public TreeNode getParent()
{
- undo_list.addElement(listener);
- }
-
- protected Element createBranchElement(Element parent, AttributeSet a)
- {
- return new BranchElement(parent, a, 0, 0);
+ return tree_parent;
}
-
- protected Element createLeafElement(Element parent, AttributeSet a, int p0, int p1)
+
+ public AttributeSet getAttributes()
{
- return new LeafElement(parent, a, p0, p1-p0);
+ return attr;
}
- public Position createPosition(int offs)
+ public Document getDocument()
{
- final int a = offs;
- return new Position()
- {
- public int getOffset()
- {
- return a;
- }
- };
+ return AbstractDocument.this;
}
-
- protected void fireChangedUpdate(DocumentEvent e)
+
+ public Element getElement(int index)
{
+ return (Element) elts.elementAt(index);
}
-
- protected void fireInsertUpdate(DocumentEvent e)
+
+ public String getName()
{
+ return name;
}
-
- protected void fireRemoveUpdate(DocumentEvent e)
+
+ public Element getParentElement()
{
+ return parent;
}
-
- protected void fireUndoableEditUpdate(UndoableEditEvent e)
+
+ public abstract boolean isLeaf();
+
+ public abstract int getEndOffset();
+
+ public abstract int getElementCount();
+
+ public abstract int getElementIndex(int offset);
+
+ public abstract int getStartOffset();
+ }
+
+ public interface AttributeContext
+ {
+ }
+
+ public class BranchElement extends AbstractElement
+ {
+ private static final long serialVersionUID = -8595176318868717313L;
+
+ public BranchElement(Element e, AttributeSet a, int s, int end)
{
+ super(e, a);
}
- int getAsynchronousLoadPriority()
+
+ public boolean isLeaf()
{
- return 0;
+ return false;
}
-
- protected AttributeContext getAttributeContext()
+
+ public int getEndOffset()
{
- return null;
+ return 0;
}
-
- Element getBidiRootElement()
+
+ public int getElementCount()
{
- return null;
+ return 0;
}
-
- protected Content getContent()
+
+ public int getElementIndex(int offset)
{
- return content;
+ return 0;
}
-
- protected Thread getCurrentWriter()
+
+ public int getStartOffset()
{
- return null;
+ return 0;
}
+ }
+ public interface Content
+ {
+ Position createPosition(int offset) throws BadLocationException;
- public Dictionary getDocumentProperties()
- {
- return null;
- }
+ int length();
+
+ UndoableEdit insertString(int where, String str)
+ throws BadLocationException;
+
+ UndoableEdit remove(int where, int nitems) throws BadLocationException;
+
+ String getString(int where, int len) throws BadLocationException;
+
+ void getChars(int where, int len, Segment txt) throws BadLocationException;
+ }
+
+ public class DefaultDocumentEvent extends CompoundEdit
+ implements DocumentEvent
+ {
+ private static final long serialVersionUID = -7406103236022413522L;
+
+ public int len;
+ public int off;
- public Position getEndPosition()
+ public Document getDocument()
{
- return null;
+ return AbstractDocument.this;
}
public int getLength()
{
- return content.length();
+ return len;
}
-
- public EventListener[] getListeners(Class listenerType)
+
+ public int getOffset()
{
- return null;
+ return off;
}
-
- public Object getProperty(Object key)
+
+ public DocumentEvent.EventType getType()
{
- return null;
+ return null;
}
- public Element[] getRootElements()
+ public DocumentEvent.ElementChange getChange(Element elem)
{
- return null;
+ return null;
}
+ }
+
+ public static class ElementEdit extends AbstractUndoableEdit
+ {
+ private static final long serialVersionUID = -1216620962142928304L;
+ }
+
+ public class LeafElement extends AbstractElement
+ {
+ private static final long serialVersionUID = 5115368706941283802L;
- public Position getStartPosition()
+ public LeafElement(Element e, AttributeSet a, int s, int end)
{
- return null;
+ super(e, a);
}
- public String getText(int offset, int length)
- {
- try {
- return content.getString(offset, length);
- } catch (Exception e) {
- System.out.println("Hmmm, fail to getText: " + offset + " -> " + length);
- return null;
- }
- }
-
- public void getText(int offset, int length, Segment txt)
- {
- String a = getText(offset, length);
-
- if (a == null)
- {
- txt.offset = 0;
- txt.count = 0;
- txt.array = new char[0];
- return;
- }
-
- txt.offset = offset;
- txt.count = length;
-
- char chars[] = new char[ a.length() ];
-
- a.getChars(0, a.length(), chars, 0);
-
- txt.array = chars;
- }
-
- public void insertString(int offs, String str, AttributeSet a)
- {
- try {
- content.insertString(offs, str);
- } catch (Exception e) {
- System.err.println("FAILED TO INSERT-STRING: " + e + ", at:"+offs);
- }
- }
-
- protected void insertUpdate(DefaultDocumentEvent chng, AttributeSet attr)
- {
- }
-
- protected void postRemoveUpdate(DefaultDocumentEvent chng)
- {
- }
-
- public void putProperty(Object key, Object value)
- {
- }
-
- public void readLock()
- {
- }
-
- public void readUnlock()
- {
- }
-
- public void remove(int offs, int len)
+ public boolean isLeaf()
{
+ return true;
}
-
- public void removeDocumentListener(DocumentListener listener)
- {
- }
-
- public void removeUndoableEditListener(UndoableEditListener listener)
+
+ public int getEndOffset()
{
+ return 0;
}
-
- protected void removeUpdate(DefaultDocumentEvent chng)
+
+ public int getElementCount()
{
+ return 0;
}
-
- public void render(Runnable r)
+
+ public int getElementIndex(int offset)
{
+ return 0;
}
-
- void setAsynchronousLoadPriority(int p)
+
+ public int getStartOffset()
{
+ return 0;
}
+ }
+
+ 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";
- void setDocumentProperties(Dictionary x)
- {
- }
-
- protected void writeLock()
- {
- }
-
- protected void writeUnlock()
- {
- }
+ Content content;
+
+ protected AbstractDocument(Content doc)
+ {
+ this(doc, null);
+ }
+
+ protected AbstractDocument(Content doc, AttributeContext context)
+ {
+ content = doc;
+ }
+
+ 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)
+ {
+ return new BranchElement(parent, a, 0, 0);
+ }
+
+ protected Element createLeafElement(Element parent, AttributeSet a, int p0,
+ int p1)
+ {
+ return new LeafElement(parent, a, p0, p1 - p0);
+ }
+
+ public Position createPosition(int offs)
+ {
+ final int a = offs;
+ return new Position()
+ {
+ public int getOffset()
+ {
+ return a;
+ }
+ };
+ }
+
+ protected void fireChangedUpdate(DocumentEvent event)
+ {
+ DocumentListener[] listeners = getDocumentListeners();
+
+ for (int index = 0; index < listeners.length; ++index)
+ listeners[index].changedUpdate(event);
+ }
+
+ protected void fireInsertUpdate(DocumentEvent event)
+ {
+ DocumentListener[] listeners = getDocumentListeners();
+
+ for (int index = 0; index < listeners.length; ++index)
+ listeners[index].insertUpdate(event);
+ }
+
+ protected void fireRemoveUpdate(DocumentEvent event)
+ {
+ DocumentListener[] listeners = getDocumentListeners();
+
+ for (int index = 0; index < listeners.length; ++index)
+ listeners[index].removeUpdate(event);
+ }
+
+ protected void fireUndoableEditUpdate(UndoableEditEvent event)
+ {
+ UndoableEditListener[] listeners = getUndoableEditListeners();
+
+ for (int index = 0; index < listeners.length; ++index)
+ listeners[index].undoableEditHappened(event);
+ }
+
+ public int getAsynchronousLoadPriority()
+ {
+ return 0;
+ }
+
+ protected AttributeContext getAttributeContext()
+ {
+ return null;
+ }
+
+ public Element getBidiRootElement()
+ {
+ return null;
+ }
+
+ protected Content getContent()
+ {
+ return content;
+ }
+
+ protected Thread getCurrentWriter()
+ {
+ return null;
+ }
+
+ public Dictionary getDocumentProperties()
+ {
+ return null;
+ }
+
+ public Position getEndPosition()
+ {
+ return null;
+ }
+
+ public int getLength()
+ {
+ return content.length();
+ }
+
+ public EventListener[] getListeners(Class listenerType)
+ {
+ return listenerList.getListeners(listenerType);
+ }
+
+ public Object getProperty(Object key)
+ {
+ return null;
+ }
+
+ public Element[] getRootElements()
+ {
+ return null;
+ }
+
+ public Position getStartPosition()
+ {
+ return null;
+ }
+
+ public String getText(int offset, int length)
+ {
+ try
+ {
+ return content.getString(offset, length);
+ }
+ catch (Exception e)
+ {
+ System.out.println("Hmmm, fail to getText: " + offset + " -> "
+ + length);
+ return null;
+ }
+ }
+
+ public void getText(int offset, int length, Segment txt)
+ {
+ String a = getText(offset, length);
+
+ if (a == null)
+ {
+ txt.offset = 0;
+ txt.count = 0;
+ txt.array = new char[0];
+ return;
+ }
+
+ txt.offset = offset;
+ txt.count = length;
+
+ char[] chars = new char[a.length()];
+
+ a.getChars(0, a.length(), chars, 0);
+
+ txt.array = chars;
+ }
+
+ public void insertString(int offs, String str, AttributeSet a)
+ throws BadLocationException
+ {
+ content.insertString(offs, str);
+ }
+
+ protected void insertUpdate(DefaultDocumentEvent chng, AttributeSet attr)
+ {
+ }
+
+ protected void postRemoveUpdate(DefaultDocumentEvent chng)
+ {
+ }
+
+ public void putProperty(Object key, Object value)
+ {
+ }
+
+ public void readLock()
+ {
+ }
+
+ public void readUnlock()
+ {
+ }
+
+ public void remove(int offs, int len)
+ {
+ }
+
+ /**
+ * 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)
+ {
+ }
+
+ public void render(Runnable r)
+ {
+ }
+
+ public void setAsynchronousLoadPriority(int p)
+ {
+ }
+
+ public void setDocumentProperties(Dictionary x)
+ {
+ }
+
+ protected void writeLock()
+ {
+ }
+
+ protected void writeUnlock()
+ {
+ }
}
diff --git a/libjava/javax/swing/text/BadLocationException.java b/libjava/javax/swing/text/BadLocationException.java
index d62ad5465f9..01463d139bd 100644
--- a/libjava/javax/swing/text/BadLocationException.java
+++ b/libjava/javax/swing/text/BadLocationException.java
@@ -1,5 +1,5 @@
-/* BadLocationException.java --
- Copyright (C) 2002 Free Software Foundation, Inc.
+/* BadLocationException.java --
+ Copyright (C) 2002, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -37,27 +37,28 @@ exception statement from your version. */
package javax.swing.text;
-
public class BadLocationException extends Exception
-{
- int offset;
+{
+ private static final long serialVersionUID = -7712259886815656766L;
+ int offset;
+
/**
* Constructs a <code>BadLocationException</code>
*
* @param str A string indicating what was wrong with the arguments
* @param offset Offset within the document that was requested &gt;= 0
*/
- public BadLocationException (String str, int offset)
+ public BadLocationException(String str, int offset)
{
- super (str);
+ super(str);
this.offset = offset;
}
/**
* Returns the offset into the document that was not legal
*/
- public int offsetRequested ()
+ public int offsetRequested()
{
return offset;
}
diff --git a/libjava/javax/swing/text/DefaultCaret.java b/libjava/javax/swing/text/DefaultCaret.java
index 1c4607fce9f..d79e920aa94 100644
--- a/libjava/javax/swing/text/DefaultCaret.java
+++ b/libjava/javax/swing/text/DefaultCaret.java
@@ -1,4 +1,4 @@
-/* DefaultCaret.java --
+/* DefaultCaret.java --
Copyright (C) 2002, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -44,132 +44,184 @@ import java.awt.Rectangle;
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;
-public class DefaultCaret extends Rectangle implements Caret, FocusListener, MouseListener, MouseMotionListener
+public class DefaultCaret extends Rectangle
+ implements Caret, FocusListener, MouseListener, MouseMotionListener
{
- Color color = new Color(0,0,0);
- JTextComponent parent;
-
- public void mouseDragged(java.awt.event.MouseEvent evt)
- {
- }
-
- public void mouseMoved(java.awt.event.MouseEvent evt)
- {
- }
-
- public void mouseClicked(java.awt.event.MouseEvent evt)
- {
- }
-
- public void mouseEntered(java.awt.event.MouseEvent evt)
- {
- }
-
- public void mouseExited(java.awt.event.MouseEvent evt)
- {
- }
-
- public void mousePressed(java.awt.event.MouseEvent evt)
- {
- }
-
- public void mouseReleased(java.awt.event.MouseEvent evt)
- {
- }
-
- public void focusGained(java.awt.event.FocusEvent evt)
- {
- }
-
- public void focusLost(java.awt.event.FocusEvent evt)
- {
- }
-
- // caret methods:
-
- public void deinstall(JTextComponent c)
- {
- parent.removeFocusListener(this);
- parent.removeMouseListener(this);
-
- parent = null;
- }
- public void install(JTextComponent c)
- {
- parent.addFocusListener(this);
- parent.addMouseListener(this);
- parent = c;
- repaint();
- }
-
- Point magic = null;
- public void setMagicCaretPosition(Point p)
- { magic = p; }
- public Point getMagicCaretPosition()
- { return magic; }
-
-
- int mark = 0;
- public int getMark()
- { return mark; }
-
- boolean vis_sel = true;
- public void setSelectionVisible(boolean v)
- { vis_sel = v; repaint(); }
- public boolean isSelectionVisible()
- { return vis_sel; }
-
- private void repaint()
- {
- if (parent != null)
- {
- parent.repaint();
- }
- }
-
- public void paint(Graphics g)
- {
- g.setColor(color);
- g.drawLine(x,y,
- x,y+height);
- }
-
-
- Vector changes = new Vector();
- public void addChangeListener(ChangeListener l)
- { changes.addElement(l); }
- public void removeChangeListener(ChangeListener l)
- { changes.removeElement(l); }
-
-
- int blink = 500;
- public int getBlinkRate()
- { return blink; }
- public void setBlinkRate(int rate)
- { blink = rate; }
-
- int dot = 0;
- public int getDot()
- { return dot; }
- public void moveDot(int dot)
- { setDot(dot); }
- public void setDot(int dot)
- {
- this.dot = dot;
- repaint();
- }
-
- boolean vis = true;
- public boolean isVisible()
- { return vis; }
- public void setVisible(boolean v)
- {
- vis = v;
- repaint();
- }
+ 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)
+ {
+ }
+
+ public void mouseMoved(java.awt.event.MouseEvent evt)
+ {
+ }
+
+ public void mouseClicked(java.awt.event.MouseEvent evt)
+ {
+ }
+
+ public void mouseEntered(java.awt.event.MouseEvent evt)
+ {
+ }
+
+ public void mouseExited(java.awt.event.MouseEvent evt)
+ {
+ }
+
+ public void mousePressed(java.awt.event.MouseEvent evt)
+ {
+ }
+
+ public void mouseReleased(java.awt.event.MouseEvent evt)
+ {
+ }
+
+ public void focusGained(java.awt.event.FocusEvent evt)
+ {
+ }
+
+ public void focusLost(java.awt.event.FocusEvent evt)
+ {
+ }
+
+ public void deinstall(JTextComponent c)
+ {
+ parent.removeFocusListener(this);
+ parent.removeMouseListener(this);
+ parent = null;
+ }
+
+ public void install(JTextComponent c)
+ {
+ parent.addFocusListener(this);
+ parent.addMouseListener(this);
+ parent = c;
+ repaint();
+ }
+
+ public void setMagicCaretPosition(Point p)
+ {
+ magic = p;
+ }
+
+ public Point getMagicCaretPosition()
+ {
+ return magic;
+ }
+
+ public int getMark()
+ {
+ return mark;
+ }
+
+ public void setSelectionVisible(boolean v)
+ {
+ vis_sel = v;
+ repaint();
+ }
+
+ public boolean isSelectionVisible()
+ {
+ return vis_sel;
+ }
+
+ private void repaint()
+ {
+ if (parent != null)
+ parent.repaint();
+ }
+
+ public void paint(Graphics g)
+ {
+ g.setColor(color);
+ g.drawLine(x, y, x, y + height);
+ }
+
+ public EventListener[] getListeners(Class listenerType)
+ {
+ return listenerList.getListeners(listenerType);
+ }
+
+ public void addChangeListener(ChangeListener listener)
+ {
+ listenerList.add(ChangeListener.class, listener);
+ }
+
+ public void removeChangeListener(ChangeListener listener)
+ {
+ listenerList.remove(ChangeListener.class, listener);
+ }
+
+ 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()
+ {
+ return blink;
+ }
+
+ public void setBlinkRate(int rate)
+ {
+ blink = rate;
+ }
+
+ public int getDot()
+ {
+ return dot;
+ }
+
+ public void moveDot(int dot)
+ {
+ setDot(dot);
+ }
+
+ public void setDot(int dot)
+ {
+ this.dot = dot;
+ repaint();
+ }
+
+ public boolean isVisible()
+ {
+ return vis;
+ }
+
+ public void setVisible(boolean v)
+ {
+ vis = v;
+ repaint();
+ }
}
diff --git a/libjava/javax/swing/text/Document.java b/libjava/javax/swing/text/Document.java
index 351b0aa6066..6ecb7ca21db 100644
--- a/libjava/javax/swing/text/Document.java
+++ b/libjava/javax/swing/text/Document.java
@@ -1,4 +1,4 @@
-/* Document.java --
+/* Document.java --
Copyright (C) 2002, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -40,27 +40,44 @@ package javax.swing.text;
import javax.swing.event.DocumentListener;
import javax.swing.event.UndoableEditListener;
+
public interface Document
-{
+{
String StreamDescriptionProperty = "stream";
-
String TitleProperty = "text";
void addDocumentListener(DocumentListener listener);
+
void addUndoableEditListener(UndoableEditListener listener);
+
Position createPosition(int offs);
+
Element getDefaultRootElement();
+
Position getEndPosition();
+
int getLength();
+
Object getProperty(Object key);
+
Element[] getRootElements();
+
Position getStartPosition();
+
String getText(int offset, int length);
+
void getText(int offset, int length, Segment txt);
- void insertString(int offset, String str, AttributeSet a);
+
+ void insertString(int offset, String str, AttributeSet a)
+ throws BadLocationException;
+
void putProperty(Object key, Object value);
+
void remove(int offs, int len);
+
void removeDocumentListener(DocumentListener listener);
+
void removeUndoableEditListener(UndoableEditListener listener);
+
void render(Runnable r);
}
diff --git a/libjava/javax/swing/text/GapContent.java b/libjava/javax/swing/text/GapContent.java
index 50165437716..93446826868 100644
--- a/libjava/javax/swing/text/GapContent.java
+++ b/libjava/javax/swing/text/GapContent.java
@@ -1,4 +1,4 @@
-/* GapContent.java --
+/* GapContent.java --
Copyright (C) 2002, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -35,69 +35,75 @@ this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
-package javax.swing.text;
+package javax.swing.text;
+
+import java.io.Serializable;
// too lazy to make a real gapcontent.
// lets just use a stringbuffer instead.
-
import javax.swing.undo.UndoableEdit;
-public class GapContent implements AbstractDocument.Content
+public class GapContent
+ implements AbstractDocument.Content, Serializable
{
- StringBuffer buf = new StringBuffer();
-
- public GapContent()
- {
- this(10);
- }
+ private static final long serialVersionUID = 8374645204155842629L;
- public GapContent(int size)
- {
- }
-
- public Position createPosition(final int offset) throws BadLocationException
- {
- return new Position()
- {
- int off = offset;
- public int getOffset()
- {
- return off;
- }
- };
- }
-
- public int length()
- {
- return buf.length();
- }
-
- public UndoableEdit insertString(int where, String str) throws BadLocationException
- {
- buf.insert(where, str);
- return null;
- }
-
- public UndoableEdit remove(int where, int nitems) throws BadLocationException
- {
- buf.delete(where, where + nitems);
- return null;
- }
-
- public String getString(int where, int len) throws BadLocationException
- {
- return buf.toString();
- }
-
- public void getChars(int where, int len, Segment txt) throws BadLocationException
- {
- txt.array = new char[len];
-
- System.arraycopy(buf.toString().toCharArray(), where,
- txt.array, 0,
- len);
-
- txt.count = len;
- txt.offset = 0;
- }
+ StringBuffer buf = new StringBuffer();
+
+ public GapContent()
+ {
+ this(10);
+ }
+
+ public GapContent(int size)
+ {
+ }
+
+ public Position createPosition(final int offset) throws BadLocationException
+ {
+ return new Position()
+ {
+ int off = offset;
+
+ public int getOffset()
+ {
+ return off;
+ }
+ };
+ }
+
+ public int length()
+ {
+ return buf.length();
+ }
+
+ public UndoableEdit insertString(int where, String str)
+ throws BadLocationException
+ {
+ buf.insert(where, str);
+ return null;
+ }
+
+ public UndoableEdit remove(int where, int nitems)
+ throws BadLocationException
+ {
+ buf.delete(where, where + nitems);
+ return null;
+ }
+
+ public String getString(int where, int len) throws BadLocationException
+ {
+ return buf.toString();
+ }
+
+ public void getChars(int where, int len, Segment txt)
+ throws BadLocationException
+ {
+ txt.array = new char[len];
+
+ System.arraycopy(buf.toString().toCharArray(), where, txt.array, 0, len);
+
+ txt.count = len;
+ txt.offset = 0;
+ }
}
diff --git a/libjava/javax/swing/text/JTextComponent.java b/libjava/javax/swing/text/JTextComponent.java
index 48bb0c03ce6..6451ef5c31f 100644
--- a/libjava/javax/swing/text/JTextComponent.java
+++ b/libjava/javax/swing/text/JTextComponent.java
@@ -1,5 +1,5 @@
-/* JTextComponent.java --
- Copyright (C) 2002 Free Software Foundation, Inc.
+/* JTextComponent.java --
+ Copyright (C) 2002, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -42,8 +42,10 @@ import java.awt.Component;
import java.awt.Dimension;
import java.awt.Image;
import java.awt.Insets;
-import java.awt.Rectangle;
import java.awt.Point;
+import java.awt.Rectangle;
+import java.awt.event.InputMethodListener;
+
import javax.accessibility.Accessible;
import javax.accessibility.AccessibleContext;
import javax.accessibility.AccessibleRole;
@@ -51,6 +53,7 @@ import javax.accessibility.AccessibleStateSet;
import javax.accessibility.AccessibleText;
import javax.swing.Icon;
import javax.swing.JComponent;
+import javax.swing.JViewport;
import javax.swing.KeyStroke;
import javax.swing.Scrollable;
import javax.swing.UIManager;
@@ -60,6 +63,7 @@ import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.plaf.TextUI;
+
public abstract class JTextComponent extends JComponent
implements Scrollable, Accessible
{
@@ -67,410 +71,323 @@ public abstract class JTextComponent extends JComponent
// implements AccessibleText, CaretListener, DocumentListener,
// AccessibleAction, AccessibleEditableText
// {
-// } // class AccessibleJTextComponent
-
- /**
- * AccessibleJTextComponent
- */
- public class AccessibleJTextComponent extends AccessibleJComponent
- implements AccessibleText, CaretListener, DocumentListener {
-
- //-------------------------------------------------------------
- // Variables --------------------------------------------------
- //-------------------------------------------------------------
-
- /**
- * caretPos
- */
- int caretPos;
-
-
- //-------------------------------------------------------------
- // Initialization ---------------------------------------------
- //-------------------------------------------------------------
-
- /**
- * Constructor AccessibleJTextComponent
- * @param component TODO
- */
- public AccessibleJTextComponent(JTextComponent component) {
- super(component);
- // TODO
- } // AccessibleJTextComponent()
-
-
- //-------------------------------------------------------------
- // Methods ----------------------------------------------------
- //-------------------------------------------------------------
-
- /**
- * getCaretPosition
- * @returns int
- */
- public int getCaretPosition() {
- return 0; // TODO
- } // getCaretPosition()
-
- /**
- * getSelectedText
- * @returns String
- */
- public String getSelectedText() {
- return null; // TODO
- } // getSelectedText()
-
- /**
- * getSelectionStart
- * @returns int
- */
- public int getSelectionStart() {
- return 0; // TODO
- } // getSelectionStart()
-
- /**
- * getSelectionEnd
- * @returns int
- */
- public int getSelectionEnd() {
- return 0; // TODO
- } // getSelectionEnd()
-
- /**
- * caretUpdate
- * @param value0 TODO
- */
- public void caretUpdate(CaretEvent value0) {
- // TODO
- } // caretUpdate()
-
- /**
- * getAccessibleStateSet
- * @returns AccessibleStateSet
- */
- public AccessibleStateSet getAccessibleStateSet() {
- return null; // TODO
- } // getAccessibleStateSet()
-
- /**
- * getAccessibleRole
- * @returns AccessibleRole
- */
- public AccessibleRole getAccessibleRole() {
- return null; // TODO
- } // getAccessibleRole()
-
- /**
- * getAccessibleText
- * @returns AccessibleText
- */
- public AccessibleText getAccessibleText() {
- return null; // TODO
- } // getAccessibleText()
-
- /**
- * insertUpdate
- * @param value0 TODO
- */
- public void insertUpdate(DocumentEvent value0) {
- // TODO
- } // insertUpdate()
-
- /**
- * removeUpdate
- * @param value0 TODO
- */
- public void removeUpdate(DocumentEvent value0) {
- // TODO
- } // removeUpdate()
-
- /**
- * changedUpdate
- * @param value0 TODO
- */
- public void changedUpdate(DocumentEvent value0) {
- // TODO
- } // changedUpdate()
-
- /**
- * getIndexAtPoint
- * @param value0 TODO
- * @returns int
- */
- public int getIndexAtPoint(Point value0) {
- return 0; // TODO
- } // getIndexAtPoint()
-
- /**
- * getRootEditorRect
- * @returns Rectangle
- */
- Rectangle getRootEditorRect() {
- return null; // TODO
- } // getRootEditorRect()
-
- /**
- * getCharacterBounds
- * @param value0 TODO
- * @returns Rectangle
- */
- public Rectangle getCharacterBounds(int value0) {
- return null; // TODO
- } // getCharacterBounds()
-
- /**
- * getCharCount
- * @returns int
- */
- public int getCharCount() {
- return 0; // TODO
- } // getCharCount()
-
- /**
- * getCharacterAttribute
- * @param value0 TODO
- * @returns AttributeSet
- */
- public AttributeSet getCharacterAttribute(int value0) {
- return null; // TODO
- } // getCharacterAttribute()
-
- /**
- * getAtIndex
- * @param value0 TODO
- * @param value1 TODO
- * @returns String
- */
- public String getAtIndex(int value0, int value1) {
- return null; // TODO
- } // getAtIndex()
-
- /**
- * getAfterIndex
- * @param value0 TODO
- * @param value1 TODO
- * @returns String
- */
- public String getAfterIndex(int value0, int value1) {
- return null; // TODO
- } // getAfterIndex()
-
- /**
- * getBeforeIndex
- * @param value0 TODO
- * @param value1 TODO
- * @returns String
- */
- public String getBeforeIndex(int value0, int value1) {
- return null; // TODO
- } // getBeforeIndex()
-
-
- } // AccessibleJTextComponent
-
+// }
-
- public static class KeyBinding
+ /**
+ * AccessibleJTextComponent
+ */
+ public class AccessibleJTextComponent extends AccessibleJComponent
+ implements AccessibleText, CaretListener, DocumentListener
{
- public KeyStroke key;
- public String actionName;
- public KeyBinding(KeyStroke key, String actionName)
- {
- this.key = key;
- this.actionName = actionName;
- }
- } // class KeyBinding
+ private static final long serialVersionUID = 7664188944091413696L;
- int icon_gap;
- Icon icon;
- int align;
- Document doc;
+ /**
+ * caretPos
+ */
+ int caretPos;
- public JTextComponent()
+ /**
+ * Constructor AccessibleJTextComponent
+ * @param component TODO
+ */
+ public AccessibleJTextComponent()
{
- this("", null, 0);
}
- public JTextComponent(Icon image)
+ /**
+ * getCaretPosition
+ * @return int
+ */
+ public int getCaretPosition()
{
- this("", image, 0);
+ return 0; // TODO
}
- public JTextComponent(Icon image, int horizontalAlignment)
+ /**
+ * getSelectedText
+ * @return String
+ */
+ public String getSelectedText()
{
- this("", image, horizontalAlignment);
+ return null; // TODO
}
- public JTextComponent(String text)
+ /**
+ * getSelectionStart
+ * @return int
+ */
+ public int getSelectionStart()
{
- this(text, null, 0);
+ return 0; // TODO
}
- public JTextComponent(String text, int horizontalAlignment)
+ /**
+ * getSelectionEnd
+ * @return int
+ */
+ public int getSelectionEnd()
{
- this(text, null, horizontalAlignment);
+ return 0; // TODO
}
- public JTextComponent(String text, Icon icon, int horizontalAlignment)
+ /**
+ * caretUpdate
+ * @param value0 TODO
+ */
+ public void caretUpdate(CaretEvent value0)
{
- setDocument(new PlainDocument());
-
- // do the work.....
- setText(text);
- this.icon = icon;
- this.align = horizontalAlignment;
-
- // its an editor, so:
- enableEvents(AWTEvent.KEY_EVENT_MASK);
- updateUI();
+ // TODO
}
- public void setDocument(Document s)
+ /**
+ * getAccessibleStateSet
+ * @return AccessibleStateSet
+ */
+ public AccessibleStateSet getAccessibleStateSet()
{
- doc = s;
- revalidate();
- repaint();
+ return null; // TODO
}
- public Document getDocument()
+ /**
+ * getAccessibleRole
+ * @return AccessibleRole
+ */
+ public AccessibleRole getAccessibleRole()
{
- if (doc == null)
- System.out.println("doc == null !!!");
- return doc;
+ return null; // TODO
}
- protected int checkHorizontalKey(int key, String message)
- {
- // Verify that key is a legal value for the horizontalAlignment properties.
- return 0;
- }
- protected int checkVerticalKey(int key, String message)
- {
- // Verify that key is a legal value for the verticalAlignment or verticalTextPosition properties.
- return 0;
- }
- public AccessibleContext getAccessibleContext()
- {
- // Get the AccessibleContext of this object
- return null;
- }
- public Icon getDisabledIcon()
+ /**
+ * getAccessibleText
+ * @return AccessibleText
+ */
+ public AccessibleText getAccessibleText()
{
- return null;
+ return null; // TODO
}
- public int getDisplayedMnemonic()
- {
- // Return the keycode that indicates a mnemonic key.
- return 0;
- }
- public int getHorizontalAlignment()
- {
- // Returns the alignment of the label's contents along the X axis.
- return 0;
- }
- public int getHorizontalTextPosition()
- {
- // Returns the horizontal position of the label's text, relative to its image.
- return 0;
- }
-
- public Icon getIcon()
- { return icon; }
- public int getIconTextGap()
- { return icon_gap; }
-
- Component getLabelFor()
+ /**
+ * insertUpdate
+ * @param value0 TODO
+ */
+ public void insertUpdate(DocumentEvent value0)
{
- // Get the component this is labelling.
- return null;
+ // TODO
}
- public Insets getMargin()
+ /**
+ * removeUpdate
+ * @param value0 TODO
+ */
+ public void removeUpdate(DocumentEvent value0)
{
- // FIXME: Not implemented.
- return null;
+ // TODO
}
- public void setText(String text)
- {
- getDocument().remove(0,doc.getLength());
- getDocument().insertString(0, text, null);
- }
-
- public String getText()
+ /**
+ * changedUpdate
+ * @param value0 TODO
+ */
+ public void changedUpdate(DocumentEvent value0)
{
- return getDocument().getText(0,
- getDocument().getLength());
+ // TODO
}
- public String getUIClassID()
- {
- // Returns a string that specifies the name of the l&f class that renders this component.
- return "TextComponentUI";
- }
- public int getVerticalAlignment()
- {
- // Returns the alignment of the label's contents along the Y axis.
- return 0;
- }
- public int getVerticalTextPosition()
+ /**
+ * getIndexAtPoint
+ * @param value0 TODO
+ * @return int
+ */
+ public int getIndexAtPoint(Point value0)
{
- // Returns the vertical position of the label's text, relative to its image.
- return 0;
+ return 0; // TODO
}
- public boolean imageUpdate(Image img, int infoflags, int x, int y, int w, int h)
- {
- // This is overriden to return false if the current Icon's Image is not equal to the passed in Image img.
- return (img == icon);
- }
- protected String paramString()
+ /**
+ * getRootEditorRect
+ * @return Rectangle
+ */
+ Rectangle getRootEditorRect()
{
- // Returns a string representation of this JTextComponent.
- return "JTextComponent";
+ return null;
}
- void setDisabledIcon(Icon disabledIcon)
+
+ /**
+ * getCharacterBounds
+ * @param value0 TODO
+ * @return Rectangle
+ */
+ public Rectangle getCharacterBounds(int value0)
{
- // Set the icon to be displayed if this JTextComponent is "disabled" (JTextComponent.setEnabled(false)).
+ return null; // TODO
}
- void setDisplayedMnemonic(char aChar)
+
+ /**
+ * getCharCount
+ * @return int
+ */
+ public int getCharCount()
{
- // Specifies the displayedMnemonic as a char value.
+ return 0; // TODO
}
- void setDisplayedMnemonic(int key)
+
+ /**
+ * getCharacterAttribute
+ * @param value0 TODO
+ * @return AttributeSet
+ */
+ public AttributeSet getCharacterAttribute(int value0)
{
- // Specify a keycode that indicates a mnemonic key.
+ return null; // TODO
}
- void setHorizontalAlignment(int alignment)
+
+ /**
+ * getAtIndex
+ * @param value0 TODO
+ * @param value1 TODO
+ * @return String
+ */
+ public String getAtIndex(int value0, int value1)
{
- // Sets the alignment of the label's contents along the X axis.
+ return null; // TODO
}
- void setHorizontalTextPosition(int textPosition)
+
+ /**
+ * getAfterIndex
+ * @param value0 TODO
+ * @param value1 TODO
+ * @return String
+ */
+ public String getAfterIndex(int value0, int value1)
{
- // Sets the horizontal position of the label's text, relative to its image.
+ return null; // TODO
}
- void setIcon(Icon icon)
+
+ /**
+ * getBeforeIndex
+ * @param value0 TODO
+ * @param value1 TODO
+ * @return String
+ */
+ public String getBeforeIndex(int value0, int value1)
{
- // Defines the icon this component will display.
+ return null; // TODO
}
- public void setIconTextGap(int iconTextGap)
+ }
+
+ public static class KeyBinding
+ {
+ public KeyStroke key;
+ public String actionName;
+
+ public KeyBinding(KeyStroke key, String actionName)
{
- // If both the icon and text properties are set, this property defines the space between them.
+ this.key = key;
+ this.actionName = actionName;
}
+ }
+
+ private static final long serialVersionUID = -8796518220218978795L;
- public void setLabelFor(Component c)
- {
- // Set the component this is labelling.
- }
-
- public void setVerticalAlignment(int alignment)
- {
- // Sets the alignment of the label's contents along the Y axis.
- }
- public void setVerticalTextPosition(int textPosition)
- {
- // Sets the vertical position of the label's text, relative to its image.
- }
+ public static final String DEFAULT_KEYMAP = "default";
+ public static final String FOCUS_ACCELERATOR_KEY = "focusAcceleratorKey";
+
+ private Document doc;
+ private Caret caret;
+ private boolean editable;
+
+ public JTextComponent()
+ {
+ enableEvents(AWTEvent.KEY_EVENT_MASK);
+ updateUI();
+ }
+
+ public void setDocument(Document s)
+ {
+ doc = s;
+ revalidate();
+ repaint();
+ }
+
+ public Document getDocument()
+ {
+ if (doc == null)
+ System.out.println("doc == null !!!");
+ return doc;
+ }
+
+ /**
+ * Get the AccessibleContext of this object
+ */
+ public AccessibleContext getAccessibleContext()
+ {
+ return null;
+ }
+
+ public Insets getMargin()
+ {
+ // FIXME: Not implemented.
+ return null;
+ }
+
+ public void setText(String text)
+ {
+ try
+ {
+ getDocument().remove(0, doc.getLength());
+ getDocument().insertString(0, text, null);
+ }
+ catch (BadLocationException e)
+ {
+ }
+ }
+
+ /**
+ * Retrieves the current text in this text document.
+ *
+ * @return the text
+ *
+ * @exception NullPointerException if the underlaying document is null
+ */
+ public String getText()
+ {
+ return getDocument().getText(0, getDocument().getLength());
+ }
+
+ /**
+ * Retrieves a part of the current text in this document.
+ *
+ * @param offset the postion of the first character
+ * @param length the length of the text to retrieve
+ *
+ * @return the text
+ *
+ * @exception BadLocationException if arguments do not hold pre-conditions
+ */
+ public String getText(int offset, int length)
+ throws BadLocationException
+ {
+ return getDocument().getText(offset, length);
+ }
+
+ /**
+ * Returns a string that specifies the name of the l&amp;f class
+ * that renders this component.
+ *
+ * @return the string "TextComponentUI"
+ */
+ public String getUIClassID()
+ {
+ return "TextComponentUI";
+ }
+
+ /**
+ * Returns a string representation of this JTextComponent.
+ */
+ protected String paramString()
+ {
+ return "JTextComponent";
+ }
public TextUI getUI()
{
@@ -486,26 +403,246 @@ public abstract class JTextComponent extends JComponent
{
return null;
}
+
public int getScrollableUnitIncrement(Rectangle visible, int orientation,
int direction)
{
return 0;
}
+
public int getScrollableBlockIncrement(Rectangle visible, int orientation,
int direction)
{
return 0;
}
-} // class JTextComponent
+ /**
+ * Checks whether this text component it editable.
+ *
+ * @return true if editable, false otherwise
+ */
+ public boolean isEditable()
+ {
+ return editable;
+ }
+
+ /**
+ * Enables/disabled this text component's editability.
+ *
+ * @param editable true to make it editable, false otherwise.
+ */
+ public void setEditable(boolean editable)
+ {
+ firePropertyChange("editable", this.editable, editable);
+ this.editable = editable;
+ }
+
+ /**
+ * The <code>Caret</code> object used in this text component.
+ *
+ * @return the caret object
+ */
+ public Caret getCaret()
+ {
+ return caret;
+ }
+
+ /**
+ * Retrisves the current caret position.
+ *
+ * @return the current position
+ */
+ public int getCaretPosition()
+ {
+ return caret.getDot();
+ }
+
+ /**
+ * Sets the caret to a new position.
+ *
+ * @param position the new position
+ */
+ public void setCaretPosition(int position)
+ {
+ if (doc == null)
+ return;
+
+ if (position < 0 || position > doc.getLength())
+ throw new IllegalArgumentException();
+
+ caret.setDot(position);
+ }
+
+ /**
+ * Moves the caret to a given position. This selects the text between
+ * the old and the new position of the caret.
+ */
+ public void moveCaretPosition(int position)
+ {
+ if (doc == null)
+ return;
+
+ if (position < 0 || position > doc.getLength())
+ throw new IllegalArgumentException();
+
+ caret.moveDot(position);
+ }
+
+ /**
+ * Returns the start postion of the currently selected text.
+ *
+ * @return the start postion
+ */
+ public int getSelectionStart()
+ {
+ return Math.min(caret.getDot(), caret.getMark());
+ }
+
+ /**
+ * Selects the text from the given postion to the selection end position.
+ *
+ * @param end the start positon of the selected text.
+ */
+ public void setSelectionStart(int start)
+ {
+ select(start, getSelectionEnd());
+ }
+
+ /**
+ * Returns the end postion of the currently selected text.
+ *
+ * @return the end postion
+ */
+ public int getSelectionEnd()
+ {
+ return Math.max(caret.getDot(), caret.getMark());
+ }
+
+ /**
+ * Selects the text from the selection start postion to the given position.
+ *
+ * @param end the end positon of the selected text.
+ */
+ public void setSelectionEnd(int end)
+ {
+ select(getSelectionStart(), end);
+ }
+
+ /**
+ * Selects a part of the content of the text component.
+ *
+ * @param start the start position of the selected text
+ * @param ent the end position of the selected text
+ */
+ public void select(int start, int end)
+ {
+ int length = doc.getLength();
+
+ start = Math.max(start, 0);
+ start = Math.min(start, length);
+
+ end = Math.max(end, 0);
+ end = Math.min(end, length);
+
+ setCaretPosition(start);
+ moveCaretPosition(end);
+ }
+
+ /**
+ * Selects the whole content of the text component.
+ */
+ public void selectAll()
+ {
+ select(0, doc.getLength());
+ }
+
+ public boolean getScrollableTracksViewportHeight()
+ {
+ if (getParent() instanceof JViewport)
+ return ((JViewport) getParent()).getHeight() > getPreferredSize().height;
+ return false;
+ }
+ public boolean getScrollableTracksViewportWidth()
+ {
+ if (getParent() instanceof JViewport)
+ return ((JViewport) getParent()).getWidth() > getPreferredSize().width;
+ return false;
+ }
+ /**
+ * Adds a <code>CaretListener</code> object to this text component.
+ *
+ * @param listener the listener to add
+ */
+ public void addCaretListener(CaretListener listener)
+ {
+ listenerList.add(CaretListener.class, listener);
+ }
+ /**
+ * Removed a <code>CaretListener</code> object from this text component.
+ *
+ * @param listener the listener to remove
+ */
+ public void removeCaretListener(CaretListener listener)
+ {
+ listenerList.remove(CaretListener.class, listener);
+ }
+ /**
+ * Returns all added <code>CaretListener</code> objects.
+ *
+ * @return an array of listeners
+ */
+ public CaretListener[] getCaretListeners()
+ {
+ return (CaretListener[]) getListeners(CaretListener.class);
+ }
+ /**
+ * Notifies all registered <code>CaretListener</code> objects that the caret
+ * was updated.
+ *
+ * @param event the event to send
+ */
+ protected void fireCaretUpdate(CaretEvent event)
+ {
+ CaretListener[] listeners = getCaretListeners();
+ for (int index = 0; index < listeners.length; ++index)
+ listeners[index].caretUpdate(event);
+ }
+ /**
+ * Adds an <code>InputListener</code> object to this text component.
+ *
+ * @param listener the listener to add
+ */
+ public void addInputMethodListener(InputMethodListener listener)
+ {
+ listenerList.add(InputMethodListener.class, listener);
+ }
+ /**
+ * Removes an <code>InputListener</code> object from this text component.
+ *
+ * @param listener the listener to remove
+ */
+ public void removeInputMethodListener(InputMethodListener listener)
+ {
+ listenerList.remove(InputMethodListener.class, listener);
+ }
+ /**
+ * Returns all added <code>InputMethodListener</code> objects.
+ *
+ * @return an array of listeners
+ */
+ public InputMethodListener[] getInputMethodListeners()
+ {
+ return (InputMethodListener[]) getListeners(InputMethodListener.class);
+ }
+}
diff --git a/libjava/javax/swing/text/MutableAttributeSet.java b/libjava/javax/swing/text/MutableAttributeSet.java
index 6bc18df1cbc..d8cb62a7b26 100644
--- a/libjava/javax/swing/text/MutableAttributeSet.java
+++ b/libjava/javax/swing/text/MutableAttributeSet.java
@@ -44,48 +44,42 @@ import java.util.Enumeration;
* @author Andrew Selkirk
* @version 1.0
*/
-public interface MutableAttributeSet extends AttributeSet {
-
- //-------------------------------------------------------------
- // Methods ----------------------------------------------------
- //-------------------------------------------------------------
-
- /**
- * addAttribute
- * @param name TODO
- * @param value TODO
- */
- void addAttribute(Object name, Object value);
-
- /**
- * addAttributes
- * @param attributes TODO
- */
- void addAttributes(AttributeSet attributes);
-
- /**
- * removeAttribute
- * @param name TODO
- */
- void removeAttribute(Object name);
-
- /**
- * removeAttributes
- * @param names TODO
- */
- void removeAttributes(Enumeration names);
-
- /**
- * removeAttributes
- * @param attributes TODO
- */
- void removeAttributes(AttributeSet attributes);
-
- /**
- * setResolveParent
- * @param parent TODO
- */
- void setResolveParent(AttributeSet parent);
-
-
-} // MutableAttributeSet
+public interface MutableAttributeSet extends AttributeSet
+{
+ /**
+ * addAttribute
+ * @param name TODO
+ * @param value TODO
+ */
+ void addAttribute(Object name, Object value);
+
+ /**
+ * addAttributes
+ * @param attributes TODO
+ */
+ void addAttributes(AttributeSet attributes);
+
+ /**
+ * removeAttribute
+ * @param name TODO
+ */
+ void removeAttribute(Object name);
+
+ /**
+ * removeAttributes
+ * @param names TODO
+ */
+ void removeAttributes(Enumeration names);
+
+ /**
+ * removeAttributes
+ * @param attributes TODO
+ */
+ void removeAttributes(AttributeSet attributes);
+
+ /**
+ * setResolveParent
+ * @param parent TODO
+ */
+ void setResolveParent(AttributeSet parent);
+}
diff --git a/libjava/javax/swing/text/PlainDocument.java b/libjava/javax/swing/text/PlainDocument.java
index 45fe5ef01be..930e5d3cb56 100644
--- a/libjava/javax/swing/text/PlainDocument.java
+++ b/libjava/javax/swing/text/PlainDocument.java
@@ -1,5 +1,5 @@
-/* PlainDocument.java --
- Copyright (C) 2002 Free Software Foundation, Inc.
+/* PlainDocument.java --
+ Copyright (C) 2002, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -37,22 +37,33 @@ exception statement from your version. */
package javax.swing.text;
-
public class PlainDocument extends AbstractDocument
{
- PlainDocument()
- {
- super(new GapContent());
- }
-
- public Element getDefaultRootElement()
- {
- return null;
- }
-
- public Element getParagraphElement(int pos)
- {
- return null;
- }
-}
+ private static final long serialVersionUID = 4758290289196893664L;
+
+ public static final String lineLimitAttribute = "lineLimit";
+ public static final String tabSizeAttribute = "tabSize";
+
+ private int tabSize;
+
+ public PlainDocument()
+ {
+ this(new GapContent());
+ }
+ public PlainDocument(AbstractDocument.Content content)
+ {
+ super(content);
+ tabSize = 8;
+ }
+
+ public Element getDefaultRootElement()
+ {
+ return null;
+ }
+
+ public Element getParagraphElement(int pos)
+ {
+ return null;
+ }
+}
diff --git a/libjava/javax/swing/text/Style.java b/libjava/javax/swing/text/Style.java
index f6c8723b03a..d8553c02c92 100644
--- a/libjava/javax/swing/text/Style.java
+++ b/libjava/javax/swing/text/Style.java
@@ -39,9 +39,26 @@ package javax.swing.text;
import javax.swing.event.ChangeListener;
-public interface Style
+public interface Style extends MutableAttributeSet
{
- void addChangeListener(ChangeListener l);
- String getName();
- void removeChangeListener(ChangeListener l);
+ /**
+ * Returns the name of the style.
+ *
+ * @return the name
+ */
+ String getName();
+
+ /**
+ * Adds a <code>ChangeListener</code> object to the style.
+ *
+ * @param listener the listener object to add
+ */
+ void addChangeListener(ChangeListener listener);
+
+ /**
+ * Removes a <code>ChangeListener</code> from to the style.
+ *
+ * @param listener the listener object to remove,
+ */
+ void removeChangeListener(ChangeListener listener);
}
OpenPOWER on IntegriCloud