Skip to content

Commit

Permalink
Many fields moved from Main to MainLoader
Browse files Browse the repository at this point in the history
The rest of the application should not know anything about Main, so Main should not have any public fields. They have been moved to the class where they are written: MainLoader.

Getter methods have been introduced in MainLoader, and the (moved) fields have been made private.

MainLoader is not likely to be the final destination of all these fields.
  • Loading branch information
HelgeStenstrom committed Jul 17, 2019
1 parent 56cfe5c commit 3283ca7
Show file tree
Hide file tree
Showing 52 changed files with 654 additions and 520 deletions.
142 changes: 3 additions & 139 deletions src/main/java/com/goxr3plus/xr3player/application/Main.java
@@ -1,57 +1,32 @@
package com.goxr3plus.xr3player.application;

import java.util.logging.Level;
import java.util.logging.Logger;

import com.goxr3plus.fxborderlessscene.borderless.BorderlessScene;
import com.goxr3plus.xr3player.controllers.chromium.WebBrowserController;
import com.goxr3plus.xr3player.controllers.djmode.DJMode;
import com.goxr3plus.xr3player.controllers.dropbox.DropboxDownloadsTableViewer;
import com.goxr3plus.xr3player.controllers.dropbox.DropboxViewer;
import com.goxr3plus.xr3player.controllers.general.BottomBar;
import com.goxr3plus.xr3player.controllers.general.EmotionsTabPane;
import com.goxr3plus.xr3player.controllers.general.MainLoadingScreen;
import com.goxr3plus.xr3player.controllers.general.OnlineMusicController;
import com.goxr3plus.xr3player.controllers.general.PlayListModesSplitPane;
import com.goxr3plus.xr3player.controllers.general.PlayListModesTabPane;
import com.goxr3plus.xr3player.controllers.general.SideBar;
import com.goxr3plus.xr3player.controllers.general.TopBar;
import com.goxr3plus.xr3player.controllers.general.WelcomeScreen;
import com.goxr3plus.xr3player.controllers.librarymode.LibraryMode;
import com.goxr3plus.xr3player.controllers.loginmode.LoginMode;
import com.goxr3plus.xr3player.controllers.loginmode.UserInformation;
import com.goxr3plus.xr3player.controllers.moviemode.MovieModeController;
import com.goxr3plus.xr3player.controllers.settings.ApplicationSettingsController;
import com.goxr3plus.xr3player.controllers.smartcontroller.DragViewer;
import com.goxr3plus.xr3player.controllers.smartcontroller.MediaContextMenu;
import com.goxr3plus.xr3player.controllers.smartcontroller.MediaInformation;
import com.goxr3plus.xr3player.controllers.smartcontroller.ShopContextMenu;
import com.goxr3plus.xr3player.controllers.smartcontroller.SmartController;
import com.goxr3plus.xr3player.controllers.systemtree.TreeViewContextMenu;
import com.goxr3plus.xr3player.controllers.systemtree.TreeViewManager;
import com.goxr3plus.xr3player.controllers.tagging.TagWindow;
import com.goxr3plus.xr3player.controllers.windows.AboutWindow;
import com.goxr3plus.xr3player.controllers.windows.ConsoleWindowController;
import com.goxr3plus.xr3player.controllers.windows.EmotionsWindow;
import com.goxr3plus.xr3player.controllers.windows.ExportWindowController;
import com.goxr3plus.xr3player.controllers.windows.FileAndFolderChooser;
import com.goxr3plus.xr3player.controllers.windows.MediaDeleteWindow;
import com.goxr3plus.xr3player.controllers.windows.MediaSearchWindow;
import com.goxr3plus.xr3player.controllers.windows.RenameWindow;
import com.goxr3plus.xr3player.controllers.windows.StarWindow;
import com.goxr3plus.xr3player.controllers.windows.UpdateWindow;
import com.goxr3plus.xr3player.controllers.xplayer.XPlayersList;
import com.goxr3plus.xr3player.database.DatabaseManager;
import com.goxr3plus.xr3player.database.DatabaseTool;
import com.goxr3plus.xr3player.database.PropertiesDb;
import com.goxr3plus.xr3player.models.lists.EmotionListsController;
import com.goxr3plus.xr3player.models.lists.PlayedMediaList;
import com.goxr3plus.xr3player.models.lists.StarredMediaList;

import javafx.application.Application;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

import java.util.logging.Level;
import java.util.logging.Logger;
//import main.java.com.goxr3plus.xr3capture.application.CaptureWindow;

