-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMatrixView.java
More file actions
48 lines (43 loc) · 1.32 KB
/
MatrixView.java
File metadata and controls
48 lines (43 loc) · 1.32 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
package main.java;
import javafx.scene.layout.GridPane;
public class MatrixView {
GridPane matrixPane;
ElementView[][] elements;
public MatrixView(int rows, int cols) {
elements = new ElementView[rows][cols];
matrixPane = new GridPane();
matrixPane.setStyle("-fx-background-color : goldenrod;");
for (int i = 0; i < rows; i++ ) {
for (int j = 0; j < cols; j++) {
elements[i][j] = new ElementView(new Position(i, j));
matrixPane.add(elements[i][j].getRootNode(), j, i);
}
}
}
public MatrixView(Matrix a) {
if (a != null) {
int cols = a.getCols();
int rows = a.getRows();
elements = new ElementView[rows][cols];
matrixPane = new GridPane();
for (int i = 0; i < rows; i++ ) {
for (int j = 0; j < cols; j++) {
elements[i][j] = new ElementView(new Position(i, j));
matrixPane.add(elements[i][j].getRootNode(a.getBackingArray()[i][j]), j, i);
}
}
}
else {
System.out.println(a);
}
}
public GridPane getGrid() {
return matrixPane;
}
public ElementView getElementAtPosition(Position pos) {
return getMatrix()[pos.getRow()][pos.getCol()];
}
public ElementView[][] getMatrix() {
return elements;
}
}