Repository for the HealthTool which enables Apple users to analyse their health data from the Apple health app and prepares the data for contributing it for future studies on wearable data.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

130 lines
3.0 KiB

3 years ago
  1. package application.customviews;
  2. import application.helpers.Utils;
  3. import application.helpers.wrappers.SubElement;
  4. import application.res.Colors;
  5. import application.res.Text;
  6. import javafx.beans.property.BooleanProperty;
  7. import javafx.beans.property.SimpleBooleanProperty;
  8. import javafx.beans.value.ChangeListener;
  9. import javafx.event.EventHandler;
  10. import javafx.scene.control.Label;
  11. import javafx.scene.input.MouseEvent;
  12. import javafx.scene.layout.BorderPane;
  13. import javafx.scene.layout.HBox;
  14. import javafx.scene.shape.Circle;
  15. /**
  16. * This class represents one of the sub elements of the select view.
  17. * {@link EntryView}s can contain sub elements like the information concerning
  18. * the date of birth which is represented in this class. They can be selected on
  19. * their own and the selection state is indicated by a circle on the left side
  20. * of the sub element.
  21. *
  22. * @author Bianca
  23. *
  24. */
  25. public class SubEntryView extends HBox
  26. {
  27. /**
  28. * Circle which indicates the selection state. Invisible / grey if not selected,
  29. * green if selected.
  30. */
  31. private Circle c;
  32. /**
  33. * Property which indicates whether the sub element is selected.
  34. */
  35. private BooleanProperty selected;
  36. /**
  37. * Data of this sub element.
  38. */
  39. private SubElement elem;
  40. /**
  41. * Initializes all attributes, sets up the view and draws the initial circle.
  42. * Starts in the unselected state.
  43. *
  44. * @param elem The data of the sub element.
  45. */
  46. public SubEntryView(SubElement elem)
  47. {
  48. this.elem=elem;
  49. selected = new SimpleBooleanProperty(false);
  50. BorderPane circleContainer = new BorderPane();
  51. c = new Circle(10, Colors.grey);
  52. circleContainer.setCenter(c);
  53. getChildren().add(circleContainer);
  54. getChildren().add(new Label(String.format(Text.F_ME_SAVE, Utils.shortenHKStrings(getName()), getValue())));
  55. setOnMouseClicked(new EventHandler<MouseEvent>()
  56. {
  57. @Override
  58. public void handle(MouseEvent event)
  59. {
  60. setSelected(!isSelected());
  61. }
  62. });
  63. }
  64. /**
  65. * Returns the name / identifier of the sub element.
  66. *
  67. * @return The described value.
  68. */
  69. public String getName()
  70. {
  71. return elem.getType();
  72. }
  73. /**
  74. * Returns the value / entrycount of the sub element.
  75. *
  76. * @return The described value.
  77. */
  78. public int getValue()
  79. {
  80. return elem.getValue();
  81. }
  82. /**
  83. * Allows for a listener to be attached to the selected property of the sub
  84. * element.
  85. *
  86. * @param listen Listener to add to the property
  87. */
  88. public void addCheckListener(ChangeListener<Boolean> listen)
  89. {
  90. selected.addListener(listen);
  91. }
  92. /**
  93. * Shows whether the element is selected or not.
  94. *
  95. * @return The describes value.
  96. */
  97. public boolean isSelected()
  98. {
  99. return selected.get();
  100. }
  101. /**
  102. * Changes the value of the selection of this element to the given selection and
  103. * adjusts the circles color.
  104. *
  105. * @param value The value the selection should take.
  106. */
  107. public void setSelected(boolean value)
  108. {
  109. if (value) //select
  110. {
  111. c.setFill(Colors.green);
  112. }
  113. else //remove selection
  114. {
  115. c.setFill(Colors.grey);
  116. }
  117. this.selected.set(value);
  118. }
  119. }