@@ -2,37 +2,36 @@ ScalaFX Extras
22==============
33
44[ ![ Scala CI] ( https://github.com/scalafx/scalafx-extras/actions/workflows/scala.yml/badge.svg )] ( https://github.com/scalafx/scalafx-extras/actions/workflows/scala.yml )
5- [ ![ Maven Central] ( https://maven-badges.herokuapp.com/maven-central/org.scalafx/scalafx-extras_2.13 /badge.svg )] ( https://maven-badges.herokuapp.com/maven-central/org.scalafx/scalafx-extras_2.13 )
6- [ ![ Scaladoc] ( https://javadoc.io/badge2/org.scalafx/scalafx-extras_2.13 /scaladoc.svg )] ( https://javadoc.io/doc/org.scalafx/scalafx-extras_2.13 )
5+ [ ![ Maven Central] ( https://maven-badges.herokuapp.com/maven-central/org.scalafx/scalafx-extras_3 /badge.svg )] ( https://maven-badges.herokuapp.com/maven-central/org.scalafx/scalafx-extras_3 )
6+ [ ![ Scaladoc] ( https://javadoc.io/badge2/org.scalafx/scalafx-extras_3 /scaladoc.svg )] ( https://javadoc.io/doc/org.scalafx/scalafx-extras_3 )
77
88ScalaFX Extras are additions to ScalaFX that simplify creation of User interfaces. In contrast to ScalaFX core, the
99Extras do not have direct corresponding concepts in JavaFX.
1010
1111** Contents**
1212
1313<!-- TOC -->
14-
15- * [ Project Structure ] ( #project-structure )
16- * [ SBT ] ( #sbt )
17- * [ Features ] ( #features )
18- * [ Helper Methods ] ( #helper-methods )
19- * [ Simpler Display of Standard Dialogs ] ( #simpler-display-of-standard-dialogs )
20- * [ Easy Custom Dialogs] ( #easy-custom-dialogs )
21- * [ Edit a Case Class object with AutoDialog] ( #edit-a-case-class-object-with-autodialog )
22- * [ BusyWorker] ( #busyworker )
14+ * [ Project Structure ] ( #project-structure )
15+ * [ SBT ] ( #sbt )
16+ * [ Features ] ( #features )
17+ * [ Helper Methods ] ( #helper-methods )
18+ * [ Simpler Display of Standard Dialogs ] ( #simpler-display-of-standard-dialogs )
19+ * [ Easy Custom Panes ] ( #easy-custom-panes )
20+ * [ Easy Custom Dialogs] ( #easy-custom-dialogs )
21+ * [ Edit a Case Class object with AutoDialog] ( #edit-a-case-class-object-with-autodialog )
22+ * [ BusyWorker] ( #busyworker )
2323 * [ Example 1] ( #example-1 )
2424 * [ Example 2] ( #example-2 )
25- * [ Simpler Use of FXML with MVCfx Pattern] ( #simpler-use-of-fxml-with-mvcfx-pattern )
26- * [ ImageDisplay Component] ( #imagedisplay-component )
27- * [ Demos] ( #demos )
28- * [ StopWatch Application] ( #stopwatch-application )
29- * [ ShowMessage Demo] ( #showmessage-demo )
30- * [ BusyWorker Demo] ( #busyworker-demo )
31- * [ ImageDisplay Demo] ( #imagedisplay-demo )
32- * [ Status] ( #status )
33- * [ Discussion and Support] ( #discussion-and-support )
34- * [ License] ( #license )
35-
25+ * [ Simpler Use of FXML with MVCfx Pattern] ( #simpler-use-of-fxml-with-mvcfx-pattern )
26+ * [ ImageDisplay Component] ( #imagedisplay-component )
27+ * [ Demos] ( #demos )
28+ * [ StopWatch Application] ( #stopwatch-application )
29+ * [ ShowMessage Demo] ( #showmessage-demo )
30+ * [ BusyWorker Demo] ( #busyworker-demo )
31+ * [ ImageDisplay Demo] ( #imagedisplay-demo )
32+ * [ Status] ( #status )
33+ * [ Discussion and Support] ( #discussion-and-support )
34+ * [ License] ( #license )
3635<!-- TOC -->
3736
3837Project Structure
@@ -80,9 +79,9 @@ Example execution some code on a separate thread and waiting for the result of c
8079
8180``` scala
8281val x = offFXAndWait {
83- val a = 3
84- val b = 7
85- a * b
82+ val a = 3
83+ val b = 7
84+ a * b
8685}
8786
8887```
@@ -95,10 +94,10 @@ Standard dialogs can be quickly displayed using functions provided my `ShowMessa
9594import org .scalafx .extras .ShowMessage
9695
9796ShowMessage .information(
98- " Dialog Title" ,
99- " This is the information 'header'" ,
100- " This is the information detailed 'content'." ,
101- parentWindow
97+ " Dialog Title" ,
98+ " This is the information 'header'" ,
99+ " This is the information detailed 'content'." ,
100+ parentWindow
102101)
103102```
104103
@@ -120,20 +119,80 @@ exceptions dialogs are displayed.
120119``` scala
121120class MyUIModel extends Model with ShowMessage {
122121
123- def onSomeUserAction (): Unit = {
124- // ...
125- showInformation(" Dialog Title" ,
126- " This is the information 'header'" ,
127- " This is the information detailed 'content'." )
128- // ...
129- }
122+ def onSomeUserAction (): Unit = {
123+ // ...
124+ showInformation(" Dialog Title" ,
125+ " This is the information 'header'" ,
126+ " This is the information detailed 'content'." )
127+ // ...
128+ }
130129
131- // ...
130+ // ...
132131}
133132```
134133
135134The demos module has a complete example of a simple application in ` ShowMessageDemoApp ` .
136135
136+ ### Easy Custom Panes
137+
138+ ` GenericPane ` is a helper class that simplifies creation of panes. Particularly suited for creation of input controls.
139+
140+ Typically there are 4 steps to using a ` GenericPane ` :
141+
142+ 1 . Creation, where elements of the pane are appended vertically using ` add*(...) ` methods, for instance,
143+ ` addStringField(label, defaultText) `
144+
145+ 2 . Adding the pane to the UI
146+
147+ 3 . User interaction, after the pane is displayed
148+
149+ 4 . Optionally, reading of input. Pane's editable content can be read using ` next*() ` methods. Content is read in the
150+ order it is added. The whole pane content can be read multiple tiles. Remember to call ` resetReadout() ` to ensure
151+ that reading is restarted from the beginning of the pane.
152+
153+ A complete example in Scala 3. Shows a pane with 2 directory selection fields and a button "Print Fields". When the
154+ button is pressed values
155+ of the directory fields are printed
156+
157+ [ // ] : # ( @formatter:off )
158+ ``` scala
159+ import scalafx .application .JFXApp3
160+ import scalafx .application .JFXApp3 .PrimaryStage
161+ import scalafx .geometry .Insets
162+ import scalafx .scene .Scene
163+ import scalafx .scene .control .Button
164+ import scalafx .scene .layout .VBox
165+ import scalafx .scene .paint .*
166+ import scalafx .scene .paint .Color .*
167+ import scalafx .scene .text .Text
168+
169+ object GenericPaneDemo extends JFXApp3 :
170+
171+ override def start (): Unit =
172+
173+ val gp = new GenericPane ():
174+ addDirectoryField(" Input" , " images" )
175+ addDirectoryField(" Output" , " output" )
176+
177+ stage = new PrimaryStage :
178+ title = " GenericPane Demo"
179+ scene = new Scene :
180+ content = new VBox :
181+ padding = Insets (7 , 7 , 7 , 7 )
182+ spacing = 7
183+ children = Seq (
184+ gp.pane,
185+ new Button (" Print Fields" ):
186+ onAction = (_) =>
187+ gp.resetReadout()
188+ println(s " Input dir : ${gp.nextString()}" )
189+ println(s " Output dir: ${gp.nextString()}" )
190+ )
191+ ```
192+ [ // ] : # ( @formatter:off )
193+
194+ ![ GenericPane Demo] ( notes/assets/GenericPane.png )
195+
137196### Easy Custom Dialogs
138197
139198Custom dialogs can be quickly created using ` GenericDialogFX ` class. This class is particularly suited for creation of
@@ -152,27 +211,27 @@ Here is en example:
152211``` scala
153212// Create a dialog
154213val dialog =
155- new GenericDialogFX (
156- title = " GenericDialogFX Demo" ,
157- header = " Fancy description can go here."
158- ) {
159- // Add fields
160- addCheckbox(" Check me out!" , defaultValue = false )
161- addCheckbox(" Check me too!" , defaultValue = true )
162- }
214+ new GenericDialogFX (
215+ title = " GenericDialogFX Demo" ,
216+ header = " Fancy description can go here."
217+ ) {
218+ // Add fields
219+ addCheckbox(" Check me out!" , defaultValue = false )
220+ addCheckbox(" Check me too!" , defaultValue = true )
221+ }
163222
164223// Show dialog to the user
165224dialog.showDialog()
166225
167226// Read input provided by the user
168227if (dialog.wasOKed) {
169- val select1 = dialog.nextBoolean()
170- val select2 = dialog.nextBoolean()
228+ val select1 = dialog.nextBoolean()
229+ val select2 = dialog.nextBoolean()
171230
172- println(s " Selection 1: $select1" )
173- println(s " Selection 2: $select2" )
231+ println(s " Selection 1: $select1" )
232+ println(s " Selection 2: $select2" )
174233} else {
175- println(" Dialog was cancelled." )
234+ println(" Dialog was cancelled." )
176235}
177236```
178237
@@ -198,10 +257,10 @@ case class FilterOptions(kernelSize: Int = 7,
198257val filterOptions = FilterOptions ()
199258
200259val result : Option [FilterOptions ] =
201- new AutoDialog (filterOptions)
202- .showDialog(
203- " AutoDialog Demo" ,
204- " Fields are auto generated from `FilterOptions` object" )
260+ new AutoDialog (filterOptions)
261+ .showDialog(
262+ " AutoDialog Demo" ,
263+ " Fields are auto generated from `FilterOptions` object" )
205264
206265println(s " Result: $result" )
207266```
0 commit comments