Skip to content

Commit

Permalink
Replace I18n ids with constants done
Browse files Browse the repository at this point in the history
  • Loading branch information
innodax committed May 11, 2024
1 parent a15cabb commit ef08a87
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,30 @@ public static void launch(String... args) {
Application.launch(args);
}

private static final String TAB_EDITOR_TITLE = "tab.editor.title";
private static final String TAB_TERMINAL_TITLE = "tab.terminal.title";
private static final String TAB_WORKSPACE_TITLE = "tab.workspace.title";
private static final String MENU_VIEW = "menu.view";
private static final String MENU_HELP = "menu.help";
private static final String MENU_SETTINGS = "menu.settings";

@Override
public void start(Stage stage) {
StageHolder stageHolder = StageHolder.createInstance(stage);
MenuHolder menuHolder = MenuHolder.getInstance();
stage.setTitle(AppSettings.APP_TITLE);

MenuItem editorItem = new MenuItem(I18nUtils.get("tab.editor.title"));
MenuItem editorItem = new MenuItem(I18nUtils.get(TAB_EDITOR_TITLE));
editorItem.setOnAction(actionEvent -> stageHolder.getContent().getTabs().add(new EditorTab()));
Menu mainMenu = new Menu(I18nUtils.get("menu.view"));
Menu mainMenu = new Menu(I18nUtils.get(MENU_VIEW));
mainMenu.getItems().addAll(editorItem);

Menu helpMenu = new Menu(I18nUtils.get("menu.help"));
Menu settingsMenu = new Menu(I18nUtils.get("menu.settings"));
Menu helpMenu = new Menu(I18nUtils.get(MENU_HELP));
Menu settingsMenu = new Menu(I18nUtils.get(MENU_SETTINGS));

Menu terminalSettingsMenu = new Menu(I18nUtils.get("tab.terminal.title"));
Menu editorSettingsMenu = new Menu(I18nUtils.get("tab.editor.title"));
Menu workSpaceSettingsMenu = new Menu(I18nUtils.get("tab.workspace.title"));
Menu terminalSettingsMenu = new Menu(I18nUtils.get(TAB_TERMINAL_TITLE));
Menu editorSettingsMenu = new Menu(I18nUtils.get(TAB_EDITOR_TITLE));
Menu workSpaceSettingsMenu = new Menu(I18nUtils.get(TAB_WORKSPACE_TITLE));
settingsMenu.getItems().addAll(terminalSettingsMenu, editorSettingsMenu, workSpaceSettingsMenu);

menuHolder.put("menu.help", helpMenu);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
*/
public class AlertBuilder {

private static final String ALERT_CONFIRM = "alert.confirm";
private static final String ALERT_UNSAVED_HEADER = "alert.unsaved.header";
private static final String ALERT_UNSAVED_CONTENT = "alert.unsaved.content";
private static final String ALERT_CANCEL = "alert.cancel";
private static final String ALERT_OK = "alert.ok";

private final Alert alert;

/**
Expand Down Expand Up @@ -96,12 +102,12 @@ public static class Prebuilt {
* {@link Alert} to confirm close.
*/
public static final Alert CLOSE_CONFIRMATION =
new AlertBuilder(I18nUtils.get("alert.confirm"), Alert.AlertType.CONFIRMATION)
.header(I18nUtils.get("alert.unsaved.header"))
.content(I18nUtils.get("alert.unsaved.content"))
new AlertBuilder(I18nUtils.get(ALERT_CONFIRM), Alert.AlertType.CONFIRMATION)
.header(I18nUtils.get(ALERT_UNSAVED_HEADER))
.content(I18nUtils.get(ALERT_UNSAVED_CONTENT))
.clearButtonTypes()
.button(I18nUtils.get("alert.cancel"), ButtonBar.ButtonData.CANCEL_CLOSE)
.button(I18nUtils.get("alert.ok"), ButtonBar.ButtonData.OK_DONE)
.button(I18nUtils.get(ALERT_CANCEL), ButtonBar.ButtonData.CANCEL_CLOSE)
.button(I18nUtils.get(ALERT_OK), ButtonBar.ButtonData.OK_DONE)
.build();

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
* Plugin for code completion settings.
*/
public class AutoCompletePlugin implements CompaJPlugin {
private static final String MENU_SETTINGS_EDITOR = "menu.settings.editor";
private static final String MENU_SETTINGS_EDITOR_DISABLE = "menu.settings.editor.autocomplete.disable";
private static final String MENU_SETTINGS_EDITOR_ENABLE = "menu.settings.editor.autocomplete.enable";

public AutoCompletePlugin() {
EventPublisher.INSTANCE.subscribeOn(UiMenuEvent.STARTUP_NAME, this::addSettingsOnStartup);
Expand All @@ -27,16 +30,16 @@ private void addSettingsOnStartup(CompaJEvent compaJEvent) {
updateCodeCompletionStateText(!isEnabled, codeCompletion);
AppPreference.CODE_AUTOCOMPLETE.update(!isEnabled);
});
UiChildPayload autoCompleteSettings = new UiChildPayload("menu.settings.editor",
UiChildPayload autoCompleteSettings = new UiChildPayload(MENU_SETTINGS_EDITOR,
codeCompletion);
EventPublisher.INSTANCE.sendTo(UiMenuEvent.ADD_CHILD(autoCompleteSettings));
}

private void updateCodeCompletionStateText(Boolean isEnabled, MenuItem menuItem) {
if (isEnabled) {
menuItem.setText(I18nUtils.get("menu.settings.editor.autocomplete.disable"));
menuItem.setText(I18nUtils.get(MENU_SETTINGS_EDITOR_DISABLE));
} else {
menuItem.setText(I18nUtils.get("menu.settings.editor.autocomplete.enable"));
menuItem.setText(I18nUtils.get(MENU_SETTINGS_EDITOR_ENABLE));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
public class EpidemicModelPlugin implements CompaJPlugin {

private static final Logger LOGGER = LoggerFactory.getLogger(EpidemicModelPlugin.class);
private static final String MENU_SIMPLE_MODELS = "menu.simple_models";
private static final String MENU_SIMPLE_MODELS_EPIDEMIC = "menu.simple_models.epidemic";

public EpidemicModelPlugin() {
LOGGER.info("Loading: {}", getClass().getName());
Expand All @@ -33,10 +35,10 @@ private void createMenu(CompaJEvent event) {
sisModel.setOnAction(actionEvent -> Compaj.addWorkSpaceWidget(new SISModelWidget()));

MenuItem seirModel = new MenuItem("SEIR");
Menu infectModels = new Menu(I18nUtils.get("menu.simple_models.epidemic"));
Menu infectModels = new Menu(I18nUtils.get(MENU_SIMPLE_MODELS_EPIDEMIC));

infectModels.getItems().addAll(sirModel, sisModel, seirModel);
Menu modelsMenu = new Menu(I18nUtils.get("menu.simple_models"));
Menu modelsMenu = new Menu(I18nUtils.get(MENU_SIMPLE_MODELS));
modelsMenu.getItems().add(infectModels);

EventPublisher.INSTANCE.sendTo(UiMenuEvent.ADD_ROOT(modelsMenu));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
public class LocaleSwitchPlugin implements CompaJPlugin {

private static final Logger LOGGER = LoggerFactory.getLogger(LocaleSwitchPlugin.class);
private static final String MENU_SETTINGS_LANG = "menu.settings.lang";

public LocaleSwitchPlugin() {
LOGGER.info("Loading: {}", getClass().getName());
Expand All @@ -30,7 +31,7 @@ private void createMenu(CompaJEvent event) {
enLang.setOnAction(actionEvent -> I18nUtils.changeLang(Locale.US));
MenuItem ruLang = new MenuItem("Русский");
ruLang.setOnAction(actionEvent -> I18nUtils.changeLang(Locale.forLanguageTag("ru-RU")));
Menu languageMenu = new Menu(I18nUtils.get("menu.settings.lang"));
Menu languageMenu = new Menu(I18nUtils.get(MENU_SETTINGS_LANG));
languageMenu.getItems().addAll(enLang, ruLang);

UiChildPayload uiChildPayload = new UiChildPayload("menu.settings", languageMenu);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ public class EditorTab extends Tab {

private static final String LOG_INFO_PREFIX = "[INFO]";
private static final String LOG_ERROR_PREFIX = "[ERROR]";
private static final String TAB_EDITOR_CONSOLE_TITLE = "tab.editor.console.title";
private static final String TAB_EDITOR_CONSOLE_COMPILATION = "tab.editor.console.compilation";
private static final String TAB_EDITOR_CONSOLE_COMPILATION_OK = "tab.editor.console.compilation.ok";

private final CodeAreaView codeArea;
private final TextArea consoleText;
Expand Down Expand Up @@ -61,7 +64,7 @@ public EditorTab() {
codeArea = new CodeAreaView();
VBox.setVgrow(codeArea, Priority.ALWAYS);
consoleText = new TextArea();
console = new TitledPane(I18nUtils.get("tab.editor.console.title"), consoleText);
console = new TitledPane(I18nUtils.get(TAB_EDITOR_CONSOLE_TITLE), consoleText);
console.setAnimated(false);
console.setExpanded(false);
consoleText.setEditable(false);
Expand Down Expand Up @@ -128,12 +131,12 @@ private void saveFileAction(Event event) {
private void runFileAction(Event event) {
consoleText.clear();
console.setExpanded(true);
logInfo(I18nUtils.get("tab.editor.console.compilation") + " " + getText());
logInfo(I18nUtils.get(TAB_EDITOR_CONSOLE_COMPILATION) + " " + getText());
try {
Object result = Compaj.getInstance().getTranslator().evaluate(codeArea.getText());
WhenConditional.create()
.when(Objects.nonNull(result)).then(() -> log(result.toString()))
.orFinally(() -> logInfo(I18nUtils.get("tab.editor.console.compilation.ok")));
.orFinally(() -> logInfo(I18nUtils.get(TAB_EDITOR_CONSOLE_COMPILATION_OK)));
} catch (Exception e) {
logError(e.getMessage());
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@

public class TerminalTab extends CloseConfirmationTab {

private static final String TAB_TERMINAL_TITLE = "tab.terminal.title";
private static final String TAB_TERMINAL_REPL_CLEAR = "tab.terminal.repl.clear";

private final ReplView replView;

public TerminalTab() {
super(I18nUtils.get("tab.terminal.title"));
super(I18nUtils.get(TAB_TERMINAL_TITLE));
setClosable(false);

Button clear = new Button(I18nUtils.get("tab.terminal.repl.clear"));
Button clear = new Button(I18nUtils.get(TAB_TERMINAL_REPL_CLEAR));
clear.setOnAction(actionEvent -> clear());
ToolBar toolBar = new ToolBar();
toolBar.getItems().add(clear);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ public class WorkSpaceTab extends CloseConfirmationTab {

private final WidgetTreeView widgetTreeView;
private final ScrollPane widgetPane;
private static final String TAB_WORKSPACE_TITLE = "tab.workspace.title";

public WorkSpaceTab() {
super(I18nUtils.get("tab.workspace.title"));
super(I18nUtils.get(TAB_WORKSPACE_TITLE));
setClosable(false);

widgetPane = new ScrollPane();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public class I18nUtils {
private static final ResourceBundle.Control FALLBACK =
ResourceBundle.Control.getNoFallbackControl(ResourceBundle.Control.FORMAT_DEFAULT);
private static final String RESOURCE_NAME = "lang";
private static final String ALERT_INFO = "alert.info";
private static final String MENU_SETTINGS_LAND_CHANGE = "menu.settings.lang.change";
private static Locale currentLocale;
private static ResourceBundle currentBundle;

Expand All @@ -29,8 +31,8 @@ public static void changeLang(Locale locale) {
currentLocale = locale;
loadBundle();
clearCache();
new AlertBuilder(I18nUtils.get("alert.info"), Alert.AlertType.INFORMATION)
.content(I18nUtils.get("menu.settings.lang.change"))
new AlertBuilder(I18nUtils.get(ALERT_INFO), Alert.AlertType.INFORMATION)
.content(I18nUtils.get(MENU_SETTINGS_LAND_CHANGE))
.build()
.show();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,19 @@ public class VariablesTableView extends VBox {

private TableView<Variable> root;
private List<Variable> data;
private static final String TAB_TERMINAL_VARIABLES_VARIABLE = "tab.terminal.variables.variable";
private static final String TAB_TERMINAL_VARIABLES_VALUE = "tab.terminal.variables.value";

public VariablesTableView() {
data = new ArrayList<>();
root = new TableView<>();
root.prefHeightProperty().bind(heightProperty());
root.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
TableColumn<Variable, String> nameColumn =
new TableColumn<>(I18nUtils.get("tab.terminal.variables.variable"));
new TableColumn<>(I18nUtils.get(TAB_TERMINAL_VARIABLES_VARIABLE));
nameColumn.setCellValueFactory(new PropertyValueFactory<>("name"));
TableColumn<Variable, Object> dataColumn =
new TableColumn<>(I18nUtils.get("tab.terminal.variables.value"));
new TableColumn<>(I18nUtils.get(TAB_TERMINAL_VARIABLES_VALUE));
dataColumn.setCellValueFactory(new PropertyValueFactory<>("data"));
root.getColumns().addAll(nameColumn, dataColumn);
root.getItems().addAll(data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,16 @@

public class WidgetTreeView extends TreeView<WorkSpaceWidget> {

private static final String TAB_WORKSPACE_DESC = "tab.workspace.desc";
private static final String TAB_WORKSPACE_TITLE = "tab.workspace.title";
private static final String TAB_WORKSPACE_WIDGET_CONTEXT_EXPORT = "tab.workspace.widget.context.export";
private static final String ALERT_CLOSE = "alert.close";

private TreeItem<WorkSpaceWidget> rootItem;

public WidgetTreeView() {
Label workSpaceDesc = new Label(I18nUtils.get("tab.workspace.desc"));
BaseWidget rootWidget = new BaseWidget(workSpaceDesc, I18nUtils.get("tab.workspace.title"));
Label workSpaceDesc = new Label(I18nUtils.get(TAB_WORKSPACE_DESC));
BaseWidget rootWidget = new BaseWidget(workSpaceDesc, I18nUtils.get(TAB_WORKSPACE_TITLE));
rootItem = new TreeItem<>(rootWidget);
rootItem.setExpanded(true);
setRoot(rootItem);
Expand All @@ -39,14 +44,14 @@ private void treeCellUpdater(WidgetTreeCell treeCell) {
ContextMenu contextMenu =
new ContextMenuBuilder()
.add(
I18nUtils.get("alert.close"),
I18nUtils.get(ALERT_CLOSE),
i -> {
treeCell.getWidget().close();
treeCell.getParentItem().getChildren().remove(treeCell.getCellItem());
getSelectionModel().clearSelection();
})
.add(
I18nUtils.get("tab.workspace.widget.context.export"),
I18nUtils.get(TAB_WORKSPACE_WIDGET_CONTEXT_EXPORT),
i -> {
try {
File f = FileViewUtils.saveFileWindow("PNG Image", "*.png");
Expand Down

0 comments on commit ef08a87

Please sign in to comment.