Skip to content

Commit

Permalink
Merge pull request #187 from pwgit-create/develop
Browse files Browse the repository at this point in the history
Appwish Enterprise 2.0.5.   PR to Master Branch
  • Loading branch information
pwgit-create authored Jul 29, 2024
2 parents bb607be + 09e7afb commit 4cdbfb2
Show file tree
Hide file tree
Showing 16 changed files with 307 additions and 88 deletions.
8 changes: 7 additions & 1 deletion AppWish/AppWish/dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>pn.dev</groupId>
<artifactId>code-generator-gui-ollama</artifactId>
<name>CodeGenerator-GUI</name>
<version>2.0.4</version>
<version>2.0.5</version>
<description>The GUI interface for the pn.dev.code-generator-ollama library</description>
<inceptionYear>2024</inceptionYear>
<developers>
Expand All @@ -20,6 +20,12 @@
<timezone>Central European Time</timezone>
</developer>
</developers>
<licenses>
<license>
<name>MIT License</name>
<url>https://raw.githubusercontent.com/pwgit-create/APPWISH_OLLAMA/master/LICENSE</url>
</license>
</licenses>
<build>
<plugins>
<plugin>
Expand Down
5 changes: 2 additions & 3 deletions AppWish/AppWish/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>pn.dev</groupId>
<artifactId>code-generator-gui-ollama</artifactId>
<version>2.0.4</version>
<version>2.0.5</version>
<name>CodeGenerator-GUI</name>


Expand Down Expand Up @@ -53,7 +53,7 @@
<dependency>
<groupId>pn.dev</groupId>
<artifactId>code-generator-ollama</artifactId>
<version>2.0.4</version>
<version>2.0.5</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
Expand All @@ -65,7 +65,6 @@
<artifactId>javafx-fxml</artifactId>
<version>${javafx.version}</version>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
Expand Down
54 changes: 36 additions & 18 deletions AppWish/AppWish/src/main/java/pn/app_wish/AppWish.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import java.io.File;

import javafx.stage.StageStyle;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.simple.SimpleLogger;
Expand Down Expand Up @@ -51,7 +52,7 @@

