jdk/src/share/classes/javax/swing/text/StyledDocument.java
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1997-1998 Sun Microsystems, Inc.  All Rights Reserved.
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.text;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.awt.Font;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.Color;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * Interface for a generic styled document.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * @author  Timothy Prinzing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
public interface StyledDocument extends Document {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
     * Adds a new style into the logical style hierarchy.  Style attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
     * resolve from bottom up so an attribute specified in a child
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
     * will override an attribute specified in the parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
     * @param nm   the name of the style (must be unique within the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
     *   collection of named styles).  The name may be null if the style
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
     *   is unnamed, but the caller is responsible
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
     *   for managing the reference returned as an unnamed style can't
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
     *   be fetched by name.  An unnamed style may be useful for things
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
     *   like character attribute overrides such as found in a style
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
     *   run.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
     * @param parent the parent style.  This may be null if unspecified
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     *   attributes need not be resolved in some other style.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     * @return the style
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    public Style addStyle(String nm, Style parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     * Removes a named style previously added to the document.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     * @param nm  the name of the style to remove
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    public void removeStyle(String nm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * Fetches a named style previously added.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * @param nm  the name of the style
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * @return the style
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    public Style getStyle(String nm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * Changes the content element attributes used for the given range of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * existing content in the document.  All of the attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * defined in the given Attributes argument are applied to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * given range.  This method can be used to completely remove
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * all content level attributes for the given range by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * giving an Attributes argument that has no attributes defined
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * and setting replace to true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * @param offset the start of the change >= 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * @param length the length of the change >= 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * @param s    the non-null attributes to change to.  Any attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     *  defined will be applied to the text for the given range.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * @param replace indicates whether or not the previous
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     *  attributes should be cleared before the new attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     *  as set.  If true, the operation will replace the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     *  previous attributes entirely.  If false, the new
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     *  attributes will be merged with the previous attributes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    public void setCharacterAttributes(int offset, int length, AttributeSet s, boolean replace);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * Sets paragraph attributes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * @param offset the start of the change >= 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * @param length the length of the change >= 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * @param s    the non-null attributes to change to.  Any attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     *  defined will be applied to the text for the given range.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * @param replace indicates whether or not the previous
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     *  attributes should be cleared before the new attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     *  are set.  If true, the operation will replace the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     *  previous attributes entirely.  If false, the new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     *  attributes will be merged with the previous attributes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    public void setParagraphAttributes(int offset, int length, AttributeSet s, boolean replace);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * Sets the logical style to use for the paragraph at the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * given position.  If attributes aren't explicitly set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * for character and paragraph attributes they will resolve
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * through the logical style assigned to the paragraph, which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * in turn may resolve through some hierarchy completely
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * independent of the element hierarchy in the document.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * @param pos the starting position >= 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * @param s the style to set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    public void setLogicalStyle(int pos, Style s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * Gets a logical style for a given position in a paragraph.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * @param p the position >= 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * @return the style
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    public Style getLogicalStyle(int p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * Gets the element that represents the paragraph that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * encloses the given offset within the document.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * @param pos the offset >= 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * @return the element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    public Element getParagraphElement(int pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * Gets the element that represents the character that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * is at the given offset within the document.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * @param pos the offset >= 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * @return the element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    public Element getCharacterElement(int pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * Takes a set of attributes and turn it into a foreground color
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * specification.  This might be used to specify things
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * like brighter, more hue, etc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * @param attr the set of attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * @return the color
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    public Color getForeground(AttributeSet attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * Takes a set of attributes and turn it into a background color
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * specification.  This might be used to specify things
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * like brighter, more hue, etc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * @param attr the set of attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * @return the color
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    public Color getBackground(AttributeSet attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * Takes a set of attributes and turn it into a font
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * specification.  This can be used to turn things like
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * family, style, size, etc into a font that is available
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * on the system the document is currently being used on.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * @param attr the set of attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * @return the font
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    public Font getFont(AttributeSet attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
}