Java: Swing: Text components and Document: AttributeSet properties
Most attributes defined in StyleConstants also have utility methods for setting and accessing, but not for removing. Removing must be done directly. These methods also introduce a global default value, which is questionable.
Field Name | Definition class (or inner class of StyleConstants) | Value type | Description / Comments | Direct use | Default value (if StyleConstants method) | StyleConstants use | View support (implies StyleConstants use unless from document) |
|---|---|---|---|---|---|---|---|
ResolveAttribute | StyleConstants (also AttributeSet) | AttributeSet | resolver, for internal use only As a client, you shouldn't care where the value comes from. | internal (StyleContext, implementations) MinimalHTMLWriter: class attribute for <p> | |||
NameAttribute | StyleConstants (also AttributeSet) | Object (maybe String would make more sense, but HTML packages uses HTML.Tag) | name maybe intended to have the same value as Style.getName() | StyleContext: uses it to store the name of the Style (a String) HTML package: a lot | |||
ElementNameAttribute | AbstractDocument | String | if this attribute is set on an AbstractElement, it returns the value as its name. Custom elements (or documents) must support it for embedded Components/Icons (at least in theAttributeSet given to insertString()). | transient AbstractDocument: see comments DefaultStyledDocument (set): used to change the name of an element StyleConstants (add): setComponent, setIcon | |||
RUN_DIRECTION | TextAttribute | Boolean | run direction left to right or not? | AbstractDocument: inspected on paragraph elements for bidi structure DefaultStyledDocument: setParagraphAttributes: if present (and i18n on Document), update bidi structure (this is deactivated in HTMLDocument) | |||
BidiLevel | CharacterConstants | Integer | Unicode bidirectional level | AbstractDocument.BidiElement: set | 0 | AbstractDocument: TextLayoutStrategy: | |
ComposedTextAttribute | StyleConstants | AttributedString | composed text (input method) | transient AbstractDocument: JTextComponent: Utilities: | |||
Background | ColorConstants | Color | Background color | LG (see below) | black (why?) | SC | LG by document JTextComponent: ComposedTextCaret by document |
Foreground | ColorConstants | Color | Foreground color | from component | black | from component SC action BasicHTML (set): set special color so that it is taken from component | LG by document html/ImageView by document |
Family | FontConstants | String | Font name | from component | Monospaced | from component SC action | LG by document html/CommentView/HiddenTagView by document |
Size | FontConstants | Integer (should be Number) | Font size | from component | 12 | from component SC action html/CSS | LG by document |
Bold | FontConstants | Boolean? | from component | false | from component SC action Utilities: paintComposedText html tags | LG by document | |
Italic | FontConstants | Boolean? | from component | false | from component SC action Utilities: paintComposedText html tags | LG by document | |
Underline | CharacterConstants | Boolean | false | action html tags | LG | ||
StrikeThrough | CharacterConstants | Boolean | false | LG | |||
Subscript | CharacterConstants | Boolean | false | SC | LG | ||
Superscript | CharacterConstants | Boolean | false | SC | LG | ||
LeftIndent | ParagraphConstants | Float (points) | left margin | 0 | CompositeView (latent) | ||
RightIndent | ParagraphConstants | Float (points) | left margin | 0 | CompositeView (latent) | ||
SpaceAbove | ParagraphConstants | Float (points) | left margin | 0 | CompositeView (latent) | ||
SpaceBelow | ParagraphConstants | Float (points) | left margin | 0 | CompositeView (latent) | ||
FirstLineIndent | ParagraphConstants | Float (points) | indention of first line may be <0 | 0 | ParagraphView | ||
LineSpacing | ParagraphConstants | Float (points) | additional line spacing | 0 | ParagraphView | ||
Alignment | ParagraphConstants | Integer (enum) | paragraph alignment | ALIGN_LEFT | action | ParagraphView html/HRuleView html/LineView | |
TabSet | ParagraphConstants | TabSet | tabulator settings | null | ParagraphView | ||
Orientation | ParagraphConstants | undocumented | unused | ||||
ComponentAttribute | CharacterConstants | Component | embedded component | transient special view | null | JTextPane (set): insertComponent | ComponentView |
IconAttribute | CharacterConstants | Icon | embedded icon | transient special view | null | JTextPane (set): insertIcon | IconView |
ModelAttribute | StyleConstants | Object | Model for embedded views | only HTML package |
and background: test for isDefined() and only then call getBackground(). Probably to avoid repainting inherited backgrounds, but does it work?
StyleContext methods getForeground(), getBackground(), getFont() convert the attributes into the corresponding Object. Sub/superscript decrease the font size by 2. In JDK1.2, getBackground() accidently used Foreground as key and thus returned the foreground color.
They can be used to support the corresponding methods in StyledDocument, and that's what DefaultStyledDocument does.
StyledEditorKit removes it from input attributes (which are given to Document.insertString() when text is typed).
There are setInsets() / setParagraphInsets() in CompositeView and the set values are used for calculation, but they are only called from ParagraphView (and some HTML classes). (The same attributes cannot be easily used for the insets of a paragraph and of parent elements because they are also inherited).
BasicTextPaneUI sets (by StyleConstants) or removes the attribute on the StyledDocument's StyleContext.DEFAULT_STYLE (if it exists) if the text components corresponding property changes.
StyledEditorKit has an Action inner class to change/toggle this attribute
StyledEditorKit (and HTMLEditorKit in fallback mode) create special views (based on ElementNameAttribute) that can something useful with this attribute.
MinimalHTMLWriter creates <u>, <i>, or <b> open/close tags around the element with the attribute
HTML package not inspected yet.
html package doesn't use StyleConstants.set/get/is except where noted.
javax.swing.text.TableView makes references to HTML.Attributes, although it is not in the HTML package.
(C) 2001-2009 Christian Kaufhold (swing@chka.de)