public Splash_Controller( final JavaFX_Server_Template main, Splash_Model model, Splash_View view) { // final JavaFX_App_Template main -> Da die Main-Klasse sich selbst übergibt, kann // der Controller jetzt so auf Methoden in der Main-Klasse zugreifen super(model, view); // We could monitor the progress property and pass it on to the progress bar // However, JavaFX can also do this for us: We just bind the progressProperty of the // progress bar to the progressProperty of the task. view.progress .progressProperty() .bind( model.initializer .progressProperty()); // Aktualisieren(Listener)/Verbinden den Ladebalken aus dem // model mit dem view // The stateProperty tells us the status of the task. When the state is SUCCEEDED, // the task is finished, so we tell the main program to continue. // Below are two equivalent implementations - only one of these should be used! // Using an anonymous class // model.initializer.stateProperty().addListener( // new ChangeListener<Worker.State>() { // @Override // public void changed( // ObservableValue<? extends Worker.State> observable, // Worker.State oldValue, Worker.State newValue) { // if (newValue == Worker.State.SUCCEEDED) // main.startApp(); // } // }); // Using a lambda expression model .initializer .stateProperty() .addListener( // Beobachten den Ladebalken (observable, oldValue, newValue) -> { if (newValue == Worker.State .SUCCEEDED) // Wenn Ladebalken fertig geladen wurde (resourcen jetzt geladen), // starte im JavaFX_App_Template die methode "startApp()" welche // die MVC-Komponenten lädt main .startApp(); // Über die im Parameter übergebenen Objekte (bzw. das Main-Klasse // Objekt selbst) kann jetzt auf die Methode startApp() zugegriffen // werden }); }
/** * Copyright 2015, FHNW, Prof. Dr. Brad Richards. All rights reserved. This code is licensed under * the terms of the BSD 3-clause license (see the file license.txt). * * <p>The singleton instance of this class provide central storage for resources used by the * program. It also defines application-global constants, such as the application name. * * @author Brad Richards */ public class ServiceLocator { private static ServiceLocator serviceLocator; // singleton // Application-global constants private final Class<?> APP_CLASS = JavaFX_Server_Template.class; private final String APP_NAME = "JavaFX_Server_Template"; private final JavaFX_Server_Template JavaFX_Server_Template_mainProgram = JavaFX_Server_Template.getMainProgram(); // Supported locales (for translations) private final Locale[] locales = new Locale[] { new Locale("en"), new Locale("de") }; // Wird nur gebraucht damit wir wissen wie viele Sprachen es gibt, Translator-Objekt liest // die texte ein aus den files // Resources private Logger logger; private Configuration configuration; private Translator translator; // Mutlilingual-Texte werden hier eingelesen // May be deleted private boolean windowIsActive = true; // For deactivating the thread ShowTimeInWindow() in Bonuspunkte_Controller // // http://stackoverflow.com/questions/26494865/javafx-8-changing-title-of-primary-stage // final private String windowTitle = this.translator.getString("program.name.windowName"); // // getWindowTitle - TEST OB MAN WINDOW NAME ÄNDERN KANN /** * Factory method for returning the singleton * * @param mainClass The main class of this program * @return The singleton resource locator */ public static ServiceLocator getServiceLocator() { if (serviceLocator == null) serviceLocator = new ServiceLocator(); return serviceLocator; } /** * Private constructor, because this class is a singleton * * @param appName Name of the main class of this program */ private ServiceLocator() { // Currently nothing to do here. We must define this constructor anyway, // because the default constructor is public } public Class<?> getAPP_CLASS() { return APP_CLASS; } public String getAPP_NAME() { return APP_NAME; } public JavaFX_Server_Template getJavaFX_App_Template_mainProgram() { return JavaFX_Server_Template_mainProgram; } public Logger getLogger() { return logger; } public void setLogger(Logger logger) { this.logger = logger; } public Configuration getConfiguration() { return configuration; } public void setConfiguration( Configuration configuration) { // Wenn Parameter "new Configuration" -> in Klasse Configuration wird // Konstruktor aufgerufen this.configuration = configuration; // Speichere das vom Konstruktor erschaffene Objekt hier im ServiceLocator } public Locale[] getLocales() { return locales; } public Translator getTranslator() { return translator; } public void setTranslator(Translator translator) { this.translator = translator; } public boolean getIsWindowIsActive() { return windowIsActive; } public void setWindowIsActive(boolean windowIsActive) { this.windowIsActive = windowIsActive; } // For deactivating the thread ShowTimeInWindow() public void setChangeValueWindowIsActive() { if (this.windowIsActive) { this.windowIsActive = false; } else if (this.windowIsActive) { this.windowIsActive = true; } } }