Skip to content

Commit

Permalink
Make document property read only (#342)
Browse files Browse the repository at this point in the history
  • Loading branch information
jperedadnr committed Jun 25, 2024
1 parent 5620154 commit a5656b0
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 18 deletions.
12 changes: 4 additions & 8 deletions rta/src/main/java/com/gluonhq/richtextarea/RichTextArea.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Document> documentProperty() {
return documentProperty;
// documentProperty
final ReadOnlyObjectWrapper<Document> documentProperty = new ReadOnlyObjectWrapper<>(this, "document", new Document());
public final ReadOnlyObjectProperty<Document> documentProperty() {
return documentProperty.getReadOnlyProperty();
}
public final Document getDocument() {
return documentProperty.get();
}
public final void setDocument(Document value) {
documentProperty.set(value);
}
private final ObjectProperty<Document> documentProperty = new SimpleObjectProperty<>(this, "document", new Document());

// autoSaveProperty
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
Expand Down

0 comments on commit a5656b0

Please sign in to comment.