From 26bb7795e84164a2ee4ef8e6d891e0cf54e4ee6c Mon Sep 17 00:00:00 2001 From: Hiroshi Miura Date: Fri, 3 May 2024 15:42:51 +0900 Subject: [PATCH] chore: introduce acceptance test - Use AssertJ-Swing for test framework - Add Sample project folder - Test Menus Signed-off-by: Hiroshi Miura --- build.gradle | 33 ++ gradle/libs.versions.toml | 2 + test-acceptance/data/project/.gitignore | 3 + test-acceptance/data/project/dictionary/.keep | 0 .../data/project/glossary/glossary.txt | 2 + test-acceptance/data/project/omegat.project | 33 ++ .../data/project/omegat/ignored_words.txt | 0 .../data/project/omegat/learned_words.txt | 0 .../data/project/omegat/project_save.tmx | 17 + .../data/project/source/Bundle.properties | 36 ++ test-acceptance/data/project/target/.keep | 0 test-acceptance/data/project/tm/.keep | 0 .../src/org/omegat/TestMainInitializer.java | 20 + .../src/org/omegat/gui/GlossaryEntryTest.java | 81 ++++ .../src/org/omegat/gui/ProjectMenuTest.java | 76 ++++ .../omegat/gui/dialogs/AboutDialogTest.java | 65 +++ .../org/omegat/gui/dialogs/LogDialogTest.java | 47 ++ .../org/omegat/gui/main/DockingDefaults.xml | 59 +++ .../src/org/omegat/gui/main/TestCoreGUI.java | 115 +++++ .../org/omegat/gui/main/TestMainWindow.java | 332 ++++++++++++++ .../gui/main/TestMainWindowMenuHandler.java | 428 ++++++++++++++++++ 21 files changed, 1349 insertions(+) create mode 100644 test-acceptance/data/project/.gitignore create mode 100644 test-acceptance/data/project/dictionary/.keep create mode 100644 test-acceptance/data/project/glossary/glossary.txt create mode 100644 test-acceptance/data/project/omegat.project create mode 100644 test-acceptance/data/project/omegat/ignored_words.txt create mode 100644 test-acceptance/data/project/omegat/learned_words.txt create mode 100644 test-acceptance/data/project/omegat/project_save.tmx create mode 100644 test-acceptance/data/project/source/Bundle.properties create mode 100644 test-acceptance/data/project/target/.keep create mode 100644 test-acceptance/data/project/tm/.keep create mode 100644 test-acceptance/src/org/omegat/TestMainInitializer.java create mode 100644 test-acceptance/src/org/omegat/gui/GlossaryEntryTest.java create mode 100644 test-acceptance/src/org/omegat/gui/ProjectMenuTest.java create mode 100644 test-acceptance/src/org/omegat/gui/dialogs/AboutDialogTest.java create mode 100644 test-acceptance/src/org/omegat/gui/dialogs/LogDialogTest.java create mode 100644 test-acceptance/src/org/omegat/gui/main/DockingDefaults.xml create mode 100644 test-acceptance/src/org/omegat/gui/main/TestCoreGUI.java create mode 100644 test-acceptance/src/org/omegat/gui/main/TestMainWindow.java create mode 100644 test-acceptance/src/org/omegat/gui/main/TestMainWindowMenuHandler.java diff --git a/build.gradle b/build.gradle index a70b5b6e23..e49bebaf3d 100644 --- a/build.gradle +++ b/build.gradle @@ -193,6 +193,13 @@ sourceSets { srcDir 'test/fixtures' } } + testAcceptance { + java { + compileClasspath += main.output + test.output + runtimeClasspath += main.output + test.output + srcDir 'test-acceptance/src' + } + } testIntegration { java { srcDir 'test-integration/src' @@ -204,6 +211,8 @@ configurations { all [testRuntime, testCompile]*.exclude group: 'org.languagetool', module: 'language-all' testIntegrationImplementation.extendsFrom implementation + testAcceptanceImplementation.extendsFrom testImplementation + testAcceptanceRuntime.extendsFrom testRuntime jaxb genMac } @@ -332,6 +341,7 @@ dependencies { testFixturesApi(libs.slf4j.api) testFixturesImplementation(libs.commons.io) testFixturesImplementation(libs.omegat.vldocking) + testFixturesImplementation(libs.assertj.swing.junit) testImplementation(libs.xmlunit.legacy) // LanguageTool unit tests exercise these languages @@ -352,6 +362,14 @@ dependencies { // genMac only genMac(libs.omegat.appbundler) + testAcceptanceImplementation sourceSets.main.output + testAcceptanceImplementation(libs.commons.io) + testAcceptanceImplementation(libs.slf4j.jdk14) + testAcceptanceImplementation(libs.slf4j.format.jdk14) + testAcceptanceImplementation(testFixtures(project.rootProject)) + testAcceptanceImplementation(libs.assertj.swing.junit) + testAcceptanceImplementation(libs.bundles.jackson) + testIntegrationImplementation sourceSets.main.output, sourceSets.test.output testIntegrationImplementation(testFixtures(project.rootProject)) testIntegrationRuntimeOnly(libs.slf4j.jdk14) @@ -1580,6 +1598,21 @@ tasks.register('testOnJava21', Test) { group = 'verification' } +tasks.register('testAcceptance', Test) { + description = 'Run Acceptance GUI test' + group = 'verification' + javaLauncher = javaToolchains.launcherFor { + languageVersion = JavaLanguageVersion.of(17) + vendor = JvmVendorSpec.ADOPTIUM + } + jvmArgs(["--add-opens", "java.desktop/sun.awt.X11=ALL-UNNAMED", + "--add-opens", "java.base/java.util=ALL-UNNAMED"]) + testClassesDirs = sourceSets.testAcceptance.output.classesDirs + classpath = sourceSets.testAcceptance.runtimeClasspath + systemProperties = System.properties + shouldRunAfter(tasks.test) +} + ext.mavenStyleVersion = version.replace('_', '-') publishing { diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index c995c787c8..17e1fde4ee 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -49,6 +49,7 @@ jna = "5.13.0" jfa = "1.2.0" tipoftheday = "0.4.4" flatlaf="3.4.1" +assertj_swing_junit = "4.0.0-beta-1" [libraries] slf4j-api = {group = "org.slf4j", name = "slf4j-api", version.ref = "slf4j"} @@ -132,6 +133,7 @@ jna = {group = "net.java.dev.jna", name = "jna-platform", version.ref = "jna"} jfa = {group = "de.jangassen", name = "jfa", version.ref = "jfa"} flatlaf = {group = "com.formdev", name = "flatlaf", version.ref = "flatlaf"} language-detector = {group = "org.omegat", name = "language-detector", version.ref = "languagedetector"} +assertj_swing_junit = {group = "tokyo.northside", name = "assertj-swing-junit", version.ref = "assertj_swing_junit"} [bundles] groovy = ["groovy-jsr223", "groovy-dateutil", "groovy-json", "groovy-xml", "groovy-swing", "groovy-templates", "ivy"] diff --git a/test-acceptance/data/project/.gitignore b/test-acceptance/data/project/.gitignore new file mode 100644 index 0000000000..2f3bf92e42 --- /dev/null +++ b/test-acceptance/data/project/.gitignore @@ -0,0 +1,3 @@ +project_stats.txt +project_stats.json +*.bak diff --git a/test-acceptance/data/project/dictionary/.keep b/test-acceptance/data/project/dictionary/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test-acceptance/data/project/glossary/glossary.txt b/test-acceptance/data/project/glossary/glossary.txt new file mode 100644 index 0000000000..af39f3a7f4 --- /dev/null +++ b/test-acceptance/data/project/glossary/glossary.txt @@ -0,0 +1,2 @@ +# Glossary in tab-separated format -*- coding: utf-8 -*- +Introduction 紹介 diff --git a/test-acceptance/data/project/omegat.project b/test-acceptance/data/project/omegat.project new file mode 100644 index 0000000000..df72303659 --- /dev/null +++ b/test-acceptance/data/project/omegat.project @@ -0,0 +1,33 @@ + + + + __DEFAULT__ + + **/.svn/** + **/CVS/** + **/.cvs/** + **/.git/** + **/.hg/** + **/.repositories/** + **/desktop.ini + **/Thumbs.db + **/.DS_Store + **/~$* + + __DEFAULT__ + __DEFAULT__ + __DEFAULT__ + __DEFAULT__ + __DEFAULT__ + __DEFAULT__ + + en + fr + org.omegat.tokenizer.LuceneEnglishTokenizer + org.omegat.tokenizer.LuceneFrenchTokenizer + false + true + true + + + diff --git a/test-acceptance/data/project/omegat/ignored_words.txt b/test-acceptance/data/project/omegat/ignored_words.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test-acceptance/data/project/omegat/learned_words.txt b/test-acceptance/data/project/omegat/learned_words.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test-acceptance/data/project/omegat/project_save.tmx b/test-acceptance/data/project/omegat/project_save.tmx new file mode 100644 index 0000000000..ae4a8b233b --- /dev/null +++ b/test-acceptance/data/project/omegat/project_save.tmx @@ -0,0 +1,17 @@ + + + +
+ + + + + Birds in Oregon + + + Birds in Oregon + + + + + diff --git a/test-acceptance/data/project/source/Bundle.properties b/test-acceptance/data/project/source/Bundle.properties new file mode 100644 index 0000000000..47ddb2e48c --- /dev/null +++ b/test-acceptance/data/project/source/Bundle.properties @@ -0,0 +1,36 @@ +# +# OmegaT - Computer Assisted Translation (CAT) tool +# with fuzzy matching, translation memory, keyword search, +# glossaries, and translation leveraging into updated projects. +# +# Copyright (C) 2023 Hiroshi Miura +# Home page: https://www.omegat.org/ +# Support center: https://omegat.org/support +# +# This file is part of OmegaT. +# +# OmegaT is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# OmegaT is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +MT_ENGINE_APERTIUM=Apertium + +MT_JSON_ERROR=Error while reading MT results + +APERTIUM_ERROR=Error {0}: {1} +APERTIUM_CUSTOM_SERVER_LABEL=Connect to custom server instead of apertium.org +APERTIUM_CUSTOM_SERVER_URL_LABEL=Custom server URL +APERTIUM_CUSTOM_SERVER_KEY_LABEL=API key (optional) +APERTIUM_CUSTOM_SERVER_NOTFOUND=Unable to connect to server. Ensure the server URL is correct. +APERTIUM_CUSTOM_SERVER_INVALID=The server is not a valid Apertium server. Ensure the URL is correct. +APERTIUM_MARKUNKNOWN_LABEL=Mark unknown words + diff --git a/test-acceptance/data/project/target/.keep b/test-acceptance/data/project/target/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test-acceptance/data/project/tm/.keep b/test-acceptance/data/project/tm/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test-acceptance/src/org/omegat/TestMainInitializer.java b/test-acceptance/src/org/omegat/TestMainInitializer.java new file mode 100644 index 0000000000..d4d59676cd --- /dev/null +++ b/test-acceptance/src/org/omegat/TestMainInitializer.java @@ -0,0 +1,20 @@ +package org.omegat; + +import javax.swing.UIManager; + +import org.omegat.filters2.master.PluginUtils; + +public final class TestMainInitializer { + + private TestMainInitializer() { + } + + public static void initClassloader() { + ClassLoader cl = ClassLoader.getSystemClassLoader(); + MainClassLoader mainClassLoader = (cl instanceof MainClassLoader) ? (MainClassLoader) cl + : new MainClassLoader(cl); + PluginUtils.getThemePluginJars().forEach(mainClassLoader::add); + UIManager.put("ClassLoader", mainClassLoader); + } + +} diff --git a/test-acceptance/src/org/omegat/gui/GlossaryEntryTest.java b/test-acceptance/src/org/omegat/gui/GlossaryEntryTest.java new file mode 100644 index 0000000000..96f7b1a9c0 --- /dev/null +++ b/test-acceptance/src/org/omegat/gui/GlossaryEntryTest.java @@ -0,0 +1,81 @@ +package org.omegat.gui; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.awt.event.KeyEvent; +import java.io.File; +import java.nio.file.Files; + +import javax.swing.SwingUtilities; + +import org.apache.commons.io.FileUtils; +import org.junit.Test; + +import org.omegat.gui.dialogs.CreateGlossaryEntry; +import org.omegat.gui.glossary.GlossaryTextArea; +import org.omegat.gui.main.BaseMainWindowMenu; +import org.omegat.gui.main.ProjectUICommands; +import org.omegat.gui.main.TestCoreGUI; +import org.omegat.util.Preferences; + +public class GlossaryEntryTest extends TestCoreGUI { + + private File tmpDir; + + /** + * Test case to create glossary entry and see a result. + * + * @throws Exception + */ + @Test + public void testOpenGlossaryEntryDialog() throws Exception { + // 0. Prepare project folder + tmpDir = Files.createTempDirectory("omegat-sample-project-").toFile(); + File projSrc = new File("test-acceptance/data/project/"); + FileUtils.copyDirectory(projSrc, tmpDir); + FileUtils.forceDeleteOnExit(tmpDir); + // 1. Prepare preference for the test; + // * OmegaT doesn't show a file list dialog on a project load event. + // * Glossary sort order preference + Preferences.setPreference(Preferences.PROJECT_FILES_SHOW_ON_LOAD, false); + Preferences.setPreference(Preferences.GLOSSARY_SORT_BY_LENGTH, false); + Preferences.setPreference(Preferences.GLOSSARY_SORT_BY_SRC_LENGTH, false); + assertFalse(Preferences.isPreferenceDefault(Preferences.PROJECT_FILES_SHOW_ON_LOAD, true)); + // 2. Open a sample project. + SwingUtilities.invokeAndWait(() -> ProjectUICommands.projectOpen(tmpDir)); + // 3. Operate Glossary preference from menu. + Preferences.setPreference(Preferences.GLOSSARY_STEMMING, true); + window.menuItem(BaseMainWindowMenu.OPTIONS_MENU).click(); + window.menuItem(BaseMainWindowMenu.OPTIONS_GLOSSARY_SUBMENU).click(); + assertTrue(window.menuItem(BaseMainWindowMenu.OPTIONS_GLOSSARY_FUZZY_MATCHING_CHECKBOX_MENUITEM) + .target().getModel().isSelected()); + window.menuItem(BaseMainWindowMenu.OPTIONS_GLOSSARY_FUZZY_MATCHING_CHECKBOX_MENUITEM).click(); + // 4. toggle options > glossary menu + window.menuItem(BaseMainWindowMenu.OPTIONS_MENU).click(); + window.menuItem(BaseMainWindowMenu.OPTIONS_GLOSSARY_SUBMENU).click(); + assertFalse(window.menuItem(BaseMainWindowMenu.OPTIONS_GLOSSARY_FUZZY_MATCHING_CHECKBOX_MENUITEM) + .target().getModel().isSelected()); + // 5. Click menu Edit > Create glossary menu items. + window.menuItem(BaseMainWindowMenu.EDIT_MENU).click(); + window.menuItem(BaseMainWindowMenu.EDIT_CREATE_GLOSSARY_MENUITEM).click(); + // 6. Check Create glossary dialog visible + window.dialog(CreateGlossaryEntry.DIALOG_NAME).requireVisible(); + // 7. Enter glossary keyword and translation in the field + window.dialog(CreateGlossaryEntry.DIALOG_NAME).textBox(CreateGlossaryEntry.SOURCE_TEXT_FIELD) + .enterText("Apertium"); + window.dialog(CreateGlossaryEntry.DIALOG_NAME).textBox(CreateGlossaryEntry.TARGET_TEXT_FIELD) + .enterText("Translation Engine"); + // 8. Click a OK button + window.dialog(CreateGlossaryEntry.DIALOG_NAME).button(CreateGlossaryEntry.OK_BUTTON).click(); + // 9. Enforce refresh glossary pane + GlossaryTextArea glossaryTextArea = ((GlossaryTextArea) (window + .textBox(GlossaryTextArea.TEXTPANE_NAME).target())); + glossaryTextArea.refresh(); + // 10. Wait showing a search result during some operation + window.textBox(GlossaryTextArea.TEXTPANE_NAME).rightClick(); + window.pressKey(KeyEvent.VK_ESCAPE); + // Check the glossary pane shown in the pane + assertFalse(glossaryTextArea.getDisplayedEntries().isEmpty()); + } +} diff --git a/test-acceptance/src/org/omegat/gui/ProjectMenuTest.java b/test-acceptance/src/org/omegat/gui/ProjectMenuTest.java new file mode 100644 index 0000000000..2fc3601c75 --- /dev/null +++ b/test-acceptance/src/org/omegat/gui/ProjectMenuTest.java @@ -0,0 +1,76 @@ +/************************************************************************** + OmegaT - Computer Assisted Translation (CAT) tool + with fuzzy matching, translation memory, keyword search, + glossaries, and translation leveraging into updated projects. + + Copyright (C) 2024 Hiroshi Miura + Home page: https://www.omegat.org/ + Support center: https://omegat.org/support + + This file is part of OmegaT. + + OmegaT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OmegaT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + **************************************************************************/ +package org.omegat.gui; + +import static org.junit.Assert.assertFalse; + +import java.io.File; +import java.nio.file.Files; + +import org.junit.Test; + +import org.omegat.core.Core; +import org.omegat.gui.dialogs.NewProjectFileChooser; +import org.omegat.gui.main.BaseMainWindowMenu; +import org.omegat.gui.main.TestCoreGUI; + +public class ProjectMenuTest extends TestCoreGUI { + + File tempDir; + + @Override + protected void onSetUp() throws Exception { + super.onSetUp(); + tempDir = Files.createTempDirectory("omegat").toFile(); + } + + /** + * Test project menus. + */ + @Test + public void testNewProject() { + window.requireTitle("OmegaT 6.1.0"); + // 2. click menu Project > new project + window.menuItem(BaseMainWindowMenu.PROJECT_MENU).click(); + window.menuItem(BaseMainWindowMenu.PROJECT_NEW_MENUITEM).click(); + window.fileChooser(NewProjectFileChooser.DIALOG_NAME).requireEnabled(); + window.fileChooser().selectFile(tempDir); + window.fileChooser().approve(); + assertFalse(Core.getProject().isProjectLoaded()); + /* + * window.dialog(Timeout.timeout(30000L)).requireVisible(); + * window.dialog(ProjectPropertiesDialog.DIALOG_NAME).requireModal(); + * window.dialog(ProjectPropertiesDialog.DIALOG_NAME).button( + * ProjectPropertiesDialog.OK_BUTTON_NAME).click(); + * assertTrue(Core.getProject().isProjectLoaded()); + */ + // 3. select project > Exit menu. + window.menuItem(BaseMainWindowMenu.PROJECT_MENU).click(); + window.menuItem(BaseMainWindowMenu.PROJECT_EXIT_MENUITEM).click(); + window.requireNotVisible(); + window.requireDisabled(); + } + +} diff --git a/test-acceptance/src/org/omegat/gui/dialogs/AboutDialogTest.java b/test-acceptance/src/org/omegat/gui/dialogs/AboutDialogTest.java new file mode 100644 index 0000000000..4176399304 --- /dev/null +++ b/test-acceptance/src/org/omegat/gui/dialogs/AboutDialogTest.java @@ -0,0 +1,65 @@ +/************************************************************************** + OmegaT - Computer Assisted Translation (CAT) tool + with fuzzy matching, translation memory, keyword search, + glossaries, and translation leveraging into updated projects. + + Copyright (C) 2024 Hiroshi Miura + Home page: https://www.omegat.org/ + Support center: https://omegat.org/support + + This file is part of OmegaT. + + OmegaT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OmegaT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + **************************************************************************/ + +package org.omegat.gui.dialogs; + +import static org.junit.Assert.assertTrue; + +import java.util.regex.Pattern; + +import org.junit.Test; + +import org.omegat.gui.main.BaseMainWindowMenu; +import org.omegat.gui.main.TestCoreGUI; +import org.omegat.util.OStrings; + +public class AboutDialogTest extends TestCoreGUI { + + @Test + public void testAboutDialog() throws InterruptedException { + window.menuItem(BaseMainWindowMenu.HELP_MENU).click(); + window.menuItem(BaseMainWindowMenu.HELP_ABOUT_MENUITEM).click(); + // Check about dialog + window.dialog(AboutDialog.DIALOG_NAME).requireModal(); + Pattern pattern = Pattern.compile(OStrings.getApplicationDisplayName() + + "\\s+\\S+\\s+\\d+\\.\\d+\\.\\d+(\\s+)?\\([@0-9A-Fa-fv]+\\)"); + window.dialog(AboutDialog.DIALOG_NAME).label(AboutDialog.VERSION_LABEL_NAME).requireText(pattern); + // String aboutMessage = + // window.dialog(AboutDialog.DIALOG_NAME).textBox().text(); + String javaVersion = window.dialog(AboutDialog.DIALOG_NAME).label(AboutDialog.JAVA_VERSION_LABEL_NAME) + .text(); + assertTrue(javaVersion.contains(System.getProperty("java.version"))); + // check license dialog + window.dialog(AboutDialog.DIALOG_NAME).button(AboutDialog.LICENSE_BUTTON_NAME).click(); + window.dialog(LicenseDialog.DIALOG_NAME).requireVisible(); + window.dialog(LicenseDialog.DIALOG_NAME).requireModal(); + assertTrue(window.dialog(LicenseDialog.DIALOG_NAME).textBox(LicenseDialog.LICENSE_TEXT_PANE_NAME) + .text().contains("=========")); + window.dialog(LicenseDialog.DIALOG_NAME).button(LicenseDialog.OK_BUTTON_NAME).click(); + // close about dialog + window.dialog(AboutDialog.DIALOG_NAME).button(AboutDialog.OK_BUTTON_NAME).click(); + } + +} diff --git a/test-acceptance/src/org/omegat/gui/dialogs/LogDialogTest.java b/test-acceptance/src/org/omegat/gui/dialogs/LogDialogTest.java new file mode 100644 index 0000000000..f539fffc18 --- /dev/null +++ b/test-acceptance/src/org/omegat/gui/dialogs/LogDialogTest.java @@ -0,0 +1,47 @@ +/************************************************************************** + OmegaT - Computer Assisted Translation (CAT) tool + with fuzzy matching, translation memory, keyword search, + glossaries, and translation leveraging into updated projects. + + Copyright (C) 2024 Hiroshi Miura + Home page: https://www.omegat.org/ + Support center: https://omegat.org/support + + This file is part of OmegaT. + + OmegaT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OmegaT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + **************************************************************************/ + +package org.omegat.gui.dialogs; + +import static org.junit.Assert.assertFalse; + +import org.junit.Test; + +import org.omegat.gui.main.BaseMainWindowMenu; +import org.omegat.gui.main.TestCoreGUI; + +public class LogDialogTest extends TestCoreGUI { + + @Test + public void testLogDialog() { + window.menuItem(BaseMainWindowMenu.HELP_MENU).click(); + window.menuItem(BaseMainWindowMenu.HELP_LOG_MENUITEM).click(); + window.dialog(LogDialog.DIALOG_NAME).requireModal(); + assertFalse( + window.dialog(LogDialog.DIALOG_NAME).textBox(LogDialog.LOG_TEXTPANE_NAME).text().isEmpty()); + window.dialog(LogDialog.DIALOG_NAME).button(LogDialog.OK_BUTTON_NAME).click(); + } + +} diff --git a/test-acceptance/src/org/omegat/gui/main/DockingDefaults.xml b/test-acceptance/src/org/omegat/gui/main/DockingDefaults.xml new file mode 100644 index 0000000000..1df3d58856 --- /dev/null +++ b/test-acceptance/src/org/omegat/gui/main/DockingDefaults.xml @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test-acceptance/src/org/omegat/gui/main/TestCoreGUI.java b/test-acceptance/src/org/omegat/gui/main/TestCoreGUI.java new file mode 100644 index 0000000000..e5a1bf2992 --- /dev/null +++ b/test-acceptance/src/org/omegat/gui/main/TestCoreGUI.java @@ -0,0 +1,115 @@ +/************************************************************************** + OmegaT - Computer Assisted Translation (CAT) tool + with fuzzy matching, translation memory, keyword search, + glossaries, and translation leveraging into updated projects. + + Copyright (C) 2024 Hiroshi Miura + Home page: https://www.omegat.org/ + Support center: https://omegat.org/support + + This file is part of OmegaT. + + OmegaT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OmegaT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + **************************************************************************/ +package org.omegat.gui.main; + +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Collections; + +import javax.swing.JFrame; +import javax.swing.SwingUtilities; + +import org.apache.commons.io.FileUtils; +import org.assertj.swing.edt.GuiActionRunner; +import org.assertj.swing.fixture.FrameFixture; +import org.assertj.swing.junit.testcase.AssertJSwingJUnitTestCase; + +import org.omegat.TestMainInitializer; +import org.omegat.core.Core; +import org.omegat.core.CoreEvents; +import org.omegat.core.TestCoreInitializer; +import org.omegat.core.data.NotLoadedProject; +import org.omegat.core.threads.IAutoSave; +import org.omegat.filters2.master.FilterMaster; +import org.omegat.filters2.master.PluginUtils; +import org.omegat.util.Preferences; +import org.omegat.util.RuntimePreferences; +import org.omegat.util.gui.UIDesignManager; + +public abstract class TestCoreGUI extends AssertJSwingJUnitTestCase { + + protected FrameFixture window; + protected JFrame frame; + + @Override + protected void onSetUp() throws Exception { + Path tmp = Files.createTempDirectory("omegat"); + FileUtils.forceDeleteOnExit(tmp.toFile()); + RuntimePreferences.setConfigDir(tmp.toString()); + TestMainInitializer.initClassloader(); + // same order as Main.main + Preferences.init(); + PluginUtils.loadPlugins(Collections.emptyMap()); + FilterMaster.setFilterClasses(PluginUtils.getFilterClasses()); + Preferences.initFilters(); + Preferences.initSegmentation(); + // + frame = GuiActionRunner.execute(() -> { + Core.setProject(new NotLoadedProject()); + UIDesignManager.initialize(); + TestMainWindow mw = new TestMainWindow(TestMainWindowMenuHandler.class); + TestCoreInitializer.initMainWindow(mw); + TestCoreInitializer.initAutoSave(autoSave); + + CoreEvents.fireApplicationStartup(); + SwingUtilities.invokeLater(() -> { + // setVisible can't be executed directly, because we need to + // call all application startup listeners for initialize UI + Core.getMainWindow().getApplicationFrame().setVisible(true); + }); + return mw.getApplicationFrame(); + }); + + window = new FrameFixture(robot(), frame); + window.show(); + } + + static IAutoSave autoSave = new IAutoSave() { + public void enable() { + } + + public void disable() { + } + }; + + static class TestMainWindowMenu extends BaseMainWindowMenu { + + TestMainWindowMenu(IMainWindow mainWindow, BaseMainWindowMenuHandler mainWindowMenuHandler) { + super(mainWindow, mainWindowMenuHandler); + initComponents(); + } + + @Override + void createMenuBar() { + mainMenu.add(projectMenu); + mainMenu.add(editMenu); + mainMenu.add(gotoMenu); + mainMenu.add(viewMenu); + mainMenu.add(toolsMenu); + mainMenu.add(optionsMenu); + mainMenu.add(helpMenu); + } + } +} diff --git a/test-acceptance/src/org/omegat/gui/main/TestMainWindow.java b/test-acceptance/src/org/omegat/gui/main/TestMainWindow.java new file mode 100644 index 0000000000..0ec46e9cbd --- /dev/null +++ b/test-acceptance/src/org/omegat/gui/main/TestMainWindow.java @@ -0,0 +1,332 @@ +/************************************************************************** + OmegaT - Computer Assisted Translation (CAT) tool + with fuzzy matching, translation memory, keyword search, + glossaries, and translation leveraging into updated projects. + + Copyright (C) 2024 Hiroshi Miura + Home page: https://www.omegat.org/ + Support center: https://omegat.org/support + + This file is part of OmegaT. + + OmegaT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OmegaT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + **************************************************************************/ +package org.omegat.gui.main; + +import java.awt.BorderLayout; +import java.awt.Cursor; +import java.awt.Dimension; +import java.awt.Font; +import java.awt.GraphicsEnvironment; +import java.awt.HeadlessException; +import java.awt.Rectangle; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import javax.swing.JFrame; +import javax.swing.SwingUtilities; +import javax.swing.WindowConstants; +import javax.swing.plaf.FontUIResource; + +import tokyo.northside.logging.ILogger; +import tokyo.northside.logging.LoggerFactory; + +import org.omegat.core.Core; +import org.omegat.core.CoreEvents; +import org.omegat.core.events.IApplicationEventListener; +import org.omegat.core.events.IProjectEventListener; +import org.omegat.gui.search.SearchWindowController; +import org.omegat.util.Log; +import org.omegat.util.OConsts; +import org.omegat.util.OStrings; +import org.omegat.util.Preferences; +import org.omegat.util.gui.FontUtil; +import org.omegat.util.gui.StaticUIUtils; +import org.omegat.util.gui.UIDesignManager; +import org.omegat.util.gui.UIScale; + +import com.vlsolutions.swing.docking.Dockable; +import com.vlsolutions.swing.docking.DockingDesktop; + +@SuppressWarnings("serial") +class TestMainWindow implements IMainWindow { + private final JFrame applicationFrame; + private FontUIResource font; + private final ILogger logger = LoggerFactory.getLogger(TestMainWindow.class, + OStrings.getResourceBundle()); + public final BaseMainWindowMenu menu; + public final DockingDesktop desktop; + + /** + * Set of all open search windows. + */ + private final List searches = new ArrayList<>(); + + TestMainWindow(Class mainWindowMenuHandler) throws IOException { + applicationFrame = new JFrame(); + applicationFrame.setPreferredSize(new Dimension(1920, 1040)); + font = FontUtil.getScaledFont(); + try { + BaseMainWindowMenuHandler handler = mainWindowMenuHandler + .getDeclaredConstructor(IMainWindow.class).newInstance(this); + menu = new TestCoreGUI.TestMainWindowMenu(this, handler); + } catch (Exception e) { + throw new RuntimeException(); + } + applicationFrame.setJMenuBar(menu.mainMenu); + applicationFrame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); + + desktop = new DockingDesktop(); + desktop.addDockableStateWillChangeListener(event -> { + if (event.getFutureState().isClosed()) { + event.cancel(); + } + }); + applicationFrame.getContentPane().add(desktop, BorderLayout.CENTER); + MainWindowStatusBar mainWindowStatusBar = new MainWindowStatusBar(); + applicationFrame.getContentPane().add(mainWindowStatusBar, BorderLayout.SOUTH); + + StaticUIUtils.setWindowIcon(applicationFrame); + + updateTitle(); + + CoreEvents.registerProjectChangeListener(eventType -> { + updateTitle(); + if (eventType == IProjectEventListener.PROJECT_CHANGE_TYPE.CLOSE) { + closeSearchWindows(); + } + }); + + CoreEvents.registerApplicationEventListener(new IApplicationEventListener() { + public void onApplicationStartup() { + initializeScreenLayout(); + resetDesktopLayout(); + // Ensure any "closed" Dockables are visible. These can be newly + // added panes not included in an older layout file, or e.g. + // panes + // installed by plugins. + UIDesignManager.ensureDockablesVisible(desktop); + UIDesignManager.removeUnusedMenuSeparators(menu.getOptionsMenu().getPopupMenu()); + } + + public void onApplicationShutdown() { + } + }); + + UIScale.addPropertyChangeListener(evt -> CoreEvents.fireFontChanged(FontUtil.getScaledFont())); + CoreEvents.registerFontChangedEventListener( + newFont -> font = (newFont instanceof FontUIResource) ? (FontUIResource) newFont + : new FontUIResource(newFont)); + + // Set up prompt to reload if segmentation or filters settings change + Preferences.addPropertyChangeListener(evt -> { + if (Core.getProject().isProjectLoaded()) { + String prop = evt.getPropertyName(); + if (prop.equals(Preferences.PROPERTY_SRX) + && Core.getProject().getProjectProperties().getProjectSRX() == null) { + SwingUtilities.invokeLater(ProjectUICommands::promptReload); + } else if (prop.equals(Preferences.PROPERTY_FILTERS) + && Core.getProject().getProjectProperties().getProjectFilters() == null) { + SwingUtilities.invokeLater(ProjectUICommands::promptReload); + } + } + }); + + applicationFrame.pack(); + } + + /** + * Sets the title of the main window appropriately + */ + private void updateTitle() { + String s = OStrings.getDisplayNameAndVersion(); + applicationFrame.setTitle(s); + } + + @Override + public void addSearchWindow(final SearchWindowController newSearchWindow) { + newSearchWindow.addWindowListener(new WindowAdapter() { + @Override + public void windowClosed(WindowEvent e) { + removeSearchWindow(newSearchWindow); + } + }); + synchronized (searches) { + searches.add(newSearchWindow); + } + } + + @Override + public List getSearchWindows() { + return Collections.unmodifiableList(searches); + } + + private void removeSearchWindow(SearchWindowController searchWindow) { + synchronized (searches) { + searches.remove(searchWindow); + } + } + + private void closeSearchWindows() { + synchronized (searches) { + // dispose other windows + for (SearchWindowController sw : searches) { + sw.dispose(); + } + searches.clear(); + } + } + + /** + * Initialize the size of OmegaT window, then load the layout prefs. + */ + public void initializeScreenLayout() { + /* + * (23dec22) Set a reasonable default window size assuming a + * standard"pro" laptop resolution of 1920x1080. Smaller screens do not + * need to be considered since OmegaT will just use the whole window + * size in such cases. + */ + + // Check the real available space accounting for macOS DOCK, Windows + // Toolbar, etc. + Rectangle localAvailableSpace = GraphicsEnvironment.getLocalGraphicsEnvironment() + .getMaximumWindowBounds(); + int screenWidth = localAvailableSpace.width; + int screenHeight = localAvailableSpace.height; + int omegatWidth = OConsts.OMEGAT_WINDOW_WIDTH; + int omegatHeight = OConsts.OMEGAT_WINDOW_HEIGHT; + + if (omegatWidth > screenWidth) { + omegatWidth = screenWidth; + } + + if (omegatHeight > screenHeight) { + omegatHeight = screenHeight; + } + + // Attempt to center the OmegaT main window on the screen + int omegatLeftPosition = (screenWidth - omegatWidth) / 2; + + Rectangle defaultWindowSize = new Rectangle(omegatLeftPosition, 0, omegatWidth, omegatHeight); + applicationFrame.setBounds(defaultWindowSize); + } + + @Override + public JFrame getApplicationFrame() { + return applicationFrame; + } + + @Override + public void lockUI() { + } + + @Override + public void unlockUI() { + } + + @Override + public Font getApplicationFont() { + return font; + } + + @Override + public void showStatusMessageRB(final String messageKey, final Object... params) { + } + + @Override + public void showTimedStatusMessageRB(final String messageKey, final Object... params) { + } + + @Override + public void showProgressMessage(final String messageText) { + } + + @Override + public void showLengthMessage(final String messageText) { + } + + @Override + public void showLockInsertMessage(final String messageText, final String toolTip) { + } + + @Override + public void displayWarningRB(final String warningKey, final Object... params) { + logger.atWarn().setMessageRB(warningKey).addArgument(params).log(); + } + + @Override + public void displayWarningRB(final String warningKey, final String supercedesKey, + final Object... params) { + } + + @Override + public void displayErrorRB(final Throwable ex, final String errorKey, final Object... params) { + } + + @Override + public void showErrorDialogRB(final String title, final String message, final Object... args) { + } + + @Override + public int showConfirmDialog(final Object message, final String title, final int optionType, + final int messageType) throws HeadlessException { + return 0; + } + + @Override + public void showMessageDialog(final String message) { + } + + /** + * {@inheritDoc} + */ + public void addDockable(Dockable pane) { + desktop.addDockable(pane); + } + + @Override + public void setCursor(final Cursor cursor) { + applicationFrame.setCursor(cursor); + } + + @Override + public Cursor getCursor() { + return applicationFrame.getCursor(); + } + + @Override + public IMainMenu getMainMenu() { + return menu; + } + + @Override + public DockingDesktop getDesktop() { + return desktop; + } + + @Override + public void resetDesktopLayout() { + try (InputStream in = MainWindowUI.class.getResourceAsStream("DockingDefaults.xml")) { + desktop.readXML(in); + } catch (Exception e) { + Log.log(e); + } + } +} diff --git a/test-acceptance/src/org/omegat/gui/main/TestMainWindowMenuHandler.java b/test-acceptance/src/org/omegat/gui/main/TestMainWindowMenuHandler.java new file mode 100644 index 0000000000..005590fc57 --- /dev/null +++ b/test-acceptance/src/org/omegat/gui/main/TestMainWindowMenuHandler.java @@ -0,0 +1,428 @@ +/************************************************************************** + OmegaT - Computer Assisted Translation (CAT) tool + with fuzzy matching, translation memory, keyword search, + glossaries, and translation leveraging into updated projects. + + Copyright (C) 2024 Hiroshi Miura + Home page: https://www.omegat.org/ + Support center: https://omegat.org/support + + This file is part of OmegaT. + + OmegaT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OmegaT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + **************************************************************************/ +package org.omegat.gui.main; + +import java.awt.Component; +import java.awt.KeyboardFocusManager; +import java.io.File; +import java.util.List; + +import javax.swing.JDialog; +import javax.swing.text.JTextComponent; + +import org.omegat.core.Core; +import org.omegat.core.data.SourceTextEntry; +import org.omegat.core.data.TMXEntry; +import org.omegat.core.search.SearchMode; +import org.omegat.gui.dialogs.AboutDialog; +import org.omegat.gui.dialogs.LogDialog; +import org.omegat.gui.editor.EditorUtils; +import org.omegat.gui.editor.SegmentExportImport; +import org.omegat.gui.exttrans.MachineTranslationInfo; +import org.omegat.gui.filelist.IProjectFilesList; +import org.omegat.gui.filters2.FiltersCustomizerController; +import org.omegat.gui.preferences.PreferencesWindowController; +import org.omegat.gui.preferences.view.EditingBehaviorController; +import org.omegat.gui.search.SearchWindowController; +import org.omegat.gui.segmentation.SegmentationCustomizerController; +import org.omegat.gui.stat.StatisticsWindow; +import org.omegat.util.Log; +import org.omegat.util.Preferences; +import org.omegat.util.StaticUtils; +import org.omegat.util.StringUtil; + +public class TestMainWindowMenuHandler extends BaseMainWindowMenuHandler { + + IMainWindow mainWindow; + + public TestMainWindowMenuHandler(IMainWindow mw) { + this.mainWindow = mw; + } + + /** + * Create a new project. + */ + public void projectNewMenuItemActionPerformed() { + ProjectUICommands.projectCreate(); + } + + @Override + public void projectExitMenuItemActionPerformed() { + mainWindow.getApplicationFrame().setVisible(false); + mainWindow.getApplicationFrame().setEnabled(false); + } + + public void viewFileListMenuItemActionPerformed() { + IProjectFilesList projWin = Core.getProjectFilesList(); + if (projWin == null) { + return; + } + projWin.setActive(!projWin.isActive()); + } + + public void editUndoMenuItemActionPerformed() { + Component focused = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner(); + if (focused == Core.getNotes()) { + Core.getNotes().undo(); + } else { + Core.getEditor().undo(); + } + } + + public void editRedoMenuItemActionPerformed() { + Component focused = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner(); + if (focused == Core.getNotes()) { + Core.getNotes().redo(); + } else { + Core.getEditor().redo(); + } + } + + public void editOverwriteTranslationMenuItemActionPerformed() { + ProjectUICommands.doRecycleTrans(); + } + + public void editInsertTranslationMenuItemActionPerformed() { + ProjectUICommands.doInsertTrans(); + } + + public void editOverwriteMachineTranslationMenuItemActionPerformed() { + MachineTranslationInfo tr = Core.getMachineTranslatePane().getDisplayedTranslation(); + if (tr == null) { + Core.getMachineTranslatePane().forceLoad(); + } else if (!StringUtil.isEmpty(tr.result)) { + Core.getEditor().replaceEditText(tr.result, String.format("MT:[%s]", tr.translatorName)); + } + } + + /** + * replaces entire edited segment text with a the source text of a segment + * at cursor position + */ + public void editOverwriteSourceMenuItemActionPerformed() { + if (!Core.getProject().isProjectLoaded()) { + return; + } + String toInsert = Core.getEditor().getCurrentEntry().getSrcText(); + if (Preferences.isPreference(Preferences.GLOSSARY_REPLACE_ON_INSERT)) { + toInsert = EditorUtils.replaceGlossaryEntries(toInsert); + } + Core.getEditor().replaceEditText(toInsert); + } + + /** inserts the source text of a segment at cursor position */ + public void editInsertSourceMenuItemActionPerformed() { + if (!Core.getProject().isProjectLoaded()) { + return; + } + String toInsert = Core.getEditor().getCurrentEntry().getSrcText(); + if (Preferences.isPreference(Preferences.GLOSSARY_REPLACE_ON_INSERT)) { + toInsert = EditorUtils.replaceGlossaryEntries(toInsert); + } + Core.getEditor().insertText(toInsert); + } + + /** select the source text of the current segment */ + public void editSelectSourceMenuItemActionPerformed() { + if (!Core.getProject().isProjectLoaded()) { + return; + } + Core.getEditor().selectSourceText(); + } + + public void editExportSelectionMenuItemActionPerformed() { + if (!Core.getProject().isProjectLoaded()) { + return; + } + String selection = Core.getEditor().getSelectedText(); + if (selection == null) { + SourceTextEntry ste = Core.getEditor().getCurrentEntry(); + TMXEntry te = Core.getProject().getTranslationInfo(ste); + if (te.isTranslated()) { + selection = te.translation; + } else { + selection = ste.getSrcText(); + } + } + SegmentExportImport.exportCurrentSelection(selection); + } + + public void editSearchDictionaryMenuItemActionPerformed() { + if (!Core.getProject().isProjectLoaded()) { + return; + } + String selection = Core.getEditor().getSelectedText(); + if (selection == null) { + SourceTextEntry ste = Core.getEditor().getCurrentEntry(); + selection = ste.getSrcText(); + } + Core.getDictionaries().searchText(selection); + } + + public void editCreateGlossaryEntryMenuItemActionPerformed() { + if (!Core.getProject().isProjectLoaded()) { + return; + } + Core.getGlossary().showCreateGlossaryEntryDialog(Core.getMainWindow().getApplicationFrame()); + } + + public void editFindInProjectMenuItemActionPerformed() { + if (!Core.getProject().isProjectLoaded()) { + return; + } + SearchWindowController search = new SearchWindowController(SearchMode.SEARCH); + mainWindow.addSearchWindow(search); + + search.makeVisible(getTrimmedSelectedTextInMainWindow()); + } + + void findInProjectReuseLastWindow() { + if (!Core.getProject().isProjectLoaded()) { + return; + } + + List windows = mainWindow.getSearchWindows(); + for (int i = windows.size() - 1; i >= 0; i--) { + SearchWindowController swc = windows.get(i); + if (swc.getMode() == SearchMode.SEARCH) { + swc.makeVisible(getTrimmedSelectedTextInMainWindow()); + return; + } + } + editFindInProjectMenuItemActionPerformed(); + } + + public void editReplaceInProjectMenuItemActionPerformed() { + if (!Core.getProject().isProjectLoaded()) { + return; + } + SearchWindowController search = new SearchWindowController(SearchMode.REPLACE); + mainWindow.addSearchWindow(search); + + search.makeVisible(getTrimmedSelectedTextInMainWindow()); + } + + private String getTrimmedSelectedTextInMainWindow() { + String selection = null; + Component component = mainWindow.getApplicationFrame().getMostRecentFocusOwner(); + if (component instanceof JTextComponent) { + selection = ((JTextComponent) component).getSelectedText(); + if (!StringUtil.isEmpty(selection)) { + selection = EditorUtils.removeDirectionChars(selection); + selection = selection.trim(); + } + } + return selection; + } + + /** Set active match to #1. */ + public void editSelectFuzzy1MenuItemActionPerformed() { + Core.getMatcher().setActiveMatch(0); + } + + /** Set active match to #2. */ + public void editSelectFuzzy2MenuItemActionPerformed() { + Core.getMatcher().setActiveMatch(1); + } + + /** Set active match to #3. */ + public void editSelectFuzzy3MenuItemActionPerformed() { + Core.getMatcher().setActiveMatch(2); + } + + /** Set active match to #4. */ + public void editSelectFuzzy4MenuItemActionPerformed() { + Core.getMatcher().setActiveMatch(3); + } + + /** Set active match to #5. */ + public void editSelectFuzzy5MenuItemActionPerformed() { + Core.getMatcher().setActiveMatch(4); + } + + /** Set active match to the next one */ + public void editSelectFuzzyNextMenuItemActionPerformed() { + Core.getMatcher().setNextActiveMatch(); + } + + /** Set active match to the previous one */ + public void editSelectFuzzyPrevMenuItemActionPerformed() { + Core.getMatcher().setPrevActiveMatch(); + } + + public void insertCharsLRMActionPerformed() { + Core.getEditor().insertText("\u200E"); + } + + public void insertCharsRLMActionPerformed() { + Core.getEditor().insertText("\u200F"); + } + + public void insertCharsLREActionPerformed() { + Core.getEditor().insertText("\u202A"); + } + + public void insertCharsRLEActionPerformed() { + Core.getEditor().insertText("\u202B"); + } + + public void insertCharsPDFActionPerformed() { + Core.getEditor().insertText("\u202C"); + } + + public void editMultipleDefaultActionPerformed() { + Core.getEditor().setAlternateTranslationForCurrentEntry(false); + } + + public void editMultipleAlternateActionPerformed() { + Core.getEditor().setAlternateTranslationForCurrentEntry(true); + } + + public void editRegisterUntranslatedMenuItemActionPerformed() { + Core.getEditor().registerUntranslated(); + } + + public void editRegisterEmptyMenuItemActionPerformed() { + Core.getEditor().registerEmptyTranslation(); + } + + public void editRegisterIdenticalMenuItemActionPerformed() { + Core.getEditor().registerIdenticalTranslation(); + } + + public void toolsShowStatisticsStandardMenuItemActionPerformed() { + new StatisticsWindow(Core.getMainWindow().getApplicationFrame(), StatisticsWindow.STAT_TYPE.STANDARD) + .setVisible(true); + } + + public void toolsShowStatisticsMatchesMenuItemActionPerformed() { + new StatisticsWindow(Core.getMainWindow().getApplicationFrame(), StatisticsWindow.STAT_TYPE.MATCHES) + .setVisible(true); + } + + public void toolsShowStatisticsMatchesPerFileMenuItemActionPerformed() { + new StatisticsWindow(Core.getMainWindow().getApplicationFrame(), + StatisticsWindow.STAT_TYPE.MATCHES_PER_FILE).setVisible(true); + } + + public void optionsAutoCompleteShowAutomaticallyItemActionPerformed() { + /* + * Preferences.setPreference(Preferences. + * AC_SHOW_SUGGESTIONS_AUTOMATICALLY, + * mainWindow.menu.optionsAutoCompleteShowAutomaticallyItem.isSelected() + * ); + */ } + + public void optionsAutoCompleteHistoryCompletionMenuItemActionPerformed() { + /* + * Preferences.setPreference(Preferences.AC_HISTORY_COMPLETION_ENABLED, + * mainWindow.menu.optionsAutoCompleteHistoryCompletionMenuItem. + * isSelected()); + */ } + + public void optionsAutoCompleteHistoryPredictionMenuItemActionPerformed() { + /* + * Preferences.setPreference(Preferences.AC_HISTORY_PREDICTION_ENABLED, + * mainWindow.menu.optionsAutoCompleteHistoryPredictionMenuItem. + * isSelected()); + */ } + + public void optionsMTAutoFetchCheckboxMenuItemActionPerformed() { + /* + * boolean enabled = + * mainWindow.menu.optionsMTAutoFetchCheckboxMenuItem.isSelected(); + * Preferences.setPreference(Preferences.MT_AUTO_FETCH, enabled); + */ } + + public void optionsGlossaryFuzzyMatchingCheckBoxMenuItemActionPerformed() { + /* + * Preferences.setPreference(Preferences.GLOSSARY_STEMMING, + * mainWindow.menu.optionsGlossaryFuzzyMatchingCheckBoxMenuItem. + * isSelected()); Preferences.save(); + */ } + + public void optionsDictionaryFuzzyMatchingCheckBoxMenuItemActionPerformed() { + /* + * Preferences.setPreference(Preferences.DICTIONARY_FUZZY_MATCHING, + * mainWindow.menu.optionsDictionaryFuzzyMatchingCheckBoxMenuItem. + * isSelected()); Preferences.save(); + */ } + + /** + * Displays the filters setup dialog to allow customizing file filters in + * detail. + */ + public void optionsSetupFileFiltersMenuItemActionPerformed() { + new PreferencesWindowController().show(mainWindow.getApplicationFrame(), + FiltersCustomizerController.class); + } + + /** + * Displays the segmentation setup dialog to allow customizing the + * segmentation rules in detail. + */ + public void optionsSentsegMenuItemActionPerformed() { + new PreferencesWindowController().show(mainWindow.getApplicationFrame(), + SegmentationCustomizerController.class); + } + + /** + * Displays the workflow setup dialog to allow customizing the diverse + * workflow options. + */ + public void optionsWorkflowMenuItemActionPerformed() { + new PreferencesWindowController().show(mainWindow.getApplicationFrame(), + EditingBehaviorController.class); + } + + /** + * Restores defaults for all dockable parts. May be expanded in the future + * to reset the entire GUI to its defaults. + */ + public void viewRestoreGUIMenuItemActionPerformed() { + mainWindow.resetDesktopLayout(); + } + + public void optionsAccessConfigDirMenuItemActionPerformed() { + openFile(new File(StaticUtils.getConfigDir())); + } + + /** + * Show log + */ + public void helpLogMenuItemActionPerformed() { + new LogDialog(mainWindow.getApplicationFrame()).setVisible(true); + } + + @Override + public void helpAboutMenuItemActionPerformed() { + JDialog aboutDialog = new AboutDialog(mainWindow.getApplicationFrame()); + aboutDialog.setVisible(true); + } + + private void openFile(File file) { + Log.log("TestMainWindowMenuHanlder.openFile called with " + file.toString()); + } +}