-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomerStartScreen.java
More file actions
108 lines (89 loc) · 3.4 KB
/
Copy pathCustomerStartScreen.java
File metadata and controls
108 lines (89 loc) · 3.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package bookstoreapp;
/**
*
* @author vguru
*/
import javafx.collections.*;
import javafx.scene.*;
import javafx.scene.control.*;
import javafx.scene.text.*;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.*;
import javafx.geometry.*;
import javafx.stage.Stage;
public class CustomerStartScreen {
public Group display(Stage primaryStage, Customer cust, ObservableList<Book> books) {
Group screen = new Group();
Button logout = new Button("Logout");
Button buy1 = new Button("Buy");
Button buy2 = new Button("Redeem Points and Buy");
TableView<Book> table = new TableView<>();
// Message for Customer
Text greeting = new Text("Welcome, " + cust.getUser() + ".\nYour status is: " + cust.getStatus());
greeting.setFont(new Font(14));
// Title column
TableColumn<Book, String> title = new TableColumn<>("Title");
title.setMinWidth(200);
title.setCellValueFactory(new PropertyValueFactory<>("name"));
// Price column
TableColumn<Book, Double> price = new TableColumn<>("Price");
price.setMinWidth(100);
price.setCellValueFactory(new PropertyValueFactory<>("price"));
// Checkbox column
TableColumn<Book, String> select = new TableColumn<>("Select");
select.setMinWidth(100);
select.setCellValueFactory(cellData -> cellData.getValue().getSelect().selectedProperty());
table.setItems(books);
table.getColumns().addAll(title, price, select);
// Button actions
buy1.setOnAction(e -> {
double total = 0.0;
for (Book book : books) {
if (book.getSelect().isSelected()) {
total += book.getPrice();
}
}
if (total > 0) {
BookstoreApp app = (BookstoreApp) primaryStage.getUserData();
if (app != null) {
app.showCustomerCostScreen(cust, total, false);
BookStore.saveCustomers();
}
}
});
buy2.setOnAction(e -> {
double total = 0.0;
for (Book book : books) {
if (book.getSelect().isSelected()) {
total += book.getPrice();
}
}
if (total > 0) {
BookstoreApp app = (BookstoreApp) primaryStage.getUserData();
if (app != null) {
app.showCustomerCostScreen(cust, total, true);
BookStore.saveCustomers();
}
}
});
logout.setOnAction(e -> {
BookstoreApp app = (BookstoreApp) primaryStage.getUserData();
if (app != null) {
app.showLoginScreen();
}
});
BorderPane header = new BorderPane();
HBox bot = new HBox();
header.setCenter(greeting);
bot.getChildren().addAll(buy1, buy2, logout);
bot.setAlignment(Pos.BOTTOM_CENTER);
bot.setSpacing(5);
VBox vbox = new VBox();
vbox.setSpacing(10);
vbox.setAlignment(Pos.CENTER);
vbox.setPadding(new Insets(40, 200, 30, 100));
vbox.getChildren().addAll(header, table, bot);
screen.getChildren().addAll(vbox);
return screen;
}
}