-
Notifications
You must be signed in to change notification settings - Fork 0
/
BuyerView.java
54 lines (46 loc) · 1.66 KB
/
BuyerView.java
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
package it.unimi.di.prog2.esame.view;
import it.unimi.di.prog2.esame.presenter.Presenter;
import javafx.geometry.Insets;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.*;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import org.jetbrains.annotations.NotNull;
public class BuyerView extends Region {
private final Label[] labels;
private final Button[] buttons;
private final int size;
public BuyerView(@NotNull String buttonText, int numRows, String title) {
size = numRows;
labels = new Label[size];
buttons = new Button[size];
setBackground(new Background(
new BackgroundFill(Color.LIGHTBLUE, new CornerRadii(5.0), Insets.EMPTY)));
setBorder(new Border(
new BorderStroke(null, BorderStrokeStyle.SOLID, new CornerRadii(5.0), new BorderWidths(2))));
GridPane grid = new GridPane();
grid.setPadding(new Insets(10, 10, 10, 10));
Label title1 = new Label(title);
title1.setFont(Font.font("sans", 20));
grid.add(title1, 0, 0);
for (int i = 0; i < size; i++) {
labels[i] = new Label("Row #" + i);
labels[i].setFont(Font.font("monospace", 14));
labels[i].setPadding(new Insets(10, 10, 10, 10));
buttons[i] = new Button(buttonText);
grid.add(labels[i], 0, 1 + i);
grid.add(buttons[i], 1, 1 + i);
}
this.getChildren().add(grid);
}
public void addHandlers(@NotNull Presenter presenter) {
for (int i = 0; i < size; i++) {
final int id = i;
buttons[i].setOnAction(eh -> presenter.action(id, labels[id].getText()));
}
}
public void set(int i, @NotNull String s) {
labels[i].setText(s);
}
}