org.bs.mdi
Class Document

java.lang.Object
  extended byorg.bs.mdi.Document

public class Document
extends Object

The Document class manages data and views. A document consists of two major components: its data and one or more views, which are represented by the RootData and RootView classes. The combination of data and views is called a Document.


Constructor Summary
protected Document(Application app)
           
 
Method Summary
 void addView(RootView view)
          Associates the specified view with this document.
 boolean close()
          Tries to close this document.
 int countViews()
          Returns the number of views associated with this document.
static Document createNew()
          Creates a new document.
 String getBaseFilename()
          Returns the basename of the document's filename.
 RootData getData()
          Returns the data associated with this document.
 String getFilename()
          Returns the document's filename.
 Printer getPrinter()
          Convenience method for getting the RootData's printer.
 UndoManager getUndoManager()
          Gets the UndoManager of this Document.
 RootView getView(int index)
          Gets the specified view.
 Iterator getViewIterator()
          Gets an iterator for all views associated with this document.
 RootView[] getViews()
          Gets an array containing all root views.
 boolean isDirty()
          Returns if this document is "dirty", i.e. contains unsaved data.
 boolean isFileExistent()
          Returns true if the document's filename already exists.
 boolean isOpened()
          Tells if this document is still opened.
 boolean isRedoPossible()
          Convenience function for calling getUndoManager().isRedoPossible();
 boolean isUndoPossible()
          Convenience function for calling getUndoManager().isUndoPossible();
static Document open(String filename)
          Opens an existing document.
 Action redo()
          Convenience function for calling getUndoManager().redo();
 void removeView(RootView view)
          Removes the specified view from this document.
 void save(String filename)
          Saves this document to a file.
 void setDirty(boolean dirty)
          Set's the "dirty" status of a document.
protected  void setFilename(String filename)
          Sets the filename and the baseFilename.
 void syncViewsWithData()
          Synchronize all root views with the data.
 Action undo()
          Convenience function for calling getUndoManager().undo();
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Document

protected Document(Application app)
Method Detail

isDirty

public boolean isDirty()
Returns if this document is "dirty", i.e. contains unsaved data.

Returns:
true if this document is "dirty"

isFileExistent

public boolean isFileExistent()
Returns true if the document's filename already exists.

Returns:
true if the document's filename already exists

getFilename

public String getFilename()
Returns the document's filename.

Note that every document has a filename, even if the document has not yet been saved. The filename of a newly created document could be "Untitled-1", for example.

Returns:
the document's filename.

getBaseFilename

public String getBaseFilename()
Returns the basename of the document's filename. This is just the last part of the path string. For example, the basename of "/bin/bash" would be just "bash".

Returns:
the basename of the filename

getData

public RootData getData()
Returns the data associated with this document.

Returns:
the data

getView

public RootView getView(int index)
Gets the specified view.

Parameters:
index - the index of the view
Returns:
the view

getViews

public RootView[] getViews()
Gets an array containing all root views.

Returns:
all RootView's

getViewIterator

public Iterator getViewIterator()
Gets an iterator for all views associated with this document.

Returns:
an iterator

countViews

public int countViews()
Returns the number of views associated with this document.

Returns:
the number of views

addView

public void addView(RootView view)
Associates the specified view with this document.

Parameters:
view - the view to be associated with this document

removeView

public void removeView(RootView view)
Removes the specified view from this document.

Parameters:
view - the view to be removed

syncViewsWithData

public void syncViewsWithData()
Synchronize all root views with the data. Calls View.syncWithData() for every associated root view.


getUndoManager

public UndoManager getUndoManager()
Gets the UndoManager of this Document.

Returns:
the UndoManager

getPrinter

public Printer getPrinter()
Convenience method for getting the RootData's printer. Equivalent for calling getData().getPrinter().

Returns:
the document's printer, or null if doesn't support printing

setDirty

public void setDirty(boolean dirty)
Set's the "dirty" status of a document.

A document is dirty if it contains unsaved modifications.

Parameters:
dirty - true if the document should be considered dirty, false otherwise

createNew

public static Document createNew()
Creates a new document.

Returns:
the new document

open

public static Document open(String filename)
                     throws FileIOException
Opens an existing document.

Parameters:
filename - the document's filename
Returns:
the opened Document
Throws:
FileIOException

save

public void save(String filename)
          throws FileIOException
Saves this document to a file.

Parameters:
filename - the filename to be used
Throws:
FileIOException

isOpened

public boolean isOpened()
Tells if this document is still opened.

Returns:
true if the document has not yet been closed, false otherwise

close

public boolean close()
Tries to close this document. Note that this operation does not necessarily have to succeed. If the document contains unsaved modifications and the user decides to close it, he may be asked to confirm this operation. He has the option of not letting the close() method succeed.

Returns:
true if closing the document succeeded, false otherwise

undo

public Action undo()
Convenience function for calling getUndoManager().undo();

Returns:
the undone Action or null in case of error

redo

public Action redo()
Convenience function for calling getUndoManager().redo();

Returns:
the redone Action or null in case or error

isUndoPossible

public boolean isUndoPossible()
Convenience function for calling getUndoManager().isUndoPossible();

Returns:
true if an action can be undone, false otherwise

isRedoPossible

public boolean isRedoPossible()
Convenience function for calling getUndoManager().isRedoPossible();

Returns:
true if an action can be redone, false otherwise

setFilename

protected void setFilename(String filename)
Sets the filename and the baseFilename.

Parameters:
filename - the new filename