@@ -13,16 +13,17 @@ Extras do not have direct corresponding concepts in JavaFX.
13130 . [ Project Structure] ( #project-structure )
14140 . [ SBT] ( #sbt )
15150 . [ Features] ( #features )
16- 1 . [ Helper Methods] ( #helper-methods )
17- 1 . [ Simpler Display of Dialogs] ( #simpler-display-of-dialogs )
18- 1 . [ BusyWorker] ( #busyworker )
19- 1 . [ Simpler Use of FXML with MVCfx Pattern] ( #simpler-use-of-fxml-with-mvcfx-pattern )
20- 1 . [ Image Display Component] ( #imagedisplay-component )
16+ 1 . [ Helper Methods] ( #helper-methods )
17+ 1 . [ Simpler Display of Standard Dialogs] ( #simpler-display-of-standard-dialogs )
18+ 1 . [ Easy Custom Dialogs] ( #easy-custom-dialogs )
19+ 1 . [ BusyWorker] ( #busyworker )
20+ 1 . [ Simpler Use of FXML with MVCfx Pattern] ( #simpler-use-of-fxml-with-mvcfx-pattern )
21+ 1 . [ Image Display Component] ( #imagedisplay-component )
21220 . [ Demos] ( #demos )
22- 1 . [ StopWatch Application] ( #stopwatch-application )
23- 1 . [ ShowMessage Demo] ( #showmessage-demo )
24- 1 . [ BusyWorker Demo] ( #busyworker-demo )
25- 1 . [ ImageDisplay Demo] ( #imagedisplay-demo )
23+ 1 . [ StopWatch Application] ( #stopwatch-application )
24+ 1 . [ ShowMessage Demo] ( #showmessage-demo )
25+ 1 . [ BusyWorker Demo] ( #busyworker-demo )
26+ 1 . [ ImageDisplay Demo] ( #imagedisplay-demo )
26270 . [ Status] ( #status )
27280 . [ Discussion and Support] ( #discussion-and-support )
28290 . [ License] ( #license )
@@ -57,7 +58,6 @@ The main helper methods:
5758* ` onFXAndWait ` run code on FX Application thread and wait till finished
5859* ` offFX ` run code a thread in parallel
5960* ` offFXAndWait ` run code a thread and wait till finished
60- * ` showException ` show an exception dialog
6161
6262Example scheduling some code on FX Application thread
6363
@@ -73,37 +73,106 @@ Example execution some code on a separate thread and waiting for the result of c
7373
7474``` scala
7575val x = offFXAndWait {
76- val a = 3
77- val b = 7
78- a * b
76+ val a = 3
77+ val b = 7
78+ a * b
7979}
8080
8181```
8282
83- ### Simpler Display of Dialogs
83+ ### Simpler Display of Standard Dialogs
8484
85- The mixin ` ShowMessage ` makes it easier to display dialogs. It is typically used with a UI ` Model ` . The dialogs can be
85+ Standard dialogs can be quickly displayed using functions provided my ` ShowMessage ` . For instance,
86+
87+ ``` scala
88+ import org .scalafx .extras .ShowMessage
89+
90+ ShowMessage .information(
91+ " Dialog Title" ,
92+ " This is the information 'header'" ,
93+ " This is the information detailed 'content'." ,
94+ parentWindow
95+ )
96+ ```
97+
98+ Dialog types supported:
99+
100+ * ` confirmation `
101+ * ` confirmationYesNoCancel `
102+ * ` error `
103+ * ` exception `
104+ * ` information `
105+ * ` warning `
106+
107+ ` ShowMessage ` can be also used as a mixin to be used within a class where there is the same ` parentWindow ` .
108+ It is typically used with a UI ` Model ` . The dialogs can be
86109displayed using a single method, like ` showInformation ` , ` showConfirmation ` . ` ShowMessage ` takes care of blocking parent
87110windows and using parent icons in dialogs. It can also log warnings, errors, and exceptions when warnings, errors, and
88111exceptions dialogs are displayed.
89112
90113``` scala
91114class MyUIModel extends Model with ShowMessage {
92115
93- def onSomeUserAction (): Unit = {
94- // ...
95- showInformation(" Dialog Title" ,
96- " This is the information \" header\" " ,
97- " This is the information detailed \" content\" ." )
98- // ...
99- }
116+ def onSomeUserAction (): Unit = {
117+ // ...
118+ showInformation(" Dialog Title" ,
119+ " This is the information ' header' " ,
120+ " This is the information detailed ' content' ." )
121+ // ...
122+ }
100123
101- // ...
124+ // ...
102125}
103126```
104127
105128The demos module has a complete example of a simple application in ` ShowMessageDemoApp ` .
106129
130+ ### Easy Custom Dialogs
131+
132+ Custom dialogs can be quickly created using ` GenericDialogFX ` class. This class is particularly suited for creation of
133+ input dialogs.
134+
135+ There are 3 steps to using the ` GenericDialogFX ` :
136+
137+ 1 . Creation, where elements of the dialog are appended vertically using ` add*(...) ` methods, for
138+ instance,` addStringField(label, defaultText) `
139+ 2 . User interaction, dialog is displayed using ` showDialog() ` method
140+ 3 . Reading of input, once the dialog is closed, dialog content can be read using ` next*() ` methods. Content is read in
141+ the order it is added.
142+
143+ Here is en example:
144+
145+ ``` scala
146+ // Create a dialog
147+ val dialog =
148+ new GenericDialogFX (
149+ title = " GenericDialogFX Demo" ,
150+ header = " Fancy description can go here."
151+ ) {
152+ // Add fields
153+ addCheckbox(" Check me out!" , defaultValue = false )
154+ addCheckbox(" Check me too!" , defaultValue = true )
155+ }
156+
157+ // Show dialog to the user
158+ dialog.showDialog()
159+
160+ // Read input provided by the user
161+ if (dialog.wasOKed) {
162+ val select1 = dialog.nextBoolean()
163+ val select2 = dialog.nextBoolean()
164+
165+ println(s " Selection 1: $select1" )
166+ println(s " Selection 2: $select2" )
167+ } else {
168+ println(" Dialog was cancelled." )
169+ }
170+ ```
171+
172+ ![ GenericDialogFX Demo] ( notes/assets/GenericDialogFX_2.png )
173+
174+ A more elaborate example is in the ` GenericDialogFXDemo ` .
175+
107176### BusyWorker
108177
109178BusyWorker helps running a UI task on separate threads (other than the JavaFX Application thread). It will show busy
@@ -129,7 +198,7 @@ new BusyWorker("Simple Task", parentWindow).doTask { () =>
129198Here is a little more elaborated example. It updates a progress message and progress indicator.
130199
131200``` scala
132- val buttonPane : Pane =
201+ val buttonPane : Pane =
133202...
134203val progressLabel : Label =
135204...
0 commit comments