org.bs.mdi
Class Data

java.lang.Object
  extended byorg.bs.mdi.Data
All Implemented Interfaces:
ActionObservable, ActionObserver, ActionProcessor
Direct Known Subclasses:
RootData

public abstract class Data
extends Object
implements ActionObserver, ActionObservable, ActionProcessor

Represents a piece of information in a document. Data objects can be nested, but there is only one RootData object which is directly associated with the document.


Constructor Summary
protected Data()
          Creates a new Data object which has no parent element and no associated Document object.
protected Data(Document document)
          Creates a new Data object which has no parent element.
protected Data(Document document, Data parent)
          Creates a new Data object.
 
Method Summary
 void actionPerformed(ActionObservable observable, Action action)
          Called from the ActionObservable when an action has been performed or redone.
 void actionUndone(ActionObservable observable, Action action)
          Called from the ActionObservable when an action has been undone.
 void addChild(Data child)
          Adds a child element.
 void addObserver(ActionObserver observer)
          Registers this observer so that it will receive notification messages.
 void applyAction(Action action)
          Applies an action or perform a redo.
protected  Action coalesceAction(Action a)
          Glues similar consecutive Actions together.
 int countChildren()
          Counts all child elements.
 int countObservers()
          Counts all registered observers.
 Data getChild(int index)
          Gets the child element at the specified index.
 Document getDocument()
          Returns the document associated with this Data object.
 Data getParentData()
          Gets the parent Data object, or null if there is no parent object (i.e. this is probably a RootData object).
 boolean isObserver(ActionObserver observer)
          Determines if the given observer is currently observing this object.
 void notifyObservers(Action action, boolean undo)
          Notifies the observers about an action which has been recently performed.
 void removeChild(Data child)
          Removes a child element.
 void removeObserver(ActionObserver observer)
          Un-registers this observer so that it will not receive notifications any longer.
 void setDocument(Document document)
          Associates this Data object with the given document.
 void undoAction(Action action)
          Perform an undo.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Data

protected Data()
Creates a new Data object which has no parent element and no associated Document object.


Data

protected Data(Document document)
Creates a new Data object which has no parent element.

Parameters:
document - the Document which this Data object belongs to

Data

protected Data(Document document,
               Data parent)
Creates a new Data object. Automatically calls parent.addChild(this) if parent is not null.

Parameters:
document - the Document which this Data object belongs to
parent - the parent element of this Data object
Method Detail

getDocument

public Document getDocument()
Returns the document associated with this Data object.

Returns:
the associated document

setDocument

public void setDocument(Document document)
Associates this Data object with the given document. This means that this Data object will use the document's UndoManager.

Parameters:
document - the document

getParentData

public Data getParentData()
Gets the parent Data object, or null if there is no parent object (i.e. this is probably a RootData object).

Returns:
the parent object

addChild

public void addChild(Data child)
Adds a child element.

Parameters:
child - the child element

removeChild

public void removeChild(Data child)
Removes a child element.

Parameters:
child - the child element

countChildren

public int countChildren()
Counts all child elements.

Returns:
the number of child elements

getChild

public Data getChild(int index)
Gets the child element at the specified index.

Parameters:
index - the index
Returns:
the child element at the specified position

addObserver

public void addObserver(ActionObserver observer)
Description copied from interface: ActionObservable
Registers this observer so that it will receive notification messages.

Specified by:
addObserver in interface ActionObservable
Parameters:
observer - the observer to be registered

removeObserver

public void removeObserver(ActionObserver observer)
Description copied from interface: ActionObservable
Un-registers this observer so that it will not receive notifications any longer.

Specified by:
removeObserver in interface ActionObservable
Parameters:
observer - the observer to be un-registered

countObservers

public int countObservers()
Description copied from interface: ActionObservable
Counts all registered observers.

Specified by:
countObservers in interface ActionObservable
Returns:
the number of registered observers.

isObserver

public boolean isObserver(ActionObserver observer)
Description copied from interface: ActionObservable
Determines if the given observer is currently observing this object.

Specified by:
isObserver in interface ActionObservable
Parameters:
observer - the observer
Returns:
true if the observer is currently observing this object, false otherwise

notifyObservers

public void notifyObservers(Action action,
                            boolean undo)
Description copied from interface: ActionObservable
Notifies the observers about an action which has been recently performed. Note that the implementation may use threading to deliver the notification messages.

Specified by:
notifyObservers in interface ActionObservable
Parameters:
action - the action which has been performed
undo - true if the action has been undone, false otherwise

actionPerformed

public void actionPerformed(ActionObservable observable,
                            Action action)
Description copied from interface: ActionObserver
Called from the ActionObservable when an action has been performed or redone.

Specified by:
actionPerformed in interface ActionObserver
Parameters:
observable - the observable which this notification originated from
action - the action which has been performed

actionUndone

public void actionUndone(ActionObservable observable,
                         Action action)
Description copied from interface: ActionObserver
Called from the ActionObservable when an action has been undone.

Specified by:
actionUndone in interface ActionObserver
Parameters:
observable - the observable which this notification originated from
action - the action which has been undone

applyAction

public void applyAction(Action action)
Description copied from interface: ActionProcessor
Applies an action or perform a redo.

Specified by:
applyAction in interface ActionProcessor
Parameters:
action - the action to be applied or redone

undoAction

public void undoAction(Action action)
Description copied from interface: ActionProcessor
Perform an undo.

Specified by:
undoAction in interface ActionProcessor
Parameters:
action - the action to be undone

coalesceAction

protected Action coalesceAction(Action a)
Glues similar consecutive Actions together.

Parameters:
a - the recently occurred action
Returns:
the coalesced action to be inserted