From a80e077d473e9e30a230cf5c9a1aa116d0215fb0 Mon Sep 17 00:00:00 2001 From: Seil0 Date: Wed, 9 Jan 2019 22:36:50 +0100 Subject: [PATCH] code clean up and removed some unneeded mwc uses in DBController --- .../HomeFlix/application/Main.java | 21 +++--- .../application/MainWindowController.java | 67 +++++++++---------- .../HomeFlix/controller/DBController.java | 40 +++++------ .../HomeFlix/controller/UpdateController.java | 6 +- .../HomeFlix/controller/XMLController.java | 12 ++++ .../kellerkinder/HomeFlix/player/Player.java | 5 -- 6 files changed, 75 insertions(+), 76 deletions(-) diff --git a/src/main/java/kellerkinder/HomeFlix/application/Main.java b/src/main/java/kellerkinder/HomeFlix/application/Main.java index 04ed160..6e519d8 100644 --- a/src/main/java/kellerkinder/HomeFlix/application/Main.java +++ b/src/main/java/kellerkinder/HomeFlix/application/Main.java @@ -85,6 +85,11 @@ public class Main extends Application { primaryStage.setScene(scene); // append scene to stage primaryStage.show(); // show stage + + + mainWindowController = loader.getController(); //Link of FXMLController and controller class + mainWindowController.init(); + // startup checks if (!XMLController.getConfigFile().exists()) { XMLController.getDirHomeFlix().mkdir(); @@ -98,8 +103,7 @@ public class Main extends Application { XMLController.getPosterCache().mkdir(); } - mainWindowController = loader.getController(); //Link of FXMLController and controller class - mainWindowController.init(); + } catch (IOException e) { LOGGER.error(e); } @@ -132,7 +136,7 @@ public class Main extends Application { * we need to get the path for the first source from the user and add it to * sources.json, if the user ends the file-/directory-chooser the program will exit */ - void addFirstSource() { + private void addFirstSource() { switch (XMLController.getSysLocal()) { case "en_US": bundle = ResourceBundle.getBundle("locals.HomeFlix-Local", Locale.US); // us_english @@ -174,7 +178,7 @@ public class Main extends Application { public void handle(ActionEvent event) { FileChooser fileChooser = new FileChooser(); fileChooser.setTitle("addStreamSource"); - File selectedFile = fileChooser.showOpenDialog(getPrimaryStage()); + File selectedFile = fileChooser.showOpenDialog(primaryStage); if (selectedFile != null && selectedFile.exists()) { mainWindowController.addSource(selectedFile.getPath(), "stream"); selectFirstSource.getAlert().close(); @@ -189,12 +193,5 @@ public class Main extends Application { selectFirstSource.setBtn2Action(btn2Action); selectFirstSource.showAndWait(); } - - public Stage getPrimaryStage() { - return primaryStage; - } - - public AnchorPane getPane() { - return pane; - } + } diff --git a/src/main/java/kellerkinder/HomeFlix/application/MainWindowController.java b/src/main/java/kellerkinder/HomeFlix/application/MainWindowController.java index 73d6b5f..9e291bc 100644 --- a/src/main/java/kellerkinder/HomeFlix/application/MainWindowController.java +++ b/src/main/java/kellerkinder/HomeFlix/application/MainWindowController.java @@ -167,7 +167,7 @@ public class MainWindowController { private boolean settingsTrue = false; private final String version = "0.7.0"; - private final String buildNumber = "167"; + private final String buildNumber = "169"; private final String versionName = "toothless dragon"; private String btnStyle; @@ -176,7 +176,6 @@ public class MainWindowController { private int indexTable; private int indexList; private int next; - private ResourceBundle bundle; private FilmTabelDataType currentTableFilm = new FilmTabelDataType("", "", "", "", false, false, null); private ObservableList languages = FXCollections.observableArrayList("English (en_US)", "Deutsch (de_DE)"); @@ -487,7 +486,9 @@ public class MainWindowController { e1.printStackTrace(); } if (output.contains("which: no vlc") || output == "") { - JFXInfoAlert vlcInfoAlert = new JFXInfoAlert("Info", getBundle().getString("vlcNotInstalled"), btnStyle, primaryStage); + JFXInfoAlert vlcInfoAlert = new JFXInfoAlert("Info", + XMLController.getLocalBundle().getString("vlcNotInstalled"), + btnStyle, primaryStage); vlcInfoAlert.showAndWait(); } else { try { @@ -535,7 +536,7 @@ public class MainWindowController { @FXML private void aboutBtnAction() { String bodyText = "Project HomeFlix \nVersion: " + version + " (Build: " + buildNumber + ") \"" - + versionName + "\" \n" + getBundle().getString("infoText"); + + versionName + "\" \n" + XMLController.getLocalBundle().getString("infoText"); JFXInfoAlert infoAlert = new JFXInfoAlert("Project HomeFlix", bodyText, btnStyle, primaryStage); infoAlert.showAndWait(); } @@ -554,7 +555,7 @@ public class MainWindowController { @FXML private void addDirectoryBtnAction(){ DirectoryChooser directoryChooser = new DirectoryChooser(); - directoryChooser.setTitle(bundle.getString("addDirectory")); + directoryChooser.setTitle(XMLController.getLocalBundle().getString("addDirectory")); File selectedFolder = directoryChooser.showDialog(primaryStage); if (selectedFolder != null && selectedFolder.exists()) { addSource(selectedFolder.getPath(), "local"); @@ -566,7 +567,7 @@ public class MainWindowController { @FXML private void addStreamSourceBtnAction(){ FileChooser fileChooser = new FileChooser(); - fileChooser.setTitle(bundle.getString("addStreamSource")); + fileChooser.setTitle(XMLController.getLocalBundle().getString("addStreamSource")); File selectedFile = fileChooser.showOpenDialog(primaryStage); if (selectedFile != null && selectedFile.exists()) { addSource(selectedFile.getPath(), "stream"); @@ -677,8 +678,10 @@ public class MainWindowController { // clear old sources list/table getSourcesList().clear(); getSourceRoot().getChildren().clear(); + // update the database and all films from the database dbController.refreshDataBase(); + checkAllPosters(); // check if there is anything to cache } /** @@ -754,37 +757,37 @@ public class MainWindowController { void setLocalUI() { switch (XMLController.getUsrLocal()) { case "en_US": - setBundle(ResourceBundle.getBundle("locals.HomeFlix-Local", Locale.US)); // us_English + XMLController.setLocalBundle(ResourceBundle.getBundle("locals.HomeFlix-Local", Locale.US)); // us_English languageChoisBox.getSelectionModel().select(0); break; case "de_DE": - setBundle(ResourceBundle.getBundle("locals.HomeFlix-Local", Locale.GERMAN)); // German + XMLController.setLocalBundle(ResourceBundle.getBundle("locals.HomeFlix-Local", Locale.GERMAN)); // German languageChoisBox.getSelectionModel().select(1); break; default: - setBundle(ResourceBundle.getBundle("locals.HomeFlix-Local", Locale.US)); // default local + XMLController.setLocalBundle(ResourceBundle.getBundle("locals.HomeFlix-Local", Locale.US)); // default local languageChoisBox.getSelectionModel().select(0); break; } - aboutBtn.setText(getBundle().getString("info")); - settingsBtn.setText(getBundle().getString("settings")); - searchTextField.setPromptText(getBundle().getString("tfSearch")); - openfolderbtn.setText(getBundle().getString("openFolder")); - updateBtn.setText(getBundle().getString("checkUpdates")); - addDirectoryBtn.setText(getBundle().getString("addDirectory")); - addStreamSourceBtn.setText(getBundle().getString("addStreamSource")); - homeflixSettingsLbl.setText(getBundle().getString("homeflixSettingsLbl")); - mainColorLbl.setText(getBundle().getString("mainColorLbl")); - fontsizeLbl.setText(getBundle().getString("fontsizeLbl")); - languageLbl.setText(getBundle().getString("languageLbl")); - autoUpdateToggleBtn.setText(getBundle().getString("autoUpdate")); - autoplayToggleBtn.setText(getBundle().getString("autoplay")); - branchLbl.setText(getBundle().getString("branchLbl")); - columnStreamUrl.setText(getBundle().getString("columnStreamUrl")); - columnTitle.setText(getBundle().getString("columnName")); - columnSeason.setText(getBundle().getString("columnSeason")); - columnEpisode.setText(getBundle().getString("columnEpisode")); - columnFavorite.setText(getBundle().getString("columnFavorite")); + aboutBtn.setText(XMLController.getLocalBundle().getString("info")); + settingsBtn.setText(XMLController.getLocalBundle().getString("settings")); + searchTextField.setPromptText(XMLController.getLocalBundle().getString("tfSearch")); + openfolderbtn.setText(XMLController.getLocalBundle().getString("openFolder")); + updateBtn.setText(XMLController.getLocalBundle().getString("checkUpdates")); + addDirectoryBtn.setText(XMLController.getLocalBundle().getString("addDirectory")); + addStreamSourceBtn.setText(XMLController.getLocalBundle().getString("addStreamSource")); + homeflixSettingsLbl.setText(XMLController.getLocalBundle().getString("homeflixSettingsLbl")); + mainColorLbl.setText(XMLController.getLocalBundle().getString("mainColorLbl")); + fontsizeLbl.setText(XMLController.getLocalBundle().getString("fontsizeLbl")); + languageLbl.setText(XMLController.getLocalBundle().getString("languageLbl")); + autoUpdateToggleBtn.setText(XMLController.getLocalBundle().getString("autoUpdate")); + autoplayToggleBtn.setText(XMLController.getLocalBundle().getString("autoplay")); + branchLbl.setText(XMLController.getLocalBundle().getString("branchLbl")); + columnStreamUrl.setText(XMLController.getLocalBundle().getString("columnStreamUrl")); + columnTitle.setText(XMLController.getLocalBundle().getString("columnName")); + columnSeason.setText(XMLController.getLocalBundle().getString("columnSeason")); + columnEpisode.setText(XMLController.getLocalBundle().getString("columnEpisode")); + columnFavorite.setText(XMLController.getLocalBundle().getString("columnFavorite")); } // if AutoUpdate, then check for updates @@ -870,14 +873,6 @@ public class MainWindowController { return sourcesList; } - public ResourceBundle getBundle() { - return bundle; - } - - public void setBundle(ResourceBundle bundle) { - this.bundle = bundle; - } - public TreeTableView getFilmsTreeTable() { return filmsTreeTable; } diff --git a/src/main/java/kellerkinder/HomeFlix/controller/DBController.java b/src/main/java/kellerkinder/HomeFlix/controller/DBController.java index 8ed23b9..b07d195 100644 --- a/src/main/java/kellerkinder/HomeFlix/controller/DBController.java +++ b/src/main/java/kellerkinder/HomeFlix/controller/DBController.java @@ -457,26 +457,26 @@ public class DBController { ObservableList textFlow = mainWindowController.getTextFlow().getChildren(); ArrayList nameText = new ArrayList(); - nameText.add(new Text(mainWindowController.getBundle().getString("title") + ": ")); - nameText.add(new Text(mainWindowController.getBundle().getString("year") + ": ")); - nameText.add(new Text(mainWindowController.getBundle().getString("rated") + ": ")); - nameText.add(new Text(mainWindowController.getBundle().getString("released") + ": ")); - nameText.add(new Text(mainWindowController.getBundle().getString("season") + ": ")); - nameText.add(new Text(mainWindowController.getBundle().getString("episode") + ": ")); - nameText.add(new Text(mainWindowController.getBundle().getString("runtime") + ": ")); - nameText.add(new Text(mainWindowController.getBundle().getString("genre") + ": ")); - nameText.add(new Text(mainWindowController.getBundle().getString("director") + ": ")); - nameText.add(new Text(mainWindowController.getBundle().getString("writer") + ": ")); - nameText.add(new Text(mainWindowController.getBundle().getString("actors") + ": ")); - nameText.add(new Text(mainWindowController.getBundle().getString("plot") + ": ")); - nameText.add(new Text(mainWindowController.getBundle().getString("language") + ": ")); - nameText.add(new Text(mainWindowController.getBundle().getString("country") + ": ")); - nameText.add(new Text(mainWindowController.getBundle().getString("awards") + ": ")); - nameText.add(new Text(mainWindowController.getBundle().getString("metascore") + ": ")); - nameText.add(new Text(mainWindowController.getBundle().getString("imdbRating") + ": ")); - nameText.add(new Text(mainWindowController.getBundle().getString("type") + ": ")); - nameText.add(new Text(mainWindowController.getBundle().getString("boxOffice") + ": ")); - nameText.add(new Text(mainWindowController.getBundle().getString("website") + ": ")); + nameText.add(new Text(XMLController.getLocalBundle().getString("title") + ": ")); + nameText.add(new Text(XMLController.getLocalBundle().getString("year") + ": ")); + nameText.add(new Text(XMLController.getLocalBundle().getString("rated") + ": ")); + nameText.add(new Text(XMLController.getLocalBundle().getString("released") + ": ")); + nameText.add(new Text(XMLController.getLocalBundle().getString("season") + ": ")); + nameText.add(new Text(XMLController.getLocalBundle().getString("episode") + ": ")); + nameText.add(new Text(XMLController.getLocalBundle().getString("runtime") + ": ")); + nameText.add(new Text(XMLController.getLocalBundle().getString("genre") + ": ")); + nameText.add(new Text(XMLController.getLocalBundle().getString("director") + ": ")); + nameText.add(new Text(XMLController.getLocalBundle().getString("writer") + ": ")); + nameText.add(new Text(XMLController.getLocalBundle().getString("actors") + ": ")); + nameText.add(new Text(XMLController.getLocalBundle().getString("plot") + ": ")); + nameText.add(new Text(XMLController.getLocalBundle().getString("language") + ": ")); + nameText.add(new Text(XMLController.getLocalBundle().getString("country") + ": ")); + nameText.add(new Text(XMLController.getLocalBundle().getString("awards") + ": ")); + nameText.add(new Text(XMLController.getLocalBundle().getString("metascore") + ": ")); + nameText.add(new Text(XMLController.getLocalBundle().getString("imdbRating") + ": ")); + nameText.add(new Text(XMLController.getLocalBundle().getString("type") + ": ")); + nameText.add(new Text(XMLController.getLocalBundle().getString("boxOffice") + ": ")); + nameText.add(new Text(XMLController.getLocalBundle().getString("website") + ": ")); // set the correct font for the nameText for (Text text : nameText) { diff --git a/src/main/java/kellerkinder/HomeFlix/controller/UpdateController.java b/src/main/java/kellerkinder/HomeFlix/controller/UpdateController.java index 9b71c0a..3c7caf1 100644 --- a/src/main/java/kellerkinder/HomeFlix/controller/UpdateController.java +++ b/src/main/java/kellerkinder/HomeFlix/controller/UpdateController.java @@ -76,7 +76,7 @@ public class UpdateController implements Runnable { public void run() { LOGGER.info("beta:" + useBeta + "; checking for updates ..."); Platform.runLater(() -> { - mainWindowController.getUpdateBtn().setText(mainWindowController.getBundle().getString("updateBtnChecking")); + mainWindowController.getUpdateBtn().setText(XMLController.getLocalBundle().getString("updateBtnChecking")); }); try { @@ -116,12 +116,12 @@ public class UpdateController implements Runnable { */ if (buildNumber >= updateBuildNumber) { Platform.runLater(() -> { - mainWindowController.getUpdateBtn().setText(mainWindowController.getBundle().getString("updateBtnNoUpdateAvailable")); + mainWindowController.getUpdateBtn().setText(XMLController.getLocalBundle().getString("updateBtnNoUpdateAvailable")); }); LOGGER.info("no update available"); } else { Platform.runLater(() -> { - mainWindowController.getUpdateBtn().setText(mainWindowController.getBundle().getString("updateBtnUpdateAvailable")); + mainWindowController.getUpdateBtn().setText(XMLController.getLocalBundle().getString("updateBtnUpdateAvailable")); }); LOGGER.info("update available"); browserDownloadUrl = objectAsset.getString("browser_download_url", ""); diff --git a/src/main/java/kellerkinder/HomeFlix/controller/XMLController.java b/src/main/java/kellerkinder/HomeFlix/controller/XMLController.java index 2fb9a45..8d36204 100644 --- a/src/main/java/kellerkinder/HomeFlix/controller/XMLController.java +++ b/src/main/java/kellerkinder/HomeFlix/controller/XMLController.java @@ -30,7 +30,9 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; +import java.util.Locale; import java.util.Properties; +import java.util.ResourceBundle; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -60,6 +62,7 @@ public class XMLController { private static boolean useBeta = false; private static boolean autoplay = false; private static double fontSize = 17; + private static ResourceBundle localBundle = ResourceBundle.getBundle("locals.HomeFlix-Local", Locale.US); // user settings private static String omdbAPIKey; @@ -281,6 +284,15 @@ public class XMLController { public static void setFontSize(double fontSize) { XMLController.fontSize = fontSize; } + + public static ResourceBundle getLocalBundle() { + return localBundle; + } + + public static void setLocalBundle(ResourceBundle localBundle) { + XMLController.localBundle = localBundle; + } + // getters for APIs diff --git a/src/main/java/kellerkinder/HomeFlix/player/Player.java b/src/main/java/kellerkinder/HomeFlix/player/Player.java index 3481813..f6d5cc8 100644 --- a/src/main/java/kellerkinder/HomeFlix/player/Player.java +++ b/src/main/java/kellerkinder/HomeFlix/player/Player.java @@ -24,7 +24,6 @@ package kellerkinder.HomeFlix.player; import javafx.event.EventHandler; import javafx.fxml.FXMLLoader; -import javafx.scene.Parent; import javafx.scene.Scene; import javafx.scene.image.Image; import javafx.scene.layout.AnchorPane; @@ -78,10 +77,6 @@ public class Player { public Stage getStage() { return stage; } - - public Parent getPane() { - return pane; - } public Scene getScene() { return scene;