first commit
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
plugins {
|
||||
id("gradle.java-application-conventions")
|
||||
alias(libs.plugins.javafx)
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(project(":prometeu-infra"))
|
||||
implementation(libs.javafx.controls)
|
||||
implementation(libs.javafx.fxml)
|
||||
implementation(libs.richtextfx)
|
||||
}
|
||||
|
||||
javafx {
|
||||
version = libs.versions.javafx.get()
|
||||
modules("javafx.controls", "javafx.fxml")
|
||||
}
|
||||
|
||||
application {
|
||||
mainClass = "p.studio.App"
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package p.studio;
|
||||
|
||||
import javafx.application.Application;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.stage.Stage;
|
||||
import p.studio.utilities.i18n.I18n;
|
||||
import p.studio.window.MainView;
|
||||
|
||||
public class App extends Application {
|
||||
|
||||
@Override
|
||||
public void init() throws Exception {
|
||||
super.init();
|
||||
Container.init();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start(Stage stage) {
|
||||
var root = new MainView();
|
||||
var scene = new Scene(root, 1200, 800);
|
||||
|
||||
scene.getStylesheets().add(Container.theme().getDefaultTheme());
|
||||
stage.titleProperty().bind(Container.i18n().bind(I18n.APP_TITLE));
|
||||
stage.setScene(scene);
|
||||
stage.show();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
launch();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package p.studio;
|
||||
|
||||
import p.studio.utilities.ThemeService;
|
||||
import p.studio.utilities.i18n.I18nService;
|
||||
|
||||
public class Container {
|
||||
private static final I18nService i18nService;
|
||||
private static final ThemeService themeService;
|
||||
|
||||
static {
|
||||
i18nService = new I18nService();
|
||||
themeService = new ThemeService();
|
||||
}
|
||||
|
||||
public static void init() {
|
||||
}
|
||||
|
||||
public static I18nService i18n() { return i18nService; }
|
||||
|
||||
public static ThemeService theme() { return new ThemeService(); }
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package p.studio.utilities;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class ThemeService {
|
||||
private static final String THEME_PATH = "/themes/";
|
||||
private static final String DEFAULT_THEME = THEME_PATH + "default-prometeu.css";
|
||||
|
||||
public String getDefaultTheme() {
|
||||
return Objects.requireNonNull(getClass().getResource(DEFAULT_THEME)).toExternalForm();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package p.studio.utilities.i18n;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
public enum I18n {
|
||||
APP_TITLE("app.title"),
|
||||
|
||||
MENU_FILE("menu.file"),
|
||||
MENU_FILE_NEWPROJECT("menu.file.newProject"),
|
||||
MENU_FILE_OPEN("menu.file.open"),
|
||||
MENU_FILE_SAVE("menu.file.save"),
|
||||
|
||||
MENU_EDIT("menu.edit"),
|
||||
MENU_VIEW("menu.view"),
|
||||
MENU_HELP("menu.help"),
|
||||
|
||||
TOOLBAR_PLAY("toolbar.play"),
|
||||
TOOLBAR_STOP("toolbar.stop"),
|
||||
TOOLBAR_EXPORT("toolbar.export"),
|
||||
|
||||
WORKSPACE_CODE("workspace.code"),
|
||||
WORKSPACE_ASSETS("workspace.assets"),
|
||||
WORKSPACE_DEBUG("workspace.debug"),
|
||||
|
||||
;
|
||||
|
||||
@Getter
|
||||
private final String key;
|
||||
|
||||
I18n(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package p.studio.utilities.i18n;
|
||||
|
||||
import javafx.beans.binding.Bindings;
|
||||
import javafx.beans.binding.StringBinding;
|
||||
import javafx.beans.property.ObjectProperty;
|
||||
import javafx.beans.property.SimpleObjectProperty;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.Locale;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
public final class I18nService {
|
||||
private final ObjectProperty<Locale> locale = new SimpleObjectProperty<>(Locale.ENGLISH);
|
||||
|
||||
public ObjectProperty<Locale> localeProperty() { return locale; }
|
||||
public Locale getLocale() { return locale.get(); }
|
||||
public void setLocale(Locale l) { locale.set(l); }
|
||||
|
||||
private ResourceBundle bundle(Locale l) {
|
||||
return ResourceBundle.getBundle("i18n.messages", l);
|
||||
}
|
||||
|
||||
public String text(I18n i18n) {
|
||||
return bundle(getLocale()).getString(i18n.getKey());
|
||||
}
|
||||
|
||||
public String format(I18n i18n, Object... args) {
|
||||
return new MessageFormat(text(i18n), getLocale()).format(args);
|
||||
}
|
||||
|
||||
public StringBinding bind(I18n key) {
|
||||
return Bindings.createStringBinding(
|
||||
() -> text(key),
|
||||
locale
|
||||
);
|
||||
}
|
||||
|
||||
public StringBinding bind(I18n key, Object... args) {
|
||||
return Bindings.createStringBinding(
|
||||
() -> format(key, args),
|
||||
locale
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package p.studio.window;
|
||||
|
||||
import javafx.scene.layout.BorderPane;
|
||||
import p.studio.workspaces.PlaceholderWorkspace;
|
||||
import p.studio.workspaces.WorkspaceHost;
|
||||
import p.studio.workspaces.WorkspaceId;
|
||||
import p.studio.workspaces.editor.EditorWorkspace;
|
||||
|
||||
public final class MainView extends BorderPane {
|
||||
private static final WorkspaceHost HOST = new WorkspaceHost();
|
||||
|
||||
public MainView() {
|
||||
var menubar = new MenuBar();
|
||||
setTop(menubar);
|
||||
|
||||
HOST.register(new EditorWorkspace());
|
||||
HOST.register(new PlaceholderWorkspace(WorkspaceId.ASSETS, "Assets"));
|
||||
HOST.register(new PlaceholderWorkspace(WorkspaceId.BUILD, "Build"));
|
||||
HOST.register(new PlaceholderWorkspace(WorkspaceId.DEVICE, "Device"));
|
||||
|
||||
var bar = new WorkspaceBar(HOST::show);
|
||||
setLeft(bar);
|
||||
setCenter(HOST);
|
||||
|
||||
// default
|
||||
bar.select(WorkspaceId.EDITOR);
|
||||
HOST.show(WorkspaceId.EDITOR);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package p.studio.window;
|
||||
|
||||
import javafx.scene.control.Menu;
|
||||
import javafx.scene.control.MenuItem;
|
||||
import p.studio.Container;
|
||||
import p.studio.utilities.i18n.I18n;
|
||||
|
||||
public final class MenuBar extends javafx.scene.control.MenuBar {
|
||||
public MenuBar() {
|
||||
|
||||
Menu file = new Menu();
|
||||
file.textProperty().bind(Container.i18n().bind(I18n.MENU_FILE));
|
||||
|
||||
MenuItem newProject = new MenuItem();
|
||||
newProject.textProperty().bind(Container.i18n().bind(I18n.MENU_FILE_NEWPROJECT));
|
||||
|
||||
MenuItem open = new MenuItem();
|
||||
open.textProperty().bind(Container.i18n().bind(I18n.MENU_FILE_OPEN));
|
||||
|
||||
MenuItem save = new MenuItem();
|
||||
save.textProperty().bind(Container.i18n().bind(I18n.MENU_FILE_SAVE));
|
||||
|
||||
file.getItems().addAll(newProject, open, save);
|
||||
|
||||
Menu edit = new Menu();
|
||||
edit.textProperty().bind(Container.i18n().bind(I18n.MENU_EDIT));
|
||||
|
||||
Menu view = new Menu();
|
||||
view.textProperty().bind(Container.i18n().bind(I18n.MENU_VIEW));
|
||||
|
||||
Menu help = new Menu();
|
||||
help.textProperty().bind(Container.i18n().bind(I18n.MENU_HELP));
|
||||
|
||||
getMenus().addAll(file, edit, view, help);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package p.studio.window;
|
||||
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.scene.control.ToggleButton;
|
||||
import javafx.scene.control.ToggleGroup;
|
||||
import javafx.scene.layout.VBox;
|
||||
import p.studio.workspaces.WorkspaceId;
|
||||
|
||||
import java.util.EnumMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public final class WorkspaceBar extends VBox {
|
||||
private final ToggleGroup group = new ToggleGroup();
|
||||
private final Map<WorkspaceId, ToggleButton> buttons = new EnumMap<>(WorkspaceId.class);
|
||||
|
||||
public WorkspaceBar(Consumer<WorkspaceId> onSelect) {
|
||||
setPadding(new Insets(8));
|
||||
setSpacing(8);
|
||||
setPrefWidth(56);
|
||||
|
||||
addBtn(WorkspaceId.EDITOR, "📝", "Editor", onSelect);
|
||||
addBtn(WorkspaceId.ASSETS, "📦", "Assets", onSelect);
|
||||
addBtn(WorkspaceId.BUILD, "⚙️", "Build", onSelect);
|
||||
addBtn(WorkspaceId.DEVICE, "🎮", "Device", onSelect);
|
||||
}
|
||||
|
||||
private void addBtn(WorkspaceId id, String icon, String tooltip, Consumer<WorkspaceId> onSelect) {
|
||||
ToggleButton b = new ToggleButton(icon);
|
||||
b.setToggleGroup(group);
|
||||
b.setFocusTraversable(false);
|
||||
b.setPrefSize(40, 40);
|
||||
b.setMinSize(40, 40);
|
||||
b.setMaxSize(40, 40);
|
||||
b.setUserData(id);
|
||||
b.setOnAction(e -> onSelect.accept(id));
|
||||
b.setStyle("-fx-font-size: 16px;");
|
||||
|
||||
buttons.put(id, b);
|
||||
getChildren().add(b);
|
||||
}
|
||||
|
||||
public void select(WorkspaceId id) {
|
||||
ToggleButton b = buttons.get(id);
|
||||
if (b != null) b.setSelected(true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package p.studio.workspaces;
|
||||
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.layout.StackPane;
|
||||
import p.studio.utilities.i18n.I18n;
|
||||
|
||||
public final class PlaceholderWorkspace implements Workspace {
|
||||
private final WorkspaceId id;
|
||||
private final StackPane root = new StackPane();
|
||||
|
||||
public PlaceholderWorkspace(WorkspaceId id, String label) {
|
||||
this.id = id;
|
||||
root.getChildren().add(new Label(label + " (TODO)"));
|
||||
}
|
||||
|
||||
@Override public WorkspaceId id() { return id; }
|
||||
@Override public I18n title() { return I18n.WORKSPACE_ASSETS; }
|
||||
@Override public Node root() { return root; }
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package p.studio.workspaces;
|
||||
|
||||
import p.studio.utilities.i18n.I18n;
|
||||
|
||||
public interface Workspace {
|
||||
WorkspaceId id();
|
||||
I18n title();
|
||||
javafx.scene.Node root();
|
||||
default void onShow() {}
|
||||
default void onHide() {}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
package p.studio.workspaces;
|
||||
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.layout.StackPane;
|
||||
|
||||
import java.util.EnumMap;
|
||||
import java.util.Map;
|
||||
|
||||
public final class WorkspaceHost extends StackPane {
|
||||
private final Map<WorkspaceId, Workspace> workspaces = new EnumMap<>(WorkspaceId.class);
|
||||
private WorkspaceId active;
|
||||
|
||||
public void register(Workspace ws) {
|
||||
workspaces.put(ws.id(), ws);
|
||||
|
||||
Node r = ws.root();
|
||||
r.setVisible(false);
|
||||
r.setManaged(false);
|
||||
getChildren().add(r);
|
||||
}
|
||||
|
||||
public void show(WorkspaceId id) {
|
||||
if (active == id) return;
|
||||
|
||||
if (active != null) {
|
||||
Workspace old = workspaces.get(active);
|
||||
old.onHide();
|
||||
Node n = old.root();
|
||||
n.setVisible(false);
|
||||
n.setManaged(false);
|
||||
}
|
||||
|
||||
Workspace next = workspaces.get(id);
|
||||
if (next == null) throw new IllegalStateException("Workspace not registered: " + id);
|
||||
|
||||
Node n = next.root();
|
||||
n.setVisible(true);
|
||||
n.setManaged(true);
|
||||
next.onShow();
|
||||
|
||||
active = id;
|
||||
}
|
||||
|
||||
public WorkspaceId active() { return active; }
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package p.studio.workspaces;
|
||||
|
||||
public enum WorkspaceId {
|
||||
EDITOR,
|
||||
ASSETS,
|
||||
BUILD,
|
||||
DEVICE
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package p.studio.workspaces.editor;
|
||||
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.layout.Region;
|
||||
|
||||
public final class EditorToolbar extends HBox {
|
||||
|
||||
public EditorToolbar() {
|
||||
setPadding(new Insets(6, 10, 6, 10));
|
||||
setSpacing(8);
|
||||
getStyleClass().add("main-toolbar");
|
||||
|
||||
Button newBtn = iconButton("📄", "New");
|
||||
Button openBtn = iconButton("📂", "Open");
|
||||
Button saveBtn = iconButton("💾", "Save");
|
||||
|
||||
Button runBtn = iconButton("▶", "Run");
|
||||
runBtn.getStyleClass().add("accent");
|
||||
|
||||
Region spacer = new Region();
|
||||
HBox.setHgrow(spacer, javafx.scene.layout.Priority.ALWAYS);
|
||||
|
||||
getChildren().addAll(
|
||||
newBtn,
|
||||
openBtn,
|
||||
saveBtn,
|
||||
spacer,
|
||||
runBtn
|
||||
);
|
||||
}
|
||||
|
||||
private Button iconButton(String icon, String tooltip) {
|
||||
Button b = new Button(icon);
|
||||
b.setFocusTraversable(false);
|
||||
b.getStyleClass().add("toolbar-button");
|
||||
return b;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package p.studio.workspaces.editor;
|
||||
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.layout.BorderPane;
|
||||
import org.fxmisc.richtext.CodeArea;
|
||||
import org.fxmisc.richtext.LineNumberFactory;
|
||||
import p.studio.utilities.i18n.I18n;
|
||||
import p.studio.workspaces.Workspace;
|
||||
import p.studio.workspaces.WorkspaceId;
|
||||
|
||||
public final class EditorWorkspace implements Workspace {
|
||||
private final BorderPane root = new BorderPane();
|
||||
private final EditorToolbar toolbar = new EditorToolbar();
|
||||
private final CodeArea codeArea = new CodeArea();
|
||||
|
||||
public EditorWorkspace() {
|
||||
codeArea.setParagraphGraphicFactory(LineNumberFactory.get(codeArea));
|
||||
codeArea.replaceText("""
|
||||
fn frame(): void
|
||||
{
|
||||
// hello Prometeu
|
||||
}
|
||||
""");
|
||||
|
||||
root.setTop(toolbar);
|
||||
root.setCenter(codeArea);
|
||||
}
|
||||
|
||||
@Override public WorkspaceId id() { return WorkspaceId.EDITOR; }
|
||||
@Override public I18n title() { return I18n.WORKSPACE_CODE; }
|
||||
@Override public Node root() { return root; }
|
||||
|
||||
public CodeArea codeArea() { return codeArea; }
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
app.title=Prometeu Studio
|
||||
|
||||
menu.file=File
|
||||
menu.file.newProject=New Project
|
||||
menu.file.open=Open
|
||||
menu.file.save=Save
|
||||
menu.edit=Edit
|
||||
menu.view=View
|
||||
menu.help=Help
|
||||
|
||||
toolbar.play=Play
|
||||
toolbar.stop=Stop
|
||||
toolbar.export=Export
|
||||
workspace.code=Code
|
||||
workspace.assets=Assets
|
||||
workspace.debug=Debug
|
||||
@@ -0,0 +1,16 @@
|
||||
app.title=Prometeu Studio
|
||||
|
||||
menu.file=Arquivo
|
||||
menu.file.newProject=Novo Projeto
|
||||
menu.file.open=Abrir
|
||||
menu.file.save=Salvar
|
||||
menu.edit=Editar
|
||||
menu.view=Visualizar
|
||||
menu.help=Ajuda
|
||||
|
||||
toolbar.play=Executar
|
||||
toolbar.stop=Parar
|
||||
toolbar.export=Exportar
|
||||
workspace.code=Código
|
||||
workspace.assets=Assets
|
||||
workspace.debug=Depurar
|
||||
@@ -0,0 +1,36 @@
|
||||
.root {
|
||||
-fx-font-family: "Inter", "Segoe UI", sans-serif;
|
||||
-fx-base: #1e1e1e;
|
||||
-fx-background: #1e1e1e;
|
||||
}
|
||||
|
||||
.main-toolbar {
|
||||
-fx-background-color: #252526;
|
||||
-fx-border-color: #2d2d2d;
|
||||
-fx-border-width: 0 0 1 0;
|
||||
}
|
||||
|
||||
.toolbar-button {
|
||||
-fx-background-color: transparent;
|
||||
-fx-text-fill: #d4d4d4;
|
||||
-fx-font-size: 14px;
|
||||
-fx-padding: 6 10 6 10;
|
||||
-fx-background-radius: 6;
|
||||
}
|
||||
|
||||
.toolbar-button:hover {
|
||||
-fx-background-color: #2a2d2e;
|
||||
}
|
||||
|
||||
.toolbar-button:pressed {
|
||||
-fx-background-color: #37373d;
|
||||
}
|
||||
|
||||
.toolbar-button.accent {
|
||||
-fx-background-color: #0e639c;
|
||||
-fx-text-fill: white;
|
||||
}
|
||||
|
||||
.toolbar-button.accent:hover {
|
||||
-fx-background-color: #1177bb;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
/*
|
||||
* This source file was generated by the Gradle 'init' task
|
||||
*/
|
||||
package p.studio.app;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
class MessageUtilsTest {
|
||||
@Test void testGetMessage() {
|
||||
assertEquals("Hello World!", MessageUtils.getMessage());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user