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