Tutorial Application
Application object
A sapphire application must contain an Application object that extends BaseApplication.
package com.sfxcode.sapphire.core.demo.tutorial
import com.sfxcode.sapphire.core.application.BaseApplication
import com.sfxcode.sapphire.core.controller.BaseApplicationController
object Application extends BaseApplication {
val applicationController: BaseApplicationController = new ApplicationController
override def height: Int = 555
override def width: Int = 700
override def forceMaxWidth: Boolean = true
override def forceMaxHeight: Boolean = true
}
ApplicationController
Application controller is used for startup purposes.
Normally the main scene content is replaced by a ViewController.
Here we will use a MainViewController and later we connect a Navigation-, Workspace- and StatusBarController.
package com.sfxcode.sapphire.core.demo.tutorial
import java.util.{ Locale, ResourceBundle }
import com.sfxcode.sapphire.core.application.ApplicationEnvironment
import com.sfxcode.sapphire.core.controller.BaseApplicationController
import com.sfxcode.sapphire.core.demo.tutorial.controller.MainViewController
class ApplicationController extends BaseApplicationController {
lazy val mainViewController: MainViewController =
getController[MainViewController]()
def applicationDidLaunch() {
logger.info("start " + this)
// #Resources
ApplicationEnvironment.loadResourceBundle("bundles/application")
// #Resources
replaceSceneContent(mainViewController)
}
def reload(): Unit = {
// Styling
reloadStyles()
// Resources
ApplicationEnvironment.clearResourceBundleCache()
ApplicationEnvironment.loadResourceBundle("bundles/application")
// FXML
val newMainViewController = getController[MainViewController]()
replaceSceneContent(newMainViewController)
}
def applicationName: ApplicationName =
ApplicationName(configStringValue("application.name"))
// #CustomBundle
// only example values ...
override def resourceBundleForView(viewPath: String): ResourceBundle =
if (viewPath.contains("mySpecialViewName")) {
val path = "myCustomResourcePath"
val classLoader = Thread.currentThread().getContextClassLoader
ResourceBundle.getBundle(path, Locale.getDefault(), classLoader)
} else
super.resourceBundleForView(viewPath) // = applicationEnvironment.resourceBundle
// #CustomBundle
}
case class ApplicationName(name: String)
MainViewController
The following code snippet loads the MainViewController by the FXMLoader from the CDI managed ApplicationController Bean.
lazy val mainViewController = getController[MainViewController]()
This pattern for Controller-Loading is commonly used in sapphire-core Framework.
2.0.1*