Skip to content

Commit 3fae2c8

Browse files
Merge pull request #686 from JordanMartinez/fixDemo
Only save/load ".rtfx" files; warn about file format changes
2 parents d274018 + 40d2fe1 commit 3fae2c8

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

  • richtextfx-demos/src/main/java/org/fxmisc/richtext/demo/richtext

richtextfx-demos/src/main/java/org/fxmisc/richtext/demo/richtext/RichText.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@
6161

6262
public class RichText extends Application {
6363

64+
// the saved/loaded files and their format are arbitrary and may change across versions
65+
private static final String RTFX_FILE_EXTENSION = ".rtfx";
66+
6467
public static void main(String[] args) {
6568
// The following properties are required on Linux for improved text rendering
6669
//System.setProperty("prism.lcdtext", "false");
@@ -94,8 +97,14 @@ public static void main(String[] args) {
9497
public void start(Stage primaryStage) {
9598
mainStage = primaryStage;
9699

97-
Button loadBtn = createButton("loadfile", this::loadDocument, "Load document");
98-
Button saveBtn = createButton("savefile", this::saveDocument, "Save document");
100+
Button loadBtn = createButton("loadfile", this::loadDocument,
101+
"Load document.\n\n" +
102+
"Note: the demo will load only previously-saved \"" + RTFX_FILE_EXTENSION + "\" files. " +
103+
"This file format is abitrary and may change across versions.");
104+
Button saveBtn = createButton("savefile", this::saveDocument,
105+
"Save document.\n\n" +
106+
"Note: the demo will save the area's content to a \"" + RTFX_FILE_EXTENSION + "\" file. " +
107+
"This file format is abitrary and may change across versions.");
99108
CheckBox wrapToggle = new CheckBox("Wrap");
100109
wrapToggle.setSelected(true);
101110
area.wrapTextProperty().bind(wrapToggle.selectedProperty());
@@ -373,6 +382,8 @@ private void loadDocument() {
373382
FileChooser fileChooser = new FileChooser();
374383
fileChooser.setTitle("Load document");
375384
fileChooser.setInitialDirectory(new File(initialDir));
385+
fileChooser.setSelectedExtensionFilter(
386+
new FileChooser.ExtensionFilter("Arbitrary RTFX file", "*" + RTFX_FILE_EXTENSION));
376387
File selectedFile = fileChooser.showOpenDialog(mainStage);
377388
if (selectedFile != null) {
378389
area.clear();
@@ -408,6 +419,7 @@ private void saveDocument() {
408419
FileChooser fileChooser = new FileChooser();
409420
fileChooser.setTitle("Save document");
410421
fileChooser.setInitialDirectory(new File(initialDir));
422+
fileChooser.setInitialFileName("example rtfx file" + RTFX_FILE_EXTENSION);
411423
File selectedFile = fileChooser.showSaveDialog(mainStage);
412424
if (selectedFile != null) {
413425
save(selectedFile);

0 commit comments

Comments
 (0)