From 391ef59f70bfb5cb584e73aea300da082f276730 Mon Sep 17 00:00:00 2001 From: Jannik Date: Sat, 28 Apr 2018 18:02:02 +0200 Subject: [PATCH] code cleanup --- pom.xml | 1 + .../HomeFlix/application/Main.java | 49 ++--- .../application/MainWindowController.java | 184 ++++++++---------- .../locals/HomeFlix-Local_de_DE.properties | 7 - .../locals/HomeFlix-Local_en_US.properties | 7 - 5 files changed, 101 insertions(+), 147 deletions(-) diff --git a/pom.xml b/pom.xml index 95f22a2..2887ba2 100644 --- a/pom.xml +++ b/pom.xml @@ -80,6 +80,7 @@ maven-shade-plugin 3.1.1 + Project-HomeFlix true diff --git a/src/main/java/kellerkinder/HomeFlix/application/Main.java b/src/main/java/kellerkinder/HomeFlix/application/Main.java index d9012c4..588952e 100644 --- a/src/main/java/kellerkinder/HomeFlix/application/Main.java +++ b/src/main/java/kellerkinder/HomeFlix/application/Main.java @@ -40,7 +40,6 @@ import javafx.scene.layout.AnchorPane; import javafx.stage.DirectoryChooser; import javafx.stage.FileChooser; import javafx.stage.Stage; -import javafx.stage.WindowEvent; public class Main extends Application { @@ -56,8 +55,7 @@ public class Main extends Application { private static String javaVers = System.getProperty("java.version"); private static String javaVend = System.getProperty("java.vendor"); private static String local = System.getProperty("user.language") + "_" + System.getProperty("user.country"); - private String dirWin = userHome + "/Documents/HomeFlix"; // Windows: C:/Users/"User"/Documents/HomeFlix - private String dirLinux = userHome + "/HomeFlix"; // Linux: /home/"User"/HomeFlix + private static String dirHomeFlix; private File directory; private File configFile; private File posterCache; @@ -88,26 +86,14 @@ public class Main extends Application { primaryStage.setResizable(false); primaryStage.setTitle("Project HomeFlix"); primaryStage.getIcons().add(new Image(Main.class.getResourceAsStream("/icons/Homeflix_Icon_64x64.png"))); //adds application icon - primaryStage.setOnCloseRequest(new EventHandler() { - public void handle(WindowEvent we) { - System.exit(1); - } - }); + primaryStage.setOnCloseRequest(event -> System.exit(1)); mainWindowController = loader.getController(); //Link of FXMLController and controller class mainWindowController.setMain(this); //call setMain - - // get OS and the specific paths - if (osName.contains("Windows")) { - directory = new File(dirWin); - configFile = new File(dirWin + "/config.xml"); - posterCache = new File(dirWin + "/posterCache"); - } else { - directory = new File(dirLinux); - configFile = new File(dirLinux + "/config.xml"); - posterCache = new File(dirLinux + "/posterCache"); - } + directory = new File(dirHomeFlix); + configFile = new File(dirHomeFlix + "/config.xml"); + posterCache = new File(dirHomeFlix + "/posterCache"); // generate window scene = new Scene(pane); // create new scene, append pane to scene @@ -117,7 +103,8 @@ public class Main extends Application { // startup checks if (!configFile.exists()) { - directory.mkdir(); + directory.mkdir(); + addFirstSource(); mainWindowController.setColor("ee3523"); mainWindowController.setFontSize(17.0); @@ -130,7 +117,7 @@ public class Main extends Application { posterCache.mkdir(); } - // init here as it loads the games to the mwc and the gui, therefore the window must exist + // initialize here as it loads the games to the mwc and the GUI, therefore the window must exist mainWindowController.init(); mainWindowController.getDbController().init(); } catch (IOException e) { @@ -148,7 +135,7 @@ public class Main extends Application { bundle = ResourceBundle.getBundle("locals.HomeFlix-Local", Locale.US); // us_english break; case "de_DE": - bundle = ResourceBundle.getBundle("locals.HomeFlix-Local", Locale.GERMAN); // German + bundle = ResourceBundle.getBundle("locals.HomeFlix-Local", Locale.GERMAN); // de_german break; default: bundle = ResourceBundle.getBundle("locals.HomeFlix-Local", Locale.US); // default local @@ -200,20 +187,20 @@ public class Main extends Application { } /** - * set the log file location and initialize the logger - * launch the GUI + * set the log file location and initialize the logger launch the GUI * @param args arguments given at the start */ public static void main(String[] args) { - if (System.getProperty("os.name").equals("Windows")) { - System.setProperty("logFilename", userHome + "/Documents/HomeFlix/app.log"); - File logFile = new File(userHome + "/Documents/HomeFlix/app.log"); - logFile.delete(); + + if (osName.contains("Windows")) { + dirHomeFlix = userHome + "/Documents/HomeFlix"; } else { - System.setProperty("logFilename", userHome + "/HomeFlix/app.log"); - File logFile = new File(userHome + "/HomeFlix/app.log"); - logFile.delete(); + dirHomeFlix = userHome + "/HomeFlix"; } + + System.setProperty("logFilename", dirHomeFlix + "/app.log"); + File logFile = new File(dirHomeFlix + "/app.log"); + logFile.delete(); LOGGER = LogManager.getLogger(Main.class.getName()); launch(args); } diff --git a/src/main/java/kellerkinder/HomeFlix/application/MainWindowController.java b/src/main/java/kellerkinder/HomeFlix/application/MainWindowController.java index fa8cba6..7945689 100644 --- a/src/main/java/kellerkinder/HomeFlix/application/MainWindowController.java +++ b/src/main/java/kellerkinder/HomeFlix/application/MainWindowController.java @@ -200,30 +200,30 @@ public class MainWindowController { private TableColumn sourceColumn; @FXML private TableColumn modeColumn; - + + private Main main; + private MainWindowController mainWindowController; + private UpdateController updateController; + private OMDbAPIController omdbAPIController; + private DBController dbController; + private static final Logger LOGGER = LogManager.getLogger(MainWindowController.class.getName()); + private boolean menuTrue = false; private boolean settingsTrue = false; private boolean autoUpdate = false; private boolean useBeta = false; private boolean autoplay = false; - private static final Logger LOGGER = LogManager.getLogger(MainWindowController.class.getName()); - private int hashA = -647380320; private final String version = "0.7.0"; private final String buildNumber = "151"; private final String versionName = "toothless dragon"; - private String dialogBtnStyle; + private String btnStyle; private String color; private String local; private String omdbAPIKey; - // text strings - private String errorLoad; - private String errorSave; - private String infoText; - private String vlcNotInstalled; - private double fontSize; + private final int hashA = -647380320; private int last; private int indexTable; private int indexList; @@ -247,12 +247,6 @@ public class MainWindowController { private ContextMenu menu = new ContextMenu(like, dislike); private Properties props = new Properties(); - private Main main; - private MainWindowController mainWindowController; - private UpdateController updateController; - private OMDbAPIController omdbAPIController; - private DBController dbController; - /** * "Main" Method called in Main.java main() when starting * Initialize other objects: Updater, dbController and ApiQuery @@ -274,6 +268,28 @@ public class MainWindowController { initActions(); } + // Initialize UI elements + private void initUI() { + versionLbl.setText("Version: " + version + " (Build: " + buildNumber + ")"); + fontsizeSlider.setValue(getFontSize()); + colorPicker.setValue(Color.valueOf(getColor())); + + updateBtn.setFont(Font.font("System", 12)); + autoUpdateToggleBtn.setSelected(isAutoUpdate()); + autoplayToggleBtn.setSelected(isAutoplay()); + languageChoisBox.setItems(languages); + branchChoisBox.setItems(branches); + + if (isUseBeta()) { + branchChoisBox.getSelectionModel().select(1); + } else { + branchChoisBox.getSelectionModel().select(0); + } + + setLocalUI(); + applyColor(); + } + // Initialize the tables (treeTableViewfilm and sourcesTable) private void initTabel() { @@ -402,7 +418,7 @@ public class MainWindowController { public void handle(ActionEvent event) { dbController.like(getCurrentStreamUrl()); dbController.refresh(getCurrentStreamUrl(), indexList); - refreshTable(); + refreshTableElement(); } }); @@ -411,7 +427,7 @@ public class MainWindowController { public void handle(ActionEvent event) { dbController.dislike(getCurrentStreamUrl()); dbController.refresh(getCurrentStreamUrl(), indexList); - refreshTable(); + refreshTableElement(); } }); @@ -479,28 +495,6 @@ public class MainWindowController { }); } - // initialize UI elements - private void initUI() { - versionLbl.setText("Version: " + version + " (Build: " + buildNumber + ")"); - fontsizeSlider.setValue(getFontSize()); - colorPicker.setValue(Color.valueOf(getColor())); - - updateBtn.setFont(Font.font("System", 12)); - autoUpdateToggleBtn.setSelected(isAutoUpdate()); - autoplayToggleBtn.setSelected(isAutoplay()); - languageChoisBox.setItems(languages); - branchChoisBox.setItems(branches); - - if (isUseBeta()) { - branchChoisBox.getSelectionModel().select(1); - } else { - branchChoisBox.getSelectionModel().select(0); - } - - setLocalUI(); - applyColor(); - } - @FXML private void playbtnclicked() { if (currentTableFilm.getStreamUrl().contains("_rootNode")) { @@ -528,7 +522,7 @@ public class MainWindowController { e1.printStackTrace(); } if (output.contains("which: no vlc") || output == "") { - JFXInfoAlert vlcInfoAlert = new JFXInfoAlert("Info", vlcNotInstalled, dialogBtnStyle, main.getPrimaryStage()); + JFXInfoAlert vlcInfoAlert = new JFXInfoAlert("Info", getBundle().getString("vlcNotInstalled"), btnStyle, main.getPrimaryStage()); vlcInfoAlert.showAndWait(); } else { try { @@ -575,8 +569,8 @@ public class MainWindowController { @FXML private void aboutBtnAction() { String bodyText = "cemu_UI by @Seil0 \nVersion: " + version + " (Build: " + buildNumber + ") \"" - + versionName + "\" \n" + infoText; - JFXInfoAlert infoAlert = new JFXInfoAlert("Project HomeFlix", bodyText, dialogBtnStyle, main.getPrimaryStage()); + + versionName + "\" \n" + getBundle().getString("infoText"); + JFXInfoAlert infoAlert = new JFXInfoAlert("Project HomeFlix", bodyText, btnStyle, main.getPrimaryStage()); infoAlert.showAndWait(); } @@ -634,26 +628,18 @@ public class MainWindowController { @FXML private void autoUpdateToggleBtnAction(){ - if (isAutoUpdate()) { - setAutoUpdate(false); - } else { - setAutoUpdate(true); - } + autoUpdate = isAutoUpdate() ? false : true; saveSettings(); } @FXML private void autoplayToggleBtnAction(){ - if (isAutoplay()) { - setAutoplay(false); - } else { - setAutoplay(true); - } + autoplay = isAutoplay() ? false : true; saveSettings(); } // refresh the selected child of the root node - private void refreshTable() { + private void refreshTableElement() { filmRoot.getChildren().get(indexTable).setValue(filmsList.get(indexList)); } @@ -726,27 +712,15 @@ public class MainWindowController { * if usedColor is less than checkColor set text fill white, else black */ private void applyColor() { - String style = "-fx-background-color: #" + getColor() + ";"; + String menuBtnStyle; String btnStyleBlack = "-fx-button-type: RAISED; -fx-background-color: #" + getColor() + "; -fx-text-fill: BLACK;"; String btnStyleWhite = "-fx-button-type: RAISED; -fx-background-color: #" + getColor() + "; -fx-text-fill: WHITE;"; BigInteger usedColor = new BigInteger(getColor(), 16); BigInteger checkColor = new BigInteger("78909cff", 16); - sideMenuVBox.setStyle(style); - topHBox.setStyle(style); - searchTextField.setFocusColor(Color.valueOf(getColor())); - if (usedColor.compareTo(checkColor) == -1) { - dialogBtnStyle = btnStyleWhite; - settingsBtn.setStyle("-fx-text-fill: WHITE;"); - aboutBtn.setStyle("-fx-text-fill: WHITE;"); - addDirectoryBtn.setStyle(btnStyleWhite); - addStreamSourceBtn.setStyle(btnStyleWhite); - updateBtn.setStyle(btnStyleWhite); - playbtn.setStyle(btnStyleWhite); - openfolderbtn.setStyle(btnStyleWhite); - returnBtn.setStyle(btnStyleWhite); - forwardBtn.setStyle(btnStyleWhite); + btnStyle = btnStyleWhite; + menuBtnStyle = "-fx-text-fill: WHITE;"; playbtn.setGraphic(play_arrow_white); returnBtn.setGraphic(skip_previous_white); @@ -755,16 +729,8 @@ public class MainWindowController { menuHam.getStyleClass().clear(); menuHam.getStyleClass().add("jfx-hamburgerW"); } else { - dialogBtnStyle = btnStyleBlack; - settingsBtn.setStyle("-fx-text-fill: BLACK;"); - aboutBtn.setStyle("-fx-text-fill: BLACK;"); - addDirectoryBtn.setStyle(btnStyleBlack); - addStreamSourceBtn.setStyle(btnStyleBlack); - updateBtn.setStyle(btnStyleBlack); - playbtn.setStyle(btnStyleBlack); - openfolderbtn.setStyle(btnStyleBlack); - returnBtn.setStyle(btnStyleBlack); - forwardBtn.setStyle(btnStyleBlack); + btnStyle = btnStyleBlack; + menuBtnStyle = "-fx-text-fill: BLACK;"; playbtn.setGraphic(play_arrow_black); returnBtn.setGraphic(skip_previous_black); @@ -773,6 +739,24 @@ public class MainWindowController { menuHam.getStyleClass().clear(); menuHam.getStyleClass().add("jfx-hamburgerB"); } + + // boxes and TextFields + sideMenuVBox.setStyle("-fx-background-color: #" + getColor() + ";"); + topHBox.setStyle("-fx-background-color: #" + getColor() + ";"); + searchTextField.setFocusColor(Color.valueOf(getColor())); + + // normal buttons + addDirectoryBtn.setStyle(btnStyle); + addStreamSourceBtn.setStyle(btnStyle); + updateBtn.setStyle(btnStyle); + playbtn.setStyle(btnStyle); + openfolderbtn.setStyle(btnStyle); + returnBtn.setStyle(btnStyle); + forwardBtn.setStyle(btnStyle); + + // menu buttons + settingsBtn.setStyle(menuBtnStyle); + aboutBtn.setStyle(menuBtnStyle); } // slide in in 400ms @@ -829,10 +813,6 @@ public class MainWindowController { columnSeason.setText(getBundle().getString("columnSeason")); columnEpisode.setText(getBundle().getString("columnEpisode")); columnFavorite.setText(getBundle().getString("columnFavorite")); - errorLoad = getBundle().getString("errorLoad"); - errorSave = getBundle().getString("errorSave"); - infoText = getBundle().getString("infoText"); - vlcNotInstalled = getBundle().getString("vlcNotInstalled"); } /** @@ -853,7 +833,7 @@ public class MainWindowController { props.storeToXML(outputStream, "Project HomeFlix settings"); // write new .xml outputStream.close(); } catch (IOException e) { - LOGGER.error(errorLoad, e); + LOGGER.error("An error occurred while saving the settings!", e); } } @@ -872,7 +852,7 @@ public class MainWindowController { setColor(props.getProperty("color")); } catch (Exception e) { LOGGER.error("cloud not load color", e); - setColor(""); + setColor("00a8cc"); } try { @@ -912,7 +892,7 @@ public class MainWindowController { inputStream.close(); } catch (IOException e) { - LOGGER.error(errorSave, e); + LOGGER.error("An error occurred while loading the settings!", e); } // try loading the omdbAPI key @@ -966,14 +946,14 @@ public class MainWindowController { return dbController; } - public void setColor(String input) { - this.color = input; - } - public String getColor() { return color; } + public void setColor(String input) { + this.color = input; + } + public FilmTabelDataType getCurrentTableFilm() { return currentTableFilm; } @@ -986,13 +966,13 @@ public class MainWindowController { return currentTableFilm.getStreamUrl(); } - public void setFontSize(Double input) { - this.fontSize = input; - } - public Double getFontSize() { return fontSize; } + + public void setFontSize(Double input) { + this.fontSize = input; + } public int getIndexTable() { return indexTable; @@ -1002,13 +982,13 @@ public class MainWindowController { return indexList; } - public void setAutoUpdate(boolean input) { - this.autoUpdate = input; - } - public boolean isAutoUpdate() { return autoUpdate; } + + public void setAutoUpdate(boolean input) { + this.autoUpdate = input; + } public boolean isUseBeta() { return useBeta; @@ -1026,13 +1006,13 @@ public class MainWindowController { this.autoplay = autoplay; } - public void setLocal(String input) { - this.local = input; - } - public String getLocal() { return local; } + + public void setLocal(String input) { + this.local = input; + } public String getOmdbAPIKey() { return omdbAPIKey; diff --git a/src/main/resources/locals/HomeFlix-Local_de_DE.properties b/src/main/resources/locals/HomeFlix-Local_de_DE.properties index 166e686..93e9015 100644 --- a/src/main/resources/locals/HomeFlix-Local_de_DE.properties +++ b/src/main/resources/locals/HomeFlix-Local_de_DE.properties @@ -31,13 +31,6 @@ columnEpisode = Episode columnFavorite = Favorit #error translations -errorUpdateV = Beim ausf\u00FChren des Updates ist ein Fehler aufgetreten! \nError: could not check update version (nvc)\nWeitere Hilfe erhalten sie unter www.kellerkinder.xyz \noder wenden sie sich an support@kellerkinder.xyz -errorUpdateD = Beim ausf\u00FChren des Updates ist ein Fehler aufgetreten! \nError: could not download update files (ndf)\nWeitere Hilfe erhalten sie unter www.kellerkinder.xyz \noder wenden sie sich an support@kellerkinder.xyz -errorMode = Oh, da lief etwas falsch! Da hat jemand einen falschen Modus verwendet. \nError: mode unknow (muk)\nWeitere Hilfe erhalten sie unter www.kellerkinder.xyz \noder wenden sie sich an support@kellerkinder.xyz -errorOpenStream = Beim \u00F6ffnen des Streams ist ein Fehler aufgetreten! -errorLoad = Beim laden der Einstellungen ist ein Fehler aufgetreten! -errorSave = Beim speichern der Einstellungen ist ein Fehler aufgetreten! -noFilmFound = Kein Film mit diesem Titel gefunden! vlcNotInstalled = Um einen Film abspielen wird der VLC Media Player ben\u00F6tigt! infoText = \nAutoren: \n \u2022 seil0@kellerkinder.xyz \n \u2022 hendrik.schutter@coptersicht.de \n(c) 2016-2018 Kellerkinder www.kellerkinder.xyz diff --git a/src/main/resources/locals/HomeFlix-Local_en_US.properties b/src/main/resources/locals/HomeFlix-Local_en_US.properties index 8b16294..4080802 100644 --- a/src/main/resources/locals/HomeFlix-Local_en_US.properties +++ b/src/main/resources/locals/HomeFlix-Local_en_US.properties @@ -31,13 +31,6 @@ columnEpisode = Episode columnFavorite = Favorite #error translations -errorUpdateV = An error has occurred during update! \nError: could not check update version (nvc) \nTo get help, visit www.kellerkinder.xyz \nor contcat support@kellerkinder.xyz -errorUpdateD = An error has occurred during update! \nError: could not download update files (ndf) \nTo get help, visit www.kellerkinder.xyz \nor contcat support@kellerkinder.xyz -errorMode = Oh, something went wrong! It seems someone has used a wrong mode. \nError: mode unknow (muk) \nTo get help, visit www.kellerkinder.xyz \nor contcat support@kellerkinder.xyz -errorOpenStream = An error has occurred during opening the stream! -errorLoad = An error occurred while loading the settings! -errorSave = An error occurred while saving the settings! -noFilmFound = No film with this title found! vlcNotInstalled = VLC Media Player is required to play a movie! infoText = \nMaintainers: \n \u2022 seil0@kellerkinder.xyz \n \u2022 hendrik.schutter@coptersicht.de \n(c) 2016-2018 Kellerkinder www.kellerkinder.xyz