Projects / Hotel Management System / src / hoteldraft / RoomsController.java
RoomsController.java
Raw
/*
 * 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 hoteldraft;

import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.animation.RotateTransition;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.SnapshotParameters;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.effect.BoxBlur;
import javafx.scene.effect.ColorAdjust;
import javafx.scene.effect.Light;
import javafx.scene.effect.Lighting;
import javafx.scene.image.ImageView;
import javafx.scene.image.WritableImage;
import javafx.scene.input.MouseEvent;
import javafx.scene.paint.Color;
import static javafx.scene.paint.Color.rgb;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
import javafx.util.Duration;

/**
 *
 * @author Hala
 */
public class RoomsController implements Initializable{
    
    private double xOffSet = 0;
    private double yOffSet = 0;
    
    private Stage stage;
    private Scene scene;
    private Parent root;
    @FXML
    private ImageView settingsImg;
    @FXML
    private Label exit;
    @FXML
    private Label minimize;
    @FXML
    private Button settingsImgBtn;
    
    @FXML
    private Label Single;
    @FXML
    private Label Double;
    @FXML
    private Label Queen;
    @FXML
    private Label King;
    @FXML
    private Label Suite;
    @FXML
    private Label miniSuite;
    @FXML
    private ImageView SingleImg;
    @FXML
    private ImageView TwinImg;
    @FXML
    private ImageView QueenImg;
    @FXML
    private ImageView KingImg;
    @FXML
    private ImageView SuiteImg;
    @FXML
    private ImageView MiniSuiteImg;

