aboutsummaryrefslogtreecommitdiff
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.java26
-rw-r--r--libjava/javax/swing/text/Document.java136
-rw-r--r--libjava/javax/swing/text/GapContent.java76
-rw-r--r--libjava/javax/swing/text/StyleConstants.java8
4 files changed, 239 insertions, 7 deletions
diff --git a/libjava/javax/swing/text/AbstractDocument.java b/libjava/javax/swing/text/AbstractDocument.java
index a2c3fa6..29be0ad 100644
--- a/libjava/javax/swing/text/AbstractDocument.java
+++ b/libjava/javax/swing/text/AbstractDocument.java
@@ -43,6 +43,7 @@ import java.io.Serializable;
import java.util.Dictionary;
import java.util.Enumeration;
import java.util.EventListener;
+import java.util.Hashtable;
import java.util.Vector;
import javax.swing.event.DocumentEvent;
@@ -71,7 +72,10 @@ public abstract class AbstractDocument
Content content;
AttributeContext context;
DocumentFilter documentFilter;
-
+
+ /** The documents properties. */
+ Dictionary properties;
+
protected EventListenerList listenerList = new EventListenerList();
protected AbstractDocument(Content doc)
@@ -175,7 +179,11 @@ public abstract class AbstractDocument
public Dictionary getDocumentProperties()
{
- return null;
+ // FIXME: make me thread-safe
+ if (properties == null)
+ properties = new Hashtable();
+
+ return properties;
}
public Position getEndPosition()
@@ -201,7 +209,12 @@ public abstract class AbstractDocument
public Object getProperty(Object key)
{
- return null;
+ // FIXME: make me thread-safe
+ Object value = null;
+ if (properties != null)
+ value = properties.get(key);
+
+ return value;
}
public Element[] getRootElements()
@@ -258,6 +271,11 @@ public abstract class AbstractDocument
public void putProperty(Object key, Object value)
{
+ // FIXME: make me thread-safe
+ if (properties == null)
+ properties = new Hashtable();
+
+ properties.put(key, value);
}
public void readLock()
@@ -366,6 +384,8 @@ public abstract class AbstractDocument
public void setDocumentProperties(Dictionary x)
{
+ // FIXME: make me thread-safe
+ properties = x;
}
protected void writeLock()
diff --git a/libjava/javax/swing/text/Document.java b/libjava/javax/swing/text/Document.java
index d3bbabb..31aded6 100644
--- a/libjava/javax/swing/text/Document.java
+++ b/libjava/javax/swing/text/Document.java
@@ -40,48 +40,182 @@ package javax.swing.text;
import javax.swing.event.DocumentListener;
import javax.swing.event.UndoableEditListener;
-
+/**
+ * A Document is the model that backs up all text components in Swing.
+ * This interface supports different kinds of implementations, from
+ * simple plain text model up to complex styled HTML or RTF models.
+ */
public interface Document
{
+ /**
+ * The key for the property that describes the source of a document.
+ */
String StreamDescriptionProperty = "stream";
+
+ /**
+ * The key for the property that is the title of a document.
+ */
String TitleProperty = "title";
+ /**
+ * Adds a {@link DocumentListener} to this document.
+ *
+ * @param listener the DocumentListener to add
+ */
void addDocumentListener(DocumentListener listener);
+ /**
+ * Adds an {@link UndoableEditListener} to this document.
+ *
+ * @param listener the UndoableEditListener to add
+ */
void addUndoableEditListener(UndoableEditListener listener);
+ /**
+ * Creates a mark in the character content at the specified offset.
+ *
+ * @param offs the offset where to place the mark
+ *
+ * @return the created Position object
+ *
+ * @throws BadLocationException of the specified offset is not a valid
+ * position in the documents content
+ */
Position createPosition(int offs)
throws BadLocationException;
+ /**
+ * Returns the default root element. Views should be using this element
+ * unless other mechanisms for assigning views to element structure is
+ * provided.
+ *
+ * @return the default root element
+ */
Element getDefaultRootElement();
+ /**
+ * Returns the position that marks the end of the document.
+ *
+ * @return the position that marks the end of the document
+ */
Position getEndPosition();
+ /**
+ * Returns the length of the document content.
+ *
+ * @return the length of the document content
+ */
int getLength();
+ /**
+ * Returns a document property with the specified key.
+ *
+ * @param key the (non-null) key for the property to fetch
+ *
+ * @return the property for <code>key</code> or null if no such property
+ * is stored
+ */
Object getProperty(Object key);
+ /**
+ * Returns the root elements of the document content.
+ *
+ * @return the root elements of the document content
+ */
Element[] getRootElements();
+ /**
+ * Returns the position that marks the beginning of the document
+ * content.
+ *
+ * @return the start position
+ */
Position getStartPosition();
+ /**
+ * Returns the textual content starting at <code>offset</code> with
+ * a length of <code>length</code>.
+ *
+ * @param offset the beginning of the text fragment to fetch
+ * @param length the length of the text fragment to fetch
+ *
+ * @return the text fragment starting at <code>offset</code> with
+ * a length of <code>length</code>
+ *
+ * @throws BadLocationException if <code>offset</code> or <code>length</code>
+ * are no valid locations in the document content
+ */
String getText(int offset, int length)
throws BadLocationException;
+ /**
+ * Fetch the textual content starting at <code>offset</code> with
+ * a length of <code>length</code> and store it in <code>txt</code>.
+ *
+ * @param offset the beginning of the text fragment to fetch
+ * @param length the length of the text fragment to fetch
+ * @param txt the Segment where to store the text fragment
+ *
+ * @throws BadLocationException if <code>offset</code> or <code>length</code>
+ * are no valid locations in the document content
+ */
void getText(int offset, int length, Segment txt)
throws BadLocationException;
+ /**
+ * Inserts a piece of text with an AttributeSet at the specified
+ * <code>offset</code>.
+ *
+ * @param offset the location where to insert the content
+ * @param str the textual content to insert
+ * @param a the Attributes associated with the piece of text
+ *
+ * @throws BadLocationException if <code>offset</code>
+ * is not a valid location in the document content
+ */
void insertString(int offset, String str, AttributeSet a)
throws BadLocationException;
+ /**
+ * Sets a document property.
+ *
+ * @param key the key of the property
+ * @param value the value of the property
+ */
void putProperty(Object key, Object value);
+ /**
+ * Removes a piece of content.
+ *
+ * @param offs the location of the fragment to remove
+ * @param len the length of the fragment to remove
+ *
+ * @throws BadLocationException if <code>offs</code> or <code>len</code>
+ * are no valid locations in the document content
+ */
void remove(int offs, int len)
throws BadLocationException;
+ /**
+ * Removes a DocumentListener from this Document.
+ *
+ * @param listener the DocumentListener to remove
+ */
void removeDocumentListener(DocumentListener listener);
+ /**
+ * Removes an UndoableEditListener from this Document.
+ *
+ * @param listener the UndoableEditListener to remove
+ */
void removeUndoableEditListener(UndoableEditListener listener);
+ /**
+ * This allows the Document to be rendered safely. It is made sure that
+ * the Runnable can read the document without any changes while reading.
+ * The Runnable is not allowed to change the Document itself.
+ *
+ * @param r the Runnable that renders the Document
+ */
void render(Runnable r);
}
diff --git a/libjava/javax/swing/text/GapContent.java b/libjava/javax/swing/text/GapContent.java
index 44a8dcb..ea088dd 100644
--- a/libjava/javax/swing/text/GapContent.java
+++ b/libjava/javax/swing/text/GapContent.java
@@ -44,6 +44,16 @@ import java.io.Serializable;
// lets just use a stringbuffer instead.
import javax.swing.undo.UndoableEdit;
+/**
+ * This implementation of {@link AbstractDocument.Content} uses a gapped
+ * buffer. This takes advantage of the fact that text area content is
+ * mostly inserted sequentially. The buffer is a char array that maintains
+ * a gap at the current insertion point. If characters a inserted at
+ * gap boundaries, the cost is minimal (simple array access). The array only
+ * has to be shifted around when the insertion point moves (then the gap also
+ * moves and one array copy is necessary) or when the gap is filled up and
+ * the buffer has to be enlarged.
+ */
public class GapContent
implements AbstractDocument.Content, Serializable
{
@@ -51,16 +61,34 @@ public class GapContent
StringBuffer buf = new StringBuffer();
+ /**
+ * Creates a new GapContent object.
+ */
public GapContent()
{
this(10);
}
+ /**
+ * Creates a new GapContent object with a specified initial size.
+ *
+ * @param size the initial size of the buffer
+ */
public GapContent(int size)
{
buf.append("\n");
}
+ /**
+ * Creates and returns a mark at the specified position.
+ *
+ * @param offset the position at which to create the mark
+ *
+ * @return the create Position object for the mark
+ *
+ * @throws BadLocationException if the offset is not a valid position in
+ * the buffer
+ */
public Position createPosition(final int offset) throws BadLocationException
{
return new Position()
@@ -74,11 +102,28 @@ public class GapContent
};
}
+ /**
+ * Returns the length of the content.
+ *
+ * @return the length of the content
+ */
public int length()
{
return buf.length();
}
+ /**
+ * Inserts a string at the specified position.
+ *
+ * @param where the position where the string is inserted
+ * @param str the string that is to be inserted
+ *
+ * @return an UndoableEdit object (currently not supported, so
+ * <code>null</code> is returned)
+ *
+ * @throws BadLocationException if <code>where</code> is not a valid location
+ * in the buffer
+ */
public UndoableEdit insertString(int where, String str)
throws BadLocationException
{
@@ -86,6 +131,18 @@ public class GapContent
return null;
}
+ /**
+ * Removes a piece of content at th specified position.
+ *
+ * @param where the position where the content is to be removed
+ * @param nitems number of characters to be removed
+ *
+ * @return an UndoableEdit object (currently not supported, so
+ * <code>null</code> is returned)
+ *
+ * @throws BadLocationException if <code>where</code> is not a valid location
+ * in the buffer
+ */
public UndoableEdit remove(int where, int nitems)
throws BadLocationException
{
@@ -93,11 +150,30 @@ public class GapContent
return null;
}
+ /**
+ * Returns a piece of content as String.
+ *
+ * @param where the start location of the fragment
+ * @param len the length of the fragment
+ *
+ * @throws BadLocationException if <code>where</code> or
+ * <code>where + len</code> are no valid locations in the buffer
+ */
public String getString(int where, int len) throws BadLocationException
{
return buf.substring(where, where+len);
}
+ /**
+ * Fetches a piece of content and stores it in a {@link Segment} object.
+ *
+ * @param where the start location of the fragment
+ * @param len the length of the fragment
+ * @param txt the Segment object to store the fragment in
+ *
+ * @throws BadLocationException if <code>where</code> or
+ * <code>where + len</code> are no valid locations in the buffer
+ */
public void getChars(int where, int len, Segment txt)
throws BadLocationException
{
diff --git a/libjava/javax/swing/text/StyleConstants.java b/libjava/javax/swing/text/StyleConstants.java
index e1232af..e9019b1 100644
--- a/libjava/javax/swing/text/StyleConstants.java
+++ b/libjava/javax/swing/text/StyleConstants.java
@@ -1,5 +1,5 @@
/* StyleConstants.java --
- Copyright (C) 2004 Free Software Foundation, Inc.
+ Copyright (C) 2004, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -83,8 +83,10 @@ public class StyleConstants
public static final Object ResolveAttribute = new StyleConstants("resolver");
String keyname;
-
- private StyleConstants(String k)
+
+ // Package-private to avoid accessor constructor for use by
+ // subclasses.
+ StyleConstants(String k)
{
keyname = k;
}