Project 3: Enhanced Text Editor
For this project you will work on the code repository created by one of the
other teams for Project 2. You will extend this implementation by adding
support for rich text, including:
- Multiple font families, such as Courier New, Times Roman, etc.
- Multiple sizes for each font (e.g. 9 point, 12 point, etc.)
- Boldface characters
- Italic characters
- Underline
You will also add support for word wrapping.
Features
Here are the specific new features that you should add to the existing
editor:
- New formatting panel: An additional GUI panel should appear
at the top of the window,
displaying controls for each of the above options. To set the
characteristics for a range of characters, the user selects the
characters and then clicks on the appropriate controls. For example,
clicking on the boldface control should set the range of characters
to boldface, unless all of the characters are already in boldface,
in which case it should
clear the boldface attribute. You may use existing Swing controls
to implement this panel. Is sufficient to support a few font families
and sizes for this project (having a larger number will not expose
any additional design issues).
- Independent attributes: The attributes should all be
independently settable (e.g., a character can be both boldface
and italic).
- Insertion format: When the user types in new characters,
each new character should acquire the formatting of the preceding
character in the document.
- Copy and paste: When copying and pasting within a document,
the pasted characters should preserve the formatting of the copied
characters. When pasting from other documents, you can treat the
pasted characters as if they were freshly typed by the user.
- New file format: When writing out files, you must save
information about the rich text formatting, so that when the file is
loaded again all of the formatting will still be visible. Thus, you
must design a file format in which to save the rich text information.
Your file format must support simple text files with no formatting
information, such as the ones you used in Project 1. When an unformatted
file is read by the editor, it should be displayed in a default format
that you can choose. When reading in files, your editor must behave
reasonably if it contains formatting information that doesn't
conform to your chosen syntax. You must design your own syntax for the
files and write your own parser (e.g., you may not use JSON or XML as
the file format). You may use low-level Java parsing packages such
as
StringTokenizer
or regular expressions (e.g.
Pattern
), but I'm not sure that these will actually make
life much simpler for you.
- Line wrapping: For this project, you should implement
automatic line wrapping. This means that the horizontal scrollbar will
no longer be needed. Instead, if a line of text is too long to fit
on a single line of the display window, you must wrap it onto multiple
lines. You should perform word wrapping if possible: split lines only at
space characters unless a single word is too long to fit on one line.
- Scrollbar updates: The size of the vertical scrollbar knob
should take into account word wrapping (the total vertical space required
to display the document might not be closely related to the number of
newline characters in the document).
Refactoring
You will need to make architectural changes to the
existing implementation in order to support the new features. In
addition, you will probably discover things in the existing
implementation that can be improved. As part of the project, you should
improve the structure of the existing code. Even if rich text can be
implemented with no architectural changes, you should make at least
3-4 non-trivial structural improvements. You should spend at least 25%
of your total time for this project on refactoring; focus on
changes that are most important for the new features, or that have
the biggest impact on overall complexity.
In your work for this project, don't take the quick-and-dirty approach
of making the fewest possible code changes to implement the new features.
Instead, think strategically: try to produce the architecture that
would have resulted if you had designed the system from the start
to support the new features. This is a good general approach to use
any time you are
enhancing existing code. If you take the fewest-possible-code-changes
approach, the code will get more complex and harder to read with each
change.
Create a file refactoring
in the top-level project directory
that summarizes the major architectural changes you made during this
project, including the "non-trivial structural improvements" mentioned
above.
Unit tests
Update the Junit test suite to reflect any changes you make for this
project. As with Project 2, the tests should cover all code related to
text management, undo, and redo, and they should use an "isomorphic to
the code" structure. You do not need to write unit tests
for displaying and event handling code.
Submitting Your Project
To submit your project, create another issue on
cs190codereview.appspot.com
as follows:
- Create a git tag named
project3
for the last commit that
is part of your Project 3 submission. Push this tag to GitHub.
- Use the same
upload.py
script that you used for
Project 2 by invoking the following command:
python upload.py --rev project2..project3
This will create a code review that shows the differences between your
Project 2 and Project 3 submissions.
- When asked for "New issue subject", type "AAA/BBB Project 3", where
AAA and BBB are the last names of the team members, in alphabetical
order (use "AAA Project 3" if your team has only one person).
- Don't forget to create a
refactoring
file as described
above.
Once you have created the code review, check to make sure it is visible at
cs190codereview.appspot.com.
Late Days
If you are planning to use late days for this project, please
send me an email before the project deadline so that I know your plans. Send
me another email once you eventually upload your code review.