/**
Expand Down Expand Up @@ -102,115 +77,9 @@ public static void main(final String[] args) {

// ------ START: The below have not dependencies on classes ------//

public static WelcomeScreen welcomeScreen;

public static MediaDeleteWindow mediaDeleteWindow;

/**
* The star window.
*/
public static StarWindow starWindow;

/**
* The rename window.
*/
public static RenameWindow renameWindow;

/**
* The rename window.
*/
public static EmotionsWindow emotionsWindow;

/**
* Audio Tagging Window
*/
public static TagWindow tagWindow;

public static MediaSearchWindow mediaSearchWindow;

/**
* This window is being used to export files from the application to the outside
* world
*/
public static ExportWindowController exportWindow;

/**
* The About Window of the Application
*/
public static AboutWindow aboutWindow;

/**
* The console Window of the Application
*/
public static ConsoleWindowController consoleWindow;

/**
* This Window contains the settings for the whole application
*/
public static ApplicationSettingsController settingsWindow;

/**
* This class is used to capture the computer Screen or a part of it [ Check
* XR3Capture package]
*/
// public static CaptureWindow captureWindow;

public static UpdateWindow updateWindow;

//

/**
* The Top Bar of the Application
*/
public static TopBar topBar;

/**
* The Bottom Bar of the Application
*/
public static BottomBar bottomBar;

/**
* The Side Bar of The Application
*/
public static SideBar sideBar;

/**
* Application Update Screen
*/
public static MainLoadingScreen updateScreen;

/**
* The TreeView of DJMode
*/
public static TreeViewManager treeManager;

public static MediaInformation mediaInformation;
//

public static TreeViewContextMenu treeViewContextMenu;

/**
* The Constant songsContextMenu.
*/
public static MediaContextMenu songsContextMenu;

/**
* The Constant songsContextMenu.
*/
public static ShopContextMenu shopContextMenu;

/**
* The Constant EmotionListsController.
*/
public static EmotionListsController emotionListsController;

//

/**
* The WebBrowser of the Application
*/
public static WebBrowserController webBrowser;

//

/**
Expand All @@ -228,11 +97,6 @@ public static void main(final String[] args) {
*/
public static PlayedMediaList playedSongs = new PlayedMediaList();

/**
* Used to provide ui for drag and view
*/
public static DragViewer dragViewer;

// ------ END: The above have not dependencies on other classes ------

