Commit f6bd4c15 authored by Janita Lillevik Røyseth's avatar Janita Lillevik Røyseth
Browse files

Refactoring of code. TodoTask now holds on CheckBox. Added functionality to...

Refactoring of code. TodoTask now holds on CheckBox. Added functionality to move tasks in the list, no icons for these functions yet.
parent 63c215f7
package edu.ntnu.idata1002.prosjekt2021.model;
import javafx.scene.control.CheckBox;
import java.util.ArrayList;
import java.util.List;
......@@ -49,6 +51,88 @@ public class Careplan {
this.tasks.remove(todoTask);
}
/**
* Changes the position of the given todotask with one spot down.
*
* @param todoTask the task to be moved up in the list
*/
public void changeTaskPositionUp(TodoTask todoTask) {
if(this.tasks.indexOf( todoTask ) == 0) {
//Do nothing
} else {
TodoTask todoTaskMovedDown = this.tasks.get(this.tasks.indexOf( todoTask )-1);
int todoTaskIndex = this.tasks.indexOf(todoTask);
this.tasks.set( this.tasks.indexOf( todoTask )-1, todoTask);
this.tasks.set( todoTaskIndex, todoTaskMovedDown);
}
}
/**
* Changes the position of the given todoTask with one spot up.
*
* @param todoTask todotask to be places one spot up.
*/
public void changeTaskPositionDown(TodoTask todoTask) {
if(this.tasks.indexOf( todoTask ) == this.tasks.size()-1) {
//Do nothing
} else {
TodoTask todoTaskMovedUp = this.tasks.get(this.tasks.indexOf( todoTask ) + 1);
int todoTaskIndex = this.tasks.indexOf(todoTask);
this.tasks.set( this.tasks.indexOf( todoTask ) + 1, todoTask);
this.tasks.set( todoTaskIndex, todoTaskMovedUp);
}
}
/**
* Changes the position of the given to do task to the
* bottom of the ArrayList.
*
* @param todoTask todoTask to be placed at the bottom.
*/
public void changeTaskPostitionBottom(TodoTask todoTask) {
if(this.tasks.indexOf( todoTask ) == this.tasks.size()-1) {
//Do nothing
} else {
for(TodoTask task : this.tasks) {
if(this.tasks.indexOf(task) > this.tasks.indexOf(todoTask)) {
this.tasks.set(this.tasks.indexOf(task)-1, task);
}
}
this.tasks.set( this.tasks.size()-1, todoTask);
}
}
/**
* Changes the position of the given todoTask to the
* top of the ArrayList.
*
* @param todoTask todoTask to be places at top.
*/
public void changeTaskPostitionTop(TodoTask todoTask) {
this.tasks.remove(todoTask);
this.tasks.add(0, todoTask);
}
/**
* Iterates over the list of todotasks and returns the todotask
* with the matching checkbox. If no matches are found, null will
* be returned.
*
* @param checkBox the checkbox to find to the corresponding todotask item for.
* @return todotask with the corresponding checkbox, or null if no matches are found.
*/
public TodoTask findTaskByCheckBox(CheckBox checkBox) {
TodoTask todoTaskFound = null;
for(TodoTask todoTask : this.tasks) {
if(checkBox.equals(todoTask.getCheckbox())) {
todoTaskFound = todoTask;
}
}
return todoTaskFound;
}
/**
* Returns the type of care in this careplan.
*
......@@ -69,8 +153,8 @@ public class Careplan {
public List<TodoTask> getTasksByTimeOfDay(String timeOfDay) {
List<TodoTask> tasksByTimeOfDay = new ArrayList<>();
for(TodoTask task : tasks) {
if(task.getTimeOfDay().equals(timeOfDay)) {
for (TodoTask task : tasks) {
if (task.getTimeOfDay().equals(timeOfDay)) {
tasksByTimeOfDay.add(task);
}
}
......
......@@ -31,7 +31,7 @@ public class Patient {
/**
* This patients phonenumber.
*/
private String phoneNumber;
private String phonenumber;
/**
......@@ -85,12 +85,12 @@ public class Patient {
*
* @param fullName full name of the patient.
* @param address address of the patient.
* @param phoneNumber telephone number of the patient.
* @param phonenumber telephone number of the patient.
* @param socialSecurityNumber unique socialSecurityNumber of the patient.
* @param city the city where this patient resides.
* @param postalCode the postal code where this patient resides.
*/
public Patient(String fullName, String address, String phoneNumber,
public Patient(String fullName, String address, String phonenumber,
String socialSecurityNumber, String city, int postalCode, Image picture){
//These fields are required, other fields can be set later.
if(fullName == null || fullName.isBlank() ||
......@@ -99,7 +99,7 @@ public class Patient {
}
this.fullName = fullName;
this.address = address;
this.phoneNumber = phoneNumber;
this.phonenumber = phonenumber;
this.socialSecurityNumber = socialSecurityNumber;
this.postalCode = postalCode;
this.city = city;
......@@ -145,8 +145,8 @@ public class Patient {
*
* @return telephone number of the patient.
*/
public String getPhoneNumber() {
return phoneNumber;
public String getPhonenumber() {
return phonenumber;
}
/**
......@@ -161,10 +161,10 @@ public class Patient {
/**
* Sets new telephone number to the patient.
*
* @param phoneNumber new telephone number of the patient.
* @param phonenumber new telephone number of the patient.
*/
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
public void setPhonenumber(String phonenumber) {
this.phonenumber = phonenumber;
}
/**
......
package edu.ntnu.idata1002.prosjekt2021.model;
import javafx.scene.control.CheckBox;
/**
* Represents a task. Holds a description, deadline by "time of day"
* and a boolean value for being finished.
......@@ -8,9 +10,8 @@ package edu.ntnu.idata1002.prosjekt2021.model;
* @version 24.04.2021
*/
public class TodoTask {
private String description;
private CheckBox checkBox;
private String timeOfDay;
private boolean isDone;
/**
* Creates an instance of task.
......@@ -19,9 +20,8 @@ public class TodoTask {
* @param timeOfDay the time of day when the task is to be done.
*/
public TodoTask(String description, String timeOfDay){
this.description = description;
this.checkBox = new CheckBox(description);
this.timeOfDay = timeOfDay;
this.isDone = false;
}
/**
......@@ -29,8 +29,8 @@ public class TodoTask {
*
* @return description of a task.
*/
public String getDescription() {
return description;
public CheckBox getCheckbox() {
return this.checkBox;
}
/**
......@@ -39,13 +39,7 @@ public class TodoTask {
* @param description new description of a task.
*/
public void setDescription(String description) {
if(description == null){
description = "";
}
if(description.isBlank()){
throw new IllegalArgumentException("Description cannot be empty or null");
}
this.description = description;
this.checkBox.setText(description);
}
/**
......@@ -73,15 +67,7 @@ public class TodoTask {
* returns <code>false</code> if task is not completed.
*/
public boolean isDone(){
return isDone;
return this.checkBox.isSelected();
}
/**
* Sets task to true when it is completed.
*
* @param status the status of the task
*/
public void setIsDone(boolean status){
this.isDone = status;
}
}
......@@ -87,7 +87,7 @@ public class TaskDetailsDialog extends Dialog<TodoTask> {
//Custom setup of dialog for EDIT mode
setTitle("Endre gjøremål");
getDialogPane().setHeaderText("Endre gjøremål");
description.setText(this.task.getDescription());
description.setText(this.task.getCheckbox().getText());
for(Object timeOfDay : deadLine.getItems()) {
if (task.getTimeOfDay().equals(timeOfDay)) {
deadLine.getSelectionModel().select(timeOfDay);
......
......@@ -8,12 +8,42 @@
-fx-background-color: f7f9fb;
}
.dialog-pane .button {
-fx-background-radius: 15;
-fx-background-color: #417bc5;
-fx-background-radius: 10;
-fx-background-color: #8eb9f0;
-fx-text-fill: white;
}
.dialog-pane .button:hover {
-fx-background-radius: 15;
-fx-background-color: rgba(57, 101, 164, 0.99);
-fx-background-radius: 10;
-fx-background-color: #417bc5;
-fx-text-fill: white;
}
.combo-box {
-fx-prompt-text-fill: #00375b;
-fx-background-color: #8eb9f0;
-fx-font-family: Helvetica;
}
.combo-box:hover {
-fx-prompt-text-fill: #00375b;
-fx-background-color: #417bc5;
-fx-font-family: Helvetica;
}
.combo-box .text-field {
-fx-prompt-text-fill: #00375b;
-fx-font-family: Helvetica;
}
.combo-box .text-field:focused {
-fx-prompt-text-fill: #00375b;
-fx-font-family: Helvetica;
}
.combo-box-base .text{
-fx-fill: #00375b;
}
.combo-box > .arrow-button > .arrow {
-fx-background-color: #00375b;
-fx-text-fill: #00375b;
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment