aboutsummaryrefslogtreecommitdiff
path: root/src/dk.biks.bachelorizer/dk/biks/bachelorizer/Window.java
blob: 475de52481c739d9228dde2449c7588ea61bffc7 (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. /// Label styling
  23. public static String LABEL_STYLE =
  24. "-fx-font-weight: bold; -fx-font-size: 20;";
  25. /// Application model
  26. private GUI model = new GUI();
  27. /// Application controller
  28. private Control control = new Control(model, this);
  29. /// Name of student
  30. private TextField nameEntry = new TextField();
  31. /// Text entry for adding an activity
  32. private TextField activityEntry = new TextField();
  33. /// Text area for activity entries
  34. private TextArea area = new TextArea();
  35. /// Button to delete one activity
  36. private Button delOne = new Button("Delete one");
  37. /// Button to delete all activities
  38. private Button delAll = new Button("Delete all");
  39. /// Application instantiation
  40. ///
  41. /// @param args application parameters
  42. public static void main(final String[] args) {
  43. launch(args);
  44. }
  45. @Override
  46. public void start(final Stage stage) {
  47. // pass application parameters to controller
  48. control.setParameters(getParameters().getRaw());
  49. // add listeners
  50. // NameEntry.setOnAction(e -> control.enterName(
  51. // activityEntry.getText()));
  52. activityEntry.setOnAction(e -> control.enterActivity(
  53. activityEntry.getText()));
  54. delOne.setOnAction(e -> control.delOne());
  55. delAll.setOnAction(e -> control.delAll());
  56. // add buttons
  57. VBox root = new VBox(10,
  58. ourHBox("Student", nameEntry),
  59. ourHBox("Add activity", activityEntry),
  60. new HBox(10, delOne, delAll),
  61. area);
  62. // compose stage
  63. Scene scene = new Scene(root, 500, 500);
  64. stage.setTitle("JavaFX Demo");
  65. stage.setScene(scene);
  66. stage.show();
  67. }
  68. /// action to apply student name
  69. ///
  70. /// @param s Text to apply
  71. public void setStudentName(final String s) {
  72. nameEntry.setText(s);
  73. }
  74. /// action to apply text to area
  75. ///
  76. /// @param s Text to apply
  77. public void setArea(final String s) {
  78. area.setText(s);
  79. }
  80. /// Button action to clear field
  81. public void clearActivityEntry() {
  82. activityEntry.setText("");
  83. }
  84. /// Styled HBox with label and TextField
  85. ///
  86. /// @param s Label string
  87. /// @param f Text field
  88. /// @return HBox containing styled label and text field
  89. public HBox ourHBox(final String s, final TextField f) {
  90. Label label = new Label(s+":");
  91. label.setStyle(LABEL_STYLE);
  92. return new HBox(10, label, f);
  93. }
  94. }