2018-03-29 19:51:34 +02:00
package 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.application.Application ;
import javafx.fxml.FXMLLoader ;
import javafx.stage.Stage ;
2018-04-05 11:08:50 +02:00
import javafx.util.Duration ;
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-03-29 19:45:41 +02:00
2018-03-29 19:51:34 +02:00
public class Main extends Application
{
2018-03-29 19:45:41 +02:00
private MainWindowController mwc ;
2018-03-29 19:51:34 +02:00
2018-03-29 19:45:41 +02:00
private DBController dbc = new DBController ( this ) ;
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 ;
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 (
getClass ( ) . getResource ( " MainWindow.fxml " ) ) ;
2018-03-29 19:45:41 +02:00
AnchorPane pane = loader . load ( ) ;
2018-04-02 20:31:47 +02:00
primaryStage . setTitle ( " jFxKasse " ) ; // Title of window
2018-03-29 19:45:41 +02:00
mwc = loader . getController ( ) ;
mwc . setMain ( this , dbc ) ;
2018-04-02 20:31:47 +02:00
firstStart ( ) ;
2018-03-29 19:45:41 +02:00
Scene scene = new Scene ( pane ) ;
2018-03-29 19:51:34 +02:00
scene . getStylesheets ( )
. add ( Main . class . getResource ( " application.css " ) . toExternalForm ( ) ) ;
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-04-05 12:25:29 +02:00
mwc . updateTimeLabel ( ) ; // update time
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-03-29 19:45:41 +02:00
launch ( args ) ;
}
2018-04-02 20:31:47 +02:00
/ * *
* Checks if the config . xml is preset .
* @author hendrik
* /
2018-03-29 19:51:34 +02:00
private void firstStart ( ) throws Exception
{
2018-04-02 20:31:47 +02:00
if ( mwc . loadSettings ( ) ) {
// config.xml found, app starting normal
2018-03-31 23:50:17 +02:00
System . out . println ( " XML gefunden! " ) ;
2018-04-02 20:31:47 +02:00
mwc . initUI ( ) ; // Starting the UI elements
mwc . setDBLabel ( ) ; // Set databese labels
dbc . dbname = mwc . getDatabaseName ( ) ; // handover database name
dbc . connectDatabase ( ) ; // estabishing DB conection
mwc . fillTablePositionen ( ) ; // fill TreeTable 'Positionen'
2018-04-03 00:45:22 +02:00
mwc . loadGridButtons ( ) ;
2018-04-02 20:31:47 +02:00
} else {
// config.xml NOT found, first start of app
2018-03-29 19:45:41 +02:00
System . out . println ( " keine XML gefunden! " ) ;
2018-04-02 20:31:47 +02:00
mwc . blockUI ( true ) ; // disable UI elements that need DB
File dir = new File ( System . getProperty ( " user.home " ) + " /bin/jFxKasse " ) ;
dir . mkdir ( ) ; // Create new Subfolder
2018-03-29 19:45:41 +02:00
}
}
}