|
miSim | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--misim.editor.Line
The Line class represents a single line of a file. It may contain zero or more tokens, and may also refer to an included file which itself may contain zero or more lines.
Note that the tokens represent the text part of the file.
The tokens are stored as a vector, which is immutable - all edit functions remove the existing vector and replace it with an appropriate new one. This appears heavy handed, but allows undo events to be stored simply by storing the token vector from the line being altered.
Line class objects are created by a class which implements the LineFactory interface.
Line class may be extended to support information generated during assembly or compilation. In this case, a new LineFactory must be implemented, and passed to the editor to create appropriate instances of the Line subclass as files are edited.
Field Summary | |
protected int |
tokenIndex
The index for the TokenIterator interface |
protected java.util.Vector |
tokens
The vector of tokens that this line contains |
Constructor Summary | |
Line()
Constructor, creates a new line with no tokens |
|
Line(java.util.Vector tokens)
Constructor, creates a new line with the given vector of tokens |
Method Summary | |
void |
addError(EditorException editorException)
Add an error to this line, that can be displayed by the editor |
EditorException |
addError(Token aToken,
int errNo)
Add an error to this line, that can be displayed by the editor |
void |
addWarning(Token aToken,
int errNo)
Add an warning to this line, that can be displayed by the editor |
void |
clearErrors()
Remove all errors and warnings from this line. |
int |
countTokens()
|
boolean |
delete(int start,
int length,
Line endLine,
Parser parser,
EditorPrefs prefs)
Delete a range of characters starting on this line. |
void |
draw(java.awt.Graphics g,
int x,
int y,
int lineHeight,
int lineWidth,
int leftMargin,
boolean showErrors)
Draw this line |
int |
errorCount()
Return the number of errors for this line |
int |
getColumn(int pixelPos)
Return the character column for the given pixel position. |
EditorException |
getError(int index)
Return the given error for this line, or null |
Token |
getLastToken()
Return the last token before this one, or null if at the start of the line. |
int |
getLength()
Return the length of the line in characters |
Token |
getNextToken()
Return this token, and advance the pointer to the next token. |
int |
getPixelPos(int column)
Return the pixel position of the given text column. |
Token |
getToken(int index)
|
java.util.Vector |
getTokenVector()
|
java.lang.String |
getValue()
Return the line as a text string |
EditorException |
getWarning(int index)
Return the given warning for this line, or null |
int |
getWidth()
|
Line |
insert(CursorPos cursor,
char aChar,
Parser parser,
EditorPrefs prefs,
LineFactory factory)
Insert a character into the current line at a given column. |
java.util.Vector |
insert(CursorPos cursor,
java.lang.String newText,
Parser parser,
EditorPrefs prefs,
LineFactory factory)
Insert a string into the current line at a given column. |
void |
previousToken()
move to the previous token. |
void |
redo(Undoable undo,
CursorPos cursor)
|
void |
resetTokenIndex()
Reset the token iterator index |
void |
undo(Undoable undo,
CursorPos cursor)
|
int |
warningCount()
Return the number of warnings for this line |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected java.util.Vector tokens
protected int tokenIndex
Constructor Detail |
public Line()
public Line(java.util.Vector tokens)
tokens
- The vector of tokens for this lineMethod Detail |
public Token getToken(int index)
public int countTokens()
public java.util.Vector getTokenVector()
public void resetTokenIndex()
resetTokenIndex
in interface TokenIterator
public Token getNextToken()
getNextToken
in interface TokenIterator
public Token getLastToken()
getLastToken
in interface TokenIterator
public void previousToken() throws EditorException
previousToken
in interface TokenIterator
public java.lang.String getValue()
public int getLength()
public int getWidth()
public void draw(java.awt.Graphics g, int x, int y, int lineHeight, int lineWidth, int leftMargin, boolean showErrors)
g
- The graphics context to draw tox
- The x co-ordinate of the liney
- The y co-ordinate of the linelineHeight
- The height of a displayed linelineWidth
- The width of a displayed lineleftMargin
- The left margin for the lineshowErrors
- If true, indicate errors for this linepublic int getPixelPos(int column)
column
- The character position that we want the position ofpublic int getColumn(int pixelPos)
pixelPos
- The pix position that we are concerned withpublic EditorException addError(Token aToken, int errNo)
aToken
- The token that caused the error, or nullerrNo
- The message error identifierpublic void addError(EditorException editorException)
editorException
- The exception that caused the errorerrNo
- The message error identifierpublic void clearErrors()
public int errorCount()
public EditorException getError(int index)
index
- The index for the errorpublic void addWarning(Token aToken, int errNo)
aToken
- The token that caused the error, or nullerrNo
- The message error identifierpublic int warningCount()
public EditorException getWarning(int index)
index
- The index for the warningpublic void undo(Undoable undo, CursorPos cursor)
undo
in interface UndoIF
public void redo(Undoable undo, CursorPos cursor)
redo
in interface UndoIF
public java.util.Vector insert(CursorPos cursor, java.lang.String newText, Parser parser, EditorPrefs prefs, LineFactory factory)
col
- The column to insert the text atnewText
- The text to insert.parser
- The current parserprefs
- The Editor prefs objectfactory
- The LineFactory class to create additional linespublic Line insert(CursorPos cursor, char aChar, Parser parser, EditorPrefs prefs, LineFactory factory)
col
- The column to insert the text ataChar
- The character to insert.parser
- The current parserprefs
- The Editor prefs objectfactory
- The LineFactory class to create additional linespublic boolean delete(int start, int length, Line endLine, Parser parser, EditorPrefs prefs)
start
- The start columnlength
- The number of characters in the start and end lines to deleteendLine
- The last line in the deletion range, or nullparser
- The current parserprefs
- The Editor prefs object
|
miSim | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |