Step in Button zum refresehen der Table
This commit is contained in:
@ -1,14 +1,11 @@
|
||||
package fabrik.simulator.pic16f84;
|
||||
|
||||
import javafx.application.Application;
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.TableColumn;
|
||||
import javafx.scene.control.TableView;
|
||||
|
||||
import javafx.scene.layout.GridPane;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.stage.Stage;
|
||||
@ -17,96 +14,46 @@ import java.io.IOException;
|
||||
|
||||
public class CreateWindow extends Application {
|
||||
|
||||
private static final int NUM_COLUMNS = 8; // Anzahl der Spalten
|
||||
private static VBox table;
|
||||
public static GridPane grid = new GridPane();
|
||||
|
||||
@Override
|
||||
public void start(Stage primaryStage) throws IOException {
|
||||
// Erstelle eine Instanz der DataRegister-Klasse
|
||||
|
||||
public void start(Stage primaryStage) throws IOException{
|
||||
DataRegister.initDataRegister();
|
||||
|
||||
// Erstelle eine TableView für die Datenanzeige
|
||||
TableView<DataEntry[]> tableView = new TableView<>();
|
||||
|
||||
// Erstelle Spalten für die TableView
|
||||
for (int i = 0; i < NUM_COLUMNS; i++) {
|
||||
TableColumn<DataEntry[], String> column = new TableColumn<>("0" + (i + 1));
|
||||
final int columnIndex = i;
|
||||
column.setCellValueFactory(cellData -> {
|
||||
if (cellData.getValue() != null && cellData.getValue().length > columnIndex) {
|
||||
return new SimpleStringProperty(cellData.getValue()[columnIndex].getValue());
|
||||
} else {
|
||||
return new SimpleStringProperty("");
|
||||
}
|
||||
});
|
||||
tableView.getColumns().add(column);
|
||||
}
|
||||
|
||||
// Fülle die TableView mit Daten aus dem Array
|
||||
int numRows = (int) Math.ceil((double) DataRegister.getDataRegister().length / NUM_COLUMNS);
|
||||
for (int row = 0; row < numRows; row++) {
|
||||
DataEntry[] rowData = new DataEntry[NUM_COLUMNS];
|
||||
for (int col = 0; col < NUM_COLUMNS; col++) {
|
||||
int index = row * NUM_COLUMNS + col;
|
||||
if (index < DataRegister.getDataRegister().length) {
|
||||
String address = "0x" + Integer.toHexString(index).toUpperCase();
|
||||
String value = "0x" + Integer.toHexString(DataRegister.getDataRegister()[index]).toUpperCase();
|
||||
rowData[col] = new DataEntry(address, value);
|
||||
} else {
|
||||
rowData[col] = new DataEntry("", "");
|
||||
}
|
||||
}
|
||||
tableView.getItems().add(rowData);
|
||||
}
|
||||
|
||||
// Erstelle Labels für die Spezialregister
|
||||
Label pclLabel = new Label("PCL: 0x" + Integer.toHexString(DataRegister.getRegister(DataRegister.getPCL())).toUpperCase());
|
||||
Label statusLabel = new Label("STATUS: 0x" + Integer.toHexString(DataRegister.getRegister(DataRegister.getSTATUS())).toUpperCase());
|
||||
Label fsrLabel = new Label("FSR: 0x" + Integer.toHexString(DataRegister.getRegister(DataRegister.getFSR())).toUpperCase());
|
||||
Label pclathLabel = new Label("PCLATH: 0x" + Integer.toHexString(DataRegister.getRegister(DataRegister.getPCLATH())).toUpperCase());
|
||||
Label intconLabel = new Label("INTCON: 0x" + Integer.toHexString(DataRegister.getRegister(DataRegister.getINTCON())).toUpperCase());
|
||||
table = Table.refresh();
|
||||
|
||||
FXMLLoader codewindow = new FXMLLoader(CreateWindow.class.getResource("frontend.fxml"));
|
||||
Parent code = codewindow.load();
|
||||
|
||||
|
||||
|
||||
// Erstelle einen VBox, um die TableView und Labels anzuzeigen
|
||||
VBox table = new VBox();
|
||||
table.getChildren().addAll(tableView, pclLabel, statusLabel, fsrLabel, pclathLabel, intconLabel);
|
||||
|
||||
GridPane grid = new GridPane();
|
||||
|
||||
grid.add(table, 0, 1);
|
||||
grid.add(code, 1, 1);
|
||||
grid.add(table, 1, 1);
|
||||
grid.add(code, 0, 1);
|
||||
|
||||
grid.relocate(0, 0);
|
||||
|
||||
Scene scene = new Scene(grid, 1600, 800);
|
||||
Scene scene = new Scene(grid, 1800, 800);
|
||||
primaryStage.setScene(scene);
|
||||
primaryStage.setTitle("Simulator");
|
||||
primaryStage.show();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
static void main(String[] args) {
|
||||
|
||||
launch(args);
|
||||
|
||||
}
|
||||
|
||||
// Hilfsklasse für die Datenanzeige in der TableView
|
||||
public static class DataEntry {
|
||||
private final String address;
|
||||
private final String value;
|
||||
|
||||
public DataEntry(String address, String value) {
|
||||
this.address = address;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
public static void refreshTable(Stage stage) throws IOException {
|
||||
grid.getChildren().remove(table);
|
||||
table= Table.refresh();
|
||||
grid.add(table, 1, 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user