miSim

misim.editor
Class TextFile

java.lang.Object
  |
  +--misim.util.FileDetails
        |
        +--misim.editor.TextFile
All Implemented Interfaces:
LineIterator, UndoIF

public class TextFile
extends FileDetails
implements LineIterator, UndoIF


Field Summary
static int FILE_ITERATOR
          The type of this line iterator
 
Fields inherited from class misim.util.FileDetails
output
 
Constructor Summary
TextFile(java.lang.String filename, boolean webFile)
          Constructor - create a new file
TextFile(java.lang.String filename, java.lang.String directory, boolean webFile)
           
 
Method Summary
 void addLine(int index, Line aLine)
          Add a line to the file
 LineFactory getFactory()
           
 Line getLine(int index)
          Get the line at a particular index in the file.
 int getLineIndex()
          Return the current line index being read in this file
 int getMaxWidth()
          Return the maximum pixel width of any line in this file
 Line getNextLine()
          Return the next line, and advance the index to the next line in the file.
 Parser getParser()
           
 java.lang.String getText()
          Return the contents of the text file as a string.
 int getType()
          Return the type of this iterator, as an integer.
 void insertLine(Line aLine)
          Insert a new line at the current line index.
 int lines()
          Return the number of lines in this file
 int readFile(EditorPrefs prefs)
           
 void redo(Undoable undo, CursorPos cursor)
          Redo a change made to the file
 void removeAllLines()
          Remove all lines from the file
 void removeLine(int index)
          Remove a line from the file
 void resetLineIndex()
          Reset the current line index to the beginning of the file
 void saveFile()
           
 int search(java.lang.String text, CursorPos cursor, boolean ignoreCase, boolean forward)
          Search for the given text from the cursor position.
 void setFactory(LineFactory factory)
           
 void setMaxWidth(int newMax)
          Test the new maximum display width of the file, and if it is larger than the existing maximum, set the maximum width to the new value
 void setParser(Parser parser)
           
 void undo(Undoable undo, CursorPos cursor)
          Undo a change made to the file
 boolean updatedOnDisk()
          Check to see if the file has been updated on disk since the last time it was read.
 
Methods inherited from class misim.util.FileDetails
getDirectory, getFilename, getInputStream, getLastModified, getOutputStream, isNewFile, isWebFile, setDirectory, setFilename
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FILE_ITERATOR

public static final int FILE_ITERATOR
The type of this line iterator
Constructor Detail

TextFile

public TextFile(java.lang.String filename,
                boolean webFile)
Constructor - create a new file
Parameters:
filename - The name for this file.
webFile - If true, this file is being managed by an applet

TextFile

public TextFile(java.lang.String filename,
                java.lang.String directory,
                boolean webFile)
Method Detail

setParser

public void setParser(Parser parser)

getParser

public Parser getParser()

setFactory

public void setFactory(LineFactory factory)

getFactory

public LineFactory getFactory()

readFile

public int readFile(EditorPrefs prefs)
             throws java.io.IOException

getMaxWidth

public int getMaxWidth()
Return the maximum pixel width of any line in this file
Returns:
The maximum display width of this file

setMaxWidth

public void setMaxWidth(int newMax)
Test the new maximum display width of the file, and if it is larger than the existing maximum, set the maximum width to the new value
Parameters:
newMax - The new display width for the file

updatedOnDisk

public boolean updatedOnDisk()
Check to see if the file has been updated on disk since the last time it was read.
Returns:
True if the file has been updated on disk since it was last read

saveFile

public void saveFile()
              throws java.io.IOException

getText

public java.lang.String getText()
Return the contents of the text file as a string. Note this method is a short term solution, as String storage is not suited to handling large files.
Returns:
A String representing the contents of the panel

lines

public int lines()
Return the number of lines in this file
Returns:
The number of lines in this file

resetLineIndex

public void resetLineIndex()
Reset the current line index to the beginning of the file
Specified by:
resetLineIndex in interface LineIterator

getNextLine

public Line getNextLine()
Return the next line, and advance the index to the next line in the file.
Specified by:
getNextLine in interface LineIterator
Returns:
The next line in the file, or null if there are no more

getLineIndex

public int getLineIndex()
Return the current line index being read in this file
Specified by:
getLineIndex in interface LineIterator
Returns:
The current line index

insertLine

public void insertLine(Line aLine)
Insert a new line at the current line index. Note that the next call to getNextLine will return the line after the line just inserted.
Specified by:
insertLine in interface LineIterator
Parameters:
aLine - The line to insert

getType

public int getType()
Return the type of this iterator, as an integer.
Specified by:
getType in interface LineIterator
Returns:
This iterator type

search

public int search(java.lang.String text,
                  CursorPos cursor,
                  boolean ignoreCase,
                  boolean forward)
Search for the given text from the cursor position. If the text is found, the method returns the index of the start of the text and depending on the direction of the search and the cursor position is updated to immediately before or after the text searched for. Otherwise the search returns -1.
Parameters:
text - The string to search for
cursor - The cursor position to search from
ignoreCase - If true, search ingnoring case
forward - If true seek forward through the file.
Returns:
The index of the start of the found text, or -1

getLine

public Line getLine(int index)
Get the line at a particular index in the file. Note that this only looks at the 'top level' of the file. If lines contain other lines (for instance an included file) then those are ignored.
Parameters:
index - The line number to return
Returns:
The specified line, or null if it doesn't exist

removeLine

public void removeLine(int index)
Remove a line from the file
Parameters:
index - The line number to remove

removeAllLines

public void removeAllLines()
Remove all lines from the file

addLine

public void addLine(int index,
                    Line aLine)
Add a line to the file
Parameters:
index - The line number to add
line - The line to add

undo

public void undo(Undoable undo,
                 CursorPos cursor)
Undo a change made to the file
Specified by:
undo in interface UndoIF

redo

public void redo(Undoable undo,
                 CursorPos cursor)
Redo a change made to the file
Specified by:
redo in interface UndoIF

miSim