1+ // Copyright 2019 doubleSlash Net Business GmbH
2+ //
3+ // This file is part of KeepTime.
4+ // KeepTime is free software: you can redistribute it and/or modify
5+ // it under the terms of the GNU General Public License as published by
6+ // the Free Software Foundation, either version 3 of the License, or
7+ // (at your option) any later version.
8+ //
9+ // This program is distributed in the hope that it will be useful,
10+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
11+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+ // GNU General Public License for more details.
13+ //
14+ // You should have received a copy of the GNU General Public License
15+ // along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
117package de .doubleslash .keeptime ;
218
319import java .io .IOException ;
1430import org .springframework .boot .autoconfigure .SpringBootApplication ;
1531import org .springframework .context .ConfigurableApplicationContext ;
1632
33+ import de .doubleslash .keeptime .common .FontProvider ;
1734import de .doubleslash .keeptime .common .Resources ;
1835import de .doubleslash .keeptime .common .Resources .RESOURCE ;
1936import de .doubleslash .keeptime .controller .Controller ;
2239import de .doubleslash .keeptime .model .Settings ;
2340import de .doubleslash .keeptime .model .Work ;
2441import de .doubleslash .keeptime .view .ViewController ;
25- import de .doubleslash .keeptime .viewPopup .GlobalScreenListener ;
26- import de .doubleslash .keeptime .viewPopup .ViewControllerPopup ;
42+ import de .doubleslash .keeptime .viewpopup .GlobalScreenListener ;
43+ import de .doubleslash .keeptime .viewpopup .ViewControllerPopup ;
2744import javafx .application .Application ;
2845import javafx .event .EventHandler ;
2946import javafx .fxml .FXMLLoader ;
@@ -46,7 +63,7 @@ public class Main extends Application {
4663
4764 private static final Logger LOG = LoggerFactory .getLogger (Main .class );
4865
49- public static final String VERSION = "v1.0 .0" ;
66+ public static final String VERSION = "v1.1 .0" ;
5067
5168 private ConfigurableApplicationContext springContext ;
5269
@@ -75,7 +92,7 @@ public void init() throws Exception {
7592 public void start (final Stage primaryStage ) {
7693 LOG .info ("Initialising the UI" );
7794 try {
78- initUI (primaryStage );
95+ initialiseApplication (primaryStage );
7996 LOG .info ("UI successfully initialised." );
8097 } catch (final Exception e ) {
8198 LOG .error ("There was an error while initialising the UI" , e );
@@ -112,35 +129,35 @@ public void start(final Stage primaryStage) {
112129 }
113130 }
114131
115- private void initUI (final Stage primaryStage ) throws Exception {
116-
132+ private void initialiseApplication (final Stage primaryStage ) throws Exception {
133+ FontProvider . loadFonts ();
117134 readSettings ();
118135
119- final List <Work > todaysWorkItems = model .workRepository .findByCreationDate (LocalDate .now ());
136+ final List <Work > todaysWorkItems = model .getWorkRepository () .findByCreationDate (LocalDate .now ());
120137 LOG .info ("Found {} past work items" , todaysWorkItems .size ());
121- model .pastWorkItems .addAll (todaysWorkItems );
138+ model .getPastWorkItems () .addAll (todaysWorkItems );
122139
123- final List <Project > projects = model .projectRepository .findAll ();
140+ final List <Project > projects = model .getProjectRepository () .findAll ();
124141
125142 LOG .debug ("Found '{}' projects" , projects .size ());
126143 if (projects .isEmpty ()) {
127144 LOG .info ("Adding default project" );
128- projects .add (model .DEFAULT_PROJECT );
129- model .projectRepository .save (model .DEFAULT_PROJECT );
145+ projects .add (Model .DEFAULT_PROJECT );
146+ model .getProjectRepository () .save (Model .DEFAULT_PROJECT );
130147 }
131148
132- model .allProjects .addAll (projects );
133- model .availableProjects
134- .addAll (model .allProjects .stream ().filter (Project ::isEnabled ).collect (Collectors .toList ()));
149+ model .getAllProjects () .addAll (projects );
150+ model .getAvailableProjects ()
151+ .addAll (model .getAllProjects () .stream ().filter (Project ::isEnabled ).collect (Collectors .toList ()));
135152
136153 // set default project
137154 final Optional <Project > findAny = projects .stream ().filter (Project ::isDefault ).findAny ();
138155 if (findAny .isPresent ()) {
139- model .idleProject = findAny .get ();
140- LOG .debug ("Using project '{}' as default project." , model .idleProject );
156+ model .setIdleProject ( findAny .get () );
157+ LOG .debug ("Using project '{}' as default project." , model .getIdleProject () );
141158 }
142159
143- primaryStage .setOnHiding (( we ) -> {
160+ primaryStage .setOnHiding (we -> {
144161 popupViewStage .close ();
145162 globalScreenListener .shutdown (); // deregister, as this will keep app running
146163 });
@@ -152,21 +169,21 @@ private void initUI(final Stage primaryStage) throws Exception {
152169 private void readSettings () {
153170 LOG .debug ("Reading configuration" );
154171
155- final List <Settings > settingsList = model .settingsRepository .findAll ();
172+ final List <Settings > settingsList = model .getSettingsRepository () .findAll ();
156173 final Settings settings ;
157174 if (settingsList .isEmpty ()) {
158175 settings = new Settings ();
159176 settings .setTaskBarColor (model .taskBarColor .get ());
160177
161- settings .setDefaultBackgroundColor (model . defaultBackgroundColor . get () );
162- settings .setDefaultFontColor (model . defaultFontColor . get () );
178+ settings .setDefaultBackgroundColor (Model . ORIGINAL_DEFAULT_BACKGROUND_COLOR );
179+ settings .setDefaultFontColor (Model . ORIGINAL_DEFAULT_FONT_COLOR );
163180
164- settings .setHoverBackgroundColor (model . hoverBackgroundColor . get () );
165- settings .setHoverFontColor (model . hoverFontColor . get () );
181+ settings .setHoverBackgroundColor (Model . ORIGINAL_HOVER_BACKGROUND_COLOR );
182+ settings .setHoverFontColor (Model . ORIGINAL_HOVER_Font_COLOR );
166183 settings .setUseHotkey (false );
167184 settings .setDisplayProjectsRight (false );
168- settings .setHideProjectsOnMouseExit (true );
169- model .settingsRepository .save (settings );
185+ settings .setHideProjectsOnMouseExit (false );
186+ model .getSettingsRepository () .save (settings );
170187 } else {
171188 settings = settingsList .get (0 );
172189 }
@@ -185,10 +202,8 @@ private void initialisePopupUI(final Stage primaryStage) throws IOException {
185202 LOG .debug ("Initialising popup UI." );
186203
187204 globalScreenListener = new GlobalScreenListener ();
188- // stop and close stage when main stage is shutdown
189- model .useHotkey .addListener ((a , b , newValue ) -> {
190- globalScreenListener .register (newValue );
191- });
205+
206+ model .useHotkey .addListener ((a , b , newValue ) -> globalScreenListener .register (newValue ));
192207 globalScreenListener .register (model .useHotkey .get ());
193208
194209 popupViewStage = new Stage ();
@@ -206,8 +221,8 @@ private void initialisePopupUI(final Stage primaryStage) throws IOException {
206221 // Give the controller access to the main app.
207222 popupViewStage .setAlwaysOnTop (true );
208223 final ViewControllerPopup viewControllerPopupController = loader .getController ();
209- viewControllerPopupController .setStage (popupViewStage , popupScene );
210- viewControllerPopupController .setController (controller , model );
224+ viewControllerPopupController .setStage (popupViewStage );
225+ viewControllerPopupController .setControllerAndModel (controller , model );
211226 globalScreenListener .setViewController (viewControllerPopupController );
212227 }
213228
@@ -237,13 +252,12 @@ public void handle(final WindowEvent event) {
237252 LOG .info ("On close request" );
238253 }
239254 });
240-
255+ primaryStage . show ();
241256 viewController = loader .getController ();
242257 // Give the controller access to the main app.
243258 viewController .setStage (primaryStage );
244259 viewController .setController (controller , model );
245260
246- primaryStage .show ();
247261 }
248262
249263 @ Override
0 commit comments