-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEditorGUI.java
More file actions
208 lines (172 loc) · 6.99 KB
/
EditorGUI.java
File metadata and controls
208 lines (172 loc) · 6.99 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
import javafx.application.Application;
import javafx.scene.layout.Priority;
import javafx.scene.control.TextArea;
import java.util.List;
import javafx.scene.Node;
import javafx.scene.control.TextField;
import javafx.scene.control.CheckBox;
import javafx.scene.control.Spinner;
import javafx.scene.control.SpinnerValueFactory;
// import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.layout.VBox;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
import javafx.scene.layout.GridPane;
import javafx.scene.control.Label;
import javafx.scene.control.Button;
import javafx.scene.image.ImageView;
import javafx.scene.image.Image;
import javafx.event.EventHandler;
import javafx.event.ActionEvent;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
public class EditorGUI extends Application {
private Controller c;
private Stage primaryStage;
private ImageView[] ivListe;
private Label[] lListe;
private TextArea ta;
private Button build;
private Button bAutoEintrag;
private Button bSnap;
private GridPane g;
private int eingabesymbol;
private final int feldBreite = 80;
private final int labelBreite = 110;
private int zustaende;
private Button cJson;
private Button cXml;
public EditorGUI(int eingabesymbol, int zustaende){
this.eingabesymbol = eingabesymbol;
this.zustaende = zustaende;
}
@Override
public void start(Stage primaryStage) {
try {
this.primaryStage = primaryStage;
g = new GridPane();
ta = new TextArea();
ta.setPrefRowCount(4);
Controller c = new Controller(g,ta);
c.meldeGUIAn(this);
//structure components
VBox canvas = new VBox();
VBox tabellenBox = new VBox();
HBox specialsBox = new HBox();
VBox endBox = new VBox();
VBox startBox = new VBox();
HBox buttonBox = new HBox();
// structure window
canvas.getChildren().add(tabellenBox);
canvas.getChildren().add(specialsBox);
specialsBox.getChildren().add(endBox);
specialsBox.getChildren().add(startBox);
canvas.getChildren().add(buttonBox);
//set sizes
buttonBox.setPrefHeight(100);
buttonBox.setAlignment(Pos.BOTTOM_LEFT);
endBox.setPrefWidth(115);
startBox.setPrefWidth(115);
TextField[] alphabet = new TextField[eingabesymbol];
Label tabellenInfo = new Label("Zustandsübergangstabelle:");
for (int l=0; l<eingabesymbol; l++){
alphabet[l] = new TextField(""+(l));
g.add(alphabet[l], l+1, 0);
}
for (int i=0; i<zustaende; i++){
Label l = new Label("q"+(i));
l.setPrefWidth(labelBreite);
g.add(l,0,i + 1);
}
TextField[][] tabelle = new TextField[zustaende][eingabesymbol];
for(int k = 0; k < eingabesymbol;k++){
for(int m = 0; m < zustaende; m++){
tabelle[m][k] = new TextField("-1");
g.add(tabelle[m][k], k+1, m+1);
}
}
final int initialValue = 0;
Label startInfo = new Label("Startzustand");
Spinner startZustand = new Spinner();
SpinnerValueFactory<Integer> valueFactory = new SpinnerValueFactory.IntegerSpinnerValueFactory(0, zustaende - 1, initialValue);
startZustand.setValueFactory(valueFactory);
//define appearance of grid
g.setGridLinesVisible(true);
g.setPadding(new Insets(5));
g.setPrefSize((eingabesymbol+1)*feldBreite+10, 350);
int minHoehe = (zustaende*80) + 100;
int minBreite = (eingabesymbol+1)*feldBreite;
if(minBreite<300) minBreite = 300;
ta.setPrefWidth(minBreite);
Scene scene2 = new Scene(canvas,minBreite,minHoehe);
build = new Button("build");
build.setPrefWidth(feldBreite);
bSnap = new Button("Snapshot");
bSnap.setPrefWidth(feldBreite);
bSnap.setOnAction(e -> c.bTakeSnapshot(e,scene2));
buttonBox.getChildren().add(build);
buttonBox.getChildren().add(bSnap);
startBox.getChildren().add(startInfo);
startBox.getChildren().add(startZustand);
Label endInfo = new Label("Endzustände");
endBox.getChildren().add(endInfo);
CheckBox[] endZustaende = new CheckBox[zustaende];
for(int y = 0 ; y < zustaende; y++){
endZustaende[y] = new CheckBox("q" + (y));
endBox.getChildren().add(endZustaende[y]);
}
build.setOnAction(e -> c.buildClicked(e,bAutoEintrag,tabelle, alphabet, startZustand, endZustaende));
build.setDefaultButton(true);
tabellenBox.getChildren().add(tabellenInfo);
tabellenBox.getChildren().add(g);
// Fenster festlegen
primaryStage.setScene(scene2);
primaryStage.setTitle("Automaten Editor - Konfiguration");
primaryStage.centerOnScreen();
primaryStage.setAlwaysOnTop(false);
primaryStage.setOnCloseRequest(event ->
{
System.out.print('\u000C'); // Loescht die Konsolenausgabe
c.kniffelGUIClosed(); // Beendet
});
primaryStage.show();
}
catch(Exception e) {
e.printStackTrace();
}
}
/**
* aktPlayer [0,n]
* zeile [1,13]
*/
public Button gibButton(int aktPlayer, int zeile){
// System.out.println("AnzSpieler: "+eingabesymbol+", AktPlayer: "+aktPlayer+", Zeile:"+zeile);
Node n = g.getChildren().get(14+2*eingabesymbol+13*aktPlayer+zeile);
if(n!=null && n instanceof Button) return (Button) n;
return null;
}
public Button[] gibButtonListe(int aktPlayer){
Button[] bListe = new Button[13];
for(int i=1; i<=13; i++) bListe[i] = gibButton(aktPlayer,i);
return bListe;
}
public void gibNodeAus(){
for(int i=0; i<g.getChildren().size(); i++){
// System.out.println(g.getChildren().get(i));
Node n = g.getChildren().get(i);
if(n instanceof Label){
Label b = (Label) n;
b.setText(""+i);
}
if(n instanceof Button){
Button b = (Button) n;
b.setText(""+i);
}
}
}
public Stage getStage(){
return primaryStage;
}
}