Skip to content
Snippets Groups Projects
Commit 35f9da0b authored by ArktikHunter's avatar ArktikHunter
Browse files

Commit before refactoring dailyView and WeeklyView

parent e149df5d
No related branches found
No related tags found
1 merge request!4View schedule
package com.example.schedulerapp;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.HPos;
import javafx.geometry.Insets;
import javafx.scene.Node;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Popup;
import java.util.ArrayList;
......@@ -11,6 +18,7 @@ public class DailyView extends GridPane implements ModelSubscriber{
Model model;
iModel iModel;
ArrayList<Label> times;
Popup dropShift;
public DailyView() {
//list of time labels
......@@ -85,7 +93,7 @@ public class DailyView extends GridPane implements ModelSubscriber{
if (shift.getEnd().getMinute() == 0) text += "00";
else text += "30"; //only two options for minutes
Button shiftRep = new Button(text);
ShiftButton shiftRep = new ShiftButton(text, shift);
shiftRep.setMaxHeight(700); //so it always fills its region
shiftRep.setPrefWidth(60);
GridPane.setFillHeight(shiftRep, true);
......@@ -94,16 +102,77 @@ public class DailyView extends GridPane implements ModelSubscriber{
//todo: different colour for current user
shiftRep.setStyle("-fx-background-color: skyblue");
shiftRep.setOnAction(dropShiftPopUp);
//shiftRep.setOnMouseClicked(e -> System.out.println("test button click"));
this.add(shiftRep, col, row, 1, length);
col++;
}
}
public void drawPopUp(Shift shift){
dropShift = new Popup();
dropShift.setHeight(300);
dropShift.setWidth(300);
VBox details = new VBox();
details.setStyle("-fx-background-color: papayawhip; -fx-border-color: black");
details.setPadding(new Insets(20));
details.setSpacing(20);
Label name = new Label("Name: " + shift.getEmployeeID()); //todo: display name instead
Label start = new Label("Start: " + shift.getStart().toString());
Label end = new Label("End: " + shift.getEnd().toString());
HBox buttons = new HBox();
//todo: only display buttons if this is your shift
Button cancel = new Button("Cancel");
cancel.setCancelButton(true);
cancel.setOnAction(cancelDrop); //debug
Button drop = new Button("Drop Shift");
drop.setDefaultButton(true);
drop.setOnAction(dropShiftConfirm); //debug
buttons.getChildren().addAll(cancel, drop);
details.getChildren().addAll(name, start, end, buttons);
dropShift.getContent().add(details);
dropShift.setAutoHide(true);
}
@Override
public void modelChanged() {
draw();
}
EventHandler<ActionEvent> dropShiftPopUp =
new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent e) {
drawPopUp(((ShiftButton) e.getSource()).getShift());
dropShift.show(((Node) e.getSource()).getScene().getWindow());
}
};
EventHandler<ActionEvent> dropShiftConfirm =
new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent e) {
System.out.println("todo: drop shift :)");
dropShift.hide();
}
};
EventHandler<ActionEvent> cancelDrop =
new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent actionEvent) {
System.out.println("Shift drop cancelled.");
dropShift.hide();
}
};
}
package com.example.schedulerapp;
import javafx.scene.control.Button;
//stores the shift for easy retrieval
public class ShiftButton extends Button {
Shift shift;
public ShiftButton(String text, Shift newShift){
super(text);
shift = newShift;
}
public Shift getShift(){
return shift;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment