aboutsummaryrefslogtreecommitdiff
path: root/libjava/classpath/javax/swing/JTextPane.java
diff options
context:
space:
mode:
Diffstat (limited to 'libjava/classpath/javax/swing/JTextPane.java')
-rw-r--r--libjava/classpath/javax/swing/JTextPane.java45
1 files changed, 32 insertions, 13 deletions
diff --git a/libjava/classpath/javax/swing/JTextPane.java b/libjava/classpath/javax/swing/JTextPane.java
index 80632fff38e..a2aebd4ca68 100644
--- a/libjava/classpath/javax/swing/JTextPane.java
+++ b/libjava/classpath/javax/swing/JTextPane.java
@@ -39,8 +39,6 @@ exception statement from your version. */
package javax.swing;
import java.awt.Component;
-import java.io.IOException;
-import java.io.ObjectOutputStream;
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
@@ -51,6 +49,7 @@ import javax.swing.text.Element;
import javax.swing.text.MutableAttributeSet;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.Style;
+import javax.swing.text.StyleConstants;
import javax.swing.text.StyledDocument;
import javax.swing.text.StyledEditorKit;
@@ -106,7 +105,7 @@ public class JTextPane
* @throws IllegalArgumentException if <code>document</code> is not an
* instance of <code>StyledDocument</code>
*
- * @see {@link #setStyledDocument}
+ * @see #setStyledDocument
*/
public void setDocument(Document document)
{
@@ -120,7 +119,7 @@ public class JTextPane
/**
* Returns the {@link StyledDocument} that is the content model for
* this <code>JTextPane</code>. This is a typed wrapper for
- * {@link #getDocument}.
+ * {@link #getDocument()}.
*
* @return the content model of this <code>JTextPane</code>
*/
@@ -179,8 +178,6 @@ public class JTextPane
doc.setCharacterAttributes(start, contentLength, getInputAttributes(),
true);
- // Set dot to new position.
- setCaretPosition(start + contentLength);
}
catch (BadLocationException e)
{
@@ -197,9 +194,20 @@ public class JTextPane
*/
public void insertComponent(Component component)
{
- // TODO: One space must be inserted here with attributes set to indicate
- // that the component must be displayed here. Have to figure out the
- // attributes.
+ SimpleAttributeSet atts = new SimpleAttributeSet();
+ atts.addAttribute(StyleConstants.ComponentAttribute, component);
+ atts.addAttribute(StyleConstants.NameAttribute,
+ StyleConstants.ComponentElementName);
+ try
+ {
+ getDocument().insertString(getCaret().getDot(), " ", atts);
+ }
+ catch (BadLocationException ex)
+ {
+ AssertionError err = new AssertionError("Unexpected bad location");
+ err.initCause(ex);
+ throw err;
+ }
}
/**
@@ -209,9 +217,20 @@ public class JTextPane
*/
public void insertIcon(Icon icon)
{
- // TODO: One space must be inserted here with attributes set to indicate
- // that the icon must be displayed here. Have to figure out the
- // attributes.
+ SimpleAttributeSet atts = new SimpleAttributeSet();
+ atts.addAttribute(StyleConstants.IconAttribute, icon);
+ atts.addAttribute(StyleConstants.NameAttribute,
+ StyleConstants.IconElementName);
+ try
+ {
+ getDocument().insertString(getCaret().getDot(), " ", atts);
+ }
+ catch (BadLocationException ex)
+ {
+ AssertionError err = new AssertionError("Unexpected bad location");
+ err.initCause(ex);
+ throw err;
+ }
}
/**
@@ -300,7 +319,7 @@ public class JTextPane
* @param replace if <code>true</code>, the attributes of the current
* selection are overridden, otherwise they are merged
*
- * @see {@link #getInputAttributes}
+ * @see #getInputAttributes
*/
public void setCharacterAttributes(AttributeSet attribute,
boolean replace)