CS 4773 Object Oriented Systems Editor Specification (updated 2/21 5 PM)
The Editor class:
- public static void main(String[] args)
Command line contains a list of files to edit.
A new editing session is opened for each.
If one of the command line parameters is "-i" it creates an
EditorInspector and displays a JFrame containing buttons
to display the EditorInspector, and create and remove
EditingSessions.
- public static String getVersionMessage()
- public static String getUpdateMessage()
- public static String getTeamMessage()
- public static EditorFile getEditorFile(String filename)
Return the EditorFile corresponding to this filename,
creating a new one if necessary.
- public static void removeSession(int id)
Remove the session with the given id if one exists.
- public static boolean removeEditorFile(EditorFile ef)
If ef exists and has no sessions, remove it and return true.
Otherwise return false.
- public static String getDescriptor()
Returns a short String describing the collection of EditorFiles.
- public static String getLongDescriptor()
Returns a long multi-line String describing the
EditorFiles and their sessions.
It appends the string returned by getDescriptor() for each
EditorFile.
- public static String[] getUniqueNames()
Returns an array of the uniquenames of the EditorFiles.
- public static boolean inspectEditorFile(String fn)
Calls the inspect method of the corresponding EditorFile
if one exists and returns true.
Otherwise it returns false.
- public static EditingSession getSession(int id)
Return the session with the given id or null if none.
SessionCreator: Used only for testing Editor
- Constructor: public SessionCreator(JFrame parent)
- Creates three buttons each of which causes a JOptionPane to be displayed.
- public JButton getCreateSessionButton()
Returns a button that prompts for a string filename and calls
Editor.openEditingSession(filename)
- public JButton getRemoveSessionButton()
Returns a button that prompts for an integer sessionId,
and calls
Editor.removeSession(sessionId)
- public JButton getExecuteCommandButton()
Returns a button that prompts for a session number and then an editor
command to execute.
EditorInspector
- Constructor: public EditorInspector(Component com)
Creates a JButton.
- public JButton getInspectButton()
Returns a button that displays a frame containing information about
the EditorFiles and EditingSessions.
If com is not null it is displayed next to the com.
The frame contains at least two buttons: Update and
Inspect Editor File.
- Update updates the info displayed.
- Inspect EditorFile displays a frame which gives the user a choice
of EditoFiles to display information about.
EditorFile
- The constructor is private.
- public static EditorFile createEditorFile(String name)
Attempts to create a new EditorFile from name which is
the unique String representing the file.
- public String getUniqueName()
Returns the unique name corresponding to this file.
- public int getId()
Returns a unique ID corresponding to this EditorFile.
This is one greater than the ID of the last one created.
The first one created has ID 0.
- public void addSession(EditingSession es)
Adds this session to the sessions for this EditorFile.
- public boolean removeSession(EditingSession session)
Returns true if successful, and false otherwise.
If there are no more sessions in this EditorFile, call
Editor.removeEditorFile(this)
- public boolean removeSession(int id)
Tries to remove the session with the given id.
If one exists in this EditorFile,
it behaves as above, otherwise it returns false.
- public int getSessionCount()
Returns the number of sessions.
- public int getNumItems()
Returns the number of items in this file.
- public String getDescriptor()
Returns a String with information about this EditorFile and its sessions.
- public void inspect()
Creates an inspector for this file.
- public EditingSession getSession(int id)
Returns the editing session with the given id or null if none.
EditingSession
- Constructor is private.
- public static EditingSession openEditingSession(String localName)
Creates an EditingSession corresponding to the given filename.
Uses Editor.getEditorFile(localName).
- public void close()
Remove this editing session by calling removeSession in the
corresponding EditorFile.
- public int getCursorPosition()
- public int getCursorLine()
- public int getNumberLines()
- public int getId()
Each EditingSession has a unique ID, starting at 0 and incremented by
one each time one is created.
- public void setCursorPosition(int pos)
Set the cursor postion. Do not let it go past the end of the line.
- public void setCursorLine(int line)
Set the curosr line. Do not let it go past the end of the file.
- public String getLongDescriptor(int n)
Returns a multi-line String describing this session.
Each line is indented b spaces.
RawCommand
- Constructor: public RawCommand(int id, CommandExecuter exe)
- Constructor: public RawCommand(int id, CommandExecuter exe, CommandArguments args)
- public void setArgs(CommandArguments args)
- public boolean execute()
CommandArguments
- See the sample code.
- Needs many more constructors than shown.
Commands
- Constructor sets the EditingSession and creates a number of
CommandExecuters.
- The example code just shows CommandExecuterCursor.
- There will also be sets of commands for IO, search/replace,
keystrokes, etc.
CommandExecuter
- An abstract class with one abstract method.
CommandExecuterCursor
- This is given to illustrate how to execute some commands.
CommandDecoder
- This illustrates how String command can be decoded.
- It does not hangle the arguments correctly.
- It should probably use a StringTokenizer.
- It should also probably ignore case in the comparisons.