Package edu.spbstu.hoteldb

Source Code of edu.spbstu.hoteldb.Main

package edu.spbstu.hoteldb;

import java.awt.Dimension;
import java.awt.Toolkit;
import java.sql.SQLException;
import java.util.LinkedList;
import java.util.List;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuBar;
import javafx.scene.control.MenuItem;
import javafx.scene.control.TextArea;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import edu.spbstu.hoteldb.admin.panel.FinancePanel;
import edu.spbstu.hoteldb.admin.panel.PersonnelPanel;
import edu.spbstu.hoteldb.admin.panel.RootPanel;
import edu.spbstu.hoteldb.admin.panel.RootSearchPanel;
import edu.spbstu.hoteldb.admin.panel.StatisticsPanel;
import edu.spbstu.hoteldb.handlers.ExitEventHandler;
import edu.spbstu.hoteldb.interfaces.Panel;
import edu.spbstu.hoteldb.panels.CleaningPanel;
import edu.spbstu.hoteldb.panels.LoginPanel;
import edu.spbstu.hoteldb.panels.PanelType;
import edu.spbstu.hoteldb.panels.ReceptionPanel;
import edu.spbstu.hoteldb.panels.RegisterPanel;
import edu.spbstu.hoteldb.panels.ResultsPanel;
import edu.spbstu.hoteldb.panels.UserPanel;

public class Main extends Application {

  private TextArea results;
  private HBox content;

  public static void main(String[] args) {
    launch(args);
  }

  @Override
  public void start(Stage stage) throws Exception {
    stage.setTitle("Hotel_db");
    stage.setMinHeight(500);
    stage.setMinWidth(500);
    stage.setMaximized(true);

    results = new TextArea();
    content = new HBox();

    VBox root = new VBox();
    content.setSpacing(10);
    content.setPadding(new Insets(10, 10, 10, 10));

    List<Object> args = new LinkedList<Object>();
    args.add(0, results);
    args.add(1, this);
    LoginPanel cp = new LoginPanel();
    cp.connect();
    cp.create(args);

    HBox.setHgrow(cp, Priority.ALWAYS);
    root.getChildren().addAll(createMenuBar(), content);

    Dimension scrsize = Toolkit.getDefaultToolkit().getScreenSize();
    stage.setScene(new Scene(root, scrsize.width * 0.7, scrsize.height));
    stage.show();
    content.setPrefSize(stage.getWidth(), stage.getHeight());
    content.getChildren().addAll(cp,
        new ResultsPanel(results, stage.getWidth(), stage.getHeight()));
  }

  private MenuBar createMenuBar() {
    MenuBar menuBar = new MenuBar();
    Menu menuCommon = new Menu("Menu");
    MenuItem miexit = new MenuItem("Exit");
    miexit.setOnAction(new ExitEventHandler());
    MenuItem milogout = new MenuItem("Log out");
    milogout.setOnAction(new EventHandler<ActionEvent>() {
      @Override
      public void handle(ActionEvent arg0) {
        setPanel(PanelType.LoginPanel, null);
      }
    });
    menuCommon.getItems().addAll(milogout, miexit);
    menuBar.getMenus().addAll(menuCommon);
    return menuBar;
  }

  public Node createCleaningPanel() {
    VBox vbox = new VBox();
    return vbox;
  }

  public void setPanel(PanelType t, List<Object> args) {
    if (args == null) {
      args = new LinkedList<Object>();
    }
    Panel p = (Panel) content.getChildren().get(0);
    try {
      p.close();
    } catch (SQLException e) {
      e.printStackTrace();
    }

    content.getChildren().remove(0);

    Panel panel = null;
    args.add(0, results);
    switch (t) {
    case RootPanel:
      args.add(1, this);
      panel = new RootPanel();
      break;
    case LoginPanel:
      args.add(1, this);
      panel = new LoginPanel();
      break;
    case UserPanel:
      panel = new UserPanel();
      break;
    case ReceptionPanel:
      panel = new ReceptionPanel();
      break;
    case RegisterPanel:
      args.add(1, this);
      panel = new RegisterPanel();
      break;
    case FinancePanel:
      panel = new FinancePanel(this, args);
      break;
    case PersonnelPanel:
      panel = new PersonnelPanel(this);
      break;
    case StatisticsPanel:
      panel = new StatisticsPanel(this);
      break;
    case RootSearchPanel:
      panel = new RootSearchPanel(this);
      break;
    case CleaningPanel:
      panel = new CleaningPanel(results);
      break;
    default:
      throw new IllegalArgumentException("undefined panel");
    }

    try {
      panel.connect();
    } catch (ClassNotFoundException | SQLException e) {
      e.printStackTrace();
    }

    panel.create(args);

    HBox.setHgrow((Node) panel, Priority.ALWAYS);
    content.getChildren().add(0, (Node) panel);
  }
}
TOP

Related Classes of edu.spbstu.hoteldb.Main

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.