2016-08-14 15:17:14 +02:00
/ * *
* Project HomeFlix
*
* Copyright 2016 < admin @kellerkinder >
*
* 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 ;
2016-09-09 20:41:20 +02:00
import java.io.FileReader ;
2016-08-14 15:17:14 +02:00
import java.io.IOException ;
import java.io.InputStream ;
import java.io.InputStreamReader ;
import java.io.OutputStream ;
2016-11-12 15:02:55 +01:00
import java.io.PrintWriter ;
import java.io.StringWriter ;
2016-08-14 15:17:14 +02:00
import java.math.BigInteger ;
2016-09-09 20:41:20 +02:00
import java.net.URI ;
import java.net.URISyntaxException ;
2016-08-14 15:17:14 +02:00
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 ;
2016-08-15 18:36:57 +02:00
import org.apache.commons.lang3.SystemUtils ;
2016-08-14 15:17:14 +02:00
import com.eclipsesource.json.Json ;
2016-09-09 20:41:20 +02:00
import com.eclipsesource.json.JsonArray ;
2016-08-14 15:17:14 +02:00
import com.eclipsesource.json.JsonObject ;
2016-09-09 20:41:20 +02:00
import com.eclipsesource.json.JsonValue ;
2016-08-14 15:17:14 +02:00
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 ;
2016-10-10 16:55:26 +02:00
import javafx.animation.FadeTransition ;
import javafx.animation.ParallelTransition ;
import javafx.animation.TranslateTransition ;
2016-08-14 15:17:14 +02:00
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.fxml.FXML ;
import javafx.scene.control.Alert ;
import javafx.scene.control.Alert.AlertType ;
import javafx.scene.control.ChoiceBox ;
import javafx.scene.control.Label ;
2016-09-09 20:41:20 +02:00
import javafx.scene.control.TableColumn ;
import javafx.scene.control.TableView ;
2016-11-12 15:02:55 +01:00
import javafx.scene.control.TextArea ;
2016-08-14 15:17:14 +02:00
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 ;
2016-11-12 15:02:55 +01:00
import javafx.scene.layout.GridPane ;
2016-10-09 16:05:44 +02:00
import javafx.scene.layout.HBox ;
2016-11-12 15:02:55 +01:00
import javafx.scene.layout.Priority ;
2016-08-14 15:17:14 +02:00
import javafx.scene.layout.VBox ;
import javafx.scene.paint.Color ;
import javafx.scene.text.Font ;
import javafx.stage.DirectoryChooser ;
2016-10-10 16:55:26 +02:00
import javafx.util.Duration ;
2016-08-14 15:17:14 +02:00
public class MainWindowController {
@FXML
private AnchorPane anpane ;
@FXML
2016-10-09 18:35:55 +02:00
private AnchorPane settingsAnchor ;
2016-09-09 20:41:20 +02:00
@FXML
2016-10-09 18:35:55 +02:00
private AnchorPane streamingSettingsAnchor ;
2016-08-14 15:17:14 +02:00
@FXML
2016-10-09 16:05:44 +02:00
private HBox topHBox ;
2016-08-14 15:17:14 +02:00
@FXML
2016-10-09 16:05:44 +02:00
private VBox sideMenuVBox ;
2016-08-14 15:17:14 +02:00
@FXML
2016-09-09 20:41:20 +02:00
private TreeTableView < streamUiData > treeTableViewfilm ;
@FXML
2016-10-09 18:35:55 +02:00
private TableView < streamUiData > tableViewStreamingdata ;
2016-08-14 15:17:14 +02:00
@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
2016-10-09 16:05:44 +02:00
private JFXButton infoBtn ;
2016-08-14 15:17:14 +02:00
@FXML
2016-10-09 16:05:44 +02:00
private JFXButton settingsBtn ;
2016-08-14 15:17:14 +02:00
@FXML
2016-10-09 16:05:44 +02:00
private JFXButton streamingSettingsBtn ;
2016-08-14 15:17:14 +02:00
@FXML
2016-10-09 16:05:44 +02:00
private JFXButton switchBtn ;
2016-09-09 20:41:20 +02:00
@FXML
2016-10-09 16:05:44 +02:00
private JFXButton debugBtn ;
2016-09-09 20:41:20 +02:00
@FXML
2016-10-09 18:35:55 +02:00
private JFXButton updateBtn ;
2016-09-09 20:41:20 +02:00
@FXML
2016-10-09 18:35:55 +02:00
private JFXButton directoryBtn ;
2016-08-14 15:17:14 +02:00
@FXML
2016-10-09 18:35:55 +02:00
private JFXButton streamingDirectoryBtn ;
2016-08-14 15:17:14 +02:00
@FXML
2016-10-09 18:35:55 +02:00
private JFXToggleButton autoupdateBtn ;
2016-08-14 15:17:14 +02:00
@FXML
2016-10-09 18:35:55 +02:00
public JFXTextField tfPath ;
2016-08-14 15:17:14 +02:00
@FXML
2016-10-09 18:35:55 +02:00
public JFXTextField tfStreamingPath ;
2016-09-09 20:41:20 +02:00
@FXML
2016-08-14 15:17:14 +02:00
private JFXTextField tfsearch ;
@FXML
2016-10-09 18:35:55 +02:00
public JFXColorPicker mainColor ;
2016-08-14 15:17:14 +02:00
@FXML
2016-10-09 18:35:55 +02:00
public ChoiceBox < String > cbLocal ;
2016-08-14 15:17:14 +02:00
@FXML
2016-10-09 18:35:55 +02:00
public JFXSlider sliderFontSize ;
2016-08-14 15:17:14 +02:00
@FXML
private JFXDialog dialog = new JFXDialog ( ) ;
@FXML
2016-10-09 18:35:55 +02:00
private Label versionlbl ;
2016-08-14 15:17:14 +02:00
@FXML
2016-10-09 18:35:55 +02:00
private Label sizelbl ;
2016-08-14 15:17:14 +02:00
@FXML
2016-10-09 18:35:55 +02:00
private Label aulbl ;
2016-08-14 15:17:14 +02:00
@FXML
private ImageView image1 ;
2016-11-12 15:02:55 +01:00
2016-08-14 15:17:14 +02:00
@FXML
2016-10-10 16:55:26 +02:00
TreeItem < streamUiData > root = new TreeItem < > ( new streamUiData ( 1 , 1 , 1 , 5 . 0 , " 1 " , " filme " , " 1 " ) ) ;
2016-09-09 20:41:20 +02:00
@FXML
TreeTableColumn < streamUiData , Double > columnRating = new TreeTableColumn < > ( " Bewertung " ) ;
@FXML
TreeTableColumn < streamUiData , String > columnTitel = new TreeTableColumn < > ( " Name " ) ;
@FXML
TreeTableColumn < streamUiData , String > columnStreamUrl = new TreeTableColumn < > ( " Datei Name " ) ;
2016-08-14 15:17:14 +02:00
@FXML
2016-10-09 16:05:44 +02:00
TreeTableColumn < streamUiData , String > columnResolution = new TreeTableColumn < > ( " Aufl<EFBFBD> sung " ) ;
2016-08-14 15:17:14 +02:00
@FXML
2016-10-09 16:05:44 +02:00
TreeTableColumn < streamUiData , Integer > columnYear = new TreeTableColumn < > ( " Jahr " ) ;
2016-08-14 15:17:14 +02:00
@FXML
2016-10-09 16:05:44 +02:00
TreeTableColumn < streamUiData , Integer > columnSeason = new TreeTableColumn < > ( " Staffel " ) ;
2016-10-10 16:55:26 +02:00
@FXML
TreeTableColumn < streamUiData , Integer > columnEpisode = new TreeTableColumn < > ( " Episode " ) ;
2016-09-09 20:41:20 +02:00
@FXML
2016-10-10 16:55:26 +02:00
private TreeItem < streamUiData > streamingRoot = new TreeItem < > ( new streamUiData ( 1 , 1 , 1 , 1 . 0 , " 1 " , " filme " , " 1 " ) ) ;
2016-09-09 20:41:20 +02:00
@FXML
private TableColumn < streamUiData , String > dataNameColumn = new TableColumn < > ( " Datei Name " ) ;
@FXML
private TableColumn < streamUiData , String > dataNameEndColumn = new TableColumn < > ( " Datei Name mit Endung " ) ;
2016-08-14 15:17:14 +02:00
2016-11-12 15:02:55 +01:00
private boolean menutrue = false ; //saves the position of menubtn (opened or closed)
2016-08-14 15:17:14 +02:00
private boolean settingstrue = false ;
2016-09-09 20:41:20 +02:00
private boolean streamingSettingsTrue = false ;
2016-11-18 09:41:38 +01:00
private String version = " 0.4.0 " ;
2016-11-21 18:24:06 +01:00
private String buildNumber = " 102 " ;
2016-11-12 15:02:55 +01:00
private String versionName = " glowing bucket " ;
2016-11-18 09:41:38 +01:00
private String buildURL = " https://raw.githubusercontent.com/Seil0/Project-HomeFlix/master/updates/buildNumber.txt " ;
2016-09-09 20:41:20 +02:00
private String downloadLink = " https://raw.githubusercontent.com/Seil0/Project-HomeFlix/master/updates/downloadLink.txt " ;
private File dir = new File ( System . getProperty ( " user.home " ) + " /Documents/HomeFlix " ) ;
private File file = new File ( dir + " /config.xml " ) ;
2016-08-14 15:17:14 +02:00
2016-08-14 16:03:36 +02:00
private String updateDataURL ;
private String errorUpdateD ;
private String errorUpdateV ;
2016-08-15 18:36:57 +02:00
private String errorPlay ;
2016-10-09 16:05:44 +02:00
private String errorOpenStream ;
private String errorMode ;
2016-11-21 18:24:06 +01:00
private String errorLoad ;
private String errorSave ;
private String noFilmFound ;
2016-08-14 15:17:14 +02:00
private String infoText ;
2016-08-15 18:36:57 +02:00
private String linuxBugText ;
private String vlcNotInstalled ;
2016-11-18 09:41:38 +01:00
private String aktBuildNumber ;
2016-08-14 15:17:14 +02:00
private String path ;
2016-09-09 20:41:20 +02:00
private String streamingPath ;
2016-08-14 15:17:14 +02:00
private String color ;
private String Name ;
private String datPath ;
private String autoUpdate ;
2016-11-21 18:24:06 +01:00
private String mode ;
private String title ;
private String year ;
private String rating ;
private String publishedOn ;
private String duration ;
private String genre ;
private String director ;
private String writer ;
private String actors ;
private String plot ;
private String language ;
private String country ;
private String awards ;
private String metascore ;
private String imdbRating ;
private String type ;
2016-08-14 15:17:14 +02:00
private double size ;
private int last ;
private int selected ;
private int next ;
private int local ;
private File selectedFolder ;
2016-09-09 20:41:20 +02:00
private File selectedStreamingFolder ;
2016-08-14 15:17:14 +02:00
private ResourceBundle bundle ;
2016-09-09 20:41:20 +02:00
private ObservableList < streamUiData > newDaten = FXCollections . observableArrayList ( ) ;
private ObservableList < streamUiData > filterData = FXCollections . observableArrayList ( ) ;
private ObservableList < streamUiData > streamData = FXCollections . observableArrayList ( ) ;
2016-08-14 15:17:14 +02:00
private ObservableList < String > locals = FXCollections . observableArrayList ( " english " , " deutsch " ) ;
2016-09-09 20:41:20 +02:00
private ObservableList < streamUiData > streamingData = FXCollections . observableArrayList ( ) ;
2016-11-21 18:24:06 +01:00
private ImageView menu_icon_black = new ImageView ( new Image ( " recources/icons/menu_icon_black.png " ) ) ;
private ImageView menu_icon_white = new ImageView ( new Image ( " recources/icons/menu_icon_white.png " ) ) ;
private ImageView skip_previous_white = new ImageView ( new Image ( " recources/icons/ic_skip_previous_white_18dp_1x.png " ) ) ;
private ImageView skip_previous_black = new ImageView ( new Image ( " recources/icons/ic_skip_previous_black_18dp_1x.png " ) ) ;
private ImageView skip_next_white = new ImageView ( new Image ( " recources/icons/ic_skip_next_white_18dp_1x.png " ) ) ;
private ImageView skip_next_black = new ImageView ( new Image ( " recources/icons/ic_skip_next_black_18dp_1x.png " ) ) ;
private ImageView play_arrow_white = new ImageView ( new Image ( " recources/icons/ic_play_arrow_white_18dp_1x.png " ) ) ;
private ImageView play_arrow_black = new ImageView ( new Image ( " recources/icons/ic_play_arrow_black_18dp_1x.png " ) ) ;
2016-08-14 15:17:14 +02:00
private DirectoryChooser directoryChooser = new DirectoryChooser ( ) ;
Properties props = new Properties ( ) ;
//wenn menubtn clicked
/ * *
* TODO change value of Text - color change
* /
@FXML
private void menubtnclicked ( ) {
if ( menutrue = = false ) {
2016-10-10 16:55:26 +02:00
sideMenuSlideIn ( ) ;
2016-08-14 15:17:14 +02:00
menutrue = true ;
} else {
2016-10-10 16:55:26 +02:00
sideMenuSlideOut ( ) ;
2016-08-14 15:17:14 +02:00
menutrue = false ;
}
if ( settingstrue = = true ) {
2016-10-09 18:35:55 +02:00
settingsAnchor . setVisible ( false ) ;
setPath ( tfPath . getText ( ) ) ;
2016-08-14 15:17:14 +02:00
saveSettings ( ) ;
settingstrue = false ;
}
2016-09-09 20:41:20 +02:00
if ( streamingSettingsTrue = = true ) {
2016-10-09 18:35:55 +02:00
streamingSettingsAnchor . setVisible ( false ) ;
2016-09-09 20:41:20 +02:00
streamingSettingsTrue = false ;
}
2016-08-14 15:17:14 +02:00
}
@FXML
private void playbtnclicked ( ) {
2016-08-15 18:36:57 +02:00
if ( SystemUtils . IS_OS_LINUX ) {
System . out . println ( " This is Linux " ) ;
String line ;
String output = " " ;
Process p ;
try {
p = Runtime . getRuntime ( ) . exec ( " which vlc " ) ;
BufferedReader input = new BufferedReader ( new InputStreamReader ( p . getInputStream ( ) ) ) ;
while ( ( line = input . readLine ( ) ) ! = null ) {
output = line ;
}
System . out . println ( output ) ;
input . close ( ) ;
} catch ( IOException e1 ) {
// Auto-generated catch block
e1 . printStackTrace ( ) ;
}
if ( output . contains ( " which: no vlc " ) | | output = = " " ) {
Alert alert = new Alert ( AlertType . INFORMATION ) ;
alert . setHeaderText ( " " ) ;
alert . setTitle ( " Info " ) ;
alert . setContentText ( vlcNotInstalled ) ;
alert . showAndWait ( ) ;
} else if ( datPath . contains ( " " ) ) {
Alert alert = new Alert ( AlertType . INFORMATION ) ;
alert . setHeaderText ( " " ) ;
alert . setTitle ( " Info " ) ;
alert . setContentText ( linuxBugText ) ;
alert . showAndWait ( ) ;
} else {
try {
Runtime . getRuntime ( ) . exec ( " vlc " + getPath ( ) + " / " + datPath ) ;
} catch ( IOException e ) {
2016-11-12 15:02:55 +01:00
showErrorMsg ( errorPlay , e ) ;
2016-08-15 18:36:57 +02:00
}
}
} else if ( SystemUtils . IS_OS_WINDOWS | | SystemUtils . IS_OS_MAC_OSX ) {
System . out . println ( " This is Windows or Mac OSX " ) ;
2016-09-09 20:41:20 +02:00
if ( mode . equals ( " local " ) ) {
try {
Desktop . getDesktop ( ) . open ( new File ( getPath ( ) + " \\ " + datPath ) ) ;
} catch ( IOException e ) {
2016-11-12 15:02:55 +01:00
showErrorMsg ( errorPlay , e ) ;
2016-09-09 20:41:20 +02:00
}
} else if ( mode . equals ( " streaming " ) ) {
try {
2016-11-12 15:02:55 +01:00
Desktop . getDesktop ( ) . browse ( new URI ( datPath ) ) ; //opens the streaming url in browser (other option?)
2016-09-09 20:41:20 +02:00
} catch ( URISyntaxException | IOException e ) {
2016-11-12 15:02:55 +01:00
showErrorMsg ( errorOpenStream , ( IOException ) e ) ;
2016-09-09 20:41:20 +02:00
}
} else {
2016-11-12 15:02:55 +01:00
IOException e = new IOException ( " error " ) ;
showErrorMsg ( errorMode , e ) ;
2016-08-15 18:36:57 +02:00
}
2016-08-14 15:17:14 +02:00
}
}
@FXML
private void openfolderbtnclicked ( ) {
try {
2016-09-09 20:41:20 +02:00
Desktop . getDesktop ( ) . open ( new File ( getPath ( ) ) ) ; //<2F> ffnet den aktuellen Pfad
2016-08-14 15:17:14 +02:00
} catch ( IOException e ) {
e . printStackTrace ( ) ;
}
}
@FXML
private void returnBtnclicked ( ) {
treeTableViewfilm . getSelectionModel ( ) . select ( last ) ;
}
@FXML
private void forwardBtnclicked ( ) {
treeTableViewfilm . getSelectionModel ( ) . select ( next ) ;
}
2016-10-09 16:05:44 +02:00
@FXML
private void infoBtnclicked ( ) {
Alert alert = new Alert ( AlertType . INFORMATION ) ;
alert . setTitle ( " Info " ) ;
alert . setHeaderText ( " Project HomeFlix " ) ;
alert . setContentText ( infoText ) ;
alert . showAndWait ( ) ;
}
@FXML
private void settingsBtnclicked ( ) {
if ( settingstrue = = false ) {
2016-10-09 18:35:55 +02:00
if ( streamingSettingsTrue = = true ) {
streamingSettingsAnchor . setVisible ( false ) ;
streamingSettingsTrue = false ;
}
settingsAnchor . setVisible ( true ) ;
2016-10-09 16:05:44 +02:00
settingstrue = true ;
} else {
2016-10-09 18:35:55 +02:00
settingsAnchor . setVisible ( false ) ;
setPath ( tfPath . getText ( ) ) ;
2016-10-09 16:05:44 +02:00
saveSettings ( ) ;
settingstrue = false ;
}
}
/ * *
* TODO zus <EFBFBD> tzliche infos <EFBFBD> ber die dateien
* /
@FXML
private void streamingSettingsBtnclicked ( ) {
if ( streamingSettingsTrue = = false ) {
2016-10-09 18:35:55 +02:00
if ( settingstrue = = true ) {
settingsAnchor . setVisible ( false ) ;
settingstrue = false ;
}
streamingSettingsAnchor . setVisible ( true ) ;
2016-10-09 16:05:44 +02:00
streamingSettingsTrue = true ;
} else {
2016-10-09 18:35:55 +02:00
streamingSettingsAnchor . setVisible ( false ) ;
2016-10-09 16:05:44 +02:00
streamingSettingsTrue = false ;
}
}
@FXML
private void switchBtnclicked ( ) {
if ( mode . equals ( " local " ) ) { //switch to streaming mode
setMode ( " streaming " ) ;
switchBtn . setText ( " local " ) ;
} else if ( mode . equals ( " streaming " ) ) { //switch to local mode
setMode ( " local " ) ;
switchBtn . setText ( " streaming " ) ;
}
saveSettings ( ) ;
root . getChildren ( ) . remove ( 0 , root . getChildren ( ) . size ( ) ) ;
addDataUI ( ) ;
2016-10-09 18:35:55 +02:00
settingsAnchor . setVisible ( false ) ;
streamingSettingsAnchor . setVisible ( false ) ;
2016-10-10 16:55:26 +02:00
sideMenuSlideOut ( ) ; //disables sidemenu
2016-10-09 16:05:44 +02:00
menutrue = false ;
2016-10-09 18:35:55 +02:00
settingstrue = false ;
streamingSettingsTrue = false ;
2016-10-09 16:05:44 +02:00
}
@FXML
private void debugBtnclicked ( ) {
//for testing
}
2016-10-09 18:35:55 +02:00
@FXML
private void tfPathAction ( ) {
setPath ( tfPath . getText ( ) ) ;
saveSettings ( ) ;
}
@FXML
private void directoryBtnAction ( ) {
selectedFolder = directoryChooser . showDialog ( null ) ;
if ( selectedFolder = = null ) {
System . out . println ( " No Directory selected " ) ;
} else {
setPath ( selectedFolder . getAbsolutePath ( ) ) ;
saveSettings ( ) ;
tfPath . setText ( getPath ( ) ) ;
try {
2016-11-12 15:02:55 +01:00
Runtime . getRuntime ( ) . exec ( " java -jar ProjectHomeFlix.jar " ) ; //start again
System . exit ( 0 ) ; //finishes itself
2016-10-09 18:35:55 +02:00
} catch ( IOException e ) {
System . out . println ( " es ist ein Fehler aufgetreten " ) ;
e . printStackTrace ( ) ;
}
}
}
@FXML
private void mainColorAction ( ) {
editColor ( mainColor . getValue ( ) . toString ( ) ) ;
applyColor ( ) ;
}
@FXML
private void updateBtnAction ( ) {
update ( ) ;
}
@FXML
private void autoupdateBtnAction ( ) {
if ( autoUpdate . equals ( " 0 " ) ) {
setAutoUpdate ( " 1 " ) ;
} else {
setAutoUpdate ( " 0 " ) ;
}
saveSettings ( ) ;
}
@FXML
private void tfStreamingPathAction ( ) {
//
}
@FXML
private void streamingDirectoryBtnAction ( ) {
selectedStreamingFolder = directoryChooser . showDialog ( null ) ;
if ( selectedStreamingFolder = = null ) {
System . out . println ( " No Directory selected " ) ;
} else {
setStreamingPath ( selectedStreamingFolder . getAbsolutePath ( ) ) ;
saveSettings ( ) ;
tfStreamingPath . setText ( getStreamingPath ( ) ) ;
try {
2016-11-12 15:02:55 +01:00
Runtime . getRuntime ( ) . exec ( " java -jar ProjectHomeFlix.jar " ) ; //start again
System . exit ( 0 ) ; //finishes itself
2016-10-09 18:35:55 +02:00
} catch ( IOException e ) {
System . out . println ( " es ist ein Fehler aufgetreten " ) ;
e . printStackTrace ( ) ;
}
}
}
2016-10-09 16:05:44 +02:00
2016-08-14 15:17:14 +02:00
//"Main" Methode die beim start von der Klasse Main aufgerufen wird, initialiesirung der einzellnen UI-Objekte
public void setMain ( Main main ) {
loadSettings ( ) ;
initTabel ( ) ;
2016-10-09 16:05:44 +02:00
initActions ( ) ;
2016-09-09 20:41:20 +02:00
System . out . println ( " Mode: " + mode ) ;
2016-08-14 15:17:14 +02:00
2016-10-09 16:05:44 +02:00
debugBtn . setDisable ( true ) ; //debugging btn for tests
debugBtn . setVisible ( false ) ;
2016-09-09 20:41:20 +02:00
2016-10-09 18:35:55 +02:00
tfPath . setText ( getPath ( ) ) ;
2016-08-14 15:17:14 +02:00
2016-10-09 18:35:55 +02:00
sliderFontSize . setValue ( getSize ( ) ) ;
2016-08-14 15:17:14 +02:00
cbLocal . setItems ( locals ) ;
updateBtn . setFont ( Font . font ( " System " , 12 ) ) ;
if ( autoUpdate . equals ( " 1 " ) ) {
autoupdateBtn . setSelected ( true ) ;
update ( ) ;
} else {
autoupdateBtn . setSelected ( false ) ;
}
2016-10-09 18:35:55 +02:00
2016-08-14 15:17:14 +02:00
ta1 . setWrapText ( true ) ;
ta1 . setEditable ( false ) ;
ta1 . setFont ( Font . font ( " System " , getSize ( ) ) ) ;
}
2016-09-09 20:41:20 +02:00
//initialisierung der Tabellen f<> r filme(beide Modi) und Streaming-Settings
@SuppressWarnings ( { " unchecked " , " rawtypes " } )
2016-08-14 15:17:14 +02:00
private void initTabel ( ) {
2016-11-12 15:02:55 +01:00
//filmtabelle
2016-08-14 15:17:14 +02:00
columnRating . setMaxWidth ( 120 ) ;
2016-09-09 20:41:20 +02:00
columnTitel . setMaxWidth ( 240 ) ;
columnStreamUrl . setMaxWidth ( 0 ) ;
2016-10-09 18:35:55 +02:00
dataNameColumn . setPrefWidth ( 130 ) ;
dataNameEndColumn . setPrefWidth ( 170 ) ;
2016-08-14 15:17:14 +02:00
treeTableViewfilm . setRoot ( root ) ;
treeTableViewfilm . setColumnResizePolicy ( TreeTableView . CONSTRAINED_RESIZE_POLICY ) ;
treeTableViewfilm . setShowRoot ( false ) ;
//inhalt in Zelle schreiben
2016-09-09 20:41:20 +02:00
columnTitel . setCellValueFactory ( ( CellDataFeatures < streamUiData , String > p ) - >
new ReadOnlyStringWrapper ( p . getValue ( ) . getValue ( ) . getTitel ( ) ) ) ;
2016-08-14 15:17:14 +02:00
2016-09-09 20:41:20 +02:00
columnRating . setCellValueFactory ( ( CellDataFeatures < streamUiData , Double > p ) - >
new ReadOnlyObjectWrapper < Double > ( p . getValue ( ) . getValue ( ) . getRating ( ) ) ) ;
columnStreamUrl . setCellValueFactory ( ( CellDataFeatures < streamUiData , String > p ) - >
new ReadOnlyStringWrapper ( p . getValue ( ) . getValue ( ) . getStreamUrl ( ) ) ) ;
2016-08-14 15:17:14 +02:00
2016-09-09 20:41:20 +02:00
columnResolution . setCellValueFactory ( ( CellDataFeatures < streamUiData , String > p ) - >
new ReadOnlyStringWrapper ( p . getValue ( ) . getValue ( ) . getResolution ( ) ) ) ;
columnYear . setCellValueFactory ( ( CellDataFeatures < streamUiData , Integer > p ) - >
new ReadOnlyObjectWrapper ( p . getValue ( ) . getValue ( ) . getYear ( ) ) ) ;
columnSeason . setCellValueFactory ( ( CellDataFeatures < streamUiData , Integer > p ) - >
new ReadOnlyObjectWrapper ( p . getValue ( ) . getValue ( ) . getSeason ( ) ) ) ;
2016-10-10 16:55:26 +02:00
columnEpisode . setCellValueFactory ( ( CellDataFeatures < streamUiData , Integer > p ) - >
new ReadOnlyObjectWrapper ( p . getValue ( ) . getValue ( ) . getEpisode ( ) ) ) ;
2016-08-14 15:17:14 +02:00
2016-10-10 16:55:26 +02:00
treeTableViewfilm . getColumns ( ) . addAll ( columnTitel , columnRating , columnStreamUrl , columnResolution , columnYear , columnSeason , columnEpisode ) ;
2016-09-09 20:41:20 +02:00
treeTableViewfilm . getColumns ( ) . get ( 2 ) . setVisible ( false ) ; //blendet die Column mit den Dateinamen aus (wichtig um sie abzuspielen)
2016-08-14 15:17:14 +02:00
2016-09-09 20:41:20 +02:00
//Changelistener f<> r TreeTable
treeTableViewfilm . getSelectionModel ( ) . selectedItemProperty ( ) . addListener ( new ChangeListener < Object > ( ) {
2016-08-14 15:17:14 +02:00
@Override
public void changed ( ObservableValue < ? > observable , Object oldVal , Object newVal ) {
2016-09-09 20:41:20 +02:00
// last = selected; //f<> r autoplay
2016-08-14 15:17:14 +02:00
selected = treeTableViewfilm . getSelectionModel ( ) . getSelectedIndex ( ) ; // holt aktuelles Item
last = selected - 1 ;
next = selected + 1 ;
2016-09-09 20:41:20 +02:00
Name = columnTitel . getCellData ( selected ) ; // holt Namen des Aktuelle Items aus der ColumnName
datPath = columnStreamUrl . getCellData ( selected ) ; // holt den aktuellen Datei Pfad aus der ColumnDatName
ta1 . setText ( " " ) ; // l<> scht Text in ta1
2016-08-14 15:17:14 +02:00
apiAbfrage ( Name ) ; // startet die api abfrage
ta1 . positionCaret ( 0 ) ; // setzt die startposition des Cursors in
// ta1
}
} ) ;
2016-09-09 20:41:20 +02:00
//Streaming-Settings Tabelle
dataNameColumn . setCellValueFactory ( cellData - > cellData . getValue ( ) . titelProperty ( ) ) ;
dataNameEndColumn . setCellValueFactory ( cellData - > cellData . getValue ( ) . streamUrlProperty ( ) ) ;
2016-10-09 18:35:55 +02:00
tableViewStreamingdata . getColumns ( ) . addAll ( dataNameColumn , dataNameEndColumn ) ;
tableViewStreamingdata . setItems ( streamingData ) ;
2016-09-09 20:41:20 +02:00
}
//initialisierung der Button Actions
2016-10-09 16:05:44 +02:00
private void initActions ( ) {
2016-09-09 20:41:20 +02:00
2016-10-09 16:05:44 +02:00
//TODO unterscheiden zwischen streaming und local
tfsearch . textProperty ( ) . addListener ( new ChangeListener < String > ( ) {
@SuppressWarnings ( " unchecked " )
2016-09-09 20:41:20 +02:00
@Override
2016-10-09 16:05:44 +02:00
public void changed ( ObservableValue < ? extends String > 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 ) . getTitel ( ) . toLowerCase ( ) . contains ( tfsearch . getText ( ) . toLowerCase ( ) ) ) {
filterData . add ( newDaten . get ( i ) ) ;
}
}
for ( int i = 0 ; i < filterData . size ( ) ; i + + ) {
root . getChildren ( ) . addAll ( new TreeItem < streamUiData > ( filterData . get ( i ) ) ) ; //f<> gt daten zur Rootnode hinzu
}
}
} ) ;
cbLocal . getSelectionModel ( ) . selectedIndexProperty ( )
. addListener ( new ChangeListener < Number > ( ) {
public void changed ( ObservableValue < ? extends Number > ov , Number value , Number new_value ) {
setLocal ( new_value . intValue ( ) ) ;
setLoaclUI ( local ) ;
saveSettings ( ) ;
}
} ) ;
2016-10-09 18:35:55 +02:00
sliderFontSize . valueProperty ( ) . addListener ( new ChangeListener < Number > ( ) {
@Override
public void changed ( ObservableValue < ? extends Number > ov , Number old_val , Number new_val ) {
setSize ( sliderFontSize . getValue ( ) ) ;
ta1 . setFont ( Font . font ( " System " , size ) ) ;
saveSettings ( ) ;
}
} ) ;
2016-08-14 15:17:14 +02:00
}
2016-09-09 20:41:20 +02:00
//pr<70> ft auf Update und f<> rht es gegebenenfalls aus
2016-08-14 15:17:14 +02:00
private void update ( ) {
2016-11-18 09:41:38 +01:00
2016-08-14 15:17:14 +02:00
System . out . println ( " check for updates ... " ) ;
try {
2016-11-18 09:41:38 +01:00
URL url = new URL ( buildURL ) ; //URL der Datei mit aktueller Versionsnummer
2016-08-14 15:17:14 +02:00
BufferedReader in = new BufferedReader ( new InputStreamReader ( url . openStream ( ) ) ) ;
2016-11-18 09:41:38 +01:00
aktBuildNumber = in . readLine ( ) ; //schreibt inputstream in String
2016-08-14 15:17:14 +02:00
in . close ( ) ;
} catch ( IOException e1 ) {
2016-11-12 15:02:55 +01:00
showErrorMsg ( errorUpdateV , e1 ) ;
2016-08-14 15:17:14 +02:00
}
2016-11-18 09:41:38 +01:00
System . out . println ( " Build: " + buildNumber + " , Update: " + aktBuildNumber ) ;
2016-08-14 15:17:14 +02:00
2016-08-15 18:36:57 +02:00
//vergleicht die Versionsnummern, bei aktversion > version wird ein Update durchgrf<72> hrt
2016-11-18 09:41:38 +01:00
int iversion = Integer . parseInt ( buildNumber . replace ( " . " , " " ) ) ;
int iaktVersion = Integer . parseInt ( aktBuildNumber . replace ( " . " , " " ) ) ;
2016-08-14 15:17:14 +02:00
if ( iversion > = iaktVersion ) {
2016-11-12 15:02:55 +01:00
updateBtn . setText ( bundle . getString ( " updateBtnNotavail " ) ) ;
System . out . println ( " no update available " ) ;
2016-08-14 15:17:14 +02:00
} else {
2016-11-12 15:02:55 +01:00
updateBtn . setText ( bundle . getString ( " updateBtnavail " ) ) ;
System . out . println ( " update available " ) ;
2016-08-14 15:17:14 +02:00
try {
URL website ;
URL downloadURL = new URL ( downloadLink ) ;
BufferedReader in = new BufferedReader ( new InputStreamReader ( downloadURL . openStream ( ) ) ) ;
2016-08-14 16:03:36 +02:00
updateDataURL = in . readLine ( ) ;
2016-08-14 15:17:14 +02:00
website = new URL ( updateDataURL ) ; //Update URL
2016-11-18 09:41:38 +01:00
ReadableByteChannel rbc = Channels . newChannel ( website . openStream ( ) ) ; //open new Stream/Channel
FileOutputStream fos = new FileOutputStream ( " ProjectHomeFlix.jar " ) ; //nea fileoutputstram for ProjectHomeFLix.jar
fos . getChannel ( ) . transferFrom ( rbc , 0 , Long . MAX_VALUE ) ; //gets file from 0 to max size
fos . close ( ) ; //close fos (extrem wichtig!)
Runtime . getRuntime ( ) . exec ( " java -jar ProjectHomeFlix.jar " ) ; //start again
System . exit ( 0 ) ; //finishes itself
2016-08-14 15:17:14 +02:00
} catch ( IOException e ) {
2016-11-12 15:02:55 +01:00
//in case there is an error
showErrorMsg ( errorUpdateD , e ) ;
2016-08-14 15:17:14 +02:00
}
}
}
2016-09-09 20:41:20 +02:00
//l<> dt die Daten im angegeben Ordner in newDaten
2016-08-14 15:17:14 +02:00
public void loadData ( ) {
2016-09-09 20:41:20 +02:00
//load local Data
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 ] ;
2016-10-10 16:55:26 +02:00
newDaten . add ( new streamUiData ( 1 , 1 , 1 , 5 . 0 , " 1 " , titel , data ) ) ;
2016-09-09 20:41:20 +02:00
}
}
//load streaming Data TODO pr<70> fen ob streaming daten vorhanden -> momentan evtl. fehler
String titel = null ;
String resolution = null ;
String streamUrl = null ;
int season ;
2016-10-10 16:55:26 +02:00
int episode ;
2016-09-09 20:41:20 +02:00
int year ;
double rating = 5 . 0 ;
if ( getStreamingPath ( ) . equals ( " " ) | | getStreamingPath ( ) . equals ( null ) ) {
System . out . println ( " Kein Pfad angegeben " ) ; //falls der Pfad null oder "" ist
} else {
for ( int i = 0 ; i < streamingData . size ( ) ; i + + ) {
String fileName = streamingPath + " / " + streamingData . get ( i ) . getStreamUrl ( ) ;
try {
JsonObject object = Json . parse ( new FileReader ( fileName ) ) . asObject ( ) ;
JsonArray items = object . get ( " entries " ) . asArray ( ) ;
for ( JsonValue item : items ) {
titel = item . asObject ( ) . getString ( " titel " , " " ) ;
season = item . asObject ( ) . getInt ( " season " , 0 ) ;
2016-10-10 16:55:26 +02:00
episode = item . asObject ( ) . getInt ( " episode " , 0 ) ;
2016-09-09 20:41:20 +02:00
year = item . asObject ( ) . getInt ( " year " , 0 ) ;
resolution = item . asObject ( ) . getString ( " resolution " , " " ) ;
streamUrl = item . asObject ( ) . getString ( " streamUrl " , " " ) ;
2016-10-10 16:55:26 +02:00
streamData . add ( new streamUiData ( year , season , episode , rating , resolution , titel , streamUrl ) ) ;
2016-09-09 20:41:20 +02:00
}
} catch ( IOException e ) {
//Auto-generated catch block
e . printStackTrace ( ) ;
}
}
}
}
public void addDataUI ( ) {
if ( mode . equals ( " local " ) ) {
for ( int i = 0 ; i < newDaten . size ( ) ; i + + ) {
root . getChildren ( ) . add ( new TreeItem < streamUiData > ( newDaten . get ( i ) ) ) ; //f<> gt daten zur Rootnode hinzu
}
columnRating . setMaxWidth ( 120 ) ;
columnTitel . setMaxWidth ( 240 ) ;
treeTableViewfilm . getColumns ( ) . get ( 3 ) . setVisible ( false ) ;
treeTableViewfilm . getColumns ( ) . get ( 4 ) . setVisible ( false ) ;
treeTableViewfilm . getColumns ( ) . get ( 5 ) . setVisible ( false ) ;
2016-10-10 16:55:26 +02:00
treeTableViewfilm . getColumns ( ) . get ( 6 ) . setVisible ( false ) ;
2016-09-09 20:41:20 +02:00
} else if ( mode . equals ( " streaming " ) ) {
for ( int i = 0 ; i < streamData . size ( ) ; i + + ) {
root . getChildren ( ) . add ( new TreeItem < streamUiData > ( streamData . get ( i ) ) ) ; //f<> gt daten zur Rootnode hinzu
}
columnTitel . setMaxWidth ( 150 ) ;
columnResolution . setMaxWidth ( 65 ) ;
columnRating . setMaxWidth ( 52 . 5 ) ;
columnYear . setMaxWidth ( 40 ) ;
columnSeason . setMaxWidth ( 52 . 5 ) ;
2016-10-10 16:55:26 +02:00
columnEpisode . setMaxWidth ( 0 ) ; //disabled for ui size reasons
2016-09-09 20:41:20 +02:00
treeTableViewfilm . getColumns ( ) . get ( 3 ) . setVisible ( true ) ;
treeTableViewfilm . getColumns ( ) . get ( 4 ) . setVisible ( true ) ;
treeTableViewfilm . getColumns ( ) . get ( 5 ) . setVisible ( true ) ;
2016-10-10 16:55:26 +02:00
treeTableViewfilm . getColumns ( ) . get ( 6 ) . setVisible ( true ) ;
2016-08-14 15:17:14 +02:00
}
}
2016-09-09 20:41:20 +02:00
public void loadStreamingSettings ( ) {
if ( getStreamingPath ( ) . equals ( " " ) | | getStreamingPath ( ) . equals ( null ) ) {
System . out . println ( " Kein Pfad angegeben " ) ; //falls der Pfad null oder "" ist
} else {
String [ ] entries = new File ( getStreamingPath ( ) ) . list ( ) ;
for ( int i = 0 ; i < entries . length ; i + + ) {
if ( entries [ i ] . endsWith ( " .json " ) ) {
String titel = ohneEndung ( entries [ i ] ) ;
String data = entries [ i ] ;
2016-10-10 16:55:26 +02:00
streamingData . add ( new streamUiData ( 1 , 1 , 1 , 5 . 0 , " 1 " , titel , data ) ) ;
2016-09-09 20:41:20 +02:00
}
}
for ( int i = 0 ; i < streamingData . size ( ) ; i + + ) {
streamingRoot . getChildren ( ) . add ( new TreeItem < streamUiData > ( streamingData . get ( i ) ) ) ; //f<> gt daten zur Rootnode hinzu
}
}
}
2016-08-14 15:17:14 +02:00
//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 ) ;
}
2016-09-09 20:41:20 +02:00
//setzt die Farben f<> r die UI-Elemente
2016-08-14 15:17:14 +02:00
public void applyColor ( ) {
String style = " -fx-background-color: # " + getColor ( ) + " ; " ;
2016-11-21 18:24:06 +01:00
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; " ;
2016-08-14 15:17:14 +02:00
BigInteger icolor = new BigInteger ( getColor ( ) , 16 ) ;
BigInteger ccolor = new BigInteger ( " 78909cff " , 16 ) ;
2016-10-09 16:05:44 +02:00
sideMenuVBox . setStyle ( style ) ;
topHBox . setStyle ( style ) ;
2016-08-14 15:17:14 +02:00
tfsearch . setFocusColor ( Color . valueOf ( getColor ( ) ) ) ;
2016-10-09 18:35:55 +02:00
tfPath . setFocusColor ( Color . valueOf ( getColor ( ) ) ) ;
2016-08-14 15:17:14 +02:00
if ( icolor . compareTo ( ccolor ) = = - 1 ) {
settingsBtn . setStyle ( " -fx-text-fill: WHITE; " ) ;
2016-09-09 20:41:20 +02:00
streamingSettingsBtn . setStyle ( " -fx-text-fill: WHITE; " ) ;
switchBtn . setStyle ( " -fx-text-fill: WHITE; " ) ;
2016-08-14 15:17:14 +02:00
infoBtn . setStyle ( " -fx-text-fill: WHITE; " ) ;
2016-10-09 16:05:44 +02:00
debugBtn . setStyle ( " -fx-text-fill: WHITE; " ) ;
2016-11-21 18:24:06 +01:00
directoryBtn . setStyle ( btnStyleWhite ) ;
streamingDirectoryBtn . setStyle ( btnStyleWhite ) ;
updateBtn . setStyle ( btnStyleWhite ) ;
playbtn . setStyle ( btnStyleWhite ) ;
openfolderbtn . setStyle ( btnStyleWhite ) ;
returnBtn . setStyle ( btnStyleWhite ) ;
forwardBtn . setStyle ( btnStyleWhite ) ;
playbtn . setGraphic ( play_arrow_white ) ;
returnBtn . setGraphic ( skip_previous_white ) ;
forwardBtn . setGraphic ( skip_next_white ) ;
2016-08-14 16:03:36 +02:00
menubtn . setGraphic ( menu_icon_white ) ;
2016-08-14 15:17:14 +02:00
} else {
settingsBtn . setStyle ( " -fx-text-fill: BLACK; " ) ;
2016-09-09 20:41:20 +02:00
streamingSettingsBtn . setStyle ( " -fx-text-fill: BLACK; " ) ;
switchBtn . setStyle ( " -fx-text-fill: BLACK; " ) ;
2016-08-14 15:17:14 +02:00
infoBtn . setStyle ( " -fx-text-fill: BLACK; " ) ;
2016-10-09 16:05:44 +02:00
debugBtn . setStyle ( " -fx-text-fill: BLACK; " ) ;
2016-11-21 18:24:06 +01:00
directoryBtn . setStyle ( btnStyleBlack ) ;
streamingDirectoryBtn . setStyle ( btnStyleBlack ) ;
updateBtn . setStyle ( btnStyleBlack ) ;
playbtn . setStyle ( btnStyleBlack ) ;
openfolderbtn . setStyle ( btnStyleBlack ) ;
returnBtn . setStyle ( btnStyleBlack ) ;
forwardBtn . setStyle ( btnStyleBlack ) ;
playbtn . setGraphic ( play_arrow_black ) ;
returnBtn . setGraphic ( skip_previous_black ) ;
forwardBtn . setGraphic ( skip_next_black ) ;
2016-08-14 15:17:14 +02:00
menubtn . setGraphic ( menu_icon_black ) ;
}
2016-09-09 20:41:20 +02:00
//das solte weg kann aber hier bleiben wicht ist dass es zum selben zeitpunkt wie aply color ausgef<65> hrt wird
if ( mode . equals ( " local " ) ) {
2016-10-09 16:05:44 +02:00
switchBtn . setText ( " streaming " ) ; //TODO translate
2016-09-09 20:41:20 +02:00
} else if ( mode . equals ( " streaming " ) ) {
switchBtn . setText ( " local " ) ;
}
2016-08-14 15:17:14 +02:00
}
2016-10-10 16:55:26 +02:00
private void sideMenuSlideIn ( ) {
sideMenuVBox . setVisible ( true ) ;
2016-11-21 18:24:06 +01:00
//fade in from 40% to 100% opacity in 400ms
2016-10-10 16:55:26 +02:00
FadeTransition fadeTransition = new FadeTransition ( Duration . millis ( 400 ) , sideMenuVBox ) ;
fadeTransition . setFromValue ( 0 . 4 ) ;
fadeTransition . setToValue ( 1 . 0 ) ;
2016-11-21 18:24:06 +01:00
//slide in in 400ms
2016-10-10 16:55:26 +02:00
TranslateTransition translateTransition = new TranslateTransition ( Duration . millis ( 400 ) , sideMenuVBox ) ;
translateTransition . setFromX ( - 150 ) ;
translateTransition . setToX ( 0 ) ;
2016-11-21 18:24:06 +01:00
//in case both animations are used (add (fadeTransition, translateTransition) in the second line under this command)
2016-10-10 16:55:26 +02:00
ParallelTransition parallelTransition = new ParallelTransition ( ) ;
parallelTransition . getChildren ( ) . addAll ( translateTransition ) ; //(fadeTransition, translateTransition);
parallelTransition . play ( ) ;
}
2016-08-14 15:17:14 +02:00
2016-10-10 16:55:26 +02:00
private void sideMenuSlideOut ( ) {
// sideMenuVBox.setVisible(false);
2016-11-21 18:24:06 +01:00
//fade out from 100% to 40% opacity in 400ms
2016-10-10 16:55:26 +02:00
FadeTransition fadeTransition = new FadeTransition ( Duration . millis ( 400 ) , sideMenuVBox ) ;
fadeTransition . setFromValue ( 1 . 0 ) ;
fadeTransition . setToValue ( 0 . 4 ) ;
2016-11-21 18:24:06 +01:00
//slide out in 400ms
2016-10-10 16:55:26 +02:00
TranslateTransition translateTransition = new TranslateTransition ( Duration . millis ( 400 ) , sideMenuVBox ) ;
translateTransition . setFromX ( 0 ) ;
translateTransition . setToX ( - 150 ) ;
2016-11-21 18:24:06 +01:00
//in case both animations are used (add (fadeTransition, translateTransition) in the second line under this command)
2016-10-10 16:55:26 +02:00
ParallelTransition parallelTransition = new ParallelTransition ( ) ;
parallelTransition . getChildren ( ) . addAll ( translateTransition ) ; //(fadeTransition, translateTransition);
parallelTransition . play ( ) ;
}
2016-08-14 15:17:14 +02:00
public void setLoaclUI ( int local ) {
switch ( local ) {
2016-08-15 18:36:57 +02:00
case 0 : bundle = ResourceBundle . getBundle ( " recources.HomeFlix-Local " , Locale . US ) ; //us_english
2016-08-14 15:17:14 +02:00
break ;
2016-08-15 18:36:57 +02:00
case 1 : bundle = ResourceBundle . getBundle ( " recources.HomeFlix-Local " , Locale . GERMAN ) ; //german
2016-08-14 15:17:14 +02:00
break ;
2016-08-15 18:36:57 +02:00
default : bundle = ResourceBundle . getBundle ( " recources.HomeFlix-Local " , Locale . US ) ; //default local
2016-08-14 15:17:14 +02:00
break ;
}
infoBtn . setText ( bundle . getString ( " info " ) ) ;
2016-10-09 16:05:44 +02:00
settingsBtn . setText ( bundle . getString ( " settings " ) ) ;
streamingSettingsBtn . setText ( bundle . getString ( " streamingSettings " ) ) ;
2016-10-09 18:35:55 +02:00
tfPath . setPromptText ( bundle . getString ( " tfPath " ) ) ;
tfStreamingPath . setPromptText ( bundle . getString ( " tfPath " ) ) ;
2016-11-21 18:24:06 +01:00
tfsearch . setPromptText ( bundle . getString ( " tfSearch " ) ) ;
2016-08-14 15:17:14 +02:00
openfolderbtn . setText ( bundle . getString ( " openFolder " ) ) ;
updateBtn . setText ( bundle . getString ( " checkUpdates " ) ) ;
2016-08-14 16:03:36 +02:00
directoryBtn . setText ( bundle . getString ( " chooseFolder " ) ) ;
2016-10-09 18:35:55 +02:00
streamingDirectoryBtn . setText ( bundle . getString ( " chooseFolder " ) ) ;
2016-08-14 16:03:36 +02:00
sizelbl . setText ( bundle . getString ( " fontSize " ) ) ;
2016-08-14 15:17:14 +02:00
aulbl . setText ( bundle . getString ( " autoUpdate " ) ) ;
2016-11-18 09:41:38 +01:00
versionlbl . setText ( bundle . getString ( " version " ) + " " + version + " (Build: " + buildNumber + " ) " ) ;
2016-09-09 20:41:20 +02:00
columnTitel . setText ( bundle . getString ( " columnName " ) ) ;
2016-08-14 15:17:14 +02:00
columnRating . setText ( bundle . getString ( " columnRating " ) ) ;
2016-10-09 16:05:44 +02:00
columnStreamUrl . setText ( bundle . getString ( " columnStreamUrl " ) ) ;
columnResolution . setText ( bundle . getString ( " columnResolution " ) ) ;
columnSeason . setText ( bundle . getString ( " columnSeason " ) ) ;
columnYear . setText ( bundle . getString ( " columnYear " ) ) ;
2016-08-14 16:03:36 +02:00
errorUpdateD = bundle . getString ( " errorUpdateD " ) ;
errorUpdateV = bundle . getString ( " errorUpdateV " ) ;
2016-10-09 16:05:44 +02:00
errorPlay = bundle . getString ( " errorPlay " ) ;
errorOpenStream = bundle . getString ( " errorOpenStream " ) ;
errorMode = bundle . getString ( " errorMode " ) ;
2016-11-21 18:24:06 +01:00
errorLoad = bundle . getString ( " errorLoad " ) ;
errorSave = bundle . getString ( " errorSave " ) ;
noFilmFound = bundle . getString ( " noFilmFound " ) ;
2016-11-18 09:41:38 +01:00
infoText = bundle . getString ( " version " ) + " " + version + " (Build: " + buildNumber + " ) " + versionName + bundle . getString ( " infoText " ) ;
2016-08-15 18:36:57 +02:00
linuxBugText = bundle . getString ( " linuxBug " ) ;
vlcNotInstalled = bundle . getString ( " vlcNotInstalled " ) ;
2016-11-21 18:24:06 +01:00
title = bundle . getString ( " title " ) ;
year = bundle . getString ( " year " ) ;
rating = bundle . getString ( " rating " ) ;
publishedOn = bundle . getString ( " publishedOn " ) ;
duration = bundle . getString ( " duration " ) ;
genre = bundle . getString ( " genre " ) ;
director = bundle . getString ( " director " ) ;
writer = bundle . getString ( " writer " ) ;
actors = bundle . getString ( " actors " ) ;
plot = bundle . getString ( " plot " ) ;
language = bundle . getString ( " language " ) ;
country = bundle . getString ( " country " ) ;
awards = bundle . getString ( " awards " ) ;
metascore = bundle . getString ( " metascore " ) ;
imdbRating = bundle . getString ( " imdbRating " ) ;
type = bundle . getString ( " type " ) ;
2016-08-14 15:17:14 +02:00
}
2016-11-12 15:02:55 +01:00
private void showErrorMsg ( String msg , IOException exception ) {
Alert alert = new Alert ( AlertType . ERROR ) ;
alert . setTitle ( " Error " ) ;
alert . setHeaderText ( " " ) ;
alert . setContentText ( msg ) ;
// Create expandable Exception.
StringWriter sw = new StringWriter ( ) ;
PrintWriter pw = new PrintWriter ( sw ) ;
exception . printStackTrace ( pw ) ;
String exceptionText = sw . toString ( ) ;
TextArea textArea = new TextArea ( exceptionText ) ;
textArea . setEditable ( false ) ;
textArea . setWrapText ( true ) ;
textArea . setMaxWidth ( Double . MAX_VALUE ) ;
textArea . setMaxHeight ( Double . MAX_VALUE ) ;
GridPane . setVgrow ( textArea , Priority . ALWAYS ) ;
GridPane . setHgrow ( textArea , Priority . ALWAYS ) ;
GridPane expContent = new GridPane ( ) ;
expContent . setMaxWidth ( Double . MAX_VALUE ) ;
expContent . add ( textArea , 0 , 1 ) ;
// Set expandable Exception into the dialog pane.
alert . getDialogPane ( ) . setExpandableContent ( expContent ) ;
alert . showAndWait ( ) ;
exception . printStackTrace ( ) ;
}
2016-11-21 18:24:06 +01:00
//saves the Settings
2016-08-14 15:17:14 +02:00
public void saveSettings ( ) {
try {
2016-11-21 18:24:06 +01:00
props . setProperty ( " path " , getPath ( ) ) ; //writes path into property
2016-08-14 15:17:14 +02:00
props . setProperty ( " color " , getColor ( ) ) ;
props . setProperty ( " autoUpdate " , getAutoUpdate ( ) ) ;
props . setProperty ( " size " , getSize ( ) . toString ( ) ) ;
props . setProperty ( " local " , Integer . toString ( getLocal ( ) ) ) ;
2016-09-09 20:41:20 +02:00
props . setProperty ( " streamingPath " , getStreamingPath ( ) ) ;
props . setProperty ( " mode " , getMode ( ) ) ;
2016-11-21 18:24:06 +01:00
OutputStream outputStream = new FileOutputStream ( file ) ; //new outputstream
props . storeToXML ( outputStream , " Project HomeFlix settings " ) ; //writes new .xml
2016-08-14 15:17:14 +02:00
outputStream . close ( ) ;
} catch ( IOException e ) {
2016-11-21 18:24:06 +01:00
showErrorMsg ( errorSave , e ) ;
2016-08-14 15:17:14 +02:00
e . printStackTrace ( ) ;
}
}
2016-11-21 18:24:06 +01:00
//loads the Settings
2016-08-14 15:17:14 +02:00
public void loadSettings ( ) {
try {
2016-09-09 20:41:20 +02:00
InputStream inputStream = new FileInputStream ( file ) ;
2016-11-21 18:24:06 +01:00
props . loadFromXML ( inputStream ) ; //new inputstream from .xml
path = props . getProperty ( " path " ) ; //reads path from property
2016-09-09 20:41:20 +02:00
streamingPath = props . getProperty ( " streamingPath " ) ;
2016-08-14 15:17:14 +02:00
color = props . getProperty ( " color " ) ;
size = Double . parseDouble ( props . getProperty ( " size " ) ) ;
autoUpdate = props . getProperty ( " autoUpdate " ) ;
local = Integer . parseInt ( props . getProperty ( " local " ) ) ;
2016-09-09 20:41:20 +02:00
mode = props . getProperty ( " mode " ) ;
2016-08-14 15:17:14 +02:00
inputStream . close ( ) ;
} catch ( IOException e ) {
2016-11-21 18:24:06 +01:00
showErrorMsg ( errorLoad , e ) ;
2016-08-14 15:17:14 +02:00
e . printStackTrace ( ) ;
}
}
2016-11-21 18:24:06 +01:00
//cuts 0x of the Colorpickers return value
2016-09-09 20:41:20 +02:00
private void editColor ( String input ) {
StringBuilder sb = new StringBuilder ( input ) ;
sb . delete ( 0 , 2 ) ;
this . color = sb . toString ( ) ;
saveSettings ( ) ;
}
2016-11-21 18:24:06 +01:00
//getter and setter
2016-08-14 15:17:14 +02:00
public void setColor ( String input ) {
this . color = input ;
}
public String getColor ( ) {
return color ;
}
2016-09-09 20:41:20 +02:00
2016-08-14 15:17:14 +02:00
public void setPath ( String input ) {
this . path = input ;
}
public String getPath ( ) {
return path ;
}
2016-09-09 20:41:20 +02:00
public void setStreamingPath ( String input ) {
this . streamingPath = input ;
}
public String getStreamingPath ( ) {
return streamingPath ;
}
2016-08-14 15:17:14 +02:00
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 ;
}
2016-09-09 20:41:20 +02:00
public void setMode ( String input ) {
this . mode = input ;
}
public String getMode ( ) {
return mode ;
}
2016-11-21 18:24:06 +01:00
//API-Query
2016-08-14 15:17:14 +02:00
@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 {
2016-11-21 18:24:06 +01:00
//get film title
2016-08-14 15:17:14 +02:00
sc = new Scanner ( System . in ) ;
moviename = input ;
2016-11-21 18:24:06 +01:00
// in case of no or "" Film title
2016-08-14 15:17:14 +02:00
if ( moviename = = null | | moviename . equals ( " " ) ) {
System . out . println ( " No movie found " ) ;
}
2016-11-21 18:24:06 +01:00
//remove unwanted blank
2016-08-14 15:17:14 +02:00
moviename = moviename . trim ( ) ;
2016-11-21 18:24:06 +01:00
//replace blank with + for api-query
2016-08-14 15:17:14 +02:00
moviename = moviename . replace ( " " , " + " ) ;
2016-09-09 20:41:20 +02:00
//URL wird zusammengestellt abfragetypen: http,json,xml (muss json sein um sp<73> teres trennen zu erm<72> glichen)
2016-08-14 15:17:14 +02:00
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 ) {
2016-09-09 20:41:20 +02:00
//retdata in json object parsen und anschlie<69> end das json Objekt "zerschneiden"
2016-08-14 15:17:14 +02:00
System . out . println ( retdata ) ;
JsonObject object = Json . parse ( retdata ) . asObject ( ) ;
2016-11-21 18:24:06 +01:00
String titelV = object . getString ( " Title " , " " ) ;
String yearV = object . getString ( " Year " , " " ) ;
String ratedV = object . getString ( " Rated " , " " ) ;
String releasedV = object . getString ( " Released " , " " ) ;
String runtimeV = object . getString ( " Runtime " , " " ) ;
String genreV = object . getString ( " Genre " , " " ) ;
String directorV = object . getString ( " Director " , " " ) ;
String writerV = object . getString ( " Writer " , " " ) ;
String actorsV = object . getString ( " Actors " , " " ) ;
String plotV = object . getString ( " Plot " , " " ) ;
String languageV = object . getString ( " Language " , " " ) ;
String countryV = object . getString ( " Country " , " " ) ;
String awardsV = object . getString ( " Awards " , " " ) ;
2016-08-14 15:17:14 +02:00
String posterURL = object . getString ( " Poster " , " " ) ;
2016-11-21 18:24:06 +01:00
String metascoreV = object . getString ( " Metascore " , " " ) ;
String imdbRatingV = object . getString ( " imdbRating " , " " ) ;
2016-08-14 15:17:14 +02:00
@SuppressWarnings ( " unused " )
2016-11-21 18:24:06 +01:00
String imdbVotesV = object . getString ( " imdbVotes " , " " ) ;
2016-08-14 15:17:14 +02:00
@SuppressWarnings ( " unused " )
2016-11-21 18:24:06 +01:00
String imdbIDV = object . getString ( " imdbID " , " " ) ;
String typeV = object . getString ( " Type " , " " ) ;
2016-08-14 15:17:14 +02:00
String response = object . getString ( " Response " , " " ) ;
2016-11-21 18:24:06 +01:00
2016-08-14 15:17:14 +02:00
if ( response . equals ( " False " ) ) {
2016-11-21 18:24:06 +01:00
ta1 . appendText ( noFilmFound ) ;
Image im2 = new Image ( " recources/icons/close_black_2048x2048.png " ) ;
2016-08-14 15:17:14 +02:00
image1 . setImage ( im2 ) ;
} else {
2016-11-21 18:24:06 +01:00
//ausgabe des Textes in ta1 in jeweils neuer Zeile //TODOformatting
ta1 . appendText ( title + " : " + titelV + " \ n " ) ;
ta1 . appendText ( year + " : " + yearV + " \ n " ) ;
ta1 . appendText ( rating + " : " + ratedV + " \ n " ) ;
ta1 . appendText ( publishedOn + " : " + releasedV + " \ n " ) ;
ta1 . appendText ( duration + " : " + runtimeV + " \ n " ) ;
ta1 . appendText ( genre + " : " + genreV + " \ n " ) ;
ta1 . appendText ( director + " : " + directorV + " \ n " ) ;
ta1 . appendText ( writer + " : " + writerV + " \ n " ) ;
ta1 . appendText ( actors + " : " + actorsV + " \ n " ) ;
ta1 . appendText ( plot + " : " + plotV + " \ n " ) ;
ta1 . appendText ( language + " : " + languageV + " \ n " ) ;
ta1 . appendText ( country + " : " + countryV + " \ n " ) ;
ta1 . appendText ( awards + " : " + awardsV + " \ n " ) ;
ta1 . appendText ( metascore + " : " + metascoreV + " \ n " ) ;
ta1 . appendText ( imdbRating + " : " + imdbRatingV + " \ n " ) ;
ta1 . appendText ( type + " : " + typeV + " \ n " ) ;
2016-08-14 15:17:14 +02:00
Image im1 = new Image ( posterURL ) ;
image1 . setImage ( im1 ) ;
}
}
} catch ( Exception e ) {
System . out . println ( e ) ;
} finally {
2016-11-21 18:24:06 +01:00
//closes datainputStream, InputStream,Scanner if not already done
2016-08-14 15:17:14 +02:00
try {
if ( dis ! = null ) {
dis . close ( ) ;
}
if ( is ! = null ) {
is . close ( ) ;
}
if ( sc ! = null ) {
sc . close ( ) ;
}
} catch ( Exception e2 ) {
;
}
}
}
2016-08-14 17:03:39 +02:00
}