    @Override
    public void initialize(URL location, ResourceBundle resources) {
        
        //blurr box for all images
        BoxBlur bb = new BoxBlur();
        bb.setWidth(2);
        bb.setHeight(2);
        bb.setIterations(3);

        //----------------------single room img---------------------------------
        // set a clip to apply rounded border to the original image.
        Rectangle clip1 = new Rectangle(
                SingleImg.getFitWidth(), SingleImg.getFitHeight()
        );
        clip1.setArcWidth(20);
        clip1.setArcHeight(20);
        SingleImg.setClip(clip1);
        // snapshot the rounded image.
        SnapshotParameters parameters1 = new SnapshotParameters();
        parameters1.setFill(Color.TRANSPARENT);
        WritableImage image = SingleImg.snapshot(parameters1, null);
        // remove the rounding clip so that our effect can show through.
        SingleImg.setClip(null);
        // store the rounded image in the imageView.
        SingleImg.setImage(image);
        SingleImg.setEffect(bb);

        //----------------------twin room img-----------------------------------
        // set a clip to apply rounded border to the original image.
        Rectangle clip2 = new Rectangle(
                TwinImg.getFitWidth(), TwinImg.getFitHeight()
        );
        clip2.setArcWidth(20);
        clip2.setArcHeight(20);
        TwinImg.setClip(clip2);
        // snapshot the rounded image.
        SnapshotParameters parameters2 = new SnapshotParameters();
        parameters2.setFill(Color.TRANSPARENT);
        WritableImage image2 = TwinImg.snapshot(parameters2, null);
        // remove the rounding clip so that our effect can show through.
        TwinImg.setClip(null);
        // store the rounded image in the imageView.
        TwinImg.setImage(image2);
        TwinImg.setEffect(bb);

        //----------------------queen room img----------------------------------
        // set a clip to apply rounded border to the original image.
        Rectangle clip3 = new Rectangle(
                QueenImg.getFitWidth(), QueenImg.getFitHeight()
        );
        clip3.setArcWidth(20);
        clip3.setArcHeight(20);
        QueenImg.setClip(clip3);
        // snapshot the rounded image.
        SnapshotParameters parameters3 = new SnapshotParameters();
        parameters3.setFill(Color.TRANSPARENT);
        WritableImage image3 = QueenImg.snapshot(parameters3, null);
        // remove the rounding clip so that our effect can show through.
        QueenImg.setClip(null);
        // store the rounded image in the imageView.
        QueenImg.setImage(image3);
        QueenImg.setEffect(bb);

        //----------------------king room img-----------------------------------
        // set a clip to apply rounded border to the original image.
        Rectangle clip4 = new Rectangle(
                KingImg.getFitWidth(), KingImg.getFitHeight()
        );
        clip4.setArcWidth(20);
        clip4.setArcHeight(20);
        KingImg.setClip(clip4);
        // snapshot the rounded image.
        SnapshotParameters parameters4 = new SnapshotParameters();
        parameters4.setFill(Color.TRANSPARENT);
        WritableImage image4 = KingImg.snapshot(parameters4, null);
        // remove the rounding clip so that our effect can show through.
        KingImg.setClip(null);
        // store the rounded image in the imageView.
        KingImg.setImage(image4);
        KingImg.setEffect(bb);

        //---------------------------suite img----------------------------------
        // set a clip to apply rounded border to the original image.
        Rectangle clip5 = new Rectangle(
                SuiteImg.getFitWidth(), SuiteImg.getFitHeight()
        );
        clip5.setArcWidth(20);
        clip5.setArcHeight(20);
        SuiteImg.setClip(clip5);
        // snapshot the rounded image.
        SnapshotParameters parameters5 = new SnapshotParameters();
        parameters5.setFill(Color.TRANSPARENT);
        WritableImage image5 = SuiteImg.snapshot(parameters5, null);
        // remove the rounding clip so that our effect can show through.
        SuiteImg.setClip(null);
        // store the rounded image in the imageView.
        SuiteImg.setImage(image5);
        SuiteImg.setEffect(bb);

        //------------------------mini suite img--------------------------------
        // set a clip to apply rounded border to the original image.
        Rectangle clip6 = new Rectangle(
                MiniSuiteImg.getFitWidth(), MiniSuiteImg.getFitHeight()
        );
        clip6.setArcWidth(20);
        clip6.setArcHeight(20);
        MiniSuiteImg.setClip(clip6);
        // snapshot the rounded image.
        SnapshotParameters parameters6 = new SnapshotParameters();
        parameters6.setFill(Color.TRANSPARENT);
        WritableImage image6 = MiniSuiteImg.snapshot(parameters6, null);
        // remove the rounding clip so that our effect can show through.
        MiniSuiteImg.setClip(null);
        // store the rounded image in the imageView.
        MiniSuiteImg.setImage(image6);
        MiniSuiteImg.setEffect(bb);
        
        //to change settings imageview color
        Lighting lighting = new Lighting(new Light.Distant(45, 90, rgb(105, 152, 171)));
        ColorAdjust bright = new ColorAdjust(0, 1, 1, 1);
        lighting.setContentInput(bright);
        lighting.setSurfaceScale(0.0);
        settingsImg.setEffect(lighting);
        
        // to rotate settings button on hover
        RotateTransition rotation = new RotateTransition(Duration.seconds(0.5),settingsImgBtn);
        rotation.setCycleCount(1);
        rotation.setByAngle(180);
        settingsImgBtn.setOnMouseEntered(e -> rotation.play());
        settingsImgBtn.setOnMouseExited(e -> rotation.pause());
    }

    //Methods to close and minimize window.
    @FXML
    private void close_app(javafx.scene.input.MouseEvent event) {
        System.exit(0);
    }
    
    @FXML
    private void minimize_app(javafx.scene.input.MouseEvent event) {
        stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
        stage.setIconified(true);
    }
    
