KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > swing > text > StyledDocument


1 /*
2  * @(#)StyledDocument.java 1.21 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7 package javax.swing.text;
8
9 import java.awt.Font JavaDoc;
10 import java.awt.Color JavaDoc;
11
12 /**
13  * Interface for a generic styled document.
14  *
15  * @author Timothy Prinzing
16  * @version 1.21 12/19/03
17  */

18 public interface StyledDocument extends Document JavaDoc {
19
20     /**
21      * Adds a new style into the logical style hierarchy. Style attributes
22      * resolve from bottom up so an attribute specified in a child
23      * will override an attribute specified in the parent.
24      *
25      * @param nm the name of the style (must be unique within the
26      * collection of named styles). The name may be null if the style
27      * is unnamed, but the caller is responsible
28      * for managing the reference returned as an unnamed style can't
29      * be fetched by name. An unnamed style may be useful for things
30      * like character attribute overrides such as found in a style
31      * run.
32      * @param parent the parent style. This may be null if unspecified
33      * attributes need not be resolved in some other style.
34      * @return the style
35      */

36     public Style JavaDoc addStyle(String JavaDoc nm, Style JavaDoc parent);
37
38     /**
39      * Removes a named style previously added to the document.
40      *
41      * @param nm the name of the style to remove
42      */

43     public void removeStyle(String JavaDoc nm);
44
45     /**
46      * Fetches a named style previously added.
47      *
48      * @param nm the name of the style
49      * @return the style
50      */

51     public Style JavaDoc getStyle(String JavaDoc nm);
52
53     /**
54      * Changes the content element attributes used for the given range of
55      * existing content in the document. All of the attributes
56      * defined in the given Attributes argument are applied to the
57      * given range. This method can be used to completely remove
58      * all content level attributes for the given range by
59      * giving an Attributes argument that has no attributes defined
60      * and setting replace to true.
61      *
62      * @param offset the start of the change >= 0
63      * @param length the length of the change >= 0
64      * @param s the non-null attributes to change to. Any attributes
65      * defined will be applied to the text for the given range.
66      * @param replace indicates whether or not the previous
67      * attributes should be cleared before the new attributes
68      * as set. If true, the operation will replace the
69      * previous attributes entirely. If false, the new
70      * attributes will be merged with the previous attributes.
71      */

72     public void setCharacterAttributes(int offset, int length, AttributeSet JavaDoc s, boolean replace);
73
74     /**
75      * Sets paragraph attributes.
76      *
77      * @param offset the start of the change >= 0
78      * @param length the length of the change >= 0
79      * @param s the non-null attributes to change to. Any attributes
80      * defined will be applied to the text for the given range.
81      * @param replace indicates whether or not the previous
82      * attributes should be cleared before the new attributes
83      * are set. If true, the operation will replace the
84      * previous attributes entirely. If false, the new
85      * attributes will be merged with the previous attributes.
86      */

87     public void setParagraphAttributes(int offset, int length, AttributeSet JavaDoc s, boolean replace);
88
89     /**
90      * Sets the logical style to use for the paragraph at the
91      * given position. If attributes aren't explicitly set
92      * for character and paragraph attributes they will resolve
93      * through the logical style assigned to the paragraph, which
94      * in turn may resolve through some hierarchy completely
95      * independent of the element hierarchy in the document.
96      *
97      * @param pos the starting position >= 0
98      * @param s the style to set
99      */

100     public void setLogicalStyle(int pos, Style JavaDoc s);
101
102     /**
103      * Gets a logical style for a given position in a paragraph.
104      *
105      * @param p the position >= 0
106      * @return the style
107      */

108     public Style JavaDoc getLogicalStyle(int p);
109
110     /**
111      * Gets the element that represents the paragraph that
112      * encloses the given offset within the document.
113      *
114      * @param pos the offset >= 0
115      * @return the element
116      */

117     public Element JavaDoc getParagraphElement(int pos);
118
119     /**
120      * Gets the element that represents the character that
121      * is at the given offset within the document.
122      *
123      * @param pos the offset >= 0
124      * @return the element
125      */

126     public Element JavaDoc getCharacterElement(int pos);
127
128
129     /**
130      * Takes a set of attributes and turn it into a foreground color
131      * specification. This might be used to specify things
132      * like brighter, more hue, etc.
133      *
134      * @param attr the set of attributes
135      * @return the color
136      */

137     public Color JavaDoc getForeground(AttributeSet JavaDoc attr);
138
139     /**
140      * Takes a set of attributes and turn it into a background color
141      * specification. This might be used to specify things
142      * like brighter, more hue, etc.
143      *
144      * @param attr the set of attributes
145      * @return the color
146      */

147     public Color JavaDoc getBackground(AttributeSet JavaDoc attr);
148
149     /**
150      * Takes a set of attributes and turn it into a font
151      * specification. This can be used to turn things like
152      * family, style, size, etc into a font that is available
153      * on the system the document is currently being used on.
154      *
155      * @param attr the set of attributes
156      * @return the font
157      */

158     public Font JavaDoc getFont(AttributeSet JavaDoc attr);
159
160 }
161
Popular Tags