jdk/src/share/classes/javax/swing/JTextPane.java
author henryjen
Wed, 18 Jun 2014 09:13:46 -0700
changeset 25201 4adc75e0c4e5
parent 22574 7f8ce0c8c20a
permissions -rw-r--r--
8046485: Add missing @since tag under javax.swing.* Reviewed-by: alexsch, prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
22574
7f8ce0c8c20a 8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents: 22260
diff changeset
     2
 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. 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
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3750
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3750
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
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
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3750
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3750
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3750
diff changeset
    23
 * questions.
2
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
20455
f6f9a0c2796b 8020688: Broken links in documentation at http://docs.oracle.com/javase/6/docs/api/index.
mcherkas
parents: 5506
diff changeset
    42
 * <a href="http://docs.oracle.com/javase/tutorial/uiswing/components/text.html">Using Text Components</a>,
2
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.
21982
fd6e5fe509df 8029264: [doclint] more doclint and tidy cleanup
yan
parents: 20458
diff changeset
    52
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * <dl>
22260
c9185e010e03 8031082: Fix non-missing doclint problems in client libraries
darcy
parents: 21982
diff changeset
    54
 * <dt><b>Newlines</b>
2
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
20458
f2423fb3fd19 8025840: Fix all the doclint warnings about trademark
cl
parents: 20455
diff changeset
    71
 * of all JavaBeans&trade;
2
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
25201
4adc75e0c4e5 8046485: Add missing @since tag under javax.swing.*
henryjen
parents: 22574
diff changeset
    81
 * @since 1.2
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 */
22574
7f8ce0c8c20a 8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents: 22260
diff changeset
    83
