jdk/src/share/classes/javax/swing/JTextPane.java
author gsm
Mon, 07 Sep 2009 12:27:53 +0400
changeset 3750 4195b035138f
parent 715 f16baef3a20e
child 5506 202f599c92aa
permissions -rw-r--r--
6699856: Creating text in a JTextPane using Chinese text causes undesired behavior Reviewed-by: peterz
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
715
f16baef3a20e 6719955: Update copyright year
xdono
parents: 410
diff changeset
     2
 * Copyright 1997-2008 Sun Microsystems, Inc.  All Rights Reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package javax.swing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.event.ActionEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.ObjectOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.ObjectInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import javax.swing.text.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import javax.swing.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import javax.swing.plaf.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * A text component that can be marked up with attributes that are
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * represented graphically.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * You can find how-to information and examples of using text panes in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * <a href="http://java.sun.com/docs/books/tutorial/uiswing/components/text.html">Using Text Components</a>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * a section in <em>The Java Tutorial.</em>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * This component models paragraphs
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * that are composed of runs of character level attributes.  Each
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * paragraph may have a logical style attached to it which contains
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * the default attributes to use if not overridden by attributes set
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * on the paragraph or character run.  Components and images may
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * be embedded in the flow of text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * <dl>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * <dt><b><font size=+1>Newlines</font></b>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * <dd>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * For a discussion on how newlines are handled, see
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * <a href="text/DefaultEditorKit.html">DefaultEditorKit</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * </dl>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * <strong>Warning:</strong> Swing is not thread safe. For more
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * information see <a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * href="package-summary.html#threading">Swing's Threading
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * Policy</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * the same version of Swing.  As of 1.4, support for long term storage
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * of all JavaBeans<sup><font size="-2">TM</font></sup>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 *   attribute: isContainer true
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * description: A text component that can be marked up with attributes that are graphically represented.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * @author  Timothy Prinzing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * @see javax.swing.text.StyledEditorKit
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
public class JTextPane extends JEditorPane {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * Creates a new <code>JTextPane</code>.  A new instance of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * <code>StyledEditorKit</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * created and set, and the document model set to <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    public JTextPane() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        EditorKit editorKit = createDefaultEditorKit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        String contentType = editorKit.getContentType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        if (contentType != null
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            && getEditorKitClassNameForContentType(contentType) ==
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                 defaultEditorKitMap.get(contentType)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            setEditorKitForContentType(contentType, editorKit);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        setEditorKit(editorKit);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * Creates a new <code>JTextPane</code>, with a specified document model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * A new instance of <code>javax.swing.text.StyledEditorKit</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     *  is created and set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * @param doc the document model
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    public JTextPane(StyledDocument doc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        this();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        setStyledDocument(doc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * Returns the class ID for the UI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * @return the string "TextPaneUI"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * @see JComponent#getUIClassID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * @see UIDefaults#getUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    public String getUIClassID() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        return uiClassID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * Associates the editor with a text document.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * must be a <code>StyledDocument</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * @param doc  the document to display/edit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * @exception IllegalArgumentException  if <code>doc</code> can't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     *   be narrowed to a <code>StyledDocument</code> which is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     *   required type of model for this text component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    public void setDocument(Document doc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        if (doc instanceof StyledDocument) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            super.setDocument(doc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            throw new IllegalArgumentException("Model must be StyledDocument");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * Associates the editor with a text document.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * The currently registered factory is used to build a view for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * the document, which gets displayed by the editor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * @param doc  the document to display/edit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    public void setStyledDocument(StyledDocument doc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        super.setDocument(doc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * Fetches the model associated with the editor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * @return the model
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    public StyledDocument getStyledDocument() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        return (StyledDocument) getDocument();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * Replaces the currently selected content with new content
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * represented by the given string.  If there is no selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * this amounts to an insert of the given text.  If there
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * is no replacement text this amounts to a removal of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * current selection.  The replacement text will have the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * attributes currently defined for input at the point of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * insertion.  If the document is not editable, beep and return.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * @param content  the content to replace the selection with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     */
3750
4195b035138f 6699856: Creating text in a JTextPane using Chinese text causes undesired behavior
gsm
parents: 715
diff changeset
   173
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    public void replaceSelection(String content) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        replaceSelection(content, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    private void replaceSelection(String content, boolean checkEditable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        if (checkEditable && !isEditable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            UIManager.getLookAndFeel().provideErrorFeedback(JTextPane.this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        Document doc = getStyledDocument();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        if (doc != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                Caret caret = getCaret();
3750
4195b035138f 6699856: Creating text in a JTextPane using Chinese text causes undesired behavior
gsm
parents: 715
diff changeset
   187
                boolean composedTextSaved = saveComposedText(caret.getDot());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                int p0 = Math.min(caret.getDot(), caret.getMark());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                int p1 = Math.max(caret.getDot(), caret.getMark());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                AttributeSet attr = getInputAttributes().copyAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                if (doc instanceof AbstractDocument) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                    ((AbstractDocument)doc).replace(p0, p1 - p0, content,attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                    if (p0 != p1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                        doc.remove(p0, p1 - p0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                    if (content != null && content.length() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                        doc.insertString(p0, content, attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                }
3750
4195b035138f 6699856: Creating text in a JTextPane using Chinese text causes undesired behavior
gsm
parents: 715
diff changeset
   202
                if (composedTextSaved) {
4195b035138f 6699856: Creating text in a JTextPane using Chinese text causes undesired behavior
gsm
parents: 715
diff changeset
   203
                    restoreComposedText();
4195b035138f 6699856: Creating text in a JTextPane using Chinese text causes undesired behavior
gsm
parents: 715
diff changeset
   204
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            } catch (BadLocationException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                UIManager.getLookAndFeel().provideErrorFeedback(JTextPane.this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * Inserts a component into the document as a replacement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * for the currently selected content.  If there is no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * selection the component is effectively inserted at the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * current position of the caret.  This is represented in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * the associated document as an attribute of one character
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * of content.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * The component given is the actual component used by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * JTextPane.  Since components cannot be a child of more than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * one container, this method should not be used in situations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * where the model is shared by text components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * The component is placed relative to the text baseline
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * according to the value returned by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * <code>Component.getAlignmentY</code>.  For Swing components
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * this value can be conveniently set using the method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * <code>JComponent.setAlignmentY</code>.  For example, setting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * a value of <code>0.75</code> will cause 75 percent of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * component to be above the baseline, and 25 percent of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * component to be below the baseline.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * @param c    the component to insert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    public void insertComponent(Component c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        MutableAttributeSet inputAttributes = getInputAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        inputAttributes.removeAttributes(inputAttributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        StyleConstants.setComponent(inputAttributes, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        replaceSelection(" ", false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        inputAttributes.removeAttributes(inputAttributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * Inserts an icon into the document as a replacement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * for the currently selected content.  If there is no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * selection the icon is effectively inserted at the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * current position of the caret.  This is represented in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * the associated document as an attribute of one character
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * of content.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * @param g    the icon to insert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * @see Icon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    public void insertIcon(Icon g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        MutableAttributeSet inputAttributes = getInputAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        inputAttributes.removeAttributes(inputAttributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        StyleConstants.setIcon(inputAttributes, g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        replaceSelection(" ", false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        inputAttributes.removeAttributes(inputAttributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * Adds a new style into the logical style hierarchy.  Style attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * resolve from bottom up so an attribute specified in a child
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * will override an attribute specified in the parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * @param nm   the name of the style (must be unique within the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     *   collection of named styles).  The name may be <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     *   if the style is unnamed, but the caller is responsible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     *   for managing the reference returned as an unnamed style can't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     *   be fetched by name.  An unnamed style may be useful for things
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     *   like character attribute overrides such as found in a style
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     *   run.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * @param parent the parent style.  This may be <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     *   if unspecified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     *   attributes need not be resolved in some other style.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * @return the new <code>Style</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    public Style addStyle(String nm, Style parent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        StyledDocument doc = getStyledDocument();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        return doc.addStyle(nm, parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * Removes a named non-<code>null</code> style previously added to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * the document.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * @param nm  the name of the style to remove
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    public void removeStyle(String nm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        StyledDocument doc = getStyledDocument();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        doc.removeStyle(nm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * Fetches a named non-<code>null</code> style previously added.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * @param nm  the name of the style
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * @return the <code>Style</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    public Style getStyle(String nm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        StyledDocument doc = getStyledDocument();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        return doc.getStyle(nm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * Sets the logical style to use for the paragraph at the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * current caret position.  If attributes aren't explicitly set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * for character and paragraph attributes they will resolve
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * through the logical style assigned to the paragraph, which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * in term may resolve through some hierarchy completely
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * independent of the element hierarchy in the document.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * @param s  the logical style to assign to the paragraph,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     *          or <code>null</code> for no style
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    public void setLogicalStyle(Style s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        StyledDocument doc = getStyledDocument();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        doc.setLogicalStyle(getCaretPosition(), s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * Fetches the logical style assigned to the paragraph represented
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * by the current position of the caret, or <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * @return the <code>Style</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    public Style getLogicalStyle() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        StyledDocument doc = getStyledDocument();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        return doc.getLogicalStyle(getCaretPosition());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * Fetches the character attributes in effect at the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * current location of the caret, or <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * @return the attributes, or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    public AttributeSet getCharacterAttributes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        StyledDocument doc = getStyledDocument();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        Element run = doc.getCharacterElement(getCaretPosition());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        if (run != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
            return run.getAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * Applies the given attributes to character
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * content.  If there is a selection, the attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * are applied to the selection range.  If there
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * is no selection, the attributes are applied to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * the input attribute set which defines the attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * for any new text that gets inserted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * @param attr the attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     * @param replace if true, then replace the existing attributes first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    public void setCharacterAttributes(AttributeSet attr, boolean replace) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        int p0 = getSelectionStart();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        int p1 = getSelectionEnd();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        if (p0 != p1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
            StyledDocument doc = getStyledDocument();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
            doc.setCharacterAttributes(p0, p1 - p0, attr, replace);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
            MutableAttributeSet inputAttributes = getInputAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
            if (replace) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                inputAttributes.removeAttributes(inputAttributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
            inputAttributes.addAttributes(attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * Fetches the current paragraph attributes in effect
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * at the location of the caret, or <code>null</code> if none.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     * @return the attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    public AttributeSet getParagraphAttributes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        StyledDocument doc = getStyledDocument();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        Element paragraph = doc.getParagraphElement(getCaretPosition());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        if (paragraph != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
            return paragraph.getAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * Applies the given attributes to paragraphs.  If
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * there is a selection, the attributes are applied
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * to the paragraphs that intersect the selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * If there is no selection, the attributes are applied
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * to the paragraph at the current caret position.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * @param attr the non-<code>null</code> attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     * @param replace if true, replace the existing attributes first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    public void setParagraphAttributes(AttributeSet attr, boolean replace) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        int p0 = getSelectionStart();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        int p1 = getSelectionEnd();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        StyledDocument doc = getStyledDocument();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        doc.setParagraphAttributes(p0, p1 - p0, attr, replace);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * Gets the input attributes for the pane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * @return the attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    public MutableAttributeSet getInputAttributes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        return getStyledEditorKit().getInputAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * Gets the editor kit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     * @return the editor kit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    protected final StyledEditorKit getStyledEditorKit() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        return (StyledEditorKit) getEditorKit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     * @see #getUIClassID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     * @see #readObject
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    private static final String uiClassID = "TextPaneUI";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     * See <code>readObject</code> and <code>writeObject</code> in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * <code>JComponent</code> for more
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * information about serialization in Swing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     * @param s the output stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    private void writeObject(ObjectOutputStream s) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        s.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        if (getUIClassID().equals(uiClassID)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
            byte count = JComponent.getWriteObjCounter(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
            JComponent.setWriteObjCounter(this, --count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
            if (count == 0 && ui != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                ui.installUI(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    // --- JEditorPane ------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     * Creates the <code>EditorKit</code> to use by default.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     * is implemented to return <code>javax.swing.text.StyledEditorKit</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * @return the editor kit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    protected EditorKit createDefaultEditorKit() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        return new StyledEditorKit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     * Sets the currently installed kit for handling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     * content.  This is the bound property that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     * establishes the content type of the editor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     * @param kit the desired editor behavior
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     * @exception IllegalArgumentException if kit is not a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     *          <code>StyledEditorKit</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    public final void setEditorKit(EditorKit kit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        if (kit instanceof StyledEditorKit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
            super.setEditorKit(kit);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
            throw new IllegalArgumentException("Must be StyledEditorKit");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     * Returns a string representation of this <code>JTextPane</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     * This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     * is intended to be used only for debugging purposes, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     * content and format of the returned string may vary between
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     * implementations. The returned string may be empty but may not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     * be <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     * @return  a string representation of this <code>JTextPane</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
    protected String paramString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        return super.paramString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
}