Class StyleSheet
java.lang.Object
javax.swing.text.StyleContext
javax.swing.text.html.StyleSheet
vaadinx.swing.text.html.StyleSheet
- All Implemented Interfaces:
Serializable, AbstractDocument.AttributeContext
Emulator for
StyleSheet — carries author CSS from
HTMLEditorKit onto the pane's rendered content.
addRule(String) is the load-bearing method; it is the second-most-used
member of the whole javax.swing.text.html surface in the field, almost
always in this shape:
HTMLEditorKit kit = new HTMLEditorKit();
pane.setEditorKit(kit);
kit.getStyleSheet().addRule("body { font-family: sans-serif; }");
Order does not matter. Rules added before the sheet is bound to a pane
(the shape above adds them after setEditorKit, but the reverse is just as
common) are held and flushed on bind, and the peer holds them again until it is
attached to the DOM.
Appearance only
A rule reaches the real<h2> / <p> / <a> elements RTE
renders, so tag selectors translate close to 1:1. What no rule can restore is
structure Quill's model refuses — tables above all — because that is dropped as
the value enters the editor, before styling could apply (SD_sjeditorpane_rte).
Deliberate divergence: the sheet is per-kit, not shared
The JDK'sHTMLEditorKit.getStyleSheet() returns a static sheet
shared by every kit in the JVM, so one addRule silently restyles every
HTML pane in the app. We give each kit its own sheet: the sharing is a
long-standing footgun rather than intent, per-pane styling is what the calling
code means, and shadow-root injection is per-instance anyway. Sharing one kit
across several panes still styles all of them (R_best_effort_behaviour).
What is not reproduced (R_vaadin_first)
The JDK-side rule model is not populated —getRule, getDeclaration
and the AttributeSet views inherited from the JDK class read empty. The
rule text is handed to the peer instead of parsed into a shadow model, per R_vaadin_first's
"don't fabricate a store so a setter round-trips through its own getter";
getRules() exposes what was added for anyone who needs to see it.
At-rules (@media and friends) are skipped with a WARN — the rest of the
sheet still applies.- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class StyleSheet
StyleSheet.BoxPainter, StyleSheet.ListPainterNested classes/interfaces inherited from class StyleContext
StyleContext.NamedStyle, StyleContext.SmallAttributeSet -
Field Summary
Fields inherited from class StyleContext
DEFAULT_STYLE -
Constructor Summary
Constructors -
Method Summary
Methods inherited from class StyleSheet
addAttribute, addAttributes, addCSSAttribute, addCSSAttributeFromHTML, addStyleSheet, createLargeAttributeSet, createSmallAttributeSet, getBackground, getBase, getBoxPainter, getDeclaration, getFont, getForeground, getIndexOfSize, getListPainter, getPointSize, getPointSize, getRule, getRule, getStyleSheets, getViewAttributes, importStyleSheet, loadRules, removeAttribute, removeAttributes, removeAttributes, removeStyle, removeStyleSheet, setBase, setBaseFontSize, setBaseFontSize, stringToColor, translateHTMLToCSSMethods inherited from class StyleContext
addChangeListener, addStyle, getChangeListeners, getCompressionThreshold, getDefaultStyleContext, getEmptySet, getFont, getFontMetrics, getStaticAttribute, getStaticAttributeKey, getStyle, getStyleNames, readAttributes, readAttributeSet, reclaim, registerStaticAttributeKey, removeChangeListener, toString, writeAttributes, writeAttributeSet
-
Constructor Details
-
StyleSheet
public StyleSheet()
-
-
Method Details
-
addRule
Apply a CSS rule to every bound pane's content, and to any pane bound later. Accepts a single rule or a whole stylesheet's worth, as the JDK does.- Overrides:
addRulein classStyleSheet
-
getRules
The rule texts passed toaddRule(String), in order.
-