SFXApplicationController
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 SFXApplicationController {
// 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:
source
object Application extends SFXApplication with DeltaspikeBeanResolver {
DeltaspikeLauncher.init()
SFXApplicationEnvironment.documentLoader = getBean[DeltaspikeDocumentLoader]()
override val applicationController: SFXApplicationController = getBean[ApplicationController]()
}
BaseApplication Code:
sourceabstract class SFXApplication extends SFXStageSupport with LazyLogging {
val startTime: Long = System.currentTimeMillis()
def main(args: Array[String]): Unit = {
SFXApplicationEnvironment.setApplication(this)
Application.launch(classOf[SFXJavaApplication], args: _*)
}
val applicationController: SFXApplicationController
def applicationWillLaunch(): Unit = {}
def applicationDidLaunch(): Unit =
logger.info("Application Startup in %s ms".format(System.currentTimeMillis() - startTime))
def applicationWillTerminate(): Unit = {}
}
ApplicationController
Base class for your Application (extends normally SFXApplicationController). Is is used for setting the content view and holds application wide information.
Sample Code:
source
@Named
@ApplicationScoped
class ApplicationController extends SFXApplicationController {
lazy val mainController: IssueTrackingLiteController = getController[IssueTrackingLiteController]()
def applicationDidLaunch() {
replaceSceneContent(mainController)
}
// CDI Prducer Method
@Produces
def emptyName: EmptyName =
EmptyName("New Issue")
}
SFXAdditionalWindowController
Multiple Windows are supported by extending SFXAdditionalWindowController.
Example Usage:
Create a CDI Bean that extends AdditionalWindowController
sourceabstract class AbstractWindowController extends SFXAdditionalWindowController {
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
}
Create a variable (in your ApplicationController for example)
sourcelazy val secondWindowController = new SecondWindowController
Show second Window
Use x and y coordinates for window position.
sourcedef 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
sourcedef actionCloseSecondWindow(event: ActionEvent): Unit =
applicationController.secondWindowController.close()
ModalWindowController
Modal Window is basically a special Instance of a SFXAdditionalWindowController. It can be used for custom dialogs, preferences panes and so on. You only have to overwrite modality like in the sample code below:
source
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)
sourcelazy val modalWindowController = new ModalWindowController
Open Modal Window
sourcedef actionShowModalWindow(event: ActionEvent): Unit =
applicationController.modalWindowController.showAndWait()