@SuppressWarnings("serial") // Same-version serialization only
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
public class JTextPane extends JEditorPane {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * Creates a new <code>JTextPane</code>.  A new instance of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * <code>StyledEditorKit</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * created and set, and the document model set to <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    public JTextPane() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        EditorKit editorKit = createDefaultEditorKit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        String contentType = editorKit.getContentType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        if (contentType != null
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            && getEditorKitClassNameForContentType(contentType) ==
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                 defaultEditorKitMap.get(contentType)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            setEditorKitForContentType(contentType, editorKit);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        setEditorKit(editorKit);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * Creates a new <code>JTextPane</code>, with a specified document model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * A new instance of <code>javax.swing.text.StyledEditorKit</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     *  is created and set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * @param doc the document model
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    public JTextPane(StyledDocument doc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        this();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        setStyledDocument(doc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * Returns the class ID for the UI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * @return the string "TextPaneUI"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * @see JComponent#getUIClassID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * @see UIDefaults#getUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    public String getUIClassID() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        return uiClassID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * Associates the editor with a text document.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * must be a <code>StyledDocument</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * @param doc  the document to display/edit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * @exception IllegalArgumentException  if <code>doc</code> can't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     *   be narrowed to a <code>StyledDocument</code> which is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     *   required type of model for this text component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    public void setDocument(Document doc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        if (doc instanceof StyledDocument) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            super.setDocument(doc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            throw new IllegalArgumentException("Model must be StyledDocument");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * Associates the editor with a text document.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * The currently registered factory is used to build a view for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * the document, which gets displayed by the editor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * @param doc  the document to display/edit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    public void setStyledDocument(StyledDocument doc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        super.setDocument(doc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * Fetches the model associated with the editor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * @return the model
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    public StyledDocument getStyledDocument() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        return (StyledDocument) getDocument();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * Replaces the currently selected content with new content
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * represented by the given string.  If there is no selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * this amounts to an insert of the given text.  If there
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * is no replacement text this amounts to a removal of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * current selection.  The replacement text will have the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * attributes currently defined for input at the point of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * insertion.  If the document is not editable, beep and return.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * @param content  the content to replace the selection with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     */
3750
4195b035138f 6699856: Creating text in a JTextPane using Chinese text causes undesired behavior
gsm
parents: 715
diff changeset
   175
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    public void replaceSelection(String content) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        replaceSelection(content, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    private void replaceSelection(String content, boolean checkEditable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        if (checkEditable && !isEditable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            UIManager.getLookAndFeel().provideErrorFeedback(JTextPane.this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        Document doc = getStyledDocument();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        if (doc != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                Caret caret = getCaret();
3750
4195b035138f 6699856: Creating text in a JTextPane using Chinese text causes undesired behavior
gsm
parents: 715
diff changeset
   189
                boolean composedTextSaved = saveComposedText(caret.getDot());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                int p0 = Math.min(caret.getDot(), caret.getMark());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                int p1 = Math.max(caret.getDot(), caret.getMark());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                AttributeSet attr = getInputAttributes().copyAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                if (doc instanceof AbstractDocument) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                    ((AbstractDocument)doc).replace(p0, p1 - p0, content,attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                    if (p0 != p1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                        doc.remove(p0, p1 - p0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                    if (content != null && content.length() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                        doc.insertString(p0, content, attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                }
3750
4195b035138f 6699856: Creating text in a JTextPane using Chinese text causes undesired behavior
gsm
parents: 715
diff changeset
   204
                if (composedTextSaved) {
4195b035138f 6699856: Creating text in a JTextPane using Chinese text causes undesired behavior
gsm
parents: 715
diff changeset
   205
                    restoreComposedText();
4195b035138f 6699856: Creating text in a JTextPane using Chinese text causes undesired behavior
gsm
parents: 715
diff changeset
   206
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            } catch (BadLocationException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                UIManager.getLookAndFeel().provideErrorFeedback(JTextPane.this);
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * Inserts a component into the document as a replacement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * for the currently selected content.  If there is no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * selection the component is effectively inserted at the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * current position of the caret.  This is represented in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * the associated document as an attribute of one character
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * of content.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * The component given is the actual component used by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * JTextPane.  Since components cannot be a child of more than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * one container, this method should not be used in situations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * where the model is shared by text components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * The component is placed relative to the text baseline
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * according to the value returned by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * <code>Component.getAlignmentY</code>.  For Swing components
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * this value can be conveniently set using the method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * <code>JComponent.setAlignmentY</code>.  For example, setting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * a value of <code>0.75</code> will cause 75 percent of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * component to be above the baseline, and 25 percent of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * component to be below the baseline.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * @param c    the component to insert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    public void insertComponent(Component c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        MutableAttributeSet inputAttributes = getInputAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        inputAttributes.removeAttributes(inputAttributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        StyleConstants.setComponent(inputAttributes, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        replaceSelection(" ", false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        inputAttributes.removeAttributes(inputAttributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * Inserts an icon into the document as a replacement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * for the currently selected content.  If there is no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * selection the icon is effectively inserted at the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * current position of the caret.  This is represented in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * the associated document as an attribute of one character
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * of content.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * @param g    the icon to insert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * @see Icon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    public void insertIcon(Icon g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        MutableAttributeSet inputAttributes = getInputAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        inputAttributes.removeAttributes(inputAttributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        StyleConstants.setIcon(inputAttributes, g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        replaceSelection(" ", false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        inputAttributes.removeAttributes(inputAttributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * Adds a new style into the logical style hierarchy.  Style attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * resolve from bottom up so an attribute specified in a child
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * will override an attribute specified in the parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * @param nm   the name of the style (must be unique within the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     *   collection of named styles).  The name may be <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     *   if the style is unnamed, but the caller is responsible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     *   for managing the reference returned as an unnamed style can't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     *   be fetched by name.  An unnamed style may be useful for things
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     *   like character attribute overrides such as found in a style
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     *   run.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * @param parent the parent style.  This may be <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     *   if unspecified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     *   attributes need not be resolved in some other style.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * @return the new <code>Style</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    public Style addStyle(String nm, Style parent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        StyledDocument doc = getStyledDocument();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        return doc.addStyle(nm, parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * Removes a named non-<code>null</code> style previously added to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * the document.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * @param nm  the name of the style to remove
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    public void removeStyle(String nm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        StyledDocument doc = getStyledDocument();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        doc.removeStyle(nm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * Fetches a named non-<code>null</code> style previously added.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * @param nm  the name of the style
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * @return the <code>Style</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    public Style getStyle(String nm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        StyledDocument doc = getStyledDocument();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        return doc.getStyle(nm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * Sets the logical style to use for the paragraph at the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * current caret position.  If attributes aren't explicitly set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * for character and paragraph attributes they will resolve
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * through the logical style assigned to the paragraph, which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * in term may resolve through some hierarchy completely
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * independent of the element hierarchy in the document.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * @param s  the logical style to assign to the paragraph,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     *          or <code>null</code> for no style
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    public void setLogicalStyle(Style s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        StyledDocument doc = getStyledDocument();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        doc.setLogicalStyle(getCaretPosition(), s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * Fetches the logical style assigned to the paragraph represented
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * by the current position of the caret, or <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * @return the <code>Style</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    public Style getLogicalStyle() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        StyledDocument doc = getStyledDocument();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        return doc.getLogicalStyle(getCaretPosition());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * Fetches the character attributes in effect at the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * current location of the caret, or <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * @return the attributes, or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    public AttributeSet getCharacterAttributes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        StyledDocument doc = getStyledDocument();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        Element run = doc.getCharacterElement(getCaretPosition());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        if (run != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
            return run.getAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * Applies the given attributes to character
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * content.  If there is a selection, the attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * are applied to the selection range.  If there
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * is no selection, the attributes are applied to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * the input attribute set which defines the attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * for any new text that gets inserted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * @param attr the attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * @param replace if true, then replace the existing attributes first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    public void setCharacterAttributes(AttributeSet attr, boolean replace) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        int p0 = getSelectionStart();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        int p1 = getSelectionEnd();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        if (p0 != p1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            StyledDocument doc = getStyledDocument();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
            doc.setCharacterAttributes(p0, p1 - p0, attr, replace);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
            MutableAttributeSet inputAttributes = getInputAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            if (replace) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                inputAttributes.removeAttributes(inputAttributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
            inputAttributes.addAttributes(attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     * Fetches the current paragraph attributes in effect
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     * at the location of the caret, or <code>null</code> if none.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     * @return the attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    public AttributeSet getParagraphAttributes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        StyledDocument doc = getStyledDocument();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        Element paragraph = doc.getParagraphElement(getCaretPosition());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        if (paragraph != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            return paragraph.getAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * Applies the given attributes to paragraphs.  If
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * there is a selection, the attributes are applied
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * to the paragraphs that intersect the selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * If there is no selection, the attributes are applied
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * to the paragraph at the current caret position.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * @param attr the non-<code>null</code> attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     * @param replace if true, replace the existing attributes first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    public void setParagraphAttributes(AttributeSet attr, boolean replace) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        int p0 = getSelectionStart();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        int p1 = getSelectionEnd();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        StyledDocument doc = getStyledDocument();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        doc.setParagraphAttributes(p0, p1 - p0, attr, replace);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * Gets the input attributes for the pane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * @return the attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    public MutableAttributeSet getInputAttributes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        return getStyledEditorKit().getInputAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     * Gets the editor kit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     * @return the editor kit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    protected final StyledEditorKit getStyledEditorKit() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        return (StyledEditorKit) getEditorKit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     * @see #getUIClassID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     * @see #readObject
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    private static final String uiClassID = "TextPaneUI";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * See <code>readObject</code> and <code>writeObject</code> in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     * <code>JComponent</code> for more
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     * information about serialization in Swing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     * @param s the output stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    private void writeObject(ObjectOutputStream s) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        s.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        if (getUIClassID().equals(uiClassID)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
            byte count = JComponent.getWriteObjCounter(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
            JComponent.setWriteObjCounter(this, --count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
            if (count == 0 && ui != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                ui.installUI(this);
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    // --- JEditorPane ------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     * Creates the <code>EditorKit</code> to use by default.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * is implemented to return <code>javax.swing.text.StyledEditorKit</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     * @return the editor kit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    protected EditorKit createDefaultEditorKit() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        return new StyledEditorKit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     * Sets the currently installed kit for handling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     * content.  This is the bound property that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     * establishes the content type of the editor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     * @param kit the desired editor behavior
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     * @exception IllegalArgumentException if kit is not a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     *          <code>StyledEditorKit</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    public final void setEditorKit(EditorKit kit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        if (kit instanceof StyledEditorKit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
            super.setEditorKit(kit);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
            throw new IllegalArgumentException("Must be StyledEditorKit");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     * Returns a string representation of this <code>JTextPane</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     * This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     * is intended to be used only for debugging purposes, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     * content and format of the returned string may vary between
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     * implementations. The returned string may be empty but may not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     * be <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     * @return  a string representation of this <code>JTextPane</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
    protected String paramString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        return super.paramString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
}