turingmachine
Class CTMDocument

java.lang.Object
  extended by turingmachine.CTMDocument
All Implemented Interfaces:
java.io.Serializable

class CTMDocument
extends java.lang.Object
implements java.io.Serializable

A turing machine document.


Field Summary
private  CTMApplication mApplication
          The application this document belongs to.
private  java.util.ArrayList<CTMData> mComponents
          List of states in document.
private  java.lang.String mDirections
          Turing machine directions.
private  java.lang.String mFileName
          Filename this document was loaded from.
private  boolean mIsDeterministic
          Whether or not this machine is deterministic.
private  boolean mModified
          Document modification state.
private  java.awt.Dimension mSize
          Size of document.
private  int mStateCount
          Number of states created.
private  java.lang.String mStatePrefix
          Default prefix for new states.
private  java.lang.String mSymbols
          Turing machine symbols.
private  java.lang.String mTitle
          Document title.
private  java.util.ArrayList<CTMInternalFrameView> mViews
          List of views for this document.
private  CTMPreferences preferences
          Prefereneces for document.
(package private) static long serialVersionUID
          Serial id, so future version will load old files.
 
Constructor Summary
CTMDocument(CTMApplication application)
          Constructor.
 
Method Summary
 boolean close()
          Close this document and all its views.
 void commentAdd(java.awt.Rectangle bounds)
          Add a comment to the document and update views.
 java.util.Iterator<CTMData> componentIterator()
          Method for getting the components iterator as mComponents is private.
 void componentToBack(CTMData component)
          Send a component to the back.
 void componentToFront(CTMData component)
          Bring a component to the front.
 CTMApplication getApplication()
          Get the application for this document.
 java.lang.String getDirections()
          Gets turing machine tape direction symbols.
 java.lang.String getFilename()
          Getter for documents filename.
 CTMPreferences getPreferences()
          Gets document preferences.
 java.awt.Dimension getSize()
          Get the size of the document.
 java.lang.String getSymbols()
          Gets the symbols for the turing machine.
 java.lang.String getTitle()
          Gets the document title.
private  void initTransients()
          Initialises transient variables not initialised on load.
 boolean isIsDeterministic()
          Get whether or not this machine is determininistic.
 boolean isModified()
          Get whether or not this document has been modified.
static CTMDocument load(CTMApplication application)
          Load a document.
 boolean save()
          provide a save dialog and save the document.
 boolean saveAs()
          Save this document under a different name.
 boolean saveQuestion()
          Ask whether the use wants to save the document.
 void setDirections(java.lang.String aDirections)
          Sets turing machine tape direction symbols.
 void setIsDeterministic(boolean isDeterministic)
          Set whether or not this machine is determininistic.
 void setModified(boolean aModified)
          Set the status of the documents modified flag.
 void setSize(java.awt.Dimension aSize)
          Sets the size of the document view.
 void setSymbols(java.lang.String aSymbols)
          Sets the symbols for the turing machine.
 void setTitle(java.lang.String aTitle)
          Sets the document title.
 void stateAdd(java.awt.Point aPoint)
          Add a state to the document and update views.
 boolean validate()
          Check document is a valid program.
 boolean viewClose(CTMInternalFrameView aView)
          Close a view of this document.
 CTMInternalFrameView viewCreate()
          Create a new view of this document.
 void viewUpdateAll()
          Sync all views to the document.
 void viewUpdateTitles()
          Updates all view titles to reflect current document status.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serialVersionUID

static final long serialVersionUID
Serial id, so future version will load old files.

See Also:
Constant Field Values

mApplication

private transient CTMApplication mApplication
The application this document belongs to.


mViews

private transient java.util.ArrayList<CTMInternalFrameView> mViews
List of views for this document.


mModified

private transient boolean mModified
Document modification state.


mIsDeterministic

private boolean mIsDeterministic
Whether or not this machine is deterministic.


mFileName

private transient java.lang.String mFileName
Filename this document was loaded from.


mStateCount

private int mStateCount
Number of states created.


mTitle

private java.lang.String mTitle
Document title.


mSymbols

private java.lang.String mSymbols
Turing machine symbols.


mDirections

private java.lang.String mDirections
Turing machine directions.


mStatePrefix

