On Mon, 30 Sep 2024 21:33:39 GMT, Kevin Rushforth <k...@openjdk.org> wrote:

> You mean `StyleAttributeMap.Builder`, right? Question then: how do I now 
> create a StyleAttributeMap from a CSS style?

No, these methods are in `RichParagraph.Builder`.

CSS styles in StyleAttributeMap are a special case, the attribute itself is not 
public (`com.sun.jfx.incubator.scene.control.richtext.CssStyles.CSS`).  I've 
added additional explanations to the `StyledTextModel` class:


 * <h2>Creating a Paragraph</h2>
 * The model presents its content to the view(s) via immutable {@link 
RichParagraph}.
 * There are two ways of adding styles to the model:
 * <ul>
 * <li>Using the style names in the stylesheet or inline styles (example: 
{@code "-fx-font-size:200%;"}), or
 * <li>Using attributes defined in {@link StyleAttributeMap}, such as bold 
typeface, italic, and so on.
 *     In this case, the resulting paragraph appearance is decoupled from the 
stylesheet and will look the same
 *     regardless of the active stylesheet.
 * </ul>
 * The latter method is intended for applications where an editable control is 
needed, such as general purpose
 * rich text editor, the former is designed for view-only informational 
controls that must follow the application
 * theme and therefore are coupled to the stylesheet.
 * 


So, to answer your question, the user creates rich paragraph coupled to the CSS 
stylesheet like so:


                @Override
                public RichParagraph getParagraph(int index) {
                    String text = getPlainText(index);
                    RichParagraph.Builder b = RichParagraph.builder();
                    // monospaced and underline are the names of CSS styles in 
the stylesheet
                    b.withInlineAndExternalStyles(text, "-fx-fill:darkgreen;", 
"monospaced", "underline");
                    return b.build();
                }

-------------

PR Comment: https://git.openjdk.org/jfx/pull/1524#issuecomment-2386273314

Reply via email to