2018-12-03 21:33:16 +01:00
package com.jFxKasse.application ;
2018-12-03 20:27:55 +01:00
import javafx.application.Application ;
2018-03-29 19:45:41 +02:00
import java.io.File ;
2018-04-05 11:08:50 +02:00
import javafx.animation.Animation ;
import javafx.animation.KeyFrame ;
import javafx.animation.Timeline ;
2018-03-29 19:45:41 +02:00
import javafx.fxml.FXMLLoader ;
import javafx.stage.Stage ;
2018-04-05 11:08:50 +02:00
import javafx.util.Duration ;
2018-12-03 21:12:00 +01:00
import com.jFxKasse.controller.MainWindowController ;
2018-12-06 13:11:35 +01:00
import com.jFxKasse.controller.PrinterController ;
2018-12-05 22:44:15 +01:00
import com.jFxKasse.controller.XMLController ;
2018-12-03 21:12:00 +01:00
import com.jFxKasse.controller.DBController ;
2018-03-29 19:45:41 +02:00
import javafx.scene.Scene ;
import javafx.scene.layout.AnchorPane ;
2018-04-05 12:25:29 +02:00
2018-12-03 20:39:51 +01:00
public class Main extends Application
2018-03-29 19:51:34 +02:00
{
2018-12-06 15:10:28 +01:00
// path to config.xml and the database
public static String filepath ;
private static String osName = System . getProperty ( " os.name " ) ;
2018-12-05 22:44:15 +01:00
2018-12-06 15:10:28 +01:00
private static String userHome = System . getProperty ( " user.home " ) ;
2018-12-05 22:44:15 +01:00
2018-03-29 19:45:41 +02:00
private MainWindowController mwc ;
2018-03-29 19:51:34 +02:00
2018-12-06 15:10:28 +01:00
private XMLController xmlc = new XMLController ( filepath ) ;
private DBController dbc = new DBController ( filepath ) ;
2018-12-05 22:44:15 +01:00
2018-12-06 13:11:35 +01:00
private PrinterController pc = new PrinterController ( ) ;
2018-03-29 19:51:34 +02:00
2018-03-29 19:45:41 +02:00
private Stage primaryStage ;
2018-03-29 19:51:34 +02:00
2018-03-29 19:45:41 +02:00
@Override
2018-03-29 19:51:34 +02:00
public void start ( Stage primaryStage )
{
2018-03-29 19:45:41 +02:00
this . primaryStage = primaryStage ;
2018-12-06 15:10:28 +01:00
System . out . println ( " \ nstarting jFxKasse \ n " ) ;
2018-03-29 19:45:41 +02:00
mainWindow ( ) ;
}
2018-03-29 19:51:34 +02:00
private void mainWindow ( )
{
2018-03-29 19:45:41 +02:00
try {
2018-03-29 19:51:34 +02:00
FXMLLoader loader = new FXMLLoader (
2018-12-03 20:27:55 +01:00
getClass ( ) . getResource ( " /fxml/MainWindow.fxml " ) ) ;
2018-12-03 20:39:51 +01:00
2018-03-29 19:45:41 +02:00
AnchorPane pane = loader . load ( ) ;
2018-10-01 11:31:05 +02:00
primaryStage . setTitle ( " jFxKasse " ) ; // Title of window
2018-03-29 19:45:41 +02:00
2018-12-06 15:10:28 +01:00
mwc = loader . getController ( ) ; // set the mwc as the JavaFx
// MainWindowController
pc . searchPrinters ( ) ; // search for available printers
mwc . setMain ( this , dbc , xmlc , pc ) ; // set the created instances to the
// mwc
2018-03-29 19:45:41 +02:00
2018-12-06 15:10:28 +01:00
firstStart ( ) ; // test if this is the first run
2018-03-29 19:45:41 +02:00
Scene scene = new Scene ( pane ) ;
2018-12-03 20:39:51 +01:00
scene . getStylesheets ( ) . add (
Main . class . getResource ( " /css/application.css " ) . toExternalForm ( ) ) ;
2018-03-29 19:51:34 +02:00
primaryStage . setScene ( scene ) ;
2018-04-05 11:08:50 +02:00
primaryStage . show ( ) ; // shows the stage
Timeline timeline = new Timeline (
new KeyFrame ( Duration . seconds ( 1 ) , ev - > {
2018-12-06 15:10:28 +01:00
mwc . updateTimeLabel ( ) ; // update time label on UI
2018-04-05 11:08:50 +02:00
} ) ) ;
timeline . setCycleCount ( Animation . INDEFINITE ) ;
timeline . play ( ) ;
2018-03-29 19:51:34 +02:00
} catch ( Exception e ) {
2018-03-29 19:45:41 +02:00
e . printStackTrace ( ) ;
}
}
2018-03-29 19:51:34 +02:00
public static void main ( String [ ] args )
{
2018-12-06 15:10:28 +01:00
if ( osName . contains ( " Windows " ) ) {
System . out . println ( " FCK Windows " ) ;
filepath = userHome + " /Documents/jFxKasse/ " ;
} else {
filepath = userHome + " /jFxKasse/ " ;
}
2018-03-29 19:45:41 +02:00
launch ( args ) ;
}
2018-04-02 20:31:47 +02:00
/ * *
* Checks if the config . xml is preset .
* /
2018-03-29 19:51:34 +02:00
private void firstStart ( ) throws Exception
{
2018-12-05 22:44:15 +01:00
if ( xmlc . loadSettings ( ) ) {
2018-04-02 20:31:47 +02:00
// config.xml found, app starting normal
2018-12-06 15:10:28 +01:00
System . out . println ( " XML found! " ) ;
2018-04-02 20:31:47 +02:00
mwc . initUI ( ) ; // Starting the UI elements
mwc . setDBLabel ( ) ; // Set databese labels
2018-12-05 22:44:15 +01:00
dbc . setDbname ( xmlc . getDatabaseName ( ) ) ; // handover database name
2018-04-02 20:31:47 +02:00
dbc . connectDatabase ( ) ; // estabishing DB conection
mwc . fillTablePositionen ( ) ; // fill TreeTable 'Positionen'
2018-10-01 11:31:05 +02:00
mwc . fillCategory ( ) ;
2018-12-06 13:11:35 +01:00
mwc . fillPrinterSettings ( ) ;
2018-10-07 00:50:59 +02:00
mwc . fillTableJobs ( ) ;
2018-04-03 00:45:22 +02:00
mwc . loadGridButtons ( ) ;
2018-12-03 15:04:07 +01:00
mwc . getSelectedCat ( ) ; // Load DB entries in Chois Box
2018-10-05 13:01:42 +02:00
mwc . createNewJob ( ) ;
2018-04-02 20:31:47 +02:00
} else {
// config.xml NOT found, first start of app
2018-12-06 15:10:28 +01:00
System . out . println ( " no XML found! " ) ;
2018-12-05 22:44:15 +01:00
xmlc . initXML ( ) ; // set default values
2018-04-02 20:31:47 +02:00
mwc . blockUI ( true ) ; // disable UI elements that need DB
2018-10-05 23:01:30 +02:00
mwc . blockUnlock ( ) ;
2018-12-06 15:10:28 +01:00
File dir = new File ( filepath ) ;
2018-04-02 20:31:47 +02:00
dir . mkdir ( ) ; // Create new Subfolder
2018-03-29 19:45:41 +02:00
}
}
}