private java.lang.String mStatePrefix
Default prefix for new states.


mComponents

private java.util.ArrayList<CTMData> mComponents
List of states in document.


mSize

private java.awt.Dimension mSize
Size of document.


preferences

private CTMPreferences preferences
Prefereneces for document.

Constructor Detail

CTMDocument

public CTMDocument(CTMApplication application)
Constructor.

Parameters:
application - The application that created this document.
Method Detail

initTransients

private void initTransients()
Initialises transient variables not initialised on load.


getTitle

public java.lang.String getTitle()
Gets the document title.

Returns:
The documents title.

getFilename

public java.lang.String getFilename()
Getter for documents filename.

Returns:
String Documents filename.

setTitle

public void setTitle(java.lang.String aTitle)
Sets the document title.

Parameters:
aTitle - The new document title.

viewUpdateTitles

public void viewUpdateTitles()
Updates all view titles to reflect current document status.


getSymbols

public java.lang.String getSymbols()
Gets the symbols for the turing machine.

Returns:
Symbols that machine may use.

setSymbols

public void setSymbols(java.lang.String aSymbols)
Sets the symbols for the turing machine.

Parameters:
aSymbols - The allowed symbols.

getDirections

public java.lang.String getDirections()
Gets turing machine tape direction symbols.

Returns:
Turing machine tape direction symbols.

setDirections

public void setDirections(java.lang.String aDirections)
Sets turing machine tape direction symbols.

Parameters:
aDirections - The valid directions for this machine.

viewCreate

public CTMInternalFrameView viewCreate()
Create a new view of this document.

Returns:
The new view internal frame.

close

public boolean close()
Close this document and all its views.

Returns:
True if document closed, else false.

viewClose

public boolean viewClose(CTMInternalFrameView aView)
Close a view of this document.

Parameters:
aView - The view to close.
Returns:
True if view closed successfully else false.

saveQuestion

public boolean saveQuestion()
Ask whether the use wants to save the document.

Returns:
True if it is OK to close the document else false.

load

public static CTMDocument load(CTMApplication application)
Load a document.

Parameters:
application - Which application does the open dialog belong to.
Returns:
The loaded document.

saveAs

public boolean saveAs()
Save this document under a different name.

Returns:
True if save succeeded else false.

save

public boolean save()
provide a save dialog and save the document.

Returns:
True if save succeeded else false.

componentIterator

public java.util.Iterator<CTMData> componentIterator()
Method for getting the components iterator as mComponents is private.

Returns:
An Iterator for the states in the document.

stateAdd

public void stateAdd(java.awt.Point aPoint)
Add a state to the document and update views.

Parameters:
aPoint - Where to put the state.

commentAdd

public void commentAdd(java.awt.Rectangle bounds)
Add a comment to the document and update views.

Parameters:
bounds - Where to put the comment.

viewUpdateAll

public void viewUpdateAll()
Sync all views to the document.


componentToFront

public void componentToFront(CTMData component)
Bring a component to the front.

Parameters:
component - The component to reorder.

componentToBack

public void componentToBack(CTMData component)
Send a component to the back.

Parameters:
component - The component to reorder.

getSize

public java.awt.Dimension getSize()
Get the size of the document.

Returns:
The size of the document.

setSize

public void setSize(java.awt.Dimension aSize)
Sets the size of the document view.

Parameters:
aSize - The size to set it to.

validate

public boolean validate()
Check document is a valid program.

Returns:
boolean true document is fine, else false.

setModified

public void setModified(boolean aModified)
Set the status of the documents modified flag.

Parameters:
aModified - Modification state to set.

isModified

public boolean isModified()
Get whether or not this document has been modified.

Returns:
true - it has been modified, else false.

getApplication

public CTMApplication getApplication()
Get the application for this document.

Returns:
This documents application.

setIsDeterministic

public void setIsDeterministic(boolean isDeterministic)
Set whether or not this machine is determininistic.

Parameters:
isDeterministic - boolean true if it is deterministic, else false.

isIsDeterministic

public boolean isIsDeterministic()
Get whether or not this machine is determininistic.

Returns:
boolean true if it is deterministic, else false.

getPreferences

public CTMPreferences getPreferences()
Gets document preferences.

Returns:
CTMPreferences