Skip to content

Commit cee45d5

Browse files
committed
Merge remote-tracking branch 'origin/master' into stable
2 parents 21c6f13 + 4d5cda6 commit cee45d5

31 files changed

+2323
-157
lines changed

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ sudo: false
22

33
language: scala
44
scala:
5-
- 2.10.6
6-
- 2.11.8
7-
- 2.12.1
5+
- 2.10.7
6+
- 2.11.12
7+
- 2.12.6
88

99
before_install:
1010
- "export DISPLAY=:99.0"

ReadMe.md

Lines changed: 181 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,202 @@
11
ScalaFX Extras
22
==============
33

4-
Additions to ScalaFX that do not have corresponding concepts in JavaFX. The key parts are helper methods in `org.scalafx.extras` and support for a working with Model-View and FXML.
4+
[![Build Status](https://travis-ci.org/scalafx/scalafx-extras.svg?branch=master)](https://travis-ci.org/scalafx/scalafx-extras)
5+
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/org.scalafx/scalafx-extras_2.12/badge.svg)](https://maven-badges.herokuapp.com/maven-central/org.scalafx/scalafx-extras_2.12)
6+
[![Scaladoc](http://javadoc-badge.appspot.com/org.scalafx/scalafx-extras_2.12.svg?label=scaladoc)](http://javadoc-badge.appspot.com/org.scalafx/scalafx-extras_2.12)
57

6-
Module `scalafx-extras-demos` has a demo StopWatch application that illustrates uses of the Model-View and FXML API.
8+
ScalaFX Extras are additions to ScalaFX that simplify creation of User interfaces.
9+
In contrast to ScalaFX core, the Extras do not have direct corresponding concepts in JavaFX.
710

11+
**Contents**
812

9-
ScalaFX Extras is still quite experimental and APIs may change significantly.
13+
0. [Project Structure](#project-structure)
14+
0. [SBT](#sbt)
15+
0. [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)
21+
0. [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)
26+
0. [Status](#status)
27+
0. [Discussion and Support](#discussion-and-support)
28+
0. [License](#license)
29+
30+
Project Structure
31+
-----------------
32+
33+
Module `scalafx-extras` contain feature implementations.
34+
Module `scalafx-extras-demos` illustrates use of `scalafx-extras`
35+
36+
SBT
37+
---
1038

1139
To use ScalaFX Extras with SBT add following dependency:
1240

1341
```
14-
libraryDependencies += "org.scalafx" %% "scalafx-extras" % "0.1.0-SNAPSHOT"
42+
libraryDependencies += "org.scalafx" %% "scalafx-extras" % scalafx_extras_version
43+
```
44+
45+
The latest published ScalaFX Extras version: [![Maven Central](https://maven-badges.herokuapp.com/maven-central/org.scalafx/scalafx-extras_2.12/badge.svg)](https://maven-badges.herokuapp.com/maven-central/org.scalafx/scalafx-extras_2.12)
46+
47+
Features
48+
--------
49+
50+
### Helper Methods
51+
52+
Package `org.scalafx.extras` contains basic helper methods for running tasks on threads and showing exception messages.
53+
The main helper methods:
54+
55+
* `onFX` run code on FX Application thread in parallel
56+
* `onFXAndWait` run code on FX Application thread and wait till finished
57+
* `offFX` run code a thread in parallel
58+
* `offFXAndWait` run code a thread and wait till finished
59+
* `showException` show an exception dialog
60+
61+
Example scheduling some code on FX Application thread
62+
```scala
63+
onFX {
64+
counterService.doResume()
65+
_running.value = true
66+
}
67+
68+
```
69+
70+
Example execution some code on a separate thread and waiting for the result of computation
71+
```scala
72+
val x = offFXAndWait {
73+
val a = 3
74+
val b = 7
75+
a * b
76+
}
77+
78+
```
79+
80+
### Simpler Display of Dialogs
81+
82+
The mixin `ShowMessage` makes it easier to display dialogs. It is typically used with a UI `Model`.
83+
The dialogs can be displayed using a single method, like `showInformation`, `showConfirmation`. `ShowMessage` takes care of blocking parent windows and using parent icons in dialogs. It can also log warnings, errors, and exceptions when warnings, errors, and exceptions dialogs are displayed.
84+
85+
```scala
86+
class MyUIModel extends Model with ShowMessage {
87+
88+
def onSomeUserAction(): Unit = {
89+
// ...
90+
showInformation("Dialog Title",
91+
"This is the information \"header\"",
92+
"This is the information detailed \"content\".")
93+
// ...
94+
}
95+
96+
// ...
97+
}
98+
```
99+
The demos module has a complete example of an simple application in `ShowMessageDemoApp`.
100+
101+
### BusyWorker
102+
103+
BusyWorker helps running UI tasks a separate threads (other than the JavaFX Application thread).
104+
It will show busy cursor and disable specified nodes while task is performed.
105+
It gives an option to show progress and status messages.
106+
`BusyWorker` run tasks and takes care of handling handling exceptions and displaying error dialogs.
107+
There is also option to perform custom finish actions after task is completed.
108+
109+
A simple case of using `BusyWorker`.
110+
When the task is running, it will disable the root pane of the `parentWindow` to indicate that a task is performed.
111+
It will also change the cursor in the root pane to busy.
112+
When task is done, the cursor will be changed back to default and root pane will enabled back.
113+
114+
```scala
115+
new BusyWorker("Simple Task", parentWindow).doTask {
116+
Thread.sleep(1000)
117+
print(1 + 1)
118+
}
119+
```
120+
121+
A little bit more elaborated example that updates a progress message and progress indicator.
122+
The full example can be found in the `BusyWorkerDemo`.
123+
```scala
124+
val buttonPane: Pane = ...
125+
val progressLabel: Label = ...
126+
val progressBar: ProgressBar = ...
127+
128+
val busyWorker = new BusyWorker("BusyWorker Demo", buttonPane) {
129+
progressLabel.text <== progressMessage
130+
progressBar.progress <== progressValue
131+
}
132+
133+
val button = new Button("Click Me") {
134+
onAction = () => busyWorker.doTask("Task 1")(
135+
new SimpleTask[String] {
136+
override def call(): String = {
137+
val maxItems = 10
138+
for (i <- 1 to maxItems) {
139+
println(i)
140+
message() = s"Processing item $i/$maxItems"
141+
progress() = (i - 1) / 10.0
142+
Thread.sleep(250)
143+
}
144+
progress() = 1
145+
"Done"
146+
}
147+
}
148+
)
149+
}
15150
```
16151

17152

153+
154+
### Simpler Use of FXML with MVCfx Pattern
155+
156+
Package `org.scalafx.extras.mvcfx` contains classes for creating with UI components based on FXML.
157+
158+
The demos module has a complete example of a simple application: `StopWatchApp`.
159+
160+
### ImageDisplay Component
161+
162+
ImageDisplay Component is an image view with ability to zoom in, zoom out, zoom to fit.
163+
It can also automatically resizes to parent size.
164+
165+
166+
Demos
167+
-----
168+
169+
Module `scalafx-extras-demos` contains examples of using ScalaFX Extras.
170+
171+
### StopWatch Application
172+
173+
`StopWatchApp` is an application that illustrates uses of the MVCfx: a Model-Controller and SFXML/FXML API.
174+
175+
### ShowMessage Demo
176+
`ShowMessageDemoApp` is a full example of using `ShowMessage` and MVCfx.
177+
178+
### BusyWorker Demo
179+
`BusyWorkerDemo` illustrated different aspects of using `BusyWorker`.
180+
181+
### ImageDisplay Demo
182+
183+
`ImageDisplayDemoApp` a simple example of an application that can display images,
184+
with ability to zoom in, zoom out, and fit to current window. Illustrates use of the `ImageDisplay` component.
185+
186+
Status
187+
------
188+
189+
ScalaFX Extras is still quite experimental and APIs may change significantly.
190+
18191
Discussion and Support
19192
----------------------
20193

21-
Please use [ScalaFX Users Group](https://groups.google.com/forum/#!forum/scalafx-users). Please report issues using the projects Issue tracker.
194+
For discussion and support, please use [ScalaFX Users Group](https://groups.google.com/forum/#!forum/scalafx-users)
195+
or [ScalaFX on StackOverflow](https://stackoverflow.com/questions/tagged/scalafx).
196+
Please report issues using the projects Issue tracker.
22197

23198

24199
License
25200
-------
26201

27-
BSD-3-Clause ScalaFX license.
202+
BSD-3-Clause ScalaFX license.

build.sbt

Lines changed: 50 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -8,59 +8,57 @@ import java.net.URL
88
// JAR_BUILT_BY - Name to be added to Jar metadata field "Built-By" (defaults to System.getProperty("user.name")
99
//
1010

11-
val projectVersion = "0.1.0"
12-
val versionTagDir = if (projectVersion.endsWith("SNAPSHOT")) "master" else "v" + projectVersion
11+
val projectVersion = "0.2.0-SNAPSHOT"
12+
val versionTagDir = if (projectVersion.endsWith("SNAPSHOT")) "master" else "v" + projectVersion
13+
val scalaVersions = Seq("2.11.12", "2.12.7")
1314

14-
crossScalaVersions := Seq("2.11.8", "2.12.1")
15-
scalaVersion := crossScalaVersions { versions => versions.head }.value
15+
crossScalaVersions := scalaVersions
16+
scalaVersion := crossScalaVersions { versions => versions.head }.value
1617

17-
// ScalaFX project
18-
lazy val scalaFXExtrasProject = Project(
19-
id = "scalafx-extras",
20-
base = file("scalafx-extras"),
21-
settings = scalaFXExtrasSettings ++ Seq(
22-
description := "The ScalaFX Extras",
23-
fork in run := true,
24-
scalacOptions in(Compile, doc) ++= Seq(
25-
"-sourcepath", baseDirectory.value.toString,
26-
"-doc-root-content", baseDirectory.value + "/src/main/scala/root-doc.creole",
27-
"-doc-source-url", "https://github.com/SscalaFX-Extras/scalafx-extras/blob/" + versionTagDir + "/scalafx/€{FILE_PATH}.scala"
28-
) ++ (Option(System.getenv("GRAPHVIZ_DOT_PATH")) match {
29-
case Some(path) => Seq("-diagrams", "-diagrams-dot-path", path)
30-
case None => Seq.empty[String]
31-
})
32-
)
18+
// ScalaFX Extras project
19+
lazy val scalaFXExtras = (project in file("scalafx-extras")).settings(
20+
scalaFXExtrasSettings,
21+
name := "scalafx-extras",
22+
description := "The ScalaFX Extras",
23+
fork in run := true,
24+
scalacOptions in(Compile, doc) ++= Seq(
25+
"-sourcepath", baseDirectory.value.toString,
26+
"-doc-root-content", baseDirectory.value + "/src/main/scala/root-doc.creole",
27+
"-doc-source-url", "https://github.com/SscalaFX-Extras/scalafx-extras/blob/" + versionTagDir + "/scalafx/€{FILE_PATH}.scala"
28+
) ++ (Option(System.getenv("GRAPHVIZ_DOT_PATH")) match {
29+
case Some(path) => Seq("-diagrams", "-diagrams-dot-path", path)
30+
case None => Seq.empty[String]
31+
}) ++ (if(scalaVersion.value.startsWith("2.11")) Seq("-Xexperimental") else Seq.empty[String])
3332
)
3433

35-
// ScalaFX Demos project
36-
lazy val scalaFXExtrasDemosProject = Project(
37-
id = "scalafx-extras-demos",
38-
base = file("scalafx-extras-demos"),
39-
settings = scalaFXExtrasSettings ++ Seq(
40-
description := "The ScalaFX Extras demonstrations",
41-
fork in run := true,
42-
javaOptions ++= Seq(
43-
"-Xmx512M",
44-
"-Djavafx.verbose"
45-
),
46-
addCompilerPlugin("org.scalamacros" % "paradise" % "2.1.0" cross CrossVersion.full),
47-
publishArtifact := false
34+
// ScalaFX Extras Demos project
35+
lazy val scalaFXExtrasDemos = (project in file("scalafx-extras-demos")).settings(
36+
scalaFXExtrasSettings,
37+
name := "scalafx-extras-demos",
38+
description := "The ScalaFX Extras demonstrations",
39+
fork in run := true,
40+
javaOptions ++= Seq(
41+
"-Xmx512M",
42+
"-Djavafx.verbose"
43+
),
44+
addCompilerPlugin("org.scalamacros" % "paradise" % "2.1.1" cross CrossVersion.full),
45+
publishArtifact := false,
46+
libraryDependencies ++= Seq(
47+
"com.typesafe.scala-logging" %% "scala-logging" % "3.9.0",
48+
"ch.qos.logback" % "logback-classic" % "1.2.3"
4849
)
49-
) dependsOn (scalaFXExtrasProject % "compile;test->test")
50+
).dependsOn(scalaFXExtras % "compile;test->test")
5051

5152
// Resolvers
52-
lazy val sonatypeNexusSnapshots = "Sonatype Nexus Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots"
53-
lazy val sonatypeNexusStaging = "Sonatype Nexus Staging" at "https://oss.sonatype.org/service/local/staging/deploy/maven2"
54-
5553
// Add snapshots to root project to enable compilation with Scala SNAPSHOT compiler,
5654
// e.g., 2.11.0-SNAPSHOT
57-
resolvers += sonatypeNexusSnapshots
55+
resolvers += Resolver.sonatypeRepo("snapshots")
5856

5957
// Common settings
6058
lazy val scalaFXExtrasSettings = Seq(
6159
organization := "org.scalafx",
6260
version := projectVersion,
63-
crossScalaVersions := Seq("2.11.8", "2.12.1"),
61+
crossScalaVersions := scalaVersions,
6462
scalaVersion := crossScalaVersions { versions => versions.head }.value,
6563
scalacOptions ++= Seq("-unchecked", "-deprecation", "-Xcheckinit", "-encoding", "utf8", "-feature"),
6664
scalacOptions in(Compile, doc) ++= Opts.doc.title("ScalaFX Extras API"),
@@ -72,16 +70,17 @@ lazy val scalaFXExtrasSettings = Seq(
7270
"-source", "1.8",
7371
"-Xlint:deprecation"),
7472
libraryDependencies ++= Seq(
75-
"org.scala-lang" % "scala-reflect" % scalaVersion.value,
76-
"org.scalafx" %% "scalafx" % "8.0.102-R11",
77-
"org.scalafx" %% "scalafxml-core-sfx8" % "0.3",
78-
"org.scalatest" %% "scalatest" % "3.0.1" % "test"),
73+
"com.beachape" %% "enumeratum" % "1.5.13",
74+
"org.scala-lang" % "scala-reflect" % scalaVersion.value,
75+
"org.scalafx" %% "scalafx" % "8.0.181-R13",
76+
"org.scalafx" %% "scalafxml-core-sfx8" % "0.4",
77+
"org.scalatest" %% "scalatest" % "3.0.5" % "test"),
7978
autoAPIMappings := true,
8079
manifestSetting,
8180
publishSetting,
8281
fork in Test := true,
8382
parallelExecution in Test := false,
84-
resolvers += sonatypeNexusSnapshots,
83+
resolvers += Resolver.sonatypeRepo("snapshots"),
8584
// print junit-style XML for CI
8685
testOptions in Test += {
8786
val t = (target in Test).value
@@ -105,13 +104,13 @@ lazy val manifestSetting = packageOptions += {
105104
)
106105
}
107106

108-
lazy val publishSetting = publishTo := version {
109-
version: String =>
110-
if (version.trim.endsWith("SNAPSHOT"))
111-
Some(sonatypeNexusSnapshots)
112-
else
113-
Some(sonatypeNexusStaging)
114-
}.value
107+
lazy val publishSetting = publishTo := {
108+
val nexus = "https://oss.sonatype.org/"
109+
if (isSnapshot.value)
110+
Some("snapshots" at nexus + "content/repositories/snapshots")
111+
else
112+
Some("releases" at nexus + "service/local/staging/deploy/maven2")
113+
}
115114

116115
// Metadata needed by Maven Central
117116
// See also http://maven.apache.org/pom.html#Developers

notes/0.2.0.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
### ScalaFX-Extras Release v.0.2.0
2+
3+
This a feature release, several new concepts were added:
4+
5+
* The mixin `ShowMessage` makes it easier to display dialogs.
6+
* The `BusyWorker` helps running UI tasks a separate threads (other than the JavaFX Application thread).
7+
It gives an option to show progress and status messages.
8+
* The `ImageDisplay` component for showing images with ability to zoom in, zoom out, zoom to fit.
9+
It can also automatically resizes to parent size.
10+
11+
There were also significant changes to the Model-View-X pattern code.
12+
The `View` changed name to `ControllerFX` to match naming used in JavaFX.
13+
`Model` was renamed to `ModelFX`.
14+
`ModelView` was renamed to `MVCfx`.
15+
There were some other changed for smoother integration with the new `ShowMessage` and `BusyWorker` classes.
16+
The ending `FX` was added to avoid conflicts with ScalaFXML macros clashing with name `Controller`.
17+
18+
The are new demos, in `scalafx-extras-demos` project that illustrate the use of the `scalafx-extras` features.
19+
20+
To post questions please use [ScalaFX Users Group][5] of [StackOverflow ScalaFX][6]
21+
22+
[5]: https://groups.google.com/forum/#!forum/scalafx-users
23+
[6]: https://stackoverflow.com/questions/tagged/scalafx

0 commit comments

Comments
 (0)