Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.89 KB | None | 0 0
  1. package view;
  2.  
  3. import com.sun.javafx.tk.AppletWindow;
  4. import controller.AddRoomController;
  5. import javafx.beans.binding.Bindings;
  6. import javafx.beans.binding.BooleanBinding;
  7. import javafx.geometry.Insets;
  8. import javafx.geometry.Pos;
  9. import javafx.scene.Scene;
  10. import javafx.scene.control.Alert;
  11. import javafx.scene.control.Button;
  12. import javafx.scene.control.Label;
  13. import javafx.scene.control.RadioButton;
  14. import javafx.scene.control.TextField;
  15. import javafx.scene.control.ToggleGroup;
  16. import javafx.scene.layout.BorderPane;
  17. import javafx.scene.layout.GridPane;
  18. import javafx.scene.layout.VBox;
  19. import javafx.stage.Stage;
  20. import model.Room;
  21. import model.exception.InvalidDateException;
  22. import model.exception.InvalidNumBedsException;
  23. import model.exception.InvalidRoomIdException;
  24.  
  25.  
  26. public class AddRoomView extends Stage {
  27.  
  28. public AddRoomView(Room room) {
  29.  
  30. // Create a pane and set its properties
  31. BorderPane pane = new BorderPane();
  32. setWidth(900);
  33. setWidth(700);
  34.  
  35. // Place nodes in the pane
  36. ToggleGroup tg = new ToggleGroup();
  37. RadioButton suite = new RadioButton("Suite");
  38. RadioButton standard = new RadioButton("Standard");
  39.  
  40. suite.setToggleGroup(tg);
  41. standard.setToggleGroup(tg);
  42.  
  43. tg.selectToggle(suite);
  44.  
  45. addRoomPane defaultpane = new addRoomPane("suite");
  46. defaultpane.addSuite();
  47. pane.setCenter(defaultpane);
  48. pane.setTop(new MenuView());
  49. pane.setLeft(new VBox(suite,standard));
  50. suite.setOnAction(e -> {
  51.  
  52. addRoomPane ar = new addRoomPane("suite");
  53. ar.addSuite();
  54. pane.setCenter(ar);
  55.  
  56.  
  57.  
  58.  
  59. });
  60.  
  61. standard.setOnAction(e -> {
  62.  
  63.  
  64. addRoomPane ar = new addRoomPane("suite");
  65. ar.addStandardRoom();
  66. pane.setCenter(ar);
  67.  
  68.  
  69.  
  70. });
  71.  
  72. // adding buttons and fields to pane
  73.  
  74.  
  75.  
  76. // Create a scene and place it in the stage
  77. Scene scene1 = new Scene(pane);
  78.  
  79. setTitle("Add Room");
  80. setScene(scene1);
  81. show();
  82.  
  83.  
  84. }
  85. }
  86.  
  87. class addRoomPane extends GridPane {
  88. String roomType;
  89. Room room;
  90. AddRoomController controller = new AddRoomController(room);
  91.  
  92.  
  93. public addRoomPane(String roomType) {
  94. this.roomType = roomType;
  95. }
  96.  
  97. public void addStandardRoom() {
  98.  
  99. TextField roomIdField = new TextField();
  100. TextField numBedsField = new TextField();
  101. //disable and enable fields when suite is selected
  102.  
  103. BooleanBinding standardBind =
  104. Bindings.length(roomIdField.textProperty()).isEqualTo(0)
  105. .or(Bindings.length(numBedsField.textProperty()).isEqualTo(0)) ;
  106.  
  107.  
  108.  
  109.  
  110. //prompt texts for field boxes
  111.  
  112.  
  113.  
  114. add(new Label("Room ID:"), 2, 0);
  115. add(roomIdField, 2, 1);
  116. add(new Label("Number of Beds:"), 4, 0);
  117. add(numBedsField, 4, 1);
  118.  
  119. Button btAdd = new Button("Add Standard Room");
  120. add(btAdd, 1, 4);
  121.  
  122. btAdd.disableProperty().bind(standardBind);
  123.  
  124.  
  125. btAdd.setOnAction(event -> {
  126.  
  127. String roomId = roomIdField.getText();
  128. String numBeds = numBedsField.getText();
  129.  
  130. try {
  131. controller.addStandardRoom(roomId, numBeds);
  132.  
  133. } catch (InvalidRoomIdException e) {
  134. e.printStackTrace();
  135. } catch (InvalidNumBedsException e) {
  136. e.printStackTrace();
  137. }
  138. });
  139.  
  140.  
  141. }
  142.  
  143. public void addSuite() {
  144.  
  145. TextField roomIdField = new TextField();
  146. TextField lastMaintenanceField = new TextField();
  147. //disable and enable fields when suite is selected
  148.  
  149. BooleanBinding suiteBind = roomIdField.textProperty().isEmpty()
  150. .or(lastMaintenanceField.textProperty().isEmpty());
  151.  
  152. Button btAdd = new Button("Add Suite");
  153. add(btAdd, 1, 4);
  154. btAdd.disableProperty().bind(suiteBind);
  155.  
  156. //prompt texts for field boxes
  157. lastMaintenanceField.setPromptText("dd/mm/yyyy");
  158. roomIdField.setPromptText("R_000 or S_000");
  159.  
  160. add(new Label("Room ID:"), 2, 0);
  161. add(roomIdField, 2, 1);
  162. add(new Label("Last Maintenance Date:"), 3, 0);
  163. add(lastMaintenanceField, 3, 1);
  164.  
  165.  
  166. btAdd.setOnAction(event -> {
  167.  
  168. String lastMaintenanceDate = lastMaintenanceField.getText();
  169. String roomId = roomIdField.getText();
  170.  
  171. try {
  172. controller.addSuite(roomId, lastMaintenanceDate);
  173. } catch (InvalidDateException e1) {
  174. Alert a = new Alert(Alert.AlertType.WARNING, "Invalid Date Format. Date should follow dd/mm/yyyy format.");
  175. a.show();
  176.  
  177. } catch (InvalidRoomIdException e) {
  178. e.printStackTrace();
  179. }
  180. });
  181.  
  182.  
  183. }
  184.  
  185. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement