code clean up and removed some unneeded mwc uses in DBController

This commit is contained in:
Jannik 2019-01-09 22:36:50 +01:00
parent 3e80354d88
commit a80e077d47
6 changed files with 75 additions and 76 deletions

View File

@ -85,6 +85,11 @@ public class Main extends Application {
primaryStage.setScene(scene); // append scene to stage primaryStage.setScene(scene); // append scene to stage
primaryStage.show(); // show stage primaryStage.show(); // show stage
mainWindowController = loader.getController(); //Link of FXMLController and controller class
mainWindowController.init();
// startup checks // startup checks
if (!XMLController.getConfigFile().exists()) { if (!XMLController.getConfigFile().exists()) {
XMLController.getDirHomeFlix().mkdir(); XMLController.getDirHomeFlix().mkdir();
@ -98,8 +103,7 @@ public class Main extends Application {
XMLController.getPosterCache().mkdir(); XMLController.getPosterCache().mkdir();
} }
mainWindowController = loader.getController(); //Link of FXMLController and controller class
mainWindowController.init();
} catch (IOException e) { } catch (IOException e) {
LOGGER.error(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 * 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 * sources.json, if the user ends the file-/directory-chooser the program will exit
*/ */
void addFirstSource() { private void addFirstSource() {
switch (XMLController.getSysLocal()) { switch (XMLController.getSysLocal()) {
case "en_US": case "en_US":
bundle = ResourceBundle.getBundle("locals.HomeFlix-Local", Locale.US); // us_english bundle = ResourceBundle.getBundle("locals.HomeFlix-Local", Locale.US); // us_english
@ -174,7 +178,7 @@ public class Main extends Application {
public void handle(ActionEvent event) { public void handle(ActionEvent event) {
FileChooser fileChooser = new FileChooser(); FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("addStreamSource"); fileChooser.setTitle("addStreamSource");
File selectedFile = fileChooser.showOpenDialog(getPrimaryStage()); File selectedFile = fileChooser.showOpenDialog(primaryStage);
if (selectedFile != null && selectedFile.exists()) { if (selectedFile != null && selectedFile.exists()) {
mainWindowController.addSource(selectedFile.getPath(), "stream"); mainWindowController.addSource(selectedFile.getPath(), "stream");
selectFirstSource.getAlert().close(); selectFirstSource.getAlert().close();
@ -189,12 +193,5 @@ public class Main extends Application {
selectFirstSource.setBtn2Action(btn2Action); selectFirstSource.setBtn2Action(btn2Action);
selectFirstSource.showAndWait(); selectFirstSource.showAndWait();
} }
public Stage getPrimaryStage() {
return primaryStage;
}
public AnchorPane getPane() {
return pane;
}
} }

View File

@ -167,7 +167,7 @@ public class MainWindowController {
private boolean settingsTrue = false; private boolean settingsTrue = false;
private final String version = "0.7.0"; private final String version = "0.7.0";
private final String buildNumber = "167"; private final String buildNumber = "169";
private final String versionName = "toothless dragon"; private final String versionName = "toothless dragon";
private String btnStyle; private String btnStyle;
@ -176,7 +176,6 @@ public class MainWindowController {
private int indexTable; private int indexTable;
private int indexList; private int indexList;
private int next; private int next;
private ResourceBundle bundle;
private FilmTabelDataType currentTableFilm = new FilmTabelDataType("", "", "", "", false, false, null); private FilmTabelDataType currentTableFilm = new FilmTabelDataType("", "", "", "", false, false, null);
private ObservableList<String> languages = FXCollections.observableArrayList("English (en_US)", "Deutsch (de_DE)"); private ObservableList<String> languages = FXCollections.observableArrayList("English (en_US)", "Deutsch (de_DE)");
@ -487,7 +486,9 @@ public class MainWindowController {
e1.printStackTrace(); e1.printStackTrace();
} }
if (output.contains("which: no vlc") || output == "") { 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(); vlcInfoAlert.showAndWait();
} else { } else {
try { try {
@ -535,7 +536,7 @@ public class MainWindowController {
@FXML @FXML
private void aboutBtnAction() { private void aboutBtnAction() {
String bodyText = "Project HomeFlix \nVersion: " + version + " (Build: " + buildNumber + ") \"" 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); JFXInfoAlert infoAlert = new JFXInfoAlert("Project HomeFlix", bodyText, btnStyle, primaryStage);
infoAlert.showAndWait(); infoAlert.showAndWait();
} }
@ -554,7 +555,7 @@ public class MainWindowController {
@FXML @FXML
private void addDirectoryBtnAction(){ private void addDirectoryBtnAction(){
DirectoryChooser directoryChooser = new DirectoryChooser(); DirectoryChooser directoryChooser = new DirectoryChooser();
directoryChooser.setTitle(bundle.getString("addDirectory")); directoryChooser.setTitle(XMLController.getLocalBundle().getString("addDirectory"));
File selectedFolder = directoryChooser.showDialog(primaryStage); File selectedFolder = directoryChooser.showDialog(primaryStage);
if (selectedFolder != null && selectedFolder.exists()) { if (selectedFolder != null && selectedFolder.exists()) {
addSource(selectedFolder.getPath(), "local"); addSource(selectedFolder.getPath(), "local");
@ -566,7 +567,7 @@ public class MainWindowController {
@FXML @FXML
private void addStreamSourceBtnAction(){ private void addStreamSourceBtnAction(){
FileChooser fileChooser = new FileChooser(); FileChooser fileChooser = new FileChooser();
fileChooser.setTitle(bundle.getString("addStreamSource")); fileChooser.setTitle(XMLController.getLocalBundle().getString("addStreamSource"));
File selectedFile = fileChooser.showOpenDialog(primaryStage); File selectedFile = fileChooser.showOpenDialog(primaryStage);
if (selectedFile != null && selectedFile.exists()) { if (selectedFile != null && selectedFile.exists()) {
addSource(selectedFile.getPath(), "stream"); addSource(selectedFile.getPath(), "stream");
@ -677,8 +678,10 @@ public class MainWindowController {
// clear old sources list/table // clear old sources list/table
getSourcesList().clear(); getSourcesList().clear();
getSourceRoot().getChildren().clear(); getSourceRoot().getChildren().clear();
// update the database and all films from the database // update the database and all films from the database
dbController.refreshDataBase(); dbController.refreshDataBase();
checkAllPosters(); // check if there is anything to cache
} }
/** /**
@ -754,37 +757,37 @@ public class MainWindowController {
void setLocalUI() { void setLocalUI() {
switch (XMLController.getUsrLocal()) { switch (XMLController.getUsrLocal()) {
case "en_US": 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); languageChoisBox.getSelectionModel().select(0);
break; break;
case "de_DE": 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); languageChoisBox.getSelectionModel().select(1);
break; break;
default: 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); languageChoisBox.getSelectionModel().select(0);
break; break;
} }
aboutBtn.setText(getBundle().getString("info")); aboutBtn.setText(XMLController.getLocalBundle().getString("info"));
settingsBtn.setText(getBundle().getString("settings")); settingsBtn.setText(XMLController.getLocalBundle().getString("settings"));
searchTextField.setPromptText(getBundle().getString("tfSearch")); searchTextField.setPromptText(XMLController.getLocalBundle().getString("tfSearch"));
openfolderbtn.setText(getBundle().getString("openFolder")); openfolderbtn.setText(XMLController.getLocalBundle().getString("openFolder"));
updateBtn.setText(getBundle().getString("checkUpdates")); updateBtn.setText(XMLController.getLocalBundle().getString("checkUpdates"));
addDirectoryBtn.setText(getBundle().getString("addDirectory")); addDirectoryBtn.setText(XMLController.getLocalBundle().getString("addDirectory"));
addStreamSourceBtn.setText(getBundle().getString("addStreamSource")); addStreamSourceBtn.setText(XMLController.getLocalBundle().getString("addStreamSource"));
homeflixSettingsLbl.setText(getBundle().getString("homeflixSettingsLbl")); homeflixSettingsLbl.setText(XMLController.getLocalBundle().getString("homeflixSettingsLbl"));
mainColorLbl.setText(getBundle().getString("mainColorLbl")); mainColorLbl.setText(XMLController.getLocalBundle().getString("mainColorLbl"));
fontsizeLbl.setText(getBundle().getString("fontsizeLbl")); fontsizeLbl.setText(XMLController.getLocalBundle().getString("fontsizeLbl"));
languageLbl.setText(getBundle().getString("languageLbl")); languageLbl.setText(XMLController.getLocalBundle().getString("languageLbl"));
autoUpdateToggleBtn.setText(getBundle().getString("autoUpdate")); autoUpdateToggleBtn.setText(XMLController.getLocalBundle().getString("autoUpdate"));
autoplayToggleBtn.setText(getBundle().getString("autoplay")); autoplayToggleBtn.setText(XMLController.getLocalBundle().getString("autoplay"));
branchLbl.setText(getBundle().getString("branchLbl")); branchLbl.setText(XMLController.getLocalBundle().getString("branchLbl"));
columnStreamUrl.setText(getBundle().getString("columnStreamUrl")); columnStreamUrl.setText(XMLController.getLocalBundle().getString("columnStreamUrl"));
columnTitle.setText(getBundle().getString("columnName")); columnTitle.setText(XMLController.getLocalBundle().getString("columnName"));
columnSeason.setText(getBundle().getString("columnSeason")); columnSeason.setText(XMLController.getLocalBundle().getString("columnSeason"));
columnEpisode.setText(getBundle().getString("columnEpisode")); columnEpisode.setText(XMLController.getLocalBundle().getString("columnEpisode"));
columnFavorite.setText(getBundle().getString("columnFavorite")); columnFavorite.setText(XMLController.getLocalBundle().getString("columnFavorite"));
} }
// if AutoUpdate, then check for updates // if AutoUpdate, then check for updates
@ -870,14 +873,6 @@ public class MainWindowController {
return sourcesList; return sourcesList;
} }
public ResourceBundle getBundle() {
return bundle;
}
public void setBundle(ResourceBundle bundle) {
this.bundle = bundle;
}
public TreeTableView<FilmTabelDataType> getFilmsTreeTable() { public TreeTableView<FilmTabelDataType> getFilmsTreeTable() {
return filmsTreeTable; return filmsTreeTable;
} }

View File

@ -457,26 +457,26 @@ public class DBController {
ObservableList<Node> textFlow = mainWindowController.getTextFlow().getChildren(); ObservableList<Node> textFlow = mainWindowController.getTextFlow().getChildren();
ArrayList<Text> nameText = new ArrayList<Text>(); ArrayList<Text> nameText = new ArrayList<Text>();
nameText.add(new Text(mainWindowController.getBundle().getString("title") + ": ")); nameText.add(new Text(XMLController.getLocalBundle().getString("title") + ": "));
nameText.add(new Text(mainWindowController.getBundle().getString("year") + ": ")); nameText.add(new Text(XMLController.getLocalBundle().getString("year") + ": "));
nameText.add(new Text(mainWindowController.getBundle().getString("rated") + ": ")); nameText.add(new Text(XMLController.getLocalBundle().getString("rated") + ": "));
nameText.add(new Text(mainWindowController.getBundle().getString("released") + ": ")); nameText.add(new Text(XMLController.getLocalBundle().getString("released") + ": "));
nameText.add(new Text(mainWindowController.getBundle().getString("season") + ": ")); nameText.add(new Text(XMLController.getLocalBundle().getString("season") + ": "));
nameText.add(new Text(mainWindowController.getBundle().getString("episode") + ": ")); nameText.add(new Text(XMLController.getLocalBundle().getString("episode") + ": "));
nameText.add(new Text(mainWindowController.getBundle().getString("runtime") + ": ")); nameText.add(new Text(XMLController.getLocalBundle().getString("runtime") + ": "));
nameText.add(new Text(mainWindowController.getBundle().getString("genre") + ": ")); nameText.add(new Text(XMLController.getLocalBundle().getString("genre") + ": "));
nameText.add(new Text(mainWindowController.getBundle().getString("director") + ": ")); nameText.add(new Text(XMLController.getLocalBundle().getString("director") + ": "));
nameText.add(new Text(mainWindowController.getBundle().getString("writer") + ": ")); nameText.add(new Text(XMLController.getLocalBundle().getString("writer") + ": "));
nameText.add(new Text(mainWindowController.getBundle().getString("actors") + ": ")); nameText.add(new Text(XMLController.getLocalBundle().getString("actors") + ": "));
nameText.add(new Text(mainWindowController.getBundle().getString("plot") + ": ")); nameText.add(new Text(XMLController.getLocalBundle().getString("plot") + ": "));
nameText.add(new Text(mainWindowController.getBundle().getString("language") + ": ")); nameText.add(new Text(XMLController.getLocalBundle().getString("language") + ": "));
nameText.add(new Text(mainWindowController.getBundle().getString("country") + ": ")); nameText.add(new Text(XMLController.getLocalBundle().getString("country") + ": "));
nameText.add(new Text(mainWindowController.getBundle().getString("awards") + ": ")); nameText.add(new Text(XMLController.getLocalBundle().getString("awards") + ": "));
nameText.add(new Text(mainWindowController.getBundle().getString("metascore") + ": ")); nameText.add(new Text(XMLController.getLocalBundle().getString("metascore") + ": "));
nameText.add(new Text(mainWindowController.getBundle().getString("imdbRating") + ": ")); nameText.add(new Text(XMLController.getLocalBundle().getString("imdbRating") + ": "));
nameText.add(new Text(mainWindowController.getBundle().getString("type") + ": ")); nameText.add(new Text(XMLController.getLocalBundle().getString("type") + ": "));
nameText.add(new Text(mainWindowController.getBundle().getString("boxOffice") + ": ")); nameText.add(new Text(XMLController.getLocalBundle().getString("boxOffice") + ": "));
nameText.add(new Text(mainWindowController.getBundle().getString("website") + ": ")); nameText.add(new Text(XMLController.getLocalBundle().getString("website") + ": "));
// set the correct font for the nameText // set the correct font for the nameText
for (Text text : nameText) { for (Text text : nameText) {

View File

@ -76,7 +76,7 @@ public class UpdateController implements Runnable {
public void run() { public void run() {
LOGGER.info("beta:" + useBeta + "; checking for updates ..."); LOGGER.info("beta:" + useBeta + "; checking for updates ...");
Platform.runLater(() -> { Platform.runLater(() -> {
mainWindowController.getUpdateBtn().setText(mainWindowController.getBundle().getString("updateBtnChecking")); mainWindowController.getUpdateBtn().setText(XMLController.getLocalBundle().getString("updateBtnChecking"));
}); });
try { try {
@ -116,12 +116,12 @@ public class UpdateController implements Runnable {
*/ */
if (buildNumber >= updateBuildNumber) { if (buildNumber >= updateBuildNumber) {
Platform.runLater(() -> { Platform.runLater(() -> {
mainWindowController.getUpdateBtn().setText(mainWindowController.getBundle().getString("updateBtnNoUpdateAvailable")); mainWindowController.getUpdateBtn().setText(XMLController.getLocalBundle().getString("updateBtnNoUpdateAvailable"));
}); });
LOGGER.info("no update available"); LOGGER.info("no update available");
} else { } else {
Platform.runLater(() -> { Platform.runLater(() -> {
mainWindowController.getUpdateBtn().setText(mainWindowController.getBundle().getString("updateBtnUpdateAvailable")); mainWindowController.getUpdateBtn().setText(XMLController.getLocalBundle().getString("updateBtnUpdateAvailable"));
}); });
LOGGER.info("update available"); LOGGER.info("update available");
browserDownloadUrl = objectAsset.getString("browser_download_url", ""); browserDownloadUrl = objectAsset.getString("browser_download_url", "");

View File

@ -30,7 +30,9 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.Locale;
import java.util.Properties; import java.util.Properties;
import java.util.ResourceBundle;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
@ -60,6 +62,7 @@ public class XMLController {
private static boolean useBeta = false; private static boolean useBeta = false;
private static boolean autoplay = false; private static boolean autoplay = false;
private static double fontSize = 17; private static double fontSize = 17;
private static ResourceBundle localBundle = ResourceBundle.getBundle("locals.HomeFlix-Local", Locale.US);
// user settings // user settings
private static String omdbAPIKey; private static String omdbAPIKey;
@ -281,6 +284,15 @@ public class XMLController {
public static void setFontSize(double fontSize) { public static void setFontSize(double fontSize) {
XMLController.fontSize = fontSize; XMLController.fontSize = fontSize;
} }
public static ResourceBundle getLocalBundle() {
return localBundle;
}
public static void setLocalBundle(ResourceBundle localBundle) {
XMLController.localBundle = localBundle;
}
// getters for APIs // getters for APIs

View File

@ -24,7 +24,6 @@ package kellerkinder.HomeFlix.player;
import javafx.event.EventHandler; import javafx.event.EventHandler;
import javafx.fxml.FXMLLoader; import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene; import javafx.scene.Scene;
import javafx.scene.image.Image; import javafx.scene.image.Image;
import javafx.scene.layout.AnchorPane; import javafx.scene.layout.AnchorPane;
@ -78,10 +77,6 @@ public class Player {
public Stage getStage() { public Stage getStage() {
return stage; return stage;
} }
public Parent getPane() {
return pane;
}
public Scene getScene() { public Scene getScene() {
return scene; return scene;