-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathElectronicStoreView.java
More file actions
137 lines (115 loc) · 5.28 KB
/
ElectronicStoreView.java
File metadata and controls
137 lines (115 loc) · 5.28 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
mport javafx.collections.FXCollections;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.ListView;
import javafx.scene.control.TextField;
import javafx.scene.layout.Pane;
//VIEW
public class ElectronicStoreView extends Pane {
//Create all necessary attributes and get methods
private final ListView<Product> stockList;
private final ListView<String> cartList;
private final ListView<Product> popularList;
private final Label cartLabel;
private final TextField saleField;
private final TextField revenueField;
private final TextField costField;
private final Button resetButton;
private final Button addButton;
private final Button removeButton;
private final Button completeSaleButton;
public ListView<Product> getStockList() { return stockList; }
public ListView<String> getCartList() { return cartList; }
public Button getAddButton() {return addButton;}
public Button getRemoveButton() {return removeButton;}
public Button getCompleteSaleButton() {return completeSaleButton;}
public Button getResetButton(){return resetButton;}
public ElectronicStoreView() {
// Create the labels
Label storeSummary = new Label("Store Summary:");
storeSummary.relocate(22, 44);
Label salesLabel = new Label("#Sales:");
salesLabel.relocate(22, 88);
Label revenueLabel = new Label("Revenue:");
revenueLabel.relocate(22, 132);
Label aveLabel = new Label("$/Sale");
aveLabel.relocate(22, 176);
Label popularLabel = new Label("Most Popular Items:");
popularLabel.relocate(22, 220);
Label stockLabel = new Label("Store Stock:");
stockLabel.relocate(240, 44);
cartLabel = new Label("Current Cart($0.00):");
cartLabel.relocate(570, 44);
// Create the TextFields
saleField = new TextField();
saleField.relocate(131, 88);
saleField.setPrefSize(91,22);
saleField.setText("0");
revenueField = new TextField();
revenueField.relocate(131, 132);
revenueField.setPrefSize(91,22);
revenueField.setText("0");
costField = new TextField();
costField.relocate(131, 176);
costField.setPrefSize(91,22);
costField.setText("N/A");
// Create the lists
stockList = new ListView<>();
stockList.relocate(240, 88);
stockList.setPrefSize(305,287);
cartList = new ListView<>();
cartList.relocate(570, 88);
cartList.setPrefSize(305,287);
getChildren().add(cartList);
popularList = new ListView<>();
popularList.relocate(9, 264);
popularList.setPrefSize(209,109);
getChildren().add(popularList);
// Create the buttons
resetButton = new Button("RESET");
resetButton.relocate(35, 383);
resetButton.setPrefSize(131,48);
resetButton.setStyle("-fx-font: 18 arial; -fx-background-color: BLACK; -fx-text-fill: WHITE;");
getChildren().add(resetButton);
addButton = new Button("Add");
addButton.relocate(313, 383);
addButton.setPrefSize(131,48);
addButton.setStyle("-fx-font: 18 arial; -fx-background-color: GREEN; -fx-text-fill: WHITE;");
getChildren().add(addButton);
removeButton = new Button("Remove");
removeButton.relocate(570, 383);
removeButton.setPrefSize(153,48);
removeButton.setStyle("-fx-font: 18 arial; -fx-background-color: RED; -fx-text-fill: WHITE;");
getChildren().add(removeButton);
completeSaleButton = new Button("Complete Sale");
completeSaleButton.relocate(723, 383);
completeSaleButton.setPrefSize(153,48);
completeSaleButton.setStyle("-fx-font: 18 arial; -fx-background-color: rgb(255, 213, 0); -fx-text-fill: BLACK;");
getChildren().add(completeSaleButton);
// Add all the components to the Pane
getChildren().addAll(cartLabel, storeSummary, salesLabel , revenueLabel, aveLabel, popularLabel, stockLabel, saleField, revenueField, costField, stockList);
setPrefSize(900, 444);
}
//Create the update method
public void update(ElectronicStore model) {
//Set popular list and cart list display, sale field, revenue field and cost field using the needed method from the model
if(model.getPopularProducts().size() >0){
popularList.setItems(FXCollections.observableArrayList(model.getPopularProducts()));
}
stockList.setItems(FXCollections.observableArrayList(model.getStockList()));
saleField.setText(""+model.getSoldCount());
revenueField.setText(""+model.getRevenue());
if(model.getAverage() > 0){
costField.setText(""+model.getAverage());
}else{
costField.setText("0");
}
cartList.setItems(FXCollections.observableArrayList(model.CartArray()));
//Set buttons based on events
addButton.setDisable(stockList.getSelectionModel().getSelectedIndex() < 0);
removeButton.setDisable(cartList.getSelectionModel().getSelectedIndex() < 0);
completeSaleButton.setDisable(model.CartArray().size() == 0);
//set Cost label based on items in cart
cartLabel.setText("Current Cart($"+ model.getCartPrice() +"):");
}
}