From 44c317f207d526d893df5c3fa926c236c4517392 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillaume=20T=C3=A2che?= Date: Tue, 20 Aug 2024 21:31:10 +0200 Subject: [PATCH] Allows setting max lines and max line length, enables DeepL, adds user setup bridge --- .gitignore | 3 +- .../gtache/autosubtitle/Translator.java | 55 --------- .../autosubtitle/setup/SetupUserBridge.java | 35 ++++++ .../translation/TranslationException.java | 19 ++++ .../autosubtitle/translation/Translator.java | 98 +++++++++++++++++ api/src/main/java/module-info.java | 1 + .../gtache/autosubtitle/TestTranslator.java | 1 + .../autosubtitle/modules/impl/CoreModule.java | 21 ++++ .../modules/impl/MaxLineLength.java | 16 +++ .../autosubtitle/modules/impl/MaxLines.java | 16 +++ .../converter/impl/SRTSubtitleConverter.java | 2 +- core/src/main/java/module-info.java | 1 + .../impl/TestSRTSubtitleConverter.java | 2 +- deepl/pom.xml | 15 +++ .../autosubtitle/deepl/DeepLTranslator.java | 38 ------- .../modules/deepl/DeepLModule.java | 22 +++- .../modules/setup/deepl/DeepLSetupModule.java | 21 ++++ .../setup/deepl/DeepLSetupManager.java | 70 ++++++++++++ .../translation/deepl/DeepLTranslator.java | 78 +++++++++++++ deepl/src/main/java/module-info.java | 6 +- .../autosubtitle/gui/ParametersModel.java | 8 ++ .../gui/impl/ParametersBundle.properties | 2 + .../gui/impl/ParametersBundle_fr.properties | 1 + .../gui/fx/AbstractFXController.java | 2 +- .../autosubtitle/gui/fx/FXMainController.java | 2 +- .../gui/fx/FXParametersController.java | 16 ++- .../gui/fx/FXParametersModel.java | 37 ++++++- .../gui/fx/FXSetupController.java | 2 +- .../gui/fx/FXSubtitlesController.java | 50 ++++++--- .../autosubtitle/modules/gui/fx/FXModule.java | 10 +- .../modules/setup/gui/fx/FXSetupModule.java | 19 ++++ .../setup/gui/fx/FXSetupUserBridge.java | 64 +++++++++++ gui/fx/src/main/java/module-info.java | 3 +- .../autosubtitle/gui/fx/parametersView.fxml | 53 +++++---- .../gui/fx/TestFXParametersController.java | 4 +- .../gui/fx/TestFXParametersModel.java | 4 +- .../gui/fx/TestFXSetupController.java | 2 +- .../gui/fx/TestFXSubtitlesController.java | 2 +- .../autosubtitle/gui/fx/TestFXWorkBinder.java | 2 +- .../modules/gui/fx/TestFXModule.java | 5 - gui/run/pom.xml | 4 + .../gui/run/MissingComponentsModule.java | 53 --------- .../modules/gui/run/NoOpSetupManager.java | 64 ----------- .../modules/gui/run/RunComponent.java | 3 +- gui/run/src/main/java/module-info.java | 3 +- .../whisper/base/JSONSubtitleConverter.java | 4 +- .../whisperx/WhisperXSubtitleExtractor.java | 6 +- .../json/whisperx/JSONSubtitleConverter.java | 104 +++++++++++++++++- .../whisperx/src/main/java/module-info.java | 1 + 49 files changed, 752 insertions(+), 298 deletions(-) delete mode 100644 api/src/main/java/com/github/gtache/autosubtitle/Translator.java create mode 100644 api/src/main/java/com/github/gtache/autosubtitle/setup/SetupUserBridge.java create mode 100644 api/src/main/java/com/github/gtache/autosubtitle/translation/TranslationException.java create mode 100644 api/src/main/java/com/github/gtache/autosubtitle/translation/Translator.java create mode 100644 core/src/main/java/com/github/gtache/autosubtitle/modules/impl/MaxLineLength.java create mode 100644 core/src/main/java/com/github/gtache/autosubtitle/modules/impl/MaxLines.java delete mode 100644 deepl/src/main/java/com/github/gtache/autosubtitle/deepl/DeepLTranslator.java create mode 100644 deepl/src/main/java/com/github/gtache/autosubtitle/modules/setup/deepl/DeepLSetupModule.java create mode 100644 deepl/src/main/java/com/github/gtache/autosubtitle/setup/deepl/DeepLSetupManager.java create mode 100644 deepl/src/main/java/com/github/gtache/autosubtitle/translation/deepl/DeepLTranslator.java create mode 100644 gui/fx/src/main/java/com/github/gtache/autosubtitle/modules/setup/gui/fx/FXSetupModule.java create mode 100644 gui/fx/src/main/java/com/github/gtache/autosubtitle/setup/gui/fx/FXSetupUserBridge.java delete mode 100644 gui/run/src/main/java/com/github/gtache/autosubtitle/modules/gui/run/MissingComponentsModule.java delete mode 100644 gui/run/src/main/java/com/github/gtache/autosubtitle/modules/gui/run/NoOpSetupManager.java diff --git a/.gitignore b/.gitignore index b40f052..90d5fc0 100644 --- a/.gitignore +++ b/.gitignore @@ -38,4 +38,5 @@ build/ ### Mac OS ### .DS_Store -tools \ No newline at end of file +tools +.secrets diff --git a/api/src/main/java/com/github/gtache/autosubtitle/Translator.java b/api/src/main/java/com/github/gtache/autosubtitle/Translator.java deleted file mode 100644 index ce7ebd5..0000000 --- a/api/src/main/java/com/github/gtache/autosubtitle/Translator.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.github.gtache.autosubtitle; - -import com.github.gtache.autosubtitle.subtitle.Subtitle; -import com.github.gtache.autosubtitle.subtitle.SubtitleCollection; - -/** - * Translates texts and subtitles - */ -public interface Translator { - - /** - * Guesses the language of the given text - * - * @param text The text - * @return The guessed language - */ - Language getLanguage(final String text); - - /** - * Guesses the language of the given subtitle - * - * @param subtitle The subtitle - * @return The guessed language - */ - default Language getLanguage(final Subtitle subtitle) { - return getLanguage(subtitle.content()); - } - - /** - * Translates the given text to the given language - * - * @param text The text to translate - * @param to The target language - * @return The translated text - */ - String translate(String text, Language to); - - /** - * Translates the given subtitle to the given language - * - * @param subtitle The subtitle to translate - * @param to The target language - * @return The translated subtitle - */ - T translate(Subtitle subtitle, Language to); - - /** - * Translates the given subtitles collection to the given language - * - * @param collection The subtitles collection to translate - * @param to The target language - * @return The translated subtitles collection - */ - SubtitleCollection translate(SubtitleCollection collection, Language to); -} diff --git a/api/src/main/java/com/github/gtache/autosubtitle/setup/SetupUserBridge.java b/api/src/main/java/com/github/gtache/autosubtitle/setup/SetupUserBridge.java new file mode 100644 index 0000000..deee0d1 --- /dev/null +++ b/api/src/main/java/com/github/gtache/autosubtitle/setup/SetupUserBridge.java @@ -0,0 +1,35 @@ +package com.github.gtache.autosubtitle.setup; + +import java.util.List; + +/** + * Bridge between setup manager and the user + */ +public interface SetupUserBridge { + + /** + * Asks for user input + * + * @param question the question to display to the user + * @return the user input + */ + String askForUserInput(String question); + + /** + * Asks for user choice + * + * @param question the question to display to the user + * @param choices the possible choices + * @param the type of the choices + * @return the user choice + */ + T askForUserChoice(String question, List choices); + + /** + * Asks for user confirmation + * + * @param question the question to display to the user + * @return whether the user confirmed + */ + boolean askForUserConfirmation(String question); +} diff --git a/api/src/main/java/com/github/gtache/autosubtitle/translation/TranslationException.java b/api/src/main/java/com/github/gtache/autosubtitle/translation/TranslationException.java new file mode 100644 index 0000000..ce44a8d --- /dev/null +++ b/api/src/main/java/com/github/gtache/autosubtitle/translation/TranslationException.java @@ -0,0 +1,19 @@ +package com.github.gtache.autosubtitle.translation; + +/** + * Exception thrown when an error occurs during translation + */ +public class TranslationException extends Exception { + + public TranslationException(final String message) { + super(message); + } + + public TranslationException(final String message, final Throwable cause) { + super(message, cause); + } + + public TranslationException(final Throwable cause) { + super(cause); + } +} diff --git a/api/src/main/java/com/github/gtache/autosubtitle/translation/Translator.java b/api/src/main/java/com/github/gtache/autosubtitle/translation/Translator.java new file mode 100644 index 0000000..7c73b04 --- /dev/null +++ b/api/src/main/java/com/github/gtache/autosubtitle/translation/Translator.java @@ -0,0 +1,98 @@ +package com.github.gtache.autosubtitle.translation; + +import com.github.gtache.autosubtitle.Language; +import com.github.gtache.autosubtitle.subtitle.Subtitle; +import com.github.gtache.autosubtitle.subtitle.SubtitleCollection; + +/** + * Translates texts and subtitles + */ +public interface Translator { + + /** + * Guesses the language of the given text + * + * @param text The text + * @return The guessed language + */ + Language getLanguage(final String text); + + /** + * Guesses the language of the given subtitle + * + * @param subtitle The subtitle + * @return The guessed language + */ + default Language getLanguage(final Subtitle subtitle) { + return getLanguage(subtitle.content()); + } + + /** + * Translates the given text to the given language + * + * @param text The text to translate + * @param to The target language + * @return The translated text + * @throws TranslationException if an error occurred during the translation + */ + default String translate(final String text, final Language to) throws TranslationException { + return translate(text, getLanguage(text), to); + } + + /** + * Translates the given text to the given language + * + * @param text The text to translate + * @param from The source language + * @param to The target language + * @return The translated text + * @throws TranslationException if an error occurred during the translation + */ + String translate(String text, Language from, Language to) throws TranslationException; + + /** + * Translates the given subtitle to the given language + * + * @param subtitle The subtitle to translate + * @param to The target language + * @return The translated subtitle + * @throws TranslationException if an error occurred during the translation + */ + default T translate(final Subtitle subtitle, final Language to) throws TranslationException { + return translate(subtitle, getLanguage(subtitle), to); + } + + /** + * Translates the given subtitle to the given language + * + * @param subtitle The subtitle to translate + * @param from The source language + * @param to The target language + * @return The translated subtitle + * @throws TranslationException if an error occurred during the translation + */ + T translate(Subtitle subtitle, Language from, Language to) throws TranslationException; + + /** + * Translates the given subtitles collection to the given language + * + * @param collection The subtitles collection to translate + * @param to The target language + * @return The translated subtitles collection + * @throws TranslationException if an error occurred during the translation + */ + default SubtitleCollection translate(final SubtitleCollection collection, final Language to) throws TranslationException { + return translate(collection, getLanguage(collection.text()), to); + } + + /** + * Translates the given subtitles collection to the given language + * + * @param collection The subtitles collection to translate + * @param from The source language + * @param to The target language + * @return The translated subtitles collection + * @throws TranslationException if an error occurred during the translation + */ + SubtitleCollection translate(SubtitleCollection collection, Language from, Language to) throws TranslationException; +} diff --git a/api/src/main/java/module-info.java b/api/src/main/java/module-info.java index 2a4c54f..3621ebb 100644 --- a/api/src/main/java/module-info.java +++ b/api/src/main/java/module-info.java @@ -9,4 +9,5 @@ module com.github.gtache.autosubtitle.api { exports com.github.gtache.autosubtitle.subtitle; exports com.github.gtache.autosubtitle.subtitle.extractor; exports com.github.gtache.autosubtitle.subtitle.converter; + exports com.github.gtache.autosubtitle.translation; } \ No newline at end of file diff --git a/api/src/test/java/com/github/gtache/autosubtitle/TestTranslator.java b/api/src/test/java/com/github/gtache/autosubtitle/TestTranslator.java index 9ba086e..a97669b 100644 --- a/api/src/test/java/com/github/gtache/autosubtitle/TestTranslator.java +++ b/api/src/test/java/com/github/gtache/autosubtitle/TestTranslator.java @@ -1,6 +1,7 @@ package com.github.gtache.autosubtitle; import com.github.gtache.autosubtitle.subtitle.Subtitle; +import com.github.gtache.autosubtitle.translation.Translator; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; diff --git a/core/src/main/java/com/github/gtache/autosubtitle/modules/impl/CoreModule.java b/core/src/main/java/com/github/gtache/autosubtitle/modules/impl/CoreModule.java index c7736d5..4752fe1 100644 --- a/core/src/main/java/com/github/gtache/autosubtitle/modules/impl/CoreModule.java +++ b/core/src/main/java/com/github/gtache/autosubtitle/modules/impl/CoreModule.java @@ -13,6 +13,9 @@ import dagger.Provides; import dagger.multibindings.IntoMap; import dagger.multibindings.StringKey; +import javax.inject.Singleton; +import java.util.prefs.Preferences; + /** * Dagger module for Core */ @@ -53,4 +56,22 @@ public abstract class CoreModule { static String providesExecutableExtension(final OS os) { return os == OS.WINDOWS ? ".exe" : ""; } + + @Provides + @Singleton + static Preferences providesPreferences() { + return Preferences.userRoot().node("/com/github/gtache/autosubtitle"); + } + + @Provides + @MaxLineLength + static int providesMaxLineLength() { + return 40; + } + + @Provides + @MaxLines + static int providesMaxLines() { + return 1; + } } diff --git a/core/src/main/java/com/github/gtache/autosubtitle/modules/impl/MaxLineLength.java b/core/src/main/java/com/github/gtache/autosubtitle/modules/impl/MaxLineLength.java new file mode 100644 index 0000000..ca32f2a --- /dev/null +++ b/core/src/main/java/com/github/gtache/autosubtitle/modules/impl/MaxLineLength.java @@ -0,0 +1,16 @@ +package com.github.gtache.autosubtitle.modules.impl; + +import javax.inject.Qualifier; +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +@Qualifier +@Documented +@Retention(RUNTIME) +@Target({ElementType.PARAMETER, ElementType.METHOD, ElementType.FIELD}) +public @interface MaxLineLength { +} diff --git a/core/src/main/java/com/github/gtache/autosubtitle/modules/impl/MaxLines.java b/core/src/main/java/com/github/gtache/autosubtitle/modules/impl/MaxLines.java new file mode 100644 index 0000000..8e2c5aa --- /dev/null +++ b/core/src/main/java/com/github/gtache/autosubtitle/modules/impl/MaxLines.java @@ -0,0 +1,16 @@ +package com.github.gtache.autosubtitle.modules.impl; + +import javax.inject.Qualifier; +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +@Qualifier +@Documented +@Retention(RUNTIME) +@Target({ElementType.PARAMETER, ElementType.METHOD, ElementType.FIELD}) +public @interface MaxLines { +} diff --git a/core/src/main/java/com/github/gtache/autosubtitle/subtitle/converter/impl/SRTSubtitleConverter.java b/core/src/main/java/com/github/gtache/autosubtitle/subtitle/converter/impl/SRTSubtitleConverter.java index 16f4304..c6dd87f 100644 --- a/core/src/main/java/com/github/gtache/autosubtitle/subtitle/converter/impl/SRTSubtitleConverter.java +++ b/core/src/main/java/com/github/gtache/autosubtitle/subtitle/converter/impl/SRTSubtitleConverter.java @@ -1,12 +1,12 @@ package com.github.gtache.autosubtitle.subtitle.converter.impl; -import com.github.gtache.autosubtitle.Translator; import com.github.gtache.autosubtitle.subtitle.Subtitle; import com.github.gtache.autosubtitle.subtitle.SubtitleCollection; import com.github.gtache.autosubtitle.subtitle.converter.ParseException; import com.github.gtache.autosubtitle.subtitle.converter.SubtitleConverter; import com.github.gtache.autosubtitle.subtitle.impl.SubtitleCollectionImpl; import com.github.gtache.autosubtitle.subtitle.impl.SubtitleImpl; +import com.github.gtache.autosubtitle.translation.Translator; import javax.inject.Inject; import java.util.Arrays; diff --git a/core/src/main/java/module-info.java b/core/src/main/java/module-info.java index 2b88992..ab152e5 100644 --- a/core/src/main/java/module-info.java +++ b/core/src/main/java/module-info.java @@ -7,6 +7,7 @@ module com.github.gtache.autosubtitle.core { requires transitive java.net.http; requires transitive javax.inject; requires org.apache.logging.log4j; + requires java.prefs; exports com.github.gtache.autosubtitle.impl; exports com.github.gtache.autosubtitle.archive.impl; diff --git a/core/src/test/java/com/github/gtache/autosubtitle/subtitle/converter/impl/TestSRTSubtitleConverter.java b/core/src/test/java/com/github/gtache/autosubtitle/subtitle/converter/impl/TestSRTSubtitleConverter.java index 46e6be1..aa87394 100644 --- a/core/src/test/java/com/github/gtache/autosubtitle/subtitle/converter/impl/TestSRTSubtitleConverter.java +++ b/core/src/test/java/com/github/gtache/autosubtitle/subtitle/converter/impl/TestSRTSubtitleConverter.java @@ -1,10 +1,10 @@ package com.github.gtache.autosubtitle.subtitle.converter.impl; import com.github.gtache.autosubtitle.Language; -import com.github.gtache.autosubtitle.Translator; import com.github.gtache.autosubtitle.subtitle.converter.ParseException; import com.github.gtache.autosubtitle.subtitle.impl.SubtitleCollectionImpl; import com.github.gtache.autosubtitle.subtitle.impl.SubtitleImpl; +import com.github.gtache.autosubtitle.translation.Translator; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; diff --git a/deepl/pom.xml b/deepl/pom.xml index 0afc18f..d270ce4 100644 --- a/deepl/pom.xml +++ b/deepl/pom.xml @@ -11,11 +11,26 @@ autosubtitle-deepl + + 1.5.0 + 1.2.2 + + com.github.gtache.autosubtitle autosubtitle-core + + com.deepl.api + deepl-java + ${deepl.version} + + + com.github.pemistahl + lingua + ${lingua.version} + \ No newline at end of file diff --git a/deepl/src/main/java/com/github/gtache/autosubtitle/deepl/DeepLTranslator.java b/deepl/src/main/java/com/github/gtache/autosubtitle/deepl/DeepLTranslator.java deleted file mode 100644 index b5b302b..0000000 --- a/deepl/src/main/java/com/github/gtache/autosubtitle/deepl/DeepLTranslator.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.github.gtache.autosubtitle.deepl; - -import com.github.gtache.autosubtitle.Language; -import com.github.gtache.autosubtitle.Translator; -import com.github.gtache.autosubtitle.subtitle.Subtitle; -import com.github.gtache.autosubtitle.subtitle.SubtitleCollection; - -import javax.inject.Inject; - -/** - * DeepL implementation of {@link Translator} - */ -public class DeepLTranslator implements Translator { - - @Inject - DeepLTranslator() { - } - - @Override - public Language getLanguage(final String text) { - return null; - } - - @Override - public String translate(final String text, final Language to) { - return ""; - } - - @Override - public Subtitle translate(final Subtitle subtitle, final Language to) { - return null; - } - - @Override - public SubtitleCollection translate(final SubtitleCollection collection, final Language to) { - return null; - } -} diff --git a/deepl/src/main/java/com/github/gtache/autosubtitle/modules/deepl/DeepLModule.java b/deepl/src/main/java/com/github/gtache/autosubtitle/modules/deepl/DeepLModule.java index d649a41..2af5871 100644 --- a/deepl/src/main/java/com/github/gtache/autosubtitle/modules/deepl/DeepLModule.java +++ b/deepl/src/main/java/com/github/gtache/autosubtitle/modules/deepl/DeepLModule.java @@ -1,16 +1,28 @@ package com.github.gtache.autosubtitle.modules.deepl; -import com.github.gtache.autosubtitle.Translator; -import com.github.gtache.autosubtitle.deepl.DeepLTranslator; +import com.github.gtache.autosubtitle.modules.setup.deepl.DeepLSetupModule; +import com.github.gtache.autosubtitle.translation.Translator; +import com.github.gtache.autosubtitle.translation.deepl.DeepLTranslator; +import com.github.pemistahl.lingua.api.LanguageDetector; +import com.github.pemistahl.lingua.api.LanguageDetectorBuilder; import dagger.Binds; import dagger.Module; +import dagger.Provides; + +import javax.inject.Singleton; /** * Dagger module for DeepL */ -@Module -public interface DeepLModule { +@Module(includes = DeepLSetupModule.class) +public abstract class DeepLModule { @Binds - Translator bindsTranslator(final DeepLTranslator translator); + abstract Translator bindsTranslator(final DeepLTranslator translator); + + @Provides + @Singleton + static LanguageDetector providesLanguageDetector() { + return LanguageDetectorBuilder.fromAllSpokenLanguages().build(); + } } diff --git a/deepl/src/main/java/com/github/gtache/autosubtitle/modules/setup/deepl/DeepLSetupModule.java b/deepl/src/main/java/com/github/gtache/autosubtitle/modules/setup/deepl/DeepLSetupModule.java new file mode 100644 index 0000000..6f69e7e --- /dev/null +++ b/deepl/src/main/java/com/github/gtache/autosubtitle/modules/setup/deepl/DeepLSetupModule.java @@ -0,0 +1,21 @@ +package com.github.gtache.autosubtitle.modules.setup.deepl; + +import com.github.gtache.autosubtitle.modules.setup.impl.TranslatorSetup; +import com.github.gtache.autosubtitle.setup.SetupManager; +import com.github.gtache.autosubtitle.setup.deepl.DeepLSetupManager; +import dagger.Binds; +import dagger.Module; + +/** + * Dagger module for DeepL setup + */ +@Module +public abstract class DeepLSetupModule { + private DeepLSetupModule() { + } + + @Binds + @TranslatorSetup + abstract SetupManager bindsSetupManager(final DeepLSetupManager setupManager); + +} diff --git a/deepl/src/main/java/com/github/gtache/autosubtitle/setup/deepl/DeepLSetupManager.java b/deepl/src/main/java/com/github/gtache/autosubtitle/setup/deepl/DeepLSetupManager.java new file mode 100644 index 0000000..c00ba40 --- /dev/null +++ b/deepl/src/main/java/com/github/gtache/autosubtitle/setup/deepl/DeepLSetupManager.java @@ -0,0 +1,70 @@ +package com.github.gtache.autosubtitle.setup.deepl; + +import com.github.gtache.autosubtitle.setup.SetupException; +import com.github.gtache.autosubtitle.setup.SetupManager; +import com.github.gtache.autosubtitle.setup.SetupStatus; +import com.github.gtache.autosubtitle.setup.SetupUserBridge; +import com.github.gtache.autosubtitle.setup.impl.AbstractSetupManager; + +import javax.inject.Inject; +import java.util.Objects; +import java.util.prefs.BackingStoreException; +import java.util.prefs.Preferences; + +/** + * {@link SetupManager} for DeepL + */ +public class DeepLSetupManager extends AbstractSetupManager { + + private static final String DEEPL_API_KEY = "deepl.api.key"; + + private final SetupUserBridge userBridge; + private final Preferences preferences; + + @Inject + DeepLSetupManager(final SetupUserBridge userBridge, final Preferences preferences) { + this.userBridge = Objects.requireNonNull(userBridge); + this.preferences = Objects.requireNonNull(preferences); + } + + @Override + protected SetupStatus getStatus() throws SetupException { + final var key = preferences.get(DEEPL_API_KEY, null); + return key == null ? SetupStatus.NOT_INSTALLED : SetupStatus.BUNDLE_INSTALLED; + } + + @Override + public String name() { + return "DeepL"; + } + + @Override + public void install() throws SetupException { + final var key = userBridge.askForUserInput("Please enter your DeepL API key - https://www.deepl.com/pro-api? (It will be stored unencrypted)"); + if (key == null) { + throw new SetupException("API key cannot be null"); + } else { + preferences.put(DEEPL_API_KEY, key); + try { + preferences.flush(); + } catch (final BackingStoreException e) { + throw new SetupException(e); + } + } + } + + @Override + public void uninstall() throws SetupException { + preferences.remove(DEEPL_API_KEY); + try { + preferences.flush(); + } catch (final BackingStoreException e) { + throw new SetupException(e); + } + } + + @Override + public void update() throws SetupException { + //No need to update + } +} diff --git a/deepl/src/main/java/com/github/gtache/autosubtitle/translation/deepl/DeepLTranslator.java b/deepl/src/main/java/com/github/gtache/autosubtitle/translation/deepl/DeepLTranslator.java new file mode 100644 index 0000000..7ce4bea --- /dev/null +++ b/deepl/src/main/java/com/github/gtache/autosubtitle/translation/deepl/DeepLTranslator.java @@ -0,0 +1,78 @@ +package com.github.gtache.autosubtitle.translation.deepl; + +import com.deepl.api.DeepLException; +import com.github.gtache.autosubtitle.Language; +import com.github.gtache.autosubtitle.subtitle.Subtitle; +import com.github.gtache.autosubtitle.subtitle.SubtitleCollection; +import com.github.gtache.autosubtitle.subtitle.impl.SubtitleCollectionImpl; +import com.github.gtache.autosubtitle.subtitle.impl.SubtitleImpl; +import com.github.gtache.autosubtitle.translation.TranslationException; +import com.github.gtache.autosubtitle.translation.Translator; +import com.github.pemistahl.lingua.api.LanguageDetector; + +import javax.inject.Inject; +import java.util.ArrayList; +import java.util.Objects; +import java.util.prefs.Preferences; +import java.util.stream.Collectors; + +/** + * DeepL implementation of {@link Translator} + */ +public class DeepLTranslator implements Translator { + + private final Preferences preferences; + private final LanguageDetector languageDetector; + private com.deepl.api.Translator translator; + + @Inject + DeepLTranslator(final Preferences preferences, final LanguageDetector languageDetector) { + this.preferences = Objects.requireNonNull(preferences); + this.languageDetector = Objects.requireNonNull(languageDetector); + } + + @Override + public Language getLanguage(final String text) { + return Language.getLanguage(languageDetector.detectLanguageOf(text).getIsoCode639_1().toString()); + } + + @Override + public String translate(final String text, final Language from, final Language to) throws TranslationException { + final var currentTranslator = getTranslator(); + if (currentTranslator == null) { + throw new TranslationException("DeepL API key is not set"); + } + try { + final var translated = currentTranslator.translateText(text, from.iso2(), to.iso2()); + return translated.getText(); + } catch (final DeepLException e) { + throw new TranslationException(e); + } catch (final InterruptedException e) { + Thread.currentThread().interrupt(); + throw new TranslationException(e); + } + } + + @Override + public Subtitle translate(final Subtitle subtitle, final Language from, final Language to) throws TranslationException { + final var translated = translate(subtitle.content(), from, to); + return new SubtitleImpl(translated, subtitle.start(), subtitle.end(), subtitle.font(), subtitle.bounds()); + } + + @Override + public SubtitleCollection translate(final SubtitleCollection collection, final Language from, final Language to) throws TranslationException { + final var subtitles = new ArrayList(collection.subtitles().size()); + for (final var subtitle : collection.subtitles()) { + subtitles.add(translate(subtitle, from, to)); + } + final var text = subtitles.stream().map(Subtitle::content).collect(Collectors.joining("")); + return new SubtitleCollectionImpl<>(text, subtitles, to); + } + + private com.deepl.api.Translator getTranslator() { + if (translator == null && preferences.get("deepl.api.key", null) != null) { + translator = new com.deepl.api.Translator(preferences.get("deepl.api.key", null)); + } + return translator; + } +} diff --git a/deepl/src/main/java/module-info.java b/deepl/src/main/java/module-info.java index 0ea7396..67c0c6c 100644 --- a/deepl/src/main/java/module-info.java +++ b/deepl/src/main/java/module-info.java @@ -3,6 +3,10 @@ */ module com.github.gtache.autosubtitle.deepl { requires transitive com.github.gtache.autosubtitle.core; - exports com.github.gtache.autosubtitle.deepl; + requires transitive deepl.java; + requires transitive com.github.pemistahl.lingua; + requires transitive java.prefs; exports com.github.gtache.autosubtitle.modules.deepl; + exports com.github.gtache.autosubtitle.translation.deepl; + exports com.github.gtache.autosubtitle.setup.deepl; } \ No newline at end of file diff --git a/gui/api/src/main/java/com/github/gtache/autosubtitle/gui/ParametersModel.java b/gui/api/src/main/java/com/github/gtache/autosubtitle/gui/ParametersModel.java index 6b73997..e1b67dc 100644 --- a/gui/api/src/main/java/com/github/gtache/autosubtitle/gui/ParametersModel.java +++ b/gui/api/src/main/java/com/github/gtache/autosubtitle/gui/ParametersModel.java @@ -64,4 +64,12 @@ public interface ParametersModel { * @param fontSize The new font size */ void setFontSize(int fontSize); + + int maxLineLength(); + + void setMaxLineLength(int maxLineLength); + + int maxLines(); + + void setMaxLines(int maxLines); } diff --git a/gui/core/src/main/resources/com/github/gtache/autosubtitle/gui/impl/ParametersBundle.properties b/gui/core/src/main/resources/com/github/gtache/autosubtitle/gui/impl/ParametersBundle.properties index 1762433..292dd3a 100644 --- a/gui/core/src/main/resources/com/github/gtache/autosubtitle/gui/impl/ParametersBundle.properties +++ b/gui/core/src/main/resources/com/github/gtache/autosubtitle/gui/impl/ParametersBundle.properties @@ -3,4 +3,6 @@ parameters.button.save.label=Save parameters.extraction.model.label=Model to use for subtitle extraction parameters.subtitles.font.family=Default subtitle font name parameters.subtitles.font.size=Default subtitle font size +parameters.subtitles.max.length.label=Max length of a subtitles line (characters) +parameters.subtitles.max.lines.label=Max subtitles lines parameters.subtitles.output.format=Output format for the subtitles \ No newline at end of file diff --git a/gui/core/src/main/resources/com/github/gtache/autosubtitle/gui/impl/ParametersBundle_fr.properties b/gui/core/src/main/resources/com/github/gtache/autosubtitle/gui/impl/ParametersBundle_fr.properties index 2e4ccb9..bc70283 100644 --- a/gui/core/src/main/resources/com/github/gtache/autosubtitle/gui/impl/ParametersBundle_fr.properties +++ b/gui/core/src/main/resources/com/github/gtache/autosubtitle/gui/impl/ParametersBundle_fr.properties @@ -3,4 +3,5 @@ parameters.button.save.label=Sauvegarder parameters.extraction.model.label=Mod\u00E8le utilis\u00E9 pour l'extraction des sous-titres parameters.subtitles.font.family=Police par d\u00E9faut pour les sous-titres parameters.subtitles.font.size=Taille de la police par d\u00E9faut pour les sous-titres +parameters.subtitles.max.length.label=Taille maximale d'une ligne de sous-titres (caract\u00E8res) parameters.subtitles.output.format=Format de sortie pour les sous-titres \ No newline at end of file diff --git a/gui/fx/src/main/java/com/github/gtache/autosubtitle/gui/fx/AbstractFXController.java b/gui/fx/src/main/java/com/github/gtache/autosubtitle/gui/fx/AbstractFXController.java index 4b74315..bbc1556 100644 --- a/gui/fx/src/main/java/com/github/gtache/autosubtitle/gui/fx/AbstractFXController.java +++ b/gui/fx/src/main/java/com/github/gtache/autosubtitle/gui/fx/AbstractFXController.java @@ -12,7 +12,7 @@ public abstract class AbstractFXController { /** * @return the current window */ - protected abstract Window window(); + public abstract Window window(); /** * Show an error dialog diff --git a/gui/fx/src/main/java/com/github/gtache/autosubtitle/gui/fx/FXMainController.java b/gui/fx/src/main/java/com/github/gtache/autosubtitle/gui/fx/FXMainController.java index 14df25b..9128461 100644 --- a/gui/fx/src/main/java/com/github/gtache/autosubtitle/gui/fx/FXMainController.java +++ b/gui/fx/src/main/java/com/github/gtache/autosubtitle/gui/fx/FXMainController.java @@ -42,7 +42,7 @@ public class FXMainController extends AbstractFXController implements MainContro } @Override - protected Window window() { + public Window window() { return tabPane.getScene().getWindow(); } } diff --git a/gui/fx/src/main/java/com/github/gtache/autosubtitle/gui/fx/FXParametersController.java b/gui/fx/src/main/java/com/github/gtache/autosubtitle/gui/fx/FXParametersController.java index 905afea..c6ccb8b 100644 --- a/gui/fx/src/main/java/com/github/gtache/autosubtitle/gui/fx/FXParametersController.java +++ b/gui/fx/src/main/java/com/github/gtache/autosubtitle/gui/fx/FXParametersController.java @@ -37,6 +37,10 @@ public class FXParametersController extends AbstractFXController implements Para private PrefixSelectionComboBox fontFamilyCombobox; @FXML private TextField fontSizeField; + @FXML + private TextField maxLengthField; + @FXML + private TextField maxLinesField; private final FXParametersModel model; private final Preferences preferences; @@ -68,8 +72,12 @@ public class FXParametersController extends AbstractFXController implements Para return null; }; fontSizeField.setTextFormatter(new TextFormatter<>(new IntegerStringConverter(), 0, integerFilter)); + maxLengthField.setTextFormatter(new TextFormatter<>(new IntegerStringConverter(), 0, integerFilter)); + maxLinesField.setTextFormatter(new TextFormatter<>(new IntegerStringConverter(), 0, integerFilter)); fontSizeField.textProperty().bindBidirectional(model.fontSizeProperty(), new NumberStringConverter()); + maxLengthField.textProperty().bindBidirectional(model.maxLineLengthProperty(), new NumberStringConverter()); + maxLinesField.textProperty().bindBidirectional(model.maxLinesProperty(), new NumberStringConverter()); loadPreferences(); } @@ -79,11 +87,15 @@ public class FXParametersController extends AbstractFXController implements Para final var outputFormat = preferences.get("outputFormat", model.outputFormat().name()); final var fontFamily = preferences.get("fontFamily", model.fontFamily()); final var fontSize = preferences.getInt("fontSize", model.fontSize()); + final var maxLineLength = preferences.getInt("maxLineLength", model.maxLineLength()); + final var maxLines = preferences.getInt("maxLines", model.maxLines()); model.setExtractionModel(extractionModelProvider.getExtractionModel(extractionModel)); model.setOutputFormat(OutputFormat.valueOf(outputFormat)); model.setFontFamily(fontFamily); model.setFontSize(fontSize); + model.setMaxLineLength(maxLineLength); + model.setMaxLines(maxLines); logger.info("Loaded preferences"); } @@ -95,6 +107,8 @@ public class FXParametersController extends AbstractFXController implements Para preferences.put("outputFormat", model.outputFormat().name()); preferences.put("fontFamily", model.fontFamily()); preferences.putInt("fontSize", model.fontSize()); + preferences.putInt("maxLineLength", model.maxLineLength()); + preferences.putInt("maxLines", model.maxLines()); try { preferences.flush(); logger.info("Preferences saved"); @@ -124,7 +138,7 @@ public class FXParametersController extends AbstractFXController implements Para } @Override - protected Window window() { + public Window window() { return extractionModelCombobox.getScene().getWindow(); } } diff --git a/gui/fx/src/main/java/com/github/gtache/autosubtitle/gui/fx/FXParametersModel.java b/gui/fx/src/main/java/com/github/gtache/autosubtitle/gui/fx/FXParametersModel.java index ebd5a5b..055076d 100644 --- a/gui/fx/src/main/java/com/github/gtache/autosubtitle/gui/fx/FXParametersModel.java +++ b/gui/fx/src/main/java/com/github/gtache/autosubtitle/gui/fx/FXParametersModel.java @@ -3,6 +3,8 @@ package com.github.gtache.autosubtitle.gui.fx; import com.github.gtache.autosubtitle.gui.ParametersModel; import com.github.gtache.autosubtitle.modules.gui.impl.FontFamily; import com.github.gtache.autosubtitle.modules.gui.impl.FontSize; +import com.github.gtache.autosubtitle.modules.impl.MaxLineLength; +import com.github.gtache.autosubtitle.modules.impl.MaxLines; import com.github.gtache.autosubtitle.subtitle.OutputFormat; import com.github.gtache.autosubtitle.subtitle.extractor.ExtractionModel; import com.github.gtache.autosubtitle.subtitle.extractor.ExtractionModelProvider; @@ -31,9 +33,12 @@ public class FXParametersModel implements ParametersModel { private final ObservableList availableFontFamilies; private final StringProperty fontFamily; private final IntegerProperty fontSize; + private final IntegerProperty maxLineLength; + private final IntegerProperty maxLines; @Inject - FXParametersModel(final ExtractionModelProvider extractionModelProvider, @FontFamily final String defaultFontFamily, @FontSize final int defaultFontSize) { + FXParametersModel(final ExtractionModelProvider extractionModelProvider, @FontFamily final String defaultFontFamily, + @FontSize final int defaultFontSize, @MaxLineLength final int defaultMaxLineLength, @MaxLines final int defaultMaxLines) { this.availableExtractionModels = FXCollections.unmodifiableObservableList(FXCollections.observableArrayList(extractionModelProvider.getAvailableExtractionModels())); this.extractionModel = new SimpleObjectProperty<>(extractionModelProvider.getDefaultExtractionModel()); this.availableOutputFormats = FXCollections.unmodifiableObservableList(FXCollections.observableArrayList(OutputFormat.SRT)); @@ -41,6 +46,8 @@ public class FXParametersModel implements ParametersModel { this.availableFontFamilies = FXCollections.unmodifiableObservableList(FXCollections.observableArrayList("Arial")); this.fontFamily = new SimpleStringProperty(defaultFontFamily); this.fontSize = new SimpleIntegerProperty(defaultFontSize); + this.maxLineLength = new SimpleIntegerProperty(defaultMaxLineLength); + this.maxLines = new SimpleIntegerProperty(defaultMaxLines); } @Override @@ -113,4 +120,32 @@ public class FXParametersModel implements ParametersModel { IntegerProperty fontSizeProperty() { return fontSize; } + + @Override + public int maxLineLength() { + return maxLineLength.get(); + } + + @Override + public void setMaxLineLength(final int maxLineLength) { + this.maxLineLength.set(maxLineLength); + } + + IntegerProperty maxLineLengthProperty() { + return maxLineLength; + } + + @Override + public int maxLines() { + return maxLines.get(); + } + + @Override + public void setMaxLines(final int maxLines) { + this.maxLines.set(maxLines); + } + + IntegerProperty maxLinesProperty() { + return maxLines; + } } diff --git a/gui/fx/src/main/java/com/github/gtache/autosubtitle/gui/fx/FXSetupController.java b/gui/fx/src/main/java/com/github/gtache/autosubtitle/gui/fx/FXSetupController.java index 9312420..aa9fb74 100644 --- a/gui/fx/src/main/java/com/github/gtache/autosubtitle/gui/fx/FXSetupController.java +++ b/gui/fx/src/main/java/com/github/gtache/autosubtitle/gui/fx/FXSetupController.java @@ -314,7 +314,7 @@ public class FXSetupController extends AbstractFXController implements SetupCont } @Override - protected Window window() { + public Window window() { return converterNameLabel.getScene().getWindow(); } } diff --git a/gui/fx/src/main/java/com/github/gtache/autosubtitle/gui/fx/FXSubtitlesController.java b/gui/fx/src/main/java/com/github/gtache/autosubtitle/gui/fx/FXSubtitlesController.java index db151d6..d5811b9 100644 --- a/gui/fx/src/main/java/com/github/gtache/autosubtitle/gui/fx/FXSubtitlesController.java +++ b/gui/fx/src/main/java/com/github/gtache/autosubtitle/gui/fx/FXSubtitlesController.java @@ -1,7 +1,6 @@ package com.github.gtache.autosubtitle.gui.fx; import com.github.gtache.autosubtitle.Language; -import com.github.gtache.autosubtitle.Translator; import com.github.gtache.autosubtitle.gui.SubtitlesController; import com.github.gtache.autosubtitle.gui.TimeFormatter; import com.github.gtache.autosubtitle.subtitle.SubtitleCollection; @@ -9,6 +8,8 @@ import com.github.gtache.autosubtitle.subtitle.SubtitleImporterExporter; import com.github.gtache.autosubtitle.subtitle.converter.ParseException; import com.github.gtache.autosubtitle.subtitle.gui.fx.ObservableSubtitleCollectionImpl; import com.github.gtache.autosubtitle.subtitle.gui.fx.ObservableSubtitleImpl; +import com.github.gtache.autosubtitle.translation.TranslationException; +import com.github.gtache.autosubtitle.translation.Translator; import javafx.application.Platform; import javafx.beans.binding.Bindings; import javafx.beans.property.SimpleObjectProperty; @@ -39,6 +40,7 @@ import java.util.Comparator; import java.util.List; import java.util.ResourceBundle; import java.util.concurrent.CompletableFuture; +import java.util.concurrent.CompletionException; import static java.util.Objects.requireNonNull; @@ -129,19 +131,30 @@ public class FXSubtitlesController extends AbstractFXController implements Subti } }); - translationsCombobox.valueProperty().addListener((observable, oldValue, newValue) -> { - if (newValue != null && !model.collections().containsKey(newValue)) { + translationsCombobox.setOnAction(e -> { + final var value = translationsCombobox.getValue(); + if (value != null && !model.collections().containsKey(value)) { model.setTranslating(true); - CompletableFuture.supplyAsync(() -> translator.translate(model.collections().get(model.videoLanguage()), newValue)) - .whenCompleteAsync((r, t) -> { - if (t == null) { - loadCollection(r); - model.setSelectedCollection(model.collections().get(newValue)); - } else { - logger.error("Error while translating to {}", newValue, t); - } - model.setTranslating(false); - }, Platform::runLater); + CompletableFuture.supplyAsync(() -> { + final var mainCollection = model.collections().get(model.videoLanguage()); + try { + if (mainCollection == null) { + return translator.translate(model.selectedCollection(), value); + } else { + return translator.translate(mainCollection, value); + } + } catch (final TranslationException ex) { + throw new CompletionException(ex); + } + }).whenCompleteAsync((r, t) -> { + if (t == null) { + loadCollection(r); + model.setSelectedCollection(model.collections().get(value)); + } else { + logger.error("Error while translating to {}", value, t); + } + model.setTranslating(false); + }, Platform::runLater); } }); binder.createBindings(); @@ -197,7 +210,7 @@ public class FXSubtitlesController extends AbstractFXController implements Subti final var toRemove = new ArrayList(); final var toAdd = new ArrayList(); tabPane.getTabs().forEach(tab -> { - if (!model.collections().containsKey(Language.getLanguage(tab.getText()))) { + if (tab != mainSubtitlesTab && !model.collections().containsKey(Language.getLanguage(tab.getText()))) { toRemove.add(tab); } }); @@ -237,7 +250,9 @@ public class FXSubtitlesController extends AbstractFXController implements Subti filePicker.getExtensionFilters().addAll(archiveFilter, allSupportedFilter); filePicker.setSelectedExtensionFilter(allSupportedFilter); final var file = filePicker.showOpenDialog(window()); - loadSubtitles(file.toPath()); + if (file != null) { + loadSubtitles(file.toPath()); + } } @FXML @@ -283,10 +298,11 @@ public class FXSubtitlesController extends AbstractFXController implements Subti public void loadSubtitles(final Path file) { try { final var map = importerExporter.importSubtitles(file); - map.values().forEach(this::loadCollection); if (model.videoLanguage() == Language.AUTO) { model.setVideoLanguage(map.keySet().stream().findFirst().orElse(Language.AUTO)); } + map.values().forEach(this::loadCollection); + model.setSelectedCollection(model.collections().get(map.keySet().iterator().next())); } catch (final IOException | ParseException e) { logger.error("Error loading subtitles {}", file, e); showErrorDialog(resources.getString("subtitles.load.error.title"), MessageFormat.format(resources.getString("subtitles.load.error.label"), file)); @@ -316,7 +332,7 @@ public class FXSubtitlesController extends AbstractFXController implements Subti } @Override - protected Window window() { + public Window window() { return saveButton.getScene().getWindow(); } } diff --git a/gui/fx/src/main/java/com/github/gtache/autosubtitle/modules/gui/fx/FXModule.java b/gui/fx/src/main/java/com/github/gtache/autosubtitle/modules/gui/fx/FXModule.java index 0c56912..dc8b728 100644 --- a/gui/fx/src/main/java/com/github/gtache/autosubtitle/modules/gui/fx/FXModule.java +++ b/gui/fx/src/main/java/com/github/gtache/autosubtitle/modules/gui/fx/FXModule.java @@ -10,6 +10,7 @@ import com.github.gtache.autosubtitle.gui.fx.FXSubtitlesController; import com.github.gtache.autosubtitle.gui.fx.FXWorkController; import com.github.gtache.autosubtitle.modules.gui.impl.Pause; import com.github.gtache.autosubtitle.modules.gui.impl.Play; +import com.github.gtache.autosubtitle.modules.setup.gui.fx.FXSetupModule; import dagger.Binds; import dagger.Module; import dagger.Provides; @@ -19,12 +20,11 @@ import javafx.scene.image.Image; import javax.inject.Singleton; import java.io.ByteArrayInputStream; import java.util.ResourceBundle; -import java.util.prefs.Preferences; /** * Dagger module for FX */ -@Module +@Module(includes = FXSetupModule.class) public abstract class FXModule { @Binds @@ -69,10 +69,4 @@ public abstract class FXModule { static Image providesPauseImage(@Pause final byte[] pauseImage) { return new Image(new ByteArrayInputStream(pauseImage)); } - - @Provides - @Singleton - static Preferences providesPreferences() { - return Preferences.userNodeForPackage(FXParametersController.class); - } } diff --git a/gui/fx/src/main/java/com/github/gtache/autosubtitle/modules/setup/gui/fx/FXSetupModule.java b/gui/fx/src/main/java/com/github/gtache/autosubtitle/modules/setup/gui/fx/FXSetupModule.java new file mode 100644 index 0000000..dd82fca --- /dev/null +++ b/gui/fx/src/main/java/com/github/gtache/autosubtitle/modules/setup/gui/fx/FXSetupModule.java @@ -0,0 +1,19 @@ +package com.github.gtache.autosubtitle.modules.setup.gui.fx; + +import com.github.gtache.autosubtitle.setup.SetupUserBridge; +import com.github.gtache.autosubtitle.setup.gui.fx.FXSetupUserBridge; +import dagger.Binds; +import dagger.Module; + +/** + * Dagger module for FX setup + */ +@Module +public abstract class FXSetupModule { + + private FXSetupModule() { + } + + @Binds + abstract SetupUserBridge bindsSetupUserBridge(final FXSetupUserBridge setupUserBridge); +} diff --git a/gui/fx/src/main/java/com/github/gtache/autosubtitle/setup/gui/fx/FXSetupUserBridge.java b/gui/fx/src/main/java/com/github/gtache/autosubtitle/setup/gui/fx/FXSetupUserBridge.java new file mode 100644 index 0000000..ee79b8e --- /dev/null +++ b/gui/fx/src/main/java/com/github/gtache/autosubtitle/setup/gui/fx/FXSetupUserBridge.java @@ -0,0 +1,64 @@ +package com.github.gtache.autosubtitle.setup.gui.fx; + +import com.github.gtache.autosubtitle.gui.fx.FXMainController; +import com.github.gtache.autosubtitle.setup.SetupUserBridge; +import javafx.scene.control.Alert; +import javafx.scene.control.ButtonType; +import javafx.scene.control.ChoiceDialog; +import javafx.scene.control.TextInputDialog; + +import javax.inject.Inject; +import java.util.List; +import java.util.Objects; + +/** + * FX implementation of {@link SetupUserBridge} + */ +public class FXSetupUserBridge implements SetupUserBridge { + + private final FXMainController controller; + + @Inject + FXSetupUserBridge(final FXMainController mainController) { + this.controller = Objects.requireNonNull(mainController); + } + + @Override + public boolean askForUserConfirmation(final String question) { + return showConfirmationDialog("Confirmation", question); + } + + @Override + public T askForUserChoice(final String question, final List choices) { + return showChoiceDialog("Choice", question, choices); + } + + @Override + public String askForUserInput(final String question) { + return showInputDialog("Input", question); + } + + private T showChoiceDialog(final String title, final String message, final List choices) { + final var dialog = new ChoiceDialog<>(choices.getFirst(), choices); + dialog.initOwner(controller.window()); + dialog.setHeaderText(message); + dialog.setTitle(title); + return dialog.showAndWait().orElse(null); + } + + private String showInputDialog(final String title, final String message) { + final var dialog = new TextInputDialog(); + dialog.initOwner(controller.window()); + dialog.setHeaderText(message); + dialog.setTitle(title); + return dialog.showAndWait().orElse(null); + } + + private boolean showConfirmationDialog(final String title, final String message) { + final var alert = new Alert(Alert.AlertType.CONFIRMATION, message, ButtonType.YES, ButtonType.NO); + alert.initOwner(controller.window()); + alert.setHeaderText(null); + alert.setTitle(title); + return alert.showAndWait().map(bt -> bt == ButtonType.YES).orElse(false); + } +} diff --git a/gui/fx/src/main/java/module-info.java b/gui/fx/src/main/java/module-info.java index 76762b0..e710571 100644 --- a/gui/fx/src/main/java/module-info.java +++ b/gui/fx/src/main/java/module-info.java @@ -13,7 +13,8 @@ module com.github.gtache.autosubtitle.gui.fx { requires transitive java.prefs; exports com.github.gtache.autosubtitle.gui.fx; - exports com.github.gtache.autosubtitle.modules.gui.fx; + exports com.github.gtache.autosubtitle.setup.gui.fx; exports com.github.gtache.autosubtitle.subtitle.gui.fx; + exports com.github.gtache.autosubtitle.modules.gui.fx; opens com.github.gtache.autosubtitle.gui.fx to javafx.fxml; } \ No newline at end of file diff --git a/gui/fx/src/main/resources/com/github/gtache/autosubtitle/gui/fx/parametersView.fxml b/gui/fx/src/main/resources/com/github/gtache/autosubtitle/gui/fx/parametersView.fxml index 94b6cf4..67a52d8 100644 --- a/gui/fx/src/main/resources/com/github/gtache/autosubtitle/gui/fx/parametersView.fxml +++ b/gui/fx/src/main/resources/com/github/gtache/autosubtitle/gui/fx/parametersView.fxml @@ -4,37 +4,42 @@ - + + + - + + - - + + - - - - - + + + + + + + -