From 9a9a12cb29841950ea435e26f5b93abe64ec419f Mon Sep 17 00:00:00 2001 From: "jose.pereda" Date: Fri, 21 Jun 2024 22:30:05 +0200 Subject: [PATCH] Make document property read only --- .../java/com/gluonhq/richtextarea/RichTextArea.java | 12 ++++-------- .../com/gluonhq/richtextarea/RichTextAreaSkin.java | 4 ++-- .../gluonhq/richtextarea/samples/ActionsDemo.java | 2 +- .../richtextarea/samples/BasicDocumentDemo.java | 3 ++- .../richtextarea/samples/BasicPromptDemo.java | 3 ++- .../com/gluonhq/richtextarea/samples/EmojiDemo.java | 2 +- .../gluonhq/richtextarea/samples/EmojiPopupDemo.java | 2 +- .../gluonhq/richtextarea/samples/HighlightDemo.java | 3 ++- .../com/gluonhq/richtextarea/samples/ListsDemo.java | 3 ++- .../com/gluonhq/richtextarea/samples/TableDemo.java | 3 ++- 10 files changed, 19 insertions(+), 18 deletions(-) diff --git a/rta/src/main/java/com/gluonhq/richtextarea/RichTextArea.java b/rta/src/main/java/com/gluonhq/richtextarea/RichTextArea.java index fece2ac..cc6b637 100644 --- a/rta/src/main/java/com/gluonhq/richtextarea/RichTextArea.java +++ b/rta/src/main/java/com/gluonhq/richtextarea/RichTextArea.java @@ -95,19 +95,15 @@ public RichTextArea() { * By default, this property is set via {@link ActionFactory#newDocument()} or {@link ActionFactory#open(Document)}, * and gets updated only via {@link ActionFactory#save()}, unless {@link #autoSaveProperty()} is enabled, in which * the document gets updated after every change. - * - * @return the document for this control */ - public final ObjectProperty documentProperty() { - return documentProperty; + // documentProperty + final ReadOnlyObjectWrapper documentProperty = new ReadOnlyObjectWrapper<>(this, "document", new Document()); + public final ReadOnlyObjectProperty documentProperty() { + return documentProperty.getReadOnlyProperty(); } public final Document getDocument() { return documentProperty.get(); } - public final void setDocument(Document value) { - documentProperty.set(value); - } - private final ObjectProperty documentProperty = new SimpleObjectProperty<>(this, "document", new Document()); // autoSaveProperty /** diff --git a/rta/src/main/java/com/gluonhq/richtextarea/RichTextAreaSkin.java b/rta/src/main/java/com/gluonhq/richtextarea/RichTextAreaSkin.java index 8c3f4cb..70f38cd 100644 --- a/rta/src/main/java/com/gluonhq/richtextarea/RichTextAreaSkin.java +++ b/rta/src/main/java/com/gluonhq/richtextarea/RichTextAreaSkin.java @@ -416,10 +416,10 @@ protected void invalidated() { // new/open dispose(); setup(nv); - getSkinnable().setDocument(nv); + getSkinnable().documentProperty.set(nv); } else if (nv != null) { // save - getSkinnable().setDocument(nv); + getSkinnable().documentProperty.set(nv); } }; diff --git a/samples/src/main/java/com/gluonhq/richtextarea/samples/ActionsDemo.java b/samples/src/main/java/com/gluonhq/richtextarea/samples/ActionsDemo.java index 1408f2f..c90e929 100644 --- a/samples/src/main/java/com/gluonhq/richtextarea/samples/ActionsDemo.java +++ b/samples/src/main/java/com/gluonhq/richtextarea/samples/ActionsDemo.java @@ -81,7 +81,7 @@ public void start(Stage stage) { Document document = new Document(text, decorationList, text.length()); RichTextArea editor = new RichTextArea(); - editor.setDocument(document); + editor.getActionFactory().open(document).execute(new ActionEvent()); BorderPane root = new BorderPane(editor); diff --git a/samples/src/main/java/com/gluonhq/richtextarea/samples/BasicDocumentDemo.java b/samples/src/main/java/com/gluonhq/richtextarea/samples/BasicDocumentDemo.java index b6befc4..374e8b1 100644 --- a/samples/src/main/java/com/gluonhq/richtextarea/samples/BasicDocumentDemo.java +++ b/samples/src/main/java/com/gluonhq/richtextarea/samples/BasicDocumentDemo.java @@ -33,6 +33,7 @@ import com.gluonhq.richtextarea.model.ParagraphDecoration; import com.gluonhq.richtextarea.model.TextDecoration; import javafx.application.Application; +import javafx.event.ActionEvent; import javafx.scene.Scene; import javafx.scene.layout.StackPane; import javafx.stage.Stage; @@ -87,7 +88,7 @@ public void start(Stage stage) { 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); + richTextArea.getActionFactory().open(document).execute(new ActionEvent()); StackPane root = new StackPane(richTextArea); Scene scene = new Scene(root, 640, 480); stage.setScene(scene); 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 dae7efd..f2e8446 100644 --- a/samples/src/main/java/com/gluonhq/richtextarea/samples/BasicPromptDemo.java +++ b/samples/src/main/java/com/gluonhq/richtextarea/samples/BasicPromptDemo.java @@ -33,6 +33,7 @@ import com.gluonhq.richtextarea.model.ParagraphDecoration; import com.gluonhq.richtextarea.model.TextDecoration; import javafx.application.Application; +import javafx.event.ActionEvent; import javafx.geometry.Insets; import javafx.scene.Scene; import javafx.scene.layout.BorderPane; @@ -86,7 +87,7 @@ public class BasicPromptDemo extends Application { @Override public void start(Stage stage) { RichTextArea editor = new RichTextArea(); - editor.setDocument(emptyDocument); + editor.getActionFactory().open(emptyDocument).execute(new ActionEvent()); editor.setPromptText("Type something!"); editor.setPadding(new Insets(20)); diff --git a/samples/src/main/java/com/gluonhq/richtextarea/samples/EmojiDemo.java b/samples/src/main/java/com/gluonhq/richtextarea/samples/EmojiDemo.java index 8e65330..a510308 100644 --- a/samples/src/main/java/com/gluonhq/richtextarea/samples/EmojiDemo.java +++ b/samples/src/main/java/com/gluonhq/richtextarea/samples/EmojiDemo.java @@ -86,7 +86,7 @@ public void start(Stage stage) { Document document = new Document(fullText.toString(), decorationList, fullText.length()); RichTextArea editor = new RichTextArea(); - editor.setDocument(document); + editor.getActionFactory().open(document).execute(new ActionEvent()); BorderPane root = new BorderPane(editor); Scene scene = new Scene(root, 800, 300); diff --git a/samples/src/main/java/com/gluonhq/richtextarea/samples/EmojiPopupDemo.java b/samples/src/main/java/com/gluonhq/richtextarea/samples/EmojiPopupDemo.java index fbcaa98..a7f4303 100644 --- a/samples/src/main/java/com/gluonhq/richtextarea/samples/EmojiPopupDemo.java +++ b/samples/src/main/java/com/gluonhq/richtextarea/samples/EmojiPopupDemo.java @@ -71,7 +71,7 @@ public class EmojiPopupDemo extends Application { @Override public void start(Stage stage) { RichTextArea editor = new RichTextArea(); - editor.setDocument(emptyDocument); + editor.getActionFactory().open(emptyDocument).execute(new ActionEvent()); editor.setPromptText("Type something or insert emojis!"); editor.setSkinTone(EmojiSkinTone.MEDIUM_SKIN_TONE); editor.setPadding(new Insets(20)); diff --git a/samples/src/main/java/com/gluonhq/richtextarea/samples/HighlightDemo.java b/samples/src/main/java/com/gluonhq/richtextarea/samples/HighlightDemo.java index 1bdabc9..0c95db2 100644 --- a/samples/src/main/java/com/gluonhq/richtextarea/samples/HighlightDemo.java +++ b/samples/src/main/java/com/gluonhq/richtextarea/samples/HighlightDemo.java @@ -33,6 +33,7 @@ import com.gluonhq.richtextarea.model.ParagraphDecoration; import com.gluonhq.richtextarea.model.TextDecoration; import javafx.application.Application; +import javafx.event.ActionEvent; import javafx.scene.Scene; import javafx.scene.layout.BorderPane; import javafx.stage.Stage; @@ -80,7 +81,7 @@ public void start(Stage stage) { Document document = new Document(fullText, decorationList, fullText.length()); RichTextArea editor = new RichTextArea(); - editor.setDocument(document); + editor.getActionFactory().open(document).execute(new ActionEvent()); BorderPane root = new BorderPane(editor); Scene scene = new Scene(root, 800, 300); diff --git a/samples/src/main/java/com/gluonhq/richtextarea/samples/ListsDemo.java b/samples/src/main/java/com/gluonhq/richtextarea/samples/ListsDemo.java index 9d10dc1..6a2b414 100644 --- a/samples/src/main/java/com/gluonhq/richtextarea/samples/ListsDemo.java +++ b/samples/src/main/java/com/gluonhq/richtextarea/samples/ListsDemo.java @@ -33,6 +33,7 @@ import com.gluonhq.richtextarea.model.ParagraphDecoration; import com.gluonhq.richtextarea.model.TextDecoration; import javafx.application.Application; +import javafx.event.ActionEvent; import javafx.scene.Scene; import javafx.scene.control.Label; import javafx.scene.layout.BorderPane; @@ -80,7 +81,7 @@ public void start(Stage stage) { label.getStyleClass().add("numbered-list-label"); return label; }); - editor.setDocument(document); + editor.getActionFactory().open(document).execute(new ActionEvent()); BorderPane root = new BorderPane(editor); Scene scene = new Scene(root, 600, 500); diff --git a/samples/src/main/java/com/gluonhq/richtextarea/samples/TableDemo.java b/samples/src/main/java/com/gluonhq/richtextarea/samples/TableDemo.java index f0aa202..94d9d3c 100644 --- a/samples/src/main/java/com/gluonhq/richtextarea/samples/TableDemo.java +++ b/samples/src/main/java/com/gluonhq/richtextarea/samples/TableDemo.java @@ -36,6 +36,7 @@ import com.gluonhq.richtextarea.model.TableDecoration; import com.gluonhq.richtextarea.model.TextDecoration; import javafx.application.Application; +import javafx.event.ActionEvent; import javafx.scene.Scene; import javafx.scene.layout.BorderPane; import javafx.scene.text.TextAlignment; @@ -61,7 +62,7 @@ public class TableDemo extends Application { @Override public void start(Stage stage) { RichTextArea editor = new RichTextArea(); - editor.setDocument(getDocument()); + editor.getActionFactory().open(getDocument()).execute(new ActionEvent()); BorderPane root = new BorderPane(editor); Scene scene = new Scene(root, 800, 600); scene.getStylesheets().add(TableDemo.class.getResource("tableDemo.css").toExternalForm());