-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathController.java
More file actions
222 lines (189 loc) · 7.19 KB
/
Controller.java
File metadata and controls
222 lines (189 loc) · 7.19 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
import javafx.event.ActionEvent;
import javafx.scene.control.Button;
import javafx.scene.control.TextArea;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.ColumnConstraints;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.RowConstraints;
import javafx.scene.image.ImageView;
import javafx.scene.image.Image;
import javafx.scene.image.WritableImage;
import java.util.ArrayList;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.stage.*;
import javafx.event.Event;
import javafx.scene.Scene;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javafx.embed.swing.SwingFXUtils;
import javafx.scene.control.CheckBox;
import javafx.scene.control.Spinner;
public class Controller {
private ArrayList<Button> bListe;
private GridPane gp;
private TextArea ta;
private String style;
private int anzahlSnapshots;
private int anzahlxmlExports;
private int anzahljsonExports;
private Automat automat;
private EditorGUI gui;
private HauptGUI hg;
private AppGUI app;
public Controller(HauptGUI hg){
this.hg = hg;
}
public Controller(AppGUI app){
this.app = app;
}
public Controller(GridPane gp, TextArea ta) {
this.gp = gp;
this.ta = ta;
this.anzahlSnapshots = 0;
anzahljsonExports = 0;
anzahlxmlExports = 0;
// buttonListeAktiverPlayerSetzen();
}
public void toJson(Automat a){
a.parseAutomatToJSON("jsonExport/export_" + anzahljsonExports + ".json");
anzahljsonExports++;
}
public void toXml(Automat a){
a.parseAutomatToXML("xmlExport/export_" + anzahlxmlExports + ".xml");
anzahlxmlExports++;
}
void bLosClicked(Event event, Spinner tf,Spinner tfd) {
try{
Integer zahl =(int) tf.getValue();
if(zahl>0){
hg.getStage().close();
gui = new EditorGUI(Integer.valueOf((int)tfd.getValue()),Integer.valueOf((int)tf.getValue()));
gui.start(new Stage());
}
}
catch(NumberFormatException e){
}
}
public void kniffelGUIClosed(){
if(gui!=null && gui.getStage()!=null) {
gui.getStage().close();
hg = new HauptGUI();
hg.start(new Stage());
}
}
public void meldeGUIAn(EditorGUI gui){
this.gui = gui;
}
public void prüfen(ActionEvent eventm, Automat automat, TextField eingabe, Label info, ImageView correct, ImageView incorrect){
String wort = eingabe.getText();
correct.setVisible(false);
incorrect.setVisible(false);
if(automat.gehoertZuSprache(wort) == true){
info.setText("DIESE WORT GEHÖRT ZUR BESCHRIEBENEN SPRACHE");
correct.setVisible(true);
}else{
info.setText("DIESE WORT GEHÖRT NICHT ZUR BESCHRIEBENEN SPRACHE\n");
incorrect.setVisible(true);
}
}
void buildClicked(ActionEvent event, Button auto,TextField[][]tabelleRoh,TextField[] alphabetRoh,Spinner startZustandRoh,CheckBox[] endZustaendeRoh) {
int start = (int)startZustandRoh.getValue() + 1;
//convert TextField Arrays in data types, that can be worked with properly
int[][] tabelle = new int[tabelleRoh.length][tabelleRoh[0].length];
for(int i = 0; i < tabelleRoh.length;i++){
for(int k = 0; k < tabelleRoh[0].length; k++){
if(tabelleRoh[i][k].getText() == "-1" ){
tabelle[i][k] = -1;
}else{
tabelle[i][k] = Integer.parseInt(tabelleRoh[i][k].getText());
}
}
}
int length = 0;
System.out.println("-------------------------------------");
System.out.println("AUTOMAT");
System.out.println("Endzustände E: ");
ArrayList<Integer> temp = new ArrayList();
for(int i = 0; i < endZustaendeRoh.length; i++){
if(endZustaendeRoh[i].isSelected() == true){
System.out.print("q" + (i) + " ");
length++;
temp.add(i);
}
}
int[] endZustaende = new int[temp.size()];
for(int i = 0; i < temp.size();i++){
endZustaende[i] = temp.get(i);
}
char[] alphabet = new char[alphabetRoh.length];
System.out.println();
for(int i = 0; i < alphabetRoh.length; i++){
alphabet[i] = alphabetRoh[i].getText().charAt(0);
}
printTabelle(tabelle, alphabet);
System.out.println("Startzustand S: " + start);
System.out.println("Alphabet Σ: " );
printAlphabet(alphabet);
printZustaende(tabelle);
System.out.println();
System.out.println("-------------------------------------");
try {automat = new Automat(tabelle,endZustaende,alphabet,start-1);
} catch (Exception e) {e.printStackTrace();}
AppGUI app = new AppGUI(automat);
app.start(new Stage());
}
public void printTabelle(int[][] matrix, char[] alphabet){
System.out.println("Zustandsübergangstabelle δ:"); //change line on console as row comes to end in the matrix.
System.out.print(" ");
printAlphabet(alphabet);
System.out.println();
for (int i = 0; i < matrix.length; i++) { //this equals to the row in our matrix.
System.out.print("q" + (i+1) + "|");
for (int j = 0; j < matrix[i].length; j++) { //this equals to the column in each row.
System.out.print(matrix[i][j] + " ");
}
System.out.println(); //change line on console as row comes to end in the matrix.
}
}
public void printZustaende(int[][] matrix){
System.out.println();
System.out.println("Zustände Z:"); //change line on console as row comes to end in the matrix.
for (int i = 0; i < matrix.length; i++) { //this equals to the row in our matrix.
System.out.print("q" + (i) + ";");
}
}
public void printArray(int[] input){
for(int i = 0; i < input.length; i++){
System.out.print(" " + input[i] + " ");
}
}
public void printAlphabet(char[] input){
for(int i = 0; i < input.length; i++){
System.out.print(" " + input[i] + " ");
}
}
void bTakeSnapshot(ActionEvent event, Scene s) {
Image i = s.snapshot(null);
anzahlSnapshots++;
String url = "snapshots/Snapshot_"+anzahlSnapshots+".png";
File file = new File(url);
try {
ImageIO.write(SwingFXUtils.fromFXImage(i, null), "png", file);
ausgabe("Der Snapshot wurder erfolgreich erstellt und in '"+url+"' gespeichert!");
}catch (IOException e) {
System.err.print(e);
ausgabe("Der Snapshot konnte nicht erstellt/gespeichert werden!");
}
}
private void ausgabe(String text){
ta.setText(text);
// ta.appendText("\n"+g.getScoreboard().toString());
}
void bClicked(ActionEvent event, Button b, Label l, Button auto) {
}
void bExited(MouseEvent event, Button b, int zeile) {
b.setStyle(style);
}
}