To make an editor, we will need to store the sequence of entered text characters. We will also need the concept of a cursor, to help us locate where we want to be editing the sequence of text. This cursor will be between characters, and can be moved using the arrow keys. The cursor allows us to insert new characters at the cursor, and delete characters before the cursor with the backspace or delete key.
The text that you enter can then be saved to a file.
editor.model.implementations
package. Much of the manipulation
of references can be found locally here in the Node class, simplifying the
later implementation of the TextView.
Besides the get methods for each fields,
included in the skeleton is an equals
method to determine if two DoubleTextNode
objects have the same internal data.
Also included is a method called isConsistent
method, which will verify
that when this node refers to another node with either its next
or previous
, that node also refers back to this node.
setNext
or setPrev
method included in this implementation. However, if you are inside a class, and
talking to another element of the same class, you have the ability to
modify the other element's private data members.
public void addAfter(DoubleTextNode other)
other
, inserts it immediately after this node in the chain of nodes
that come next
.
public void addBefore(DoubleTextNode other)
other
, inserts it immediately before this node in the chain of nodes
that come previous
.
public void removeAfter()
next
chain.
public void removeBefore()
previous
chain.
public DoubleTextNode copyBefore()
previous
direction,
including this node.
This should be a deep copy of the nodes and their data.
public DoubleTextNode copyAfter()
next
direction,
including this node.
This should be a deep copy of the nodes and their data.
public void mergeAfter(DoubleTextNode other)
other
node into chain after this node, dropping
what is currently stored as next
.
public void mergeBefore(DoubleTextNode other)
other
node into chain before this node, dropping
what is currently stored as previous
.
DoubleTextNodeTest
suite to make
sure your implementation has the correct behavior.
DoubleTextNode
to implement the DocumentView
interface. You can track the cursor implicitly by recording the node before
and the node after
the cursor, and these nodes will keep track of the rest
of the sequence of characters.
public boolean isEmpty()
public void insert(char c)
public void removeBefore()
public boolean atStart()
public boolean atEnd()
public void goRight()
public void goLeft()
public char peekAfter()
public char peekBefore()
public DoubleTextNodeView shallowCopy()
public DoubleTextNodeView deepCopy()
public void removeAll()
DoubleTextNodeViewTest
suite to make
sure your implementation has the correct behavior.
Once you have passed the tests, you should be able to edit text in the GUI window.
ArrayView
class implements the same DocumentView
interface, but with the central data structure of an array. You will
also keep track of the index of the character before the cursor, and
the size of the sequence held in the array.
remove
method that you might find helpful to implement.
ArrayViewTest
suite to make
sure your implementation has the correct behavior.
Once you have passed the tests, you should be able to edit text in the GUI window.