jcreek.cke
Class CreekDocumentGroup

java.lang.Object
  extended byjcreek.cke.CreekDocumentGroup

public class CreekDocumentGroup
extends java.lang.Object

This class manages all of the CreekDocument objects in the program. Use this class when you want to perform operations on a document, rather than calling the document directly. For the less common operations, the user can easily get at the current document and communicate with it.

This is a singleton class, which means there's only one instance of this class in the system. To get a reference to that single instance, use the instanceOf() method.

Version:
Author:

Field Summary
protected  int curDocument
          Index into documents to the current document.
protected  java.lang.String defaultExtensionDoc
          Default filename extension for new documents.
protected  java.lang.String defaultExtensionKM
          Default filename extension for new documents.
protected  java.util.Hashtable docTypes
          Table of the supported document types, keyed by the filename extension.
protected  java.util.Vector documents
          List of documents held under this document group.
protected static CreekDocumentGroup instance
          Reference to the single instance of this class.
protected  KnowledgeModel km
          Reference to the Knowledge Model
protected  boolean kmEditable
           
protected  java.util.Hashtable kmTypes
          Table of the supported document types, keyed by the filename extension.
protected  java.awt.print.PageFormat pf
          Default page format for Printing the Documents
protected  java.beans.PropertyChangeSupport propSupport
          Makes supporting property change listeners trivial.
protected  UndoHandler undoHandler
          Undo handler that handles everything to do with undo.
protected  java.util.Hashtable viewDocs
          Table of the documents, keyed by the associated views.
 
Constructor Summary
protected CreekDocumentGroup()
          No-arg constructor for our class.
 
Method Summary
protected  void addDocument(CreekDocument doc)
          Add the given Creek document object to group and set it as the current document.
 void addPropertyChangeListener(java.beans.PropertyChangeListener l)
          Add a property change listener to this document group.
 void addPropertyChangeListener(java.lang.String name, java.beans.PropertyChangeListener l)
          Add a property change listener to this document group.
 boolean closeDocument()
          Closes the current document.
 boolean closeModel()
           
 boolean deleteContext(CreekDocument selDoc)
           
protected  void fireDirtyChange(CreekDocument doc)
          Let all the property change listeners know that the current document has become dirty or become clean.
protected  void fireDocAdded(CreekDocument oldDoc)
           
protected  void fireDocChange(CreekDocument oldDoc, CreekDocument newDoc)
          Let all the property change listeners know that the current document has been switched with another document, making that other document the new current document.
protected  void fireDocRemoved(CreekDocument oldDoc)
          Let all the property change listeners know that the current document has been switched with another document, making that other document the new current document.
protected  void fireKMEditChange(boolean newEdit)
          Let all the property change listeners know that the knowledge model editable status has changed.
protected  void fireModelClosed(KnowledgeModel oldKM)
          Let all the property change listeners know that the current knowledge model has been closed
protected  void fireModelOpened(KnowledgeModel newKM)
          Let all the property change listeners know that the current knowledge model has been opened
protected  void fireSelectionChange(CreekDocument oldDoc)
          Let all the property change listeners know that the current knowledge model has been opened
 Context[] getContexts()
           
 CreekDocument getCurrentDocument()
          Returns the reference to the current document in the group.
protected  java.awt.print.PageFormat getDefaultPageFormat()
           
 CreekDocument getDocument(ConceptView view)
          Retrieve the document object associated with the given view.
 CreekDocument getDocument(int index)
          Returns the reference to the requested document in the group.
 CreekDocument[] getDocuments()
          Returns an array of the current documents in the group.
 java.util.Hashtable getDocumentTypes()
          Retrieve a list of all the registered document types.
 KnowledgeModel getKM()
          Retrieve the KnowledgeModel.
 java.util.Hashtable getKMTypes()
           
 boolean getKnowledgeModelEditable()
           
 java.awt.print.PageFormat getPageFormat()
           
static CreekDocumentGroup instanceOf()
          Returns the reference to the single instance of this class.
 boolean isActive(CreekDocument doc)
           
 boolean isDirty()
           
 void markDocumentDirty(CreekDocument doc)
          Sends out notification to any listeners if this document is the current document.
 void markSelection(CreekDocument doc)
          Sends out notification to any listeners if this document is the current document.
 boolean newDocument(ConceptView view)
          Creates a new document object, as well as the needed UI and adds it to the group.
 void newKM(KnowledgeModel km)
           
 boolean openDocument(ConceptView view, CreekDocument doc)
          Add the given Document as a Creek document, creating the needed UI and the document object.
 void openKM(java.io.File f)
           
 void openTestKM()
          Opens a Test KnowledgeModel as Creek document, creating the needed UI and the document object.
 void registerDocument(java.lang.String ext, java.lang.Class doc)
          Registers a filename extension with a given document class.
 void registerkm(java.lang.String ext, java.lang.Class doc)
          Registers a filename extension with a given document class.
protected  void removeDocument(CreekDocument doc)
          Remove the Creek document from the document group.
 void removePropertyChangeListener(java.beans.PropertyChangeListener l)
          Remove a property change listener from this document group.
 void removePropertyChangeListener(java.lang.String name, java.beans.PropertyChangeListener l)
          Remove a property change listener from this document group.
 boolean revertDocument()
          Reverts the current document from disk.
 void saveAsKM(java.lang.String file, java.lang.String dir)
          Saves the KnowledgeModel under a new name and possibly a new file format.
 void saveKM()
          Saves the current KnowledgeModel to disk.
 void setCurrentDocument(CreekDocument newDoc)
          Sets the given document to be the current one.
 void setKM(KnowledgeModel km)
           
 void setKnowledgeModelEditable(boolean editable)
           
 void setPageFormat(java.awt.print.PageFormat pf)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

km

protected KnowledgeModel km
Reference to the Knowledge Model


instance

protected static CreekDocumentGroup instance
Reference to the single instance of this class.


curDocument

protected int curDocument
Index into documents to the current document.


documents

protected java.util.Vector documents
List of documents held under this document group.


viewDocs

protected java.util.Hashtable viewDocs
Table of the documents, keyed by the associated views. Used by MainWindow and others to find the document associated with a given view object.


docTypes

protected java.util.Hashtable docTypes
Table of the supported document types, keyed by the filename extension.


kmTypes

protected java.util.Hashtable kmTypes
Table of the supported document types, keyed by the filename extension.


undoHandler

protected UndoHandler undoHandler
Undo handler that handles everything to do with undo. As documents are created and opened, it will be added as an undoable edit listener.


propSupport

protected java.beans.PropertyChangeSupport propSupport
Makes supporting property change listeners trivial. When the current document becomes dirty these listeners are notified via the PropertyChangeEvent. The listeners must implement the PropertyChangeListener interface.


defaultExtensionDoc

protected java.lang.String defaultExtensionDoc
Default filename extension for new documents. This is used to map to the matching document class in docTypes.


defaultExtensionKM

protected java.lang.String defaultExtensionKM
Default filename extension for new documents. This is used to map to the matching document class in docTypes.


pf

protected java.awt.print.PageFormat pf
Default page format for Printing the Documents


kmEditable

protected boolean kmEditable
Constructor Detail

CreekDocumentGroup

protected CreekDocumentGroup()
No-arg constructor for our class. This is protected so we can control the number of instances of this class. If you wish to get a reference to the single instance of this class, use the instanceOf() method.

Method Detail

addDocument

protected void addDocument(CreekDocument doc)
Add the given Creek document object to group and set it as the current document. Also registers this document group as an undoable edit listener, to make sure that undoable edits are registered with the undo manager.

Parameters:
doc - document to add to group

addPropertyChangeListener

public void addPropertyChangeListener(java.beans.PropertyChangeListener l)
Add a property change listener to this document group.

Parameters:
l - new listener to add notification list

addPropertyChangeListener

public void addPropertyChangeListener(java.lang.String name,
                                      java.beans.PropertyChangeListener l)
Add a property change listener to this document group.

Parameters:
name - name of property to listen to specifically
l - new listener to add notification list

closeDocument

public boolean closeDocument()
Closes the current document. This leaves the group without a current document until the user selects one via the internal windows. This does not save the document.

Returns:
true if successful, false if no current document

deleteContext

public boolean deleteContext(CreekDocument selDoc)

closeModel

public boolean closeModel()

fireDirtyChange

protected void fireDirtyChange(CreekDocument doc)
Let all the property change listeners know that the current document has become dirty or become clean.

Parameters:
doc - document that has changed

fireKMEditChange

protected void fireKMEditChange(boolean newEdit)
Let all the property change listeners know that the knowledge model editable status has changed.


fireDocChange

protected void fireDocChange(CreekDocument oldDoc,
                             CreekDocument newDoc)
Let all the property change listeners know that the current document has been switched with another document, making that other document the new current document.

Parameters:
oldDoc - previous current document
newDoc - new current document

fireDocRemoved

protected void fireDocRemoved(CreekDocument oldDoc)
Let all the property change listeners know that the current document has been switched with another document, making that other document the new current document.

Parameters:
oldDoc - previous current document

fireDocAdded

protected void fireDocAdded(CreekDocument oldDoc)

fireModelOpened

protected void fireModelOpened(KnowledgeModel newKM)
Let all the property change listeners know that the current knowledge model has been opened

Parameters:
newKM - new KnowledgeModel

fireModelClosed

protected void fireModelClosed(KnowledgeModel oldKM)
Let all the property change listeners know that the current knowledge model has been closed

Parameters:
oldKM - old KnowledgeModel

fireSelectionChange

protected void fireSelectionChange(CreekDocument oldDoc)
Let all the property change listeners know that the current knowledge model has been opened

Parameters:
oldDoc - previous current document

getCurrentDocument

public CreekDocument getCurrentDocument()
Returns the reference to the current document in the group. If there is no current document, null is returned.

Returns:
reference to current document, or null

getDocument

public CreekDocument getDocument(int index)
Returns the reference to the requested document in the group. If there is no such document, null is returned.

Parameters:
index - index of the document to be retrieved
Returns:
reference to current document, or null

getDocument

