CIT 591 Assignment 9: General-Purpose
Text Translator
Fall 2008, David Matuszek
I often have need to perform some simple translations on text--for example, copying text from a PowerPoint slide and getting rid of all the vertical tab characters. If I need to modify text in this way just once in a while, I can do it manually in a text editor; but if I have to do it frequently, I want a tool that does it for me. This assignment is to create just such a tool.
Create a GUI that looks like this picture. (I have used a small window; your text areas should be larger.)
The menu items under the File menu are:
The menu items under the Translate menu are:
{',
encountered, and decreased by four spaces for each close brace, '}'.
Braces are not moved from one line to another; only indentation
is adjusted.'\n',
the carriage return character '\r', and the tab character '\t'.Both the upper and the lower text areas are fully editable. When the user clicks the Translate button or chooses an translation from the Translate menu, the specified translation is applied to the text in the upper area, and the result replaces any previous text in the lower area.
Name your project Translator, your package translator, and your "main" class
Translator.
Create an interface TranslatorInterface that declares the following methods:
String getName();String getDescription();String translate(String text); String[] inputLines = text.split("\n");Each translator class you write should implement TranslatorInterface.
All translator classes you write (yes, even including the identity translator!)
should be fully JUnit tested. Include an AllTests.java test suite.
Your main class should have a method addTranslateItem(TranslatorInterface translator) that
does all the work of adding a new translator to the GUI. That is, it creates
a menu item with the correct name, adds it to the Translate menu,
and adds a listener for this menu item that calls the new translator. In
addition, the name of the translator is displayed in the GUI title bar,
and the description of the translator is displayed just below the title
bar (see the above picture for an example). In other words, you should
be able to install a new translator to your program by adding a single
line to your Translator class, for instance,
addTranslateItem(new ZapGremlinsTranslator());
This is how all of the above translators should be installed in your Translator class; they should not be "hard-wired" in.
Remember that the purpose of doing assignments is to learn, not to produce the required program. If you did not do the GUI for the previous program, you should do it for this program. If you did not to JUnit testing for the previous programs, you should do some of the methods that require it for this program.
All the usual style rules apply. Good Javadoc comments, JUnit tests for all computations, proper formatting and indentation, methods that fit on a single screen, good method and variable names, etc., etc. Use the names and method signatures specified, etc.