WindowController

The WindowController combines JavaFX Stage and Scene. Creates a stage and a scene. Scene content can be exchanged by replaceSceneContent function.

Sample with scene content switching can be found in the login demo.

class ApplicationController extends BaseApplicationController {
  // Content here
}

WindowController height and width are 800 x 600 by default, but can be easily overwritten in implementation classes:

  // overwrite window default size
  override def width: Int = 200
  override def height: Int = 400

Features

  • Lifecycle

BaseApplicationController

BaseApplicationController is normally the base class for your ApplicationController.

Initialization is automatically done by the Application class (must be an object that extends BaseApplication) to be runnable

Lifecycle Methods

Following methods are supported:

  • applicationWillLaunch (before setting stage)
  • applicationDidLaunch (after setting stage)
  • applicationWillStop (before Appliction terminates)

Application

Sample Code:


object Application extends BaseApplication with DeltaspikeBeanResolver { DeltaspikeLauncher.init() ApplicationEnvironment.documentLoader = getBean[DeltaspikeDocumentLoader]() override val applicationController: BaseApplicationController = getBean[ApplicationController]() }

BaseApplication Code:

abstract class BaseApplication extends StageSupport with LazyLogging {
  val startTime: Long = System.currentTimeMillis()

  def main(args: Array[String]): Unit = {
    ApplicationEnvironment.setApplication(this)
    Application.launch(classOf[FXApplication], args: _*)
  }

  val applicationController: BaseApplicationController

  def applicationWillLaunch() {}

  def applicationDidLaunch(): Unit =
    logger.info("Application Startup in %s ms".format(System.currentTimeMillis() - startTime))

  def applicationWillTerminate() {}

}

ApplicationController

Base class for your Application (extends normally DefaultWindowController). Is is used for setting the content view and holds application wide information.

Sample Code:


@Named @ApplicationScoped class ApplicationController extends BaseApplicationController { lazy val mainController: IssueTrackingLiteController = getController[IssueTrackingLiteController]() def applicationDidLaunch() { replaceSceneContent(mainController) } // CDI Prducer Method @Produces def emptyName: EmptyName = EmptyName("New Issue") }

AdditionalWindowController

Multiple Windows are supported by extending AdditionalWindowController.

Example Usage:

Create a CDI Bean that extends AdditionalWindowController

abstract class AbstractWindowController extends AdditionalWindowController {

  lazy val viewController: AdditionalViewController =
    getController[AdditionalViewController]()

  override def startup(): Unit = {
    super.startup()
    val stage: Unit = createStage()

    replaceSceneContent(viewController)
  }

  override def width: Int = 200

  override def height: Int = 200

}
class SecondWindowController extends AbstractWindowController

Create a variable (in your ApplicationController for example)

lazy val secondWindowController = new SecondWindowController

Show second Window

Use x and y coordinates for window position.

def actionShowSecondWindow(event: ActionEvent): Unit = {
  val x = applicationController.stage.getX + applicationController.stage.getWidth
  val y = applicationController.stage.getY
  applicationController.secondWindowController.show(x, y)
}

Close second Window

def actionCloseSecondWindow(event: ActionEvent): Unit =
  applicationController.secondWindowController.close()

ModalWindowController

Modal Window is basically a special Instance of an AdditionalWindowController. It can be used for custom dialogs, preferences panes and so on. You only have to overwrite modality like in the sample code below:


class ModalWindowController extends AbstractWindowController { override def modality: Modality = Modality.APPLICATION_MODAL override def stageStyle: StageStyle = StageStyle.UTILITY }

Create a variable (in your ApplicationController for example)

lazy val modalWindowController = new ModalWindowController

Open Modal Window

def actionShowModalWindow(event: ActionEvent): Unit =
  applicationController.modalWindowController.showAndWait()