aboutsummaryrefslogtreecommitdiff
path: root/dk/abcdefghijklmnopqrstuvxyzæøå/bachelorizer/view/Window.java
blob: bf2af3d99143ed56398403eb67d4f15c31742aa8 (plain)
  1. // SPDX-FileCopyrightText: 2025 Jonas Smedegaard <dr@jones.dk>
  2. // SPDX-License-Identifier: GPL-3.0-or-later
  3. package dk.abcdefghijklmnopqrstuvxyzæøå.bachelorizer.view;
  4. import java.util.List;
  5. import javafx.application.Application;
  6. import javafx.scene.control.Button;
  7. import javafx.scene.control.Label;
  8. import javafx.scene.control.TextArea;
  9. import javafx.scene.control.TextField;
  10. import javafx.scene.layout.HBox;
  11. import javafx.scene.layout.VBox;
  12. import javafx.scene.Scene;
  13. import javafx.stage.Stage;
  14. import dk.abcdefghijklmnopqrstuvxyzæøå.bachelorizer.Control;
  15. import dk.abcdefghijklmnopqrstuvxyzæøå.bachelorizer.model.GUI;
  16. /// Bachelorizer - JavaFX Window view
  17. // Class is final to forbid subclassing,
  18. // because object is passed to controller during instatiation
  19. public final class Window extends Application { // the View
  20. /// Default constructor
  21. // (declared explicitly only to silence javadoc)
  22. public Window() {
  23. }
  24. /// Label styling
  25. public static String LABEL_STYLE =
  26. "-fx-font-weight: bold; -fx-font-size: 20;";
  27. /// Application model
  28. private GUI model = new GUI();
  29. /// Application controller
  30. private Control control = new Control(model, this);
  31. /// Name of student
  32. private TextField nameEntry = new TextField();
  33. /// Text entry for adding an activity
  34. private TextField activityEntry = new TextField();
  35. /// Text area for activity entries
  36. private TextArea area = new TextArea();
  37. /// Button to delete one activity
  38. private Button delOne = new Button("Delete one");
  39. /// Button to delete all activities
  40. private Button delAll = new Button("Delete all");
  41. /// Application instantiation
  42. ///
  43. /// @param args application parameters
  44. public static void main(String[] args) {
  45. launch(args);
  46. }
  47. @Override
  48. public void start(Stage stage) {
  49. // pass application parameters to controller
  50. control.setParameters(getParameters().getRaw());
  51. // add listeners
  52. // NameEntry.setOnAction(e -> control.enterName(
  53. // activityEntry.getText()));
  54. activityEntry.setOnAction(e -> control.enterActivity(
  55. activityEntry.getText()));
  56. delOne.setOnAction(e -> control.delOne());
  57. delAll.setOnAction(e -> control.delAll());
  58. // add buttons
  59. VBox root = new VBox(10,
  60. ourHBox("Student", nameEntry),
  61. ourHBox("Add activity", activityEntry),
  62. new HBox(10, delOne, delAll),
  63. area);
  64. // compose stage
  65. Scene scene = new Scene(root, 500, 500);
  66. stage.setTitle("JavaFX Demo");
  67. stage.setScene(scene);
  68. stage.show();
  69. }
  70. /// action to apply student name
  71. ///
  72. /// @param s Text to apply
  73. public void setStudentName(String s) {
  74. nameEntry.setText(s);
  75. }
  76. /// action to apply text to area
  77. ///
  78. /// @param s Text to apply
  79. public void setArea(String s) {
  80. area.setText(s);
  81. }
  82. /// Button action to clear field
  83. public void clearActivityEntry() {
  84. activityEntry.setText("");
  85. }
  86. /// Styled HBox with label and TextField
  87. ///
  88. /// @param s Label string
  89. /// @param f Text field
  90. /// @return HBox containing styled label and text field
  91. public HBox ourHBox(String s, TextField f) {
  92. Label label = new Label(s+":");
  93. label.setStyle(LABEL_STYLE);
  94. return new HBox(10, label, f);
  95. }
  96. }