55import javafx .event .ActionEvent ;
66import javafx .fxml .FXML ;
77import javafx .fxml .FXMLLoader ;
8+ import javafx .scene .image .ImageView ;
89import javafx .stage .FileChooser ;
910
1011import javafx .scene .Parent ;
1819
1920import java .io .File ;
2021
22+ import org .slf4j .Logger ;
23+ import org .slf4j .LoggerFactory ;
2124import org .slf4j .simple .SimpleLogger ;
2225
2326import pn .app_wish .constant .CodeEvent ;
2427import pn .app_wish .constant .GUIConstants ;
2528import pn .app_wish .constant .StaticAppWishConstants ;
29+ import pn .app_wish .util .AppWishUtil ;
2630import pn .cg .app_system .AppSystem ;
2731import pn .cg .app_system .code_generation .model .CompilationJob ;
2832import pn .cg .datastorage .DataStorage ;
4347
4448
4549public class AppWish extends Application {
50+ private static final Logger log = LoggerFactory .getLogger (AppWish .class );
4651 private static Stage mainStage ;
4752 @ FXML
4853 public TextField tf_input ;
@@ -59,7 +64,9 @@ public class AppWish extends Application {
5964 @ FXML
6065 public BorderPane bp_main ;
6166 @ FXML
62- public Button btnStopGeneratedApp ;
67+ public Button btn_StopGeneratedApp ;
68+ @ FXML
69+ public ImageView logo ;
6370
6471 private String javaExecutablePath ;
6572 private Process executingJavaAppProcess ;
@@ -98,9 +105,8 @@ public void start(Stage primaryStage) throws IOException {
98105 System .out .println ("\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n " );
99106 }
100107
101-
102108 /**
103- * Appwish GUI lifecycle
109+ * AppWish GUI lifecycle
104110 */
105111 private void onAppWish (CodeEvent codeEvent ) {
106112 isCodeGenerationOnGoing = true ;
@@ -120,7 +126,6 @@ private void onAppWish(CodeEvent codeEvent) {
120126 }
121127 contentOfExistingJavaFile = readTextByLinesFromFile (file );
122128 }
123-
124129 //**codeEvent == CodeEvent.CREATE_APPLICATION**//
125130 else {
126131 contentOfExistingJavaFile = null ;
@@ -146,29 +151,18 @@ private void onAppWish(CodeEvent codeEvent) {
146151
147152 });
148153
149- //Wait for 1.5 sec
150-
151- try {
152- Thread .sleep (1500 );
153- } catch (InterruptedException e ) {
154-
155- Thread .currentThread ().interrupt ();
156- }
157154 }
158155
159-
160156 @ FXML
161157 private void onRunJavaApp (ActionEvent ae ) {
162158 btn_run_application .setVisible (false );
163- btnStopGeneratedApp .setVisible (true );
159+ btn_StopGeneratedApp .setVisible (true );
164160
165161 if (javaExecutablePath != null ) {
166162 System .out .println ("Executing java app on path -> " + javaExecutablePath );
167163 try {
168164 ProcessBuilder pb ;
169-
170165 pb = new ProcessBuilder (StaticAppWishConstants .BASH_PATH , StaticAppWishConstants .C_ARGUMENT , StaticAppWishConstants .JAVA_TEXT + javaExecutablePath );
171-
172166 executingJavaAppProcess = pb .inheritIO ().start ();
173167 } catch (IOException e ) {
174168 throw new RuntimeException (e );
@@ -191,7 +185,9 @@ private void stopExecutedGeneratedJavaApp(ActionEvent ae) {
191185
192186 this .executingJavaAppProcess .toHandle ().destroy ();
193187 btn_run_application .setVisible (true );
194- btnStopGeneratedApp .setVisible (false );
188+ btn_StopGeneratedApp .setVisible (false );
189+ setButtonGroupVisibilityForCodeGenerationButtons (true );
190+
195191 }
196192
197193 /**
@@ -201,7 +197,7 @@ private void stopExecutedGeneratedJavaApp(ActionEvent ae) {
201197 private void startGuiThread (CodeEvent codeEvent ) {
202198 DataStorage .getInstance ().setCompilationJob (new CompilationJob (GUIConstants .DEFAULT_STAGE_TITLE ));
203199 Platform .runLater (() -> {
204- setButtonGroupVisibilityForCodeGenerationBtns (false );
200+ setButtonGroupVisibilityForCodeGenerationButtons (false );
205201 output_label .setVisible (true );
206202
207203 switch (codeEvent ) {
@@ -213,8 +209,8 @@ private void startGuiThread(CodeEvent codeEvent) {
213209 break ;
214210 }
215211
216- setButtonGroupVisibilityForCodeGenerationBtns (false );
217- btnStopGeneratedApp .setVisible (false );
212+ setButtonGroupVisibilityForCodeGenerationButtons (false );
213+ btn_StopGeneratedApp .setVisible (false );
218214 });
219215 }
220216
@@ -224,9 +220,10 @@ private void startGuiThread(CodeEvent codeEvent) {
224220 @ FXML
225221 private void createApplication (ActionEvent ae ) {
226222
227- if (!isCodeGenerationOnGoing )
223+ if (!isCodeGenerationOnGoing ) {
224+ setButtonGroupVisibilityToFalseForStartAndStopApplicationsButtons ();
228225 onAppWish (CodeEvent .CREATE_APPLICATION );
229-
226+ }
230227 }
231228
232229 /**
@@ -235,9 +232,10 @@ private void createApplication(ActionEvent ae) {
235232 @ FXML
236233 private void continueOnExistingApplication (ActionEvent ae ) {
237234
238- if (!isCodeGenerationOnGoing )
235+ if (!isCodeGenerationOnGoing ) {
236+ setButtonGroupVisibilityToFalseForStartAndStopApplicationsButtons ();
239237 onAppWish (CodeEvent .CONTINUE_ON_EXISTING_APPLICATION );
240-
238+ }
241239 }
242240
243241
@@ -247,6 +245,7 @@ private void continueOnExistingApplication(ActionEvent ae) {
247245 private void startCodeGeneration (CodeEvent codeEvent , String pathToJavaApp , List <String > contentOfExistingJavaFile ) {
248246
249247 if (tf_input != null ) {
248+ // Stop displaying start/stop application buttons
250249 // Make a recursive call to AppSystem
251250 switch (codeEvent ) {
252251 case CREATE_APPLICATION :
@@ -257,7 +256,6 @@ private void startCodeGeneration(CodeEvent codeEvent, String pathToJavaApp, List
257256 requireNonNull (contentOfExistingJavaFile ));
258257 break ;
259258 }
260-
261259 }
262260 }
263261
@@ -271,55 +269,57 @@ private void waitForCompilationResult() {
271269 }
272270
273271 /**
274- * If a compilation result exist , check if the singleton in code-generator-ollama contains a path for a executable Java file
272+ * If a compilation result exist , check if the singleton in code-generator-ollama contains a path for an executable Java file
275273 * If the above is true , activate the "run application" button and remove the "generating code..." text
276274 */
277275 private void handleCompilationResult () {
278-
279276 if (DataStorage .getInstance ().getCompilationJob ().isResult ()) {
280277 javaExecutablePath = DataStorage .getInstance ().getJavaExecutionPath ();
281278 // Draw success or error texts, and show run app button
282279 Platform .runLater (() -> {
283280 if (DataStorage .getInstance ().getJavaExecutionPath () != null ) {
284- output_label .setText ("Completed Successfully" );
285- try {
286- Thread .sleep (2500 );
287- } catch (InterruptedException e ) {
288- Thread .currentThread ().interrupt ();
289- }
290281 output_label .setVisible (false );
291282 btn_run_application .setVisible (true );
292- setButtonGroupVisibilityForCodeGenerationBtns (true );
283+ setButtonGroupVisibilityForCodeGenerationButtons (true );
293284 isCodeGenerationOnGoing = false ;
294285 } else {
295- output_label .setText ("Error" );
296- setButtonGroupVisibilityForCodeGenerationBtns (true );
297- isCodeGenerationOnGoing = false ;
286+ output_label .setText ("Something went wrong :(" );
298287 }
299288 });
300- }
301289
290+ }
302291 }
303292
304293 /**
305- * A button group broken out for reduce of redundancy
294+ * Set the visibility for the create and continue application buttons
306295 */
307- private void setButtonGroupVisibilityForCodeGenerationBtns (boolean isVisible ) {
296+ private void setButtonGroupVisibilityForCodeGenerationButtons (boolean isVisible ) {
308297 btn_create_application .setVisible (isVisible );
309298 btn_continue_on_application .setVisible (isVisible );
310299 }
311300
312- private File showOpenFileDialog () {
301+ /**
302+ * Set the visibility into false, for the start and stop application buttons (in the main gui)
303+ */
304+ private void setButtonGroupVisibilityToFalseForStartAndStopApplicationsButtons () {
305+ btn_run_application .setVisible (false );
306+ btn_StopGeneratedApp .setVisible (false );
307+ }
313308
309+
310+ private File showOpenFileDialog () {
314311 try {
315312 FileChooser fileChooser = new FileChooser ();
316313 fileChooser .setTitle ("Choose A Java file to add functionality to" );
317314 fileChooser .setInitialDirectory (new File (PathConstants .RESOURCE_PATH
318315 + StaticAppWishConstants .FOLDER_NAME_OF_GENERATED_JAVA_APPLICATIONS + File .separator ));
319-
316+ // Create an extension filter that filters out .class files
317+ FileChooser .ExtensionFilter extensionFilter = new FileChooser .ExtensionFilter (StaticAppWishConstants .CONTINUE_ON_APPLICATION_FILTER_ON_JAVA_EXTENSION_DESCRIPTION
318+ , StaticAppWishConstants .CONTINUE_ON_APPLICATION_FILTER_ON_JAVA_EXTENSION );
319+ fileChooser .getExtensionFilters ().add (extensionFilter );
320320 return fileChooser .showOpenDialog (getMainStage ());
321321 } catch (Exception e ) {
322- e . printStackTrace ( );
322+ log . error ( "Could not open the window for the file chooser" );
323323 return null ;
324324 }
325325 }
@@ -328,7 +328,7 @@ private List<String> readTextByLinesFromFile(File file) {
328328 try {
329329 return Files .readAllLines (Paths .get (file .getAbsolutePath ()));
330330 } catch (Exception e ) {
331- e . printStackTrace ( );
331+ log . error ( "Could not read the lines of the specified file" );
332332 return null ;
333333 }
334334 }
0 commit comments