zusammenfuegen

This commit is contained in:
2024-05-06 01:26:03 +02:00
parent 3590779e74
commit 68ddce74a8
4 changed files with 173 additions and 11 deletions

View File

@ -2,6 +2,8 @@ package fabrik.simulator.pic16f84;
import com.gluonhq.charm.glisten.control.ToggleButtonGroup;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
@ -23,6 +25,7 @@ import javafx.stage.Stage;
import java.util.Arrays;
import java.util.Objects;
public class Controller_Frontend {
@ -33,12 +36,13 @@ public class Controller_Frontend {
@FXML
private Button stepintoButton;
@FXML
private TableView<Table.DataEntry> tableView;
@FXML
private TextArea lstContentLabel;
private ListView<String> lstContentListView;
@FXML
private Label pclLabel;
@ -57,13 +61,126 @@ public class Controller_Frontend {
@FXML
private Button stepButton;
@FXML
private Button autoRunButton;
@FXML
private void autoRun(ActionEvent event) throws IOException {
if (lstContentListView.getItems().isEmpty()) {
// Datei ist nicht geladen oder leer
return;
}
// Aktuelle Zeile abrufen
int currentIndex = lstContentListView.getSelectionModel().getSelectedIndex();
currentIndex = (currentIndex == -1) ? 0 : currentIndex + 1;
// Durch das gesamte Programm laufen
while (currentIndex < lstContentListView.getItems().size()) {
// Scrollen zur ausgewählten Zeile
lstContentListView.scrollTo(currentIndex);
// CSS-Stil nur auf die Zellen der ausgewählten Zeile anwenden
String selectedRowStyle = "-fx-control-inner-background: red;";
int finalCurrentIndex = currentIndex;
lstContentListView.setCellFactory(column -> {
return new ListCell<String>() {
@Override
protected void updateItem(String item, boolean empty) {
super.updateItem(item, empty);
setText(item);
if (getIndex() == finalCurrentIndex) {
setStyle(selectedRowStyle);
} else {
setStyle(""); // Zurücksetzen des Stils für andere Zellen
}
}
};
});
// Befehle ausführen
Commands.decode(prog[DataRegister.getPC()]);
DataRegister.increasePC();
Table.refresh();
Stage stage = (Stage) autoRunButton.getScene().getWindow();
CreateWindow.refreshTable(stage);
try {
Thread.sleep(500); // Millisekunden
} catch (InterruptedException e) {
e.printStackTrace();
}
currentIndex++;
}
// Wenn das Ende der Datei erreicht ist, zeige eine Meldung an
System.out.println("End of file reached.");
}
@FXML
private void stepintoButton(ActionEvent event) throws IOException {
if (lstContentListView.getItems().isEmpty()) {
// Datei ist nicht geladen oder leer
return;
}
// Aktuelle Zeile abrufen
int currentIndex = lstContentListView.getSelectionModel().getSelectedIndex();
// Wenn keine Zeile ausgewählt ist, starte von der ersten Zeile
if (currentIndex == -1) {
currentIndex = 1;
} else {
// Gehe zur nächsten Zeile
currentIndex++;
}
// Überprüfen, ob currentIndex innerhalb der Grenzen liegt
if (currentIndex >= lstContentListView.getItems().size()) {
// Wenn das Ende der Datei erreicht ist, zeige eine Meldung an
System.out.println("End of file reached.");
return;
}
// Scrollen zur ausgewählten Zeile
lstContentListView.scrollTo(currentIndex);
// Zeile auswählen
lstContentListView.getSelectionModel().clearSelection();
lstContentListView.getSelectionModel().select(currentIndex);
String selectedRowStyle = "-fx-control-inner-background: red;";
int finalCurrentIndex = currentIndex + 1;
lstContentListView.setCellFactory(column -> {
return new ListCell<String>() {
@Override
protected void updateItem(String item, boolean empty) {
super.updateItem(item, empty);
setText(item);
if (getIndex() == finalCurrentIndex) {
setStyle(selectedRowStyle);
} else {
setStyle("");
}
}
};
});
// Befehle ausführen
Commands.decode(prog[DataRegister.getPC()]);
DataRegister.increasePC();
Table.refresh();
Stage stage = (Stage) stepintoButton.getScene().getWindow();
IOPorts.refreshUI(getTRISbuttons(), getPORTbuttons());
CreateWindow.refreshTable(stage);
}
@ -90,18 +207,47 @@ public class Controller_Frontend {
@FXML
private void displayLSTFileContent(File selectedFile) {
try (BufferedReader reader = new BufferedReader(new FileReader(selectedFile))) {
StringBuilder content = new StringBuilder();
ObservableList<String> contentList = FXCollections.observableArrayList();
String line;
while ((line = reader.readLine()) != null) {
content.append(line).append("\n");
contentList.add(line);
}
lstContentLabel.setText(content.toString());
}
catch (IOException e) {
lstContentListView.setItems(contentList);
} catch (IOException e) {
e.printStackTrace();
}
}
@FXML
private void stepThroughFile(ActionEvent event) {
if (lstContentListView.getItems().isEmpty()) {
// Datei ist nicht geladen oder leer
return;
}
// Aktuelle Zeile abrufen
int currentIndex = lstContentListView.getSelectionModel().getSelectedIndex();
// Wenn keine Zeile ausgewählt ist, starte von der ersten Zeile
if (currentIndex == -1) {
currentIndex = 1;
} else {
// Gehe zur nächsten Zeile
currentIndex++;
}
// Überprüfen, ob currentIndex innerhalb der Grenzen liegt
if (currentIndex >= lstContentListView.getItems().size()) {
// Wenn das Ende der Datei erreicht ist, zeige eine Meldung an
System.out.println("End of file reached.");
return;
}
// Zeile auswählen und anzeigen
lstContentListView.getSelectionModel().select(currentIndex + 1);
lstContentListView.scrollTo(currentIndex + 1);
}
@FXML
private ToggleButtonGroup bgTRISA0;
@FXML
@ -179,6 +325,10 @@ public class Controller_Frontend {
}
setTRISbuttons(allTRISButtons);
setPORTbuttons(allPORTButtons);
lstContentListView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
lstContentListView.getStylesheets().add(Objects.requireNonNull(getClass().getResource("styles.css")).toExternalForm());
}
private static void setTRISbuttons(ToggleButtonGroup[] allButtons) {

View File

@ -0,0 +1,4 @@
.list-cell:selected {
-fx-background-color: yellow;
}