scalafx-extras

The ScalaFX Extras

License

License

BSD
Categories

Categories

Scala Languages
GroupId

GroupId

org.scalafx
ArtifactId

ArtifactId

scalafx-extras_2.11
Last Version

Last Version

0.2.0
Release Date

Release Date

Type

Type

jar
Description

Description

scalafx-extras
The ScalaFX Extras
Project URL

Project URL

http://www.scalafx.org/
Project Organization

Project Organization

org.scalafx
Source Code Management

Source Code Management

https://github.com/scalafx/scalafx-extras

Download scalafx-extras_2.11

How to add to project

<!-- https://jarcasting.com/artifacts/org.scalafx/scalafx-extras_2.11/ -->
<dependency>
    <groupId>org.scalafx</groupId>
    <artifactId>scalafx-extras_2.11</artifactId>
    <version>0.2.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.scalafx/scalafx-extras_2.11/
implementation 'org.scalafx:scalafx-extras_2.11:0.2.0'
// https://jarcasting.com/artifacts/org.scalafx/scalafx-extras_2.11/
implementation ("org.scalafx:scalafx-extras_2.11:0.2.0")
'org.scalafx:scalafx-extras_2.11:jar:0.2.0'
<dependency org="org.scalafx" name="scalafx-extras_2.11" rev="0.2.0">
  <artifact name="scalafx-extras_2.11" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.scalafx', module='scalafx-extras_2.11', version='0.2.0')
)
libraryDependencies += "org.scalafx" % "scalafx-extras_2.11" % "0.2.0"
[org.scalafx/scalafx-extras_2.11 "0.2.0"]

Dependencies

compile (5)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.11.12
com.beachape : enumeratum_2.11 jar 1.5.13
org.scala-lang : scala-reflect jar 2.11.12
org.scalafx : scalafx_2.11 jar 8.0.181-R13
org.scalafx : scalafxml-core-sfx8_2.11 jar 0.4

test (1)

Group / Artifact Type Version
org.scalatest : scalatest_2.11 jar 3.0.5

Project Modules

There are no modules declared in this project.

ScalaFX Extras

Build Status Maven Central Scaladoc

ScalaFX Extras are additions to ScalaFX that simplify creation of User interfaces. In contrast to ScalaFX core, the Extras do not have direct corresponding concepts in JavaFX.

Contents

  1. Project Structure
  2. SBT
  3. Features
    1. Helper Methods
    2. Simpler Display of Dialogs
    3. BusyWorker
    4. Simpler Use of FXML with MVCfx Pattern
    5. Image Display Component
  4. Demos
    1. StopWatch Application
    2. ShowMessage Demo
    3. BusyWorker Demo
    4. ImageDisplay Demo
  5. Status
  6. Discussion and Support
  7. License

Project Structure

Module scalafx-extras contain feature implementations. Module scalafx-extras-demos illustrates use of scalafx-extras

SBT

To use ScalaFX Extras with SBT add following dependency:

libraryDependencies += "org.scalafx" %% "scalafx-extras" % scalafx_extras_version

The latest published ScalaFX Extras version: Maven Central

Features

Helper Methods

Package org.scalafx.extras contains basic helper methods for running tasks on threads and showing exception messages. The main helper methods:

  • onFX run code on FX Application thread in parallel
  • onFXAndWait run code on FX Application thread and wait till finished
  • offFX run code a thread in parallel
  • offFXAndWait run code a thread and wait till finished
  • showException show an exception dialog

Example scheduling some code on FX Application thread

onFX {
    counterService.doResume()
    _running.value = true
}

Example execution some code on a separate thread and waiting for the result of computation

val x = offFXAndWait {
    val a = 3
    val b = 7
    a * b
}

Simpler Display of Dialogs

The mixin ShowMessage makes it easier to display dialogs. It is typically used with a UI Model. 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.

class MyUIModel extends Model with ShowMessage {

  def onSomeUserAction(): Unit = {
    // ...
    showInformation("Dialog Title",
      "This is the information \"header\"",
      "This is the information detailed \"content\".")
    // ...
  }
  
  // ...
}

The demos module has a complete example of an simple application in ShowMessageDemoApp.

BusyWorker

BusyWorker helps running a UI task on separate threads (other than the JavaFX Application thread). It will show busy cursor and disable specified nodes while the task is performed. It gives an option to show progress and status messages. BusyWorker takes care of handling handling exceptions and displaying error dialogs. It provides for an option to perform custom finish actions after task is completed.

Example 1

Below is a simple example of using BusyWorker. When the task is running, BusyWorker will disable the root pane of the parentWindow to indicate that a task is performed. It will also change the cursor in the root pane to "busy". When task is done, the cursor will be changed back to default and root pane will be enabled back.

new BusyWorker("Simple Task", parentWindow).doTask { () =>
  Thread.sleep(1000)
  print(1 + 1)
}

Examnple 2

Her is a little bit more elaborated example. It updates a progress message and progress indicator.

  val buttonPane: Pane = ...
  val progressLabel: Label = ...
  val progressBar: ProgressBar = ...

  val busyWorker = new BusyWorker("BusyWorker Demo", buttonPane) {
    progressLabel.text <== progressMessage
    progressBar.progress <== progressValue
  }

  val button = new Button("Click Me") {
        onAction = () => busyWorker.doTask("Task 1")(
          new SimpleTask[String] {
            override def call(): String = {
              val maxItems = 10
              for (i <- 1 to maxItems) {
                println(i)
                message() = s"Processing item $i/$maxItems"
                progress() = (i - 1) / 10.0
                Thread.sleep(250)
              }
              progress() = 1
              "Done"
            }
          }
        )
  }

The full code example can be found in the BusyWorkerDemo.

Simpler Use of FXML with MVCfx Pattern

Package org.scalafx.extras.mvcfx contains classes for creating with UI components based on FXML.

The demos module has a complete example of a simple application: StopWatchApp.

ImageDisplay Component

ImageDisplay Component is an image view with ability to zoom in, zoom out, zoom to fit. It can also automatically resizes to parent size.

Demos

Module scalafx-extras-demos contains examples of using ScalaFX Extras.

StopWatch Application

StopWatchApp is an application that illustrates uses of the MVCfx: a Model-Controller and SFXML/FXML API.

StopWatch Demo

ShowMessage Demo

ShowMessageDemoApp is a full example of using ShowMessage and MVCfx.

ShowMessage Demo

BusyWorker Demo

BusyWorkerDemo illustrated different aspects of using BusyWorker.

BusyWorker Demo

ImageDisplay Demo

ImageDisplayDemoApp a simple example of an application that can display images, with ability to zoom in, zoom out, and fit to current window. Illustrates use of the ImageDisplay component.

Image Display Demo

Status

ScalaFX Extras is still quite experimental and APIs may change significantly.

Discussion and Support

For discussion and support, please use ScalaFX Users Group or ScalaFX on StackOverflow. Please report issues using the projects Issue tracker.

License

BSD-3-Clause ScalaFX license.

org.scalafx

ScalaFX

Versions

Version
0.2.0
0.1.0