1 /*
2 * *************************************************************************************************************************************************************
3 *
4 * SteelBlue: DCI User Interfaces
5 * http://tidalwave.it/projects/steelblue
6 *
7 * Copyright (C) 2015 - 2024 by Tidalwave s.a.s. (http://tidalwave.it)
8 *
9 * *************************************************************************************************************************************************************
10 *
11 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
13 *
14 * http://www.apache.org/licenses/LICENSE-2.0
15 *
16 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
17 * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
18 *
19 * *************************************************************************************************************************************************************
20 *
21 * git clone https://bitbucket.org/tidalwave/steelblue-src
22 * git clone https://github.com/tidalwave-it/steelblue-src
23 *
24 * *************************************************************************************************************************************************************
25 */
26 package it.tidalwave.ui.javafx;
27
28 import javax.annotation.Nonnull;
29 import org.springframework.context.ConfigurableApplicationContext;
30 import org.springframework.context.annotation.AnnotationConfigApplicationContext;
31 import org.springframework.context.annotation.Bean;
32 import org.springframework.context.annotation.Configuration;
33 import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
36 import it.tidalwave.util.PreferencesHandler;
37 import it.tidalwave.role.impl.DefaultContextManager;
38 import it.tidalwave.role.spring.spi.AnnotationSpringSystemRoleFactory;
39 import it.tidalwave.role.ui.javafx.StackPaneSelector;
40
41 /***************************************************************************************************************************************************************
42 *
43 * A base class for JavaFX applications with use Spring annotation scanning.
44 *
45 * @author Fabrizio Giudici
46 * @since 1.1-ALPHA-4
47 *
48 **************************************************************************************************************************************************************/
49 @Configuration
50 public class JavaFXSpringAnnotationApplication extends AbstractJavaFXSpringApplication
51 {
52 // Don't use Slf4j and its static logger - give Main a chance to initialize things
53 private final Logger log = LoggerFactory.getLogger(JavaFXSpringApplication.class);
54
55 @Override @Nonnull
56 protected ConfigurableApplicationContext createApplicationContext()
57 {
58 final var mainClass = getClass();
59 log.info("Scanning beans from {}", mainClass);
60 return new AnnotationConfigApplicationContext(mainClass);
61 }
62
63 @Bean(name = "javafxBinderExecutor")
64 public ThreadPoolTaskExecutor getJavaFXSafeProxyCreator()
65 {
66 return JavaFXSafeProxyCreator.getExecutor();
67 }
68
69 @Bean(name = "stackPaneSelector")
70 public StackPaneSelector getStackPaneSelector()
71 {
72 return new StackPaneSelector();
73 }
74
75 @Bean(name = "preferencesHandler")
76 public PreferencesHandler getPreferencesHandler()
77 {
78 return PreferencesHandler.getInstance();
79 }
80
81 @Bean(name = "roleManager")
82 public AnnotationSpringSystemRoleFactory getAnnotationSpringSystemRoleFactory()
83 {
84 return new AnnotationSpringSystemRoleFactory();
85 }
86
87 @Bean(name = "contextManager")
88 public DefaultContextManager getDefaultContextManager()
89 {
90 return new DefaultContextManager();
91 }
92 }