Java tutorial
/* * 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 javafx.application.Platform; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.fxml.Initializable; import javafx.geometry.Rectangle2D; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.ScrollPane; import javafx.scene.layout.AnchorPane; import javafx.stage.Screen; import javafx.stage.Stage; import javafx.stage.StageStyle; import org.springframework.context.ApplicationContext; import com.toyota.carservice.config.config; import com.toyota.carservice.config.config2; /** * FXML Controller class * * @author Herudi */ public class CarMenuManagement implements Initializable { @FXML private Button close; @FXML private Button maximize; @FXML private Button minimize; @FXML private Button resize; @FXML private Button fullscreen; @FXML private Label title; @FXML private AnchorPane paneDataCar; Stage stage; Rectangle2D rec2; Double w, h; config2 con = new config2(); @FXML private Button btnLogout; @FXML private Button btnAdd; @FXML private ScrollPane scrollPane; @FXML private Button btnBack; CarServiceController carController; @FXML private Button btnSaveCar; @FXML private Button btnBackMenu; @FXML private Button btnDeleteCar; private CarMenuController carMenuController; @Override public void initialize(URL url, ResourceBundle rb) { ApplicationContext appContex = config.getInstance().getApplicationContext(); rec2 = Screen.getPrimary().getVisualBounds(); w = 0.1; h = 0.1; Platform.runLater(() -> { stage = (Stage) maximize.getScene().getWindow(); stage.setMaximized(true); stage.setHeight(rec2.getHeight()); maximize.getStyleClass().add("decoration-button-restore"); resize.setVisible(false); loadMenu(); }); } @FXML private void aksiMaximized(ActionEvent event) { stage = (Stage) maximize.getScene().getWindow(); if (stage.isMaximized()) { if (w == rec2.getWidth() && h == rec2.getHeight()) { stage.setMaximized(false); stage.setHeight(600); stage.setWidth(800); stage.centerOnScreen(); maximize.getStyleClass().remove("decoration-button-restore"); resize.setVisible(true); } else { stage.setMaximized(false); maximize.getStyleClass().remove("decoration-button-restore"); resize.setVisible(true); } } else { stage.setMaximized(true); stage.setHeight(rec2.getHeight()); maximize.getStyleClass().add("decoration-button-restore"); resize.setVisible(false); } } @FXML private void aksiminimize(ActionEvent event) { stage = (Stage) minimize.getScene().getWindow(); if (stage.isMaximized()) { w = rec2.getWidth(); h = rec2.getHeight(); stage.setMaximized(false); stage.setHeight(h); stage.setWidth(w); stage.centerOnScreen(); Platform.runLater(() -> { stage.setIconified(true); }); } else { stage.setIconified(true); } } @FXML private void aksiResize(ActionEvent event) { } @FXML private void aksifullscreen(ActionEvent event) { stage = (Stage) fullscreen.getScene().getWindow(); if (stage.isFullScreen()) { stage.setFullScreen(false); } else { stage.setFullScreen(true); } } @FXML private void aksiClose(ActionEvent event) { Platform.exit(); System.exit(0); } protected void loadMenu() { CarMenuController carMenuController = (CarMenuController) con.loadAnchorPane(paneDataCar, "anchorMenu.fxml"); carMenuController.setListener(this); } @FXML private void btnAddOnClick(ActionEvent event) { carController = (CarServiceController) con.loadAnchorPane(paneDataCar, "anchorCar.fxml"); carController.setListener(this); displayButton(true, false, true, true); } @FXML private void btnPlayOnClick() { config2 config = new config2(); SwitchController switchController = (SwitchController) config.newStage2(stage, btnBack, "/com/toyota/carservice/view/formSwitchMode.fxml", "", true, StageStyle.UNDECORATED, false); switchController.hasLogion(true); } @FXML private void aksiLogout(ActionEvent event) { config2 config = new config2(); config.newStage2(stage, btnLogout, "/com/toyota/carservice/view/login.fxml", "Sample Apps", true, StageStyle.UNDECORATED, false); } @FXML private void btnBackOnClick(ActionEvent e) { loadMenu(); displayButton(false, true, false, false); } @FXML public void btnDeleteCarOnClick() { if (carController != null) carController.btnDeleteCarOnClick(); btnDeleteCar.setOpacity(0); btnSaveCar.setOpacity(0); displayButton(false, true, false, false); this.loadMenu(); } @FXML public void btnSaveCarOnClick() { if (carController.btnSaveCarOnClick(null)) { displayButton(false, true, false, false); this.loadMenu(); } } public void setListenerCarService(CarServiceController carController) { this.carController = carController; } public void displayButton(boolean displayBack, boolean displayAdd, boolean displaySave, boolean displayDelete) { btnAdd.setOpacity((displayAdd) ? 1 : 0); btnBackMenu.setOpacity((displayAdd) ? 1 : 0); btnSaveCar.setOpacity((displaySave) ? 1 : 0); btnDeleteCar.setOpacity((displayDelete) ? 1 : 0); btnBack.setOpacity((displayBack) ? 1 : 0); if (displayBack) btnBack.toFront(); else btnBack.toBack(); } }