-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathController.java
More file actions
345 lines (320 loc) · 13.6 KB
/
Controller.java
File metadata and controls
345 lines (320 loc) · 13.6 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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
package AnalyzerPackage;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.control.TableColumn.CellEditEvent;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.Pane;
import javafx.scene.layout.StackPane;
import javafx.stage.DirectoryChooser;
import javafx.stage.FileChooser;
import javafx.stage.Popup;
import javafx.stage.Stage;
import java.io.File;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;
public class Controller implements Initializable {
@FXML
TextArea outputTextArea;
@FXML
TextArea slicerTextArea;
@FXML
TextField variableNameTextField;
@FXML
TextField endLineTextField;
@FXML
TextField variableValueTextField;
@FXML
Label statusLabel;
static String folderPath;
static ArrayList<String> filePaths = new ArrayList<>();
static Analyzer analyzer;
@Override
public void initialize(URL location, ResourceBundle resources) {
folderPath = "";
}
public void browseFiles() {
Stage stage = new Stage();
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("Open Resource File");
List<File> list = fileChooser.showOpenMultipleDialog(stage);
filePaths.clear();
for (int i = 0; i < list.size(); i++) {
if (list.get(i).getPath().indexOf(".java") > 0 || list.get(i).getPath().indexOf(".txt") > 0) {
filePaths.add(list.get(i).getPath());
} else {
AlertClass alert = new AlertClass();
alert.display("Invalid Input!", "You can only open .java or .txt files!");
}
}
if (filePaths.size() > 0) {
statusLabel.setText("Status: " + filePaths.size() + " Files Loaded");
}
}
public void browseFolder() {
Stage stage = new Stage();
DirectoryChooser directoryChooser = new DirectoryChooser();
directoryChooser.setTitle("Open Resource Folder");
File folder = directoryChooser.showDialog(stage);
folderPath = folder.getPath();
}
public void showAnalyzer() {
try {
if (filePaths.size() > 0) {
analyzer = new Analyzer(filePaths);
AnalyzerMenu pl = new AnalyzerMenu();
var root = new StackPane();
root.setPadding(new Insets(20));
Stage stage = new Stage();
pl.pane = new Pane();
root.getChildren().add(pl.pane);
Scene sc = new Scene(root, 1200, 700);
stage.setScene(sc);
stage.setTitle("Analyzer");
pl.start(stage);
} else {
AlertClass alert = new AlertClass();
alert.display("Invalid Input!", "You need to browse files first!");
}
} catch (Exception e) {
e.printStackTrace();
}
}
public void showVisualizer() {
try {
if (filePaths.size() > 0) {
analyzer = new Analyzer(filePaths);
VisualizerMenu pl = new VisualizerMenu();
var root = new StackPane();
root.setPadding(new Insets(20));
Stage stage = new Stage();
pl.pane = new Pane();
root.getChildren().add(pl.pane);
Scene sc = new Scene(root, 1200, 700);
stage.setScene(sc);
stage.setTitle("Visualizer");
pl.start(stage);
} else {
AlertClass alert = new AlertClass();
alert.display("Invalid Input!", "You need to browse files first!");
}
} catch (Exception e) {
e.printStackTrace();
}
}
public void showNumberOfLines() {
String numberOfLines = String.valueOf(analyzer.getNumberOfLines());
outputTextArea.setText("Number of Lines:\n\t" + numberOfLines);
}
public void showNumberOfClasses() {
String numberOfClasses = String.valueOf(analyzer.getNumberOfClasses());
outputTextArea.setText("Number of Classes:\n\t" + numberOfClasses);
}
public void showNumberOfFunctions() {
String numberOfFunctions = String.valueOf(analyzer.getNumberOfFunctions());
outputTextArea.setText("Number of Functions:\n\t" + numberOfFunctions);
}
public void showNamesOfClasses() {
ArrayList<String> classesNames = analyzer.getClassesNames();
String classes = "";
for (String s : classesNames) {
classes += s + "\n\t";
}
outputTextArea.setText("Classes Names:\n\t" + classes);
}
public void showNamesOfFunctions() {
ArrayList<String> functionsNames = analyzer.getFunctionNames();
String functions = "";
for (String s : functionsNames) {
functions += s + "\n\t";
}
outputTextArea.setText("Functions Names:\n\t" + functions);
}
public void showCyclomaticComplexity() {
String cyclomaticComplexity = String.valueOf(analyzer.getCyclomaticComplexity());
outputTextArea.setText("Cyclomatic Complexity:\n\t" + cyclomaticComplexity);
}
public void showMaintainabilityIndex() {
String maintainabilityIndex = String.valueOf(analyzer.getMaintainabilityIndex());
outputTextArea.setText("Maintainability Index:\n\t" + maintainabilityIndex);
}
public void showSequenceDiagram() {
try {
// boolean mainFound = false;
// for (int i = 0; i < filePaths.size(); i++) {
// if (filePaths.get(i).contains("Main.java") || filePaths.get(i).contains("main.java") || filePaths.get(i).contains("main.txt") || filePaths.get(i).contains("Main.txt")) {
// mainFound = true;
// break;
// }
// }
// if (mainFound) {
SequenceDiagram pl = new SequenceDiagram();
pl.analyzer = analyzer;
StackPane root = new StackPane();
root.setPadding(new Insets(20));
Stage stage = new Stage();
pl.pane = new Pane();
root.getChildren().add(pl.pane);
Scene sc = new Scene(root, 1200, 700);
stage.setScene(sc);
stage.setTitle("Sequence Diagram");
pl.start(stage);
// } else {
// AlertClass alert = new AlertClass();
// alert.display("Invalid Input!", "The sequence diagram works only on main file!");
// }
} catch (Exception e) {
e.printStackTrace();
}
}
public void showClassDiagram() {
try {
ClassDiagram pl = new ClassDiagram();
pl.analyzer = analyzer;
StackPane root = new StackPane();
root.setPadding(new Insets(20));
Stage stage = new Stage();
pl.pane = new Pane();
root.getChildren().add(pl.pane);
Scene sc = new Scene(root, 1200, 700);
stage.setScene(sc);
stage.setTitle("Class Diagram");
pl.start(stage);
} catch (Exception e) {
e.printStackTrace();
}
}
public void showFlowChart() {
try {
// boolean mainFound = false;
// for (int i = 0; i < filePaths.size(); i++) {
// if (filePaths.get(i).contains("Main.java") || filePaths.get(i).contains("main.java") || filePaths.get(i).contains("main.txt") || filePaths.get(i).contains("Main.txt")) {
// mainFound = true;
// break;
// }
// }
// if (mainFound) {
FlowChart pl = new FlowChart();
pl.analyzer = analyzer;
StackPane root = new StackPane();
root.setPadding(new Insets(20));
Stage stage = new Stage();
pl.pane = new Pane();
root.getChildren().add(pl.pane);
Scene sc = new Scene(root, 1200, 700);
stage.setScene(sc);
stage.setTitle("Flow Chart");
pl.start(stage);
// } else {
// AlertClass alert = new AlertClass();
// alert.display("Invalid Input!", "The flow chart works only on main file!");
// }
} catch (Exception e) {
e.printStackTrace();
}
}
public void showSlicer() {
try {
if (filePaths.size() > 0) {
if (filePaths.size() == 1) {
analyzer = new Analyzer(filePaths);
SlicerMenu pl = new SlicerMenu();
var root = new StackPane();
root.setPadding(new Insets(20));
Stage stage = new Stage();
pl.pane = new Pane();
root.getChildren().add(pl.pane);
Scene sc = new Scene(root, 1200, 700);
stage.setScene(sc);
stage.setTitle("Slicer");
pl.start(stage);
} else {
AlertClass alert = new AlertClass();
alert.display("Invalid Input!", "You can only open ONE .java or .txt FILE ONLY!");
}
} else {
AlertClass alert = new AlertClass();
alert.display("Invalid Input!", "You need to browse files first!");
}
} catch (Exception e) {
e.printStackTrace();
}
}
public void showStaticSlicer() {
Slicer slicer;
if (filePaths.size() == 1) {
slicer = new Slicer(filePaths);
String variableName = variableNameTextField.getText();
try {
int endLine;
if (variableName.length() > 0 && endLineTextField.getText().length() > 0) {
endLine = Integer.parseInt(endLineTextField.getText());
if (endLine > slicer.getLinesCount()) {
AlertClass alert = new AlertClass();
alert.display("Invalid Input!", "The number of lines of the file is less than the end line you entered!");
} else if (endLine <= 0) {
AlertClass alert = new AlertClass();
alert.display("Invalid Input!", "End line value must be positive number!");
} else if (!slicer.staticSlicing(endLine, variableName).contains(variableName)) {
AlertClass alert = new AlertClass();
alert.display("Invalid Input!", "The variable you entered was not found in the code!");
} else {
slicerTextArea.setText(slicer.staticSlicing(endLine, variableName));
}
} else {
AlertClass alert = new AlertClass();
alert.display("Invalid Input!", "Please fill in the variable name and end line fields!");
}
} catch (NumberFormatException e) {
AlertClass alert = new AlertClass();
alert.display("Invalid Input!", "The field end line only accept integer values!");
}
} else {
AlertClass alert = new AlertClass();
alert.display("Invalid Input!", "You can only open ONE .java or .txt FILE ONLY!");
}
}
public void showDynamicSlicer() {
Slicer slicer;
if (filePaths.size() == 1) {
slicer = new Slicer(filePaths);
String variableName = variableNameTextField.getText();
try {
int variableValue;
int endLine;
if (variableName.length() > 0 && variableValueTextField.getText().length() > 0 && endLineTextField.getText().length() > 0) {
endLine = Integer.parseInt(endLineTextField.getText());
variableValue = Integer.parseInt(variableValueTextField.getText());
if (endLine > slicer.getLinesCount()) {
AlertClass alert = new AlertClass();
alert.display("Invalid Input!", "The number of lines of the file is less than the end line you entered!");
} else if (endLine < 0) {
AlertClass alert = new AlertClass();
alert.display("Invalid Input!", "End line value must be positive number!");
} else if (!slicer.dynamicSlicing(endLine, variableName, variableValue).contains(variableName)) {
AlertClass alert = new AlertClass();
alert.display("Invalid Input!", "The variable you entered was not found in the code!");
} else {
slicerTextArea.setText(slicer.dynamicSlicing(endLine, variableName, variableValue));
}
} else {
AlertClass alert = new AlertClass();
alert.display("Invalid Input!", "Please fill in the variable name, end line and variable value fields!");
}
} catch (NumberFormatException e) {
AlertClass alert = new AlertClass();
alert.display("Invalid Input!", "The fields variable value and end line only accept integer values!");
}
} else {
AlertClass alert = new AlertClass();
alert.display("Invalid Input!", "You can only open ONE .java or .txt FILE ONLY!");
}
}
}