CIT 590 Assignment 11:
General-Purpose Text Translator
Fall 2009, 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. Your GUI should be resizable.
The menu items under the File menu should be:
Put these menu items under the Translate menu:
"\015\012" in
Java) with UNIX newlines ("\012"). "\012") with Windows
newline sequences ("\015\012"). However, be careful
not to modify existing Windows newlines--that is, do not change "\015\012" into "\015\015\012".System.getProperty("line.separator").'\n',
the carriage return character '\r', and the tab character
'\t'.Both the upper and the lower text areas should be fully editable. When the user clicks the Translate button, the specified translation is applied to the text in the upper area, and the result replaces any previous text in the lower area. The program never changes any text in the upper area.
As a convenience, whenever a translation type is chosen from the Translate menu, the new translation should be automatically applied; the user should not have to explicitly click the Translate button.
Zap Gremlins translator, you can easily
create a String containing "gremlin" characters.
\d, \dd,or \ddd,
where the ds are octal digits. For example, "abc\07xyz".
Octal numbers from 0 to 377 are valid.\uDDDD,
where the Ds are exactly four hexadecimal digits.
For example, "abc\u007Fxyz".The main class should have an addTranslateItem(TranslatorInterface
translator) method to install the various translators. It should
be called once for each of the ten translators. Here's what the addTranslateItem method
should do:
TranslateListener.
TranslateListener is a class you have
to write. It should implement ActionListener.
Each time you call addTranslateItem, it should create an
new object of type TranslateListener, and save
the parameter translator in
an instance variable. When the TranslateListener's
actionPerformed method is called, it uses this
instance variable to get the name and description and to do
the translation.TranslateListenershould be an inner
class of TextTranslator. To add yet another translator (class that implements TranslatorInterface)
to the program, all you should have to do is create a new translator of
that type, and add a call to addTranslateItem in your GUI
building method.
Here's what the actionPerformed method of the TranslateListener should do:
Create
an interface TranslatorInterface that
declares the following methods:
String getName();String getDescription();String translate(String text); String[] inputLines =
text.split("\n");TextTranslatortextTranslatorclass TextTranslator extends JFrame
public static void main(String[] args)private void addTranslateItem(TranslatorInterface
translator)class TranslateListener implements ActionListener
public TranslateListener(TranslatorInterface
translator) // constructorpublic void actionPerformed(ActionEvent
arg0) interface TranslatorInterface
String getName();String getDescription();String translate(String text);class IdentityTranslator implements TranslatorInterfaceclass DetabTranslator implements TranslatorInterfaceclass EntabTranslator implements TranslatorInterfaceclass UnixNewlinesTranslator implements TranslatorInterfaceclass WindowsNewlinesTranslator implements TranslatorInterfaceclass SingleSpaceTranslator implements TranslatorInterfaceclass DoubleSpaceTranslator implements TranslatorInterfaceclass WrapTextTranslator implements TranslatorInterfaceclass FlowTextTranslator implements TranslatorInterfaceclass ZapGremlinsTranslator implements TranslatorInterfacetranslate method for all classes
that implement
TranslatorInterface (yes, even
including the identity translator!) . No other methods need be JUnit tested. TextTranslator_yourName_partnersNameAll 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.
Before midnight, Thursday, April 16 . Submit to Blackboard one copy of your project directory, properly zipped. Both your names should be in Javadoc comments in the classes. In addition, whichever of you turns the program in, should put your partner's name in the comments field in Blackboard.