public class AppWish extends Application {
private static final Logger log = LoggerFactory.getLogger(AppWish.class);
private static Stage mainStage;
public static Stage mainStage;
@FXML
public TextField tf_input;
@FXML
Expand All @@ -64,8 +65,7 @@ public class AppWish extends Application {
public Button btn_app_history;
@FXML
public Button btn_continue_on_application;
@FXML
public BorderPane bp_main;

@FXML
public Button btn_StopGeneratedApp;
@FXML
Expand All @@ -76,6 +76,7 @@ public class AppWish extends Application {
private String javaExecutablePath;
private Process executingJavaAppProcess;
private boolean isCodeGenerationOnGoing = false;
private boolean isSuperAppGeneration = false;

public static void main(String[] args) {
launch(args);
Expand All @@ -101,18 +102,25 @@ public void stop() throws Exception {
super.stop();
}

private void loadSplashScreen(Stage primaryStage) throws IOException {

// Load splashscreen.fxml and show it
Parent root = FXMLLoader.load(requireNonNull(getClass().getClassLoader().getResource("splashscreen.fxml")));
Stage splashStage = new Stage();
splashStage.setScene(new Scene(root));
splashStage.initStyle(StageStyle.UNDECORATED);
splashStage.show();
}


@Override
public void start(Stage primaryStage) throws IOException {
System.setProperty(SimpleLogger.DEFAULT_LOG_LEVEL_KEY, "DEBUG");
Parent root = FXMLLoader.load(requireNonNull(getClass().getClassLoader().getResource(DEFAULT_FXML_FILE)));
mainStage = primaryStage;
mainStage.setResizable(false);
primaryStage.setResizable(false);
primaryStage.setTitle(GUIConstants.DEFAULT_STAGE_TITLE);
Scene scene = new Scene(root);
primaryStage.setScene(scene);
primaryStage.show();
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");
System.setProperty(SimpleLogger.DEFAULT_LOG_LEVEL_KEY, "INFO");


// Splash Screen
loadSplashScreen(primaryStage);


}

Expand All @@ -121,6 +129,7 @@ public void start(Stage primaryStage) throws IOException {
*/
private void onAppWish(CodeEvent codeEvent) {
isCodeGenerationOnGoing = true;
output_label.setStyle("-fx-background-color: #00277c; -fx-text-fill: white;");
// The File Object will be null if it's a new app request or have
// a value if it is a continuous build from an existing app
File file;
Expand All @@ -143,6 +152,7 @@ private void onAppWish(CodeEvent codeEvent) {
file = null;
}

isSuperAppGeneration = false;

ThreadPoolMaster.getInstance().getExecutor().execute(() -> {
startGuiThread(codeEvent);
Expand All @@ -168,10 +178,11 @@ private void onAppWish(CodeEvent codeEvent) {
private void onRunJavaApp(ActionEvent ae) {
btn_run_application.setVisible(false);
btn_StopGeneratedApp.setVisible(true);
output_label.setVisible(false);

if (javaExecutablePath != null) {

if (!output_label.isVisible()) {
if (!isCodeGenerationOnGoing) {
log.info("Executing java app on path -> {}", javaExecutablePath);
}
try {
Expand All @@ -188,8 +199,7 @@ private final ProcessBuilder GetProcessBuilderForRunningGeneratedJavaApplication

final String classPath = javaExecutablePath.replace(MAIN_DOT_JAVA, NOTHING_STRING);

if (output_label.isVisible()) {
// Super App Creation
if (isSuperAppGeneration) {

// Security
if (classPath.concat(MAIN_DOT_JAVA).equals(javaExecutablePath)) {
Expand Down Expand Up @@ -334,17 +344,22 @@ private void handleCompilationResult(boolean isSuperGeneration) {
Platform.runLater(() -> {
if (DataStorage.getInstance().getJavaExecutionPath() != null || isSuperGeneration) {
if (!isSuperGeneration) {
output_label.setVisible(false);

btn_run_application.setVisible(true);
output_label.setText(SUCCESS_ON_SUPER_APP_CREATION_TEXT);
output_label.setStyle("-fx-background-color: green; -fx-text-fill: white;");
}
btn_run_application.setVisible(true);
setButtonGroupVisibilityForCodeGenerationButtons(true);
isCodeGenerationOnGoing = false;
if (isSuperGeneration) {
output_label.setText(SUCCESS_ON_SUPER_APP_CREATION_TEXT);
output_label.setStyle("-fx-background-color: green; -fx-text-fill: white;");

}
} else {
output_label.setText("Something went wrong :(");
output_label.setText("Failed! Try again or write an issue report.");
output_label.setStyle("-fx-background-color: red; -fx-text-fill: white;");
}
});

Expand All @@ -358,6 +373,7 @@ private void setButtonGroupVisibilityForCodeGenerationButtons(boolean isVisible)
btn_create_application.setVisible(isVisible);
btn_continue_on_application.setVisible(isVisible);
btn_super_app_creation.setVisible(isVisible);
btn_app_history.setVisible(isVisible);
}

/**
Expand Down Expand Up @@ -399,6 +415,8 @@ private List<String> readTextByLinesFromFile(File file) {
public void OnSuperAppCreationButton(ActionEvent ae) {

isCodeGenerationOnGoing = true;
isSuperAppGeneration = true;
output_label.setStyle("-fx-background-color: #00277c; -fx-text-fill: white;");
DataStorage.getInstance().setCompilationJob(new CompilationJob(GUIConstants.DEFAULT_STAGE_TITLE));
ThreadPoolMaster.getInstance().getExecutor().execute(() -> {
StartGuiThreadForSuperAppCreation();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package pn.app_wish.constant;


public record AboutConstants() {

private static final String APP_WISH_VERSION = "Appwish Enterprise 2.0.5";
private static final String ABOUT_APP_WISH = "AppWish (2) is a open source project that creates Java applications from text input with the help of AI models";
private static final String DEVELOPED_BY = "Pwgit-Create / Peter Westin";
private static final String CONTACT = "\nEmail: [email protected]";
private static final String LINK_TO_DISCUSSION = "https://github.com/pwgit-create/APPWISH_OLLAMA/discussions";
private static final String LINK_TO_ISSUE_PORTAL="https://github.com/pwgit-create/APPWISH_OLLAMA/issues";
private static final String IF_YOU_LIKE_THE_PROJECT = "\n\nIf you like AppWish and wants to show your support, please let me know by leaving a post";
private static final String THANKS_FOR_USING_APP_WISH_ENTERPRISE = "\n\nThanks for taking the time to read the about section, you rock! :)";


/**
* Builds an About String that can be used in the About section
* @return String
*/
public static String BuildAboutString() {

return "Version: " +
APP_WISH_VERSION +
"\n\nWhat is AppWish used for? " +
ABOUT_APP_WISH +
"\n\nDeveloper: " +
DEVELOPED_BY +
"\n\nQuestions or in need of support? " +
CONTACT +
"\nIssue Portal: " +
LINK_TO_ISSUE_PORTAL +
"\n\nJoin the discussion and see updates: " +
LINK_TO_DISCUSSION +
IF_YOU_LIKE_THE_PROJECT +
THANKS_FOR_USING_APP_WISH_ENTERPRISE;

}

/*
Get the header text for the about section
*/
public static String GetHeaderText(){

return "AppWish Enterprise";
}

/*
Get the header text for the about section
*/
public static String GetTitleTest(){

return "About AppWish";
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package pn.app_wish.constant;

public class GUIConstants {
public record GUIConstants() {

public static final String DEFAULT_STAGE_TITLE ="App Wish";
public static final String DEFAULT_FXML_FILE="start.fxml";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
import javafx.util.Callback;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pn.app_wish.AppWish;
import pn.app_wish.constant.AboutConstants;
import pn.app_wish.constant.GUIConstants;
import pn.app_wish.constant.StaticAppWishConstants;
import pn.app_wish.util.AppWishUtil;
Expand Down Expand Up @@ -51,12 +53,16 @@ public class AppHistoryController implements Initializable {
@FXML
private Button btnDeleteApp;

@FXML
private Button btnAbout;

private Process executingJavaAppProcess;


@Override
public void initialize(URL url, ResourceBundle resourceBundle) {
AnchorPane.setRightAnchor(btnMainScene, 0d);
AnchorPane.setRightAnchor(btnDeleteApp, 0d);
AnchorPane.setRightAnchor(btnStopApp, 80d);
btnStopApp.setVisible(false);
try {
Expand Down Expand Up @@ -163,6 +169,25 @@ private void showConfirmDialogForDeletionOfAnJavaApplication(ActionEvent ae) {
}
}

@FXML
private void showAboutMessage(ActionEvent ae) {
if (fileListView != null) {
Alert alert = new Alert(Alert.AlertType.INFORMATION);
alert.setTitle(AboutConstants.GetTitleTest());
alert.setHeaderText(AboutConstants.GetHeaderText());

// Make text copyable
final TextArea textArea = new TextArea(AboutConstants.BuildAboutString());
textArea.setEditable(false);
textArea.setWrapText(true);
GridPane gridPane = new GridPane();
gridPane.setMaxWidth(Double.MAX_VALUE);
gridPane.add(textArea, 0, 0);
alert.getDialogPane().setContent(gridPane);
alert.showAndWait();
}
}

private void deleteJavaApp(File classFileOfApplication) {

Platform.runLater(() -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package pn.app_wish.controller;
import javafx.animation.PauseTransition;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.stage.Stage;
import javafx.util.Duration;
import pn.app_wish.AppWish;

import java.io.IOException;
import java.net.URL;
import java.util.Objects;
import java.util.ResourceBundle;




public class SplashScreenController implements Initializable {
@FXML
private ImageView splashImage;

@FXML
private Label label;

@Override
public void initialize(URL url, ResourceBundle rb) {

splashImage.setImage(new Image("shooting_star.png"));
PauseTransition delay = new PauseTransition(Duration.seconds(3));
delay.setOnFinished(event -> {
// Close the SplashScreen and show the main application stage
Stage splashStage = (Stage) splashImage.getScene().getWindow();
splashStage.close();

try {
Parent root = FXMLLoader.load(Objects.requireNonNull(getClass().getClassLoader().getResource("start.fxml")));
Stage mainStage = new Stage();
//mainStage.setResizable(false);
mainStage.setScene(new Scene(root));

AppWish.mainStage = mainStage;
mainStage.show();
} catch (IOException ex) {
// Handle exception
}
});
delay.play();
}
}
11 changes: 7 additions & 4 deletions AppWish/AppWish/src/main/resources/app_history.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>

<AnchorPane prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/17.0.2-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="pn.app_wish.controller.AppHistoryController">
<AnchorPane maxHeight="400" maxWidth="592" minHeight="400.0" minWidth="592.0" style="-fx-background-color: #00277c; " xmlns="http://javafx.com/javafx/17.0.2-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="pn.app_wish.controller.AppHistoryController">

<ListView fx:id="fileListView" prefHeight="400.0" prefWidth="200.0" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="0.0" />
<Button fx:id="selectButton" layoutX="210.0" layoutY="10.0" mnemonicParsing="false" onAction="#handleSelectButtonAction" style="-fx-background-color: green;" text="Run" textFill="#f8f8f8" />
<ListView fx:id="fileListView" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="0.0" />


<Button fx:id="selectButton" layoutX="248.0" layoutY="2.0" mnemonicParsing="false" onAction="#handleSelectButtonAction" style="-fx-background-color: #00328c" text="Run" textFill="#f8f8f8" />
<Button fx:id="btnMainScene" mnemonicParsing="false" onAction="#goToMainScene" style="-fx-background-color: #00328c" text="Back" textFill="WHITE" />
<Button fx:id="btnStopApp" mnemonicParsing="false" onAction="#stopExecutedJavaApp" style="-fx-background-color: red" text="Stop your app" textFill="WHITE" />
<Button fx:id="btnDeleteApp" layoutX="531.0" layoutY="368.0" mnemonicParsing="false" onAction="#showConfirmDialogForDeletionOfAnJavaApplication" style="-fx-background-color:red;" text="Delete" textFill="#f5eef5" />
<Button fx:id="btnDeleteApp" layoutX="531.0" layoutY="374.0" onAction="#showConfirmDialogForDeletionOfAnJavaApplication" style="-fx-background-color: #00328c" text="Delete" textFill="#f5eef5" />
<Button fx:id="btnAbout" layoutX="248.0" layoutY="374.0" mnemonicParsing="false" onAction="#showAboutMessage" style="-fx-background-color: #00328c" text="About" textFill="#f5eef5" />

</AnchorPane>
Binary file not shown.
Loading

0 comments on commit 4cdbfb2

Please sign in to comment.