|
4 | 4 | import org.fxmisc.flowless.VirtualizedScrollPane; |
5 | 5 |
|
6 | 6 | import java.util.function.BiConsumer; |
7 | | -import java.util.function.Function; |
8 | 7 |
|
9 | 8 | /** |
10 | 9 | * AreaFactory is a convenience class used to create StyledTextArea |
|
13 | 12 | * |
14 | 13 | */ |
15 | 14 | public class AreaFactory { |
| 15 | + |
| 16 | + /* ********************************************************************** * |
| 17 | + * * |
| 18 | + * StyledTextArea * |
| 19 | + * * |
| 20 | + * ********************************************************************** */ |
| 21 | + |
| 22 | + // StyledTextArea 1 |
16 | 23 | public static <S, PS> StyledTextArea<S, PS> styledTextArea( |
17 | 24 | S initialStyle, BiConsumer<? super TextExt, S> applyStyle, |
18 | | - PS initialParagraphStyle, BiConsumer<TextFlow, PS> applyParagraphStyle, boolean preserveStyle |
| 25 | + PS initialParagraphStyle, BiConsumer<TextFlow, PS> applyParagraphStyle |
19 | 26 | ) { |
20 | | - return new StyledTextArea<S, PS>(initialStyle, applyStyle, initialParagraphStyle, applyParagraphStyle, preserveStyle); |
| 27 | + return new StyledTextArea<S, PS>( |
| 28 | + initialStyle, applyStyle, |
| 29 | + initialParagraphStyle, applyParagraphStyle, |
| 30 | + true); |
21 | 31 | } |
22 | 32 |
|
23 | | - public static <S, PS> StyledTextArea<S, PS> styledTextArea( |
| 33 | + // Embeds StyledTextArea 1 |
| 34 | + public static <S, PS>VirtualizedScrollPane<StyledTextArea<S, PS>> embeddedStyledTextArea( |
24 | 35 | S initialStyle, BiConsumer<? super TextExt, S> applyStyle, |
25 | 36 | PS initialParagraphStyle, BiConsumer<TextFlow, PS> applyParagraphStyle |
26 | 37 | ) { |
27 | | - return new StyledTextArea<S, PS>(initialStyle, applyStyle, initialParagraphStyle, applyParagraphStyle, true); |
| 38 | + return new VirtualizedScrollPane<>(styledTextArea(initialStyle, applyStyle, initialParagraphStyle, applyParagraphStyle)); |
28 | 39 | } |
29 | 40 |
|
| 41 | + // StyledTextArea 2 |
| 42 | + public static <S, PS> StyledTextArea<S, PS> styledTextArea( |
| 43 | + S initialStyle, BiConsumer<? super TextExt, S> applyStyle, |
| 44 | + PS initialParagraphStyle, BiConsumer<TextFlow, PS> applyParagraphStyle, |
| 45 | + boolean preserveStyle |
| 46 | + ) { |
| 47 | + return new StyledTextArea<S, PS>( |
| 48 | + initialStyle, applyStyle, |
| 49 | + initialParagraphStyle, applyParagraphStyle, |
| 50 | + preserveStyle); |
| 51 | + } |
| 52 | + |
| 53 | + // Embeds StyledTextArea 2 |
30 | 54 | public static <S, PS>VirtualizedScrollPane<StyledTextArea<S, PS>> embeddedStyledTextArea( |
31 | 55 | S initialStyle, BiConsumer<? super TextExt, S> applyStyle, |
32 | 56 | PS initialParagraphStyle, BiConsumer<TextFlow, PS> applyParagraphStyle, boolean preserveStyle |
33 | 57 | ) { |
34 | 58 | return new VirtualizedScrollPane<>(styledTextArea(initialStyle, applyStyle, initialParagraphStyle, applyParagraphStyle, preserveStyle)); |
35 | 59 | } |
36 | 60 |
|
37 | | - public static <S, PS>VirtualizedScrollPane<StyledTextArea<S, PS>> embeddedStyledTextArea( |
38 | | - S initialStyle, BiConsumer<? super TextExt, S> applyStyle, |
39 | | - PS initialParagraphStyle, BiConsumer<TextFlow, PS> applyParagraphStyle |
| 61 | + // Clones StyledTextArea |
| 62 | + public static <S, PS> StyledTextArea<S, PS> cloneStyleTextArea(StyledTextArea<S, PS> area) { |
| 63 | + return new StyledTextArea<S, PS>(area.getInitialStyle(), area.getApplyStyle(), |
| 64 | + area.getInitialParagraphStyle(), area.getApplyParagraphStyle(), |
| 65 | + area.getContent(), area.isPreserveStyle()); |
| 66 | + } |
| 67 | + |
| 68 | + // Embeds cloned StyledTextArea |
| 69 | + public static <S, PS>VirtualizedScrollPane<StyledTextArea<S, PS>> embeddedClonedStyledTextArea(StyledTextArea<S, PS> area) { |
| 70 | + return new VirtualizedScrollPane<>(cloneStyleTextArea(area)); |
| 71 | + } |
| 72 | + |
| 73 | + // Embeds a cloned StyledTextArea from an embedded StyledTextArea |
| 74 | + public static <S, PS>VirtualizedScrollPane<StyledTextArea<S, PS>> embeddedClonedStyledTextArea( |
| 75 | + VirtualizedScrollPane<StyledTextArea<S, PS>> virtualizedScrollPaneWithArea |
40 | 76 | ) { |
41 | | - return new VirtualizedScrollPane<>(styledTextArea(initialStyle, applyStyle, initialParagraphStyle, applyParagraphStyle)); |
| 77 | + return embeddedClonedStyledTextArea(virtualizedScrollPaneWithArea.getContent()); |
42 | 78 | } |
43 | 79 |
|
| 80 | + /* ********************************************************************** * |
| 81 | + * * |
| 82 | + * StyleClassedTextArea * |
| 83 | + * * |
| 84 | + * ********************************************************************** */ |
| 85 | + |
| 86 | + // StyleClassedTextArea 1 |
44 | 87 | public static StyleClassedTextArea styleClassedTextArea(boolean preserveStyle) { |
45 | 88 | return new StyleClassedTextArea(preserveStyle); |
46 | 89 | } |
47 | 90 |
|
48 | | - public static StyleClassedTextArea styleClassedTextArea() { |
49 | | - return styleClassedTextArea(true); |
50 | | - } |
51 | | - |
| 91 | + // Embeds StyleClassedTextArea 1 |
52 | 92 | public static VirtualizedScrollPane<StyleClassedTextArea> embeddedStyleClassedTextArea(boolean preserveStyle) { |
53 | 93 | return new VirtualizedScrollPane<>(styleClassedTextArea(preserveStyle)); |
54 | 94 | } |
55 | 95 |
|
| 96 | + // StyleClassedTextArea 2 |
| 97 | + public static StyleClassedTextArea styleClassedTextArea() { |
| 98 | + return styleClassedTextArea(true); |
| 99 | + } |
| 100 | + |
| 101 | + // Embeds StyleClassedTextArea 2 |
56 | 102 | public static VirtualizedScrollPane<StyleClassedTextArea> embeddedStyleClassedTextArea() { |
57 | 103 | return new VirtualizedScrollPane<>(styleClassedTextArea()); |
58 | 104 | } |
59 | 105 |
|
60 | | - public static CodeArea codeArea() { |
61 | | - return new CodeArea(); |
| 106 | + // Clones StyleClassedTextArea |
| 107 | + public static StyleClassedTextArea cloneStyleClassedTextArea(StyleClassedTextArea area) { |
| 108 | + return new StyleClassedTextArea(area.getContent(), area.isPreserveStyle()); |
62 | 109 | } |
63 | 110 |
|
64 | | - public static CodeArea codeArea(String text) { |
65 | | - return new CodeArea(text); |
| 111 | + // Embeds cloned StyleClassedTextArea |
| 112 | + public static VirtualizedScrollPane<StyleClassedTextArea> embeddedClonedStyleClassedTextArea(StyleClassedTextArea area) { |
| 113 | + return new VirtualizedScrollPane<>(cloneStyleClassedTextArea(area)); |
66 | 114 | } |
67 | 115 |
|
| 116 | + // Embeds a cloned StyleClassedTextArea from an embedded StyleClassedTextArea |
| 117 | + public static VirtualizedScrollPane<StyleClassedTextArea> embeddedClonedStyleClassedTextArea( |
| 118 | + VirtualizedScrollPane<StyleClassedTextArea> virtualizedScrollPaneWithArea |
| 119 | + ) { |
| 120 | + return embeddedClonedStyleClassedTextArea(virtualizedScrollPaneWithArea.getContent()); |
| 121 | + } |
| 122 | + |
| 123 | + /* ********************************************************************** * |
| 124 | + * * |
| 125 | + * CodeArea * |
| 126 | + * * |
| 127 | + * ********************************************************************** */ |
| 128 | + |
| 129 | + // CodeArea 1 |
| 130 | + public static CodeArea codeArea() { |
| 131 | + return new CodeArea(); |
| 132 | + } |
| 133 | + |
| 134 | + // Embeds CodeArea 1 |
68 | 135 | public static VirtualizedScrollPane<CodeArea> embeddedCodeArea() { |
69 | 136 | return new VirtualizedScrollPane<>(codeArea()); |
70 | 137 | } |
71 | 138 |
|
| 139 | + // CodeArea 2 |
| 140 | + public static CodeArea codeArea(String text) { |
| 141 | + return new CodeArea(text); |
| 142 | + } |
| 143 | + |
| 144 | + // Embeds CodeArea 2 |
72 | 145 | public static VirtualizedScrollPane<CodeArea> embeddedCodeArea(String text) { |
73 | 146 | return new VirtualizedScrollPane<>(codeArea(text)); |
74 | 147 | } |
75 | 148 |
|
76 | | - /** |
77 | | - * Creates a text area that uses inline css derived from the style info to define |
78 | | - * style of text segments. |
79 | | - * |
80 | | - * @param <S> type of text style information. |
81 | | - * @param <PS> type of paragraph style information. |
82 | | - * @param initialStyle style to use for text ranges where no other |
83 | | - * style is set via {@code setStyle(...)} methods. |
84 | | - * @param styleToCss function that converts an instance of {@code S} |
85 | | - * to a CSS string. |
86 | | - */ |
87 | | - public static <S, PS> StyledTextArea<S, PS> inlineStyleTextArea( |
88 | | - S initialStyle, Function<S, String> styleToCss, PS initialParagraphStyle, Function<PS, String> paragraphStyleToCss |
89 | | - ) { |
90 | | - return styledTextArea( |
91 | | - initialStyle, |
92 | | - (text, style) -> text.setStyle(styleToCss.apply(style)), |
93 | | - initialParagraphStyle, |
94 | | - (paragraph, style) -> paragraph.setStyle(paragraphStyleToCss.apply(style))); |
| 149 | + // Clones CodeArea |
| 150 | + public static CodeArea cloneCodeArea(CodeArea area) { |
| 151 | + return new CodeArea(area.getContent()); |
95 | 152 | } |
96 | 153 |
|
97 | | - public static <S, PS> VirtualizedScrollPane<StyledTextArea<S, PS>> embeddedInlineStyleTextArea( |
98 | | - S initialStyle, Function<S, String> styleToCss, PS initialParagraphStyle, Function<PS, String> paragraphStyleToCss |
99 | | - ) { |
100 | | - return new VirtualizedScrollPane<>(inlineStyleTextArea(initialStyle, styleToCss, initialParagraphStyle, paragraphStyleToCss)); |
| 154 | + // Embeds a cloned CodeArea |
| 155 | + public static VirtualizedScrollPane<CodeArea> embeddedClonedCodeArea(CodeArea area) { |
| 156 | + return new VirtualizedScrollPane<>(cloneCodeArea(area)); |
101 | 157 | } |
102 | 158 |
|
103 | | - public static InlineCssTextArea inlineCssTextArea() { |
104 | | - return new InlineCssTextArea(); |
| 159 | + // Embeds a cloned CodeArea from an embedded CodeArea |
| 160 | + public static VirtualizedScrollPane<CodeArea> embeddedClonedCodeArea(VirtualizedScrollPane<CodeArea> virtualizedScrollPaneWithArea) { |
| 161 | + return new VirtualizedScrollPane<>(cloneCodeArea(virtualizedScrollPaneWithArea.getContent())); |
105 | 162 | } |
106 | 163 |
|
107 | | - public static InlineCssTextArea inlineCssTextArea(String text) { |
108 | | - return new InlineCssTextArea(text); |
| 164 | + /* ********************************************************************** * |
| 165 | + * * |
| 166 | + * InlineCssTextArea * |
| 167 | + * * |
| 168 | + * ********************************************************************** */ |
| 169 | + |
| 170 | + // InlineCssTextArea 1 |
| 171 | + public static InlineCssTextArea inlineCssTextArea() { |
| 172 | + return new InlineCssTextArea(); |
109 | 173 | } |
110 | 174 |
|
| 175 | + // Embeds InlineCssTextArea 1 |
111 | 176 | public static VirtualizedScrollPane<InlineCssTextArea> embeddedInlineCssTextArea() { |
112 | 177 | return new VirtualizedScrollPane<>(inlineCssTextArea()); |
113 | 178 | } |
114 | 179 |
|
| 180 | + // InlineCssTextArea 2 |
| 181 | + public static InlineCssTextArea inlineCssTextArea(String text) { |
| 182 | + return new InlineCssTextArea(text); |
| 183 | + } |
| 184 | + |
| 185 | + // Embeds InlineCssTextArea 2 |
115 | 186 | public static VirtualizedScrollPane<InlineCssTextArea> embeddedInlineCssTextArea(String text) { |
116 | 187 | return new VirtualizedScrollPane<>(inlineCssTextArea(text)); |
117 | 188 | } |
| 189 | + |
| 190 | + // Clones InlineCssTextArea |
| 191 | + public static InlineCssTextArea cloneInlineCssTextArea(InlineCssTextArea area) { |
| 192 | + return new InlineCssTextArea(area.getContent()); |
| 193 | + } |
| 194 | + |
| 195 | + // Embeds a cloned InlineCssTextArea |
| 196 | + public static VirtualizedScrollPane<InlineCssTextArea> embeddedClonedInlineCssTextArea(InlineCssTextArea area) { |
| 197 | + return new VirtualizedScrollPane<>(cloneInlineCssTextArea(area)); |
| 198 | + } |
| 199 | + |
| 200 | + // Embeds a cloned InlineCssTextArea from an embedded InlineCssTextArea |
| 201 | + public static VirtualizedScrollPane<InlineCssTextArea> embeddedClonedInlineCssTextArea( |
| 202 | + VirtualizedScrollPane<InlineCssTextArea> virtualizedScrollPaneWithArea |
| 203 | + ) { |
| 204 | + return new VirtualizedScrollPane<>(cloneInlineCssTextArea(virtualizedScrollPaneWithArea.getContent())); |
| 205 | + } |
118 | 206 | } |
0 commit comments