diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..0499fc0 --- /dev/null +++ b/.classpath @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/.gitignore b/.gitignore index cd2946a..3dd2f04 100644 --- a/.gitignore +++ b/.gitignore @@ -45,3 +45,6 @@ $RECYCLE.BIN/ Network Trash Folder Temporary Items .apdisk +ProjectHomeFlix.jar +jfoenix.jar +minimal-json-0.9.4.jar diff --git a/.project b/.project new file mode 100644 index 0000000..5457f9b --- /dev/null +++ b/.project @@ -0,0 +1,23 @@ + + + Project HomeFlix + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.xtext.ui.shared.xtextBuilder + + + + + + org.eclipse.xtext.ui.shared.xtextNature + org.eclipse.jdt.core.javanature + + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..3a21537 --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/bin/Homeflix_Icon_64x64.png b/bin/Homeflix_Icon_64x64.png new file mode 100644 index 0000000..64787d6 Binary files /dev/null and b/bin/Homeflix_Icon_64x64.png differ diff --git a/bin/Homeflix_Poster.png b/bin/Homeflix_Poster.png new file mode 100644 index 0000000..9f2aa98 Binary files /dev/null and b/bin/Homeflix_Poster.png differ diff --git a/bin/application/DBController$1.class b/bin/application/DBController$1.class new file mode 100644 index 0000000..6925686 Binary files /dev/null and b/bin/application/DBController$1.class differ diff --git a/bin/application/DBController.class b/bin/application/DBController.class new file mode 100644 index 0000000..006445c Binary files /dev/null and b/bin/application/DBController.class differ diff --git a/bin/application/HomeFlix-Local_de_DE.properties b/bin/application/HomeFlix-Local_de_DE.properties new file mode 100644 index 0000000..50ed795 --- /dev/null +++ b/bin/application/HomeFlix-Local_de_DE.properties @@ -0,0 +1,15 @@ +# HomeFlix-Local_de_DE.properties German Local +info = Info +settings = Einstellungen +play = play +openFolder = Ordner \u00F6ffnen +chooseFolder = Ordner auswählen +fontSize = Schriftgr\u00F6\u00DFe: +checkUpdates = Auf Update pr\u00FCfen +autoUpdate = beim Start nach Updates suchen: +version = Version: +columnName = Name +columnRating = Bewertung +columnDatName = Datei Name +errorUpdate = Es ist ein Fehler aufgetreten! \n Um Hilfe zu erhalten besuchen Sie \nwww.kellerkinder.xyz oder support@kellerkinder.xyz +infoText = \nMaintainer: seilo@kellerkinder.xyz und \nhendrik.schutter@coptersicht.de \n(c) 2016 Kellerkinder www.kellerkinder.xyz \ No newline at end of file diff --git a/bin/application/HomeFlix-Local_en_US.properties b/bin/application/HomeFlix-Local_en_US.properties new file mode 100644 index 0000000..25a9919 --- /dev/null +++ b/bin/application/HomeFlix-Local_en_US.properties @@ -0,0 +1,15 @@ +# HomeFlix-Local_en_US.properties US-English Local and default +info = Info +settings = Settings +play = play +openFolder = open Folder +chooseFolder = choose Directory +fontSize = font size: +checkUpdates = check for updates +autoUpdate = check at startup for updates: +version = Version: +columnName = Name +columnRating = Rating +columnDatName = File Name +errorUpdate = An error has occurred! \n To get help, visit \n nwww.kellerkinder.xyz or support@kellerkinder.xyz +infoText = \nMaintainer: seilo@kellerkinder.xyz and \nhendrik.schutter@coptersicht.de \n(c) 2016 Kellerkinder www.kellerkinder.xyz \ No newline at end of file diff --git a/bin/application/Main.class b/bin/application/Main.class new file mode 100644 index 0000000..a83a966 Binary files /dev/null and b/bin/application/Main.class differ diff --git a/bin/application/MainWindow.fxml b/bin/application/MainWindow.fxml new file mode 100644 index 0000000..e44b558 --- /dev/null +++ b/bin/application/MainWindow.fxml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/bin/application/MainWindowController$1.class b/bin/application/MainWindowController$1.class new file mode 100644 index 0000000..7f2237a Binary files /dev/null and b/bin/application/MainWindowController$1.class differ diff --git a/bin/application/MainWindowController$2$1.class b/bin/application/MainWindowController$2$1.class new file mode 100644 index 0000000..f20a801 Binary files /dev/null and b/bin/application/MainWindowController$2$1.class differ diff --git a/bin/application/MainWindowController$2$2.class b/bin/application/MainWindowController$2$2.class new file mode 100644 index 0000000..20a7145 Binary files /dev/null and b/bin/application/MainWindowController$2$2.class differ diff --git a/bin/application/MainWindowController$2$3.class b/bin/application/MainWindowController$2$3.class new file mode 100644 index 0000000..7c34a8b Binary files /dev/null and b/bin/application/MainWindowController$2$3.class differ diff --git a/bin/application/MainWindowController$2$4.class b/bin/application/MainWindowController$2$4.class new file mode 100644 index 0000000..b91a643 Binary files /dev/null and b/bin/application/MainWindowController$2$4.class differ diff --git a/bin/application/MainWindowController$2$5.class b/bin/application/MainWindowController$2$5.class new file mode 100644 index 0000000..e670191 Binary files /dev/null and b/bin/application/MainWindowController$2$5.class differ diff --git a/bin/application/MainWindowController$2$6.class b/bin/application/MainWindowController$2$6.class new file mode 100644 index 0000000..8f4224d Binary files /dev/null and b/bin/application/MainWindowController$2$6.class differ diff --git a/bin/application/MainWindowController$2.class b/bin/application/MainWindowController$2.class new file mode 100644 index 0000000..9769d9c Binary files /dev/null and b/bin/application/MainWindowController$2.class differ diff --git a/bin/application/MainWindowController$3.class b/bin/application/MainWindowController$3.class new file mode 100644 index 0000000..b3eb020 Binary files /dev/null and b/bin/application/MainWindowController$3.class differ diff --git a/bin/application/MainWindowController$4.class b/bin/application/MainWindowController$4.class new file mode 100644 index 0000000..91832b3 Binary files /dev/null and b/bin/application/MainWindowController$4.class differ diff --git a/bin/application/MainWindowController$5.class b/bin/application/MainWindowController$5.class new file mode 100644 index 0000000..1380ab2 Binary files /dev/null and b/bin/application/MainWindowController$5.class differ diff --git a/bin/application/MainWindowController$6.class b/bin/application/MainWindowController$6.class new file mode 100644 index 0000000..57aa192 Binary files /dev/null and b/bin/application/MainWindowController$6.class differ diff --git a/bin/application/MainWindowController.class b/bin/application/MainWindowController.class new file mode 100644 index 0000000..1cab0b0 Binary files /dev/null and b/bin/application/MainWindowController.class differ diff --git a/bin/application/application.css b/bin/application/application.css new file mode 100644 index 0000000..83d6f33 --- /dev/null +++ b/bin/application/application.css @@ -0,0 +1 @@ +/* JavaFX CSS - Leave this comment until you have at least create one rule which uses -fx-Property */ \ No newline at end of file diff --git a/bin/application/uiData.class b/bin/application/uiData.class new file mode 100644 index 0000000..9b06b70 Binary files /dev/null and b/bin/application/uiData.class differ diff --git a/bin/menu_icon_black.png b/bin/menu_icon_black.png new file mode 100644 index 0000000..19711de Binary files /dev/null and b/bin/menu_icon_black.png differ diff --git a/build.fxbuild b/build.fxbuild new file mode 100644 index 0000000..a7511ff --- /dev/null +++ b/build.fxbuild @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/config.xml b/config.xml new file mode 100644 index 0000000..ada16c4 --- /dev/null +++ b/config.xml @@ -0,0 +1,10 @@ + + + +Project HomeFlix settings +ee3523 +0 +12.0 +1 +C:\Users\Jannik\Videos\Beispielfilme + diff --git a/src/Homeflix_Icon_64x64.png b/src/Homeflix_Icon_64x64.png new file mode 100644 index 0000000..64787d6 Binary files /dev/null and b/src/Homeflix_Icon_64x64.png differ diff --git a/src/Homeflix_Poster.png b/src/Homeflix_Poster.png new file mode 100644 index 0000000..9f2aa98 Binary files /dev/null and b/src/Homeflix_Poster.png differ diff --git a/src/application/DBController.java b/src/application/DBController.java new file mode 100644 index 0000000..958eb0a --- /dev/null +++ b/src/application/DBController.java @@ -0,0 +1,216 @@ +package application; + +import java.sql.Connection; //für Datenbank +import java.sql.DriverManager; //für Datenbank +import java.sql.PreparedStatement; //für Datenbank +import java.sql.ResultSet; //für Datenbank +import java.sql.SQLException; //für Datenbank +import java.sql.Statement; //für Datenbank +import java.io.File;//für Dateien einlesen + +class DBController { + + @SuppressWarnings("unused") + private MainWindowController mainWindowController; + private static final DBController dbcontroller = new DBController(); + private static Connection connection; + private static final String DB_PATH = System.getProperty("user.dir") + "/" + "Homeflix.db"; // der Pfad der Datenbank-Datei + private String path; + File f; + File file[]; //ArrayList für die Dateien + + static { + try { + Class.forName("org.sqlite.JDBC"); //Datenbanktreiber + } catch (ClassNotFoundException e) { + System.err.println("Fehler beim Laden des JDBC-Treibers"); + e.printStackTrace(); + } + } + + public static void main(String input) { + DBController datenbank = DBController.getInstance(); //neues Datenbank-Objekt wird erstellt + datenbank.setPath(input); // Pfad zuweisen + datenbank.f = new File(datenbank.getPath()); // für Datenbank-Datei einlesen + datenbank.file = datenbank.f.listFiles(); // für Datenbank-Datei einlesen + datenbank.verbindeDatenbank(); + datenbank.fuelleDatenbank(); + //datenbank.defavorisieren("Frozen"); + //datenbank.favorisieren("Frozen"); + //datenbank.ausgebenTitel(); + //System.out.println("Pfad: " + datenbank.getPfad("Frozen")); + //System.out.println("Bewertung: " + datenbank.getFavStatus("Frozen")); + } + + DBController(){ + } + + private static DBController getInstance(){ + return dbcontroller; + } +// Die Datenbak wird mit Hilfe des JDBC-Treibers eingebunden + public void verbindeDatenbank() { + try { + if (connection != null) + return; + System.out.println("Erstelle Verbindung zur Datenbank..."); + connection = DriverManager.getConnection("jdbc:sqlite:" + DB_PATH); + if (!connection.isClosed()) + System.out.println("...Verbindung hergestellt"); + } catch (SQLException e) { + throw new RuntimeException(e); + } + + Runtime.getRuntime().addShutdownHook(new Thread() { + public void run() { + try { + if (!connection.isClosed() && connection != null) { + connection.close(); + if (connection.isClosed()) + System.out.println("Verbindung getrennt"); + } + } catch (SQLException e) { + e.printStackTrace(); + } + } + }); + } +// Die Dateien werden in die Datenbank geschrieben + public void fuelleDatenbank() { + + try { + System.out.println("Erstelle Einträge"); + Statement stmt = connection.createStatement(); + stmt.executeUpdate("DROP TABLE IF EXISTS filme;"); + stmt.executeUpdate("CREATE TABLE filme (titel, pfad, bewertung);"); // Tabelle "filme" und die Spalten "titel", "pfad", "bewertung" erstellen + + PreparedStatement ps = connection.prepareStatement("INSERT INTO filme VALUES (?, ?, ?);"); // SQL Befehl + + //System.out.println(file.length); + + for(int i=0;i!=file.length;i++) // Geht alle Dateien im Verzeichniss durch + { + //System.out.println(file[i].getName()); + ps.setString(1, ohneEndung(file[i].getName())); // definiert Name als String in der ersten Spalte + ps.setString(2,file[i].getName()); // definiert Pfad als String in der zweiten Spalte + ps.setInt(3, 0); // definiert Bewertung als Integer in der dritten Spalte + ps.addBatch(); // fügt den Eintrag hinzu + } + + connection.setAutoCommit(false); + ps.executeBatch(); // scheibt alle Einträge in die Datenbank + connection.setAutoCommit(true); + //connection.close(); + } catch (SQLException e) { + System.err.println("Konnte nicht ausgeführt werden"); + e.printStackTrace(); + } + } + + public void ausgeben(){ + System.out.println("Einträge ausgeben"); + try { + Statement stmt = connection.createStatement(); + mainWindowController = new MainWindowController(); + ResultSet rs = stmt.executeQuery("SELECT * FROM filme;"); + while (rs.next()) { +// MainWindowController mainWindowController = new MainWindowController(); + } + //rs.close(); +// mainWindowController.initTabel(); + + + } catch (SQLException e) { + System.err.println("Konnte nicht ausgeführt werden"); + e.printStackTrace(); + } + + + } +// Kontroll Methode, ob ein Film wirklich in der Datenbank ist + public String getTitel(String name){ + try { + Statement stmt = connection.createStatement(); + ResultSet rs = stmt.executeQuery("SELECT titel, pfad FROM filme WHERE titel = '"+name+"';" ); + return rs.getString("titel"); + } catch (SQLException e) { + System.err.println("Konnte nicht ausgeführt werden"); + e.printStackTrace(); + } + return "Error 404"; + } +// gibt den Pfad eines bestimmten Films + public String getPfad(String name){ + try { + Statement stmt = connection.createStatement(); + ResultSet rs = stmt.executeQuery("SELECT titel, pfad FROM filme WHERE titel = '"+name+"';" ); //SQL Befehl + return rs.getString("pfad"); + } catch (SQLException e) { + System.err.println("Konnte nicht ausgeführt werden"); + e.printStackTrace(); + } + return "Error 404"; + } +// gibt die Favorisierung eines bestimmten Films + public boolean getFavStatus(String name){ + try { + Statement stmt = connection.createStatement(); + ResultSet rs = stmt.executeQuery("SELECT titel, bewertung FROM filme WHERE titel = '"+name+"';" ); //SQL Befehl + System.out.println(rs.getInt("bewertung")); + if((rs.getInt("bewertung")) == 1){ + return true; + } + else{ + return false; + } + } catch (SQLException e) { + System.err.println("Konnte nicht ausgeführt werden"); + e.printStackTrace(); + return false; + } + } +// setzt die Defavorisierung eines bestimmten Films + public void defavorisieren(String name){ + System.out.println("setze Bewertung"); + try { + Statement stmt = connection.createStatement(); + String sql = ("UPDATE filme SET bewertung=0 WHERE titel='"+name+"';"); //SQL Befehl + stmt.executeUpdate(sql); + connection.setAutoCommit(false); + connection.setAutoCommit(true); + } catch (SQLException e) { + System.err.println("Konnte nicht ausgeführt werden"); + e.printStackTrace(); + } + } +// setzt die Favorisierung eines bestimmten Films + public void favorisieren(String name){ + System.out.println("setze Bewertung"); + try { + Statement stmt = connection.createStatement(); + String sql = ("UPDATE filme SET bewertung=1 WHERE titel='"+name+"';"); //SQL Befehl + stmt.executeUpdate(sql); + connection.setAutoCommit(false); + connection.setAutoCommit(true); + } catch (SQLException e) { + System.err.println("Konnte nicht ausgeführt werden"); + e.printStackTrace(); + } + } +//entfernt die Endung + private static String ohneEndung (String str) { + + if (str == null) return null; + int pos = str.lastIndexOf("."); + if (pos == -1) return str; + return str.substring(0, pos); + } + + public String getPath() { + return path; + } + + public void setPath(String path) { + this.path = path.replace("\\", "\\\\"); + } +} diff --git a/src/application/HomeFlix-Local_de_DE.properties b/src/application/HomeFlix-Local_de_DE.properties new file mode 100644 index 0000000..50ed795 --- /dev/null +++ b/src/application/HomeFlix-Local_de_DE.properties @@ -0,0 +1,15 @@ +# HomeFlix-Local_de_DE.properties German Local +info = Info +settings = Einstellungen +play = play +openFolder = Ordner \u00F6ffnen +chooseFolder = Ordner auswählen +fontSize = Schriftgr\u00F6\u00DFe: +checkUpdates = Auf Update pr\u00FCfen +autoUpdate = beim Start nach Updates suchen: +version = Version: +columnName = Name +columnRating = Bewertung +columnDatName = Datei Name +errorUpdate = Es ist ein Fehler aufgetreten! \n Um Hilfe zu erhalten besuchen Sie \nwww.kellerkinder.xyz oder support@kellerkinder.xyz +infoText = \nMaintainer: seilo@kellerkinder.xyz und \nhendrik.schutter@coptersicht.de \n(c) 2016 Kellerkinder www.kellerkinder.xyz \ No newline at end of file diff --git a/src/application/HomeFlix-Local_en_US.properties b/src/application/HomeFlix-Local_en_US.properties new file mode 100644 index 0000000..25a9919 --- /dev/null +++ b/src/application/HomeFlix-Local_en_US.properties @@ -0,0 +1,15 @@ +# HomeFlix-Local_en_US.properties US-English Local and default +info = Info +settings = Settings +play = play +openFolder = open Folder +chooseFolder = choose Directory +fontSize = font size: +checkUpdates = check for updates +autoUpdate = check at startup for updates: +version = Version: +columnName = Name +columnRating = Rating +columnDatName = File Name +errorUpdate = An error has occurred! \n To get help, visit \n nwww.kellerkinder.xyz or support@kellerkinder.xyz +infoText = \nMaintainer: seilo@kellerkinder.xyz and \nhendrik.schutter@coptersicht.de \n(c) 2016 Kellerkinder www.kellerkinder.xyz \ No newline at end of file diff --git a/src/application/Main.java b/src/application/Main.java new file mode 100644 index 0000000..b7248c6 --- /dev/null +++ b/src/application/Main.java @@ -0,0 +1,148 @@ +/** + * Project HomeFlix + * + * Copyright 2016 + * + * 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 application; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.Optional; +import java.util.Properties; + +import javafx.application.Application; +import javafx.fxml.FXMLLoader; +import javafx.scene.Scene; +import javafx.scene.control.Alert; +import javafx.scene.control.Alert.AlertType; +import javafx.scene.control.ButtonType; +import javafx.scene.image.Image; +import javafx.scene.layout.AnchorPane; +import javafx.scene.paint.Color; +import javafx.stage.DirectoryChooser; +import javafx.stage.Stage; + +public class Main extends Application { + + public Stage primaryStage; + private String path; + private String color = "ee3523"; + private String autoUpdate = "0"; + private double size = 12; + private int local = 0; + Properties props = new Properties(); + private MainWindowController mainWindowController; + + @Override + public void start(Stage primaryStage) { + this.primaryStage = primaryStage; + mainWindow(); + } + + public void mainWindow(){ + File file = new File("config.xml"); + try { + FXMLLoader loader = new FXMLLoader(Main.class.getResource("MainWindow.fxml")); + AnchorPane pane = loader.load(); + primaryStage.setMinHeight(600.00); + primaryStage.setMinWidth(900.00); + primaryStage.setResizable(false); + primaryStage.setTitle("Project HomeFlix"); + primaryStage.getIcons().add(new Image(Main.class.getResourceAsStream("/Homeflix_Icon_64x64.png"))); //fügt Anwendungsicon hinzu + + + mainWindowController = loader.getController(); //verknüpfung von FXMLController und Controller Klasse + mainWindowController.setAutoUpdate(autoUpdate); //setzt autoupdate + mainWindowController.setMain(this); //aufruf setMain + + //prüft ob config.xml vorhanden, wenn nicht hole Pfad und schreibe Daten in Controller + if (file.exists() != true) { + mainWindowController.setPath(firstStart()); + mainWindowController.setColor(color); + mainWindowController.setSize(size); + mainWindowController.setAutoUpdate(autoUpdate); + mainWindowController.setLoaclUI(local); + mainWindowController.saveSettings(); + Runtime.getRuntime().exec("java -jar ProjectHomeFlix.jar"); //starte neu um Bugs zu verhindern + System.exit(0); //beendet sich selbst + }else{ + loadSettings(); + } + + mainWindowController.applyColor(); //setzt die Theme Farbe + mainWindowController.cbLocal.getSelectionModel().select(mainWindowController.getLocal()); //setzt local + mainWindowController.mainColor.setValue(Color.valueOf(mainWindowController.getColor())); + mainWindowController.loadData(); //läd die Daten im Controller + + Scene scene = new Scene(pane); //neue Scen um inhalt der stage anzuzeigen + + primaryStage.setScene(scene); + primaryStage.show(); //zeige scene + } catch (IOException e) { + // Auto-generated catch block + e.printStackTrace(); + } + } + + //methode für den erstmaligen Start + private String firstStart(){ + Alert alert = new Alert(AlertType.CONFIRMATION); //neuer alert mit filechooser + alert.setTitle("Project HomeFlix"); + alert.setHeaderText("Es ist kein Stammverzeichniss für Filme angegeben!"); + alert.setContentText("Stammverzeichniss angeben?"); + + Optional result = alert.showAndWait(); + if (result.get() == ButtonType.OK){ + DirectoryChooser directoryChooser = new DirectoryChooser(); + File selectedDirectory = + directoryChooser.showDialog(primaryStage); + path = selectedDirectory.getAbsolutePath(); + + } else { + path = ""; + } + return path; + } + + //lädt die einstellungen aus der XML + public void loadSettings(){ + File configFile = new File("config.xml"); + try { + InputStream inputStream = new FileInputStream(configFile); + props.loadFromXML(inputStream); + path = props.getProperty("path"); + color = props.getProperty("color"); + autoUpdate = props.getProperty("autoUpdate"); + size = Double.parseDouble(props.getProperty("size")); + local = Integer.parseInt(props.getProperty("local")); + + inputStream.close(); + } catch (IOException e) { + // Auto-generated catch block + e.printStackTrace(); + } + } + + + public static void main(String[] args) { + launch(args); + } +} \ No newline at end of file diff --git a/src/application/MainWindow.fxml b/src/application/MainWindow.fxml new file mode 100644 index 0000000..e44b558 --- /dev/null +++ b/src/application/MainWindow.fxml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/application/MainWindowController.java b/src/application/MainWindowController.java new file mode 100644 index 0000000..cc4e46c --- /dev/null +++ b/src/application/MainWindowController.java @@ -0,0 +1,854 @@ +/** + * Project HomeFlix + * + * Copyright 2016 + * + * 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 application; + +import java.awt.Desktop; +import java.io.BufferedReader; +import java.io.DataInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.math.BigInteger; +import java.net.URL; +import java.nio.channels.Channels; +import java.nio.channels.ReadableByteChannel; +import java.util.Locale; +import java.util.Properties; +import java.util.ResourceBundle; +import java.util.Scanner; + +import com.eclipsesource.json.Json; +import com.eclipsesource.json.JsonObject; +import com.jfoenix.controls.JFXButton; +import com.jfoenix.controls.JFXColorPicker; +import com.jfoenix.controls.JFXDialog; +import com.jfoenix.controls.JFXSlider; +import com.jfoenix.controls.JFXTextArea; +import com.jfoenix.controls.JFXTextField; +import com.jfoenix.controls.JFXToggleButton; + +import javafx.beans.property.ReadOnlyObjectWrapper; +import javafx.beans.property.ReadOnlyStringWrapper; +import javafx.beans.value.ChangeListener; +import javafx.beans.value.ObservableValue; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; +import javafx.event.ActionEvent; +import javafx.event.EventHandler; +import javafx.fxml.FXML; +import javafx.geometry.Insets; +import javafx.scene.control.Alert; +import javafx.scene.control.Alert.AlertType; +import javafx.scene.control.ChoiceBox; +import javafx.scene.control.Label; +import javafx.scene.control.TreeItem; +import javafx.scene.control.TreeTableColumn; +import javafx.scene.control.TreeTableColumn.CellDataFeatures; +import javafx.scene.control.TreeTableView; +import javafx.scene.image.Image; +import javafx.scene.image.ImageView; +import javafx.scene.layout.AnchorPane; +import javafx.scene.layout.VBox; +import javafx.scene.paint.Color; +import javafx.scene.text.Font; +import javafx.scene.text.FontWeight; +import javafx.stage.DirectoryChooser; + +public class MainWindowController { + @FXML + private AnchorPane anpane; + @FXML + private AnchorPane settingsan = new AnchorPane(); + @FXML + private VBox topVBox; + @FXML + private VBox menuBox = new VBox(); + @FXML + private VBox settingsBox = new VBox(); + @FXML + private TreeTableView treeTableViewfilm; + @FXML + private JFXTextArea ta1; + @FXML + private JFXButton menubtn; + @FXML + private JFXButton playbtn; + @FXML + private JFXButton openfolderbtn; + @FXML + private JFXButton returnBtn; + @FXML + private JFXButton forwardBtn; + @FXML + private JFXButton infoBtn = new JFXButton("Info"); + @FXML + private JFXButton demoBtn = new JFXButton("Beheben"); + @FXML + private JFXButton settingsBtn = new JFXButton("Settings"); + @FXML + private JFXButton updateBtn = new JFXButton("Auf Update prüfen"); + @FXML + private JFXButton directoryBtn = new JFXButton("Ordner auswählen"); + @FXML + private JFXToggleButton autoupdateBtn = new JFXToggleButton(); + @FXML + public JFXTextField tfPfad = new JFXTextField(); + @FXML + private JFXTextField tfsearch; + @FXML + public JFXColorPicker mainColor = new JFXColorPicker(); + @FXML + public ChoiceBox cbLocal = new ChoiceBox(); + @FXML + public JFXSlider sl1 = new JFXSlider(); + @FXML + private JFXDialog dialog = new JFXDialog(); + @FXML + private Label versionlbl = new Label(); + @FXML + private Label sizelbl = new Label("Schriftgröße:"); + @FXML + private Label aulbl = new Label("beim starten nach Updates suchen:"); + @FXML + private ImageView image1; + + @FXML + TreeItem root = new TreeItem<>(new uiData(1.0, "filme","1")); + @FXML + TreeTableColumn columnRating = new TreeTableColumn<>("Bewertung"); + @FXML + TreeTableColumn columnName = new TreeTableColumn<>("Name"); + @FXML + TreeTableColumn columnDatName = new TreeTableColumn<>("Datei Name"); + + private boolean menutrue = false; //merker für menubtn (öffnen oder schließen) + private boolean settingstrue = false; + private String version = "0.3.5"; + private String versionURL = "https://raw.githubusercontent.com/Seil0/Project-HomeFlix/master/version"; + private String downloadLink = ""; + private String updateDataURL = "https://raw.githubusercontent.com/Seil0/Project-HomeFlix/master/ProjectHomeFlix.jar"; + + private String errorUpdate; + private String infoText; + private String aktVersion; + private String path; + private String color; + private String Name; + private String datPath; + private String autoUpdate; + private double size; + private int last; + private int selected; + private int next; + private int local; + private File selectedFolder; + private ResourceBundle bundle; + + private ObservableList newDaten = FXCollections.observableArrayList(); + private ObservableList filterData = FXCollections.observableArrayList(); + private ObservableList locals = FXCollections.observableArrayList("english", "deutsch"); + private Image imHF = new Image("Homeflix_Poster.png"); + private ImageView menu_icon_black = new ImageView(new Image("menu_icon_black.png")); +// private ImageView menu_icon_white = new ImageView(new Image("menu_icon_white.png")); + private DirectoryChooser directoryChooser = new DirectoryChooser(); + Properties props = new Properties(); + + //wenn menubtn clicked + /** + * TODO fix directory bug under linux + * TODO change value of Text-color change + * TODO menu icon white + */ + @FXML + private void menubtnclicked(){ + if(menutrue == false){ + anpane.getChildren().addAll(menuBox); + + //infobtn clicked + infoBtn.setOnAction(new EventHandler(){ + @Override + public void handle(ActionEvent event) { + Alert alert = new Alert(AlertType.INFORMATION); + alert.setTitle("Info"); + alert.setHeaderText("Project HomeFlix"); + alert.setContentText(infoText); + alert.showAndWait(); + } + }); + + //setteingsbtn clicked, deklarieren der actions der Objekte die bei settingsbtn angezeigt werden + settingsBtn.setOnAction(new EventHandler() { + @Override + public void handle(ActionEvent event){ + if(settingstrue == false){ + anpane.getChildren().addAll(settingsBox); + + tfPfad.setOnAction(new EventHandler(){ + @Override + public void handle(ActionEvent event){ + setPath(tfPfad.getText()); + saveSettings(); + } + }); + directoryBtn.setOnAction(new EventHandler() { + @Override + public void handle(ActionEvent event){ + selectedFolder = directoryChooser.showDialog(null); + if(selectedFolder == null){ + System.out.println("No Directory selected"); + }else{ + setPath(selectedFolder.getAbsolutePath()); + saveSettings(); + tfPfad.setText(getPath()); + try { + Runtime.getRuntime().exec("java -jar ProjectHomeFlix.jar"); //starte neu + System.exit(0); //beendet sich selbst + } catch (IOException e) { + System.out.println("es ist ein Fehler aufgetreten"); + e.printStackTrace(); + } + } + } + }); + mainColor.setOnAction(new EventHandler(){ + @Override + public void handle(ActionEvent event){ + editColor(mainColor.getValue().toString()); + applyColor(); + } + }); + sl1.valueProperty().addListener(new ChangeListener() { + @Override + public void changed(ObservableValue ov,Number old_val, Number new_val) { + setSize(sl1.getValue()); + ta1.setFont(Font.font("System", size)); + saveSettings(); + } + }); + + //updater + updateBtn.setOnAction(new EventHandler() { + @Override + public void handle(ActionEvent event){ + update(); + } + }); + autoupdateBtn.setOnAction(new EventHandler(){ + @Override + public void handle(ActionEvent event) { + if(autoUpdate.equals("0")){ + setAutoUpdate("1"); + saveSettings(); + }else{ + setAutoUpdate("0"); + saveSettings(); + } + } + }); + + settingstrue = true; + }else{ + anpane.getChildren().removeAll(settingsBox); + setPath(tfPfad.getText()); + saveSettings(); + settingstrue = false; + } + } + }); + + //demoBtn clicked + demoBtn.setOnAction(new EventHandler(){ + @Override + public void handle(ActionEvent event) { + /** + * TODO DBController + */ +// loadData(); + } + }); + + menutrue = true; + }else{ + anpane.getChildren().removeAll(menuBox); + menutrue = false; + } + if(settingstrue == true){ + anpane.getChildren().removeAll(settingsBox); + setPath(tfPfad.getText()); + saveSettings(); + settingstrue = false; + } + } + + @FXML + private void playbtnclicked(){ + try { + Desktop.getDesktop().open(new File(getPath()+"\\"+ datPath)); //öffnt die aktuell ausgewählte Datei + } catch (IOException e) { + // Auto-generated catch block + e.printStackTrace(); + } + } + + @FXML + private void openfolderbtnclicked(){ + try { + Desktop.getDesktop().open(new File(getPath())); //öffnet den aktuellen Pfad + } catch (IOException e) { + // Auto-generated catch block + e.printStackTrace(); + } + } + + @FXML + private void returnBtnclicked(){ + treeTableViewfilm.getSelectionModel().select(last); + } + + @FXML + private void forwardBtnclicked(){ + treeTableViewfilm.getSelectionModel().select(next); + } + + //"Main" Methode die beim start von der Klasse Main aufgerufen wird, initialiesirung der einzellnen UI-Objekte + @SuppressWarnings({ "static-access"}) + public void setMain(Main main) { + + loadSettings(); + initTabel(); + + infoBtn.setPrefWidth(130); + infoBtn.setPrefHeight(32); + infoBtn.setFont(Font.font("System", FontWeight.BOLD, 15)); + + settingsBtn.setPrefWidth(130); + settingsBtn.setPrefHeight(32); + settingsBtn.setFont(Font.font("System", FontWeight.BOLD, 15)); + + demoBtn.setPrefWidth(130); + demoBtn.setPrefHeight(32); + demoBtn.setFont(Font.font("System", FontWeight.BOLD, 15)); + demoBtn.setDisable(false); + + menubtn.setText(""); + menubtn.setMaxSize(32, 32); + + tfPfad.setPrefWidth(250); + tfPfad.setPromptText("Pfad"); + tfPfad.setText(getPath()); + + sl1.setMaxWidth(250); + sl1.setMin(2); + sl1.setMax(48); + sl1.setValue(getSize()); + + cbLocal.setItems(locals); + + updateBtn.setFont(Font.font("System", 12)); + + directoryBtn.setFont(Font.font("System", 12)); + directoryBtn.setMaxSize(180, 25); + + if(autoUpdate.equals("1")){ + autoupdateBtn.setSelected(true); + update(); + }else{ + autoupdateBtn.setSelected(false); + } + + versionlbl.setText("Version: "+version); + + menuBox.setSpacing(2.5); //Zeilenabstand + menuBox.setPadding(new Insets(2.5,0,0,2.5)); // abstand zum Rand + menuBox.getChildren().addAll(infoBtn, settingsBtn,demoBtn); + menuBox.setFillWidth(true); + + AnchorPane.setTopAnchor(menuBox, 33d); + AnchorPane.setBottomAnchor(menuBox, 0d); + + settingsBox.setStyle("-fx-background-color: #FFFFFF;"); + settingsBox.getChildren().add(settingsan); + + settingsan.getChildren().addAll(tfPfad, directoryBtn, mainColor, sizelbl, sl1, cbLocal, updateBtn, aulbl, autoupdateBtn, versionlbl); + + settingsan.setTopAnchor(tfPfad, 5d); + settingsan.setLeftAnchor(tfPfad, 5d); + + settingsan.setTopAnchor(directoryBtn, 5d); + settingsan.setLeftAnchor(directoryBtn, 260d); + + settingsan.setTopAnchor(mainColor, 40d); + settingsan.setLeftAnchor(mainColor, 5d); + + settingsan.setTopAnchor(sizelbl, 75d); + settingsan.setLeftAnchor(sizelbl, 5d); + + settingsan.setTopAnchor(sl1, 110d); + settingsan.setLeftAnchor(sl1, 5d); + + settingsan.setTopAnchor(cbLocal, 145d); + settingsan.setLeftAnchor(cbLocal, 5d); + + settingsan.setTopAnchor(updateBtn, 180d); + settingsan.setLeftAnchor(updateBtn, 5d); + + settingsan.setTopAnchor(aulbl, 215d); + settingsan.setLeftAnchor(aulbl, 5d); + + settingsan.setTopAnchor(autoupdateBtn, 230d); + settingsan.setLeftAnchor(autoupdateBtn, 5d); + + settingsan.setTopAnchor(versionlbl, 280d); + settingsan.setLeftAnchor(versionlbl, 5d); + + AnchorPane.setTopAnchor(settingsBox, 34d); + AnchorPane.setRightAnchor(settingsBox, 0d); + AnchorPane.setBottomAnchor(settingsBox, 0d); + AnchorPane.setLeftAnchor(settingsBox, 130d); + + ta1.setWrapText(true); + ta1.setEditable(false); + ta1.setFont(Font.font("System", getSize())); + + image1.setImage(imHF); + + tfsearch.textProperty().addListener(new ChangeListener() { + @SuppressWarnings("unchecked") + @Override + public void changed(ObservableValue observable,String oldValue, String newValue) { + int counter = newDaten.size(); + filterData.removeAll(filterData); + root.getChildren().remove(0,root.getChildren().size()); + + for(int i = 0; i < counter; i++){ + if(newDaten.get(i).getFilmName().toLowerCase().contains(tfsearch.getText().toLowerCase())){ + filterData.add(newDaten.get(i)); + } + } + + for(int i = 0; i < filterData.size(); i++){ + root.getChildren().addAll(new TreeItem(filterData.get(i))); //fügt daten zur Rootnode hinzu + } + } + }); + + cbLocal.getSelectionModel().selectedIndexProperty() + .addListener(new ChangeListener() { + public void changed(ObservableValue ov, Number value, Number new_value) { + setLocal(new_value.intValue()); + setLoaclUI(local); + saveSettings(); + } + }); + } + + //initialisierung der TreeTabelView + @SuppressWarnings("unchecked") + private void initTabel(){ + + root.setExpanded(true); + + columnRating.setMaxWidth(120); + columnName.setMaxWidth(240); + columnDatName.setMaxWidth(0); + + treeTableViewfilm.setRoot(root); + treeTableViewfilm.setColumnResizePolicy( TreeTableView.CONSTRAINED_RESIZE_POLICY ); + treeTableViewfilm.setShowRoot(false); + + //inhalt in Zelle schreiben + columnName.setCellValueFactory((CellDataFeatures p) -> + new ReadOnlyStringWrapper(p.getValue().getValue().getFilmName())); + + columnRating.setCellValueFactory((CellDataFeatures p) -> + new ReadOnlyObjectWrapper(p.getValue().getValue().getFilmBewertung())); + + columnDatName.setCellValueFactory((CellDataFeatures p) -> + new ReadOnlyStringWrapper(p.getValue().getValue().getDataName())); + + treeTableViewfilm.getColumns().addAll(columnName, columnRating, columnDatName); + + //Changelistener für TreeTable + treeTableViewfilm.getSelectionModel().selectedItemProperty().addListener(new ChangeListener() { + + @Override + public void changed(ObservableValue observable, Object oldVal, Object newVal) { + // last = selected; //für autoplay + selected = treeTableViewfilm.getSelectionModel().getSelectedIndex(); // holt aktuelles Item + last = selected - 1; + next = selected + 1; + Name = columnName.getCellData(selected); // holt Namen des Aktuelle Items aus der ColumnName + datPath = columnDatName.getCellData(selected); // holt den aktuellen Datei Pfad aus der ColumnDatName + ta1.setText(""); // löscht Text in ta1 + apiAbfrage(Name); // startet die api abfrage + ta1.positionCaret(0); // setzt die startposition des Cursors in + // ta1 + } + }); + + treeTableViewfilm.getColumns().get(2).setVisible(false); //blendet die Column mit den Dateinamen aus (wichtig um sie abzuspielen) + } + + //prüft auf Update und füht es gegebenenfalls aus + private void update(){ + + System.out.println("check for updates ..."); + try { + URL url = new URL(versionURL); //URL der Datei mit aktueller Versionsnummer + BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream())); + aktVersion = in.readLine(); //schreibt inputstream in String + in.close(); + } catch (IOException e1) { + // Auto-generated catch block + e1.printStackTrace(); + } + System.out.println("Version: "+version+", Update: "+aktVersion); + + //vergleicht die Versionsnummern, bei aktversion > version wird ein Update durchgrführt + int iversion = Integer.parseInt(version.replace(".", "")); + int iaktVersion = Integer.parseInt(aktVersion.replace(".", "")); + + if(iversion >= iaktVersion){ + updateBtn.setText("kein Update verfügbar"); + System.out.println("kein Update verfügbar"); + }else{ + updateBtn.setText("Update verfügbar"); + System.out.println("Update verfügbar"); + try { + URL website; + URL downloadURL = new URL(downloadLink); + BufferedReader in = new BufferedReader(new InputStreamReader(downloadURL.openStream())); + //updateDataURL = in.readLine(); + website = new URL(updateDataURL); //Update URL + ReadableByteChannel rbc = Channels.newChannel(website.openStream()); //öffnet neuen Stream/Channel + FileOutputStream fos = new FileOutputStream("ProjectHomeFlix.jar"); //neuer fileoutputstram für ProjectHomeFLix.jar + fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); //holt datei von 0 bis max größe + fos.close(); //schließt den fos (extrem wichtig!) + Runtime.getRuntime().exec("java -jar ProjectHomeFlix.jar"); //starte neu + System.exit(0); //beendet sich selbst + } catch (IOException e) { + //Falls ein Fehler auftritt (ungetestet) + e.printStackTrace(); + Alert alert = new Alert(AlertType.ERROR); + alert.setTitle("Error"); + alert.setHeaderText(""); + alert.setContentText(errorUpdate); + alert.showAndWait(); + e.printStackTrace(); + } + } + } + + //lädt die Daten im angegeben Ordner in newDaten + public void loadData(){ + if(getPath().equals("")||getPath().equals(null)){ + System.out.println("Kein Pfad angegeben"); //falls der Pfad null oder "" ist + }else{ + String[] entries = new File(getPath()).list(); + for(int i = 0; i < entries.length; i++){ + String titel = ohneEndung(entries[i]); + String data = entries[i]; + newDaten.add(new uiData(5.0, titel ,data)); + } + for(int i = 0; i < newDaten.size(); i++){ + root.getChildren().add(new TreeItem(newDaten.get(i))); //fügt daten zur Rootnode hinzu + } + } + } + + //entfernt die Endung vom String + private String ohneEndung (String str) { + if (str == null) return null; + int pos = str.lastIndexOf("."); + if (pos == -1) return str; + return str.substring(0, pos); + } + + //setzt die Farben für die UI-Elemente + public void applyColor(){ + String style = "-fx-background-color: #"+getColor()+";"; + String btnStyle = "-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 icolor = new BigInteger(getColor(),16); + BigInteger ccolor = new BigInteger("78909cff",16); + + menuBox.setStyle(style); + topVBox.setStyle(style); + tfsearch.setFocusColor(Color.valueOf(getColor())); + tfPfad.setFocusColor(Color.valueOf(getColor())); + + if(icolor.compareTo(ccolor) == -1){ + settingsBtn.setStyle("-fx-text-fill: WHITE;"); + infoBtn.setStyle("-fx-text-fill: WHITE;"); + demoBtn.setStyle("-fx-text-fill: WHITE;"); + directoryBtn.setStyle(btnStylewhite); + updateBtn.setStyle(btnStylewhite); + playbtn.setStyle(btnStylewhite); + openfolderbtn.setStyle(btnStylewhite); + returnBtn.setStyle(btnStylewhite); + forwardBtn.setStyle(btnStylewhite); +//TODO menubtn.setGraphic(menu_icon_white); + menubtn.setGraphic(menu_icon_black); + }else{ + settingsBtn.setStyle("-fx-text-fill: BLACK;"); + infoBtn.setStyle("-fx-text-fill: BLACK;"); + demoBtn.setStyle("-fx-text-fill: BLACK;"); + directoryBtn.setStyle(btnStyle); + updateBtn.setStyle(btnStyle); + playbtn.setStyle(btnStyle); + openfolderbtn.setStyle(btnStyle); + returnBtn.setStyle(btnStyle); + forwardBtn.setStyle(btnStyle); + menubtn.setGraphic(menu_icon_black); + } + } + + + + public void setLoaclUI(int local){ + switch(local){ + case 0: bundle = ResourceBundle.getBundle("application.HomeFlix-Local", Locale.US); //us_english + break; + case 1: bundle = ResourceBundle.getBundle("application.HomeFlix-Local", Locale.GERMAN); //german + break; + default:bundle = ResourceBundle.getBundle("application.HomeFlix-Local", Locale.US); //default local + break; + } + settingsBtn.setText(bundle.getString("settings")); + infoBtn.setText(bundle.getString("info")); + playbtn.setText(bundle.getString("play")); + openfolderbtn.setText(bundle.getString("openFolder")); + sizelbl.setText(bundle.getString("fontSize")); + updateBtn.setText(bundle.getString("checkUpdates")); + aulbl.setText(bundle.getString("autoUpdate")); + versionlbl.setText(bundle.getString("version")+" "+version); + columnName.setText(bundle.getString("columnName")); + columnRating.setText(bundle.getString("columnRating")); + columnDatName.setText(bundle.getString("columnDatName")); + errorUpdate = bundle.getString("errorUpdate"); + infoText = bundle.getString("version")+" "+version+bundle.getString("infoText"); + } + + //speichert die Einstellungen + public void saveSettings(){ + File configFile = new File("config.xml"); //neue Datei "config.xml" + try { + props.setProperty("path", getPath()); //setzt pfad in propselement + props.setProperty("color", getColor()); + props.setProperty("autoUpdate", getAutoUpdate()); + props.setProperty("size", getSize().toString()); + props.setProperty("local", Integer.toString(getLocal())); + OutputStream outputStream = new FileOutputStream(configFile); //neuer outputstream + props.storeToXML(outputStream, "Project HomeFlix settings"); + outputStream.close(); + } catch (IOException e) { + System.out.println("An error has occurred!"); + e.printStackTrace(); + } + } + + //lädt die Einstellungen + public void loadSettings(){ + File configFile = new File("config.xml"); + try { + InputStream inputStream = new FileInputStream(configFile); + props.loadFromXML(inputStream); + path = props.getProperty("path"); //setzt Propselement in Pfad + color = props.getProperty("color"); + size = Double.parseDouble(props.getProperty("size")); + autoUpdate = props.getProperty("autoUpdate"); + local = Integer.parseInt(props.getProperty("local")); + inputStream.close(); + } catch (IOException e) { + System.out.println("An error has occurred!"); + e.printStackTrace(); + } + } + + //getter Und setter + public void setColor(String input){ + this.color = input; + } + + public String getColor(){ + return color; + } + + //entfernt 0x von dem rückgabe wert des Colorpickers + private void editColor(String input){ + StringBuilder sb = new StringBuilder(input); + sb.delete(0, 2); + this.color = sb.toString(); + saveSettings(); + } + + public void setPath(String input){ + this.path = input; + } + + public String getPath(){ + return path; + } + + public void setSize(Double input){ + this.size = input; + } + + public Double getSize(){ + return size; + } + + public void setAutoUpdate(String input){ + this.autoUpdate = input; + } + + public String getAutoUpdate(){ + return autoUpdate; + } + + public void setLocal(int input){ + this.local = input; + } + + public int getLocal(){ + return local; + } + + //methode der API-Abfrage + @SuppressWarnings("deprecation") + private void apiAbfrage(String input){ + URL url = null; + Scanner sc = null; + String apiurl = "https://www.omdbapi.com/?"; //API URL + String moviename = null; + String dataurl = null; + String retdata = null; + InputStream is = null; + DataInputStream dis = null; + + try { + + // hohlen des Filmtitels + sc = new Scanner(System.in); + moviename = input; + + // für keinen oder "" Filmtitel + if (moviename == null || moviename.equals("")) { + System.out.println("No movie found"); + } + + //entfernen ungewolter leerzeichen + moviename = moviename.trim(); + + // ersetzen der Leerzeichen durch + für api-abfrage + moviename = moviename.replace(" ", "+"); + + //URL wird zusammengestellt abfragetypen: http,json,xml (muss json sein um späteres trennen zu ermöglichen) + dataurl = apiurl + "t=" + moviename + "&plot=full&r=json"; + + url = new URL(dataurl); + is = url.openStream(); + dis = new DataInputStream(is); + + // lesen der Daten aus dem Antwort Stream + while ((retdata = dis.readLine()) != null) { + //retdata in json object parsen und anschließend das json Objekt "zerschneiden" + System.out.println(retdata); + JsonObject object = Json.parse(retdata).asObject(); + String titel = object.getString("Title", ""); + String year = object.getString("Year", ""); + String rated = object.getString("Rated", ""); + String released = object.getString("Released", ""); + String runtime = object.getString("Runtime", ""); + String genre = object.getString("Genre", ""); + String director = object.getString("Director", ""); + String writer = object.getString("Writer", ""); + String actors = object.getString("Actors", ""); + String plot = object.getString("Plot", ""); + String language = object.getString("Language", ""); + String country = object.getString("Country", ""); + String awards = object.getString("Awards", ""); + String posterURL = object.getString("Poster", ""); + String metascore = object.getString("Metascore", ""); + String imdbRating = object.getString("imdbRating", ""); + @SuppressWarnings("unused") + String imdbVotes = object.getString("imdbVotes", ""); + @SuppressWarnings("unused") + String imdbID = object.getString("imdbID", ""); + String type = object.getString("Type", ""); + String response = object.getString("Response", ""); + + if(response.equals("False")){ + ta1.appendText("Kein Film mit diesem Titel gefunden!"); + Image im2 = new Image("http://publicdomainvectors.org/photos/jean_victor_balin_cross.png"); + image1.setImage(im2); + }else{ + //ausgabe des Textes in ta1 in jeweils neuer Zeile + ta1.appendText("Titel: "+titel+"\n"); + ta1.appendText("Jahr: "+ year+"\n"); + ta1.appendText("Einstufung: "+rated+"\n"); + ta1.appendText("Veröffentlicht am: "+released+"\n"); + ta1.appendText("Laufzeit: "+runtime+"\n"); + ta1.appendText("Genre: "+genre+"\n"); + ta1.appendText("Regisseur: "+director+"\n"); + ta1.appendText("Autor: "+writer+"\n"); + ta1.appendText("Schauspieler: "+actors+"\n"); + ta1.appendText("Beschreibung: "+plot+"\n"); + ta1.appendText("Original Sprache: "+language+"\n"); + ta1.appendText("Produktionsland: "+country+"\n"); + ta1.appendText("Auszeichnungen: "+awards+"\n"); + ta1.appendText("Metascore: "+metascore+"\n"); + ta1.appendText("imdb Bewertung: "+imdbRating+"\n"); + ta1.appendText("Type: "+type+"\n"); + + Image im1 = new Image(posterURL); + image1.setImage(im1); + } + } + + } catch (Exception e) { + System.out.println(e); + } finally { + try { + //schließt datainputStream, InputStream,Scanner + if (dis != null) { + dis.close(); + } + + if (is != null) { + is.close(); + } + + if (sc != null) { + sc.close(); + } + } catch (Exception e2) { + ; + } + } + } + +} diff --git a/src/application/application.css b/src/application/application.css new file mode 100644 index 0000000..83d6f33 --- /dev/null +++ b/src/application/application.css @@ -0,0 +1 @@ +/* JavaFX CSS - Leave this comment until you have at least create one rule which uses -fx-Property */ \ No newline at end of file diff --git a/src/application/uiData.java b/src/application/uiData.java new file mode 100644 index 0000000..f78b8d7 --- /dev/null +++ b/src/application/uiData.java @@ -0,0 +1,57 @@ +package application; + +import javafx.beans.property.DoubleProperty; +import javafx.beans.property.SimpleDoubleProperty; +import javafx.beans.property.SimpleStringProperty; +import javafx.beans.property.StringProperty; + +public class uiData { + + private DoubleProperty filmBewertung = new SimpleDoubleProperty(); + private StringProperty filmName = new SimpleStringProperty(); + private StringProperty dataName = new SimpleStringProperty(); + + //uiData ist der Typ der Daten in der TreeTabelView + public uiData (final Double filmBewertung, final String filmName, final String dataName) { + this.filmBewertung.set(filmBewertung); + this.filmName.set(filmName); + this.dataName.set(dataName); + } + + public Double getFilmBewertung() { + return filmBewertung.get(); + } + + public String getFilmName() { + return filmName.get(); + } + + public String getDataName() { + return dataName.get(); + } + + + public void setFilmBewertung(Double filmBewertung) { + this.filmBewertung.set(filmBewertung); + } + + public void setFilmName(String filmName) { + this.filmName.set(filmName); + } + + public void setDataName(StringProperty dataName) { + this.dataName = dataName; + } + + public DoubleProperty FilmBewertungProperty(){ + return filmBewertung; + } + + public StringProperty FilmNameProperty(){ + return filmName; + } + + public StringProperty DataNameProperty(){ + return dataName; + } +} diff --git a/src/menu_icon_black.png b/src/menu_icon_black.png new file mode 100644 index 0000000..19711de Binary files /dev/null and b/src/menu_icon_black.png differ