package com.scrivenvar;
import static com.scrivenvar.Constants.LOGO_128;
import static com.scrivenvar.Constants.LOGO_16;
import static com.scrivenvar.Constants.LOGO_256;
import static com.scrivenvar.Constants.LOGO_32;
import static com.scrivenvar.Constants.LOGO_512;
import com.scrivenvar.service.Options;
import com.scrivenvar.service.events.AlertService;
import com.scrivenvar.util.StageState;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.stage.Stage;
public final class Main extends Application {
private static Application app;
private final MainWindow mainWindow = new MainWindow();
private final Options options = Services.load( Options.class );
public static void main( String[] args ) {
launch( args );
}
@Override
public void start( final Stage stage ) throws Exception {
initApplication();
initState( stage );
initStage( stage );
initAlertService();
stage.show();
}
private void initApplication() {
app = this;
}
private Options getOptions() {
return this.options;
}
private String getApplicationTitle() {
return Messages.get( "Main.title" );
}
private StageState initState( Stage stage ) {
return new StageState( stage, getOptions().getState() );
}
private void initStage( Stage stage ) {
stage.getIcons().addAll(
new Image( LOGO_16 ),
new Image( LOGO_32 ),
new Image( LOGO_128 ),
new Image( LOGO_256 ),
new Image( LOGO_512 ) );
stage.setTitle( getApplicationTitle() );
stage.setScene( getScene() );
}
private void initAlertService() {
final AlertService service = Services.load( AlertService.class );
service.setWindow( getScene().getWindow() );
}
private Scene getScene() {
return getMainWindow().getScene();
}
private MainWindow getMainWindow() {
return this.mainWindow;
}
private static Application getApplication() {
return app;
}
public static void showDocument( String uri ) {
getApplication().getHostServices().showDocument( uri );
}
}