Step in Button zum refresehen der Table
This commit is contained in:
114
src/main/java/fabrik/simulator/pic16f84/Table.java
Normal file
114
src/main/java/fabrik/simulator/pic16f84/Table.java
Normal file
@ -0,0 +1,114 @@
|
||||
package fabrik.simulator.pic16f84;
|
||||
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
import javafx.geometry.Insets;
|
||||
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.TableColumn;
|
||||
import javafx.scene.control.TableView;
|
||||
|
||||
import javafx.scene.layout.VBox;
|
||||
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static javafx.application.Application.launch;
|
||||
|
||||
public class Table {
|
||||
|
||||
|
||||
//Hier wird die Tabelle aktualisiert
|
||||
//Tabelle aktualisieren
|
||||
|
||||
private static final int NUM_COLUMNS = 8; // Anzahl der Spalten
|
||||
private static final double TABLE_WIDTH = 310; // Breite der TableView
|
||||
|
||||
|
||||
|
||||
public static VBox refresh(){
|
||||
// Erstelle eine Instanz der DataRegister-Klasse
|
||||
|
||||
|
||||
// Erstelle eine TableView für die Datenanzeige
|
||||
TableView<DataEntry[]> tableView = new TableView<>();
|
||||
tableView.setPrefWidth(TABLE_WIDTH);
|
||||
|
||||
|
||||
|
||||
|
||||
// Erstelle Spalten für die TableView
|
||||
for (int i = 0; i < NUM_COLUMNS; i++) {
|
||||
TableColumn<DataEntry[], String> column = new TableColumn<>("0" + (i));
|
||||
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());
|
||||
|
||||
|
||||
|
||||
|
||||
// Erstelle einen VBox, um die TableView und Labels anzuzeigen
|
||||
VBox table = new VBox();
|
||||
table.getChildren().addAll(tableView, pclLabel, statusLabel, fsrLabel, pclathLabel, intconLabel);
|
||||
VBox.setMargin(tableView, new Insets(0, 0, 0, 0));
|
||||
|
||||
return table;
|
||||
|
||||
}
|
||||
|
||||
public 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user