diff --git a/samples/README.md b/samples/README.md index aca4dd3..fdde310 100644 --- a/samples/README.md +++ b/samples/README.md @@ -5,9 +5,9 @@ > cd samples > ``` -## BasicDemo +## BasicPromptDemo -The [BasicDemo](/samples/src/main/java/com/gluonhq/richtextarea/samples/BasicDemo.java) is the most simple use case of +The [BasicPromptDemo](/samples/src/main/java/com/gluonhq/richtextarea/samples/BasicPromptDemo.java) is the simplest use case of the RichTextArea control: it shows a prompt message, and the user can add text. While all the control features are available, there are no menus or toolbars included, so user interaction is limited @@ -38,11 +38,24 @@ the [FullFeaturedDemo](#fullfeatureddemo) sample for a complete and advanced sho To run this sample, using Java 17+, do as follows: ``` -mvn javafx:run -Dmain.class=com.gluonhq.richtextarea.samples.BasicDemo +mvn javafx:run -Dmain.class=com.gluonhq.richtextarea.samples.BasicPromptDemo ``` ![rta_editor.png](../.github/assets/BasicDemo.png) +## BasicDocumentDemo + +The [BasicDocumentDemo](/samples/src/main/java/com/gluonhq/richtextarea/samples/BasicDocumentDemo.java) is an update +to the BasicPromptDemo where we add a decorated text to the RichTextArea control. + +### Usage + +To run this sample, using Java 17+, do as follows: + +``` +mvn javafx:run -Dmain.class=com.gluonhq.richtextarea.samples.BasicDocumentDemo +``` + ## HighlightDemo The [HighlightDemo](/samples/src/main/java/com/gluonhq/richtextarea/samples/HighlightDemo.java) shows how to use the diff --git a/samples/src/main/java/com/gluonhq/richtextarea/samples/BasicDocumentDemo.java b/samples/src/main/java/com/gluonhq/richtextarea/samples/BasicDocumentDemo.java new file mode 100644 index 0000000..c63db38 --- /dev/null +++ b/samples/src/main/java/com/gluonhq/richtextarea/samples/BasicDocumentDemo.java @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2023, Gluon + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL GLUON BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package com.gluonhq.richtextarea.samples; + +import com.gluonhq.richtextarea.RichTextArea; +import com.gluonhq.richtextarea.model.DecorationModel; +import com.gluonhq.richtextarea.model.Document; +import com.gluonhq.richtextarea.model.ParagraphDecoration; +import com.gluonhq.richtextarea.model.TextDecoration; +import javafx.application.Application; +import javafx.scene.Scene; +import javafx.scene.layout.StackPane; +import javafx.scene.paint.Color; +import javafx.stage.Stage; + +import java.util.List; + +/** + * Basic sample with the RichTextArea control, showing a text with a default + * font family, font size, and foreground color. + *

+ * While all the control features are available, but there are no menus or + * toolbars included, so user interaction is limited to shortcuts or context + * menu. + *

+ * For instance, after typing some text, select all (Ctrl/Cmd + A) or part of it + * (with mouse or keyboard) and press Ctrl/Cmd + I for italic or Ctrl/Cmd + B for bold. + *

+ * Undo/Redo, Cut/Copy/Paste options work as usual. + * You can copy text with emoji unicode, and paste it on the editor. + * For instance, while running this sample, copy this text: + *

+ *     {@code Hello 👋🏼}
+ * 
+ * and paste it, you should see the waving hand emoji and some text. Also copying from + * the control and pasting it on the control itself or on any other application will work + * too, keeping the rich content when possible. + *

+ * Right click to display a context menu with different options, like inserting a + * 2x1 table. + *

+ * To apply the rest of the control features, some UI is needed for user interaction. See + * the {@link FullFeaturedDemo} sample for a complete and advanced showcase. + */ +public class BasicDocumentDemo extends Application { + + @Override + public void start(Stage stage) { + // String to decorate + String text = "Hello RTA"; + /* + * Defines the text decorations with + * font family as Arial, + * font size as 20, + * foreground color as RED + */ + TextDecoration textDecoration = TextDecoration.builder().presets() + .fontFamily("Arial") + .fontSize(20) + .foreground(Color.RED) + .build(); + ParagraphDecoration paragraphDecoration = ParagraphDecoration.builder().presets().build(); + DecorationModel decorationModel = new DecorationModel(0, text.length(), textDecoration, paragraphDecoration); + Document document = new Document(text, List.of(decorationModel), text.length()); + RichTextArea richTextArea = new RichTextArea(); + richTextArea.setDocument(document); + StackPane root = new StackPane(richTextArea); + Scene scene = new Scene(root, 640, 480); + stage.setScene(scene); + stage.setTitle("RichTextArea"); + stage.show(); + } +} diff --git a/samples/src/main/java/com/gluonhq/richtextarea/samples/BasicDemo.java b/samples/src/main/java/com/gluonhq/richtextarea/samples/BasicPromptDemo.java similarity index 96% rename from samples/src/main/java/com/gluonhq/richtextarea/samples/BasicDemo.java rename to samples/src/main/java/com/gluonhq/richtextarea/samples/BasicPromptDemo.java index 466c297..dae7efd 100644 --- a/samples/src/main/java/com/gluonhq/richtextarea/samples/BasicDemo.java +++ b/samples/src/main/java/com/gluonhq/richtextarea/samples/BasicPromptDemo.java @@ -44,7 +44,7 @@ * Basic sample with the RichTextArea control, showing a prompt message. *

* While all the control features are available, but there are no menus or - * toolbars included, so user interaction is limited to shorcuts or context + * toolbars included, so user interaction is limited to shortcuts or context * menu. *

* For instance, after typing some text, select all (Ctrl/Cmd + A) or part of it @@ -66,7 +66,7 @@ * To apply the rest of the control features, some UI is needed for user interaction. See * the {@link FullFeaturedDemo} sample for a complete and advanced showcase. */ -public class BasicDemo extends Application { +public class BasicPromptDemo extends Application { /** * Defines the text and paragraph decorations, based on the default presets,