mirror of
https://github.com/2OOP/pism.git
synced 2026-02-04 10:54:51 +00:00
Added function input for enabling/disabling localization p/text
This commit is contained in:
@@ -4,7 +4,6 @@ import javafx.scene.image.ImageView;
|
|||||||
import org.toop.framework.resource.resources.ImageAsset;
|
import org.toop.framework.resource.resources.ImageAsset;
|
||||||
import org.toop.local.AppContext;
|
import org.toop.local.AppContext;
|
||||||
|
|
||||||
import java.awt.*;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
@@ -23,30 +22,38 @@ import javafx.scene.text.Text;
|
|||||||
import javafx.util.StringConverter;
|
import javafx.util.StringConverter;
|
||||||
|
|
||||||
public final class Primitive {
|
public final class Primitive {
|
||||||
public static Text header(String key) {
|
public static Text header(String key, boolean localize) {
|
||||||
var header = new Text();
|
var header = new Text();
|
||||||
header.getStyleClass().add("header");
|
header.getStyleClass().add("header");
|
||||||
|
|
||||||
if (!key.isEmpty()) {
|
if (!key.isEmpty()) {
|
||||||
header.setText(AppContext.getString(key));
|
if (localize) header.setText(AppContext.getString(key)); else header.setText(key);
|
||||||
header.textProperty().bind(AppContext.bindToKey(key));
|
header.textProperty().bind(AppContext.bindToKey(key, localize));
|
||||||
}
|
}
|
||||||
|
|
||||||
return header;
|
return header;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Text text(String key) {
|
public static Text header(String key) {
|
||||||
|
return header(key, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Text text(String key, boolean localize) {
|
||||||
var text = new Text();
|
var text = new Text();
|
||||||
text.getStyleClass().add("text");
|
text.getStyleClass().add("text");
|
||||||
|
|
||||||
if (!key.isEmpty()) {
|
if (!key.isEmpty()) {
|
||||||
text.setText(AppContext.getString(key));
|
if (localize) text.setText(AppContext.getString(key)); else text.setText(key);
|
||||||
text.textProperty().bind(AppContext.bindToKey(key));
|
text.textProperty().bind(AppContext.bindToKey(key, localize));
|
||||||
}
|
}
|
||||||
|
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Text text(String key) {
|
||||||
|
return text(key, true);
|
||||||
|
}
|
||||||
|
|
||||||
public static ImageView image(File file) {
|
public static ImageView image(File file) {
|
||||||
ImageAsset imageAsset = new ImageAsset(file);
|
ImageAsset imageAsset = new ImageAsset(file);
|
||||||
ImageView imageView = new ImageView(imageAsset.getImage());
|
ImageView imageView = new ImageView(imageAsset.getImage());
|
||||||
@@ -57,13 +64,13 @@ public final class Primitive {
|
|||||||
return imageView;
|
return imageView;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Button button(String key, Runnable onAction) {
|
public static Button button(String key, Runnable onAction, boolean localize) {
|
||||||
var button = new Button();
|
var button = new Button();
|
||||||
button.getStyleClass().add("button");
|
button.getStyleClass().add("button");
|
||||||
|
|
||||||
if (!key.isEmpty()) {
|
if (!key.isEmpty()) {
|
||||||
button.setText(AppContext.getString(key));
|
if (localize) button.setText(AppContext.getString(key)); else button.setText(key);
|
||||||
button.textProperty().bind(AppContext.bindToKey(key));
|
button.textProperty().bind(AppContext.bindToKey(key, localize));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (onAction != null) {
|
if (onAction != null) {
|
||||||
@@ -74,13 +81,17 @@ public final class Primitive {
|
|||||||
return button;
|
return button;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TextField input(String promptKey, String text, Consumer<String> onValueChanged) {
|
public static Button button(String key, Runnable onAction) {
|
||||||
|
return button(key, onAction, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TextField input(String promptKey, String text, Consumer<String> onValueChanged, boolean localize) {
|
||||||
var input = new TextField();
|
var input = new TextField();
|
||||||
input.getStyleClass().add("input");
|
input.getStyleClass().add("input");
|
||||||
|
|
||||||
if (!promptKey.isEmpty()) {
|
if (!promptKey.isEmpty()) {
|
||||||
input.setPromptText(AppContext.getString(promptKey));
|
if (localize) input.setPromptText(AppContext.getString(promptKey)); else input.setPromptText(promptKey);
|
||||||
input.promptTextProperty().bind(AppContext.bindToKey(promptKey));
|
input.promptTextProperty().bind(AppContext.bindToKey(promptKey, localize));
|
||||||
}
|
}
|
||||||
|
|
||||||
input.setText(text);
|
input.setText(text);
|
||||||
@@ -93,6 +104,10 @@ public final class Primitive {
|
|||||||
return input;
|
return input;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static TextField input(String promptKey, String text, Consumer<String> onValueChanged) {
|
||||||
|
return input(promptKey, text, onValueChanged, true);
|
||||||
|
}
|
||||||
|
|
||||||
public static Slider slider(int min, int max, int value, Consumer<Integer> onValueChanged) {
|
public static Slider slider(int min, int max, int value, Consumer<Integer> onValueChanged) {
|
||||||
var slider = new Slider();
|
var slider = new Slider();
|
||||||
slider.getStyleClass().add("slider");
|
slider.getStyleClass().add("slider");
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ public final class ServerView extends ViewWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void setupLayout() {
|
private void setupLayout() {
|
||||||
var playerHeader = Primitive.header(user);
|
var playerHeader = Primitive.header(user, false);
|
||||||
|
|
||||||
var playerListSection = Primitive.vbox(
|
var playerListSection = Primitive.vbox(
|
||||||
playerHeader,
|
playerHeader,
|
||||||
@@ -52,7 +52,7 @@ public final class ServerView extends ViewWidget {
|
|||||||
listView.getItems().clear();
|
listView.getItems().clear();
|
||||||
|
|
||||||
for (String player : players) {
|
for (String player : players) {
|
||||||
var playerButton = Primitive.button(player, () -> onPlayerClicked.accept(player));
|
var playerButton = Primitive.button(player, () -> onPlayerClicked.accept(player), false);
|
||||||
listView.getItems().add(playerButton);
|
listView.getItems().add(playerButton);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -58,10 +58,19 @@ public class AppContext {
|
|||||||
return "MISSING RESOURCE";
|
return "MISSING RESOURCE";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static StringBinding bindToKey(String key) {
|
public static StringBinding bindToKey(String key, boolean localize) {
|
||||||
return Bindings.createStringBinding(
|
if (localize) return Bindings.createStringBinding(
|
||||||
() -> localization.getString(key, locale),
|
() -> localization.getString(key, locale),
|
||||||
localeProperty
|
localeProperty
|
||||||
);
|
);
|
||||||
|
|
||||||
|
return Bindings.createStringBinding(
|
||||||
|
() -> key
|
||||||
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static StringBinding bindToKey(String key) {
|
||||||
|
return bindToKey(key, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user