Configuration dialog.
+ Help dialog
This commit is contained in:
1 parent
8591df9dbd
commit
a4993e2d78
3 files changed
+239
No files matched your search
@@ -0,0 +1,131 @@
|
|||||||
|
package com.molnarandrei.sopa.ui;
|
||||||
|
|
||||||
|
import atlantafx.base.controls.Spacer;
|
||||||
|
import atlantafx.base.theme.Styles;
|
||||||
|
import com.molnarandrei.sopa.data.yaml.Config;
|
||||||
|
import com.molnarandrei.sopa.ui.lib.Packing;
|
||||||
|
import javafx.geometry.Insets;
|
||||||
|
import javafx.scene.Scene;
|
||||||
|
import javafx.scene.control.*;
|
||||||
|
import javafx.scene.layout.*;
|
||||||
|
import javafx.stage.Modality;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
import javafx.stage.Window;
|
||||||
|
import org.kordamp.ikonli.javafx.FontIcon;
|
||||||
|
import org.kordamp.ikonli.materialdesign2.MaterialDesignC;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
/** Edits the settings of the app; they are saved only with "Guardar cambios". */
|
||||||
|
public class ConfigDialog extends Stage {
|
||||||
|
|
||||||
|
/** A whole number setting, valid from {@code min}. */
|
||||||
|
private record Setting(TextField field, int min, Consumer<Integer> set) {}
|
||||||
|
|
||||||
|
private final List<Setting> settings = new ArrayList<>();
|
||||||
|
private final GridPane grid = new GridPane();
|
||||||
|
|
||||||
|
public ConfigDialog(Window owner) {
|
||||||
|
initOwner(owner);
|
||||||
|
initModality(Modality.WINDOW_MODAL);
|
||||||
|
setTitle("Configuración");
|
||||||
|
|
||||||
|
var title = new Label("Configuración");
|
||||||
|
Styles.addStyleClass(title, Styles.TITLE_1);
|
||||||
|
|
||||||
|
grid.setVgap(8);
|
||||||
|
grid.setHgap(16);
|
||||||
|
var fieldColumn = new ColumnConstraints();
|
||||||
|
fieldColumn.setHgrow(Priority.ALWAYS);
|
||||||
|
grid.getColumnConstraints().addAll(new ColumnConstraints(), fieldColumn);
|
||||||
|
|
||||||
|
var config = Config.get();
|
||||||
|
add("Historial de respuestas:", "Respuestas que se guardan por paso; al superarlas se borran las más antiguas.",
|
||||||
|
1, config::getResponseHistory, config::setResponseHistory);
|
||||||
|
add("Tiempo de espera (s):", "Segundos que se espera a conectar con el servidor y a recibir su respuesta antes de dar la llamada por fallida.",
|
||||||
|
1, config::getCallTimeout, config::setCallTimeout);
|
||||||
|
add("Cambios a deshacer:", "Eliminaciones y modificaciones que se pueden deshacer con Ctrl+Z; las más antiguas se olvidan.",
|
||||||
|
1, config::getMaxUndo, config::setMaxUndo);
|
||||||
|
add("Agrupar ediciones (s):", "Las ediciones de un mismo fichero en estos segundos desde la primera se deshacen juntas. Con 0 se deshacen una a una.",
|
||||||
|
0, config::getUndoMergeSeconds, config::setUndoMergeSeconds);
|
||||||
|
|
||||||
|
var scroll = new ScrollPane(grid);
|
||||||
|
scroll.setFitToWidth(true);
|
||||||
|
scroll.setPadding(new Insets(4));
|
||||||
|
|
||||||
|
var cancel = new Button("Cancelar");
|
||||||
|
cancel.setCancelButton(true);
|
||||||
|
cancel.setOnAction(e -> close());
|
||||||
|
|
||||||
|
var save = new Button("Guardar cambios", FontIcon.of(MaterialDesignC.CONTENT_SAVE));
|
||||||
|
Styles.addStyleClass(save, Styles.ACCENT);
|
||||||
|
save.setDefaultButton(true);
|
||||||
|
save.setOnAction(e -> save());
|
||||||
|
|
||||||
|
var root = new BorderPane();
|
||||||
|
root.setPadding(new Insets(16));
|
||||||
|
root.setTop(title);
|
||||||
|
BorderPane.setMargin(title, new Insets(0, 0, 8, 0));
|
||||||
|
root.setCenter(scroll);
|
||||||
|
root.setBottom(new VBox(8, new Separator(), new HBox(8, new Spacer(), cancel, save)));
|
||||||
|
BorderPane.setMargin(root.getBottom(), new Insets(8, 0, 0, 0));
|
||||||
|
root.setPrefWidth(480);
|
||||||
|
|
||||||
|
var scene = new Scene(root);
|
||||||
|
if (owner != null && owner.getScene() != null)
|
||||||
|
scene.getStylesheets().addAll(owner.getScene().getStylesheets());
|
||||||
|
setScene(scene);
|
||||||
|
Packing.pack(this, scene);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void add(String name, String description, int min, Supplier<Integer> get, Consumer<Integer> set) {
|
||||||
|
var label = new Label(name);
|
||||||
|
var field = new TextField(String.valueOf(get.get()));
|
||||||
|
// Only digits can be typed.
|
||||||
|
field.setTextFormatter(new TextFormatter<String>(change -> change.getControlNewText().matches("\\d*") ? change : null));
|
||||||
|
field.textProperty().addListener((obs, old, value) -> field.pseudoClassStateChanged(Styles.STATE_DANGER, false));
|
||||||
|
var tooltip = new Tooltip(description + (min > 0 ? " Mínimo %d.".formatted(min) : ""));
|
||||||
|
tooltip.setWrapText(true);
|
||||||
|
tooltip.setMaxWidth(360);
|
||||||
|
label.setTooltip(tooltip);
|
||||||
|
field.setTooltip(tooltip);
|
||||||
|
// Behind the label and the field, so the gaps of the row show the tooltip too.
|
||||||
|
var background = new Region();
|
||||||
|
Tooltip.install(background, tooltip);
|
||||||
|
|
||||||
|
var row = settings.size();
|
||||||
|
grid.add(background, 0, row, 2, 1);
|
||||||
|
grid.add(label, 0, row);
|
||||||
|
grid.add(field, 1, row);
|
||||||
|
settings.add(new Setting(field, min, set));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Saves when every value is valid; else marks the invalid fields and keeps the dialog open. */
|
||||||
|
private void save() {
|
||||||
|
var valid = true;
|
||||||
|
for (var setting : settings) {
|
||||||
|
var invalid = valueOf(setting) == null;
|
||||||
|
setting.field().pseudoClassStateChanged(Styles.STATE_DANGER, invalid);
|
||||||
|
valid &= ! invalid;
|
||||||
|
}
|
||||||
|
if (! valid) return;
|
||||||
|
|
||||||
|
for (var setting : settings)
|
||||||
|
setting.set().accept(valueOf(setting));
|
||||||
|
Config.get().save();
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Null when blank, too big or below the minimum. */
|
||||||
|
private static Integer valueOf(Setting setting) {
|
||||||
|
try {
|
||||||
|
var value = Integer.parseInt(setting.field().getText());
|
||||||
|
return value < setting.min() ? null : value;
|
||||||
|
} catch (NumberFormatException blankOrTooBig) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,96 @@
|
|||||||
|
package com.molnarandrei.sopa.ui;
|
||||||
|
|
||||||
|
import atlantafx.base.controls.Spacer;
|
||||||
|
import atlantafx.base.theme.Styles;
|
||||||
|
import com.molnarandrei.sopa.ui.lib.Packing;
|
||||||
|
import javafx.geometry.Insets;
|
||||||
|
import javafx.scene.Scene;
|
||||||
|
import javafx.scene.control.*;
|
||||||
|
import javafx.scene.layout.*;
|
||||||
|
import javafx.stage.Modality;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
import javafx.stage.Window;
|
||||||
|
|
||||||
|
public class HelpDialog extends Stage {
|
||||||
|
private static final String[][] SHORTCUTS = {
|
||||||
|
{"Ctrl+N", "Crea dentro de lo seleccionado en el árbol: un caso en un proyecto, un paso en un caso o en el caso de un paso. Sin selección, un proyecto."},
|
||||||
|
{"Ctrl+S", "Guarda el editor o las propiedades abiertas."},
|
||||||
|
{"Enter", "Guarda el campo."},
|
||||||
|
{"Ctrl+Z", "En el árbol, deshace la última eliminación o modificación. Cada campo se guarda al salir de él, así que cada cambio se puede deshacer; las ediciones de un mismo fichero en 10 s (por defecto, en Configuración) se deshacen juntas."},
|
||||||
|
{"Ctrl+C / X / V", "En el árbol, copia, corta y pega casos y pasos."},
|
||||||
|
{"Supr", "En el árbol, elimina lo seleccionado."},
|
||||||
|
{"Tab / Mayús+Tab", "En el XML, sangra o quita la sangría."},
|
||||||
|
};
|
||||||
|
|
||||||
|
public HelpDialog(Window owner) {
|
||||||
|
initOwner(owner);
|
||||||
|
initModality(Modality.WINDOW_MODAL);
|
||||||
|
setTitle("Ayuda");
|
||||||
|
|
||||||
|
var shortcuts = new GridPane();
|
||||||
|
shortcuts.setHgap(16);
|
||||||
|
shortcuts.setVgap(8);
|
||||||
|
var descriptionColumn = new ColumnConstraints();
|
||||||
|
descriptionColumn.setHgrow(Priority.ALWAYS);
|
||||||
|
// The keys keep their width, the descriptions wrap in the rest.
|
||||||
|
var keysColumn = new ColumnConstraints();
|
||||||
|
keysColumn.setMinWidth(Region.USE_PREF_SIZE);
|
||||||
|
shortcuts.getColumnConstraints().addAll(keysColumn, descriptionColumn);
|
||||||
|
for (int row = 0; row < SHORTCUTS.length; row++) {
|
||||||
|
var keys = new Label(SHORTCUTS[row][0]);
|
||||||
|
Styles.addStyleClass(keys, Styles.TEXT_BOLD);
|
||||||
|
keys.setMinWidth(Region.USE_PREF_SIZE);
|
||||||
|
shortcuts.add(keys, 0, row);
|
||||||
|
shortcuts.add(text(SHORTCUTS[row][1]), 1, row);
|
||||||
|
}
|
||||||
|
|
||||||
|
var content = new VBox(8,
|
||||||
|
title("Sopa", Styles.TITLE_1),
|
||||||
|
text("Sopa prueba servicios SOAP. Un proyecto tiene casos de prueba y cada caso, pasos: llamadas SOAP con "
|
||||||
|
+ "aserciones y extracciones que guardan propiedades para los pasos siguientes. Ejecutar un caso o un "
|
||||||
|
+ "proyecto ejecuta sus pasos en orden y se detiene en el primero que falla."),
|
||||||
|
title("Pensada para agentes", Styles.TITLE_3),
|
||||||
|
text("Un proyecto son ficheros YAML y .properties legibles en su carpeta, descritos en su AGENTS.md. Tú o un "
|
||||||
|
+ "agente IA podéis editarlos desde fuera y la app los recarga al momento; lo que cambias en la app se "
|
||||||
|
+ "escribe en ellos."),
|
||||||
|
title("Atajos", Styles.TITLE_3),
|
||||||
|
shortcuts
|
||||||
|
);
|
||||||
|
content.setPadding(new Insets(4));
|
||||||
|
|
||||||
|
var scroll = new ScrollPane(content);
|
||||||
|
scroll.setFitToWidth(true);
|
||||||
|
|
||||||
|
var close = new Button("Cerrar");
|
||||||
|
close.setDefaultButton(true);
|
||||||
|
close.setCancelButton(true);
|
||||||
|
close.setOnAction(e -> close());
|
||||||
|
|
||||||
|
var root = new BorderPane();
|
||||||
|
root.setPadding(new Insets(16));
|
||||||
|
root.setCenter(scroll);
|
||||||
|
root.setBottom(new VBox(8, new Separator(), new HBox(new Spacer(), close)));
|
||||||
|
BorderPane.setMargin(root.getBottom(), new Insets(8, 0, 0, 0));
|
||||||
|
root.setPrefSize(560, 520);
|
||||||
|
|
||||||
|
var scene = new Scene(root);
|
||||||
|
if (owner != null && owner.getScene() != null)
|
||||||
|
scene.getStylesheets().addAll(owner.getScene().getStylesheets());
|
||||||
|
setScene(scene);
|
||||||
|
Packing.pack(this, scene);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Label title(String text, String style) {
|
||||||
|
var label = new Label(text);
|
||||||
|
Styles.addStyleClass(label, style);
|
||||||
|
return label;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Label text(String text) {
|
||||||
|
var label = new Label(text);
|
||||||
|
label.setWrapText(true);
|
||||||
|
// Else layouts give it the height of one line and it shows as "...".
|
||||||
|
label.setMinHeight(Region.USE_PREF_SIZE);
|
||||||
|
return label;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,6 +5,8 @@ import com.molnarandrei.sopa.data.yaml.Config;
|
|||||||
import com.molnarandrei.sopa.data.yaml.Kind;
|
import com.molnarandrei.sopa.data.yaml.Kind;
|
||||||
import com.molnarandrei.sopa.events.Events;
|
import com.molnarandrei.sopa.events.Events;
|
||||||
import com.molnarandrei.sopa.events.ProjectTreeViewEvent;
|
import com.molnarandrei.sopa.events.ProjectTreeViewEvent;
|
||||||
|
import com.molnarandrei.sopa.ui.ConfigDialog;
|
||||||
|
import com.molnarandrei.sopa.ui.HelpDialog;
|
||||||
import com.molnarandrei.sopa.ui.PropertiesDialog;
|
import com.molnarandrei.sopa.ui.PropertiesDialog;
|
||||||
import com.molnarandrei.sopa.ui.create.CreateProjectDialog;
|
import com.molnarandrei.sopa.ui.create.CreateProjectDialog;
|
||||||
import javafx.event.EventHandler;
|
import javafx.event.EventHandler;
|
||||||
@@ -17,8 +19,10 @@ import com.molnarandrei.sopa.project.ProjectService;
|
|||||||
import javafx.scene.control.*;
|
import javafx.scene.control.*;
|
||||||
import javafx.stage.*;
|
import javafx.stage.*;
|
||||||
import org.kordamp.ikonli.javafx.FontIcon;
|
import org.kordamp.ikonli.javafx.FontIcon;
|
||||||
|
import org.kordamp.ikonli.materialdesign2.MaterialDesignA;
|
||||||
import org.kordamp.ikonli.materialdesign2.MaterialDesignC;
|
import org.kordamp.ikonli.materialdesign2.MaterialDesignC;
|
||||||
import org.kordamp.ikonli.materialdesign2.MaterialDesignF;
|
import org.kordamp.ikonli.materialdesign2.MaterialDesignF;
|
||||||
|
import org.kordamp.ikonli.materialdesign2.MaterialDesignH;
|
||||||
|
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -70,12 +74,20 @@ public class TopMenu extends MenuBar {
|
|||||||
propertiesMenu = new Menu();
|
propertiesMenu = new Menu();
|
||||||
propertiesMenu.setGraphic(propertiesLabel);
|
propertiesMenu.setGraphic(propertiesLabel);
|
||||||
|
|
||||||
|
var config = new MenuItem("Configuración", FontIcon.of(MaterialDesignC.COG));
|
||||||
|
config.setOnAction(e -> new ConfigDialog(getScene().getWindow()).show());
|
||||||
|
var help = new MenuItem("Ayuda", FontIcon.of(MaterialDesignH.HELP_CIRCLE_OUTLINE));
|
||||||
|
help.setOnAction(e -> new HelpDialog(getScene().getWindow()).show());
|
||||||
|
var appMenu = new Menu("Aplicación", FontIcon.of(MaterialDesignA.APPLICATION_COG));
|
||||||
|
appMenu.getItems().addAll(config, help);
|
||||||
|
|
||||||
// MenuBar only holds Menus, so the spacer is an empty, disabled Menu whose button grows (see layoutChildren).
|
// MenuBar only holds Menus, so the spacer is an empty, disabled Menu whose button grows (see layoutChildren).
|
||||||
separatorMenu = new Menu();
|
separatorMenu = new Menu();
|
||||||
separatorMenu.setDisable(true);
|
separatorMenu.setDisable(true);
|
||||||
|
|
||||||
getMenus().addAll(
|
getMenus().addAll(
|
||||||
projectMenu,
|
projectMenu,
|
||||||
|
appMenu,
|
||||||
separatorMenu,
|
separatorMenu,
|
||||||
propertiesMenu
|
propertiesMenu
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in new issue
Block a user