    @FXML
    private void SingleclickToRooms(javafx.scene.input.MouseEvent e) throws IOException {
        
        RoomsAvaiabilityController.indexOfRoom=1;
        
        Parent root = FXMLLoader.load(getClass().getResource("RoomsAvailability.fxml"));
        
        root.setOnMousePressed((event) -> {
            xOffSet = event.getSceneX();
            yOffSet = event.getSceneY();
        });
        root.setOnMouseDragged((event) -> {
            stage.setX(event.getScreenX() - xOffSet);
            stage.setY(event.getScreenY() - yOffSet);
        });
        
        stage = (Stage) ((Node) e.getSource()).getScene().getWindow();
        scene = new Scene(root,Color.TRANSPARENT);
        stage.setScene(scene);
        stage.show();
    }
    @FXML
    private void DoubleclickToRooms(javafx.scene.input.MouseEvent e) throws IOException {
        
        RoomsAvaiabilityController.indexOfRoom=2;
        
        Parent root = FXMLLoader.load(getClass().getResource("RoomsAvailability.fxml"));
        
        root.setOnMousePressed((event) -> {
            xOffSet = event.getSceneX();
            yOffSet = event.getSceneY();
        });
        root.setOnMouseDragged((event) -> {
            stage.setX(event.getScreenX() - xOffSet);
            stage.setY(event.getScreenY() - yOffSet);
        });
        
        stage = (Stage) ((Node) e.getSource()).getScene().getWindow();
        scene = new Scene(root,Color.TRANSPARENT);
        stage.setScene(scene);
        stage.show();
    }
    @FXML
    private void QueenclickToRooms(javafx.scene.input.MouseEvent e) throws IOException {
        
        RoomsAvaiabilityController.indexOfRoom=3;
        
        Parent root = FXMLLoader.load(getClass().getResource("RoomsAvailability.fxml"));
        
        root.setOnMousePressed((event) -> {
            xOffSet = event.getSceneX();
            yOffSet = event.getSceneY();
        });
        root.setOnMouseDragged((event) -> {
            stage.setX(event.getScreenX() - xOffSet);
            stage.setY(event.getScreenY() - yOffSet);
        });
        
        stage = (Stage) ((Node) e.getSource()).getScene().getWindow();
        scene = new Scene(root,Color.TRANSPARENT);
        stage.setScene(scene);
        stage.show();
    }
    
    @FXML
    private void KingclickToRooms(javafx.scene.input.MouseEvent e) throws IOException {
        
        RoomsAvaiabilityController.indexOfRoom=4;
        
        Parent root = FXMLLoader.load(getClass().getResource("RoomsAvailability.fxml"));
        
        root.setOnMousePressed((event) -> {
            xOffSet = event.getSceneX();
            yOffSet = event.getSceneY();
        });
        root.setOnMouseDragged((event) -> {
            stage.setX(event.getScreenX() - xOffSet);
            stage.setY(event.getScreenY() - yOffSet);
        });
        
        stage = (Stage) ((Node) e.getSource()).getScene().getWindow();
        scene = new Scene(root,Color.TRANSPARENT);
        stage.setScene(scene);
        stage.show();
    }
    @FXML
    private void SuiteclickToRooms(javafx.scene.input.MouseEvent e) throws IOException {
        
        RoomsAvaiabilityController.indexOfRoom=5;
        
        Parent root = FXMLLoader.load(getClass().getResource("RoomsAvailability.fxml"));
        
        root.setOnMousePressed((event) -> {
            xOffSet = event.getSceneX();
            yOffSet = event.getSceneY();
        });
        root.setOnMouseDragged((event) -> {
            stage.setX(event.getScreenX() - xOffSet);
            stage.setY(event.getScreenY() - yOffSet);
        });
        
        stage = (Stage) ((Node) e.getSource()).getScene().getWindow();
        scene = new Scene(root,Color.TRANSPARENT);
        stage.setScene(scene);
        stage.show();
    }
    @FXML
    private void miniSuiteclickToRooms(javafx.scene.input.MouseEvent e) throws IOException {
        
        RoomsAvaiabilityController.indexOfRoom=6;
        
        Parent root = FXMLLoader.load(getClass().getResource("RoomsAvailability.fxml"));
        
        root.setOnMousePressed((event) -> {
            xOffSet = event.getSceneX();
            yOffSet = event.getSceneY();
        });
        root.setOnMouseDragged((event) -> {
            stage.setX(event.getScreenX() - xOffSet);
            stage.setY(event.getScreenY() - yOffSet);
        });
        
        stage = (Stage) ((Node) e.getSource()).getScene().getWindow();
        scene = new Scene(root,Color.TRANSPARENT);
        stage.setScene(scene);
        stage.show();
    }
    
    /*---------------------class switching events---------------------*/
    @FXML
    private void switchToReservations(ActionEvent e) throws IOException {
        Parent root = FXMLLoader.load(getClass().getResource("Reservations.fxml"));
        
        root.setOnMousePressed((event) -> {
            xOffSet = event.getSceneX();
            yOffSet = event.getSceneY();
        });
        root.setOnMouseDragged((event) -> {
            stage.setX(event.getScreenX() - xOffSet);
            stage.setY(event.getScreenY() - yOffSet);
        });
        
        stage = (Stage) ((Node) e.getSource()).getScene().getWindow();
        scene = new Scene(root,Color.TRANSPARENT);
        stage.setScene(scene);
        stage.show();
    }

