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