From 5401f6309f8a8dab030d175e218b68fc9810ed3c Mon Sep 17 00:00:00 2001 From: Abhinay Agarwal Date: Thu, 7 Sep 2023 19:00:13 +0530 Subject: [PATCH 1/4] Add BasicDocumentDemo --- samples/README.md | 19 +++- samples/pom.xml | 2 +- .../samples/BasicDocumentDemo.java | 98 +++++++++++++++++++ .../{BasicDemo.java => BasicPromptDemo.java} | 26 +++-- 4 files changed, 134 insertions(+), 11 deletions(-) create mode 100644 samples/src/main/java/com/gluonhq/richtextarea/samples/BasicDocumentDemo.java rename samples/src/main/java/com/gluonhq/richtextarea/samples/{BasicDemo.java => BasicPromptDemo.java} (82%) 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/pom.xml b/samples/pom.xml index b001ac8..d5f05e9 100644 --- a/samples/pom.xml +++ b/samples/pom.xml @@ -16,7 +16,7 @@ 0.0.8 com.gluonhq.richtextarea.samples.FullFeaturedDemo 2022.1.0 - 1.1.2-SNAPSHOT + 1.1.1 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 82% 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..ad85e18 100644 --- a/samples/src/main/java/com/gluonhq/richtextarea/samples/BasicDemo.java +++ b/samples/src/main/java/com/gluonhq/richtextarea/samples/BasicPromptDemo.java @@ -36,6 +36,7 @@ import javafx.geometry.Insets; import javafx.scene.Scene; import javafx.scene.layout.BorderPane; +import javafx.scene.paint.Color; import javafx.stage.Stage; import java.util.List; @@ -44,7 +45,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,21 +67,32 @@ * 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 { + String text = "Hello RTA"; /** * Defines the text and paragraph decorations, based on the default presets, * but with Arial font */ - private static final List decorations = List.of( - new DecorationModel(0, 0, - TextDecoration.builder().presets().fontFamily("Arial").build(), - ParagraphDecoration.builder().presets().build())); + private final List decorations; + + { + TextDecoration textDecoration = TextDecoration.builder().presets() + .fontFamily("Arial") + .fontSize(20) + .foreground(Color.RED) + .build(); + ParagraphDecoration paragraphDecoration = ParagraphDecoration.builder().presets().build(); + decorations = List.of( + new DecorationModel(0, 0, + textDecoration, + paragraphDecoration)); + } /** * Creates an empty document with the new decorations */ - private static final Document emptyDocument = + private final Document emptyDocument = new Document("", decorations, 0); @Override From 0c02ec791312e582351737ccd7005061319318f9 Mon Sep 17 00:00:00 2001 From: Abhinay Agarwal Date: Thu, 7 Sep 2023 19:01:42 +0530 Subject: [PATCH 2/4] revert to latest snapshot --- samples/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/pom.xml b/samples/pom.xml index d5f05e9..b001ac8 100644 --- a/samples/pom.xml +++ b/samples/pom.xml @@ -16,7 +16,7 @@ 0.0.8 com.gluonhq.richtextarea.samples.FullFeaturedDemo 2022.1.0 - 1.1.1 + 1.1.2-SNAPSHOT From 8cb05c9312ce5086258115f4c1cda780fdb24481 Mon Sep 17 00:00:00 2001 From: Abhinay Agarwal Date: Thu, 7 Sep 2023 19:27:52 +0530 Subject: [PATCH 3/4] revert back changes made to basicpromptdemo --- .../richtextarea/samples/BasicPromptDemo.java | 21 +++++-------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/samples/src/main/java/com/gluonhq/richtextarea/samples/BasicPromptDemo.java b/samples/src/main/java/com/gluonhq/richtextarea/samples/BasicPromptDemo.java index ad85e18..804fb4e 100644 --- a/samples/src/main/java/com/gluonhq/richtextarea/samples/BasicPromptDemo.java +++ b/samples/src/main/java/com/gluonhq/richtextarea/samples/BasicPromptDemo.java @@ -69,30 +69,19 @@ */ public class BasicPromptDemo extends Application { - String text = "Hello RTA"; /** * Defines the text and paragraph decorations, based on the default presets, * but with Arial font */ - private final List decorations; - - { - TextDecoration textDecoration = TextDecoration.builder().presets() - .fontFamily("Arial") - .fontSize(20) - .foreground(Color.RED) - .build(); - ParagraphDecoration paragraphDecoration = ParagraphDecoration.builder().presets().build(); - decorations = List.of( - new DecorationModel(0, 0, - textDecoration, - paragraphDecoration)); - } + private static final List decorations = List.of( + new DecorationModel(0, 0, + TextDecoration.builder().presets().fontFamily("Arial").build(), + ParagraphDecoration.builder().presets().build())); /** * Creates an empty document with the new decorations */ - private final Document emptyDocument = + private static final Document emptyDocument = new Document("", decorations, 0); @Override From 02357736401bd18a279e67895002b9fb9a8c9090 Mon Sep 17 00:00:00 2001 From: Abhinay Agarwal Date: Thu, 7 Sep 2023 19:28:25 +0530 Subject: [PATCH 4/4] remove unused import --- .../java/com/gluonhq/richtextarea/samples/BasicPromptDemo.java | 1 - 1 file changed, 1 deletion(-) diff --git a/samples/src/main/java/com/gluonhq/richtextarea/samples/BasicPromptDemo.java b/samples/src/main/java/com/gluonhq/richtextarea/samples/BasicPromptDemo.java index 804fb4e..dae7efd 100644 --- a/samples/src/main/java/com/gluonhq/richtextarea/samples/BasicPromptDemo.java +++ b/samples/src/main/java/com/gluonhq/richtextarea/samples/BasicPromptDemo.java @@ -36,7 +36,6 @@ import javafx.geometry.Insets; import javafx.scene.Scene; import javafx.scene.layout.BorderPane; -import javafx.scene.paint.Color; import javafx.stage.Stage; import java.util.List;