    private void switchToNewReservation(ActionEvent e) throws IOException {
        Parent root = FXMLLoader.load(getClass().getResource("NewReservation.fxml"));
        
        root.setOnMousePressed((event) -> {
            xOffSet = event.getSceneX();
            yOffSet = event.getSceneY();
        });
        root.setOnMouseDragged((event) -> {
            stage.setX(event.getScreenX() - xOffSet);
            stage.setY(event.getScreenY() - yOffSet);
        });
        
        stage = (Stage) ((Node) e.getSource()).getScene().getWindow();
        scene = new Scene(root,Color.TRANSPARENT);
        stage.setScene(scene);
        stage.show();

    }

    @FXML
    private void switchToLoggedIn(ActionEvent e) throws IOException {
        Parent root = FXMLLoader.load(getClass().getResource("LoggedIn.fxml"));
        
        root.setOnMousePressed((event) -> {
            xOffSet = event.getSceneX();
            yOffSet = event.getSceneY();
        });
        root.setOnMouseDragged((event) -> {
            stage.setX(event.getScreenX() - xOffSet);
            stage.setY(event.getScreenY() - yOffSet);
        });
        
        stage = (Stage) ((Node) e.getSource()).getScene().getWindow();
        scene = new Scene(root,Color.TRANSPARENT);
        stage.setScene(scene);
        stage.show();
    }

    @FXML
    private void switchToRooms(ActionEvent e) throws IOException {
        Parent root = FXMLLoader.load(getClass().getResource("Rooms.fxml"));
        
        root.setOnMousePressed((event) -> {
            xOffSet = event.getSceneX();
            yOffSet = event.getSceneY();
        });
        root.setOnMouseDragged((event) -> {
            stage.setX(event.getScreenX() - xOffSet);
            stage.setY(event.getScreenY() - yOffSet);
        });/**/
        
        stage = (Stage) ((Node) e.getSource()).getScene().getWindow();
        scene = new Scene(root,Color.TRANSPARENT);
        stage.setScene(scene);
        stage.show();
    }

    @FXML
    private void switchToServices(ActionEvent e) throws IOException {
        Parent root = FXMLLoader.load(getClass().getResource("Services.fxml"));
        
        root.setOnMousePressed((event) -> {
            xOffSet = event.getSceneX();
            yOffSet = event.getSceneY();
        });
        root.setOnMouseDragged((event) -> {
            stage.setX(event.getScreenX() - xOffSet);
            stage.setY(event.getScreenY() - yOffSet);
        });
        
        stage = (Stage) ((Node) e.getSource()).getScene().getWindow();
        scene = new Scene(root,Color.TRANSPARENT);
        stage.setScene(scene);
        stage.show();
    }

    @FXML
    private void switchToSearch(ActionEvent e) throws IOException {
        Parent root = FXMLLoader.load(getClass().getResource("Search.fxml"));
        
        root.setOnMousePressed((event) -> {
            xOffSet = event.getSceneX();
            yOffSet = event.getSceneY();
        });
        root.setOnMouseDragged((event) -> {
            stage.setX(event.getScreenX() - xOffSet);
            stage.setY(event.getScreenY() - yOffSet);
        });
        
        stage = (Stage) ((Node) e.getSource()).getScene().getWindow();
        scene = new Scene(root,Color.TRANSPARENT);
        stage.setScene(scene);
        stage.show();
    }
    
    @FXML
    private void switchToSettings(ActionEvent e) throws IOException {
        Parent root = FXMLLoader.load(getClass().getResource("Settings.fxml"));
        
        root.setOnMousePressed((event) -> {
            xOffSet = event.getSceneX();
            yOffSet = event.getSceneY();
        });
        root.setOnMouseDragged((event) -> {
            stage.setX(event.getScreenX() - xOffSet);
            stage.setY(event.getScreenY() - yOffSet);
        });
        
        stage = (Stage) ((Node) e.getSource()).getScene().getWindow();
        scene = new Scene(root,Color.TRANSPARENT);
        stage.setScene(scene);
        stage.show();
    }
}