2016-08-14 15:17:14 +02:00
/ * *
* Project HomeFlix
*
2017-02-09 20:39:43 +01:00
* Copyright 2016 - 2017 < admin @kellerkinder >
2016-08-14 15:17:14 +02:00
*
* 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 .
*
* /
2017-04-15 17:54:47 +02:00
2017-07-26 17:10:37 +02:00
package org.kellerkinder.Project_HomeFlix ;
2017-02-09 16:27:52 +01:00
2016-08-14 15:17:14 +02:00
import java.io.File ;
import java.io.IOException ;
2017-02-09 16:27:52 +01:00
import java.util.Locale ;
2016-08-14 15:17:14 +02:00
import java.util.Optional ;
2017-02-09 16:27:52 +01:00
import java.util.ResourceBundle ;
2017-09-16 18:22:46 +02:00
import org.apache.logging.log4j.LogManager ;
import org.apache.logging.log4j.Logger ;
2016-08-14 15:17:14 +02:00
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.stage.DirectoryChooser ;
import javafx.stage.Stage ;
public class Main extends Application {
2017-03-20 22:32:54 +01:00
Stage primaryStage ;
2016-08-14 15:17:14 +02:00
private String path ;
2017-06-04 20:13:04 +02:00
String currentWorkingDirectory ;
2017-04-06 12:07:34 +02:00
private String COLOR = " ee3523 " ;
private String FONT_FAMILY = " System " ;
private String mode = " local " ; //local or streaming TODO
2017-02-09 20:39:43 +01:00
private String local = System . getProperty ( " user.language " ) + " _ " + System . getProperty ( " user.country " ) ;
2017-04-06 12:07:34 +02:00
private boolean AUTO_UPDATE = false ;
private double FONT_SIZE = 17 ;
2017-02-09 20:39:43 +01:00
private ResourceBundle bundle ;
private MainWindowController mainWindowController ;
2017-04-06 12:07:34 +02:00
private File directory ;
private File settingsFile ;
2017-04-09 15:07:56 +02:00
private File posterCache ;
2017-04-06 12:07:34 +02:00
private String dirWin = System . getProperty ( " user.home " ) + " /Documents/HomeFlix " ; //Windows: C:/Users/"User"/Documents/HomeFlix
private String dirLinux = System . getProperty ( " user.home " ) + " /HomeFlix " ; //Linux: /home/"User"/HomeFlix
2017-09-16 18:22:46 +02:00
private static Logger LOGGER ;
2016-08-14 15:17:14 +02:00
@Override
2017-04-25 23:35:20 +02:00
public void start ( Stage primaryStage ) throws IOException {
currentWorkingDirectory = new java . io . File ( " . " ) . getCanonicalPath ( ) ;
2017-06-04 20:13:04 +02:00
this . primaryStage = primaryStage ;
2016-08-14 15:17:14 +02:00
mainWindow ( ) ;
}
2017-03-05 18:29:24 +01:00
private void mainWindow ( ) {
2017-06-04 20:13:04 +02:00
2016-08-14 15:17:14 +02:00
try {
2017-09-16 18:22:46 +02:00
FXMLLoader loader = new FXMLLoader ( ) ;
loader . setLocation ( ClassLoader . getSystemResource ( " fxml/MainWindow.fxml " ) ) ;
AnchorPane pane = ( AnchorPane ) 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 ( " /icons/Homeflix_Icon_64x64.png " ) ) ) ; //adds application icon
mainWindowController = loader . getController ( ) ; //Link of FXMLController and controller class
mainWindowController . setAutoUpdate ( AUTO_UPDATE ) ; //set auto-update
mainWindowController . setCurrentWorkingDirectory ( currentWorkingDirectory ) ;
mainWindowController . setMain ( this ) ; //call setMain
/ * * Linux else Windows , check if directory & config exist
* Windows : config file : C : / Users / " User " / Documents / HomeFlix / config . xml
* directory : C : / Users / " User " / Documents / HomeFlix
* Linux : config file : / home / " User " / HomeFlix / config . xml
* directory : / home / " User " / HomeFlix
* /
if ( System . getProperty ( " os.name " ) . equals ( " Linux " ) ) {
directory = new File ( dirLinux ) ;
settingsFile = new File ( dirLinux + " /config.xml " ) ;
} else {
directory = new File ( dirWin ) ;
settingsFile = new File ( dirWin + " /config.xml " ) ;
}
posterCache = new File ( directory + " /posterCache " ) ;
if ( ! settingsFile . exists ( ) ) {
directory . mkdir ( ) ;
mainWindowController . setPath ( firstStart ( ) ) ;
mainWindowController . setStreamingPath ( directory . getAbsolutePath ( ) ) ;
mainWindowController . setColor ( COLOR ) ;
mainWindowController . setSize ( FONT_SIZE ) ;
mainWindowController . setAutoUpdate ( AUTO_UPDATE ) ;
mainWindowController . setLocal ( local ) ;
mainWindowController . setMode ( mode ) ;
mainWindowController . saveSettings ( ) ;
try {
Runtime . getRuntime ( ) . exec ( " java -jar ProjectHomeFlix.jar " ) ; //start again (preventing Bugs)
System . exit ( 0 ) ; //finishes it self
} catch ( Exception e ) {
LOGGER . error ( " error while restarting HomeFlix " , e ) ;
}
}
if ( ! posterCache . exists ( ) ) {
posterCache . mkdir ( ) ;
}
mainWindowController . loadSettings ( ) ;
mainWindowController . loadStreamingSettings ( ) ;
mainWindowController . initUI ( ) ;
mainWindowController . initActions ( ) ;
mainWindowController . initTabel ( ) ;
mainWindowController . setLocalUI ( ) ;
mainWindowController . applyColor ( ) ; //set theme color
mainWindowController . dbController . main ( ) ; //initialize database controller
mainWindowController . dbController . createDatabase ( ) ; //creating the database
mainWindowController . dbController . loadData ( ) ; //loading data from database to mainWindowController
mainWindowController . addDataUI ( ) ;
Scene scene = new Scene ( pane ) ; //create new scene, append pane to scene
scene . getStylesheets ( ) . add ( getClass ( ) . getResource ( " /css/MainWindow.css " ) . toExternalForm ( ) ) ;
primaryStage . setScene ( scene ) ; //append scene to stage
primaryStage . show ( ) ; //show stage
2016-08-14 15:17:14 +02:00
} catch ( IOException e ) {
2017-09-16 18:22:46 +02:00
LOGGER . error ( " " , e ) ;
2016-08-14 15:17:14 +02:00
}
}
2017-02-09 16:27:52 +01:00
//Method for first Start
2016-08-14 15:17:14 +02:00
private String firstStart ( ) {
2017-02-09 20:39:43 +01:00
MainWindowController . firststart = true ;
2017-02-09 16:27:52 +01:00
switch ( System . getProperty ( " user.language " ) + " _ " + System . getProperty ( " user.country " ) ) {
2017-07-26 17:10:37 +02:00
case " en_US " : bundle = ResourceBundle . getBundle ( " locals.HomeFlix-Local " , Locale . US ) ; //us_english
2017-02-09 16:27:52 +01:00
break ;
2017-07-26 17:10:37 +02:00
case " de_DE " : bundle = ResourceBundle . getBundle ( " locals.HomeFlix-Local " , Locale . GERMAN ) ; //German
2017-02-09 16:27:52 +01:00
break ;
2017-07-26 17:10:37 +02:00
default : bundle = ResourceBundle . getBundle ( " locals.HomeFlix-Local " , Locale . US ) ; //default local
2017-02-09 16:27:52 +01:00
break ;
}
Alert alert = new Alert ( AlertType . CONFIRMATION ) ; //new alert with file-chooser
2016-08-14 15:17:14 +02:00
alert . setTitle ( " Project HomeFlix " ) ;
2017-02-09 16:27:52 +01:00
alert . setHeaderText ( bundle . getString ( " firstStartHeader " ) ) ;
alert . setContentText ( bundle . getString ( " firstStartContent " ) ) ;
2016-08-14 15:17:14 +02:00
Optional < ButtonType > result = alert . showAndWait ( ) ;
if ( result . get ( ) = = ButtonType . OK ) {
DirectoryChooser directoryChooser = new DirectoryChooser ( ) ;
File selectedDirectory =
directoryChooser . showDialog ( primaryStage ) ;
path = selectedDirectory . getAbsolutePath ( ) ;
} else {
path = " " ;
}
return path ;
}
2017-02-09 20:39:43 +01:00
2016-08-14 15:17:14 +02:00
public static void main ( String [ ] args ) {
2017-09-16 18:22:46 +02:00
if ( System . getProperty ( " os.name " ) . equals ( " Linux " ) ) {
System . setProperty ( " logFilename " , System . getProperty ( " user.home " ) + " /HomeFlix/app.log " ) ;
File logFile = new File ( System . getProperty ( " user.home " ) + " /HomeFlix/app.log " ) ;
logFile . delete ( ) ;
} else {
System . setProperty ( " logFilename " , System . getProperty ( " user.home " ) + " /Documents/HomeFlix/app.log " ) ;
File logFile = new File ( System . getProperty ( " user.home " ) + " /Documents/HomeFlix/app.log " ) ;
logFile . delete ( ) ;
}
LOGGER = LogManager . getLogger ( Main . class . getName ( ) ) ;
2016-08-14 15:17:14 +02:00
launch ( args ) ;
}
2017-04-06 12:07:34 +02:00
public String getFONT_FAMILY ( ) {
return FONT_FAMILY ;
}
public void setFONT_FAMILY ( String FONT_FAMILY ) {
this . FONT_FAMILY = FONT_FAMILY ;
}
2017-04-09 15:07:56 +02:00
public File getPosterCache ( ) {
return posterCache ;
}
public void setPosterCache ( File posterCache ) {
this . posterCache = posterCache ;
}
2016-08-14 15:17:14 +02:00
}