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