// ------ START: Vary basic for the application ------
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/com/goxr3plus/xr3player/application/MainExit.java
Expand Up @@ -42,10 +42,10 @@ else if (Main.libraryMode.openedLibrariesViewer.isFree(true)) {
terminateXR3Player(0);
else {
final VacuumProgressService vService = new VacuumProgressService();
Main.updateScreen.getLabel().textProperty().bind(vService.messageProperty());
Main.updateScreen.getProgressBar().setProgress(-1);
Main.updateScreen.getProgressBar().progressProperty().bind(vService.progressProperty());
Main.updateScreen.setVisible(true);
MainLoader.getUpdateScreen().getLabel().textProperty().bind(vService.messageProperty());
MainLoader.getUpdateScreen().getProgressBar().setProgress(-1);
MainLoader.getUpdateScreen().getProgressBar().progressProperty().bind(vService.progressProperty());
MainLoader.getUpdateScreen().setVisible(true);
vService.start(new File(DatabaseTool.getUserFolderAbsolutePathWithSeparator() + "dbFile.db"),
new File(DatabaseTool.getUserFolderAbsolutePathWithSeparator() + "dbFile.db-journal"));
Main.dbManager.commitAndVacuum();
Expand Down Expand Up @@ -92,15 +92,15 @@ public static void terminateXR3Player(final int exitCode) {
case WINDOWS:
new Thread(() -> {
// Disposing all Browsers...
Main.webBrowser.disposeAllBrowsers();
MainLoader.getWebBrowser().disposeAllBrowsers();
System.exit(exitCode);
}).start();
break;
case LINUX:
case MAC:
Platform.runLater(() -> {
// Disposing all Browsers...
Main.webBrowser.disposeAllBrowsers();
MainLoader.getWebBrowser().disposeAllBrowsers();
System.exit(exitCode);
});
break;
Expand Down Expand Up @@ -170,7 +170,7 @@ public static void restartTheApplication(final boolean askUser) {
} catch (final Exception ex) {
Logger.getLogger(Main.class.getName()).log(Level.INFO, null, ex);
Platform.runLater(() -> {
Main.updateScreen.setVisible(false);
MainLoader.getUpdateScreen().setVisible(false);

// Show failed message
Platform.runLater(() -> AlertTool.showNotification("Restart seems to failed",
Expand All @@ -188,7 +188,7 @@ private static void startExitPauseTransition(final int seconds, final boolean as
// Wait 20 seconds
final PauseTransition pause = new PauseTransition(Duration.seconds(seconds));
pause.setOnFinished(f -> {
Main.updateScreen.setVisible(false);
MainLoader.getUpdateScreen().setVisible(false);

// Show failed message
if (seconds != 0 && askUser)
Expand Down
Expand Up @@ -31,7 +31,7 @@ public class MainLoadUser {
public static void loadTheUsers() {

// Set Update Screen Visible
Main.updateScreen.setVisible(true);
MainLoader.getUpdateScreen().setVisible(true);

// Create Chromium Folder
if (!IOAction.createFileOrFolder(DatabaseTool.getAbsoluteDatabaseParentFolderPathWithSeparator() + "Chromium",
Expand Down Expand Up @@ -83,16 +83,16 @@ public static void startAppWithUser(final User selectedUser) {
// Close the LoginMode
Main.loginMode.userSearchBox.getSearchBoxWindow().close();
Main.loginMode.setVisible(false);
Main.updateScreen.getProgressBar().setProgress(-1);
Main.updateScreen.getLabel().setText("Launching...");
Main.updateScreen.setVisible(true);
MainLoader.getUpdateScreen().getProgressBar().setProgress(-1);
MainLoader.getUpdateScreen().getLabel().setText("Launching...");
MainLoader.getUpdateScreen().setVisible(true);

// Prepare the BackgroundImageView
Main.loginMode.getChildren().remove(Main.loginMode.getBackgroundImageView());
Main.applicationStackPane.getChildren().add(1, Main.loginMode.getBackgroundImageView());

// SideBar
Main.sideBar.prepareForLoginMode(false);
MainLoader.getSideBar().prepareForLoginMode(false);

// Set root visible
Main.root.setVisible(true);
Expand All @@ -116,7 +116,7 @@ public static void startAppWithUser(final User selectedUser) {

// --------- Create the Menu Items of available users for Settings Window
if (Main.loginMode.viewer.getItemsObservableList().size() == 1)
Main.settingsWindow.getCopySettingsMenuButton().setDisable(true);
MainLoader.getSettingsWindow().getCopySettingsMenuButton().setDisable(true);
else
Main.loginMode.viewer.getItemsObservableList().stream()
.filter(userr -> !((User) userr).getName().equals(selectedUser.getName())).forEach(userr -> {
Expand All @@ -137,7 +137,7 @@ public static void startAppWithUser(final User selectedUser) {
// Ask the user
if (AlertTool.doQuestion("Override Settings",
"Soore you want to override your current user settings with the one that you selected from the menu ?",
Main.settingsWindow.getCopySettingsMenuButton(), Main.window))
MainLoader.getSettingsWindow().getCopySettingsMenuButton(), Main.window))

// Don't block the application due to IO Operations
new Thread(() -> {
Expand Down Expand Up @@ -169,7 +169,7 @@ public static void startAppWithUser(final User selectedUser) {
menuItem.setDisable(true);

// Finally add the Menu Item
Main.settingsWindow.getCopySettingsMenuButton().getItems().add(menuItem);
MainLoader.getSettingsWindow().getCopySettingsMenuButton().getItems().add(menuItem);
});

// ----Update the UserInformation properties file when the total libraries
Expand All @@ -179,7 +179,7 @@ public static void startAppWithUser(final User selectedUser) {
.updateProperty("Total-Libraries", String.valueOf(newValue.intValue())));

// ----Bind Label to User Name
Main.sideBar.getNameLabel().setText(Main.userInfoMode.getUserName().getText());
MainLoader.getSideBar().getNameLabel().setText(Main.userInfoMode.getUserName().getText());

// ---Store this user as last logged in user
Main.applicationProperties.updateProperty("Last-LoggedIn-User", selectedUser.getName());
Expand Down

1 comment on commit 3283ca7

@HelgeStenstrom
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code change is not good, because it doesn’t do anything about the global state that was kept in static fields in Main. They have just been moved to MainLoader, but they are still static, and they still represent global state.

Instead we should have a class with non-static members, holding the same values. There should only be one instance of this new class, and a reference to it should be kept by objects that need it. Likely, we create the single instance in Main, and pass a reference to it to the main controller class.

Please sign in to comment.