From ef08a87cf5fa702eee948743cf271d3d1d51cb1d Mon Sep 17 00:00:00 2001 From: innodax Date: Sat, 11 May 2024 15:25:10 +0200 Subject: [PATCH] Replace I18n ids with constants done --- .../compaj/gui/CompaJApplication.java | 21 ++++++++++++------- .../compaj/gui/component/AlertBuilder.java | 16 +++++++++----- .../compaj/gui/plugin/AutoCompletePlugin.java | 9 +++++--- .../gui/plugin/EpidemicModelPlugin.java | 6 ++++-- .../compaj/gui/plugin/LocaleSwitchPlugin.java | 3 ++- .../compaj/gui/tab/EditorTab.java | 9 +++++--- .../compaj/gui/tab/TerminalTab.java | 7 +++++-- .../compaj/gui/tab/WorkSpaceTab.java | 3 ++- .../compaj/gui/util/I18nUtils.java | 6 ++++-- .../compaj/gui/view/VariablesTableView.java | 6 ++++-- .../compaj/gui/view/WidgetTreeView.java | 13 ++++++++---- 11 files changed, 67 insertions(+), 32 deletions(-) diff --git a/gui/src/main/java/tech/hiddenproject/compaj/gui/CompaJApplication.java b/gui/src/main/java/tech/hiddenproject/compaj/gui/CompaJApplication.java index 09706b8..7e1e7cc 100644 --- a/gui/src/main/java/tech/hiddenproject/compaj/gui/CompaJApplication.java +++ b/gui/src/main/java/tech/hiddenproject/compaj/gui/CompaJApplication.java @@ -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); diff --git a/gui/src/main/java/tech/hiddenproject/compaj/gui/component/AlertBuilder.java b/gui/src/main/java/tech/hiddenproject/compaj/gui/component/AlertBuilder.java index 1d1976d..e0434ae 100644 --- a/gui/src/main/java/tech/hiddenproject/compaj/gui/component/AlertBuilder.java +++ b/gui/src/main/java/tech/hiddenproject/compaj/gui/component/AlertBuilder.java @@ -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; /** @@ -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(); } diff --git a/gui/src/main/java/tech/hiddenproject/compaj/gui/plugin/AutoCompletePlugin.java b/gui/src/main/java/tech/hiddenproject/compaj/gui/plugin/AutoCompletePlugin.java index 1a577a9..594b876 100644 --- a/gui/src/main/java/tech/hiddenproject/compaj/gui/plugin/AutoCompletePlugin.java +++ b/gui/src/main/java/tech/hiddenproject/compaj/gui/plugin/AutoCompletePlugin.java @@ -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); @@ -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)); } } diff --git a/gui/src/main/java/tech/hiddenproject/compaj/gui/plugin/EpidemicModelPlugin.java b/gui/src/main/java/tech/hiddenproject/compaj/gui/plugin/EpidemicModelPlugin.java index 2ba711a..b3df9e4 100644 --- a/gui/src/main/java/tech/hiddenproject/compaj/gui/plugin/EpidemicModelPlugin.java +++ b/gui/src/main/java/tech/hiddenproject/compaj/gui/plugin/EpidemicModelPlugin.java @@ -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()); @@ -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)); diff --git a/gui/src/main/java/tech/hiddenproject/compaj/gui/plugin/LocaleSwitchPlugin.java b/gui/src/main/java/tech/hiddenproject/compaj/gui/plugin/LocaleSwitchPlugin.java index a682879..1748a9e 100644 --- a/gui/src/main/java/tech/hiddenproject/compaj/gui/plugin/LocaleSwitchPlugin.java +++ b/gui/src/main/java/tech/hiddenproject/compaj/gui/plugin/LocaleSwitchPlugin.java @@ -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()); @@ -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); diff --git a/gui/src/main/java/tech/hiddenproject/compaj/gui/tab/EditorTab.java b/gui/src/main/java/tech/hiddenproject/compaj/gui/tab/EditorTab.java index 9e2bc01..fba3bfa 100644 --- a/gui/src/main/java/tech/hiddenproject/compaj/gui/tab/EditorTab.java +++ b/gui/src/main/java/tech/hiddenproject/compaj/gui/tab/EditorTab.java @@ -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; @@ -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); @@ -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(); diff --git a/gui/src/main/java/tech/hiddenproject/compaj/gui/tab/TerminalTab.java b/gui/src/main/java/tech/hiddenproject/compaj/gui/tab/TerminalTab.java index 3bb765e..ceb9041 100644 --- a/gui/src/main/java/tech/hiddenproject/compaj/gui/tab/TerminalTab.java +++ b/gui/src/main/java/tech/hiddenproject/compaj/gui/tab/TerminalTab.java @@ -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); diff --git a/gui/src/main/java/tech/hiddenproject/compaj/gui/tab/WorkSpaceTab.java b/gui/src/main/java/tech/hiddenproject/compaj/gui/tab/WorkSpaceTab.java index fec2cc4..d56a273 100644 --- a/gui/src/main/java/tech/hiddenproject/compaj/gui/tab/WorkSpaceTab.java +++ b/gui/src/main/java/tech/hiddenproject/compaj/gui/tab/WorkSpaceTab.java @@ -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(); diff --git a/gui/src/main/java/tech/hiddenproject/compaj/gui/util/I18nUtils.java b/gui/src/main/java/tech/hiddenproject/compaj/gui/util/I18nUtils.java index 10dbf45..dc319b5 100644 --- a/gui/src/main/java/tech/hiddenproject/compaj/gui/util/I18nUtils.java +++ b/gui/src/main/java/tech/hiddenproject/compaj/gui/util/I18nUtils.java @@ -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; @@ -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(); } diff --git a/gui/src/main/java/tech/hiddenproject/compaj/gui/view/VariablesTableView.java b/gui/src/main/java/tech/hiddenproject/compaj/gui/view/VariablesTableView.java index 92fa4f3..8b1363c 100644 --- a/gui/src/main/java/tech/hiddenproject/compaj/gui/view/VariablesTableView.java +++ b/gui/src/main/java/tech/hiddenproject/compaj/gui/view/VariablesTableView.java @@ -16,6 +16,8 @@ public class VariablesTableView extends VBox { private TableView root; private List 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<>(); @@ -23,10 +25,10 @@ public VariablesTableView() { root.prefHeightProperty().bind(heightProperty()); root.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY); TableColumn nameColumn = - new TableColumn<>(I18nUtils.get("tab.terminal.variables.variable")); + new TableColumn<>(I18nUtils.get(TAB_TERMINAL_VARIABLES_VARIABLE)); nameColumn.setCellValueFactory(new PropertyValueFactory<>("name")); TableColumn 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); diff --git a/gui/src/main/java/tech/hiddenproject/compaj/gui/view/WidgetTreeView.java b/gui/src/main/java/tech/hiddenproject/compaj/gui/view/WidgetTreeView.java index 7f5557a..8438913 100644 --- a/gui/src/main/java/tech/hiddenproject/compaj/gui/view/WidgetTreeView.java +++ b/gui/src/main/java/tech/hiddenproject/compaj/gui/view/WidgetTreeView.java @@ -21,11 +21,16 @@ public class WidgetTreeView extends TreeView { + 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 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); @@ -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");