com.toyota.carservice.controller.SwitchController.java Source code

Java tutorial

Introduction

Here is the source code for com.toyota.carservice.controller.SwitchController.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.toyota.carservice.controller;

import java.net.URL;
import java.util.ResourceBundle;

import org.springframework.context.ApplicationContext;

import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import javafx.util.Duration;

import com.toyota.carservice.animations.FadeInTransition;
import com.toyota.carservice.animations.FadeOutRightTransition;
import com.toyota.carservice.animations.FadeOutUpTransition;
import com.toyota.carservice.config.config;
import com.toyota.carservice.config.config2;
import com.toyota.carservice.implementjdbc.CarDaoJdbcImpl;
import com.toyota.carservice.implementjdbc.UserDaoJdbcImpl;

/**
 * FXML Controller class
 *
 * @author Edi.Y
 * 
 */
public class SwitchController implements Initializable {

    @FXML
    private Button btnKelolaData;
    @FXML
    private Button btnInformasiService;
    @FXML
    private Label lblClose;

    @FXML
    private TextField txtUsername;

    @FXML
    private TextField txtPassword;

    @FXML
    private Label lblConfirmation;

    @FXML
    private AnchorPane paneMenu;

    @FXML
    private AnchorPane paneLogin;

    Stage stage;

    @Override
    public void initialize(URL url, ResourceBundle rb) {
        Platform.runLater(() -> {
            new FadeInTransition(btnInformasiService).play();
            new FadeInTransition(btnKelolaData).play();
            lblClose.setOnMouseClicked((MouseEvent event) -> {
                Platform.exit();
                System.exit(0);
            });
        });
    }

    @FXML
    private void aksiKelolaData(ActionEvent event) {
        config2 c = new config2();
        c.newStage(stage, lblClose, "/com/toyota/carservice/view/formCarMenu.fxml", "Kelola Data Informasi Service",
                true, StageStyle.UNDECORATED, false);
    }

    @FXML
    private void aksiInformasiService(ActionEvent event) {
        config2 c = new config2();
        c.newStage(stage, lblClose, "/com/toyota/carservice/view/formServiceInformation.fxml",
                "Informasi Data Service", true, StageStyle.UNDECORATED, false);
    }

    @FXML
    private void btnLoginOnAction(ActionEvent event) {
        ApplicationContext ctx = config.getInstance().getApplicationContext();
        UserDaoJdbcImpl userDaoImpl = ctx.getBean(UserDaoJdbcImpl.class);
        //       if(userDaoImpl.check(txtUsername.getText(), txtPassword.getText())>0){
        if (Boolean.TRUE) {
            paneMenu.toFront();
            paneMenu.setOpacity(1);
            paneLogin.setOpacity(0);
            lblClose.toFront();
        } else {
            new FadeInTransition(lblConfirmation).playFrom(Duration.millis(15));
        }
    }

    public void hasLogion(boolean hasLogin) {
        paneMenu.toFront();
        paneMenu.setOpacity(1);
        paneLogin.setOpacity(0);
        lblClose.toFront();
    }

}