documentation work

* added a lot of documentation to the code
* log4j 2.10 -> 2.11
This commit is contained in:
Jannik 2018-04-02 18:29:59 +02:00
parent a918b0b1d8
commit 5e4373d70d
12 changed files with 151 additions and 43 deletions

View File

@ -4,7 +4,7 @@
<groupId>org.kellerkinder</groupId> <groupId>org.kellerkinder</groupId>
<artifactId>Project-HomeFlix</artifactId> <artifactId>Project-HomeFlix</artifactId>
<version>0.6.0</version> <version>0.6.1</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>Project-HomeFlix</name> <name>Project-HomeFlix</name>
@ -19,7 +19,7 @@
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
<version>4.11</version> <version>4.12</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
@ -50,13 +50,13 @@
<dependency> <dependency>
<groupId>org.apache.logging.log4j</groupId> <groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId> <artifactId>log4j-api</artifactId>
<version>2.10.0</version> <version>2.11.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.logging.log4j</groupId> <groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId> <artifactId>log4j-core</artifactId>
<version>2.10.0</version> <version>2.11.0</version>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -19,7 +19,6 @@
* MA 02110-1301, USA. * MA 02110-1301, USA.
* *
*/ */
package kellerkinder.HomeFlix.application; package kellerkinder.HomeFlix.application;
import java.io.File; import java.io.File;
@ -77,6 +76,10 @@ public class Main extends Application {
mainWindow(); mainWindow();
} }
/**
* initialize the mainWindowController, GUI and load the saved settings or call addFirstSource
* initialize the primaryStage and set the file/directory paths
*/
private void mainWindow(){ private void mainWindow(){
try { try {
FXMLLoader loader = new FXMLLoader(); FXMLLoader loader = new FXMLLoader();
@ -111,7 +114,7 @@ public class Main extends Application {
// startup checks // startup checks
if (!configFile.exists()) { if (!configFile.exists()) {
directory.mkdir(); directory.mkdir();
getFirstSource(); addFirstSource();
mainWindowController.setColor("ee3523"); mainWindowController.setColor("ee3523");
mainWindowController.setSize(FONT_SIZE); mainWindowController.setSize(FONT_SIZE);
mainWindowController.setAutoUpdate(false); mainWindowController.setAutoUpdate(false);
@ -132,10 +135,10 @@ public class Main extends Application {
} }
/** /**
* TODO add option to add streaming as first source when there i no config.xml * 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 * sources.json, if the user ends the file-/directory-chooser the program will exit
*/ */
private void getFirstSource() { private void addFirstSource() {
switch (System.getProperty("user.language") + "_" + System.getProperty("user.country")) { switch (System.getProperty("user.language") + "_" + System.getProperty("user.country")) {
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
@ -192,6 +195,11 @@ public class Main extends Application {
selectFirstSource.showAndWait(); selectFirstSource.showAndWait();
} }
/**
* 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) { public static void main(String[] args) {
if (System.getProperty("os.name").equals("Windows")) { if (System.getProperty("os.name").equals("Windows")) {
System.setProperty("logFilename", userHome + "/Documents/HomeFlix/app.log"); System.setProperty("logFilename", userHome + "/Documents/HomeFlix/app.log");
@ -210,10 +218,6 @@ public class Main extends Application {
return primaryStage; return primaryStage;
} }
public void setPrimaryStage(Stage primaryStage) {
this.primaryStage = primaryStage;
}
public AnchorPane getPane() { public AnchorPane getPane() {
return pane; return pane;
} }

View File

@ -19,7 +19,6 @@
* MA 02110-1301, USA. * MA 02110-1301, USA.
* *
*/ */
package kellerkinder.HomeFlix.application; package kellerkinder.HomeFlix.application;
import java.awt.Desktop; import java.awt.Desktop;
@ -759,18 +758,22 @@ public class MainWindowController {
} }
//set color of UI-Elements //set color of UI-Elements
/**
* set the color of the GUI-Elements
* if usedColor is less than checkColor set text fill white, else black
*/
private void applyColor() { private void applyColor() {
String style = "-fx-background-color: #" + getColor() + ";"; String style = "-fx-background-color: #" + getColor() + ";";
String btnStyleBlack = "-fx-button-type: RAISED; -fx-background-color: #" + getColor() + "; -fx-text-fill: BLACK;"; 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;"; String btnStyleWhite = "-fx-button-type: RAISED; -fx-background-color: #" + getColor() + "; -fx-text-fill: WHITE;";
BigInteger icolor = new BigInteger(getColor(), 16); BigInteger usedColor = new BigInteger(getColor(), 16);
BigInteger ccolor = new BigInteger("78909cff", 16); BigInteger checkColor = new BigInteger("78909cff", 16);
sideMenuVBox.setStyle(style); sideMenuVBox.setStyle(style);
topHBox.setStyle(style); topHBox.setStyle(style);
searchTextField.setFocusColor(Color.valueOf(getColor())); searchTextField.setFocusColor(Color.valueOf(getColor()));
if (icolor.compareTo(ccolor) == -1) { if (usedColor.compareTo(checkColor) == -1) {
dialogBtnStyle = btnStyleWhite; dialogBtnStyle = btnStyleWhite;
settingsBtn.setStyle("-fx-text-fill: WHITE;"); settingsBtn.setStyle("-fx-text-fill: WHITE;");
aboutBtn.setStyle("-fx-text-fill: WHITE;"); aboutBtn.setStyle("-fx-text-fill: WHITE;");
@ -822,6 +825,9 @@ public class MainWindowController {
translateTransition.play(); translateTransition.play();
} }
/**
* set the local based on the languageChoisBox selection
*/
void setLocalUI() { void setLocalUI() {
switch (getLocal()) { switch (getLocal()) {
case "en_US": case "en_US":
@ -895,7 +901,9 @@ public class MainWindowController {
LOGGER.error("An error occurred", exception); LOGGER.error("An error occurred", exception);
} }
// save settings /**
* save the configuration to the config.xml file
*/
public void saveSettings() { public void saveSettings() {
LOGGER.info("saving settings ..."); LOGGER.info("saving settings ...");
try { try {
@ -907,14 +915,17 @@ public class MainWindowController {
props.setProperty("ratingSortType", columnFavorite.getSortType().toString()); props.setProperty("ratingSortType", columnFavorite.getSortType().toString());
OutputStream outputStream = new FileOutputStream(main.getConfigFile()); // new output-stream OutputStream outputStream = new FileOutputStream(main.getConfigFile()); // new output-stream
props.storeToXML(outputStream, "Project HomeFlix settings"); // writes new .xml props.storeToXML(outputStream, "Project HomeFlix settings"); // write new .xml
outputStream.close(); outputStream.close();
} catch (IOException e) { } catch (IOException e) {
LOGGER.error(errorLoad, e); LOGGER.error(errorLoad, e);
} }
} }
// load settings /**
* load the configuration from the config.xml file
* and try to load the API keys from apiKeys.json
*/
public void loadSettings() { public void loadSettings() {
LOGGER.info("loading settings ..."); LOGGER.info("loading settings ...");

View File

@ -18,7 +18,6 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA. * MA 02110-1301, USA.
*/ */
package kellerkinder.HomeFlix.controller; package kellerkinder.HomeFlix.controller;
import java.io.File; import java.io.File;
@ -53,12 +52,7 @@ import kellerkinder.HomeFlix.datatypes.SourceDataType;
import kellerkinder.HomeFlix.datatypes.FilmTabelDataType; import kellerkinder.HomeFlix.datatypes.FilmTabelDataType;
public class DBController { public class DBController {
public DBController(Main main, MainWindowController mainWindowController) {
this.main = main;
this.mainWindowController = mainWindowController;
}
private MainWindowController mainWindowController; private MainWindowController mainWindowController;
private Main main; private Main main;
private String DB_PATH = System.getProperty("user.home") + "\\Documents\\HomeFlix" + "\\" + "Homeflix.db"; //path to database file private String DB_PATH = System.getProperty("user.home") + "\\Documents\\HomeFlix" + "\\" + "Homeflix.db"; //path to database file
@ -71,6 +65,22 @@ public class DBController {
private Connection connection = null; private Connection connection = null;
private static final Logger LOGGER = LogManager.getLogger(DBController.class.getName()); private static final Logger LOGGER = LogManager.getLogger(DBController.class.getName());
/**
* constructor for DBController
* @param main the main object
* @param mainWindowController the mainWindowController object
*/
public DBController(Main main, MainWindowController mainWindowController) {
this.main = main;
this.mainWindowController = mainWindowController;
}
/**
* initialize the {@link DBController}
* initialize the database connection
* check if there is a need to create a new database
* refresh the database
*/
public void init() { public void init() {
LOGGER.info("<========== starting loading sql ==========>"); LOGGER.info("<========== starting loading sql ==========>");
initDatabaseConnection(); initDatabaseConnection();
@ -79,12 +89,16 @@ public class DBController {
LOGGER.info("<========== finished loading sql ==========>"); LOGGER.info("<========== finished loading sql ==========>");
} }
/**
* create a new connection to the HomeFlix.db database
* AutoCommit is set to false to prevent some issues, so manual commit is active!
*/
private void initDatabaseConnection() { private void initDatabaseConnection() {
DB_PATH = main.getDirectory() + "/Homeflix.db"; DB_PATH = main.getDirectory() + "/Homeflix.db";
try { try {
// create a database connection // create a database connection
connection = DriverManager.getConnection("jdbc:sqlite:" + DB_PATH); connection = DriverManager.getConnection("jdbc:sqlite:" + DB_PATH);
connection.setAutoCommit(false); //AutoCommit to false -> manual commit is active connection.setAutoCommit(false);
} catch (SQLException e) { } catch (SQLException e) {
// if the error message is "out of memory", it probably means no database file is found // if the error message is "out of memory", it probably means no database file is found
LOGGER.error("error while loading the ROM database", e); LOGGER.error("error while loading the ROM database", e);
@ -94,6 +108,7 @@ public class DBController {
/** /**
* if tables don't exist create them * if tables don't exist create them
* films table: streamUrl is primary key
* cache table: streamUrl is primary key * cache table: streamUrl is primary key
*/ */
private void createDatabase() { private void createDatabase() {
@ -110,6 +125,9 @@ public class DBController {
} }
} }
/**
* get all database entries
*/
private void loadDatabase() { private void loadDatabase() {
// get all entries from the table // get all entries from the table
try { try {
@ -131,7 +149,11 @@ public class DBController {
LOGGER.info("filme in db: " + filmsdbStreamURL.size()); LOGGER.info("filme in db: " + filmsdbStreamURL.size());
} }
// load the sources from sources.json /**
* load sources from sources.json
* if mode == local, get all files and series-folder from the directory
* else mode must be streaming, read all entries from the streaming file
*/
private void loadSources() { private void loadSources() {
// remove sources from table // remove sources from table
mainWindowController.getSourcesList().removeAll(mainWindowController.getSourcesList()); mainWindowController.getSourcesList().removeAll(mainWindowController.getSourcesList());
@ -181,7 +203,10 @@ public class DBController {
} }
} }
// loading data from database to mainWindowController /**
* load the data to the mainWindowController
* order entries by title
*/
private void loadDataToMWC() { private void loadDataToMWC() {
LOGGER.info("loading data to mwc ..."); LOGGER.info("loading data to mwc ...");
try { try {
@ -381,7 +406,10 @@ public class DBController {
} }
} }
// prints all entries from the database to the console /**
* DEBUG
* prints all entries from the database to the console
*/
public void printAllDBEntriesDEBUG() { public void printAllDBEntriesDEBUG() {
System.out.println("Outputting all entries ... \n"); System.out.println("Outputting all entries ... \n");
try { try {
@ -581,6 +609,11 @@ public class DBController {
} }
} }
/**
* return the currentTime in ms saved in the database
* @param streamUrl URL of the film
* @return {@link Double} currentTime in ms
*/
public double getCurrentTime(String streamUrl) { public double getCurrentTime(String streamUrl) {
LOGGER.info("currentTime: " + streamUrl); LOGGER.info("currentTime: " + streamUrl);
double currentTime = 0; double currentTime = 0;
@ -597,6 +630,11 @@ public class DBController {
return currentTime; return currentTime;
} }
/**
* save the currentTime to the database
* @param streamUrl URL of the film
* @param currentTime currentTime in ms of the film
*/
public void setCurrentTime(String streamUrl, double currentTime) { public void setCurrentTime(String streamUrl, double currentTime) {
LOGGER.info("currentTime: " + streamUrl); LOGGER.info("currentTime: " + streamUrl);
try { try {
@ -609,12 +647,18 @@ public class DBController {
} }
} }
public String getNextEpisode(String streamUrl, int nextEp) { /**
* get the next episode of a
* @param title URL of the film
* @param nextEp number of the next episode
* @return {@link String} the streamUrl of the next episode
*/
public String getNextEpisode(String title, int nextEp) {
String nextStreamUrl = ""; String nextStreamUrl = "";
try { try {
Statement stmt = connection.createStatement(); Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery( ResultSet rs = stmt.executeQuery(
"SELECT * FROM films WHERE streamUrl = \"" + streamUrl + "\" AND episode = " + nextEp + ";"); "SELECT * FROM films WHERE title = \"" + title + "\" AND episode = " + nextEp + ";");
nextStreamUrl = rs.getString("streamUrl"); nextStreamUrl = rs.getString("streamUrl");
rs.close(); rs.close();
stmt.close(); stmt.close();
@ -624,7 +668,6 @@ public class DBController {
return nextStreamUrl; return nextStreamUrl;
} }
// removes the ending // removes the ending
private String cutOffEnd(String str) { private String cutOffEnd(String str) {
if (str == null) return null; if (str == null) return null;

View File

@ -19,7 +19,6 @@
* MA 02110-1301, USA. * MA 02110-1301, USA.
* *
*/ */
package kellerkinder.HomeFlix.controller; package kellerkinder.HomeFlix.controller;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;

View File

@ -18,7 +18,6 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA. * MA 02110-1301, USA.
*/ */
package kellerkinder.HomeFlix.controller; package kellerkinder.HomeFlix.controller;
import java.io.BufferedReader; import java.io.BufferedReader;

View File

@ -18,7 +18,6 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA. * MA 02110-1301, USA.
*/ */
package kellerkinder.HomeFlix.datatypes; package kellerkinder.HomeFlix.datatypes;
import javafx.beans.property.BooleanProperty; import javafx.beans.property.BooleanProperty;
@ -36,7 +35,6 @@ public class FilmTabelDataType {
private final BooleanProperty favorite = new SimpleBooleanProperty(); private final BooleanProperty favorite = new SimpleBooleanProperty();
private final BooleanProperty cached = new SimpleBooleanProperty(); private final BooleanProperty cached = new SimpleBooleanProperty();
private final SimpleObjectProperty<ImageView> image = new SimpleObjectProperty<>(); private final SimpleObjectProperty<ImageView> image = new SimpleObjectProperty<>();
/** /**
* tableData is the data-type of tree-table-view * tableData is the data-type of tree-table-view

View File

@ -18,7 +18,6 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA. * MA 02110-1301, USA.
*/ */
package kellerkinder.HomeFlix.datatypes; package kellerkinder.HomeFlix.datatypes;
import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.SimpleStringProperty;

View File

@ -1,6 +1,26 @@
/**
* Project-HomeFlix
*
* Copyright 2016-2018 <@Seil0>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
*/
package kellerkinder.HomeFlix.player; 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.Parent;
@ -19,6 +39,12 @@ public class Player {
private AnchorPane pane; private AnchorPane pane;
private Scene scene; private Scene scene;
/**
* generate a new PlayerWindow
* @param file the file you want to play
* @param currentEp the current episode (needed for autoplay)
* @param dbController the dbController object
*/
public Player(String file, String currentEp, DBController dbController) { public Player(String file, String currentEp, DBController dbController) {
try { try {
FXMLLoader fxmlLoader = new FXMLLoader(ClassLoader.getSystemResource("fxml/PlayerWindow.fxml")); FXMLLoader fxmlLoader = new FXMLLoader(ClassLoader.getSystemResource("fxml/PlayerWindow.fxml"));

View File

@ -1,3 +1,24 @@
/**
* Project-HomeFlix
*
* Copyright 2016-2018 <@Seil0>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
*/
package kellerkinder.HomeFlix.player; package kellerkinder.HomeFlix.player;
import java.io.File; import java.io.File;
@ -69,6 +90,13 @@ public class PlayerController {
private ImageView fullscreen_black = new ImageView(new Image("icons/ic_fullscreen_black_24dp_1x.png")); private ImageView fullscreen_black = new ImageView(new Image("icons/ic_fullscreen_black_24dp_1x.png"));
private ImageView fullscreen_exit_black = new ImageView(new Image("icons/ic_fullscreen_exit_black_24dp_1x.png")); private ImageView fullscreen_exit_black = new ImageView(new Image("icons/ic_fullscreen_exit_black_24dp_1x.png"));
/**
* initialize the new PlayerWindow
* @param file the file you want to play
* @param currentEp the current episode (needed for autoplay)
* @param player the player object (needed for closing action)
* @param dbController the dbController object
*/
public void init(String file, String currentEp, Player player, DBController dbController) { public void init(String file, String currentEp, Player player, DBController dbController) {
this.file = file; this.file = file;
this.player = player; this.player = player;
@ -113,7 +141,7 @@ public class PlayerController {
if (duration - currentTime < 10000) { if (duration - currentTime < 10000) {
if (nextEp != 0) { if (nextEp != 0) {
dbController.getNextEpisode(file, nextEp); dbController.getNextEpisode(new File(file).getName(), nextEp);
System.out.println("next episode is: " + dbController.getNextEpisode(file, nextEp)); System.out.println("next episode is: " + dbController.getNextEpisode(file, nextEp));
} else { } else {
if (duration - currentTime < 100) { if (duration - currentTime < 100) {
@ -135,6 +163,9 @@ public class PlayerController {
fullscreenBtn.setGraphic(fullscreen_exit_black); fullscreenBtn.setGraphic(fullscreen_exit_black);
} }
/**
* initialize some PlayerWindow GUI-Elements actions
*/
private void initActions() { private void initActions() {
player.getScene().addEventFilter(MouseEvent.MOUSE_MOVED, new EventHandler<MouseEvent>() { player.getScene().addEventFilter(MouseEvent.MOUSE_MOVED, new EventHandler<MouseEvent>() {

View File

@ -18,7 +18,6 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA. * MA 02110-1301, USA.
*/ */
package org.kellerkinder.Alerts; package org.kellerkinder.Alerts;
import com.jfoenix.controls.JFXAlert; import com.jfoenix.controls.JFXAlert;

View File

@ -18,7 +18,6 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA. * MA 02110-1301, USA.
*/ */
package org.kellerkinder.Alerts; package org.kellerkinder.Alerts;
import com.jfoenix.controls.JFXAlert; import com.jfoenix.controls.JFXAlert;