-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: API & Desktop spring boot autoconf
- Loading branch information
1 parent
cc89864
commit e3e6b35
Showing
13 changed files
with
178 additions
and
219 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 0 additions & 23 deletions
23
jsgenerator-desktop/src/main/java/com/osscameroon/jsgenerator/desktop/HelloApplication.java
This file was deleted.
Oops, something went wrong.
14 changes: 0 additions & 14 deletions
14
jsgenerator-desktop/src/main/java/com/osscameroon/jsgenerator/desktop/HelloController.java
This file was deleted.
Oops, something went wrong.
62 changes: 62 additions & 0 deletions
62
...p/src/main/java/com/osscameroon/jsgenerator/desktop/autoconfigure/JsGeneratorDesktop.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package com.osscameroon.jsgenerator.desktop.autoconfigure; | ||
|
||
import com.osscameroon.jsgenerator.core.autoconfigure.JsGeneratorCoreAutoconfigure; | ||
import com.osscameroon.jsgenerator.desktop.controller.FxmlNavigator; | ||
import com.osscameroon.jsgenerator.desktop.controller.FxmlResolver; | ||
import com.osscameroon.jsgenerator.desktop.controller.HelloViewController; | ||
import javafx.application.Application; | ||
import javafx.fxml.FXMLLoader; | ||
import javafx.scene.Parent; | ||
import javafx.scene.Scene; | ||
import javafx.stage.Stage; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.ImportAutoConfiguration; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.context.ApplicationContext; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Lazy; | ||
import org.springframework.core.io.ClassPathResource; | ||
|
||
import java.io.IOException; | ||
|
||
@ImportAutoConfiguration(JsGeneratorCoreAutoconfigure.class) | ||
@SpringBootApplication(scanBasePackageClasses = HelloViewController.class) | ||
public class JsGeneratorDesktop extends Application { | ||
private static ApplicationContext context; | ||
private static FxmlResolver fxmlResolver; | ||
private static Scene scene; | ||
|
||
public static void main(String[] args) { | ||
context = SpringApplication.run(JsGeneratorDesktop.class, args); | ||
fxmlResolver = context.getBean(FxmlResolver.class); | ||
launch(JsGeneratorDesktop.class, args); | ||
} | ||
|
||
/** | ||
* Inject this bean to navigate from one view to another, like a router. | ||
* | ||
* @return | ||
*/ | ||
@Bean | ||
@Lazy | ||
public FxmlNavigator fxmlNavigator() { | ||
return scene::setRoot; | ||
} | ||
|
||
@Bean | ||
public FxmlResolver fxmlResolver() { | ||
return path -> { | ||
path = "com/osscameroon/jsgenerator/desktop/controller/%s.fxml".formatted(path); | ||
final var loader = new FXMLLoader(new ClassPathResource(path).getURL()); | ||
loader.setControllerFactory(context::getBean); | ||
return (Parent) loader.load(); | ||
}; | ||
} | ||
|
||
@Override | ||
public void start(Stage stage) throws IOException { | ||
final var parent = fxmlResolver.resolve("hello-view"); | ||
stage.setScene(scene = new Scene(parent)); | ||
stage.show(); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...r-desktop/src/main/java/com/osscameroon/jsgenerator/desktop/controller/FxmlNavigator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.osscameroon.jsgenerator.desktop.controller; | ||
|
||
import javafx.scene.Parent; | ||
|
||
@FunctionalInterface | ||
public interface FxmlNavigator { | ||
void navigate(Parent parent); | ||
} |
10 changes: 10 additions & 0 deletions
10
...or-desktop/src/main/java/com/osscameroon/jsgenerator/desktop/controller/FxmlResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.osscameroon.jsgenerator.desktop.controller; | ||
|
||
import javafx.scene.Parent; | ||
|
||
import java.io.IOException; | ||
|
||
@FunctionalInterface | ||
public interface FxmlResolver { | ||
Parent resolve(String relativePathWithoutExtension) throws IOException; | ||
} |
34 changes: 34 additions & 0 deletions
34
...top/src/main/java/com/osscameroon/jsgenerator/desktop/controller/HelloViewController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.osscameroon.jsgenerator.desktop.controller; | ||
|
||
import com.osscameroon.jsgenerator.core.Converter; | ||
import javafx.fxml.FXML; | ||
import javafx.scene.control.Label; | ||
import javafx.scene.control.TextArea; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
import java.nio.charset.StandardCharsets; | ||
|
||
@Component | ||
public final class HelloViewController { | ||
private final Converter converter; | ||
|
||
@FXML | ||
private TextArea inputArea; | ||
@FXML | ||
private Label outputLabel; | ||
|
||
public HelloViewController(Converter converter) { | ||
this.converter = converter; | ||
} | ||
|
||
@FXML | ||
private void convert() throws IOException { | ||
try (var stream = new ByteArrayOutputStream()) { | ||
converter.convert(new ByteArrayInputStream(inputArea.textProperty().getValue().getBytes()), stream); | ||
outputLabel.setText(stream.toString(StandardCharsets.UTF_8)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,18 @@ | ||
module com.osscameroon.jsgenerator.desktop { | ||
exports com.osscameroon.jsgenerator.desktop.autoconfigure; | ||
exports com.osscameroon.jsgenerator.desktop.controller; | ||
|
||
opens com.osscameroon.jsgenerator.desktop.controller to javafx.fxml, spring.beans; | ||
opens com.osscameroon.jsgenerator.desktop.autoconfigure to javafx.fxml, spring.beans; | ||
|
||
requires com.osscameroon.jsgenerator.core; | ||
requires javafx.controls; | ||
requires javafx.fxml; | ||
requires javafx.web; | ||
|
||
requires org.controlsfx.controls; | ||
requires com.dlsc.formsfx; | ||
requires net.synedra.validatorfx; | ||
requires org.kordamp.ikonli.javafx; | ||
requires org.kordamp.bootstrapfx.core; | ||
requires eu.hansolo.tilesfx; | ||
requires spring.boot.autoconfigure; | ||
requires spring.boot; | ||
requires spring.context; | ||
|
||
opens com.osscameroon.jsgenerator.desktop to javafx.fxml; | ||
exports com.osscameroon.jsgenerator.desktop; | ||
requires javafx.graphics; | ||
requires javafx.controls; | ||
requires javafx.fxml; | ||
requires spring.core; | ||
} |
Oops, something went wrong.