public CreekDocument getDocument(ConceptView view)
Retrieve the document object associated with the given view.

Parameters:
view - view showing the requested document

getDocuments

public CreekDocument[] getDocuments()
Returns an array of the current documents in the group. If there are no documents, null is returned.

Returns:
array of Creek documents, or null

getContexts

public Context[] getContexts()

getKM

public KnowledgeModel getKM()
Retrieve the KnowledgeModel.


getDocumentTypes

public java.util.Hashtable getDocumentTypes()
Retrieve a list of all the registered document types. Returns the list in the form of a hashtable for the convenience of looking up the types by extension. Each key of the hastable is a filename extension, while the value is the document class that supports files with that extension.

Returns:
hashtable of registered document types

getKMTypes

public java.util.Hashtable getKMTypes()

instanceOf

public static CreekDocumentGroup instanceOf()
Returns the reference to the single instance of this class.

Returns:
reference to this singleton

markDocumentDirty

public void markDocumentDirty(CreekDocument doc)
Sends out notification to any listeners if this document is the current document. This is used by the documents to let the document group (and its listeners) know that it is dirty. It is _not_ meant to mark the document dirty.


markSelection

public void markSelection(CreekDocument doc)
Sends out notification to any listeners if this document is the current document. This is used by the documents to let the document group (and its listeners) know that a slection change has taken place.


newDocument

public boolean newDocument(ConceptView view)
Creates a new document object, as well as the needed UI and adds it to the group. This document will become the current document. The name of the document will be of the form "Untitled #" where # is a number from 1 to 32767.

Parameters:
view - view to associate with this document
Returns:
true if successful, false otherwise

newKM

public void newKM(KnowledgeModel km)

openDocument

public boolean openDocument(ConceptView view,
                            CreekDocument doc)
Add the given Document as a Creek document, creating the needed UI and the document object. The new document will be added to the group and will become the current document.

Parameters:
view - view to associate with this document
doc - document to be opened as a Creek document
Returns:
true if successful, false if unknown file format, or corrupt file structure

setKM

public void setKM(KnowledgeModel km)

isActive

public boolean isActive(CreekDocument doc)

openTestKM

public void openTestKM()
Opens a Test KnowledgeModel as Creek document, creating the needed UI and the document object. The new document will be added to the group and will become the current document.


openKM

public void openKM(java.io.File f)
            throws java.io.IOException,
                   java.lang.ClassNotFoundException
Throws:
java.io.IOException
java.lang.ClassNotFoundException

registerDocument

public void registerDocument(java.lang.String ext,
                             java.lang.Class doc)
Registers a filename extension with a given document class. This tells the document group to use that class when opening files with the given extension.

The first document type registered will be treated as the default type, used when creating new documents.

Parameters:
ext - filename extension
doc - document class

registerkm

public void registerkm(java.lang.String ext,
                       java.lang.Class doc)
Registers a filename extension with a given document class. This tells the document group to use that class when opening files with the given extension.

The first document type registered will be treated as the default type, used when creating new documents.

Parameters:
ext - filename extension
doc - document class

removeDocument

protected void removeDocument(CreekDocument doc)
Remove the Creek document from the document group. Updates the current document index data member to -1 so there is no current document.

Parameters:
doc - document to be removed

removePropertyChangeListener

public void removePropertyChangeListener(java.beans.PropertyChangeListener l)
Remove a property change listener from this document group.

Parameters:
l - listener to remove from notification list

removePropertyChangeListener

public void removePropertyChangeListener(java.lang.String name,
                                         java.beans.PropertyChangeListener l)
Remove a property change listener from this document group.

Parameters:
name - property name to listen for specifically
l - listener to remove from notification list

revertDocument

public boolean revertDocument()
Reverts the current document from disk. If there is no current document then this returns false.

Returns:
return value from CreekDocument.revert()

saveAsKM

public void saveAsKM(java.lang.String file,
                     java.lang.String dir)
              throws java.io.IOException
Saves the KnowledgeModel under a new name and possibly a new file format. The file format is determined by the file extension. If the new file extension is not recognized, we'll just write out in the current format to the given filename.

Parameters:
file - file name
dir - directory path
Returns:
true if successful, false if error
Throws:
java.io.IOException

saveKM

public void saveKM()
            throws java.io.IOException
Saves the current KnowledgeModel to disk.

Returns:
return value from KnowledgeModel.save()
Throws:
java.io.IOException

setCurrentDocument

public void setCurrentDocument(CreekDocument newDoc)
Sets the given document to be the current one. Sends out notification to any listeners that current document has been switched.

Parameters:
newDoc - document to make current

isDirty

public boolean isDirty()

getDefaultPageFormat

protected java.awt.print.PageFormat getDefaultPageFormat()

getPageFormat

public java.awt.print.PageFormat getPageFormat()

setPageFormat

public void setPageFormat(java.awt.print.PageFormat pf)

setKnowledgeModelEditable

public void setKnowledgeModelEditable(boolean editable)

getKnowledgeModelEditable

public boolean getKnowledgeModelEditable()


Created at IDI, NTNU by the Artificial Intelligence and Learning group