|
61 | 61 |
|
62 | 62 | public class RichText extends Application { |
63 | 63 |
|
| 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 | + |
64 | 67 | public static void main(String[] args) { |
65 | 68 | // The following properties are required on Linux for improved text rendering |
66 | 69 | //System.setProperty("prism.lcdtext", "false"); |
@@ -94,8 +97,14 @@ public static void main(String[] args) { |
94 | 97 | public void start(Stage primaryStage) { |
95 | 98 | mainStage = primaryStage; |
96 | 99 |
|
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."); |
99 | 108 | CheckBox wrapToggle = new CheckBox("Wrap"); |
100 | 109 | wrapToggle.setSelected(true); |
101 | 110 | area.wrapTextProperty().bind(wrapToggle.selectedProperty()); |
@@ -373,6 +382,8 @@ private void loadDocument() { |
373 | 382 | FileChooser fileChooser = new FileChooser(); |
374 | 383 | fileChooser.setTitle("Load document"); |
375 | 384 | fileChooser.setInitialDirectory(new File(initialDir)); |
| 385 | + fileChooser.setSelectedExtensionFilter( |
| 386 | + new FileChooser.ExtensionFilter("Arbitrary RTFX file", "*" + RTFX_FILE_EXTENSION)); |
376 | 387 | File selectedFile = fileChooser.showOpenDialog(mainStage); |
377 | 388 | if (selectedFile != null) { |
378 | 389 | area.clear(); |
@@ -408,6 +419,7 @@ private void saveDocument() { |
408 | 419 | FileChooser fileChooser = new FileChooser(); |
409 | 420 | fileChooser.setTitle("Save document"); |
410 | 421 | fileChooser.setInitialDirectory(new File(initialDir)); |
| 422 | + fileChooser.setInitialFileName("example rtfx file" + RTFX_FILE_EXTENSION); |
411 | 423 | File selectedFile = fileChooser.showSaveDialog(mainStage); |
412 | 424 | if (selectedFile != null) { |
413 | 425 | save(selectedFile); |
|
0 commit comments