diff options
author | Roman Kennke <roman@kennke.org> | 2005-04-25 19:36:43 +0000 |
---|---|---|
committer | Michael Koch <mkoch@gcc.gnu.org> | 2005-04-25 19:36:43 +0000 |
commit | 8efae6bbfa04f662589bbfc64dbbe68935f973d2 (patch) | |
tree | 6a73f30784c260b998e5fb2e421b3c002d8ff608 /libjava/javax/swing/text | |
parent | 9f62c3e3ed53732a8fe755ad5109c1a6ed25bb0c (diff) | |
download | gcc-8efae6bbfa04f662589bbfc64dbbe68935f973d2.zip gcc-8efae6bbfa04f662589bbfc64dbbe68935f973d2.tar.gz gcc-8efae6bbfa04f662589bbfc64dbbe68935f973d2.tar.bz2 |
2005-04-25 Roman Kennke <roman@kennke.org>
* javax/swing/plaf/basic/BasicScrollBarUI.java
(initDefaults): Initialize thumb*Color fields correctly.
2005-04-25 Roman Kennke <roman@kennke.org>
* javax/swing/text/GapContent.java:
Added API comments.
2005-04-25 Roman Kennke <roman@kennke.org>
* javax/swing/plaf/metal/MetalBorders.java:
Added inner class ScrollPaneBorder.
* javax/swing/plaf/metal/MetalLookAndFeel.java
(initComponentDefaults): Added default for "ScrollPane.border"
to use the new ScrollPaneBorder.
2005-04-25 Roman Kennke <roman@kennke.org>
* javax/swing/text/AbstractDocument.java:
Added FIXME comments. This class still has to be
implemented thread-safe.
2005-04-25 Roman Kennke <roman@kennke.org>
* javax/swing/tree/DefaultTreeSelectionModel.java
(DefaultTreeSelectionModel): Initialize listenerList here.
2005-04-25 Roman Kennke <roman@kennke.org>
* javax/swing/plaf/metal/MetalTextFieldUI.java
(createUI): Return one instance per Component instead of a
shared instance.
2005-04-25 Roman Kennke <roman@kennke.org>
* javax/swing/text/Document.java:
Added API documentation comments.
2005-04-25 Roman Kennke <roman@kennke.org>
* javax/swing/text/AbstractDocument.java
(getDocumentProperties): Implemented.
(setDocumentProperties): Implemented.
(getProperty): Implemented.
(putProperty): Implemented.
2005-04-25 Roman Kennke <roman@kennke.org>
* javax/swing/BoxLayout
(preferredLayoutSize): Fixed computation so that it correctly
adds the top and bottom insets of the container.
2005-04-25 Roman Kennke <roman@kennke.org>
* javax/swing/plaf/basic/BasicMenuItemUI.java
(paintText): Make use of the 'selectionForeground' UI default
for text painting.
2005-04-25 Roman Kennke <roman@kennke.org>
* javax/swing/plaf/basic/BasicLookAndFeel.java
(initSystemColorDefaults): Modified colors to match the
BasicLookAndFeel in the reference implementation.
(initComponentDefaults): Likewise.
From-SVN: r98733
Diffstat (limited to 'libjava/javax/swing/text')
-rw-r--r-- | libjava/javax/swing/text/AbstractDocument.java | 26 | ||||
-rw-r--r-- | libjava/javax/swing/text/Document.java | 136 | ||||
-rw-r--r-- | libjava/javax/swing/text/GapContent.java | 76 | ||||
-rw-r--r-- | libjava/javax/swing/text/StyleConstants.java | 8 |
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; } |