From 9b7a85cabec2bcfbb4edccbd72ec3ca487879323 Mon Sep 17 00:00:00 2001 From: Jannik Date: Tue, 12 Jun 2018 16:24:12 +0200 Subject: [PATCH] code clean up --- .../java/com/cemu_UI/application/Main.java | 104 ++++++++---------- .../application/MainWindowController.java | 86 +++++---------- src/main/resources/fxml/MainWindow.fxml | 2 +- 3 files changed, 72 insertions(+), 120 deletions(-) diff --git a/src/main/java/com/cemu_UI/application/Main.java b/src/main/java/com/cemu_UI/application/Main.java index 6879180..7d922e3 100644 --- a/src/main/java/com/cemu_UI/application/Main.java +++ b/src/main/java/com/cemu_UI/application/Main.java @@ -47,7 +47,6 @@ import javafx.scene.control.ButtonType; import javafx.scene.control.Alert.AlertType; import javafx.scene.layout.AnchorPane; - public class Main extends Application { private Stage primaryStage; @@ -63,13 +62,12 @@ public class Main extends Application { private static String javaVers = System.getProperty("java.version"); private static String javaVend= System.getProperty("java.vendor"); private String gamesDBdownloadURL = "https://github.com/Seil0/cemu_UI/raw/master/downloadContent/games.db"; - public String dirWin = userHome + "/Documents/cemu_UI"; // Windows: C:/Users/"User"/Documents/cemu_UI - public String dirLinux = userHome + "/cemu_UI"; // Linux: /home/"User"/cemu_UI - private File directory; - private File configFile; - private File gamesDBFile; - private File reference_gamesFile; - private File pictureCache; + private static String dirCemuUI; + private static File directory; + private static File configFile; + private static File gamesDBFile; + private static File reference_gamesFile; + private static File pictureCache; private static Logger LOGGER; @Override @@ -78,7 +76,10 @@ public class Main extends Application { LOGGER.info("OS: " + osName + " " + osVers + " " + osArch); LOGGER.info("Java: " + javaVend + " " + javaVers); LOGGER.info("User: " + userName + " " + userHome); + this.primaryStage = primaryStage; + mainWindowController = new MainWindowController(this); + mainWindow(); initActions(); } catch (Exception e) { @@ -91,28 +92,21 @@ public class Main extends Application { try { FXMLLoader loader = new FXMLLoader(); loader.setLocation(ClassLoader.getSystemResource("fxml/MainWindow.fxml")); + loader.setController(mainWindowController); pane = (AnchorPane) loader.load(); + primaryStage.setMinWidth(265.00); + primaryStage.setMinHeight(425.00); primaryStage.setTitle("cemu_UI"); -// primaryStage.getIcons().add(new Image(Main.class.getResourceAsStream("/resources/Homeflix_Icon_64x64.png"))); //adds application icon - - mainWindowController = loader.getController(); // Link of FXMLController and controller class - mainWindowController.setMain(this); // call setMain - cloudController = new CloudController(mainWindowController); // call cloudController constructor +// primaryStage.getIcons().add(new Image(Main.class.getResourceAsStream(""))); //adds application icon + primaryStage.setOnCloseRequest(event -> System.exit(1)); - // get OS and the specific paths - if (osName.equals("Linux")) { - directory = new File(dirLinux); - configFile = new File(dirLinux + "/config.xml"); - gamesDBFile = new File(dirLinux + "/games.db"); - reference_gamesFile = new File(dirLinux + "/reference_games.db"); - pictureCache= new File(dirLinux+"/picture_cache"); - } else { - directory = new File(dirWin); - configFile = new File(dirWin + "/config.xml"); - gamesDBFile = new File(dirWin + "/games.db"); - reference_gamesFile = new File(dirWin + "/reference_games.db"); - pictureCache= new File(dirWin+"/picture_cache"); - } + // generate window + scene = new Scene(pane); // create new scene, append pane to scene + scene.getStylesheets().add(Main.class.getResource("/css/MainWindows.css").toExternalForm()); + primaryStage.setScene(scene); // append scene to stage + primaryStage.show(); // show stage + + cloudController = new CloudController(mainWindowController); // call cloudController constructor // startup checks // check if client_secret.json is present @@ -165,14 +159,6 @@ public class Main extends Application { } } - // generate window - scene = new Scene(pane); // create new scene, append pane to scene - scene.getStylesheets().add(Main.class.getResource("/css/MainWindows.css").toExternalForm()); - primaryStage.setMinWidth(265.00); - primaryStage.setMinHeight(425.00); - primaryStage.setScene(scene); // append scene to stage - primaryStage.show(); // show stage - // init here as it loads the games to the mwc and the gui, therefore the window must exist mainWindowController.init(); mainWindowController.getDbController().init(); @@ -183,9 +169,31 @@ public class Main extends Application { cloudController.sync(mainWindowController.getCloudService(), mainWindowController.getCemuPath(), directory.getPath()); } - } catch (IOException e) { - e.printStackTrace(); - } + } catch (IOException e) { + e.printStackTrace(); + } + } + + public static void main(String[] args) { + + if (osName.contains("Windows")) { + dirCemuUI = userHome + "/Documents/cemu_UI"; + } else { + dirCemuUI = userHome + "/cemu_UI"; + } + + directory = new File(dirCemuUI); + configFile = new File(dirCemuUI + "/config.xml"); + gamesDBFile = new File(dirCemuUI + "/games.db"); + reference_gamesFile = new File(dirCemuUI + "/reference_games.db"); + pictureCache= new File(dirCemuUI+"/picture_cache"); + + // delete old log file and create new + System.setProperty("logFilename", dirCemuUI + "/app.log"); + File logFile = new File(dirCemuUI + "/app.log"); + logFile.delete(); + LOGGER = LogManager.getLogger(Main.class.getName()); + launch(args); } private void firstStart() { @@ -291,26 +299,6 @@ public class Main extends Application { primaryStage.heightProperty().addListener(heightListener); primaryStage.maximizedProperty().addListener(maximizeListener); } - - public static void main(String[] args) { - // delete old log file and create new - if (osName.equals("Linux")) { - System.setProperty("logFilename", userHome + "/cemu_UI/app.log"); - File logFile = new File(userHome + "/cemu_UI/app.log"); - logFile.delete(); - } else { - System.setProperty("logFilename", userHome + "/Documents/cemu_UI/app.log"); - File logFile = new File(userHome + "/Documents/cemu_UI/app.log"); - logFile.delete(); - } - LOGGER = LogManager.getLogger(Main.class.getName()); - launch(args); - } - - @Override - public void stop() { - System.exit(0); - } public Stage getPrimaryStage() { return primaryStage; diff --git a/src/main/java/com/cemu_UI/application/MainWindowController.java b/src/main/java/com/cemu_UI/application/MainWindowController.java index a675138..b7490c9 100644 --- a/src/main/java/com/cemu_UI/application/MainWindowController.java +++ b/src/main/java/com/cemu_UI/application/MainWindowController.java @@ -111,37 +111,26 @@ public class MainWindowController { @FXML private JFXButton aboutBtn; - @FXML private JFXButton settingsBtn; - @FXML private JFXButton addBtn; - @FXML private JFXButton reloadRomsBtn; - @FXML private JFXButton smmdbBtn; - @FXML private JFXButton cemuTFBtn; - @FXML private JFXButton romTFBtn; - @FXML private JFXButton updateBtn; - @FXML private JFXButton smmdbDownloadBtn; - @FXML private JFXButton playBtn; - @FXML private JFXButton lastTimePlayedBtn; - @FXML JFXButton totalPlaytimeBtn; @@ -150,58 +139,46 @@ public class MainWindowController { @FXML private JFXTextField cemuTextField; - @FXML private JFXTextField romTextField; - @FXML private JFXTextField courseSearchTextFiled; - @FXML private JFXTextField executeCommandTextFiled; - + @FXML private TextFlow smmdbTextFlow; - + @FXML private JFXColorPicker colorPicker; - + @FXML private JFXToggleButton cloudSyncToggleBtn; - @FXML private JFXToggleButton autoUpdateToggleBtn; - @FXML private JFXToggleButton fullscreenToggleBtn; @FXML private ChoiceBox languageChoisBox; - @FXML private ChoiceBox branchChoisBox; @FXML private AnchorPane mainAnchorPane; - @FXML private AnchorPane gamesAnchorPane; - @FXML private AnchorPane settingsAnchorPane; - @FXML private AnchorPane smmdbAnchorPane; @FXML private ScrollPane mainScrollPane; - @FXML private ScrollPane settingsScrollPane; - @FXML private ScrollPane smmdbScrollPane; - @FXML private ScrollPane smmdbImageViewScrollPane; @@ -210,7 +187,6 @@ public class MainWindowController { @FXML private HBox topHBox; - @FXML private HBox bottomHBox; @@ -219,31 +195,22 @@ public class MainWindowController { @FXML private Label helpLbl; - @FXML private Label cemu_UISettingsLbl; - @FXML private Label cemuDirectoryLbl; - @FXML private Label romDirectoryLbl; - @FXML private Label mainColorLbl; - @FXML private Label languageLbl; - @FXML private Label updateLbl; - @FXML private Label branchLbl; - @FXML private Label cemuSettingsLbl; - @FXML private Label licensesLbl; @@ -251,17 +218,14 @@ public class MainWindowController { private JFXTreeTableView courseTreeTable = new JFXTreeTableView(); @FXML - TreeItem root = new TreeItem<>(new CourseTableDataType("", "", 0, 0)); + private TreeItem root = new TreeItem<>(new CourseTableDataType("", "", 0, 0)); @FXML private JFXTreeTableColumn titleColumn = new JFXTreeTableColumn<>("title"); - @FXML private JFXTreeTableColumn idColumn = new JFXTreeTableColumn<>("id"); - @FXML private JFXTreeTableColumn starsColumn = new JFXTreeTableColumn<>("stars"); - @FXML private JFXTreeTableColumn timeColumn = new JFXTreeTableColumn<>("time"); @@ -294,7 +258,7 @@ public class MainWindowController { private String selectedGameTitle; private String id; private String version = "0.3.0"; - private String buildNumber = "077"; + private String buildNumber = "079"; private String versionName = "Purple Comet"; private int xPos = -200; private int yPos = 17; @@ -372,8 +336,8 @@ public class MainWindowController { private String smmdbDownloadBtnLoading; private String smmdbDownloadBtnDownload; - public void setMain(Main m) { - this.main = m; + public MainWindowController(Main main) { + this.main = main; dbController = new DBController(main, this); smmdbAPIController = new SmmdbAPIController(); } @@ -382,7 +346,7 @@ public class MainWindowController { * initialize the MainWindowController * loadSettings, checkAutoUpdate, initUI and initActions */ - void init() { + public void init() { loadSettings(); checkAutoUpdate(); initUI(); @@ -837,7 +801,7 @@ public class MainWindowController { } @FXML - void detailsSlideoutBtnAction() { + private void detailsSlideoutBtnAction() { playBtnSlideOut(); } @@ -851,7 +815,7 @@ public class MainWindowController { } @FXML - void settingsBtnAction() { + private void settingsBtnAction() { if (smmdbTrue) { smmdbAnchorPane.setVisible(false); smmdbTrue = false; @@ -867,12 +831,12 @@ public class MainWindowController { } @FXML - void reloadRomsBtnAction() throws IOException { + private void reloadRomsBtnAction() throws IOException { reloadRoms(); } @FXML - void smmdbBtnAction() { + private void smmdbBtnAction() { // show smmdbAnchorPane if (smmdbTrue) { smmdbAnchorPane.setVisible(false); @@ -911,7 +875,7 @@ public class MainWindowController { } @FXML - void playBtnAction() throws InterruptedException, IOException { + private void playBtnAction() throws InterruptedException, IOException { dbController.setLastPlayed(selectedGameTitleID); playGame = new playGame(this, dbController); @@ -919,17 +883,17 @@ public class MainWindowController { } @FXML - void totalPlaytimeBtnAction() { + private void totalPlaytimeBtnAction() { } @FXML - void lastTimePlayedBtnAction() { + private void lastTimePlayedBtnAction() { } @FXML - void cemuTFBtnAction() { + private void cemuTFBtnAction() { File cemuDirectory = directoryChooser.showDialog(main.getPrimaryStage()); if (cemuDirectory != null) { cemuTextField.setText(cemuDirectory.getAbsolutePath()); @@ -937,7 +901,7 @@ public class MainWindowController { } @FXML - void romTFBtnAction() { + private void romTFBtnAction() { File romDirectory = directoryChooser.showDialog(main.getPrimaryStage()); if (romDirectory != null) { romTextField.setText(romDirectory.getAbsolutePath()); @@ -945,7 +909,7 @@ public class MainWindowController { } @FXML - void updateBtnAction() { + private void updateBtnAction() { updateController = new UpdateController(this, buildNumber, useBeta); Thread updateThread = new Thread(updateController); updateThread.setName("Updater"); @@ -953,7 +917,7 @@ public class MainWindowController { } @FXML - void autoUpdateToggleBtnAction() { + private void autoUpdateToggleBtnAction() { if (isAutoUpdate()) { setAutoUpdate(false); } else { @@ -963,12 +927,12 @@ public class MainWindowController { } @FXML - void courseSearchTextFiledAction() { + private void courseSearchTextFiledAction() { // not in use } @FXML - void smmdbDownloadBtnAction() { + private void smmdbDownloadBtnAction() { String downloadUrl = "http://smmdb.ddns.net/api/downloadcourse?id=" + id + "&type=zip"; String downloadFileURL = getCemuPath() + "/" + id + ".zip"; // getCemuPath() + "/" + smmID + "/" + id + ".rar" String outputFile = getCemuPath() + "/"; @@ -1036,7 +1000,7 @@ public class MainWindowController { } @FXML - void fullscreenToggleBtnAction() { + private void fullscreenToggleBtnAction() { if (fullscreen) { fullscreen = false; } else { @@ -1046,7 +1010,7 @@ public class MainWindowController { } @FXML - void cloudSyncToggleBtnAction() { + private void cloudSyncToggleBtnAction() { if(cloudSync) { cloudSync = false; } else { @@ -1096,13 +1060,13 @@ public class MainWindowController { } @FXML - void colorPickerAction() { + private void colorPickerAction() { editColor(colorPicker.getValue().toString()); applyColor(); } @FXML - void addBtnAction() { + private void addBtnAction() { String headingText = addGameBtnHeadingText; String bodyText = addGameBtnBodyText; JFXEditGameDialog addGameDialog = new JFXEditGameDialog(headingText, bodyText, dialogBtnStyle, 450, 300, 0, diff --git a/src/main/resources/fxml/MainWindow.fxml b/src/main/resources/fxml/MainWindow.fxml index c9dde2c..d7ed28e 100644 --- a/src/main/resources/fxml/MainWindow.fxml +++ b/src/main/resources/fxml/MainWindow.fxml @@ -18,7 +18,7 @@ - +