diff --git a/.idea/compiler.xml b/.idea/compiler.xml
new file mode 100644
index 000000000..56784efc1
--- /dev/null
+++ b/.idea/compiler.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/encodings.xml b/.idea/encodings.xml
new file mode 100644
index 000000000..aa00ffab7
--- /dev/null
+++ b/.idea/encodings.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 000000000..f0f82878c
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
new file mode 100644
index 000000000..ab823708d
--- /dev/null
+++ b/.idea/workspace.xml
@@ -0,0 +1,153 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1731351667015
+
+
+ 1731351667015
+
+
+
+
+ 1731353731247
+
+
+
+ 1731353731247
+
+
+
+ 1731353769644
+
+
+
+ 1731353769644
+
+
+
+ 1731353837715
+
+
+
+ 1731353837715
+
+
+
+ 1731353942246
+
+
+
+ 1731353942246
+
+
+
+ 1731354055843
+
+
+
+ 1731354055843
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/LICENSE b/LICENSE
index 0e259d42c..1625c1793 100644
--- a/LICENSE
+++ b/LICENSE
@@ -118,4 +118,4 @@ express Statement of Purpose.
Work.
d. Affirmer understands and acknowledges that Creative Commons is not a
party to this document and has no duty or obligation with respect to
- this CC0 or use of the Work.
+ this CC0 or use of the Work.
\ No newline at end of file
diff --git a/README.md b/README.md
index 5e1d8b77c..373df73b7 100644
--- a/README.md
+++ b/README.md
@@ -1,36 +1,192 @@
-# Note Application
+# The Translator
+## Contributors and GitHub Usernames:
+Julia Zaki / julia-zaki
-This is a minimal example demonstrating usage of the
-password-protected user part of the API used in lab 5.
+Christina Huang / HChristinaH
-You can find more information about the API endpoints in
-[the documentation](https://www.postman.com/cloudy-astronaut-813156/csc207-grade-apis-demo/documentation/fg3zkjm/5-password-protected-user).
+Edan Wong / 903Edan
-If your team is considering an application for which it would be convenient to
-store data in something like a database, you may find that the API calls demonstrated
-here will be useful in your project, as this will allow you to store
-an arbitrary JSON object associated with a username and password.
+Manjun Zhu / Karrrrmen
-In this application, a single note has a name (the "username" in terms of the API) and the note
-can be read by anyone who knows the name — but only edited by someone who
-knows the password for it.
+Mingyu (Roy) Son / SonM12
-You can see the documentation in the various files for more information.
+## Table of Contents
-## Testing
+1. [Summary of the project's purpose](#1-summary-of-the-projects-purpose)
-The repo also includes an example of a use case interactor test, as well as
-an example of an end-to-end test which automates button clicks and inspects
-the contents of the actual views. This is something we discussed in the lectures
-about testing in CA but had not provided a code example of before. Note, one
-could also inspect the contents of the ViewModel objects instead when testing
-CA to make a similar test which would be less dependent on the details of the
-specific UI implementation.
+2. [Features of the Software](#2-features-of-the-software)
-## Project Starter Code
+3. [Installation Instructions](#3-installation-instructions)
-Your team may choose to use this repo as starter code for your project. You could
-also use the lab 5 code — or start from an empty repo if your team prefers.
+4. [Usage guide](#4-usage-guide)
-If you choose to use one of the repositories we have provided, you can either make
-a fork of it or copy the subset of code you want into a completely new repository.
+5. [License](#5-license)
+
+6. [Feedback](#6-feedback)
+
+7. [Contributions](#7-contributions)
+
+
+## 1. Summary of the project's purpose
+The program is a translation tool designed to help users for translating text and files between multiple
+languages, switching between input and output languages, converting images to text for translation, providing
+pronounciation of the translated text and usage-tracking for character used. The program aims to solve problems
+regarding language barriers bewteen different media. This program is useful for new language learners, people who
+work with foreign language materials, or people who need efficient translation tools to encounter everyday situations.
+
+## 2. Features of the Software
+
+The Translator has mutlitple features which include:
+
+
+1. **Translate Text**
+
+The translate text use case allows the user to translate text from one language to another.
+
+Example user story:
+Emily is learning Spanish for the first time. Her Spanish assingment requires her to write about her summer vacation.
+However, Emily forgot how to say "beach" in Spanish. She uses The Translator to translate the word "beach" from English
+to Spanish. The Translator gives her back "playa" which is the correct Spanish word for "beach".
+
+Example use case tutorial:
+
+[Text Translator Demo](Resources/Translate%20Text.mov)
+
+2. **Switch Translation**
+
+The switch translation use case allows the user to switch the input language to become the ouput language and
+vice-versa. It also allows the user to switch the input text to become the ouput text and
+vice-versa.
+
+Example user story:
+Julia is translating a sentence from English to her second language, French. She wants to make sure that the generated
+translation is correct. She clicks the switch button and ends up with the translated French sentence as the input and
+the English sentence she originally wrote as the output. She reads that English translation and sees that it makes
+sense and does communicate the same point as what she had originally written (it could be the exact same thing she had
+inputted but sometimes translators can alter the sentence). This helped her ensure that the French translation that was
+generated by the program was indeed correct.
+
+Example use case tutorial:
+
+[Switch Translation Demo](Resources/Switch.mov)
+
+3. **Translate File**
+
+The translate file use case allows the user to input a file and translate the text in the file into their chosen
+language.
+
+Example user story:
+Edan is currently enrolled in a Korean learning course and several course materials are distributed in different
+format of files. He wants those text in the files to be translated directly into his mother language so that he
+does not have to copy and paste the text from the file into the translator. Therefore, he uses the
+translate-file feature to translate the materials in an efficient way.
+
+Example use case tutorial:
+
+[Translate File Demo](Resources/TranslateFileUseCase.mp4)
+
+4. **Translate Image**
+
+The translate image use case allows the user to input an image and translate the text in the image into their chosen
+language.
+
+Example user story:
+Christina is studying abroad in Japan and sees a sign at a subway. She is not very familiar with Japanese and she
+cannot easily type in the characters into her translation app so she uses the convert image to text feature to take
+a picture and translate the sign.
+
+Example use case tutorial:
+
+[Translate Image Demo](Resources/ImageUploadDemo.mp4)
+
+5. **Check Usage**
+
+The check usage use case allows the user to check whether their input text is within the free-tier limit of the
+translator to avoid payments.
+
+Example user story:
+Karmen is working on a history assignment that requires translating a lengthy article from a foreign language.
+To ensure she stays within the free-tier limits of the translation service, she needs to monitor the character count
+and limit from the App. Using the "CheckUsage" feature, Karmen can track her usage, avoid exceeding the limit and
+complete her assignment without unexpected costs.
+
+Example use case tutorial:
+
+[Check Usage Demo](Resources/CheckUsageDemo.mov)
+
+6. **Text to Speech**
+
+The text to speech use case allows the user to listen to the pronounciation of the translated text.
+
+Example user story:
+As an international student, Roy is studying English in order to prepare for his English proficiency test. However, while studying the subject,
+he came across some words or sentences he does not know how to pronounce. Using the speaker button located at the
+bottom right side of text boxes, Roy can listen to the speech.
+
+Example use case tutorial:
+
+[Text to Speech Demo](Resources/TextToSpeechUseCase.mp4)
+
+
+## 3. Installation Instructions
+This Translator Program requires installation of FreeTTS.
+1. Download the latest FreeTTS zip file from https://sourceforge.net/projects/freetts/files/ .
+2. Extract downloaded zip file.
+3. Browse to the following path.
+ * freetts-1.2.2-bin/freetts-1.2/lib/
+4. Run jsapi.exe file and install freeTTS
+ * For Mac users, open terminal and browse to the extracted /lib folder.
+ * chmod +x ./jsapi.sh and afterwards sh ./jsapi.sh
+5. Check jsapi.jar file is installed in the /lib folder.
+6. Include /lib folder into the project.
+ 1. File -> project structure -> Project Settings -> Modules
+ 2. Click "+" icon, then select "1 JARs or Directories"
+ 3. Select the entire /lib folder.
+ 4. Apply then OK.
+
+
+
+## 4. Usage guide
+1. Ensure you have Java (preferably v.11) Installed. If you do not, follow the instructions in this link:
+ https://www.java.com/en/download/help/download_options.html
+2. Fork and clone the repository and open it in IntelliJ.
+3. If you notice that some files are underlined in red, try reloading maven.
+4. Head to the README file and follow the instruction in [Installation Instructions](#3-installation-instructions)
+5. Then go to the [Features of the Software](#2-features-of-the-software) section and start exploring the software
+ with your features of choice.
+6. Once you are done head to the [Feedback](#6-feedback) section and complete feedback form. This will help us improve
+ the software!
+7. You can also make a contribution if you head over to [Contributions](#7-contributions).
+
+## 5. License
+License is in the Project file.
+
+## 6. Feedback
+Users can give feedback via the Google forms link below.
+
+We believe valid feedback is in the form of what was done well and what could be improved. Your feedback should target usability and simplicity of use, performance, presence of bugs and suggestions for new features.
+Feedback allows us to collect valuable insights from users to help us enhance the functionality, usability, and overall user experience of the software.
+
+_Guidelines for what to expect when submitting your feedback:_
+
+Providing your feedback: Submit your feedback while considering what counts as valid feedback for us (as mentioned above). Share your experiences and areas of improvements.
+How we review your feedback: Upon submitting your feedback, we will review it thoroughly. Feedback regarding bugs and issues will be addressed immediately to ensure the software works correctly for its current users. Constructive feedback will be taken into consideration during future improvements of the software.
+Updates: Suggestions and fixes may take time implement so make sure you look out for updates of the software as soon as they become available.
+Stay engaged: Feel free to provide your feedback at any time. Your feedback helps us improve The Translator!!
+
+Google form link:
+https://forms.gle/XRTDruZFNydroKSE9
+
+## 7. Contributions
+To contribute to this project, open an issue or submit a merge request.
+
+To fork this project on GitHub, click the fork button in the top right of the repository.
+Provide a brief description of the changes you intend on making to the project, and click the “Create Fork” button.
+
+In your merge request, please summarize with clarity which files were modified and what files were added.
+Make sure to explain why these changes were necessary.
+
+The protocols for reviewing contributions are as follows:
+Your code should have clean coding style and code correctness, include tests and state test coverage,
+adhere to Clean Architecture and SOLID principles, and include javadocs that are accurate, clear, complete,
+easy to use, and up to date.
diff --git a/Resources/CheckUsageDemo.mov b/Resources/CheckUsageDemo.mov
new file mode 100644
index 000000000..4f328f1c7
Binary files /dev/null and b/Resources/CheckUsageDemo.mov differ
diff --git a/Resources/FreeTTS Install.png b/Resources/FreeTTS Install.png
new file mode 100644
index 000000000..9d6e5b916
Binary files /dev/null and b/Resources/FreeTTS Install.png differ
diff --git a/Resources/ImageUploadDemo.mp4 b/Resources/ImageUploadDemo.mp4
new file mode 100644
index 000000000..e30d99bf3
Binary files /dev/null and b/Resources/ImageUploadDemo.mp4 differ
diff --git a/Resources/Switch.mov b/Resources/Switch.mov
new file mode 100644
index 000000000..4820dbe91
Binary files /dev/null and b/Resources/Switch.mov differ
diff --git a/Resources/TextToSpeechUseCase.mp4 b/Resources/TextToSpeechUseCase.mp4
new file mode 100644
index 000000000..32dee55dd
Binary files /dev/null and b/Resources/TextToSpeechUseCase.mp4 differ
diff --git a/Resources/Translate Text.mov b/Resources/Translate Text.mov
new file mode 100644
index 000000000..eef715f53
Binary files /dev/null and b/Resources/Translate Text.mov differ
diff --git a/Resources/TranslateFileUseCase.mp4 b/Resources/TranslateFileUseCase.mp4
new file mode 100644
index 000000000..e7f9c5e12
Binary files /dev/null and b/Resources/TranslateFileUseCase.mp4 differ
diff --git a/Resources/imageInFrench.png b/Resources/imageInFrench.png
new file mode 100644
index 000000000..0eec65a1d
Binary files /dev/null and b/Resources/imageInFrench.png differ
diff --git a/Resources/imageNoText.gif b/Resources/imageNoText.gif
new file mode 100644
index 000000000..501c6a839
Binary files /dev/null and b/Resources/imageNoText.gif differ
diff --git a/Resources/speaker_resized.png b/Resources/speaker_resized.png
new file mode 100644
index 000000000..e6af3f4dd
Binary files /dev/null and b/Resources/speaker_resized.png differ
diff --git a/Result_TestFileTranslation.txt b/Result_TestFileTranslation.txt
new file mode 100644
index 000000000..d0d48dda4
--- /dev/null
+++ b/Result_TestFileTranslation.txt
@@ -0,0 +1,3 @@
+C'est l'heure. Il est 2 heures du matin.
+Peux-tu baisser la voix et chuchoter davantage ?
+Quand cette nuit devient un peu plus profonde
diff --git a/TestFileTranslation.txt b/TestFileTranslation.txt
new file mode 100644
index 000000000..39dddf46e
--- /dev/null
+++ b/TestFileTranslation.txt
@@ -0,0 +1,3 @@
+시간이 됐어 it's 2AM
+목소릴 낮추고 더 속삭여줄래?
+이 밤이 좀 더 깊어지면
\ No newline at end of file
diff --git a/TestingFileTranslation.txt b/TestingFileTranslation.txt
new file mode 100644
index 000000000..c3a68a9b7
--- /dev/null
+++ b/TestingFileTranslation.txt
@@ -0,0 +1,4 @@
+시간이 됐어 it's 2AM
+목소릴 낮추고 더 속삭여줄래?
+이 밤이 좀 더 깊어지면
+뭔가 더 솔직해도 될 것 같은 기분이 들어
\ No newline at end of file
diff --git a/accessibility-report.md b/accessibility-report.md
new file mode 100644
index 000000000..c3589f0fd
--- /dev/null
+++ b/accessibility-report.md
@@ -0,0 +1,39 @@
+## Principle of Universal Design
+
+1) Equitable Use (YES)
+ * All input format requirements are the same for all users, ensuring fairness in accessing program's features
+
+2) Flexibility in Use (YES)
+ * Provided translation various input types, like text, files and image
+ * Allow usage tracking for characters used, which is beyond solving language related problem
+
+3) Simple and Intuitive Use (NO)
+ * Initial interface is in English, which requires users to understand basic English before operating the program
+
+4) Perceptible Information (YES)
+ * Buttons' labels differntiate by their features, which direct users to feature easily
+
+5) Tolerance for Error (YES)
+ * All errors can be retrieved by re-entering the input and preventing the program from crashing
+
+6) Low Physical Effort (YES)
+ * Buttons are gathered in a line, which minimize effort to find all program's features
+
+7) Size and Space for Approach and Use
+ * Buttons are appropriate in size and are for easy tapping, which make reaching to all features comfortable
+
+## Marketed Audience
+The program will be marketed towards students who are seeking a flexible learning tool or native English learners
+who wish to practice their oral skill and tourists who need to translation on signs in foreign countries.
+Despite the general text translation features, this program features text-to-speech translation for English,
+which is aiming to assist people with improving English proficiency. The imageTranslation able to detect text
+in a picture and translated them in desired language, which is great for understanding road sign or instructions
+in foreign countries.
+
+## Non-benifited Audiences
+Non-English speakers or individuals who do not know English are the potential demographics who are less likely to
+use our program. Although our program support languages translated into English, for those who are not proficient
+in English might struggle to fully understand the functionality of our program as the interface is primarily in
+English, where primarily instruction like titles, labels and buttons are in English. One possible solution to resolve
+these issue is to include a multilingual interface of the program or add icon next to button to reduce the dependency
+of requiring users to understand instruction in English.
diff --git a/pom.xml b/pom.xml
index 527f61e36..15d17aeab 100644
--- a/pom.xml
+++ b/pom.xml
@@ -28,6 +28,18 @@
test
+
+ com.deepl.api
+ deepl-java
+ 1.6.0
+
+
+
+ commons-io
+ commons-io
+ 2.15.1
+
+
diff --git a/src/main/java/app/CheckUsageAppBuilder.java b/src/main/java/app/CheckUsageAppBuilder.java
new file mode 100644
index 000000000..cd954f40e
--- /dev/null
+++ b/src/main/java/app/CheckUsageAppBuilder.java
@@ -0,0 +1,83 @@
+package app;
+
+import javax.swing.JFrame;
+import javax.swing.WindowConstants;
+
+import entity.CheckUsage;
+import interface_adapter.checkUsage.CheckUsageController;
+import interface_adapter.checkUsage.CheckUsagePresenter;
+import interface_adapter.checkUsage.CheckUsageViewModel;
+import use_case.checkUsage.CheckUsageDataAccessInterface;
+import use_case.checkUsage.CheckUsageInteractor;
+import use_case.checkUsage.CheckUsageOutputBoundary;
+import view.checkUsage.CheckUsageView;
+
+/**
+ * Builder for the File Translator Application.
+ */
+
+public class CheckUsageAppBuilder {
+ public static final int HEIGHT = 250;
+ public static final int WIDTH = 400;
+ private CheckUsageDataAccessInterface checkUsageDAO;
+ private CheckUsageViewModel checkUsageViewModel = new CheckUsageViewModel();
+ private CheckUsageView checkUsageView;
+ private CheckUsageInteractor checkUsageInteractor;
+
+ /**
+ * Sets the checkUsageDAO to be used in this application.
+ * @param checkUsageDataAccess the DAO to use
+ * @return this builder
+ */
+ public CheckUsageAppBuilder addCheckUsageDAO(CheckUsageDataAccessInterface checkUsageDataAccess) {
+ checkUsageDAO = checkUsageDataAccess;
+ return this;
+ }
+
+ /**
+ * Creates the objects for the CheckUsage Use Case and connects the CheckUsageView to its
+ * controller.
+ *
This method must be called after addCheckUsageView!
+ * @return this builder
+ * @throws RuntimeException if this method is called before addCheckUsageView
+ */
+ public CheckUsageAppBuilder addCheckUsageUseCase() {
+ final CheckUsageOutputBoundary checkUsageOutputBoundary =
+ new CheckUsagePresenter(checkUsageViewModel);
+ final CheckUsage checkUsage = new CheckUsage(checkUsageDAO);
+
+ checkUsageInteractor = new CheckUsageInteractor(checkUsageDAO, checkUsageOutputBoundary,
+ checkUsage);
+
+ final CheckUsageController controller = new CheckUsageController(checkUsageInteractor);
+ if (checkUsageView == null) {
+ throw new RuntimeException("addCheckUsageView must be called before addCheckUsageUseCase");
+ }
+ checkUsageView.setCheckUsageController(controller);
+ return this;
+ }
+
+ /**
+ * Creates the CheckUsageView and underlying CheckUsageViewModel.
+ * @return this builder
+ */
+ public CheckUsageAppBuilder addCheckUsageView() {
+ checkUsageViewModel = new CheckUsageViewModel();
+ checkUsageView = new CheckUsageView(checkUsageViewModel);
+ return this;
+ }
+
+ /**
+ * Builds the translator application.
+ * @return the JFrame for the application
+ */
+ public JFrame build() {
+ final JFrame frame = new JFrame();
+ frame.setTitle("Translator Application - User Usage");
+ frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
+ frame.setSize(WIDTH, HEIGHT);
+ frame.add(checkUsageView);
+
+ return frame;
+ }
+}
diff --git a/src/main/java/app/MainNoteApplication.java b/src/main/java/app/MainNoteApplication.java
deleted file mode 100644
index c37860156..000000000
--- a/src/main/java/app/MainNoteApplication.java
+++ /dev/null
@@ -1,56 +0,0 @@
-package app;
-
-import data_access.DBNoteDataAccessObject;
-import use_case.note.NoteDataAccessInterface;
-
-/**
- * An application where we can view and add to a note stored by a user.
- *
- * This is a minimal example of using the password-protected user API from lab 5,
- * but demonstrating the endpoint allowing you to store an arbitrary JSON object.
- * This functionality could be used in any project where your team wants to persist
- * data which is then accessible across devices.
- *
The code is intentionally somewhat incomplete to leave work to be done if your
- * team were to choose to work on a project which would require similar functionality.
- * For example, we have intentionally not created a full "Note" entity here, but
- * rather just represented a note as a string.
- *
- * The ViewManager code has also been removed, since this minimal program only requires a single
- * view. Your team may wish to bring back the ViewManager or make your own implementation of supporting
- * switching between views depending on your project.
- */
-public class MainNoteApplication {
-
- /**
- * The main entry point of the application.
- *
- * The program will show you the note currently saved in the system.
- * You are able to edit it and then save it to the system. You can refresh
- * to update the note to reflect what was saved most recently. This
- * uses the API from lab, so there is one database storing the note,
- * which means that if anyone updates the note, that is what you will
- * see when you refresh.
- *
- * You can generalize the code to allow you to
- * specify which "user" to save the note for, which will allow your team
- * to store information specific to your team which is password-protected.
- * The username and password used in this application are currently for
- * user jonathan_calver2, but you can change that. As you did in lab 3,
- * you will likely want to store password information locally rather than
- * in your repo. Or you can require the user to enter their credentials
- * in your application; it just depends on what your program's main
- * functionality.
- *
- * @param args commandline arguments are ignored
- */
- public static void main(String[] args) {
-
- // create the data access and inject it into our builder!
- final NoteDataAccessInterface noteDataAccess = new DBNoteDataAccessObject();
-
- final NoteAppBuilder builder = new NoteAppBuilder();
- builder.addNoteDAO(noteDataAccess)
- .addNoteView()
- .addNoteUseCase().build().setVisible(true);
- }
-}
diff --git a/src/main/java/app/MainTranslatorApplication.java b/src/main/java/app/MainTranslatorApplication.java
new file mode 100644
index 000000000..aa27ac019
--- /dev/null
+++ b/src/main/java/app/MainTranslatorApplication.java
@@ -0,0 +1,40 @@
+package app;
+
+import data_access.DBImageUploadDataAccessObject;
+import data_access.DBTranslateTextDataAccessObject;
+import use_case.imageUpload.ImageUploadDataAccessInterface;
+import use_case.switchTranslation.SwitchTranslationDataAccessInterface;
+import use_case.translateText.TranslateTextDataAccessInterface;
+
+/**
+ * An application where we can translate text.
+ */
+public class MainTranslatorApplication {
+
+ /**
+ * The main entry point of the application.
+ * The program will show you the input and output language drop-down box and will allow you
+ * to type text in a textbox. You can then click Translate Text and your text will be translated.
+ * This uses the DeepL API.
+ * @param args commandline arguments are ignored
+ */
+ public static void main(String[] args) {
+
+ // create the data access and inject it into our builder!
+ final TranslateTextDataAccessInterface translateTextDataAccess = new DBTranslateTextDataAccessObject();
+ final ImageUploadDataAccessInterface imageUploadDataAccess = new DBImageUploadDataAccessObject();
+ final SwitchTranslationDataAccessInterface switchTranslationDataAccess = new DBTranslateTextDataAccessObject();
+
+ final app.TranslateTextAppBuilder builder = new app.TranslateTextAppBuilder();
+ builder.addTranslateTextDAO(translateTextDataAccess)
+ .addImageUploadDAO(imageUploadDataAccess)
+ .addSwitchTranslationDAO(switchTranslationDataAccess)
+ .addTranslateTextView()
+ .addTranslateTextUseCase()
+ .addSwitchTranslationUseCase()
+ .addImageUploadUseCase()
+ .addTextToSpeechUseCase()
+ .build().setVisible(true);
+
+ }
+}
diff --git a/src/main/java/app/NoteAppBuilder.java b/src/main/java/app/NoteAppBuilder.java
deleted file mode 100644
index a68cb9ad6..000000000
--- a/src/main/java/app/NoteAppBuilder.java
+++ /dev/null
@@ -1,83 +0,0 @@
-package app;
-
-import javax.swing.JFrame;
-import javax.swing.WindowConstants;
-
-import interface_adapter.note.NoteController;
-import interface_adapter.note.NotePresenter;
-import interface_adapter.note.NoteViewModel;
-import use_case.note.NoteDataAccessInterface;
-import use_case.note.NoteInteractor;
-import use_case.note.NoteOutputBoundary;
-import view.NoteView;
-
-/**
- * Builder for the Note Application.
- */
-public class NoteAppBuilder {
- public static final int HEIGHT = 300;
- public static final int WIDTH = 400;
- private NoteDataAccessInterface noteDAO;
- private NoteViewModel noteViewModel = new NoteViewModel();
- private NoteView noteView;
- private NoteInteractor noteInteractor;
-
- /**
- * Sets the NoteDAO to be used in this application.
- * @param noteDataAccess the DAO to use
- * @return this builder
- */
- public NoteAppBuilder addNoteDAO(NoteDataAccessInterface noteDataAccess) {
- noteDAO = noteDataAccess;
- return this;
- }
-
- /**
- * Creates the objects for the Note Use Case and connects the NoteView to its
- * controller.
- *
This method must be called after addNoteView!
- * @return this builder
- * @throws RuntimeException if this method is called before addNoteView
- */
- public NoteAppBuilder addNoteUseCase() {
- final NoteOutputBoundary noteOutputBoundary = new NotePresenter(noteViewModel);
- noteInteractor = new NoteInteractor(
- noteDAO, noteOutputBoundary);
-
- final NoteController controller = new NoteController(noteInteractor);
- if (noteView == null) {
- throw new RuntimeException("addNoteView must be called before addNoteUseCase");
- }
- noteView.setNoteController(controller);
- return this;
- }
-
- /**
- * Creates the NoteView and underlying NoteViewModel.
- * @return this builder
- */
- public NoteAppBuilder addNoteView() {
- noteViewModel = new NoteViewModel();
- noteView = new NoteView(noteViewModel);
- return this;
- }
-
- /**
- * Builds the application.
- * @return the JFrame for the application
- */
- public JFrame build() {
- final JFrame frame = new JFrame();
- frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
- frame.setTitle("Note Application");
- frame.setSize(WIDTH, HEIGHT);
-
- frame.add(noteView);
-
- // refresh so that the note will be visible when we start the program
- noteInteractor.executeRefresh();
-
- return frame;
-
- }
-}
diff --git a/src/main/java/app/TranslateFileAppBuilder.java b/src/main/java/app/TranslateFileAppBuilder.java
new file mode 100644
index 000000000..dc42b774b
--- /dev/null
+++ b/src/main/java/app/TranslateFileAppBuilder.java
@@ -0,0 +1,83 @@
+package app;
+
+import javax.swing.JFrame;
+import javax.swing.WindowConstants;
+
+import entity.FileTranslator;
+import interface_adapter.translateFile.TranslateFileController;
+import interface_adapter.translateFile.TranslateFilePresenter;
+import interface_adapter.translateFile.TranslateFileViewModel;
+import use_case.translateFile.TranslateFileDataAccessInterface;
+import use_case.translateFile.TranslateFileInteractor;
+import use_case.translateFile.TranslateFileOutputBoundary;
+import view.TranslateFileView;
+
+/**
+ * Builder for the File Translator Application.
+ */
+
+public class TranslateFileAppBuilder {
+ public static final int HEIGHT = 500;
+ public static final int WIDTH = 800;
+ private TranslateFileDataAccessInterface translateFileDAO;
+ private TranslateFileViewModel translateFileViewModel = new TranslateFileViewModel();
+ private TranslateFileView translateFileView;
+ private TranslateFileInteractor translateFileInteractor;
+
+ /**
+ * Sets the translateFileDAO to be used in this application.
+ * @param translateFileDataAccess the DAO to use
+ * @return this builder
+ */
+ public TranslateFileAppBuilder addTranslateFileDAO(TranslateFileDataAccessInterface translateFileDataAccess) {
+ translateFileDAO = translateFileDataAccess;
+ return this;
+ }
+
+ /**
+ * Creates the objects for the TranslateFile Use Case and connects the TranslateFileView to its
+ * controller.
+ *
This method must be called after addTranslateFileView!
+ * @return this builder
+ * @throws RuntimeException if this method is called before addTranslateFileView
+ */
+ public TranslateFileAppBuilder addTranslateFileUseCase() {
+ final TranslateFileOutputBoundary translateFileOutputBoundary =
+ new TranslateFilePresenter(translateFileViewModel);
+ final FileTranslator fileTranslator = new FileTranslator(translateFileDAO);
+
+ translateFileInteractor = new TranslateFileInteractor(translateFileDAO, translateFileOutputBoundary,
+ fileTranslator);
+
+ final TranslateFileController controller = new TranslateFileController(translateFileInteractor);
+ if (translateFileView == null) {
+ throw new RuntimeException("addTranslateFileView must be called before addTranslateFileUseCase");
+ }
+ translateFileView.setTranslateFileController(controller);
+ return this;
+ }
+
+ /**
+ * Creates the TranslateFileView and underlying TranslateFileViewModel.
+ * @return this builder
+ */
+ public TranslateFileAppBuilder addTranslateFileView() {
+ translateFileViewModel = new TranslateFileViewModel();
+ translateFileView = new TranslateFileView(translateFileViewModel);
+ return this;
+ }
+
+ /**
+ * Builds the translator application.
+ * @return the JFrame for the application
+ */
+ public JFrame build() {
+ final JFrame frame = new JFrame();
+ frame.setTitle("Translator Application - File Translation");
+ frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
+ frame.setSize(WIDTH, HEIGHT);
+ frame.add(translateFileView);
+
+ return frame;
+ }
+}
diff --git a/src/main/java/app/TranslateTextAppBuilder.java b/src/main/java/app/TranslateTextAppBuilder.java
new file mode 100644
index 000000000..e88b104aa
--- /dev/null
+++ b/src/main/java/app/TranslateTextAppBuilder.java
@@ -0,0 +1,211 @@
+package app;
+
+import javax.swing.JFrame;
+import javax.swing.WindowConstants;
+
+import entity.TextTranslator;
+import interface_adapter.imageUpload.ImageUploadController;
+import interface_adapter.imageUpload.ImageUploadPresenter;
+import interface_adapter.switchTranslation.SwitchTranslationController;
+import interface_adapter.switchTranslation.SwitchTranslationPresenter;
+import interface_adapter.textToSpeech.TextToSpeechPresenter;
+import interface_adapter.translateText.TranslateTextController;
+import interface_adapter.translateText.TranslateTextPresenter;
+import interface_adapter.translateText.TranslateTextViewModel;
+import use_case.imageUpload.ImageUploadDataAccessInterface;
+import use_case.imageUpload.ImageUploadInteractor;
+import use_case.imageUpload.ImageUploadOutputBoundary;
+import use_case.switchTranslation.SwitchTranslationDataAccessInterface;
+import use_case.switchTranslation.SwitchTranslationInteractor;
+import use_case.switchTranslation.SwitchTranslationOutputBoundary;
+import use_case.textToSpeech.TextToSpeechDataAccessInterface;
+import use_case.textToSpeech.TextToSpeechInteractor;
+import use_case.textToSpeech.TextToSpeechOutputBoundary;
+import use_case.translateText.TranslateTextDataAccessInterface;
+import use_case.translateText.TranslateTextInteractor;
+import use_case.translateText.TranslateTextOutputBoundary;
+import interface_adapter.textToSpeech.TextToSpeechController;
+import view.translateText.TranslateTextView;
+import view.translateText.TranslateTextViewBuilder;
+
+/**
+ * Builder for the Translator Application.
+ */
+public class TranslateTextAppBuilder {
+ public static final int HEIGHT = 500;
+ public static final int WIDTH = 800;
+ private TranslateTextDataAccessInterface translateTextDAO;
+ private ImageUploadDataAccessInterface imageUploadDAO;
+ private SwitchTranslationDataAccessInterface switchTranslationDAO;
+ private TextToSpeechDataAccessInterface textToSpeechDAO;
+ private TranslateTextViewModel translateTextViewModel = new TranslateTextViewModel();
+ private TranslateTextView translateTextView;
+
+ /**
+ * Sets the translatetextDAO to be used in this application.
+ * @param translateTextDataAccess the DAO to use
+ * @return this builder
+ */
+ public TranslateTextAppBuilder addTranslateTextDAO(TranslateTextDataAccessInterface translateTextDataAccess) {
+ translateTextDAO = translateTextDataAccess;
+ return this;
+ }
+
+ /**
+ * Creates the objects for the TranslateText Use Case and connects the TranslateTextView to its
+ * controller.
+ *
This method must be called after addTranslateTextView!
+ * @return this builder
+ * @throws RuntimeException if this method is called before addTranslateTextView
+ */
+ public TranslateTextAppBuilder addTranslateTextUseCase() {
+ final TranslateTextOutputBoundary translateTextOutputBoundary =
+ new TranslateTextPresenter(translateTextViewModel);
+ final TextTranslator textTranslator = new TextTranslator(translateTextDAO);
+
+ final TranslateTextInteractor translateTextInteractor = new TranslateTextInteractor(translateTextDAO,
+ translateTextOutputBoundary,
+ textTranslator);
+
+ final TranslateTextController controller = new TranslateTextController(translateTextInteractor);
+ if (translateTextView == null) {
+ throw new RuntimeException("addTranslateTextView must be called before addTranslateTextUseCase");
+ }
+ translateTextView.setTranslateTextController(controller);
+ return this;
+ }
+
+ /**
+ * Sets the imageUploadDAO to be used in this application.
+ * @param imageUploadDataAccess the DAO to use
+ * @return this builder
+ */
+ public TranslateTextAppBuilder addImageUploadDAO(ImageUploadDataAccessInterface imageUploadDataAccess) {
+ this.imageUploadDAO = imageUploadDataAccess;
+ return this;
+ }
+
+ /**
+ * Creates the objects for the Image Upload Use Case and connects the TranslateTextView to its
+ * controller. Image Upload uses the same view as TranslateTextView.
+ *
This method must be called after addTranslateTextView!
+ * @return this builder
+ * @throws RuntimeException if this method is called before addTranslateTextView
+ */
+ public TranslateTextAppBuilder addImageUploadUseCase() {
+ final ImageUploadOutputBoundary imageUploadOutputBoundary =
+ new ImageUploadPresenter(translateTextViewModel);
+
+ final ImageUploadInteractor imageUploadInteractor = new ImageUploadInteractor(imageUploadDAO,
+ imageUploadOutputBoundary);
+
+ final ImageUploadController controller = new ImageUploadController(imageUploadInteractor);
+ if (translateTextView == null) {
+ throw new RuntimeException("addTranslateTextView must be called before addImageUploadUseCase");
+ }
+ translateTextView.setImageUploadController(controller);
+ return this;
+ }
+
+ /**
+ * Sets the switchTranslationDAO to be used in this application.
+ * @param switchTranslationDataAccess the DAO to use
+ * @return this builder
+ */
+ public TranslateTextAppBuilder addSwitchTranslationDAO(
+ SwitchTranslationDataAccessInterface switchTranslationDataAccess) {
+ switchTranslationDAO = switchTranslationDataAccess;
+ return this;
+ }
+
+ /**
+ * Creates the objects for the Switch Translation Use Case and connects the TranslateTextView to its
+ * controller. Uses the same view as TranslateTextView.
+ *
This method must be called after addTranslateTextView!
+ * @return this builder
+ * @throws RuntimeException if this method is called before addTranslateTextView
+ */
+ public TranslateTextAppBuilder addSwitchTranslationUseCase() {
+ final SwitchTranslationOutputBoundary switchTranslationOutputBoundary =
+ new SwitchTranslationPresenter(translateTextViewModel);
+
+ final SwitchTranslationInteractor switchTranslationInteractor = new SwitchTranslationInteractor(
+ switchTranslationDAO, switchTranslationOutputBoundary);
+
+ final SwitchTranslationController controller = new SwitchTranslationController(switchTranslationInteractor);
+ if (translateTextView == null) {
+ throw new RuntimeException("addTranslateTextView must be called before addSwitchTranslationUseCase");
+ }
+ translateTextView.setSwitchTranslationController(controller);
+ return this;
+ }
+
+ /**
+ * Sets the TextToSpeechDAO to be used in this application.
+ * @param textToSpeechDataAccess the DAO to use
+ * @return this builder
+ */
+ public TranslateTextAppBuilder addTextToSpeechDAO(TextToSpeechDataAccessInterface textToSpeechDataAccess) {
+ textToSpeechDAO = textToSpeechDataAccess;
+ return this;
+ }
+
+ /**
+ * Creates the objects for Text to Speech Use Case and connects the TranslateTextView to its
+ * controller. Uses the same view as TranslateTextView.
+ *
This method must be called after addTranslateTextView!
+ * @return this builder
+ * @throws RuntimeException if this method is called before addTranslateTextView
+ */
+ public TranslateTextAppBuilder addTextToSpeechUseCase() {
+ final TextToSpeechOutputBoundary textToSpeechOutputBoundary = new TextToSpeechPresenter(translateTextViewModel);
+
+ final TextToSpeechInteractor textToSpeechInteractor = new TextToSpeechInteractor(
+ (TextToSpeechDataAccessInterface) translateTextDAO,
+ textToSpeechOutputBoundary);
+
+ final TextToSpeechController controller = new TextToSpeechController(textToSpeechInteractor);
+ if (translateTextView == null) {
+ throw new RuntimeException("addTranslateTextView must be called before addTextToSpeechUseCase");
+ }
+ translateTextView.setTextToSpeechController(controller);
+ return this;
+ }
+
+ /**
+ * Creates the TranslateTextView and underlying TranslateTextViewModel.
+ * @return this builder
+ */
+ public TranslateTextAppBuilder addTranslateTextView() {
+ translateTextViewModel = new TranslateTextViewModel();
+
+ final TranslateTextViewBuilder builder = new TranslateTextViewBuilder();
+
+ translateTextView = builder
+ .addViewModel(translateTextViewModel)
+ .addDAO(translateTextDAO)
+ .addLanguages()
+ .addInputPanel()
+ .addOutputPanel()
+ .addButtonPanel()
+ .build();
+
+ return this;
+ }
+
+ /**
+ * Builds the translator application.
+ * @return the JFrame for the application
+ */
+ public JFrame build() {
+ final JFrame frame = new JFrame();
+ frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
+ frame.setTitle("Translator Application");
+ frame.setSize(WIDTH, HEIGHT);
+
+ frame.add(translateTextView);
+
+ return frame;
+
+ }
+}
diff --git a/src/main/java/data_access/Constants.java b/src/main/java/data_access/Constants.java
new file mode 100644
index 000000000..5dce1a1be
--- /dev/null
+++ b/src/main/java/data_access/Constants.java
@@ -0,0 +1,34 @@
+package data_access;
+
+import java.util.Map;
+
+/**
+ * Constants used in data access.
+ */
+public class Constants {
+ public static final String LANGUAGE_KEY = "language";
+ public static final String TEXT_KEY = "text";
+ public static final String DETECT = "Detect Language";
+
+ public static final long WORD_MAX_FILE_SIZE = 10 * 1024 * 1024;
+ public static final long PPTX_MAX_FILE_SIZE = 10 * 1024 * 1024;
+ public static final long XLSX_MAX_FILE_SIZE = 10 * 1024 * 1024;
+ public static final long PDF_MAX_FILE_SIZE = 10 * 1024 * 1024;
+ public static final long TXT_MAX_FILE_SIZE = 1024 * 1024;
+ public static final long HTML_MAX_FILE_SIZE = 5 * 1024 * 1024;
+ public static final long XLIFF_MAX_FILE_SIZE = 10 * 1024 * 1024;
+ public static final long SRT_MAX_FILE_SIZE = 150 * 1024;
+
+ public static final Map FILE_SIZE_LIMITS = Map.of(
+ "docx", WORD_MAX_FILE_SIZE,
+ "doc", WORD_MAX_FILE_SIZE,
+ "pptx", PPTX_MAX_FILE_SIZE,
+ "xlsx", XLSX_MAX_FILE_SIZE,
+ "pdf", PDF_MAX_FILE_SIZE,
+ "txt", TXT_MAX_FILE_SIZE,
+ "html", HTML_MAX_FILE_SIZE,
+ "xlf", XLIFF_MAX_FILE_SIZE,
+ "xliff", XLIFF_MAX_FILE_SIZE,
+ "srt", SRT_MAX_FILE_SIZE);
+
+}
diff --git a/src/main/java/data_access/DBCheckUsageDataAccessObject.java b/src/main/java/data_access/DBCheckUsageDataAccessObject.java
new file mode 100644
index 000000000..b15a6ed5c
--- /dev/null
+++ b/src/main/java/data_access/DBCheckUsageDataAccessObject.java
@@ -0,0 +1,88 @@
+package data_access;
+
+import java.io.IOException;
+import java.net.URI;
+import java.net.http.HttpClient;
+import java.net.http.HttpRequest;
+import java.net.http.HttpResponse;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.json.JSONObject;
+
+import use_case.checkUsage.CheckUsageDataAccessInterface;
+import use_case.translateText.DataAccessException;
+
+/**
+ * The DAO for getting usage using DeepL API.
+ * API links: ....
+ */
+public class DBCheckUsageDataAccessObject extends DeeplTranslator
+ implements CheckUsageDataAccessInterface {
+
+ public static final String CHARACTER_COUNT = "character_count";
+ public static final String CHARACTER_LIMIT = "character_limit";
+
+ public DBCheckUsageDataAccessObject() {
+ try {
+ checkUsage();
+ getCharacterCount();
+ getCharacterLimit();
+ }
+ catch (DataAccessException ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ /**
+ * Get the character count and character limit as a Map.
+ *
+ * @return a set withs keys "character_count" and "character_limit" with their corresponding values
+ * @throws DataAccessException if the usage cannot be accessed for any reason
+ */
+ private Map checkUsage() throws DataAccessException {
+ try {
+ final String url = "https://api-free.deepl.com/v2/usage";
+ final HttpClient client;
+ final Map usage = new HashMap<>();
+ client = HttpClient.newHttpClient();
+ final HttpRequest request = HttpRequest.newBuilder()
+ .uri(URI.create(url))
+ .header("Authorization", "DeepL-Auth-Key " + super.getAuthKey())
+ .GET()
+ .build();
+
+ final HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString());
+ final JSONObject jsonUsage = new JSONObject(response.body());
+ usage.put(CHARACTER_COUNT, String.valueOf(jsonUsage.get(CHARACTER_COUNT)));
+ usage.put(CHARACTER_LIMIT, String.valueOf(jsonUsage.get(CHARACTER_LIMIT)));
+ return usage;
+ }
+ catch (IOException | InterruptedException ex) {
+ throw new DataAccessException(ex.getMessage());
+ }
+ }
+ /**
+ * Return the character count.
+ * If the character count is null, return an empty string.
+ *
+ * @return the character count of the usage
+ */
+
+ @Override
+ public String getCharacterCount() throws DataAccessException {
+ return this.checkUsage().get(CHARACTER_COUNT);
+ }
+
+ /**
+ * Return the character limit.
+ * If the character limit is null, return an empty string.
+ *
+ * @return the character limit of the usage
+ */
+
+ @Override
+ public String getCharacterLimit() throws DataAccessException {
+ return this.checkUsage().get(CHARACTER_LIMIT);
+ }
+}
diff --git a/src/main/java/data_access/DBImageUploadDataAccessObject.java b/src/main/java/data_access/DBImageUploadDataAccessObject.java
new file mode 100644
index 000000000..f49b1228c
--- /dev/null
+++ b/src/main/java/data_access/DBImageUploadDataAccessObject.java
@@ -0,0 +1,74 @@
+package data_access;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Base64;
+
+import org.apache.commons.io.FileUtils;
+import org.json.JSONArray;
+import org.json.JSONObject;
+
+import okhttp3.FormBody;
+import okhttp3.OkHttpClient;
+import okhttp3.Request;
+import okhttp3.RequestBody;
+import okhttp3.Response;
+import use_case.imageUpload.ImageUploadDataAccessInterface;
+import use_case.translateText.DataAccessException;
+
+/**
+ * The DAO for recognizing text from an image using OCR Space API.
+ * API Link: ...
+ */
+public class DBImageUploadDataAccessObject implements ImageUploadDataAccessInterface {
+
+ /**
+ * Extracts text from an image.
+ *
+ * @param imageFile the file of the image
+ * @return a String of text from the image
+ * @throws DataAccessException if text could not be extracted for any reason
+ */
+ public String getText(File imageFile) throws DataAccessException {
+
+ final String apiKey = "c0885d222488957";
+ final String result;
+ final String baseImage;
+
+ // Convert image to base64code
+ try {
+ final byte[] image = FileUtils.readFileToByteArray(imageFile);
+ baseImage = Base64.getEncoder().encodeToString(image);
+ }
+ catch (IOException ex) {
+ throw new DataAccessException(ex.getMessage());
+ }
+
+ // POST Method
+ final OkHttpClient client = new OkHttpClient().newBuilder()
+ .build();
+
+ final RequestBody formBody = new FormBody.Builder()
+ .add("base64Image", "data:image/png;base64," + baseImage)
+ .add("language", "eng")
+ .build();
+
+ final Request request = new Request.Builder()
+ .url("https://api.ocr.space/parse/image")
+ .post(formBody)
+ .addHeader("apikey", apiKey)
+ .build();
+
+ try {
+ final Response response = client.newCall(request).execute();
+
+ final JSONObject responseBody = new JSONObject(response.body().string());
+ final JSONArray parsedResults = responseBody.getJSONArray("ParsedResults");
+ result = parsedResults.getJSONObject(0).getString("ParsedText");
+ }
+ catch (IOException ex) {
+ throw new DataAccessException(ex.getMessage());
+ }
+ return result;
+ }
+}
diff --git a/src/main/java/data_access/DBNoteDataAccessObject.java b/src/main/java/data_access/DBNoteDataAccessObject.java
deleted file mode 100644
index dadb0cab0..000000000
--- a/src/main/java/data_access/DBNoteDataAccessObject.java
+++ /dev/null
@@ -1,107 +0,0 @@
-package data_access;
-
-import java.io.IOException;
-
-import org.json.JSONException;
-import org.json.JSONObject;
-
-import entity.User;
-import okhttp3.MediaType;
-import okhttp3.OkHttpClient;
-import okhttp3.Request;
-import okhttp3.RequestBody;
-import okhttp3.Response;
-import use_case.note.DataAccessException;
-import use_case.note.NoteDataAccessInterface;
-
-/**
- * The DAO for accessing notes stored in the database.
- *
This class demonstrates how your group can use the password-protected user
- * endpoints of the API used in lab 5 to store persistent data in your program.
- *
- *
You can also refer to the lab 5 code for signing up a new user and other use cases.
- *
- * See
- *
- * the documentation
- * of the API for more details.
- */
-public class DBNoteDataAccessObject implements NoteDataAccessInterface {
- private static final int SUCCESS_CODE = 200;
- private static final int CREDENTIAL_ERROR = 401;
- private static final String CONTENT_TYPE_LABEL = "Content-Type";
- private static final String CONTENT_TYPE_JSON = "application/json";
- private static final String STATUS_CODE_LABEL = "status_code";
- private static final String USERNAME = "username";
- private static final String PASSWORD = "password";
- private static final String MESSAGE = "message";
-
- @Override
- public String saveNote(User user, String note) throws DataAccessException {
- final OkHttpClient client = new OkHttpClient().newBuilder()
- .build();
-
- // POST METHOD
- final MediaType mediaType = MediaType.parse(CONTENT_TYPE_JSON);
- final JSONObject requestBody = new JSONObject();
- requestBody.put(USERNAME, user.getName());
- requestBody.put(PASSWORD, user.getPassword());
- final JSONObject extra = new JSONObject();
- extra.put("note", note);
- requestBody.put("info", extra);
- final RequestBody body = RequestBody.create(requestBody.toString(), mediaType);
- final Request request = new Request.Builder()
- .url("http://vm003.teach.cs.toronto.edu:20112/modifyUserInfo")
- .method("PUT", body)
- .addHeader(CONTENT_TYPE_LABEL, CONTENT_TYPE_JSON)
- .build();
- try {
- final Response response = client.newCall(request).execute();
-
- final JSONObject responseBody = new JSONObject(response.body().string());
-
- if (responseBody.getInt(STATUS_CODE_LABEL) == SUCCESS_CODE) {
- return loadNote(user);
- }
- else if (responseBody.getInt(STATUS_CODE_LABEL) == CREDENTIAL_ERROR) {
- throw new DataAccessException("message could not be found or password was incorrect");
- }
- else {
- throw new DataAccessException("database error: " + responseBody.getString(MESSAGE));
- }
- }
- catch (IOException | JSONException ex) {
- throw new DataAccessException(ex.getMessage());
- }
- }
-
- @Override
- public String loadNote(User user) throws DataAccessException {
- // Make an API call to get the user object.
- final String username = user.getName();
- final OkHttpClient client = new OkHttpClient().newBuilder().build();
- final Request request = new Request.Builder()
- .url(String.format("http://vm003.teach.cs.toronto.edu:20112/user?username=%s", username))
- .addHeader("Content-Type", CONTENT_TYPE_JSON)
- .build();
- try {
- final Response response = client.newCall(request).execute();
-
- final JSONObject responseBody = new JSONObject(response.body().string());
-
- if (responseBody.getInt(STATUS_CODE_LABEL) == SUCCESS_CODE) {
- final JSONObject userJSONObject = responseBody.getJSONObject("user");
- final JSONObject data = userJSONObject.getJSONObject("info");
- return data.getString("note");
- }
- else {
- throw new DataAccessException(responseBody.getString(MESSAGE));
- }
- }
- catch (IOException | JSONException ex) {
- throw new RuntimeException(ex);
- }
- }
-}
diff --git a/src/main/java/data_access/DBTranslateFileDataAccessObject.java b/src/main/java/data_access/DBTranslateFileDataAccessObject.java
new file mode 100644
index 000000000..813e2c18b
--- /dev/null
+++ b/src/main/java/data_access/DBTranslateFileDataAccessObject.java
@@ -0,0 +1,185 @@
+package data_access;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.http.HttpClient;
+import java.net.http.HttpRequest;
+import java.net.http.HttpResponse;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Random;
+
+import org.json.JSONObject;
+
+import use_case.translateFile.TranslateFileDataAccessInterface;
+import use_case.translateText.DataAccessException;
+
+/**
+ * The DAO for translating file using DeepL API.
+ * API links: ....
+ * ....
+ */
+public class DBTranslateFileDataAccessObject extends DeeplTranslator
+ implements TranslateFileDataAccessInterface {
+
+ private static final String BOUNDARY = "----WebKitFormBoundary"
+ + Long.toHexString(System.currentTimeMillis()) + new Random().nextInt(1000);
+ private static final String AUTHORIZATION = "Authorization";
+ private static final String DEEP_L_AUTH_KEY = "DeepL-Auth-Key ";
+ private static final String CONTENT_TYPE = "Content-Type";
+ private static final String STR1 = "--";
+ private static final String STR2 = "\r\n";
+ private static final int BYTE_CONSTANT = 1024;
+
+ public DBTranslateFileDataAccessObject() {
+
+ }
+
+ @Override
+ public Map translateDocumentUpload(File inputFile, String inputLanguage, String outputLanguage)
+ throws DataAccessException {
+
+ final HttpClient client;
+ final Map docInfo = new HashMap<>();
+ String codeInputLang = languageToCode(inputLanguage);
+ final String codeOutputLang = languageToCode(outputLanguage);
+
+ if (codeInputLang == null) {
+ codeInputLang = "";
+ }
+
+ try {
+ final HttpRequest request = buildMultipartRequest(inputFile, codeInputLang, codeOutputLang);
+ client = HttpClient.newHttpClient();
+
+ final HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString());
+ final JSONObject docResponse = new JSONObject(response.body());
+ docInfo.put("document_id", docResponse.get("document_id").toString());
+ docInfo.put("document_key", docResponse.get("document_key").toString());
+
+ }
+ catch (IOException | InterruptedException ex) {
+ throw new DataAccessException(ex.getMessage());
+ }
+
+ return docInfo;
+ }
+
+ private HttpRequest buildMultipartRequest(File inputFile, String inputLanguage, String outputLanguage)
+ throws IOException {
+
+ final String body = createMultipartBody(inputFile, inputLanguage, outputLanguage);
+ final String url = "https://api-free.deepl.com/v2/document";
+
+ return HttpRequest.newBuilder()
+ .uri(URI.create(url))
+ .header(AUTHORIZATION, DEEP_L_AUTH_KEY + super.getAuthKey())
+ .header(CONTENT_TYPE, "multipart/form-data; boundary=" + BOUNDARY)
+ .POST(HttpRequest.BodyPublishers.ofString(body))
+ .build();
+ }
+
+ private String createMultipartBody(File inputFile, String inputLanguage, String outputLanguage) throws IOException {
+ final StringBuilder body = new StringBuilder();
+
+ body.append(STR1).append(BOUNDARY).append(STR2);
+ body.append("Content-Disposition: form-data; name=\"file\"; filename=\"")
+ .append(inputFile.getName()).append("\"\r\n");
+ body.append("Content-Type: application/octet-stream\r\n\r\n");
+
+ final byte[] fileBytes = Files.readAllBytes(inputFile.toPath());
+ body.append(new String(fileBytes, StandardCharsets.UTF_8)).append(STR2);
+
+ body.append(STR1).append(BOUNDARY).append(STR2);
+ body.append("Content-Disposition: form-data; name=\"source_lang\"\r\n\r\n");
+ body.append(inputLanguage).append(STR2);
+
+ body.append(STR1).append(BOUNDARY).append(STR2);
+ body.append("Content-Disposition: form-data; name=\"target_lang\"\r\n\r\n");
+ body.append(outputLanguage).append(STR2);
+
+ body.append(STR1).append(BOUNDARY).append("--\r\n");
+
+ return body.toString();
+ }
+
+ @Override
+ public String getDocumentStatus(String documentId, String documentKey) {
+ try {
+ final URI url = new URI("https://api-free.deepl.com/v2/document/" + documentId);
+
+ final HttpClient client = HttpClient.newHttpClient();
+ final String body = "{\"document_key\":\"" + documentKey + "\"}";
+ final HttpRequest request = HttpRequest.newBuilder(url)
+ .header(AUTHORIZATION, DEEP_L_AUTH_KEY + super.getAuthKey())
+ .header(CONTENT_TYPE, "application/json")
+ .POST(HttpRequest.BodyPublishers.ofString(body))
+ .build();
+
+ final HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString());
+ final JSONObject jsonStatus = new JSONObject(response.body());
+ String docStatus = jsonStatus.get("status").toString();
+
+ docStatus = getStatus(docStatus, jsonStatus);
+ return docStatus;
+ }
+ catch (IOException | InterruptedException | URISyntaxException ex) {
+ throw new RuntimeException(ex.getMessage());
+ }
+ }
+
+ private static String getStatus(String docStatus, JSONObject jsonStatus) {
+ String status = "";
+ if ("translating".equals(docStatus)) {
+ status = "The file is still translating. " + "\n" + "Please try to download it later.";
+ }
+ else if ("queued".equals(docStatus)) {
+ status = "The translation job is waiting in line to be processed. " + "\n"
+ + "Please try to download it later.";
+ }
+ else if ("error".equals(docStatus)) {
+ status = "ERROR: " + jsonStatus.get("error_message").toString();
+ }
+ else if ("done".equals(docStatus)) {
+ status = jsonStatus.get("status").toString();
+ }
+ return status;
+ }
+
+ @Override
+ public File downloadDocument(String documentId, String documentKey) throws DataAccessException {
+ final File outputFile = new File("temp_translated_file");
+ try {
+ final URI url = new URI("https://api-free.deepl.com/v2/document/" + documentId + "/result");
+
+ // Send HTTP request and get the binary
+ final HttpClient client = HttpClient.newHttpClient();
+ final String body = "{\"document_key\":\"" + documentKey + "\"}";
+ final HttpRequest request = HttpRequest.newBuilder(url)
+ .header(AUTHORIZATION, DEEP_L_AUTH_KEY + super.getAuthKey())
+ .header(CONTENT_TYPE, "application/json")
+ .POST(HttpRequest.BodyPublishers.ofString(body))
+ .build();
+
+ final HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofInputStream());
+
+ final InputStream inputStream = response.body();
+ final FileOutputStream outputStream = new FileOutputStream(outputFile);
+ final byte[] buffer = new byte[BYTE_CONSTANT];
+ int bytesRead;
+ while ((bytesRead = inputStream.read(buffer)) != -1) {
+ outputStream.write(buffer, 0, bytesRead);
+ }
+ return outputFile;
+ }
+ catch (IOException | InterruptedException | URISyntaxException ex) {
+ throw new DataAccessException(ex.getMessage());
+ }
+ }
+}
diff --git a/src/main/java/data_access/DBTranslateTextDataAccessObject.java b/src/main/java/data_access/DBTranslateTextDataAccessObject.java
new file mode 100644
index 000000000..f40c7ea31
--- /dev/null
+++ b/src/main/java/data_access/DBTranslateTextDataAccessObject.java
@@ -0,0 +1,137 @@
+package data_access;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import com.deepl.api.DeepLException;
+import com.deepl.api.TextResult;
+import use_case.switchTranslation.SwitchTranslationDataAccessInterface;
+import use_case.textToSpeech.TextToSpeechDataAccessInterface;
+import use_case.translateText.DataAccessException;
+import use_case.translateText.TranslateTextDataAccessInterface;
+
+import java.util.Locale;
+import javax.speech.AudioException;
+import javax.speech.Central;
+import javax.speech.EngineException;
+import javax.speech.synthesis.Synthesizer;
+import javax.speech.synthesis.SynthesizerModeDesc;
+
+/**
+ * The DAO for translating text using DeepL API.
+ * API link: ....
+ */
+
+public class DBTranslateTextDataAccessObject extends DeeplTranslator implements TranslateTextDataAccessInterface,
+ SwitchTranslationDataAccessInterface, TextToSpeechDataAccessInterface {
+
+ public DBTranslateTextDataAccessObject() {
+ }
+
+ /**
+ * Translate a text into the specified output language.
+ *
+ * @param text the text to be translated.
+ * @param inputLanguage the language name of text (ie. English). Can be "Detect Language".
+ * @param outputLanguage the language name (ie. English) to which the text is translated
+ * @return a set withs keys "text" and "language" with their corresponding values
+ * @throws DataAccessException if the text could not be translated for any reason
+ */
+
+ @Override
+ public Map translateText(String text, String inputLanguage, String outputLanguage)
+ throws DataAccessException {
+ final Map result = new HashMap<>();
+ final TextResult translationResult;
+ try {
+ translationResult = super.getTranslator().translateText(text, languageToCode(inputLanguage),
+ languageToCode(outputLanguage));
+ }
+ catch (DeepLException | InterruptedException ex) {
+ throw new DataAccessException(ex.getMessage());
+ }
+
+ if (Constants.DETECT.equalsIgnoreCase(inputLanguage)) {
+ result.put(Constants.LANGUAGE_KEY, codeToLanguage(translationResult.getDetectedSourceLanguage()
+ .toUpperCase()));
+ }
+
+ else {
+ result.put(Constants.LANGUAGE_KEY, inputLanguage);
+ }
+
+ result.put(Constants.TEXT_KEY, translationResult.getText());
+ return result;
+
+ }
+
+ /**
+ * Switch the input language to be the output language and vice versa. Switch the input text to be the output
+ * text and vice versa
+ *
+ * @param inputText the input language.
+ * @param inputLanguage the input language.
+ * @param outputLanguage the input language.
+ * @return a mapping with the keys as the output text/language and values as input text/language.
+ * @throws DataAccessException if the text could not be translated for any reason
+ */
+
+ @Override
+ public Map switchLanguagesAndTexts(String inputText, String inputLanguage, String outputLanguage)
+ throws DataAccessException {
+
+ // Use ILanguageClassGetter interface to get LanguageMapperInterfaces for input and output languages
+ ILanguageClassGetter languageClassGetter = new GetLanguageClass();
+ final ILanguageMapper inputLanguageClass = languageClassGetter.giveLanguageClass(inputLanguage);
+ final ILanguageMapper outputLanguageClass = languageClassGetter.giveLanguageClass(outputLanguage);
+
+ // translating the text using the translateText method
+ final Map translationResult = translateText(inputText, inputLanguage, outputLanguage);
+
+ // Getting the translated text
+ final String translatedText = translationResult.get(Constants.TEXT_KEY);
+
+ // Creating new variables for the switch
+
+ // switching.
+ final Map switchedResult = new HashMap<>();
+
+ switchedResult.put(Constants.TEXT_KEY, translatedText);
+
+ switchedResult.put(Constants.LANGUAGE_KEY, outputLanguageClass.giveInput(outputLanguage));
+
+ switchedResult.put("translatedText", inputText);
+
+ switchedResult.put("outputLanguage", inputLanguageClass.giveOutput(inputLanguage));
+
+ return switchedResult;
+ }
+
+ /**
+ * Converting text to speech to be played when the speaker button is pressed.
+ * @param inputText text obtained from the text field.
+ * @throws DataAccessException if the conversion was not successful for any reason.
+ */
+ @Override
+ public String convertToSpeech(String inputText) throws DataAccessException {
+ try {
+ System.setProperty("freetts.voices", "com.sun.speech.freetts.en.us" + ".cmu_us_kal.KevinVoiceDirectory");
+
+ Central.registerEngineCentral("com.sun.speech.freetts" + ".jsapi.FreeTTSEngineCentral");
+
+ final Synthesizer synthesizer = Central.createSynthesizer(new SynthesizerModeDesc(Locale.US));
+
+ synthesizer.allocate();
+
+ synthesizer.resume();
+
+ synthesizer.speakPlainText(inputText, null);
+ synthesizer.waitEngineState(Synthesizer.QUEUE_EMPTY);
+
+ }
+ catch (EngineException | AudioException | InterruptedException ex) {
+ throw new DataAccessException(ex.getMessage());
+ }
+ return inputText;
+ }
+}
diff --git a/src/main/java/data_access/DeeplTranslator.java b/src/main/java/data_access/DeeplTranslator.java
new file mode 100644
index 000000000..e4fd188db
--- /dev/null
+++ b/src/main/java/data_access/DeeplTranslator.java
@@ -0,0 +1,187 @@
+package data_access;
+
+import java.io.IOException;
+import java.net.URI;
+import java.net.http.HttpClient;
+import java.net.http.HttpRequest;
+import java.net.http.HttpResponse;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.json.JSONArray;
+
+import com.deepl.api.DeepLException;
+import com.deepl.api.Language;
+import com.deepl.api.Translator;
+import use_case.translateText.DataAccessException;
+
+/**
+ * A DeeplTranslator that contains methods for getting all target and source languages compatible
+ * with DeepL's API, and methods for converting between DeepL's language codes and language names.
+ */
+public class DeeplTranslator {
+
+ private static final String AUTH_KEY = "a3c3d2b6-e5e2-42ce-aac7-aba5f20a0571:fx";
+ private final Map codeToLanguage = new HashMap<>();
+ private final Map languageToCode = new HashMap<>();
+ private List inputLanguages = new ArrayList<>();
+ private List outputLanguages = new ArrayList<>();
+ private final Translator translator;
+
+ public DeeplTranslator() {
+ try {
+ translator = new Translator(AUTH_KEY);
+ getCodeLanguageMaps();
+ getSourceLanguages();
+ getTargetLanguages();
+ }
+ catch (DataAccessException ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ protected void getCodeLanguageMaps() throws DataAccessException {
+ final String url = "https://api-free.deepl.com/v2/languages";
+ final HttpClient client;
+
+ // Get the http client
+ try {
+ client = HttpClient.newHttpClient();
+ final HttpRequest request = HttpRequest.newBuilder()
+ .uri(URI.create(url))
+ .header("Authorization", "DeepL-Auth-Key " + AUTH_KEY)
+ .GET()
+ .build();
+
+ final HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString());
+ final JSONArray languageCodes = new JSONArray(response.body());
+
+ for (int i = 0; i < languageCodes.length(); i++) {
+
+ final String language = languageCodes.getJSONObject(i).getString("name");
+ final String code = languageCodes.getJSONObject(i).getString("language");
+ codeToLanguage.put(code, language);
+ languageToCode.put(language, code);
+ }
+ }
+ catch (InterruptedException | IOException | IllegalArgumentException ex) {
+ throw new DataAccessException(ex.getMessage());
+ }
+
+ }
+
+ /**
+ * Convert from language code to language name.
+ *
+ * @param code the language code (ie. en)
+ * @return the language name (ie. English)
+ */
+
+ protected String codeToLanguage(String code) {
+ String result = null;
+ if (code != null) {
+ result = codeToLanguage.get(code);
+ }
+ return result;
+ }
+
+ /**
+ * Convert from language name to language code that is understood by the API methods.
+ *
+ * @param language the language name (example: English)
+ * @return the language code (example: en)
+ */
+ protected String languageToCode(String language) {
+ final String result;
+ if (Constants.DETECT.equals(language)) {
+ result = null;
+ }
+
+ else {
+ result = languageToCode.get(language);
+ }
+ return result;
+ }
+
+ protected void getSourceLanguages() throws DataAccessException {
+ final List sourceLanguages;
+ try {
+ sourceLanguages = translator.getSourceLanguages();
+ }
+ catch (DeepLException | InterruptedException ex) {
+ throw new DataAccessException(ex.getMessage());
+ }
+
+ final String[] result = new String[sourceLanguages.size() + 1];
+ result[0] = Constants.DETECT;
+ for (int i = 0; i < sourceLanguages.size(); i++) {
+ result[i + 1] = sourceLanguages.get(i).getName();
+ codeToLanguage.put(sourceLanguages.get(i).getCode(), sourceLanguages.get(i).getName());
+ languageToCode.put(sourceLanguages.get(i).getName(), sourceLanguages.get(i).getCode());
+ }
+
+ inputLanguages = List.of(result);
+ }
+
+ protected void getTargetLanguages() throws DataAccessException {
+ final List targetLanguages;
+ try {
+ targetLanguages = translator.getTargetLanguages();
+ }
+ catch (DeepLException | InterruptedException ex) {
+ throw new DataAccessException(ex.getMessage());
+ }
+
+ final List result = new ArrayList<>();
+ for (Language targetLanguage : targetLanguages) {
+
+ // Fix bug with DeepL API which returns Chinese (Simplified) instead of Chinese (traditional)
+ // by manually adding Chinese target languages
+ if (!"Chinese (simplified)".equals(targetLanguage.getName())) {
+ result.add(targetLanguage.getName());
+
+ codeToLanguage.put(targetLanguage.getCode(), targetLanguage.getName());
+ languageToCode.put(targetLanguage.getName(), targetLanguage.getCode());
+ }
+
+ }
+
+ result.add("Chinese (simplified)");
+ result.add("Chinese (traditional)");
+ codeToLanguage.put("zh-HANS", "Chinese (simplified)");
+ languageToCode.put("Chinese (simplified)", "zh-HANS");
+ codeToLanguage.put("zh-HANT", "Chinese (traditional)");
+ languageToCode.put("Chinese (traditional)", "zh-HANT");
+
+ outputLanguages = result;
+ }
+
+ protected Translator getTranslator() {
+ return translator;
+ }
+
+ protected String getAuthKey() {
+ return AUTH_KEY;
+ }
+
+ /**
+ * Return all possible input languages available for translation.
+ * @return the list of input languages
+ */
+ public List getInputLanguages() {
+ return inputLanguages;
+ }
+
+ /**
+ * Return all possible output languages for the given input language.
+ * If the input language is null, return the list of all possible output languages.
+ *
+ * @param inputLanguage the input language
+ * @return the list of output languages
+ */
+ public List getOutputLanguages(String inputLanguage) {
+ return outputLanguages;
+ }
+}
diff --git a/src/main/java/data_access/GetLanguageClass.java b/src/main/java/data_access/GetLanguageClass.java
new file mode 100644
index 000000000..5ccc88546
--- /dev/null
+++ b/src/main/java/data_access/GetLanguageClass.java
@@ -0,0 +1,47 @@
+package data_access;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * LanguageMapper
+ */
+
+public class GetLanguageClass implements ILanguageClassGetter {
+
+ LanguageClassFactory factory = new LanguageClassFactory();
+ private static final List languageClasses = new ArrayList<>();
+
+ public GetLanguageClass() {
+ createLanguageClasses();
+ }
+
+ private void createLanguageClasses() {
+ languageClasses.add(factory.createLanguageClass("Chinese",
+ new String[] {"Chinese (simplified)", "Chinese (traditional)"}));
+ languageClasses.add(factory.createLanguageClass("English",
+ new String[] {"English (American)", "English (British)"}));
+ languageClasses.add(factory.createLanguageClass("Portuguese",
+ new String[] {"Portuguese (Brazilian)", "Portuguese (European)"}));
+
+ }
+
+ /**
+ * @param language the language name of text (ie. English).
+ */
+ @Override
+ public ILanguageMapper giveLanguageClass(String language) {
+ // If the language has multiple target languages
+ for (LanguageClass languageClass: languageClasses) {
+ if (languageClass.matches(language)) {
+ return languageClass;
+ }
+ }
+
+ // Else, input language and output languages are the same when switched.
+ // Use memoization to prevent duplicate classes from being created
+ LanguageClass newLanguageClass = factory.createLanguageClass(language, new String[]{language});
+ languageClasses.add(newLanguageClass);
+ return newLanguageClass;
+ }
+}
diff --git a/src/main/java/data_access/ILanguageClassGetter.java b/src/main/java/data_access/ILanguageClassGetter.java
new file mode 100644
index 000000000..87c3a9aa4
--- /dev/null
+++ b/src/main/java/data_access/ILanguageClassGetter.java
@@ -0,0 +1,5 @@
+package data_access;
+
+public interface ILanguageClassGetter {
+ ILanguageMapper giveLanguageClass(String language);
+}
diff --git a/src/main/java/data_access/ILanguageMapper.java b/src/main/java/data_access/ILanguageMapper.java
new file mode 100644
index 000000000..62fd48cca
--- /dev/null
+++ b/src/main/java/data_access/ILanguageMapper.java
@@ -0,0 +1,29 @@
+package data_access;
+
+import use_case.translateText.DataAccessException;
+
+/**
+ * LanguageMapper Interface.
+ */
+
+public interface ILanguageMapper {
+ /**
+ * Given an input language, return what it will be when that language an output language.
+ * @param inputLanguage the language name of text (ie. English). Set to null to detect language.
+ * @return what that language will be as an output language
+ * @throws DataAccessException if the text could not be translated for any reason
+ */
+ String giveOutput(String inputLanguage)
+ throws DataAccessException;
+
+ /**
+ * Given an input language, return what it will be when that language an output language.
+ *
+ * @param outputLanguage the language name (ie. English (American)) to which the text is translated
+ * @return what that language will be as an input language
+ * @throws DataAccessException if the text could not be translated for any reason
+ */
+ String giveInput(String outputLanguage)
+ throws DataAccessException;
+
+}
diff --git a/src/main/java/data_access/InMemoryImageUploadDataAccessObject.java b/src/main/java/data_access/InMemoryImageUploadDataAccessObject.java
new file mode 100644
index 000000000..d52ce7b9c
--- /dev/null
+++ b/src/main/java/data_access/InMemoryImageUploadDataAccessObject.java
@@ -0,0 +1,23 @@
+package data_access;
+
+import java.io.File;
+
+import use_case.imageUpload.ImageUploadDataAccessInterface;
+import use_case.translateText.DataAccessException;
+
+/**
+ * In memory data access object for Image Upload Use Case.
+ */
+public class InMemoryImageUploadDataAccessObject implements ImageUploadDataAccessInterface {
+ /**
+ * Extract the text from an image file.
+ *
+ * @param imageFile the file of the image
+ * @return the text from the image
+ * @throws DataAccessException if the text could not be extracted for any reason
+ */
+ @Override
+ public String getText(File imageFile) throws DataAccessException {
+ return "";
+ }
+}
diff --git a/src/main/java/data_access/LanguageClass.java b/src/main/java/data_access/LanguageClass.java
new file mode 100644
index 000000000..c6dfb2e95
--- /dev/null
+++ b/src/main/java/data_access/LanguageClass.java
@@ -0,0 +1,44 @@
+package data_access;
+
+import java.util.Arrays;
+
+public class LanguageClass implements ILanguageMapper {
+
+ private final String inputLanguage;
+ private final String[] outputLanguages;
+
+ public LanguageClass(String inputLanguage, String[] outputLanguages) {
+ this.inputLanguage = inputLanguage;
+ this.outputLanguages = outputLanguages;
+ }
+
+ /**
+ * Given an input language, return what it will be when that language an output language.
+ * @param inputLanguage the language name of text (ie. English). Set to null to detect language.
+ * @return what that language will be as an output language
+ */
+ @Override
+ public String giveOutput(String inputLanguage) {
+ return outputLanguages[0];
+ }
+
+ /**
+ * Given an input language, return what it will be when that language an output language.
+ *
+ * @param outputLanguage the language name (ie. English (American)) to which the text is translated
+ */
+ @Override
+ public String giveInput(String outputLanguage) {
+ return inputLanguage;
+ }
+
+ /**
+ * Checks if the language matches any of this language mapper's input or output languages
+ *
+ * @param language the language to be matched
+ * @return true or false whether the language is an input or output language of this mapper
+ */
+ public boolean matches(String language) {
+ return (language.equals(inputLanguage) || Arrays.asList(outputLanguages).contains(language));
+ }
+}
diff --git a/src/main/java/data_access/LanguageClassFactory.java b/src/main/java/data_access/LanguageClassFactory.java
new file mode 100644
index 000000000..c188fbdab
--- /dev/null
+++ b/src/main/java/data_access/LanguageClassFactory.java
@@ -0,0 +1,9 @@
+package data_access;
+
+public class LanguageClassFactory {
+
+ public LanguageClass createLanguageClass(String inputLanguage, String[] outputLanguage) {
+ return new LanguageClass(inputLanguage, outputLanguage);
+ }
+
+}
diff --git a/src/main/java/entity/CheckUsage.java b/src/main/java/entity/CheckUsage.java
new file mode 100644
index 000000000..423ad031a
--- /dev/null
+++ b/src/main/java/entity/CheckUsage.java
@@ -0,0 +1,45 @@
+package entity;
+
+import use_case.checkUsage.CheckUsageDataAccessInterface;
+import use_case.translateText.DataAccessException;
+
+/**
+ * The representation of a Text Translator.
+ */
+public class CheckUsage {
+
+ private final CheckUsageDataAccessInterface dataAccessObject;
+ private String characterCount;
+ private String characterLimit;
+
+ public CheckUsage(CheckUsageDataAccessInterface dataAccessObject) {
+ this.dataAccessObject = dataAccessObject;
+ }
+
+ public void setCharacterLimit(String characterLimit) {
+ this.characterLimit = characterLimit;
+ }
+
+ public void setCharacterCount(String characterCount) {
+ this.characterCount = characterCount;
+ }
+
+ public String getCharacterLimit() {
+ return characterLimit;
+ }
+
+ public String getCharacterCount() {
+ return characterCount;
+ }
+
+ /**
+ * Translates the input text in the specified output language (input language could be "Detect Language")
+ * and updates the output text and input text (if detecting language).
+ * @throws DataAccessException if the text could not be translated for any reason
+ */
+ public void getUsage() throws DataAccessException {
+ characterCount = dataAccessObject.getCharacterCount();
+ characterLimit = dataAccessObject.getCharacterLimit();
+ }
+
+}
diff --git a/src/main/java/entity/FileTranslator.java b/src/main/java/entity/FileTranslator.java
new file mode 100644
index 000000000..0b52c3819
--- /dev/null
+++ b/src/main/java/entity/FileTranslator.java
@@ -0,0 +1,93 @@
+package entity;
+
+import java.io.File;
+
+import data_access.Constants;
+import use_case.translateFile.TranslateFileDataAccessInterface;
+import use_case.translateText.DataAccessException;
+
+/**
+ * The representation of a File Translator.
+ */
+public class FileTranslator extends TextTranslator {
+
+ private final TranslateFileDataAccessInterface dataAccessObject;
+ private File inputFile;
+ private File outputFile;
+ private String documentID;
+ private String documentKey;
+ private String documentStatus;
+
+ public FileTranslator(TranslateFileDataAccessInterface dataAccessObject) {
+ this.dataAccessObject = dataAccessObject;
+ }
+
+ public void setInputFile(File inputFile) {
+ this.inputFile = inputFile;
+ }
+
+ /**
+ * Setter for the document ID by uploading input file.
+ * @throws DataAccessException if the file could not be translated for any reason
+ */
+ public void setDocumentID() throws DataAccessException {
+ this.documentID = dataAccessObject.translateDocumentUpload(
+ this.inputFile, this.getInputLanguage(), this.getOutputLanguage()
+ ).get("document_id");
+ }
+
+ /**
+ * Setter for the document key by uploading input file.
+ * @throws DataAccessException if the file could not be translated for any reason
+ */
+ public void setDocumentKey() throws DataAccessException {
+ this.documentKey = dataAccessObject.translateDocumentUpload(
+ this.inputFile, this.getInputLanguage(), this.getOutputLanguage()
+ ).get("document_key");
+ }
+
+ public void setOutputFile(File outputFile) {
+ this.outputFile = outputFile;
+ }
+
+ public File getInputFile() {
+ return inputFile;
+ }
+
+ public File getOutputFile() {
+ return outputFile;
+ }
+
+ public long getFileSize() {
+ return inputFile.length();
+ }
+
+ public String getFileType() {
+ return inputFile.getName().substring(inputFile.getName().lastIndexOf(".") + 1);
+ }
+
+ public long getMaxFileSize() {
+ return Constants.FILE_SIZE_LIMITS.get(this.getFileType());
+ }
+
+ public String getDocumentID() {
+ return documentID;
+ }
+
+ public String getDocumentKey() {
+ return documentKey;
+ }
+
+ /**
+ * Setter for the document status for the uploaded input file.
+ * @param docID the document id.
+ * @param docKey the document key.
+ */
+ public void setStatus(String docID, String docKey) {
+ this.documentStatus = dataAccessObject.getDocumentStatus(docID, docKey);
+ }
+
+ public String getStatus() {
+ return documentStatus;
+ }
+}
diff --git a/src/main/java/entity/TextTranslator.java b/src/main/java/entity/TextTranslator.java
new file mode 100644
index 000000000..98211147f
--- /dev/null
+++ b/src/main/java/entity/TextTranslator.java
@@ -0,0 +1,72 @@
+package entity;
+
+import java.util.Map;
+
+import data_access.Constants;
+import use_case.translateText.DataAccessException;
+import use_case.translateText.TranslateTextDataAccessInterface;
+
+/**
+ * The representation of a Text Translator.
+ */
+public class TextTranslator {
+
+ private final TranslateTextDataAccessInterface dataAccessObject;
+ private String inputText;
+ private String inputLanguage;
+ private String outputLanguage;
+ private String outputText;
+
+ public TextTranslator(TranslateTextDataAccessInterface dataAccessObject) {
+ this.dataAccessObject = dataAccessObject;
+ }
+
+ public TextTranslator() {
+ this.dataAccessObject = null;
+ }
+
+ public void setInputLanguage(String inputLanguage) {
+ this.inputLanguage = inputLanguage;
+ }
+
+ public void setOutputLanguage(String outputLanguage) {
+ this.outputLanguage = outputLanguage;
+ }
+
+ public void setInputText(String inputText) {
+ this.inputText = inputText;
+ }
+
+ public void setOutputText(String outputText) {
+ this.outputText = outputText;
+ }
+
+ public String getInputLanguage() {
+ return inputLanguage;
+ }
+
+ public String getOutputLanguage() {
+ return outputLanguage;
+ }
+
+ public String getInputText() {
+ return inputText;
+ }
+
+ public String getOutputText() {
+ return outputText;
+ }
+
+ /**
+ * Translates the input text in the specified output language (input language could be "Detect Language")
+ * and updates the output text and input text (if detecting language).
+ * @throws DataAccessException if the text could not be translated for any reason
+ */
+ public void translate() throws DataAccessException {
+ final Map translationResult = dataAccessObject.translateText(
+ inputText, inputLanguage, outputLanguage);
+ outputText = translationResult.get(Constants.TEXT_KEY);
+ inputLanguage = translationResult.get(Constants.LANGUAGE_KEY);
+ }
+
+}
diff --git a/src/main/java/entity/User.java b/src/main/java/entity/User.java
deleted file mode 100644
index e0c57e9a6..000000000
--- a/src/main/java/entity/User.java
+++ /dev/null
@@ -1,24 +0,0 @@
-package entity;
-
-/**
- * The representation of a password-protected user for our program.
- */
-public class User {
-
- private final String name;
- private final String password;
-
- public User(String name, String password) {
- this.name = name;
- this.password = password;
- }
-
- public String getName() {
- return name;
- }
-
- public String getPassword() {
- return password;
- }
-
-}
diff --git a/src/main/java/interface_adapter/checkUsage/CheckUsageController.java b/src/main/java/interface_adapter/checkUsage/CheckUsageController.java
new file mode 100644
index 000000000..a12365ba5
--- /dev/null
+++ b/src/main/java/interface_adapter/checkUsage/CheckUsageController.java
@@ -0,0 +1,24 @@
+package interface_adapter.checkUsage;
+
+import use_case.checkUsage.CheckUsageInteractor;
+
+/**
+ * The controller for the CheckUsage Use Case.
+ */
+
+public class CheckUsageController {
+
+ private final CheckUsageInteractor checkUsageUseCaseInteractor;
+
+ public CheckUsageController(CheckUsageInteractor checkUsageUseCaseInteractor) {
+ this.checkUsageUseCaseInteractor = checkUsageUseCaseInteractor;
+ }
+
+ /**
+ * Executes the CheckUsage Use Case.
+ */
+
+ public void execute() {
+ checkUsageUseCaseInteractor.execute();
+ }
+}
diff --git a/src/main/java/interface_adapter/checkUsage/CheckUsagePresenter.java b/src/main/java/interface_adapter/checkUsage/CheckUsagePresenter.java
new file mode 100644
index 000000000..6dc31582b
--- /dev/null
+++ b/src/main/java/interface_adapter/checkUsage/CheckUsagePresenter.java
@@ -0,0 +1,41 @@
+package interface_adapter.checkUsage;
+
+import use_case.checkUsage.CheckUsageOutputBoundary;
+import use_case.checkUsage.CheckUsageOutputData;
+
+/**
+ * The presenter for the checkUsage program.
+ */
+public class CheckUsagePresenter implements CheckUsageOutputBoundary {
+
+ private final CheckUsageViewModel checkUsageViewModel;
+
+ public CheckUsagePresenter(CheckUsageViewModel checkUsageViewModel) {
+ this.checkUsageViewModel = checkUsageViewModel;
+ }
+
+ /**
+ * Prepares the success view for the checking usage related Use Cases.
+ *
+ * @param checkUsageOutputData the output data
+ */
+ @Override
+ public void prepareSuccessView(CheckUsageOutputData checkUsageOutputData) {
+ checkUsageViewModel.getState().setCharacterCount(checkUsageOutputData.getCharacterCount());
+ checkUsageViewModel.getState().setCharacterLimit(checkUsageOutputData.getCharacterLimit());
+ checkUsageViewModel.getState().setError(null);
+ checkUsageViewModel.firePropertyChanged();
+ }
+
+ /**
+ * Prepares the failure view for the Translate related Use Cases.
+ *
+ * @param errorMessage the explanation of the failure
+ */
+ @Override
+ public void prepareFailView(String errorMessage) {
+ checkUsageViewModel.getState().setError(errorMessage);
+ checkUsageViewModel.firePropertyChanged();
+ }
+}
+
diff --git a/src/main/java/interface_adapter/checkUsage/CheckUsageState.java b/src/main/java/interface_adapter/checkUsage/CheckUsageState.java
new file mode 100644
index 000000000..c77884e62
--- /dev/null
+++ b/src/main/java/interface_adapter/checkUsage/CheckUsageState.java
@@ -0,0 +1,36 @@
+package interface_adapter.checkUsage;
+
+/**
+ * The State for checking Usage.
+ */
+
+public class CheckUsageState {
+
+ private String characterCount = "";
+ private String characterLimit = "";
+ private String error;
+
+ public String getCharacterLimit() {
+ return characterLimit;
+ }
+
+ public void setCharacterLimit(String characterLimit) {
+ this.characterLimit = characterLimit;
+ }
+
+ public String getCharacterCount() {
+ return characterCount;
+ }
+
+ public void setCharacterCount(String characterCount) {
+ this.characterCount = characterCount;
+ }
+
+ public void setError(String errorMessage) {
+ this.error = errorMessage;
+ }
+
+ public String getError() {
+ return error;
+ }
+}
diff --git a/src/main/java/interface_adapter/checkUsage/CheckUsageViewModel.java b/src/main/java/interface_adapter/checkUsage/CheckUsageViewModel.java
new file mode 100644
index 000000000..77c9e5bd0
--- /dev/null
+++ b/src/main/java/interface_adapter/checkUsage/CheckUsageViewModel.java
@@ -0,0 +1,13 @@
+package interface_adapter.checkUsage;
+
+import interface_adapter.ViewModel;
+
+/**
+ * The ViewModel for the TranslateTextView.
+ */
+public class CheckUsageViewModel extends ViewModel {
+ public CheckUsageViewModel() {
+ super("CheckUsageViewModel");
+ setState(new CheckUsageState());
+ }
+}
diff --git a/src/main/java/interface_adapter/imageUpload/ImageUploadController.java b/src/main/java/interface_adapter/imageUpload/ImageUploadController.java
new file mode 100644
index 000000000..7f922fe62
--- /dev/null
+++ b/src/main/java/interface_adapter/imageUpload/ImageUploadController.java
@@ -0,0 +1,29 @@
+package interface_adapter.imageUpload;
+
+import java.io.File;
+
+import use_case.imageUpload.ImageUploadInputBoundary;
+import use_case.imageUpload.ImageUploadInputData;
+
+/**
+ * The controller for the ImageUpload Use Case.
+ */
+public class ImageUploadController {
+
+ private final ImageUploadInputBoundary imageUploadUseCaseInteractor;
+
+ public ImageUploadController(ImageUploadInputBoundary imageUploadUseCaseInteractor) {
+ this.imageUploadUseCaseInteractor = imageUploadUseCaseInteractor;
+ }
+
+ /**
+ * Executes the ImageUpload Use Case.
+ * @param imageFile the file of the image
+ * @param inputText the input text prior to calling upload image controller
+ */
+ public void execute(File imageFile, String inputText) {
+ final ImageUploadInputData imageUploadInputData = new ImageUploadInputData(imageFile, inputText);
+
+ imageUploadUseCaseInteractor.execute(imageUploadInputData);
+ }
+}
diff --git a/src/main/java/interface_adapter/imageUpload/ImageUploadPresenter.java b/src/main/java/interface_adapter/imageUpload/ImageUploadPresenter.java
new file mode 100644
index 000000000..e8b741bf0
--- /dev/null
+++ b/src/main/java/interface_adapter/imageUpload/ImageUploadPresenter.java
@@ -0,0 +1,47 @@
+package interface_adapter.imageUpload;
+
+import interface_adapter.translateText.TranslateTextViewModel;
+import use_case.imageUpload.ImageUploadOutputBoundary;
+import use_case.imageUpload.ImageUploadOutputData;
+
+/**
+ * The presenter for the Image Upload Use Case.
+ */
+public class ImageUploadPresenter implements ImageUploadOutputBoundary {
+
+ // Uses the same view model as translate text
+ private final TranslateTextViewModel imageUploadViewModel;
+
+ public ImageUploadPresenter(TranslateTextViewModel imageUploadViewModel) {
+ this.imageUploadViewModel = imageUploadViewModel;
+ }
+
+ /**
+ * Prepares the success view for the ImageUpload related Use Cases.
+ *
+ * @param imageUploadOutputData the output data
+ */
+ @Override
+ public void prepareSuccessView(ImageUploadOutputData imageUploadOutputData) {
+ // Set current input text to the previous input text concatenated with new text from image
+ imageUploadViewModel.getState().setInputText(imageUploadOutputData.getInputText() + "\n"
+ + imageUploadOutputData.getImageText());
+ imageUploadViewModel.getState().setError(null);
+ imageUploadViewModel.firePropertyChanged();
+
+ }
+
+ /**
+ * Prepares the failure view for the Image Upload related Use Cases.
+ *
+ * @param errorMessage the explanation of the failure
+ * @param inputText the input text prior to ImageUpload Use Case
+ */
+ @Override
+ public void prepareFailView(String errorMessage, String inputText) {
+ imageUploadViewModel.getState().setInputText(inputText);
+ imageUploadViewModel.getState().setError(errorMessage);
+ imageUploadViewModel.firePropertyChanged();
+ }
+}
+
diff --git a/src/main/java/interface_adapter/note/NoteController.java b/src/main/java/interface_adapter/note/NoteController.java
deleted file mode 100644
index e3e5dfb32..000000000
--- a/src/main/java/interface_adapter/note/NoteController.java
+++ /dev/null
@@ -1,28 +0,0 @@
-package interface_adapter.note;
-
-import use_case.note.NoteInputBoundary;
-
-/**
- * Controller for our Note related Use Cases.
- */
-public class NoteController {
-
- private final NoteInputBoundary noteInteractor;
-
- public NoteController(NoteInputBoundary noteInteractor) {
- this.noteInteractor = noteInteractor;
- }
-
- /**
- * Executes the Note related Use Cases.
- * @param note the note to be recorded
- */
- public void execute(String note) {
- if (note != null) {
- noteInteractor.executeSave(note);
- }
- else {
- noteInteractor.executeRefresh();
- }
- }
-}
diff --git a/src/main/java/interface_adapter/note/NotePresenter.java b/src/main/java/interface_adapter/note/NotePresenter.java
deleted file mode 100644
index d4e416165..000000000
--- a/src/main/java/interface_adapter/note/NotePresenter.java
+++ /dev/null
@@ -1,38 +0,0 @@
-package interface_adapter.note;
-
-import use_case.note.NoteOutputBoundary;
-
-/**
- * The presenter for our Note viewing and editing program.
- */
-public class NotePresenter implements NoteOutputBoundary {
-
- private final NoteViewModel noteViewModel;
-
- public NotePresenter(NoteViewModel noteViewModel) {
- this.noteViewModel = noteViewModel;
- }
-
- /**
- * Prepares the success view for the Note related Use Cases.
- *
- * @param note the output data
- */
- @Override
- public void prepareSuccessView(String note) {
- noteViewModel.getState().setNote(note);
- noteViewModel.getState().setError(null);
- noteViewModel.firePropertyChanged();
- }
-
- /**
- * Prepares the failure view for the Note related Use Cases.
- *
- * @param errorMessage the explanation of the failure
- */
- @Override
- public void prepareFailView(String errorMessage) {
- noteViewModel.getState().setError(errorMessage);
- noteViewModel.firePropertyChanged();
- }
-}
diff --git a/src/main/java/interface_adapter/note/NoteState.java b/src/main/java/interface_adapter/note/NoteState.java
deleted file mode 100644
index c5b2234d6..000000000
--- a/src/main/java/interface_adapter/note/NoteState.java
+++ /dev/null
@@ -1,26 +0,0 @@
-package interface_adapter.note;
-
-/**
- * The State for a note.
- *
For this example, a note is simplay a string.
- */
-public class NoteState {
- private String note = "";
- private String error;
-
- public String getNote() {
- return note;
- }
-
- public void setNote(String note) {
- this.note = note;
- }
-
- public void setError(String errorMessage) {
- this.error = errorMessage;
- }
-
- public String getError() {
- return error;
- }
-}
diff --git a/src/main/java/interface_adapter/note/NoteViewModel.java b/src/main/java/interface_adapter/note/NoteViewModel.java
deleted file mode 100644
index 6e185d0fa..000000000
--- a/src/main/java/interface_adapter/note/NoteViewModel.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package interface_adapter.note;
-
-import interface_adapter.ViewModel;
-
-/**
- * The ViewModel for the NoteView.
- */
-public class NoteViewModel extends ViewModel {
- public NoteViewModel() {
- super("note");
- setState(new NoteState());
- }
-}
diff --git a/src/main/java/interface_adapter/switchTranslation/SwitchTranslationController.java b/src/main/java/interface_adapter/switchTranslation/SwitchTranslationController.java
new file mode 100644
index 000000000..219c4fa81
--- /dev/null
+++ b/src/main/java/interface_adapter/switchTranslation/SwitchTranslationController.java
@@ -0,0 +1,28 @@
+package interface_adapter.switchTranslation;
+
+import use_case.switchTranslation.SwitchTranslationInputBoundary;
+import use_case.switchTranslation.SwitchTranslationInputData;
+
+/**
+ * The controller for the SwitchTranslation Use Case.
+ */
+public class SwitchTranslationController {
+ private final SwitchTranslationInputBoundary switchTranslarionUseCaseInteractor;
+
+ public SwitchTranslationController(SwitchTranslationInputBoundary switchTranslarionUseCaseInteractor) {
+ this.switchTranslarionUseCaseInteractor = switchTranslarionUseCaseInteractor;
+ }
+
+ /**
+ * Executes the SwitchTranslation Use Case.
+ * @param inputLanguage the language of the input text
+ * @param inputText the input text for the translation
+ * @param outputLanguage the language of the translation
+ */
+ public void execute(String inputText, String inputLanguage, String outputLanguage) {
+ final SwitchTranslationInputData switchTranslationInputData = new SwitchTranslationInputData(
+ inputText, inputLanguage, outputLanguage);
+
+ switchTranslarionUseCaseInteractor.execute(switchTranslationInputData);
+ }
+}
diff --git a/src/main/java/interface_adapter/switchTranslation/SwitchTranslationPresenter.java b/src/main/java/interface_adapter/switchTranslation/SwitchTranslationPresenter.java
new file mode 100644
index 000000000..d1247da75
--- /dev/null
+++ b/src/main/java/interface_adapter/switchTranslation/SwitchTranslationPresenter.java
@@ -0,0 +1,44 @@
+package interface_adapter.switchTranslation;
+
+import interface_adapter.translateText.TranslateTextViewModel;
+import use_case.switchTranslation.SwitchTranslationOutputBoundary;
+import use_case.switchTranslation.SwitchTranslationOutputData;
+
+/**
+ * The presenter for the SwitchTranslation Use Case.
+ */
+
+public class SwitchTranslationPresenter implements SwitchTranslationOutputBoundary {
+ private final TranslateTextViewModel switchTranslationTextViewModel;
+
+ public SwitchTranslationPresenter(TranslateTextViewModel switchTranslationTextViewModel) {
+ this.switchTranslationTextViewModel = switchTranslationTextViewModel;
+ }
+
+ /**
+ * Prepares the success view for the SwitchTranslation related Use Cases.
+ *
+ * @param switchTranslationOutputData the output data
+ */
+ @Override
+ public void prepareSuccessView(SwitchTranslationOutputData switchTranslationOutputData) {
+ switchTranslationTextViewModel.getState().setOutputText(switchTranslationOutputData.getTranslatedText());
+ switchTranslationTextViewModel.getState().setInputLanguage(switchTranslationOutputData.getInputLanguage());
+ switchTranslationTextViewModel.getState().setInputText(switchTranslationOutputData.getInputText());
+ switchTranslationTextViewModel.getState().setOutputLanguage(switchTranslationOutputData.getOutputLanguage());
+ switchTranslationTextViewModel.getState().setError(null);
+ switchTranslationTextViewModel.firePropertyChanged();
+
+ }
+
+ /**
+ * Prepares the failure view for the SwitchTranslation related Use Cases.
+ *
+ * @param errorMessage the explanation of the failure
+ */
+ @Override
+ public void prepareFailView(String errorMessage) {
+ switchTranslationTextViewModel.getState().setError(errorMessage);
+ switchTranslationTextViewModel.firePropertyChanged();
+ }
+}
diff --git a/src/main/java/interface_adapter/textToSpeech/TextToSpeechController.java b/src/main/java/interface_adapter/textToSpeech/TextToSpeechController.java
new file mode 100644
index 000000000..834b752a9
--- /dev/null
+++ b/src/main/java/interface_adapter/textToSpeech/TextToSpeechController.java
@@ -0,0 +1,22 @@
+package interface_adapter.textToSpeech;
+
+import use_case.textToSpeech.TextToSpeechInputBoundary;
+
+/**
+ * Controller for Text to Speech use case.
+ */
+public class TextToSpeechController {
+ private final TextToSpeechInputBoundary textToSpeechUseCaseInteractor;
+
+ public TextToSpeechController(TextToSpeechInputBoundary textToSpeechUseCaseInteractor) {
+ this.textToSpeechUseCaseInteractor = textToSpeechUseCaseInteractor;
+ }
+
+ /**
+ * Executes the Text To Speech use case.
+ * @param inputText the text used for text to speech conversion.
+ */
+ public void execute(String inputText) {
+ textToSpeechUseCaseInteractor.execute(inputText);
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/interface_adapter/textToSpeech/TextToSpeechPresenter.java b/src/main/java/interface_adapter/textToSpeech/TextToSpeechPresenter.java
new file mode 100644
index 000000000..d81184f37
--- /dev/null
+++ b/src/main/java/interface_adapter/textToSpeech/TextToSpeechPresenter.java
@@ -0,0 +1,32 @@
+package interface_adapter.textToSpeech;
+
+import interface_adapter.translateText.TranslateTextViewModel;
+import use_case.textToSpeech.TextToSpeechOutputBoundary;
+
+/**
+ * Presenter for Text To Speech viewing and editing program.
+ */
+public class TextToSpeechPresenter implements TextToSpeechOutputBoundary {
+ private final TranslateTextViewModel textToSpeechViewModel;
+
+ public TextToSpeechPresenter(TranslateTextViewModel textToSpeechViewModel) {
+ this.textToSpeechViewModel = textToSpeechViewModel;
+ }
+
+ /**
+ * Prepares success view for Text To Speech related use cases.
+ */
+ public void prepareSuccessView() {
+ textToSpeechViewModel.getState().setError(null);
+ textToSpeechViewModel.firePropertyChanged();
+ }
+
+ /**
+ * Prepares failure view for Text To Speech related use cases.
+ * @param errorMessage explanation of the conversion failure.
+ */
+ public void prepareFailView(String errorMessage) {
+ textToSpeechViewModel.getState().setError(errorMessage);
+ textToSpeechViewModel.firePropertyChanged();
+ }
+}
diff --git a/src/main/java/interface_adapter/translateFile/TranslateFileController.java b/src/main/java/interface_adapter/translateFile/TranslateFileController.java
new file mode 100644
index 000000000..ceb1bee8e
--- /dev/null
+++ b/src/main/java/interface_adapter/translateFile/TranslateFileController.java
@@ -0,0 +1,50 @@
+package interface_adapter.translateFile;
+
+import java.io.File;
+
+import use_case.translateFile.TranslateFileInputBoundary;
+import use_case.translateFile.TranslateFileInputData;
+import use_case.translateText.DataAccessException;
+
+/**
+ * The controller for the TranslateFile Use Case.
+ */
+public class TranslateFileController {
+
+ private final TranslateFileInputBoundary translateFileUseCaseInteractor;
+
+ public TranslateFileController(TranslateFileInputBoundary translateFileUseCaseInteractor) {
+ this.translateFileUseCaseInteractor = translateFileUseCaseInteractor;
+ }
+
+ /**
+ * Executes the TranslateFile Use Case for uploading the file.
+ * @param inputLanguage the language of the input File
+ * @param inputFile the input file for the translation
+ * @param outputLanguage the language of the translation
+ */
+ public void executeUpload(String inputLanguage, File inputFile, String outputLanguage) {
+ final TranslateFileInputData translateFileInputData = new TranslateFileInputData(
+ inputLanguage, inputFile, outputLanguage, null, null);
+
+ translateFileUseCaseInteractor.executeUpload(translateFileInputData);
+ }
+
+ /**
+ * Executes the TranslateFile Use Case for downloading the file.
+ * @param inputLanguage the language of the input File
+ * @param inputFile the input file for the translation
+ * @param outputLanguage the language of the translation
+ * @param documentID the document id.
+ * @param documentKey the document key.
+ * @throws DataAccessException if the file cannot be downloaded for any reason.
+ */
+ public void executeDownload(String inputLanguage, File inputFile, String outputLanguage,
+ String documentID, String documentKey)
+ throws DataAccessException {
+ final TranslateFileInputData translateFileInputData = new TranslateFileInputData(
+ inputLanguage, inputFile, outputLanguage, documentID, documentKey);
+
+ translateFileUseCaseInteractor.executeDownload(translateFileInputData);
+ }
+}
diff --git a/src/main/java/interface_adapter/translateFile/TranslateFilePresenter.java b/src/main/java/interface_adapter/translateFile/TranslateFilePresenter.java
new file mode 100644
index 000000000..8a0c39d06
--- /dev/null
+++ b/src/main/java/interface_adapter/translateFile/TranslateFilePresenter.java
@@ -0,0 +1,41 @@
+package interface_adapter.translateFile;
+
+import use_case.translateFile.TranslateFileOutputBoundary;
+import use_case.translateFile.TranslateFileOutputData;
+
+/**
+ * The presenter for the file translation program.
+ */
+public class TranslateFilePresenter implements TranslateFileOutputBoundary {
+
+ private final TranslateFileViewModel translateFileViewModel;
+
+ public TranslateFilePresenter(TranslateFileViewModel translateFileViewModel) {
+ this.translateFileViewModel = translateFileViewModel;
+ }
+
+ /**
+ * Prepares the success view for the Translate related Use Cases.
+ *
+ * @param translateFileOutputData the output file.
+ */
+ @Override
+ public void prepareSuccessView(TranslateFileOutputData translateFileOutputData) {
+ translateFileViewModel.getState().setOutputFile(translateFileOutputData.getOutputFile());
+ translateFileViewModel.getState().setError(null);
+ translateFileViewModel.firePropertyChanged();
+
+ }
+
+ /**
+ * Prepares the failure view for the Translate related Use Cases.
+ *
+ * @param errorMessage the explanation of the failure
+ */
+ @Override
+ public void prepareFailView(String errorMessage) {
+ translateFileViewModel.getState().setError(errorMessage);
+ translateFileViewModel.firePropertyChanged();
+ }
+}
+
diff --git a/src/main/java/interface_adapter/translateFile/TranslateFileState.java b/src/main/java/interface_adapter/translateFile/TranslateFileState.java
new file mode 100644
index 000000000..620405f45
--- /dev/null
+++ b/src/main/java/interface_adapter/translateFile/TranslateFileState.java
@@ -0,0 +1,54 @@
+package interface_adapter.translateFile;
+
+import java.io.File;
+
+/**
+ * The State for a Translating File.
+ */
+public class TranslateFileState {
+ private File inputFile;
+ private File outputFile;
+ private String error;
+ private String inputLanguage;
+ private String outputLanguage;
+
+ public File getInputFile() {
+ return inputFile;
+ }
+
+ public void setInputFile(File inputFile) {
+ this.inputFile = inputFile;
+ }
+
+ public File getOutputFile() {
+ return outputFile;
+ }
+
+ public String getInputLanguage() {
+ return inputLanguage;
+ }
+
+ public void setInputLanguage(String inputLanguage) {
+ this.inputLanguage = inputLanguage;
+ }
+
+ public void setOutputLanguage(String outputLanguage) {
+ this.outputLanguage = outputLanguage;
+ }
+
+ public String getOutputLanguage() {
+ return outputLanguage;
+ }
+
+ public void setError(String errorMessage) {
+ this.error = errorMessage;
+ }
+
+ public String getError() {
+ return error;
+ }
+
+ public void setOutputFile(File outputFile) {
+ this.outputFile = outputFile;
+ }
+}
diff --git a/src/main/java/interface_adapter/translateFile/TranslateFileViewModel.java b/src/main/java/interface_adapter/translateFile/TranslateFileViewModel.java
new file mode 100644
index 000000000..93d9601a1
--- /dev/null
+++ b/src/main/java/interface_adapter/translateFile/TranslateFileViewModel.java
@@ -0,0 +1,13 @@
+package interface_adapter.translateFile;
+
+import interface_adapter.ViewModel;
+
+/**
+ * The ViewModel for the TranslateFileView.
+ */
+public class TranslateFileViewModel extends ViewModel {
+ public TranslateFileViewModel() {
+ super("TranslateFileViewModel");
+ setState(new TranslateFileState());
+ }
+}
diff --git a/src/main/java/interface_adapter/translateText/TranslateState.java b/src/main/java/interface_adapter/translateText/TranslateState.java
new file mode 100644
index 000000000..2776393bf
--- /dev/null
+++ b/src/main/java/interface_adapter/translateText/TranslateState.java
@@ -0,0 +1,52 @@
+package interface_adapter.translateText;
+
+/**
+ * The State for a Translation.
+ */
+public class TranslateState {
+ private String inputText = "";
+ private String outputText = "";
+ private String error;
+ private String inputLanguage = "Detect Language";
+ private String outputLanguage = "";
+
+ public String getInputText() {
+ return inputText;
+ }
+
+ public void setInputText(String inputText) {
+ this.inputText = inputText;
+ }
+
+ public String getOutputText() {
+ return outputText;
+ }
+
+ public void setOutputText(String outputText) {
+ this.outputText = outputText;
+ }
+
+ public String getInputLanguage() {
+ return inputLanguage;
+ }
+
+ public void setInputLanguage(String inputLanguage) {
+ this.inputLanguage = inputLanguage;
+ }
+
+ public void setOutputLanguage(String outputLanguage) {
+ this.outputLanguage = outputLanguage;
+ }
+
+ public String getOutputLanguage() {
+ return outputLanguage;
+ }
+
+ public void setError(String errorMessage) {
+ this.error = errorMessage;
+ }
+
+ public String getError() {
+ return error;
+ }
+}
diff --git a/src/main/java/interface_adapter/translateText/TranslateTextController.java b/src/main/java/interface_adapter/translateText/TranslateTextController.java
new file mode 100644
index 000000000..8ca3a0478
--- /dev/null
+++ b/src/main/java/interface_adapter/translateText/TranslateTextController.java
@@ -0,0 +1,29 @@
+package interface_adapter.translateText;
+
+import use_case.translateText.TranslateTextInputBoundary;
+import use_case.translateText.TranslateTextInputData;
+
+/**
+ * The controller for the TranslateText Use Case.
+ */
+public class TranslateTextController {
+
+ private final TranslateTextInputBoundary translateTextUseCaseInteractor;
+
+ public TranslateTextController(TranslateTextInputBoundary translateTextUseCaseInteractor) {
+ this.translateTextUseCaseInteractor = translateTextUseCaseInteractor;
+ }
+
+ /**
+ * Executes the TranslateText Use Case.
+ * @param inputLanguage the language of the input text
+ * @param inputText the input text for the translation
+ * @param outputLanguage the language of the translation
+ */
+ public void execute(String inputLanguage, String inputText, String outputLanguage) {
+ final TranslateTextInputData translateTextInputData = new TranslateTextInputData(
+ inputLanguage, inputText, outputLanguage);
+
+ translateTextUseCaseInteractor.execute(translateTextInputData);
+ }
+}
diff --git a/src/main/java/interface_adapter/translateText/TranslateTextPresenter.java b/src/main/java/interface_adapter/translateText/TranslateTextPresenter.java
new file mode 100644
index 000000000..fa817ad74
--- /dev/null
+++ b/src/main/java/interface_adapter/translateText/TranslateTextPresenter.java
@@ -0,0 +1,44 @@
+package interface_adapter.translateText;
+
+import use_case.translateText.TranslateTextOutputBoundary;
+import use_case.translateText.TranslateTextOutputData;
+
+/**
+ * The presenter for the translation program.
+ */
+public class TranslateTextPresenter implements TranslateTextOutputBoundary {
+
+ private final TranslateTextViewModel translateTextViewModel;
+
+ public TranslateTextPresenter(TranslateTextViewModel translateTextViewModel) {
+ this.translateTextViewModel = translateTextViewModel;
+ }
+
+ /**
+ * Prepares the success view for the Translate related Use Cases.
+ *
+ * @param translateTextOutputData the output data
+ */
+ @Override
+ public void prepareSuccessView(TranslateTextOutputData translateTextOutputData) {
+ translateTextViewModel.getState().setInputText(translateTextOutputData.getInputText());
+ translateTextViewModel.getState().setOutputText(translateTextOutputData.getOutputText());
+ translateTextViewModel.getState().setInputLanguage(translateTextOutputData.getInputLanguage());
+ translateTextViewModel.getState().setOutputLanguage(translateTextOutputData.getOutputLanguage());
+ translateTextViewModel.getState().setError(null);
+ translateTextViewModel.firePropertyChanged();
+
+ }
+
+ /**
+ * Prepares the failure view for the Translate related Use Cases.
+ *
+ * @param errorMessage the explanation of the failure
+ */
+ @Override
+ public void prepareFailView(String errorMessage) {
+ translateTextViewModel.getState().setError(errorMessage);
+ translateTextViewModel.firePropertyChanged();
+ }
+}
+
diff --git a/src/main/java/interface_adapter/translateText/TranslateTextViewModel.java b/src/main/java/interface_adapter/translateText/TranslateTextViewModel.java
new file mode 100644
index 000000000..c179e920d
--- /dev/null
+++ b/src/main/java/interface_adapter/translateText/TranslateTextViewModel.java
@@ -0,0 +1,13 @@
+package interface_adapter.translateText;
+
+import interface_adapter.ViewModel;
+
+/**
+ * The ViewModel for the TranslateTextView.
+ */
+public class TranslateTextViewModel extends ViewModel {
+ public TranslateTextViewModel() {
+ super("TranslateTextViewModel");
+ setState(new TranslateState());
+ }
+}
diff --git a/src/main/java/use_case/checkUsage/CheckUsageDataAccessInterface.java b/src/main/java/use_case/checkUsage/CheckUsageDataAccessInterface.java
new file mode 100644
index 000000000..961f169fe
--- /dev/null
+++ b/src/main/java/use_case/checkUsage/CheckUsageDataAccessInterface.java
@@ -0,0 +1,25 @@
+package use_case.checkUsage;
+
+import use_case.translateText.DataAccessException;
+
+/**
+ * Interface for the Check Usage DAO. It consists of methods for
+ * getting character count and character limit.
+ */
+public interface CheckUsageDataAccessInterface {
+
+ /**
+ * Get character count.
+ * @return the number of character used by user
+ * @throws DataAccessException if the character count could not be switched for any reason
+ */
+ String getCharacterCount() throws DataAccessException;
+
+ /**
+ * Get character limit.
+ * @return the maximum number of character that user can use
+ * @throws DataAccessException if the character limit could not be switched for any reason
+ */
+ String getCharacterLimit() throws DataAccessException;
+
+}
diff --git a/src/main/java/use_case/checkUsage/CheckUsageInteractor.java b/src/main/java/use_case/checkUsage/CheckUsageInteractor.java
new file mode 100644
index 000000000..0be0294f9
--- /dev/null
+++ b/src/main/java/use_case/checkUsage/CheckUsageInteractor.java
@@ -0,0 +1,51 @@
+package use_case.checkUsage;
+
+import entity.CheckUsage;
+import use_case.translateText.DataAccessException;
+
+/**
+ * The CheckUsage Interactor.
+ */
+public class CheckUsageInteractor {
+
+ private final CheckUsageDataAccessInterface dataAccessObject;
+ private final CheckUsageOutputBoundary checkUsageOutputBoundary;
+ private final CheckUsage checkUsage;
+
+ public CheckUsageInteractor(CheckUsageDataAccessInterface checkUsageDataAccessInterface,
+ CheckUsageOutputBoundary checkUsagePresenter,
+ CheckUsage checkUsage) {
+ this.dataAccessObject = checkUsageDataAccessInterface;
+ this.checkUsageOutputBoundary = checkUsagePresenter;
+ this.checkUsage = checkUsage;
+ }
+
+ /**
+ * Executes the checkUsage use case.
+ * @throws DataAccessException when character count and limit is not accessible.
+ */
+ public void execute() {
+
+ try {
+ checkUsage.setCharacterCount(dataAccessObject.getCharacterCount());
+ checkUsage.setCharacterLimit(dataAccessObject.getCharacterLimit());
+
+ if (dataAccessObject.getCharacterCount() == null || (dataAccessObject.getCharacterCount().isEmpty())) {
+ checkUsageOutputBoundary.prepareFailView("Cannot access the character count");
+ }
+ else if (dataAccessObject.getCharacterLimit() == null || (dataAccessObject.getCharacterLimit().isEmpty())) {
+ checkUsageOutputBoundary.prepareFailView("Cannot access the character limit");
+ }
+
+ else {
+ checkUsage.getUsage();
+ final CheckUsageOutputData checkUsageOutputData = new CheckUsageOutputData(
+ checkUsage.getCharacterCount(), checkUsage.getCharacterLimit());
+ checkUsageOutputBoundary.prepareSuccessView(checkUsageOutputData);
+ }
+ }
+ catch (DataAccessException ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+}
diff --git a/src/main/java/use_case/checkUsage/CheckUsageOutputBoundary.java b/src/main/java/use_case/checkUsage/CheckUsageOutputBoundary.java
new file mode 100644
index 000000000..72009f433
--- /dev/null
+++ b/src/main/java/use_case/checkUsage/CheckUsageOutputBoundary.java
@@ -0,0 +1,18 @@
+package use_case.checkUsage;
+
+/**
+ * The output boundary for the Translate Text Use Case.
+ */
+public interface CheckUsageOutputBoundary {
+ /**
+ * Prepares the success view for the CheckUsage related Use Cases.
+ * @param checkUsageOutputData the output data
+ */
+ void prepareSuccessView(CheckUsageOutputData checkUsageOutputData);
+
+ /**
+ * Prepares the failure view for the CheckUsage related Use Cases.
+ * @param errorMessage the explanation of the failure
+ */
+ void prepareFailView(String errorMessage);
+}
diff --git a/src/main/java/use_case/checkUsage/CheckUsageOutputData.java b/src/main/java/use_case/checkUsage/CheckUsageOutputData.java
new file mode 100644
index 000000000..c64e0f278
--- /dev/null
+++ b/src/main/java/use_case/checkUsage/CheckUsageOutputData.java
@@ -0,0 +1,23 @@
+package use_case.checkUsage;
+
+/**
+ * Output Data for the CheckUsage Use Case.
+ */
+public class CheckUsageOutputData {
+
+ private final String characterCount;
+ private final String characterLimit;
+
+ public CheckUsageOutputData(String characterCount, String characterLimit) {
+ this.characterCount = characterCount;
+ this.characterLimit = characterLimit;
+ }
+
+ public String getCharacterCount() {
+ return characterCount;
+ }
+
+ public String getCharacterLimit() {
+ return characterLimit;
+ }
+}
diff --git a/src/main/java/use_case/imageUpload/ImageUploadDataAccessInterface.java b/src/main/java/use_case/imageUpload/ImageUploadDataAccessInterface.java
new file mode 100644
index 000000000..464089bfc
--- /dev/null
+++ b/src/main/java/use_case/imageUpload/ImageUploadDataAccessInterface.java
@@ -0,0 +1,21 @@
+package use_case.imageUpload;
+
+import java.io.File;
+
+import use_case.translateText.DataAccessException;
+
+/**
+ * Interface for the Image Upload DAO. It consists of methods for
+ * extracting text from an image file.
+ */
+public interface ImageUploadDataAccessInterface {
+
+ /**
+ * Extract the text from an image file.
+ * @param imageFile the file of the image
+ * @return the text from the image
+ * @throws DataAccessException if the text could not be extracted for any reason
+ */
+ String getText(File imageFile) throws DataAccessException;
+
+}
diff --git a/src/main/java/use_case/imageUpload/ImageUploadInputBoundary.java b/src/main/java/use_case/imageUpload/ImageUploadInputBoundary.java
new file mode 100644
index 000000000..6a45daff7
--- /dev/null
+++ b/src/main/java/use_case/imageUpload/ImageUploadInputBoundary.java
@@ -0,0 +1,14 @@
+package use_case.imageUpload;
+
+/**
+ * Input Boundary for actions which are related to uploading images.
+ */
+public interface ImageUploadInputBoundary {
+
+ /**
+ * Executes the Image Upload Use Case.
+ * @param imageUploadInputData the input data.
+ */
+ void execute(ImageUploadInputData imageUploadInputData);
+
+}
diff --git a/src/main/java/use_case/imageUpload/ImageUploadInputData.java b/src/main/java/use_case/imageUpload/ImageUploadInputData.java
new file mode 100644
index 000000000..fd381a080
--- /dev/null
+++ b/src/main/java/use_case/imageUpload/ImageUploadInputData.java
@@ -0,0 +1,25 @@
+package use_case.imageUpload;
+
+import java.io.File;
+
+/**
+ * The Input Data for the ImageUpload Use Case.
+ */
+public class ImageUploadInputData {
+
+ private final File imageFile;
+ private final String inputText;
+
+ public ImageUploadInputData(File imageFile, String inputText) {
+ this.imageFile = imageFile;
+ this.inputText = inputText;
+ }
+
+ File getImageFile() {
+ return imageFile;
+ }
+
+ String getInputText() {
+ return inputText;
+ }
+}
diff --git a/src/main/java/use_case/imageUpload/ImageUploadInteractor.java b/src/main/java/use_case/imageUpload/ImageUploadInteractor.java
new file mode 100644
index 000000000..2fbbdf635
--- /dev/null
+++ b/src/main/java/use_case/imageUpload/ImageUploadInteractor.java
@@ -0,0 +1,62 @@
+package use_case.imageUpload;
+
+import use_case.translateText.DataAccessException;
+
+/**
+ * The ImageUpload Interactor.
+ */
+public class ImageUploadInteractor implements ImageUploadInputBoundary {
+
+ private final ImageUploadDataAccessInterface imageUploadDataAccess;
+ private final ImageUploadOutputBoundary imageUploadOutputBoundary;
+
+ public ImageUploadInteractor(ImageUploadDataAccessInterface imageUploadDataAccessObject,
+ ImageUploadOutputBoundary imageUploadPresenter) {
+ this.imageUploadDataAccess = imageUploadDataAccessObject;
+ this.imageUploadOutputBoundary = imageUploadPresenter;
+ }
+
+ /**
+ * Executes the Image Upload Use Case given ImageUploadInputData which contains imageFile and inputText.
+ * InputText is passed to keep the text previously entered in the input text field.
+ * Any text detected from the image will be concatenated with inputText on a new line.
+ * The presenter will prepare a fail view if the given file does not exist, if no text
+ * is detected in the image, or if a DataAccessException is thrown.
+ *
+ * @param imageUploadInputData the input data containing imageFile and inputText
+ */
+ @Override
+ public void execute(ImageUploadInputData imageUploadInputData) {
+
+ // Check if file exists in user's local directory
+ if (!imageUploadInputData.getImageFile().exists()) {
+ imageUploadOutputBoundary.prepareFailView("The file does not exist.",
+ imageUploadInputData.getInputText());
+ }
+
+ // Otherwise, use the DAO's getText method to retrieve the input image file's text
+ else {
+ try {
+ final String imageText = imageUploadDataAccess.getText(imageUploadInputData.getImageFile());
+ final ImageUploadOutputData outputData = new ImageUploadOutputData(
+ imageUploadInputData.getInputText(), imageText);
+
+ // If no text was found in image, prepare fail view
+ if ("".equals(imageText)) {
+ imageUploadOutputBoundary.prepareFailView("No text detected from image.",
+ imageUploadInputData.getInputText());
+ }
+
+ // Else, prepare success view
+ else {
+ imageUploadOutputBoundary.prepareSuccessView(outputData);
+ }
+ }
+
+ catch (DataAccessException ex) {
+ imageUploadOutputBoundary.prepareFailView(ex.getMessage(), imageUploadInputData.getInputText());
+ }
+ }
+
+ }
+}
diff --git a/src/main/java/use_case/imageUpload/ImageUploadOutputBoundary.java b/src/main/java/use_case/imageUpload/ImageUploadOutputBoundary.java
new file mode 100644
index 000000000..2e4188ce2
--- /dev/null
+++ b/src/main/java/use_case/imageUpload/ImageUploadOutputBoundary.java
@@ -0,0 +1,19 @@
+package use_case.imageUpload;
+
+/**
+ * The output boundary for the Image Upload Use Case.
+ */
+public interface ImageUploadOutputBoundary {
+ /**
+ * Prepares the success view for the ImageUpload related Use Cases.
+ * @param imageUploadOutputData the output data
+ */
+ void prepareSuccessView(ImageUploadOutputData imageUploadOutputData);
+
+ /**
+ * Prepares the failure view for the ImageUpload related Use Cases.
+ * @param errorMessage the explanation of the failure
+ * @param inputText the input text prior to ImageUpload Use Case
+ */
+ void prepareFailView(String errorMessage, String inputText);
+}
diff --git a/src/main/java/use_case/imageUpload/ImageUploadOutputData.java b/src/main/java/use_case/imageUpload/ImageUploadOutputData.java
new file mode 100644
index 000000000..272a4ec21
--- /dev/null
+++ b/src/main/java/use_case/imageUpload/ImageUploadOutputData.java
@@ -0,0 +1,24 @@
+package use_case.imageUpload;
+
+/**
+ * Output Data for the ImageUpload Use Case.
+ */
+public class ImageUploadOutputData {
+
+ private final String inputText;
+ private final String imageText;
+
+ public ImageUploadOutputData(String inputText, String imageText) {
+ this.inputText = inputText;
+ this.imageText = imageText;
+ }
+
+ public String getInputText() {
+ return inputText;
+ }
+
+ public String getImageText() {
+ return imageText;
+ }
+
+}
diff --git a/src/main/java/use_case/note/NoteDataAccessInterface.java b/src/main/java/use_case/note/NoteDataAccessInterface.java
deleted file mode 100644
index b71597828..000000000
--- a/src/main/java/use_case/note/NoteDataAccessInterface.java
+++ /dev/null
@@ -1,30 +0,0 @@
-package use_case.note;
-
-import entity.User;
-
-/**
- * Interface for the NoteDAO. It consists of methods for
- * both loading and saving a note.
- */
-public interface NoteDataAccessInterface {
-
- /**
- * Saves a note for a given user. This will replace any existing note.
- *
The password of the user must match that of the user saved in the system.
- * @param user the user information associated with the note
- * @param note the note to be saved
- * @return the contents of the note
- * @throws DataAccessException if the user's note can not be saved for any reason
- */
- String saveNote(User user, String note) throws DataAccessException;
-
- /**
- * Returns the note associated with the user. The password
- * is not checked, so anyone can read the information.
- * @param user the user information associated with the note
- * @return the contents of the note
- * @throws DataAccessException if the user's note can not be loaded for any reason
- */
- String loadNote(User user) throws DataAccessException;
-
-}
diff --git a/src/main/java/use_case/note/NoteInputBoundary.java b/src/main/java/use_case/note/NoteInputBoundary.java
deleted file mode 100644
index b41da9bf5..000000000
--- a/src/main/java/use_case/note/NoteInputBoundary.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package use_case.note;
-
-/**
- * The Input Boundary for our note-related use cases. Since they are closely related,
- * we have included them both in the same interface for simplicity.
- */
-public interface NoteInputBoundary {
-
- /**
- * Executes the refresh note use case.
- */
- void executeRefresh();
-
- /**
- * Executes the save note use case.
- * @param message the input data
- */
- void executeSave(String message);
-}
diff --git a/src/main/java/use_case/note/NoteInteractor.java b/src/main/java/use_case/note/NoteInteractor.java
deleted file mode 100644
index 369e9309a..000000000
--- a/src/main/java/use_case/note/NoteInteractor.java
+++ /dev/null
@@ -1,59 +0,0 @@
-package use_case.note;
-
-import entity.User;
-
-/**
- * The "Use Case Interactor" for our two note-related use cases of refreshing
- * the contents of the note and saving the contents of the note. Since they
- * are closely related, we have combined them here for simplicity.
- */
-public class NoteInteractor implements NoteInputBoundary {
-
- private final NoteDataAccessInterface noteDataAccessInterface;
- private final NoteOutputBoundary noteOutputBoundary;
- // Note: this program has it hardcoded which user object it is getting data for;
- // you could change this if you wanted to generalize the code. For example,
- // you might allow a user of the program to create a new note, which you
- // could store as a "user" through the API OR you might maintain all notes
- // in a JSON object stored in one common "user" stored through the API.
- private final User user = new User("jonathan_calver2", "abc123");
-
- public NoteInteractor(NoteDataAccessInterface noteDataAccessInterface,
- NoteOutputBoundary noteOutputBoundary) {
- this.noteDataAccessInterface = noteDataAccessInterface;
- this.noteOutputBoundary = noteOutputBoundary;
- }
-
- /**
- * Executes the refresh note use case.
- *
- */
- @Override
- public void executeRefresh() {
- try {
-
- final String note = noteDataAccessInterface.loadNote(user);
- noteOutputBoundary.prepareSuccessView(note);
- }
- catch (DataAccessException ex) {
- noteOutputBoundary.prepareFailView(ex.getMessage());
- }
- }
-
- /**
- * Executes the save note use case.
- *
- * @param note the input data
- */
- @Override
- public void executeSave(String note) {
- try {
-
- final String updatedNote = noteDataAccessInterface.saveNote(user, note);
- noteOutputBoundary.prepareSuccessView(updatedNote);
- }
- catch (DataAccessException ex) {
- noteOutputBoundary.prepareFailView(ex.getMessage());
- }
- }
-}
diff --git a/src/main/java/use_case/note/NoteOutputBoundary.java b/src/main/java/use_case/note/NoteOutputBoundary.java
deleted file mode 100644
index c0c2bb1d0..000000000
--- a/src/main/java/use_case/note/NoteOutputBoundary.java
+++ /dev/null
@@ -1,18 +0,0 @@
-package use_case.note;
-
-/**
- * The output boundary for the Login Use Case.
- */
-public interface NoteOutputBoundary {
- /**
- * Prepares the success view for the Note related Use Cases.
- * @param message the output data
- */
- void prepareSuccessView(String message);
-
- /**
- * Prepares the failure view for the Note related Use Cases.
- * @param errorMessage the explanation of the failure
- */
- void prepareFailView(String errorMessage);
-}
diff --git a/src/main/java/use_case/switchTranslation/SwitchTranslationDataAccessInterface.java b/src/main/java/use_case/switchTranslation/SwitchTranslationDataAccessInterface.java
new file mode 100644
index 000000000..d68cbea04
--- /dev/null
+++ b/src/main/java/use_case/switchTranslation/SwitchTranslationDataAccessInterface.java
@@ -0,0 +1,24 @@
+package use_case.switchTranslation;
+
+import java.util.Map;
+
+import use_case.translateText.DataAccessException;
+
+/**
+ * Interface for the Switch Translation DAO. It consists of methods for
+ * switching the texts and languages.
+ */
+public interface SwitchTranslationDataAccessInterface {
+
+ /**
+ * Switch the languages and texts.
+ * @param inputText the input text
+ * @param inputLanguage the input language
+ * @param outputLanguage the output language
+ * @return a mapping with the keys as the output text/language and values as input text/language.
+ * @throws DataAccessException if the texts and languages could not be switched for any reason
+ */
+ Map switchLanguagesAndTexts(String inputText, String inputLanguage, String outputLanguage)
+ throws DataAccessException;
+
+}
diff --git a/src/main/java/use_case/switchTranslation/SwitchTranslationInputBoundary.java b/src/main/java/use_case/switchTranslation/SwitchTranslationInputBoundary.java
new file mode 100644
index 000000000..55f33c5d5
--- /dev/null
+++ b/src/main/java/use_case/switchTranslation/SwitchTranslationInputBoundary.java
@@ -0,0 +1,15 @@
+package use_case.switchTranslation;
+
+/**
+ * Input Boundary for actions which are related to switching the translation.
+ */
+public interface SwitchTranslationInputBoundary {
+
+ /**
+ * Executes the switchTranslation use case.
+ * @param switchTranslationInputData the input data.
+ */
+ void execute(SwitchTranslationInputData switchTranslationInputData);
+
+}
+
diff --git a/src/main/java/use_case/switchTranslation/SwitchTranslationInputData.java b/src/main/java/use_case/switchTranslation/SwitchTranslationInputData.java
new file mode 100644
index 000000000..0b96f3d1e
--- /dev/null
+++ b/src/main/java/use_case/switchTranslation/SwitchTranslationInputData.java
@@ -0,0 +1,28 @@
+package use_case.switchTranslation;
+
+/**
+ * The Input Data for the SwitchTranslation Use Case.
+ */
+public class SwitchTranslationInputData {
+ private final String inputText;
+ private final String inputLanguage;
+ private final String outputLanguage;
+
+ public SwitchTranslationInputData(String inputText, String inputLanguage, String outputLanguage) {
+ this.inputText = inputText;
+ this.inputLanguage = inputLanguage;
+ this.outputLanguage = outputLanguage;
+ }
+
+ public String getInputText() {
+ return inputText;
+ }
+
+ public String getInputLanguage() {
+ return inputLanguage;
+ }
+
+ public String getOutputLanguage() {
+ return outputLanguage;
+ }
+}
diff --git a/src/main/java/use_case/switchTranslation/SwitchTranslationInteractor.java b/src/main/java/use_case/switchTranslation/SwitchTranslationInteractor.java
new file mode 100644
index 000000000..09af4f5e3
--- /dev/null
+++ b/src/main/java/use_case/switchTranslation/SwitchTranslationInteractor.java
@@ -0,0 +1,67 @@
+package use_case.switchTranslation;
+
+import java.util.Map;
+
+import data_access.Constants;
+import use_case.translateText.DataAccessException;
+
+/**
+ * The SwitchTranslation Interactor.
+ */
+
+public class SwitchTranslationInteractor implements SwitchTranslationInputBoundary {
+
+ private final SwitchTranslationDataAccessInterface switchTranslationDataAccess;
+ private final SwitchTranslationOutputBoundary switchTranslationOutputBoundary;
+ private String translatedText;
+
+ public SwitchTranslationInteractor(SwitchTranslationDataAccessInterface switchTranslationDataAccessObject,
+ SwitchTranslationOutputBoundary switchTranslationPresenter) {
+ this.switchTranslationDataAccess = switchTranslationDataAccessObject;
+ this.switchTranslationOutputBoundary = switchTranslationPresenter;
+ }
+
+ /**
+ * Executes the SwitchTranslation Use Case.
+ *
+ * @param switchTranslationInputData the input data.
+ */
+
+ @Override
+ public void execute(SwitchTranslationInputData switchTranslationInputData) {
+ try {
+ if (switchTranslationInputData.getInputText().trim().isEmpty()) {
+ switchTranslationOutputBoundary.prepareFailView("Input text cannot be empty. Please provide "
+ + "text to translate.");
+ }
+ else if (switchTranslationInputData.getInputLanguage().equals(Constants.DETECT)) {
+ switchTranslationOutputBoundary.prepareFailView("Please select an input language.");
+ }
+ else {
+ // Proceed with the switching process
+ final Map switchedResult = switchTranslationDataAccess.switchLanguagesAndTexts(
+ switchTranslationInputData.getInputText(),
+ switchTranslationInputData.getInputLanguage(),
+ switchTranslationInputData.getOutputLanguage());
+
+ // Get the switched translated text
+ translatedText = switchedResult.get(Constants.TEXT_KEY);
+
+ // Create the output data from the switched result
+ final SwitchTranslationOutputData outputData = new SwitchTranslationOutputData(
+ translatedText,
+ switchedResult.get(Constants.LANGUAGE_KEY),
+ switchedResult.get("translatedText"),
+ switchedResult.get("outputLanguage"));
+
+ // Prepare success view with output data
+ switchTranslationOutputBoundary.prepareSuccessView(outputData);
+ }
+ }
+ catch (DataAccessException ex) {
+ // Handle errors in translation or switching
+ switchTranslationOutputBoundary.prepareFailView("There seems to be an error with the switching process. "
+ + "Please try again.");
+ }
+ }
+}
diff --git a/src/main/java/use_case/switchTranslation/SwitchTranslationOutputBoundary.java b/src/main/java/use_case/switchTranslation/SwitchTranslationOutputBoundary.java
new file mode 100644
index 000000000..71b258fb3
--- /dev/null
+++ b/src/main/java/use_case/switchTranslation/SwitchTranslationOutputBoundary.java
@@ -0,0 +1,18 @@
+package use_case.switchTranslation;
+
+/**
+ * The output boundary for the SwitchTranslation Use Case.
+ */
+public interface SwitchTranslationOutputBoundary {
+ /**
+ * Prepares the success view for the SwitchTranslation related Use Cases.
+ * @param switchTranslationOutputData the output data
+ */
+ void prepareSuccessView(SwitchTranslationOutputData switchTranslationOutputData);
+
+ /**
+ * Prepares the failure view for the SwitchTranslation related Use Cases.
+ * @param errorMessage the explanation of the failure
+ */
+ void prepareFailView(String errorMessage);
+}
diff --git a/src/main/java/use_case/switchTranslation/SwitchTranslationOutputData.java b/src/main/java/use_case/switchTranslation/SwitchTranslationOutputData.java
new file mode 100644
index 000000000..b51fa26d8
--- /dev/null
+++ b/src/main/java/use_case/switchTranslation/SwitchTranslationOutputData.java
@@ -0,0 +1,34 @@
+package use_case.switchTranslation;
+
+/**
+ * Output Data for the SwitchTranslation Use Case.
+ */
+public class SwitchTranslationOutputData {
+ private final String inputText;
+ private final String inputLanguage;
+ private final String translatedText;
+ private final String outputLanguage;
+
+ public SwitchTranslationOutputData(String inputText, String inputLanguage, String translatedText, String outputLanguage) {
+ this.inputText = inputText;
+ this.inputLanguage = inputLanguage;
+ this.translatedText = translatedText;
+ this.outputLanguage = outputLanguage;
+ }
+
+ public String getInputText() {
+ return inputText;
+ }
+
+ public String getInputLanguage() {
+ return inputLanguage;
+ }
+
+ public String getTranslatedText() {
+ return translatedText;
+ }
+
+ public String getOutputLanguage() {
+ return outputLanguage;
+ }
+}
diff --git a/src/main/java/use_case/textToSpeech/TextToSpeechDataAccessInterface.java b/src/main/java/use_case/textToSpeech/TextToSpeechDataAccessInterface.java
new file mode 100644
index 000000000..ebde47ff3
--- /dev/null
+++ b/src/main/java/use_case/textToSpeech/TextToSpeechDataAccessInterface.java
@@ -0,0 +1,19 @@
+package use_case.textToSpeech;
+
+import use_case.translateText.DataAccessException;
+
+/**
+ * Interface for the textToSpeechDAO. It consists of methods for
+ * getting texts in the text field.
+ */
+public interface TextToSpeechDataAccessInterface {
+
+ /**
+ * Convert text to speech.
+ * @param inputText text to be converted to speech.
+ * @return the text of the field.
+ * @throws DataAccessException if the text could not be translated for any reason.
+ */
+ String convertToSpeech(String inputText) throws DataAccessException;
+
+}
diff --git a/src/main/java/use_case/textToSpeech/TextToSpeechInputBoundary.java b/src/main/java/use_case/textToSpeech/TextToSpeechInputBoundary.java
new file mode 100644
index 000000000..fb1575cb5
--- /dev/null
+++ b/src/main/java/use_case/textToSpeech/TextToSpeechInputBoundary.java
@@ -0,0 +1,14 @@
+package use_case.textToSpeech;
+
+/**
+ * Input Boundary for actions which are related to translating text.
+ */
+public interface TextToSpeechInputBoundary {
+
+ /**
+ * Executes the textToSpeech use case.
+ * @param inputText the input data.
+ */
+ void execute(String inputText);
+
+}
diff --git a/src/main/java/use_case/textToSpeech/TextToSpeechInteractor.java b/src/main/java/use_case/textToSpeech/TextToSpeechInteractor.java
new file mode 100644
index 000000000..22a1b99c8
--- /dev/null
+++ b/src/main/java/use_case/textToSpeech/TextToSpeechInteractor.java
@@ -0,0 +1,40 @@
+package use_case.textToSpeech;
+
+import use_case.translateText.DataAccessException;
+
+/**
+ * The TextToSpeech Interactor.
+ */
+public class TextToSpeechInteractor implements TextToSpeechInputBoundary {
+
+ private final TextToSpeechDataAccessInterface speechDataAccessInterface;
+ private final TextToSpeechOutputBoundary textToSpeechOutputBoundary;
+
+ public TextToSpeechInteractor(TextToSpeechDataAccessInterface textToSpeechDataAccessInterface,
+ TextToSpeechOutputBoundary textToSpeechOutputBoundary) {
+ this.speechDataAccessInterface = textToSpeechDataAccessInterface;
+ this.textToSpeechOutputBoundary = textToSpeechOutputBoundary;
+ }
+
+ /**
+ * Executes the TextToSpeech Use Case.
+ * @param inputText the input data.
+ */
+ @Override
+ public void execute(String inputText) {
+ try {
+ if ("".equals(inputText)) {
+ textToSpeechOutputBoundary.prepareFailView("Text is empty.");
+ }
+ else {
+ speechDataAccessInterface.convertToSpeech(inputText);
+
+ textToSpeechOutputBoundary.prepareSuccessView();
+ }
+ }
+ catch (DataAccessException ex) {
+ textToSpeechOutputBoundary.prepareFailView("There seems to be an error with conversion"
+ + "Please try again.");
+ }
+ }
+}
diff --git a/src/main/java/use_case/textToSpeech/TextToSpeechOutputBoundary.java b/src/main/java/use_case/textToSpeech/TextToSpeechOutputBoundary.java
new file mode 100644
index 000000000..9bf984dbb
--- /dev/null
+++ b/src/main/java/use_case/textToSpeech/TextToSpeechOutputBoundary.java
@@ -0,0 +1,17 @@
+package use_case.textToSpeech;
+
+/**
+ * The output boundary for the Translate Text Use Case.
+ */
+public interface TextToSpeechOutputBoundary {
+ /**
+ * Prepares the success view for the TranslateText related Use Cases.
+ */
+ void prepareSuccessView();
+
+ /**
+ * Prepares the failure view for the TranslateText related Use Cases.
+ * @param errorMessage the explanation of the failure
+ */
+ void prepareFailView(String errorMessage);
+}
diff --git a/src/main/java/use_case/translateFile/TranslateFileDataAccessInterface.java b/src/main/java/use_case/translateFile/TranslateFileDataAccessInterface.java
new file mode 100644
index 000000000..ed7ddcf5d
--- /dev/null
+++ b/src/main/java/use_case/translateFile/TranslateFileDataAccessInterface.java
@@ -0,0 +1,62 @@
+package use_case.translateFile;
+
+import java.io.File;
+import java.util.List;
+import java.util.Map;
+
+import use_case.translateText.DataAccessException;
+
+/**
+ * Interface for the translateFileDAO. It consists of methods for
+ * uploading a file for translation, downloading the translated file.
+ */
+public interface TranslateFileDataAccessInterface {
+
+ /**
+ * Uploads a document to the DeepL API for translation and returns the document handle with a document ID
+ * and a document key.
+ *
+ * @param inputFile the input file.
+ * @param inputLanguage the input language
+ * @param outputLanguage the language to be translated.
+ * @return DocumentHandle containing the document ID and status.
+ * @throws DataAccessException if the file could not be translated for any reason
+ */
+ Map translateDocumentUpload(File inputFile, String inputLanguage, String outputLanguage)
+ throws DataAccessException;
+
+ /**
+ * Return document status given the document id and document key from to the DeepL API.
+ *
+ * @param documentId the document id.
+ * @param documentKey the document key.
+ * @return the document status for the uploaded document.
+ */
+ String getDocumentStatus(String documentId, String documentKey);
+
+ /**
+ * Downloads the translated document from the DeepL API using document ID and document key
+ * and returns the file object.
+ *
+ * @param documentId the unique identifier of the document to be downloaded.
+ * @param documentKey the document key used for authentication in the API request.
+ * @return File object representing the translated document.
+ * @throws DataAccessException if the file could not be downloaded for any reason
+ */
+ File downloadDocument(String documentId, String documentKey) throws DataAccessException;
+
+ /**
+ * Return all possible input languages available for translation.
+ * @return the list of input languages
+ */
+ List getInputLanguages();
+
+ /**
+ * Return all possible output languages for the given input language.
+ * If the input language is null, return the list of all possible output languages.
+ * @param inputLanguage the input language
+ * @return the list of output languages
+ */
+ List getOutputLanguages(String inputLanguage);
+
+}
diff --git a/src/main/java/use_case/translateFile/TranslateFileInputBoundary.java b/src/main/java/use_case/translateFile/TranslateFileInputBoundary.java
new file mode 100644
index 000000000..97434e60b
--- /dev/null
+++ b/src/main/java/use_case/translateFile/TranslateFileInputBoundary.java
@@ -0,0 +1,23 @@
+package use_case.translateFile;
+
+import use_case.translateText.DataAccessException;
+
+/**
+ * Input Boundary for actions which are related to translating file.
+ */
+public interface TranslateFileInputBoundary {
+
+ /**
+ * Executes the translatefile use case for uploading the document.
+ * @param translateFileInputData the input data.
+ */
+ void executeUpload(TranslateFileInputData translateFileInputData);
+
+ /**
+ * Executes the translatefile use case for downloading the translated document.
+ * @param translateFileInputData the input data.
+ * @throws DataAccessException if the output file could not be retrieved for any reason
+ */
+ void executeDownload(TranslateFileInputData translateFileInputData) throws DataAccessException;
+
+}
diff --git a/src/main/java/use_case/translateFile/TranslateFileInputData.java b/src/main/java/use_case/translateFile/TranslateFileInputData.java
new file mode 100644
index 000000000..f9193ffbf
--- /dev/null
+++ b/src/main/java/use_case/translateFile/TranslateFileInputData.java
@@ -0,0 +1,45 @@
+package use_case.translateFile;
+
+import java.io.File;
+import java.util.Map;
+
+/**
+ * The Input Data for the TranslateFile Use Case.
+ */
+public class TranslateFileInputData {
+
+ private final String inputLanguage;
+ private final File inputFile;
+ private final String outputLanguage;
+ private final String documentID;
+ private final String documentKey;
+
+ public TranslateFileInputData(String inputLanguage, File inputFile, String outputLanguage,
+ String documentID, String documentKey) {
+ this.inputLanguage = inputLanguage;
+ this.inputFile = inputFile;
+ this.outputLanguage = outputLanguage;
+ this.documentID = documentID;
+ this.documentKey = documentKey;
+ }
+
+ String getInputLanguage() {
+ return inputLanguage;
+ }
+
+ File getInputFile() {
+ return inputFile;
+ }
+
+ String getOutputLanguage() {
+ return outputLanguage;
+ }
+
+ public String getDocumentID() {
+ return documentID;
+ }
+
+ public String getDocumentKey() {
+ return documentKey;
+ }
+}
diff --git a/src/main/java/use_case/translateFile/TranslateFileInteractor.java b/src/main/java/use_case/translateFile/TranslateFileInteractor.java
new file mode 100644
index 000000000..a204ee372
--- /dev/null
+++ b/src/main/java/use_case/translateFile/TranslateFileInteractor.java
@@ -0,0 +1,87 @@
+package use_case.translateFile;
+
+import data_access.Constants;
+import entity.FileTranslator;
+import use_case.translateText.DataAccessException;
+
+/**
+ * The TranslateFile Interactor.
+ */
+public class TranslateFileInteractor implements TranslateFileInputBoundary {
+
+ private final TranslateFileDataAccessInterface dataAccessObject;
+ private final TranslateFileOutputBoundary translateFileOutputBoundary;
+ private final FileTranslator fileTranslator;
+
+ public TranslateFileInteractor(TranslateFileDataAccessInterface translateFileDataAccessInterface,
+ TranslateFileOutputBoundary translateFilePresenter,
+ FileTranslator fileTranslator) {
+ this.dataAccessObject = translateFileDataAccessInterface;
+ this.translateFileOutputBoundary = translateFilePresenter;
+ this.fileTranslator = fileTranslator;
+
+ }
+
+ @Override
+ public void executeUpload(TranslateFileInputData translateFileInputData) {
+
+ try {
+ fileTranslator.setInputLanguage(translateFileInputData.getInputLanguage());
+ fileTranslator.setOutputLanguage(translateFileInputData.getOutputLanguage());
+ fileTranslator.setInputFile(translateFileInputData.getInputFile());
+
+ if (!dataAccessObject.getInputLanguages().contains(fileTranslator.getInputLanguage())) {
+ translateFileOutputBoundary.prepareFailView("Selected language does not exist in translator.");
+ }
+ else if (!dataAccessObject.getOutputLanguages(fileTranslator.getInputLanguage()).contains(
+ fileTranslator.getOutputLanguage())) {
+ translateFileOutputBoundary.prepareFailView("Translated language does not exist in translator.");
+ }
+ else if (fileTranslator.getInputFile() == null) {
+ translateFileOutputBoundary.prepareFailView("No file is uploaded.");
+ }
+
+ else if (!Constants.FILE_SIZE_LIMITS.containsKey(fileTranslator.getFileType())) {
+ translateFileOutputBoundary.prepareFailView("Unsupported file type.");
+ }
+
+ else if (fileTranslator.getFileSize() > fileTranslator.getMaxFileSize()) {
+ translateFileOutputBoundary.prepareFailView("File size exceeds the maximum allowed.");
+ }
+
+ else {
+ fileTranslator.setDocumentID();
+ fileTranslator.setDocumentKey();
+ fileTranslator.setStatus(fileTranslator.getDocumentID(), fileTranslator.getDocumentKey());
+ final TranslateFileOutputData translateFileOutputData = new TranslateFileOutputData(
+ fileTranslator.getOutputFile());
+ translateFileOutputBoundary.prepareSuccessView(translateFileOutputData);
+ }
+ }
+ catch (DataAccessException ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ @Override
+ public void executeDownload(TranslateFileInputData translateFileInputData) {
+ try {
+ if (translateFileInputData.getDocumentID().isEmpty()) {
+ translateFileOutputBoundary.prepareFailView("Unable to determine the document ID.");
+ }
+ else if (translateFileInputData.getDocumentKey().isEmpty()) {
+ translateFileOutputBoundary.prepareFailView("Unable to determine the document key.");
+ }
+ else {
+ fileTranslator.setOutputFile(dataAccessObject.downloadDocument(fileTranslator.getDocumentID(),
+ fileTranslator.getDocumentKey()));
+ final TranslateFileOutputData translateFileOutputData = new TranslateFileOutputData(
+ fileTranslator.getOutputFile());
+ translateFileOutputBoundary.prepareSuccessView(translateFileOutputData);
+ }
+ }
+ catch (DataAccessException ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+}
diff --git a/src/main/java/use_case/translateFile/TranslateFileOutputBoundary.java b/src/main/java/use_case/translateFile/TranslateFileOutputBoundary.java
new file mode 100644
index 000000000..e6703449c
--- /dev/null
+++ b/src/main/java/use_case/translateFile/TranslateFileOutputBoundary.java
@@ -0,0 +1,18 @@
+package use_case.translateFile;
+
+/**
+ * The output boundary for the Translate File Use Case.
+ */
+public interface TranslateFileOutputBoundary {
+ /**
+ * Prepares the success view for the TranslateFile related Use Cases.
+ * @param translateFileOutputData the output data
+ */
+ void prepareSuccessView(TranslateFileOutputData translateFileOutputData);
+
+ /**
+ * Prepares the failure view for the TranslateFile related Use Cases.
+ * @param errorMessage the explanation of the failure
+ */
+ void prepareFailView(String errorMessage);
+}
diff --git a/src/main/java/use_case/translateFile/TranslateFileOutputData.java b/src/main/java/use_case/translateFile/TranslateFileOutputData.java
new file mode 100644
index 000000000..af35cc89f
--- /dev/null
+++ b/src/main/java/use_case/translateFile/TranslateFileOutputData.java
@@ -0,0 +1,19 @@
+package use_case.translateFile;
+
+import java.io.File;
+
+/**
+ * Output Data for the TranslateFile Use Case.
+ */
+public class TranslateFileOutputData {
+
+ private final File outputFile;
+
+ public TranslateFileOutputData(File outputFile) {
+ this.outputFile = outputFile;
+ }
+
+ public File getOutputFile() {
+ return outputFile;
+ }
+}
diff --git a/src/main/java/use_case/note/DataAccessException.java b/src/main/java/use_case/translateText/DataAccessException.java
similarity index 86%
rename from src/main/java/use_case/note/DataAccessException.java
rename to src/main/java/use_case/translateText/DataAccessException.java
index b8c17920d..10fa67e2c 100644
--- a/src/main/java/use_case/note/DataAccessException.java
+++ b/src/main/java/use_case/translateText/DataAccessException.java
@@ -1,4 +1,4 @@
-package use_case.note;
+package use_case.translateText;
/**
* Exception thrown when there is an error with accessing data.
diff --git a/src/main/java/use_case/translateText/TranslateTextDataAccessInterface.java b/src/main/java/use_case/translateText/TranslateTextDataAccessInterface.java
new file mode 100644
index 000000000..3c56bc46f
--- /dev/null
+++ b/src/main/java/use_case/translateText/TranslateTextDataAccessInterface.java
@@ -0,0 +1,38 @@
+package use_case.translateText;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Interface for the translateTextDAO. It consists of methods for
+ * translating text, getting output languages for each input language,
+ * and converting between language codes and language names.
+ */
+public interface TranslateTextDataAccessInterface {
+
+ /**
+ * Translate a text into the specified output language.
+ * @param text the text to be translated.
+ * @param inputLanguage the language name of text (ie. English). Set to null to detect language.
+ * @param outputLanguage the language name (ie. English) to which the text is translated
+ * @return a set withs keys "text" and "language" with their corresponding values
+ * @throws DataAccessException if the text could not be translated for any reason
+ */
+ Map translateText(String text, String inputLanguage, String outputLanguage)
+ throws DataAccessException;
+
+ /**
+ * Return all possible input languages available for translation.
+ * @return the list of input languages
+ */
+ List getInputLanguages();
+
+ /**
+ * Return all possible output languages for the given input language.
+ * If the input language is null, return the list of all possible output languages.
+ * @param inputLanguage the input language
+ * @return the list of output languages
+ */
+ List getOutputLanguages(String inputLanguage);
+
+}
diff --git a/src/main/java/use_case/translateText/TranslateTextInputBoundary.java b/src/main/java/use_case/translateText/TranslateTextInputBoundary.java
new file mode 100644
index 000000000..63198b3a6
--- /dev/null
+++ b/src/main/java/use_case/translateText/TranslateTextInputBoundary.java
@@ -0,0 +1,14 @@
+package use_case.translateText;
+
+/**
+ * Input Boundary for actions which are related to translating text.
+ */
+public interface TranslateTextInputBoundary {
+
+ /**
+ * Executes the translatetext use case.
+ * @param translateTextInputData the input data.
+ */
+ void execute(TranslateTextInputData translateTextInputData);
+
+}
diff --git a/src/main/java/use_case/translateText/TranslateTextInputData.java b/src/main/java/use_case/translateText/TranslateTextInputData.java
new file mode 100644
index 000000000..12d12fbfa
--- /dev/null
+++ b/src/main/java/use_case/translateText/TranslateTextInputData.java
@@ -0,0 +1,29 @@
+package use_case.translateText;
+
+/**
+ * The Input Data for the TranslateText Use Case.
+ */
+public class TranslateTextInputData {
+
+ private final String inputLanguage;
+ private final String inputText;
+ private final String outputLanguage;
+
+ public TranslateTextInputData(String inputLanguage, String inputText, String outputLanguage) {
+ this.inputLanguage = inputLanguage;
+ this.inputText = inputText;
+ this.outputLanguage = outputLanguage;
+ }
+
+ String getInputLanguage() {
+ return inputLanguage;
+ }
+
+ String getInputText() {
+ return inputText;
+ }
+
+ public String getOutputLanguage() {
+ return outputLanguage;
+ }
+}
diff --git a/src/main/java/use_case/translateText/TranslateTextInteractor.java b/src/main/java/use_case/translateText/TranslateTextInteractor.java
new file mode 100644
index 000000000..2d3a8e154
--- /dev/null
+++ b/src/main/java/use_case/translateText/TranslateTextInteractor.java
@@ -0,0 +1,57 @@
+package use_case.translateText;
+
+import entity.TextTranslator;
+
+/**
+ * The TranslateText Interactor.
+ */
+public class TranslateTextInteractor implements TranslateTextInputBoundary {
+
+ private final TranslateTextDataAccessInterface dataAccessObject;
+ private final use_case.translateText.TranslateTextOutputBoundary translateTextOutputBoundary;
+ private final TextTranslator textTranslator;
+
+ public TranslateTextInteractor(TranslateTextDataAccessInterface translateTextDataAccessInterface,
+ use_case.translateText.TranslateTextOutputBoundary translateTextPresenter,
+ TextTranslator textTranslator) {
+ this.dataAccessObject = translateTextDataAccessInterface;
+ this.translateTextOutputBoundary = translateTextPresenter;
+ this.textTranslator = textTranslator;
+ }
+
+ @Override
+ public void execute(TranslateTextInputData translateTextInputData) {
+
+ try {
+ textTranslator.setInputLanguage(translateTextInputData.getInputLanguage());
+ textTranslator.setOutputLanguage(translateTextInputData.getOutputLanguage());
+ textTranslator.setInputText(translateTextInputData.getInputText());
+
+ if (!dataAccessObject.getInputLanguages().contains(textTranslator.getInputLanguage())) {
+ translateTextOutputBoundary.prepareFailView("Selected language does not exist in translator.");
+ }
+ else if (!dataAccessObject.getOutputLanguages(textTranslator.getInputLanguage())
+ .contains(textTranslator.getOutputLanguage())) {
+ translateTextOutputBoundary.prepareFailView("Translated language does not exist in translator.");
+ }
+
+ else if ("".equals(textTranslator.getInputText())) {
+ translateTextOutputBoundary.prepareFailView("Input text is empty.");
+ }
+
+ else {
+
+ textTranslator.translate();
+ final TranslateTextOutputData translateTextOutputData = new TranslateTextOutputData(
+ textTranslator.getInputText(),
+ textTranslator.getOutputText(),
+ textTranslator.getInputLanguage(),
+ textTranslator.getOutputLanguage());
+ translateTextOutputBoundary.prepareSuccessView(translateTextOutputData);
+ }
+ }
+ catch (DataAccessException ex) {
+ translateTextOutputBoundary.prepareFailView(ex.getMessage());
+ }
+ }
+}
diff --git a/src/main/java/use_case/translateText/TranslateTextOutputBoundary.java b/src/main/java/use_case/translateText/TranslateTextOutputBoundary.java
new file mode 100644
index 000000000..c79334429
--- /dev/null
+++ b/src/main/java/use_case/translateText/TranslateTextOutputBoundary.java
@@ -0,0 +1,18 @@
+package use_case.translateText;
+
+/**
+ * The output boundary for the Translate Text Use Case.
+ */
+public interface TranslateTextOutputBoundary {
+ /**
+ * Prepares the success view for the TranslateText related Use Cases.
+ * @param translateTextOutputData the output data
+ */
+ void prepareSuccessView(TranslateTextOutputData translateTextOutputData);
+
+ /**
+ * Prepares the failure view for the TranslateText related Use Cases.
+ * @param errorMessage the explanation of the failure
+ */
+ void prepareFailView(String errorMessage);
+}
diff --git a/src/main/java/use_case/translateText/TranslateTextOutputData.java b/src/main/java/use_case/translateText/TranslateTextOutputData.java
new file mode 100644
index 000000000..b974b465f
--- /dev/null
+++ b/src/main/java/use_case/translateText/TranslateTextOutputData.java
@@ -0,0 +1,36 @@
+package use_case.translateText;
+
+/**
+ * Output Data for the TranslateText Use Case.
+ */
+public class TranslateTextOutputData {
+
+ private final String inputText;
+ private final String outputText;
+ private final String inputLanguage;
+ private final String outputLanguage;
+
+ public TranslateTextOutputData(String inputText, String outputText, String inputLanguage,
+ String outputLanguage) {
+ this.inputText = inputText;
+ this.outputText = outputText;
+ this.inputLanguage = inputLanguage;
+ this.outputLanguage = outputLanguage;
+ }
+
+ public String getInputText() {
+ return inputText;
+ }
+
+ public String getOutputText() {
+ return outputText;
+ }
+
+ public String getInputLanguage() {
+ return inputLanguage;
+ }
+
+ public String getOutputLanguage() {
+ return outputLanguage;
+ }
+}
diff --git a/src/main/java/view/Constants.java b/src/main/java/view/Constants.java
new file mode 100644
index 000000000..460105e68
--- /dev/null
+++ b/src/main/java/view/Constants.java
@@ -0,0 +1,11 @@
+package view;
+
+/**
+ * Magic numbers used in View.
+ */
+
+public class Constants {
+ public static final int PANEL_WIDTH = 300;
+ public static final int PANEL_HEIGHT = 325;
+ public static final int COMBOBOX_HEIGHT = 25;
+}
diff --git a/src/main/java/view/NoteView.java b/src/main/java/view/NoteView.java
deleted file mode 100644
index 331d76493..000000000
--- a/src/main/java/view/NoteView.java
+++ /dev/null
@@ -1,95 +0,0 @@
-package view;
-
-import java.awt.Component;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.beans.PropertyChangeEvent;
-import java.beans.PropertyChangeListener;
-
-import javax.swing.BoxLayout;
-import javax.swing.JButton;
-import javax.swing.JLabel;
-import javax.swing.JOptionPane;
-import javax.swing.JPanel;
-import javax.swing.JTextArea;
-
-import interface_adapter.note.NoteController;
-import interface_adapter.note.NoteState;
-import interface_adapter.note.NoteViewModel;
-
-/**
- * The View for when the user is viewing a note in the program.
- */
-public class NoteView extends JPanel implements ActionListener, PropertyChangeListener {
-
- private final NoteViewModel noteViewModel;
-
- private final JLabel noteName = new JLabel("note for jonathan_calver2");
- private final JTextArea noteInputField = new JTextArea();
-
- private final JButton saveButton = new JButton("Save");
- private final JButton refreshButton = new JButton("Refresh");
- private NoteController noteController;
-
- public NoteView(NoteViewModel noteViewModel) {
-
- noteName.setAlignmentX(Component.CENTER_ALIGNMENT);
- this.noteViewModel = noteViewModel;
- this.noteViewModel.addPropertyChangeListener(this);
-
- final JPanel buttons = new JPanel();
- buttons.add(saveButton);
- buttons.add(refreshButton);
-
- saveButton.addActionListener(
- evt -> {
- if (evt.getSource().equals(saveButton)) {
- noteController.execute(noteInputField.getText());
-
- }
- }
- );
-
- refreshButton.addActionListener(
- evt -> {
- if (evt.getSource().equals(refreshButton)) {
- noteController.execute(null);
-
- }
- }
- );
-
- this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
-
- this.add(noteName);
- this.add(noteInputField);
- this.add(buttons);
- }
-
- /**
- * React to a button click that results in evt.
- * @param evt the ActionEvent to react to
- */
- public void actionPerformed(ActionEvent evt) {
- System.out.println("Click " + evt.getActionCommand());
- }
-
- @Override
- public void propertyChange(PropertyChangeEvent evt) {
- final NoteState state = (NoteState) evt.getNewValue();
- setFields(state);
- if (state.getError() != null) {
- JOptionPane.showMessageDialog(this, state.getError(),
- "Error", JOptionPane.ERROR_MESSAGE);
- }
- }
-
- private void setFields(NoteState state) {
- noteInputField.setText(state.getNote());
- }
-
- public void setNoteController(NoteController controller) {
- this.noteController = controller;
- }
-}
-
diff --git a/src/main/java/view/TranslateFileView.java b/src/main/java/view/TranslateFileView.java
new file mode 100644
index 000000000..74b69a946
--- /dev/null
+++ b/src/main/java/view/TranslateFileView.java
@@ -0,0 +1,208 @@
+package view;
+
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Dimension;
+import java.awt.Font;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.List;
+import java.util.Map;
+
+import javax.swing.BoxLayout;
+import javax.swing.JButton;
+import javax.swing.JComboBox;
+import javax.swing.JFileChooser;
+import javax.swing.JLabel;
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+
+import data_access.DBTranslateFileDataAccessObject;
+import interface_adapter.translateFile.TranslateFileController;
+import interface_adapter.translateFile.TranslateFileState;
+import interface_adapter.translateFile.TranslateFileViewModel;
+import use_case.translateFile.TranslateFileDataAccessInterface;
+import use_case.translateText.DataAccessException;
+
+/**
+ * The View for when the user is translating a file.
+ */
+public class TranslateFileView extends JPanel implements ActionListener, PropertyChangeListener {
+
+ private static final int BYTE_ARRAY_CONSTANT = 1024;
+ private static final Dimension BUTTONS_DIM = new Dimension(500, 70);
+ private static final Font FILEBUTTONS_FONT = new Font("Arial", Font.PLAIN, 25);
+ private static final Color UPLOADBUTTON_COLOR = new Color(47, 237, 149);
+ private static final Color DOWNLOADBUTTON_COLOR = new Color(170, 98, 209);
+
+ private final TranslateFileViewModel translateFileViewModel;
+
+ private final JLabel translation = new JLabel("File Translation");
+ private final JFileChooser translateFileInputField = new JFileChooser();
+ private final JFileChooser translateFileOutputField = new JFileChooser();
+ private final TranslateFileDataAccessInterface translateFileDai = new DBTranslateFileDataAccessObject();
+ private final List inputLanguages;
+ private final List outputLanguages;
+ private final JComboBox inputLanguageComboBox;
+ private final JComboBox outputLanguageComboBox;
+
+ private final JButton uploadButton = new JButton("Upload File");
+ private final JButton downloadButton = new JButton("Download Translated File");
+ private TranslateFileController translateFileController;
+ private final TranslateFileState translateFileState = new TranslateFileState();
+
+ public TranslateFileView(TranslateFileViewModel translateFileViewModel) {
+
+ translation.setAlignmentX(Component.CENTER_ALIGNMENT);
+ this.translateFileViewModel = translateFileViewModel;
+ this.translateFileViewModel.addPropertyChangeListener(this);
+
+ inputLanguages = translateFileDai.getInputLanguages();
+ outputLanguages = translateFileDai.getOutputLanguages(null);
+
+ inputLanguageComboBox = new JComboBox(inputLanguages.toArray());
+ inputLanguageComboBox.setAlignmentX(Component.CENTER_ALIGNMENT);
+ outputLanguageComboBox = new JComboBox(outputLanguages.toArray());
+ outputLanguageComboBox.setAlignmentX(Component.CENTER_ALIGNMENT);
+
+ final JPanel filebuttons = new JPanel();
+ uploadButton.setPreferredSize(BUTTONS_DIM);
+ uploadButton.setBackground(UPLOADBUTTON_COLOR);
+ uploadButton.setFont(FILEBUTTONS_FONT);
+ downloadButton.setPreferredSize(BUTTONS_DIM);
+ downloadButton.setBackground(DOWNLOADBUTTON_COLOR);
+ downloadButton.setFont(FILEBUTTONS_FONT);
+ filebuttons.add(uploadButton);
+ filebuttons.add(downloadButton);
+
+ uploadButton.addActionListener(
+ this::fileUploadRequest
+ );
+
+ downloadButton.addActionListener(
+ evt -> {
+ try {
+ downloadFileRequest(evt);
+ }
+ catch (DataAccessException ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+ );
+
+ this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
+
+ this.add(translation);
+ this.add(inputLanguageComboBox);
+ this.add(outputLanguageComboBox);
+ this.add(filebuttons);
+ }
+
+ private void fileUploadRequest(ActionEvent evt) {
+ if (evt.getSource().equals(uploadButton)) {
+ final int result = translateFileInputField.showOpenDialog(null);
+ if (result == JFileChooser.APPROVE_OPTION) {
+ translateFileState.setInputFile(translateFileInputField.getSelectedFile());
+ translateFileState.setInputLanguage(inputLanguageComboBox.getSelectedItem().toString());
+ translateFileState.setOutputLanguage(outputLanguageComboBox.getSelectedItem().toString());
+ setFields(translateFileState);
+ JOptionPane.showMessageDialog(null,
+ "Selected File: " + translateFileState.getInputFile().getAbsolutePath());
+
+ translateFileController.executeUpload(translateFileState.getInputLanguage(),
+ translateFileState.getInputFile(),
+ outputLanguageComboBox.getSelectedItem().toString());
+ }
+ }
+ }
+
+ private void downloadFileRequest(ActionEvent evt) throws DataAccessException {
+ if (evt.getSource().equals(downloadButton)) {
+
+ final Map docInfo = translateFileDai.translateDocumentUpload(
+ translateFileState.getInputFile(),
+ translateFileState.getInputLanguage(),
+ translateFileState.getOutputLanguage());
+
+ final String docID = docInfo.get("document_id");
+ final String docKey = docInfo.get("document_key");
+
+ final String status = translateFileDai.getDocumentStatus(docID, docKey);
+
+ if ("done".equals(status)) {
+ final File translatedFile = translateFileDai.downloadDocument(
+ docID, docKey);
+ translateFileState.setOutputFile(translatedFile);
+ translateFileState.setInputLanguage(inputLanguageComboBox.getSelectedItem().toString());
+ translateFileState.setOutputLanguage(outputLanguageComboBox.getSelectedItem().toString());
+ setFields(translateFileState);
+
+ translateFileOutputField.setDialogType(JFileChooser.SAVE_DIALOG);
+ translateFileOutputField.setApproveButtonText("Save");
+ translateFileOutputField.setDialogTitle("Choose the location to save the translated file");
+ final int returnValue = translateFileOutputField.showSaveDialog(null);
+
+ if (returnValue == JFileChooser.APPROVE_OPTION) {
+ final File selectedFile = translateFileOutputField.getSelectedFile();
+ try (InputStream translatedFileInputStream = new FileInputStream(
+ translateFileState.getOutputFile());
+
+ OutputStream fileOutputStream = new FileOutputStream(selectedFile)) {
+
+ final byte[] buffer = new byte[BYTE_ARRAY_CONSTANT];
+ int bytesRead;
+
+ while ((bytesRead = translatedFileInputStream.read(buffer)) != -1) {
+ fileOutputStream.write(buffer, 0, bytesRead);
+ }
+ JOptionPane.showMessageDialog(null, "File saved successfully.",
+ "Success", JOptionPane.INFORMATION_MESSAGE);
+ }
+ catch (IOException ex) {
+ JOptionPane.showMessageDialog(null, "Error: " + ex.getMessage(),
+ "ERROR: ", JOptionPane.ERROR_MESSAGE);
+ }
+ }
+ }
+ else {
+ JOptionPane.showMessageDialog(null, status,
+ "Message", JOptionPane.INFORMATION_MESSAGE);
+ }
+ }
+ }
+
+ /**
+ * React to a button click that results in evt.
+ * @param evt the ActionEvent to react to
+ */
+ public void actionPerformed(ActionEvent evt) {
+ System.out.println("Click " + evt.getActionCommand());
+ }
+
+ @Override
+ public void propertyChange(PropertyChangeEvent evt) {
+ final TranslateFileState state = (TranslateFileState) evt.getNewValue();
+ setFields(state);
+ if (state.getError() != null) {
+ JOptionPane.showMessageDialog(this, state.getError(),
+ "Error", JOptionPane.ERROR_MESSAGE);
+ }
+ }
+
+ private void setFields(TranslateFileState state) {
+ translateFileOutputField.setSelectedFile(state.getOutputFile());
+ }
+
+ public void setTranslateFileController(TranslateFileController controller) {
+ this.translateFileController = controller;
+ }
+
+}
diff --git a/src/main/java/view/checkUsage/CheckUsageView.java b/src/main/java/view/checkUsage/CheckUsageView.java
new file mode 100644
index 000000000..f63a1555b
--- /dev/null
+++ b/src/main/java/view/checkUsage/CheckUsageView.java
@@ -0,0 +1,107 @@
+package view.checkUsage;
+
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Dimension;
+import java.awt.Font;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+
+import javax.swing.BoxLayout;
+import javax.swing.JButton;
+import javax.swing.JLabel;
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+import javax.swing.JTextField;
+
+import data_access.DBCheckUsageDataAccessObject;
+import interface_adapter.checkUsage.CheckUsageController;
+import interface_adapter.checkUsage.CheckUsageState;
+import interface_adapter.checkUsage.CheckUsageViewModel;
+import use_case.checkUsage.CheckUsageDataAccessInterface;
+
+/**
+ * The View for when the user is translating a file.
+ */
+public class CheckUsageView extends JPanel implements ActionListener, PropertyChangeListener {
+
+ private static final Dimension BUTTONS_DIM = new Dimension(250, 35);
+ private static final Font BUTTON_FONT = new Font("Arial", Font.PLAIN, 18);
+ private static final Color BUTTON_COLOR = new Color(108, 184, 198);
+
+ private final CheckUsageViewModel checkUsageViewModel;
+
+ private final JLabel title = new JLabel("Current Usage");
+ private final JTextField characterCountOutputField = new JTextField(15);
+ private final JTextField characterLimitOutputField = new JTextField(15);
+ private final CheckUsageDataAccessInterface checkUsageDai = new DBCheckUsageDataAccessObject();
+
+ private final JButton checkUsageButton = new JButton("Check Current Usage");
+ private CheckUsageController checkUsageController;
+ private final CheckUsageState checkUsageState = new CheckUsageState();
+
+ public CheckUsageView(CheckUsageViewModel checkUsageViewModel) {
+
+ this.checkUsageViewModel = checkUsageViewModel;
+ this.checkUsageViewModel.addPropertyChangeListener(this);
+
+ this.characterCountOutputField.setEditable(false);
+ this.characterLimitOutputField.setEditable(false);
+
+ title.setAlignmentX(Component.CENTER_ALIGNMENT);
+
+ final LabelTextPanel usageCount = new LabelTextPanel(
+ new JLabel("character count"), characterCountOutputField);
+ final LabelTextPanel usageLimit = new LabelTextPanel(
+ new JLabel("character limit"), characterLimitOutputField);
+
+ final JPanel bottons = new JPanel();
+ checkUsageButton.setPreferredSize(BUTTONS_DIM);
+ checkUsageButton.setBackground(BUTTON_COLOR);
+ checkUsageButton.setFont(BUTTON_FONT);
+ bottons.add(checkUsageButton);
+
+ checkUsageButton.addActionListener(
+ evt -> {
+ checkUsageController.execute();
+ }
+ );
+
+ this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
+
+ this.add(title);
+ this.add(usageCount);
+ this.add(usageLimit);
+ this.add(bottons);
+ }
+
+ /**
+ * React to a button click that results in evt.
+ * @param evt the ActionEvent to react to
+ */
+ public void actionPerformed(ActionEvent evt) {
+ System.out.println("Click " + evt.getActionCommand());
+ }
+
+ @Override
+ public void propertyChange(PropertyChangeEvent evt) {
+ final CheckUsageState state = (CheckUsageState) evt.getNewValue();
+ setFields(state);
+ if (state.getError() != null) {
+ JOptionPane.showMessageDialog(this, state.getError(),
+ "Error", JOptionPane.ERROR_MESSAGE);
+ }
+ }
+
+ private void setFields(CheckUsageState state) {
+ characterCountOutputField.setText(state.getCharacterCount());
+ characterLimitOutputField.setText(state.getCharacterLimit());
+ }
+
+ public void setCheckUsageController(CheckUsageController controller) {
+ this.checkUsageController = controller;
+ }
+
+}
diff --git a/src/main/java/view/checkUsage/LabelTextPanel.java b/src/main/java/view/checkUsage/LabelTextPanel.java
new file mode 100644
index 000000000..9995a39c7
--- /dev/null
+++ b/src/main/java/view/checkUsage/LabelTextPanel.java
@@ -0,0 +1,16 @@
+package view.checkUsage;
+
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JTextField;
+
+/**
+ * A panel containing a label and a text field.
+ */
+
+public class LabelTextPanel extends JPanel {
+ LabelTextPanel(JLabel label, JTextField textField) {
+ this.add(label);
+ this.add(textField);
+ }
+}
diff --git a/src/main/java/view/translateText/TranslateTextView.java b/src/main/java/view/translateText/TranslateTextView.java
new file mode 100644
index 000000000..af065a47d
--- /dev/null
+++ b/src/main/java/view/translateText/TranslateTextView.java
@@ -0,0 +1,126 @@
+package view.translateText;
+
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+
+import javax.swing.JComboBox;
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+import javax.swing.JTextArea;
+
+import interface_adapter.imageUpload.ImageUploadController;
+import interface_adapter.switchTranslation.SwitchTranslationController;
+import interface_adapter.textToSpeech.TextToSpeechController;
+import interface_adapter.translateText.TranslateState;
+import interface_adapter.translateText.TranslateTextController;
+
+/**
+ * The View for when the user is translating.
+ */
+public class TranslateTextView extends JPanel implements ActionListener, PropertyChangeListener {
+
+ private JTextArea translateInputField;
+ private JTextArea translateOutputField;
+ private JComboBox inputLanguageComboBox;
+ private JComboBox outputLanguageComboBox;
+
+ private TranslateTextViewButtonPanel buttonPanel;
+ private TranslateTextViewTextPanel inputPanel;
+ private TranslateTextViewTextPanel outputPanel;
+
+ public TranslateTextView() {
+ }
+
+ /**
+ * React to a button click that results in evt.
+ * @param evt the ActionEvent to react to
+ */
+ public void actionPerformed(ActionEvent evt) {
+ System.out.println("Click " + evt.getActionCommand());
+ }
+
+ @Override
+ public void propertyChange(PropertyChangeEvent evt) {
+ final TranslateState state = (TranslateState) evt.getNewValue();
+ setFields(state);
+ if (state.getError() != null) {
+ JOptionPane.showMessageDialog(this, state.getError(),
+ "Error", JOptionPane.ERROR_MESSAGE);
+ }
+ }
+
+ private void setFields(TranslateState state) {
+
+ translateOutputField.setText(state.getOutputText());
+ inputLanguageComboBox.setSelectedItem(state.getInputLanguage());
+ outputLanguageComboBox.setSelectedItem(state.getOutputLanguage());
+ translateInputField.setText(state.getInputText());
+
+ }
+
+ /**
+ * Sets the components of TranslateTextView that are modified during the program.
+ * @param outputTextArea text area where translated is displayed
+ * @param inputComboBox combobox to select input language
+ * @param outputComboBox combobox to select input language
+ * @param inputTextArea text where text is inputted
+ */
+ public void setObservableComponents(JTextArea outputTextArea,
+ JComboBox inputComboBox,
+ JComboBox outputComboBox,
+ JTextArea inputTextArea) {
+ this.translateOutputField = outputTextArea;
+ this.inputLanguageComboBox = inputComboBox;
+ this.outputLanguageComboBox = outputComboBox;
+ this.translateInputField = inputTextArea;
+ }
+
+ public void setButtonPanel(TranslateTextViewButtonPanel buttonPanel) {
+ this.buttonPanel = buttonPanel;
+ }
+
+ public void setInputPanel(TranslateTextViewTextPanel inputPanel) {
+ this.inputPanel = inputPanel;
+ }
+
+ public void setOutputPanel(TranslateTextViewTextPanel outputPanel) {
+ this.outputPanel = outputPanel;
+ }
+
+ /**
+ * Injects TranslateText controller into textButton.
+ * @param translateTextcontroller the controller for TranslateText Use Case
+ */
+ public void setTranslateTextController(TranslateTextController translateTextcontroller) {
+ buttonPanel.setTranslateTextController(translateTextcontroller);
+
+ }
+
+ /**
+ * Injects ImageUpload controller into imageUploadButton.
+ * @param imageUploadController the controller for ImageUpload Use Case
+ */
+ public void setImageUploadController(ImageUploadController imageUploadController) {
+ buttonPanel.setImageUploadController(imageUploadController);
+ }
+
+ /**
+ * Injects SwitchTranslation controller into switchButton.
+ * @param switchTranslationController the controller for SwitchTranslation Use Case
+ */
+ public void setSwitchTranslationController(SwitchTranslationController switchTranslationController) {
+ buttonPanel.setSwitchTranslationController(switchTranslationController);
+ }
+
+ /**
+ * Injects TextToSpeechController into speaker button.
+ * @param textToSpeechController the controller for TextToSpeech Use Case
+ */
+ public void setTextToSpeechController(TextToSpeechController textToSpeechController) {
+ inputPanel.setTextToSpeechController(textToSpeechController);
+ outputPanel.setTextToSpeechController(textToSpeechController);
+ }
+
+}
diff --git a/src/main/java/view/translateText/TranslateTextViewBuilder.java b/src/main/java/view/translateText/TranslateTextViewBuilder.java
new file mode 100644
index 000000000..e8da479ff
--- /dev/null
+++ b/src/main/java/view/translateText/TranslateTextViewBuilder.java
@@ -0,0 +1,138 @@
+package view.translateText;
+
+import java.awt.Component;
+import java.awt.FlowLayout;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.swing.BorderFactory;
+import javax.swing.JComboBox;
+import javax.swing.JTextArea;
+
+import interface_adapter.translateText.TranslateTextViewModel;
+import use_case.translateText.DataAccessException;
+import use_case.translateText.TranslateTextDataAccessInterface;
+
+/**
+ * Builder for the TranslateTextView.
+ */
+public class TranslateTextViewBuilder {
+
+ private TranslateTextViewTextPanel inputPanel;
+ private TranslateTextViewTextPanel outputPanel;
+ private TranslateTextViewButtonPanel buttonPanel;
+ private TranslateTextViewModel translateTextViewModel;
+ private TranslateTextDataAccessInterface translateTextDAO;
+ private JTextArea translateInputField;
+ private JTextArea translateOutputField;
+ private JComboBox inputLanguageComboBox;
+ private JComboBox outputLanguageComboBox;
+ private List inputLanguages = new ArrayList<>();
+ private List outputLanguages = new ArrayList<>();
+ private TranslateTextView view;
+
+ /**
+ * Add the view model.
+ * @param viewModel the information to be displayed by view.
+ * @return this builder
+ */
+ public TranslateTextViewBuilder addViewModel(TranslateTextViewModel viewModel) {
+ translateTextViewModel = viewModel;
+ return this;
+ }
+
+ /**
+ * Add the TranslateTextDAO. This is used to get
+ * @param translateTextDai the data access interface
+ * @return this builder
+ */
+ public TranslateTextViewBuilder addDAO(TranslateTextDataAccessInterface translateTextDai) {
+ this.translateTextDAO = translateTextDai;
+ return this;
+ }
+
+ /**
+ * Retrieves the list of input and output languages.
+ * @return this builder
+ * @throws RuntimeException if called before addDAO
+ */
+ public TranslateTextViewBuilder addLanguages() {
+ if (translateTextDAO == null) {
+ throw new RuntimeException("addLanguages must be called after addDAO");
+ }
+ inputLanguages = translateTextDAO.getInputLanguages();
+ outputLanguages = translateTextDAO.getOutputLanguages(null);
+
+ return this;
+ }
+
+ /**
+ * Create the input panel where user can select input language, enter text, and turn input text to speech.
+ * @return this builder
+ * @throws RuntimeException if this method is called before addLanguages
+ */
+ public TranslateTextViewBuilder addInputPanel() {
+ if (inputLanguages == null) {
+ throw new RuntimeException("addInputPanel must be called after addLanguages");
+ }
+
+ inputPanel = new TranslateTextViewTextPanel(inputLanguages);
+ inputPanel.setBorder(BorderFactory.createTitledBorder("INPUT"));
+ inputPanel.getLanguageComboBox().setAlignmentX(Component.LEFT_ALIGNMENT);
+ translateInputField = inputPanel.getTextArea();
+ inputLanguageComboBox = inputPanel.getLanguageComboBox();
+
+ return this;
+ }
+
+ /**
+ * Create the outpanel where user can select input language, view translated text, and turn input text to speech.
+ * @return this builder
+ * @throws RuntimeException if this method is called before addLanguages
+ */
+ public TranslateTextViewBuilder addOutputPanel() {
+ if (outputLanguages == null) {
+ throw new RuntimeException("addOutputPanel must be called after addLanguages");
+ }
+ outputPanel = new TranslateTextViewTextPanel(outputLanguages);
+ outputPanel.setBorder(BorderFactory.createTitledBorder("OUTPUT"));
+ outputPanel.getLanguageComboBox().setAlignmentX(Component.LEFT_ALIGNMENT);
+ outputPanel.getTextArea().setEditable(false);
+ translateOutputField = outputPanel.getTextArea();
+ outputLanguageComboBox = outputPanel.getLanguageComboBox();
+ return this;
+ }
+
+ /**
+ * Create the Button Panel where user can select different features/use cases.
+ * @return this builder
+ */
+ public TranslateTextViewBuilder addButtonPanel() {
+ buttonPanel = new TranslateTextViewButtonPanel(view, inputPanel, outputPanel);
+
+ return this;
+ }
+
+ /**
+ * Creates the TranslateTextView and assigns values to its instance attributes.
+ * @return an instance of TranslateTextView
+ */
+ public TranslateTextView build() {
+
+ view = new TranslateTextView();
+ translateTextViewModel.addPropertyChangeListener(view);
+ view.setObservableComponents(translateOutputField, inputLanguageComboBox,
+ outputLanguageComboBox, translateInputField);
+ view.setButtonPanel(buttonPanel);
+ view.setInputPanel(inputPanel);
+ view.setOutputPanel(outputPanel);
+ view.setLayout(new FlowLayout());
+
+ view.add(inputPanel);
+ view.add(outputPanel);
+ view.add(buttonPanel);
+
+ return view;
+ }
+
+}
diff --git a/src/main/java/view/translateText/TranslateTextViewButtonPanel.java b/src/main/java/view/translateText/TranslateTextViewButtonPanel.java
new file mode 100644
index 000000000..2e29e29ff
--- /dev/null
+++ b/src/main/java/view/translateText/TranslateTextViewButtonPanel.java
@@ -0,0 +1,163 @@
+package view.translateText;
+
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.io.File;
+
+import javax.swing.ImageIcon;
+import javax.swing.JButton;
+import javax.swing.JFileChooser;
+import javax.swing.JFrame;
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+import javax.swing.filechooser.FileNameExtensionFilter;
+
+import app.CheckUsageAppBuilder;
+import app.TranslateFileAppBuilder;
+import data_access.DBCheckUsageDataAccessObject;
+import data_access.DBTranslateFileDataAccessObject;
+import interface_adapter.imageUpload.ImageUploadController;
+import interface_adapter.switchTranslation.SwitchTranslationController;
+import interface_adapter.translateText.TranslateTextController;
+
+/**
+ * Button Panel of TranslateTextView where user can select which features of the app to use.
+ * These include translating text, translating videos, translating files, uploading text from images,
+ * and switching input and output fields.
+ */
+public class TranslateTextViewButtonPanel extends JPanel {
+
+ private final JPanel buttonPanel = this;
+ private final JButton textButton = new JButton("Translate Text");
+ private final JButton usageButton = new JButton("Check Usage");
+ private final JButton fileButton = new JButton("Translate File");
+ private final JButton switchButton = new JButton("Switch");
+ private final JButton imageButton = new JButton("Image Upload");
+ private final TranslateTextView view;
+ private final TranslateFileAppBuilder translateFileAppBuilder = new TranslateFileAppBuilder();
+ private final JFrame fileFrame = translateFileAppBuilder.addTranslateFileDAO(new DBTranslateFileDataAccessObject())
+ .addTranslateFileView().addTranslateFileUseCase().build();
+ private final CheckUsageAppBuilder checkUsageAppBuilder = new CheckUsageAppBuilder();
+ private final JFrame usageFrame = checkUsageAppBuilder.addCheckUsageDAO(new DBCheckUsageDataAccessObject())
+ .addCheckUsageView().addCheckUsageUseCase().build();
+ private final TranslateTextViewTextPanel inputPanel;
+ private final TranslateTextViewTextPanel outputPanel;
+ private TranslateTextController translateTextController;
+ private SwitchTranslationController switchTranslationController;
+ private ImageUploadController imageUploadController;
+
+ public TranslateTextViewButtonPanel(TranslateTextView view, TranslateTextViewTextPanel inputPanel,
+ TranslateTextViewTextPanel outputPanel) {
+ this.add(textButton);
+ this.add(usageButton);
+ this.add(fileButton);
+ this.add(switchButton);
+ this.add(imageButton);
+
+ addTextButtonListener();
+ addUsageButtonListener();
+ addImageButtonListener();
+ addSwitchButtonListener();
+ addFileButtonListener();
+
+ this.view = view;
+ this.inputPanel = inputPanel;
+ this.outputPanel = outputPanel;
+ }
+
+ /**
+ * Creates and injects an action listener into textButton.
+ */
+ public void addTextButtonListener() {
+ textButton.addActionListener(
+ evt -> {
+ if (evt.getSource().equals(textButton)) {
+ translateTextController.execute(inputPanel.getLanguageComboBox().getSelectedItem().toString(),
+ inputPanel.getTextArea().getText(), outputPanel.getLanguageComboBox().getSelectedItem()
+ .toString());
+ }
+ }
+ );
+ }
+
+ /**
+ * Creates and injects an action listener into usageButton.
+ */
+ public void addUsageButtonListener() {
+ usageButton.addActionListener(
+ evt -> {
+ if (evt.getSource() == usageButton) {
+ usageFrame.setVisible(true);
+ }
+ }
+ );
+ }
+
+ /**
+ * Creates and injects an action listener into imageButton.
+ */
+ public void addImageButtonListener() {
+ final ActionListener listener = new ActionListener() {
+ /**
+ * Invoked when an action occurs.
+ *
+ * @param evt the event to be processed
+ */
+ @Override
+ public void actionPerformed(ActionEvent evt) {
+ // Save the current input text so it does not get overriden
+ if (evt.getSource().equals(imageButton)) {
+ final JFileChooser fileChooser = new JFileChooser();
+ final FileNameExtensionFilter fileFilter = new FileNameExtensionFilter("Image Files",
+ "png", "jpg", "gif", "pdf", "tif", "bmp");
+ fileChooser.setFileFilter(fileFilter);
+ final int result = fileChooser.showOpenDialog(buttonPanel);
+ if (result == JFileChooser.APPROVE_OPTION) {
+ final File imageFile = fileChooser.getSelectedFile();
+ imageUploadController.execute(imageFile, inputPanel.getTextArea().getText());
+ JOptionPane.showMessageDialog(view,
+ "", "Uploaded Image:",
+ JOptionPane.PLAIN_MESSAGE, new ImageIcon(imageFile.getAbsolutePath()));
+ }
+ }
+ }
+ };
+
+ imageButton.addActionListener(listener);
+ }
+
+ /**
+ * Creates and injects an action listener into switchButton.
+ */
+ public void addSwitchButtonListener() {
+ switchButton.addActionListener(evt -> {
+ final String inputText = inputPanel.getTextArea().getText().trim();
+ final Object inputLang = inputPanel.getLanguageComboBox().getSelectedItem();
+ final Object outputLang = outputPanel.getLanguageComboBox().getSelectedItem();
+
+ switchTranslationController.execute(inputText, inputLang.toString(), outputLang.toString());
+ });
+ }
+
+ /**
+ * Creates and injects an action listener into fileButton.
+ */
+ public void addFileButtonListener() {
+ fileButton.addActionListener(evt -> {
+ fileFrame.setVisible(true);
+ });
+ }
+
+ public void setTranslateTextController(TranslateTextController translateTextController) {
+ this.translateTextController = translateTextController;
+ }
+
+ public void setSwitchTranslationController(SwitchTranslationController switchTranslationController) {
+ this.switchTranslationController = switchTranslationController;
+ }
+
+ public void setImageUploadController(ImageUploadController imageUploadController) {
+ this.imageUploadController = imageUploadController;
+ }
+
+}
diff --git a/src/main/java/view/translateText/TranslateTextViewTextPanel.java b/src/main/java/view/translateText/TranslateTextViewTextPanel.java
new file mode 100644
index 000000000..0f6a43771
--- /dev/null
+++ b/src/main/java/view/translateText/TranslateTextViewTextPanel.java
@@ -0,0 +1,93 @@
+package view.translateText;
+
+import java.awt.Component;
+import java.awt.Dimension;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.util.List;
+
+import javax.swing.BoxLayout;
+import javax.swing.ImageIcon;
+import javax.swing.JButton;
+import javax.swing.JComboBox;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JTextArea;
+
+import interface_adapter.textToSpeech.TextToSpeechController;
+import view.Constants;
+
+/**
+ * Text Panel in TranslateTextView that has common elements from the input and output panel.
+ */
+public class TranslateTextViewTextPanel extends JPanel {
+ private final JComboBox languageComboBox;
+ private final JTextArea textArea;
+ private JButton speakerButton;
+ private TextToSpeechController textToSpeechController;
+
+ public TranslateTextViewTextPanel(List languages) {
+
+ // Format panel
+ final BoxLayout boxLayout = new BoxLayout(this, BoxLayout.Y_AXIS);
+ this.setLayout(boxLayout);
+ this.setPreferredSize(new Dimension(Constants.PANEL_WIDTH, Constants.PANEL_HEIGHT));
+
+ // Create combobox to select language
+ languageComboBox = new JComboBox(languages.toArray());
+ languageComboBox.setPreferredSize(new Dimension(Constants.PANEL_WIDTH, Constants.COMBOBOX_HEIGHT));
+
+ // Create text area in scroll pane
+ textArea = new JTextArea();
+ textArea.setLineWrap(true);
+ textArea.setWrapStyleWord(true);
+
+ final JScrollPane scrollPane = new JScrollPane(textArea);
+ scrollPane.setPreferredSize(new Dimension(Constants.PANEL_WIDTH, Constants.PANEL_HEIGHT));
+
+ // Create speaker button
+ final ImageIcon speaker = new ImageIcon("Images/speaker_resized.png");
+ speakerButton = new JButton(speaker);
+ speakerButton.setAlignmentX(Component.CENTER_ALIGNMENT);
+ addSpeakerButtonListener();
+
+ // Add components to input panel
+ this.add(languageComboBox);
+ this.add(scrollPane);
+ this.add(speakerButton);
+
+ // Add an action lis
+ }
+
+ public JComboBox getLanguageComboBox() {
+ return languageComboBox;
+ }
+
+ public JTextArea getTextArea() {
+ return textArea;
+ }
+
+ /**
+ * Creates and injects an action listener into the speaker button.
+ */
+ public void addSpeakerButtonListener() {
+ speakerButton.addActionListener(new ActionListener() {
+
+ /**
+ * Invoked when an action occurs.
+ *
+ * @param e the event to be processed
+ */
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ // TODO: replace with speaker button functionality using textToSpeechController
+ textToSpeechController.execute(textArea.getText());
+ }
+ });
+ }
+
+ public void setTextToSpeechController(TextToSpeechController textToSpeechController) {
+ this.textToSpeechController = textToSpeechController;
+ }
+
+}
diff --git a/src/test/java/app/MainNoteApplicationTest.java b/src/test/java/app/MainNoteApplicationTest.java
deleted file mode 100644
index 025d970e2..000000000
--- a/src/test/java/app/MainNoteApplicationTest.java
+++ /dev/null
@@ -1,112 +0,0 @@
-package app;
-
-import entity.User;
-import org.junit.Before;
-import org.junit.Test;
-import use_case.note.NoteDataAccessInterface;
-
-import javax.swing.*;
-import java.awt.*;
-
-import static java.lang.Thread.sleep;
-import static org.junit.Assert.*;
-
-public class MainNoteApplicationTest {
-
- private JFrame app;
-
- @Before
- public void setUp() {
-
- // create the data access and inject it into our builder!
- final NoteDataAccessInterface noteDataAccess = new NoteDataAccessInterface() {
-
- private String note = "test";
-
- @Override
- public String saveNote(User user, String note) {
- this.note = note;
- return note;
- }
-
- @Override
- public String loadNote(User user) {
- return note;
- }
- };
-
- final NoteAppBuilder builder = new NoteAppBuilder();
- app = builder.addNoteDAO(noteDataAccess)
- .addNoteView()
- .addNoteUseCase().build();
-
- app.setVisible(true);
-
- }
-
- /**
- * This is an example of an end-to-end test with a mocked database.
- *
The code creates the application and directly tests to see that the GUI
- * is updated as expected when the buttons and UI elements are interacted with.
- *
- * You can run the test to visually see what happens.
- */
- @Test
- public void testEndToEnd() {
-
- Component[] components = ((JPanel)app.getRootPane().getContentPane().getComponents()[0]).getComponents();
- JTextArea textArea = null;
- for (Component component : components) {
- if (component instanceof JTextArea) {
- textArea = (JTextArea) component;
- assertEquals("test", textArea.getText());
-
- }
- }
-
- textArea.setText("test test");
-
-
- JButton save = null;
- JButton load = null;
- for (Component component : components) {
- if (component instanceof JPanel) {
- for (Component c : ((JPanel) component).getComponents()) {
- if (c instanceof JButton) {
- if (save != null) {
- load = (JButton) c;
- }
- else {
- save = (JButton) c;
- }
- }
- }
- }
- }
-
- save.doClick();
- assertEquals("test test", textArea.getText());
- textArea.setText("");
-
- System.out.println("cleared text; about to refresh...");
- // pause execution for a bit so we can visually see the changes on the screen
- try {
- sleep(1500);
- } catch (InterruptedException e) {
- throw new RuntimeException(e);
- }
-
- load.doClick();
- assertEquals("test test", textArea.getText());
-
- System.out.println("after refresh!");
-
- // pause execution for a bit so we can visually see the changes on the screen
- try {
- sleep(1500);
- } catch (InterruptedException e) {
- throw new RuntimeException(e);
- }
-
- }
-}
\ No newline at end of file
diff --git a/src/test/java/data_access/DBImageUploadDataAccessObjectTest.java b/src/test/java/data_access/DBImageUploadDataAccessObjectTest.java
new file mode 100644
index 000000000..3aaf332ed
--- /dev/null
+++ b/src/test/java/data_access/DBImageUploadDataAccessObjectTest.java
@@ -0,0 +1,28 @@
+package data_access;
+
+import org.junit.Test;
+import use_case.translateText.DataAccessException;
+
+import java.io.File;
+
+import static org.junit.Assert.assertEquals;
+
+public class DBImageUploadDataAccessObjectTest {
+ DBImageUploadDataAccessObject imageUploadDAO = new DBImageUploadDataAccessObject();
+ @Test
+ public void testGetText() throws DataAccessException {
+ String text = imageUploadDAO.getText(new File("Images/imageInFrench.png"));
+ assertEquals("je mange un sandwich\r\n" +
+ "il adore son chien\r\n" +
+ "nous apprenons le franqais\r\n" +
+ "le chat mange le poisson\r\n" +
+ "tu bois un coca-cola\r\n", text);
+ }
+
+ @Test
+ public void testGetTextImageWithNoText() throws DataAccessException {
+ String text = imageUploadDAO.getText(new File("Images/imageNoText.gif"));
+ assertEquals("", text);
+ }
+
+}
diff --git a/src/test/java/data_access/DBTranslateFileDataAccessObjectTest.java b/src/test/java/data_access/DBTranslateFileDataAccessObjectTest.java
new file mode 100644
index 000000000..89f5dfd94
--- /dev/null
+++ b/src/test/java/data_access/DBTranslateFileDataAccessObjectTest.java
@@ -0,0 +1,52 @@
+package data_access;
+
+import org.junit.Test;
+import use_case.translateText.DataAccessException;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.Map;
+
+
+public class DBTranslateFileDataAccessObjectTest {
+ DBTranslateFileDataAccessObject translateFileDAO = new DBTranslateFileDataAccessObject();
+ @Test
+ public void testTranslateFile() throws DataAccessException, IOException {
+
+ File inputfile = new File("TestFileTranslation.txt");
+ Map docInfo =
+ translateFileDAO.translateDocumentUpload(inputfile,
+ "Detect Language", "French");
+ String docId = docInfo.get("document_id");
+ String docKey = docInfo.get("document_key");
+ File fileTranslationResult = translateFileDAO.downloadDocument(docId, docKey);
+
+ while (!"done".equals(translateFileDAO.getDocumentStatus(docId, docKey))){
+ fileTranslationResult = translateFileDAO.downloadDocument(docId, docKey);
+ }
+
+ String translatedFileContent = readFileContent(fileTranslationResult);
+ String expectedTranslation = "C'est l'heure. Il est 2 heures du matin.\n" +
+ "Peux-tu baisser la voix et chuchoter davantage ?\n" +
+ "Quand cette nuit devient un peu plus profonde\n";
+ assert(translatedFileContent.equals(expectedTranslation));
+ }
+
+ private String readFileContent(File file) throws IOException {
+ StringBuilder content = new StringBuilder();
+ try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
+ String line;
+ while ((line = reader.readLine()) != null) {
+ content.append(line).append("\n");
+ }
+ }
+ return content.toString();
+ }
+
+}
+
+
+
+
diff --git a/src/test/java/data_access/DBTranslateTextDataAccessObjectTest.java b/src/test/java/data_access/DBTranslateTextDataAccessObjectTest.java
new file mode 100644
index 000000000..9f218fd76
--- /dev/null
+++ b/src/test/java/data_access/DBTranslateTextDataAccessObjectTest.java
@@ -0,0 +1,19 @@
+package data_access;
+
+import org.junit.Test;
+import use_case.translateText.DataAccessException;
+
+import java.util.List;
+import java.util.Map;
+
+public class DBTranslateTextDataAccessObjectTest {
+ DBTranslateTextDataAccessObject translateTextDAO = new DBTranslateTextDataAccessObject();
+ @Test
+ public void testTranslateText() throws DataAccessException {
+ Map translationResult = translateTextDAO
+ .translateText("Hello World", "Detect Language", "French");
+ assert translationResult.get(Constants.LANGUAGE_KEY).equals("English");
+ assert translationResult.get(Constants.TEXT_KEY).equals("Bonjour le monde");
+ }
+
+}
diff --git a/src/test/java/use_case/imageUpload/ImageUploadInteractorTest.java b/src/test/java/use_case/imageUpload/ImageUploadInteractorTest.java
new file mode 100644
index 000000000..ec0b86a81
--- /dev/null
+++ b/src/test/java/use_case/imageUpload/ImageUploadInteractorTest.java
@@ -0,0 +1,137 @@
+package use_case.imageUpload;
+
+import data_access.InMemoryImageUploadDataAccessObject;
+import org.junit.Test;
+
+import java.io.File;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+public class ImageUploadInteractorTest {
+
+ // Mock DAO by creating in-memory DAO for Image Upload and overriding getText
+ ImageUploadDataAccessInterface imageUploadDAO = new InMemoryImageUploadDataAccessObject() {
+
+ @Override
+ public String getText(File imageFile) {
+ return "test";
+ }
+ };
+
+ @Test
+ public void successTest() {
+
+ // Mock input data to be a valid file from Images folder
+ ImageUploadInputData imageUploadInputData = new ImageUploadInputData(new File("Images/imageInFrench.png"), "");
+
+ // Create a presenter to test whether the output is expected
+ ImageUploadOutputBoundary imageUploadOB = new ImageUploadOutputBoundary() {
+
+ /**
+ * Prepares the success view for the ImageUpload related Use Cases.
+ *
+ * @param imageUploadOutputData the output data
+ */
+ @Override
+ public void prepareSuccessView(ImageUploadOutputData imageUploadOutputData) {
+ assertEquals("test", imageUploadOutputData.getImageText());
+ }
+
+ /**
+ * Prepares the failure view for the ImageUpload related Use Cases.
+ *
+ * @param errorMessage the explanation of the failure
+ * @param inputText the input text prior to ImageUpload Use Case
+ */
+ @Override
+ public void prepareFailView(String errorMessage, String inputText) {
+ fail("Use case failure is unexpected");
+ }
+ };
+
+ ImageUploadInteractor imageUploadInteractor = new ImageUploadInteractor(imageUploadDAO, imageUploadOB);
+
+ imageUploadInteractor.execute(imageUploadInputData);
+ }
+
+ @Test
+ public void failureFileDoesNoteExistTest() {
+
+ // Mock input data to be a file that does not exist
+ ImageUploadInputData imageUploadInputData = new ImageUploadInputData(new File("notAValidFile"), "");
+
+ // Create a presenter to test whether the output is expected
+ ImageUploadOutputBoundary imageUploadOB = new ImageUploadOutputBoundary() {
+
+ /**
+ * Prepares the success view for the ImageUpload related Use Cases.
+ *
+ * @param imageUploadOutputData the output data
+ */
+ @Override
+ public void prepareSuccessView(ImageUploadOutputData imageUploadOutputData) {
+ fail("Use case success is unexpected");
+ }
+
+ /**
+ * Prepares the failure view for the ImageUpload related Use Cases.
+ *
+ * @param errorMessage the explanation of the failure
+ * @param inputText the input text prior to ImageUpload Use Case
+ */
+ @Override
+ public void prepareFailView(String errorMessage, String inputText) {
+ assertEquals("The file does not exist.", errorMessage);
+ }
+ };
+
+ ImageUploadInteractor imageUploadInteractor = new ImageUploadInteractor(imageUploadDAO, imageUploadOB);
+
+ imageUploadInteractor.execute(imageUploadInputData);
+
+ }
+
+ @Test
+ public void failureNoTextInImageTest() {
+
+ // Mock DAO's getText method to return the empty string
+ imageUploadDAO = new InMemoryImageUploadDataAccessObject() {
+ @Override
+ public String getText(File imageFile) {
+ return "";
+ }
+ };
+
+ // Mock input data to be an image with no text
+ ImageUploadInputData imageUploadInputData = new ImageUploadInputData(new File("Images/imageNoText.gif"), "");
+
+ ImageUploadOutputBoundary imageUploadOB = new ImageUploadOutputBoundary() {
+
+ /**
+ * Prepares the success view for the ImageUpload related Use Cases.
+ *
+ * @param imageUploadOutputData the output data
+ */
+ @Override
+ public void prepareSuccessView(ImageUploadOutputData imageUploadOutputData) {
+ fail("Use case success is unexpected");
+ }
+
+ /**
+ * Prepares the failure view for the ImageUpload related Use Cases.
+ *
+ * @param errorMessage the explanation of the failure
+ * @param inputText the input text prior to ImageUpload Use Case
+ */
+ @Override
+ public void prepareFailView(String errorMessage, String inputText) {
+ assertEquals("No text detected from image.", errorMessage);
+ }
+ };
+
+ ImageUploadInteractor imageUploadInteractor = new ImageUploadInteractor(imageUploadDAO, imageUploadOB);
+
+ imageUploadInteractor.execute(imageUploadInputData);
+ }
+}
diff --git a/src/test/java/use_case/note/NoteInteractorTest.java b/src/test/java/use_case/note/NoteInteractorTest.java
deleted file mode 100644
index a3ed466b6..000000000
--- a/src/test/java/use_case/note/NoteInteractorTest.java
+++ /dev/null
@@ -1,46 +0,0 @@
-package use_case.note;
-
-import entity.User;
-import org.junit.Test;
-
-import static org.junit.Assert.*;
-
-public class NoteInteractorTest {
-
- @Test
- public void testExecuteRefreshSuccess() {
-
- NoteDataAccessInterface noteDAO = new NoteDataAccessInterface() {
-
-
- @Override
- public String saveNote(User user, String note) {
- return "";
- }
-
-
- @Override
- public String loadNote(User user) {
- return "test";
- }
- };
-
- NoteOutputBoundary noteOB = new NoteOutputBoundary() {
- @Override
- public void prepareSuccessView(String message) {
- assertEquals("test", message);
- }
-
- @Override
- public void prepareFailView(String errorMessage) {
- fail(errorMessage);
- }
- };
-
- NoteInteractor noteInteractor = new NoteInteractor(noteDAO, noteOB);
-
- noteInteractor.executeRefresh();
-
-
- }
-}
\ No newline at end of file
diff --git a/src/test/java/use_case/switchTranslation/SwitchTranslationInteractorTest.java b/src/test/java/use_case/switchTranslation/SwitchTranslationInteractorTest.java
new file mode 100644
index 000000000..82deaacf1
--- /dev/null
+++ b/src/test/java/use_case/switchTranslation/SwitchTranslationInteractorTest.java
@@ -0,0 +1,155 @@
+package use_case.switchTranslation;
+
+import data_access.DBTranslateTextDataAccessObject;
+import org.junit.Test;
+import use_case.translateText.DataAccessException;
+
+import java.util.Map;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+// the interactor tests.
+public class SwitchTranslationInteractorTest {
+ @Test
+ public void ExecuteSuccessEnglishAsInputTest() {
+
+ SwitchTranslationInputData inputData = new SwitchTranslationInputData("Hello", "English", "French");
+
+ SwitchTranslationDataAccessInterface switchTranslationDAO = new DBTranslateTextDataAccessObject();
+
+ SwitchTranslationOutputBoundary switchTranslationOB =
+ new SwitchTranslationOutputBoundary() {
+ @Override
+ public void prepareSuccessView(SwitchTranslationOutputData switchTranslationOutputData) {
+ assertEquals("Bonjour", switchTranslationOutputData.getInputText());
+ assertEquals("French", switchTranslationOutputData.getInputLanguage());
+ assertEquals("Hello", switchTranslationOutputData.getTranslatedText());
+ assertEquals("English (American)", switchTranslationOutputData.getOutputLanguage());
+ }
+
+ @Override
+ public void prepareFailView(String errorMessage) {
+ fail("Use case failure is unexpected.");
+ }
+ };
+
+ SwitchTranslationInputBoundary switchTranslationInteractor = new
+ SwitchTranslationInteractor(switchTranslationDAO, switchTranslationOB);
+
+ switchTranslationInteractor.execute(inputData);
+
+ }
+
+ @Test
+ public void ExecuteSuccessEnglishAsOutputTest() {
+
+ SwitchTranslationInputData inputData = new SwitchTranslationInputData("Bonjour", "French", "English (British)");
+
+ SwitchTranslationDataAccessInterface switchTranslationDAO = new DBTranslateTextDataAccessObject();
+
+ SwitchTranslationOutputBoundary switchTranslationOB =
+ new SwitchTranslationOutputBoundary() {
+ @Override
+ public void prepareSuccessView(SwitchTranslationOutputData switchTranslationOutputData) {
+ assertEquals("Hello", switchTranslationOutputData.getInputText());
+ assertEquals("English", switchTranslationOutputData.getInputLanguage());
+ assertEquals("Bonjour", switchTranslationOutputData.getTranslatedText());
+ assertEquals("French", switchTranslationOutputData.getOutputLanguage());
+ }
+
+ @Override
+ public void prepareFailView(String errorMessage) {
+ fail("Use case failure is unexpected.");
+ }
+ };
+
+ SwitchTranslationInputBoundary switchTranslationInteractor = new
+ SwitchTranslationInteractor(switchTranslationDAO, switchTranslationOB);
+
+ switchTranslationInteractor.execute(inputData);
+
+ }
+
+ @Test
+ public void failureInputLanguageDoesNotExistTest() {
+ SwitchTranslationInputData inputData = new SwitchTranslationInputData("Apple", "Detect Language", "French");
+
+ SwitchTranslationDataAccessInterface switchTranslationDAO = new DBTranslateTextDataAccessObject();
+
+ use_case.switchTranslation.SwitchTranslationOutputBoundary switchTranslationOB = new use_case.switchTranslation.SwitchTranslationOutputBoundary() {
+ @Override
+ public void prepareSuccessView(use_case.switchTranslation.SwitchTranslationOutputData switchTranslationOutputData) {
+ fail("Use case success is unexpected.");
+ }
+
+ @Override
+ public void prepareFailView(String errorMessage) {
+ assertEquals("Please select an input language.", errorMessage);
+ }
+ };
+
+ SwitchTranslationInputBoundary switchTranslationInteractor = new use_case.switchTranslation.SwitchTranslationInteractor
+ (switchTranslationDAO, switchTranslationOB);
+
+ switchTranslationInteractor.execute(inputData);
+ }
+
+ @Test
+ public void failureInputTextDoesNotExistTest() {
+ SwitchTranslationInputData inputData = new SwitchTranslationInputData("", "English", "French");
+
+ SwitchTranslationDataAccessInterface switchTranslationDAO = new DBTranslateTextDataAccessObject();
+
+ use_case.switchTranslation.SwitchTranslationOutputBoundary switchTranslationOB = new use_case.switchTranslation.SwitchTranslationOutputBoundary() {
+ @Override
+ public void prepareSuccessView(use_case.switchTranslation.SwitchTranslationOutputData switchTranslationOutputData) {
+ fail("Use case success is unexpected.");
+ }
+
+ @Override
+ public void prepareFailView(String errorMessage) {
+ assertEquals("Input text cannot be empty. Please provide "
+ + "text to translate.", errorMessage);
+ }
+ };
+
+ SwitchTranslationInputBoundary switchTranslationInteractor = new use_case.switchTranslation.SwitchTranslationInteractor
+ (switchTranslationDAO, switchTranslationOB);
+
+ switchTranslationInteractor.execute(inputData);
+ }
+
+ @Test
+ public void failureDataAccessExceptionTest() {
+ // Create input data
+ SwitchTranslationInputData inputData = new SwitchTranslationInputData("Test text", "English", "French");
+
+ // Mocked Data Access Object that throws DataAccessException
+ SwitchTranslationDataAccessInterface switchTranslationDAO = new SwitchTranslationDataAccessInterface() {
+ @Override
+ public Map switchLanguagesAndTexts(String inputText, String inputLanguage, String outputLanguage) throws DataAccessException {
+ throw new DataAccessException("Simulated data access error");
+ }
+ };
+
+ // Output Boundary to capture failure messages
+ SwitchTranslationOutputBoundary switchTranslationOB = new SwitchTranslationOutputBoundary() {
+ @Override
+ public void prepareSuccessView(SwitchTranslationOutputData switchTranslationOutputData) {
+ fail("Use case success is unexpected.");
+ }
+
+ @Override
+ public void prepareFailView(String errorMessage) {
+ assertEquals("There seems to be an error with the switching process. Please try again.", errorMessage);
+ }
+ };
+
+ // Create and execute the interactor
+ SwitchTranslationInputBoundary switchTranslationInteractor = new SwitchTranslationInteractor(switchTranslationDAO, switchTranslationOB);
+
+ switchTranslationInteractor.execute(inputData);
+ }
+
+}
\ No newline at end of file
diff --git a/src/test/java/use_case/translateFile/TranslateFileInteractorTest.java b/src/test/java/use_case/translateFile/TranslateFileInteractorTest.java
new file mode 100644
index 000000000..c0c29fe6b
--- /dev/null
+++ b/src/test/java/use_case/translateFile/TranslateFileInteractorTest.java
@@ -0,0 +1,130 @@
+package use_case.translateFile;
+
+import data_access.DBTranslateFileDataAccessObject;
+import entity.FileTranslator;
+import org.junit.Test;
+import use_case.translateText.DataAccessException;
+
+import java.io.*;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+public class TranslateFileInteractorTest {
+
+ private static final String INPUT_LANG = "Detect Language";
+ private static final String OUTPUT_LANG = "French";
+ private static final File INPUT_FILE = new File("TestFileTranslation.txt");
+ private static final File OUTPUT_FILE = new File("Result_TestFileTranslation.txt");
+
+ @Test
+ public void successTest() throws DataAccessException {
+
+ TranslateFileDataAccessInterface translateFileDAO = new DBTranslateFileDataAccessObject() {
+
+ //Mock a successfully translated file by replacing it with in-memory file
+ @Override
+ public File downloadDocument(String documentID, String documentKey) {
+ return OUTPUT_FILE;
+ }
+
+ };
+
+ FileTranslator fileTranslator = new FileTranslator(translateFileDAO);
+ String docID = translateFileDAO.translateDocumentUpload(INPUT_FILE, INPUT_LANG, OUTPUT_LANG).get("document_id");
+ String docKey = translateFileDAO.translateDocumentUpload(INPUT_FILE, INPUT_LANG, OUTPUT_LANG).get("document_key");
+ TranslateFileInputData inputData = new TranslateFileInputData(INPUT_LANG, INPUT_FILE, OUTPUT_LANG, docID, docKey);
+
+ TranslateFileOutputBoundary translateFileOB = new TranslateFileOutputBoundary() {
+
+ @Override
+ public void prepareSuccessView(TranslateFileOutputData translateFileOutputData) {
+ assertEquals(readFileContent(OUTPUT_FILE), readFileContent(translateFileOutputData.getOutputFile()));
+ }
+
+ @Override
+ public void prepareFailView(String errorMessage) {
+ fail("Use case failure is unexpected.");
+ }
+ };
+
+ TranslateFileInputBoundary translateFileInteractor = new TranslateFileInteractor
+ (translateFileDAO, translateFileOB, fileTranslator);
+
+ translateFileInteractor.executeDownload(inputData);
+
+ }
+
+ @Test
+ public void unsupportedFileTypeTest() {
+
+ TranslateFileDataAccessInterface translateFileDAO = new DBTranslateFileDataAccessObject();
+
+ final File inputImage = new File("Images/imageInFrench.png");
+ FileTranslator fileTranslator = new FileTranslator(translateFileDAO);
+ TranslateFileInputData inputData = new TranslateFileInputData(INPUT_LANG, inputImage, OUTPUT_LANG,
+ null, null);
+
+ TranslateFileOutputBoundary translateFileOB = new TranslateFileOutputBoundary() {
+
+ @Override
+ public void prepareSuccessView(TranslateFileOutputData translateFileOutputData) {
+ fail("Use case success is unexpected");
+ }
+
+ @Override
+ public void prepareFailView(String errorMessage) {
+ assertEquals("Unsupported file type.", errorMessage);
+ }
+ };
+
+ TranslateFileInputBoundary translateFileInteractor = new TranslateFileInteractor
+ (translateFileDAO, translateFileOB, fileTranslator);
+
+ translateFileInteractor.executeUpload(inputData);
+
+ }
+
+ @Test
+ public void noFileUploadedTest() {
+
+ TranslateFileDataAccessInterface translateFileDAO = new DBTranslateFileDataAccessObject();
+
+ FileTranslator fileTranslator = new FileTranslator(translateFileDAO);
+ TranslateFileInputData inputData = new TranslateFileInputData(INPUT_LANG,
+ null, OUTPUT_LANG, null, null);
+
+ TranslateFileOutputBoundary translateFileOB = new TranslateFileOutputBoundary() {
+
+ @Override
+ public void prepareSuccessView(TranslateFileOutputData translateFileOutputData) {
+ fail("Use case success is unexpected");
+ }
+
+ @Override
+ public void prepareFailView(String errorMessage) {
+ assertEquals("No file is uploaded.", errorMessage);
+ }
+ };
+
+ TranslateFileInputBoundary translateFileInteractor = new TranslateFileInteractor
+ (translateFileDAO, translateFileOB, fileTranslator);
+
+ translateFileInteractor.executeUpload(inputData);
+
+ }
+
+
+ private String readFileContent(File file) {
+ StringBuilder content = new StringBuilder();
+ try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
+ String line;
+ while ((line = reader.readLine()) != null) {
+ content.append(line).append("\n");
+ }
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ return content.toString();
+ }
+}
diff --git a/src/test/java/use_case/translateText/TranslateTextInteractorTest.java b/src/test/java/use_case/translateText/TranslateTextInteractorTest.java
new file mode 100644
index 000000000..ea57e88f9
--- /dev/null
+++ b/src/test/java/use_case/translateText/TranslateTextInteractorTest.java
@@ -0,0 +1,63 @@
+package use_case.translateText;
+
+import data_access.DBTranslateTextDataAccessObject;
+import entity.TextTranslator;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+public class TranslateTextInteractorTest {
+
+ @Test
+ public void ExecuteSuccessTest() {
+
+ TranslateTextDataAccessInterface translateTextDAO = new DBTranslateTextDataAccessObject();
+ TranslateTextInputData inputData = new TranslateTextInputData("English", "Hello", "French");
+ TextTranslator textTranslator = new TextTranslator(translateTextDAO);
+
+ use_case.translateText.TranslateTextOutputBoundary translateTextOB = new use_case.translateText.TranslateTextOutputBoundary() {
+ @Override
+ public void prepareSuccessView(use_case.translateText.TranslateTextOutputData translateTextOutputData) {
+ assertEquals("Bonjour", translateTextOutputData.getOutputText());
+ assertEquals("English", translateTextOutputData.getInputLanguage());
+ }
+
+ @Override
+ public void prepareFailView(String errorMessage) {
+ fail("Use case failure is unexpected.");
+ }
+ };
+
+ TranslateTextInputBoundary translateTextInteractor = new use_case.translateText.TranslateTextInteractor
+ (translateTextDAO, translateTextOB, textTranslator);
+
+ translateTextInteractor.execute(inputData);
+
+ }
+
+ @Test
+ public void failureLanguageDoesNotExistTest() {
+ TranslateTextDataAccessInterface translateTextDAO = new DBTranslateTextDataAccessObject();
+ TranslateTextInputData inputData = new TranslateTextInputData("unknown", "Hello", "French");
+ TextTranslator textTranslator = new TextTranslator(translateTextDAO);
+
+ use_case.translateText.TranslateTextOutputBoundary translateTextOB = new use_case.translateText.TranslateTextOutputBoundary() {
+ @Override
+ public void prepareSuccessView(use_case.translateText.TranslateTextOutputData translateTextOutputData) {
+ fail("Use case success is unexpected.");
+ }
+
+ @Override
+ public void prepareFailView(String errorMessage) {
+ assertEquals("Selected language does not exist in translator.", errorMessage);
+ }
+ };
+
+ TranslateTextInputBoundary translateTextInteractor = new use_case.translateText.TranslateTextInteractor
+ (translateTextDAO, translateTextOB, textTranslator);
+
+ translateTextInteractor.execute(inputData);
+ }
+
+}
\ No newline at end of file
diff --git a/src/test/java/view/TranslateFileViewTest.java b/src/test/java/view/TranslateFileViewTest.java
new file mode 100644
index 000000000..21a589d4a
--- /dev/null
+++ b/src/test/java/view/TranslateFileViewTest.java
@@ -0,0 +1,33 @@
+package view;
+
+import data_access.DBTranslateFileDataAccessObject;
+import entity.FileTranslator;
+import interface_adapter.translateFile.TranslateFileController;
+import interface_adapter.translateFile.TranslateFilePresenter;
+import interface_adapter.translateFile.TranslateFileViewModel;
+import use_case.translateFile.TranslateFileDataAccessInterface;
+import use_case.translateFile.TranslateFileInteractor;
+
+
+import javax.swing.*;
+import java.awt.*;
+
+
+public class TranslateFileViewTest {
+ public static void main(String[] args) {
+ TranslateFileViewModel model = new TranslateFileViewModel();
+ TranslateFileView view = new TranslateFileView(model);
+ TranslateFileController controller = new TranslateFileController(new TranslateFileInteractor(
+ new DBTranslateFileDataAccessObject(), new TranslateFilePresenter(model),
+ new FileTranslator(new DBTranslateFileDataAccessObject())));
+ view.setTranslateFileController(controller);
+ final JFrame frame = new JFrame();
+ frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
+ frame.setTitle("File Translator");
+ frame.setSize(800, 600);
+
+ frame.add(view);
+ frame.setVisible(true);
+ }
+
+}