jET
1.0alpha5


org.jet.sce
Class Scenery

java.lang.Object
  |
  +--org.jet.sce.Scenery
All Implemented Interfaces:
java.io.Serializable

public class Scenery
extends java.lang.Object
implements java.io.Serializable

The scenery is the class where data for editor is stored. It has two lists containing tracks and switches. In addition scenery may have custom properties, and description.

Be caution about securing read access to scenery. See readLock() and readUnlock() methods.

See Also:
Serialized Form

Nested Class Summary
 class Scenery.DefaultSceneryEvent
          Scenery event standard implementation.
 class Scenery.NamesIndices
          The indices for track and switch names, implementing a list data model to speed up searching for track names.
 
Field Summary
protected  javax.swing.event.EventListenerList listenerList
          Event listener list.
protected  java.util.Set switches
          Set containing switches.
protected  java.util.Set tracks
          Set containing scenery elements.
 
Constructor Summary
Scenery()
           
 
Method Summary
 void addSceneryChangeListener(SceneryChangeListener listener)
          Adds a scenery listener to this document for notification of any changes.
 void addUndoableEditListener(javax.swing.event.UndoableEditListener listener)
          Adds an undo listener for notification of any changes.
 boolean contains(java.lang.Object o)
          Tests if scenery contains specified object.
 void dump(java.io.PrintStream psOut)
          Dumps debugging info.
protected  void fireSceneryChange(SceneryEvent sce)
          Fires scenery change event to all registered scenery listeners.
 int getCount(java.lang.Class c)
          Returns element's count of specified class.
 java.lang.String getDescription()
          Gets scenery description.
 java.util.Iterator getIterator(java.lang.Class c)
          Returns iterator of elements's collection given class.
 java.util.EventListener[] getListeners(java.lang.Class listenerType)
          Returns an array of registered foo listeners on this scenery.
 java.lang.Object getProperty(java.lang.Object key)
          Gets a property with key key.
 SceneryChangeListener[] getSceneryChangeListeners()
          Returns an array of all registered scenery listeners on this document.
 java.util.Dictionary getSceneryProperties()
          Scenery may contain some properties.
 javax.swing.ListModel getTrackNames()
          Returns data model for list of track and switch names.
 javax.swing.event.UndoableEditListener[] getUndoableEditListeners()
          Returns an array of all registered undo listeners on this document.
 void insert(java.lang.Object[] obj)
          Inserts array of object to the scenery.
 void putProperty(java.lang.Object key, java.lang.Object value)
          Sets property for the scenery.
 void readLock()
          Acquires a lock to begin reading from the scenery.
 void readUnlock()
          Does a read unlock.
 void remove(java.lang.Object[] obj)
          Removes object from scenery.
 void removeSceneryChangeListener(SceneryChangeListener listener)
          Removes a scenery listener.
 void removeUndoableEditListener(javax.swing.event.UndoableEditListener listener)
          Removes an undo listener.
 void replace(java.lang.Object[] o, java.lang.Object[] n)
          Replaces old object with new ones.
 void setDescription(java.lang.String content)
          Sets scenery description.
 void setSceneryProperties(java.util.Dictionary x)
          Scenery may contain some properties.
protected  void writeLock()
          Acquires a scenery lock for writing.
protected  void writeUnlock()
          Releases a write lock previously obtained via writeLock.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

listenerList

protected javax.swing.event.EventListenerList listenerList
Event listener list.


tracks

protected java.util.Set tracks
Set containing scenery elements.


switches

protected java.util.Set switches
Set containing switches.

Constructor Detail

Scenery

public Scenery()
Method Detail

insert

public void insert(java.lang.Object[] obj)
Inserts array of object to the scenery.

Parameters:
obj - Elements to insert to.
Throws:
java.lang.IllegalArgumentException - When array is null.

remove

public void remove(java.lang.Object[] obj)
Removes object from scenery.

Parameters:
obj - An array of elements to remove.
Throws:
java.lang.IllegalArgumentException - When array is null or some of elements in array were not in scenery.

replace

public void replace(java.lang.Object[] o,
                    java.lang.Object[] n)
Replaces old object with new ones. Length of this two arrays has to match. If some of objects in old array is not in scenery, it causes to throw an exception.

Parameters:
o - Objects stored in scenery.
n - New object.
Throws:
java.lang.IllegalArgumentException - When length of the arrays are not equal or scenery does not contain some of elements of the first array.

getIterator

public java.util.Iterator getIterator(java.lang.Class c)
Returns iterator of elements's collection given class.

Parameters:
c - Class of elements.
Returns:
Iterator or null when class is not supported.

getCount

public int getCount(java.lang.Class c)
Returns element's count of specified class.

Parameters:
c - Class of elements.
Returns:
Count of elements or -1 when scenery does not contains elements specified class.

contains

public boolean contains(java.lang.Object o)
Tests if scenery contains specified object.

Returns:
True if scenery contains the object

getTrackNames

public javax.swing.ListModel getTrackNames()
Returns data model for list of track and switch names.


setDescription

public void setDescription(java.lang.String content)
Sets scenery description.

Scenery description describes scenery and it is usefull to include some user data.

Parameters:
content - The description.

getDescription

public java.lang.String getDescription()
Gets scenery description.

Scenery description describes scenery and it is usefull to include some user data.

Returns:
The description.

addSceneryChangeListener

public void addSceneryChangeListener(SceneryChangeListener listener)
Adds a scenery listener to this document for notification of any changes.

Parameters:
listener - The scenery listener to add.
See Also:
addSceneryChangeListener(org.jet.sce.SceneryChangeListener)

removeSceneryChangeListener

public void removeSceneryChangeListener(SceneryChangeListener listener)
Removes a scenery listener.

Parameters:
listener - The scenery listener to remove.
See Also:
removeSceneryChangeListener(org.jet.sce.SceneryChangeListener)

getSceneryChangeListeners

public SceneryChangeListener[] getSceneryChangeListeners()
Returns an array of all registered scenery listeners on this document.

Returns:
All of registered scenery listeners on this document.
See Also:
addSceneryChangeListener(org.jet.sce.SceneryChangeListener), removeSceneryChangeListener(org.jet.sce.SceneryChangeListener)

addUndoableEditListener

public void addUndoableEditListener(javax.swing.event.UndoableEditListener listener)
Adds an undo listener for notification of any changes.

Parameters:
listener - The undo listener to add.
See Also:
addUndoableEditListener(javax.swing.event.UndoableEditListener)

getUndoableEditListeners

public javax.swing.event.UndoableEditListener[] getUndoableEditListeners()
Returns an array of all registered undo listeners on this document.

Returns:
All undo listeners in array.
See Also:
addUndoableEditListener(javax.swing.event.UndoableEditListener), removeUndoableEditListener(javax.swing.event.UndoableEditListener)

removeUndoableEditListener

public void removeUndoableEditListener(javax.swing.event.UndoableEditListener listener)
Removes an undo listener.

Parameters:
listener - The undo listener to remove.
See Also:
removeUndoableEditListener(javax.swing.event.UndoableEditListener)

getListeners

public java.util.EventListener[] getListeners(java.lang.Class listenerType)
Returns an array of registered foo listeners on this scenery. for example you may query a scenery with the following code:
SceneryChangeListener[] mls = 
         (SceneryChangeListener[])(d.getListeners(SceneryChangeListener.class));

Returns:
The array of listener of specified class.
Throws:
java.lang.ClassCastException - If listenerType dosen't specify a class or interface that implements java.util.EventListener.
See Also:
getSceneryChangeListeners(), getUndoableEditListeners()

fireSceneryChange

protected void fireSceneryChange(SceneryEvent sce)
Fires scenery change event to all registered scenery listeners.

Parameters:
sce - Scenery event to fire.

getSceneryProperties

public java.util.Dictionary getSceneryProperties()
Scenery may contain some properties. This method retrives it all.

Returns:
The scenery properties.
See Also:
setSceneryProperties(java.util.Dictionary)

setSceneryProperties

public void setSceneryProperties(java.util.Dictionary x)
Scenery may contain some properties. This method replaces scenery properties with new one.

Parameters:
x - New properties.
See Also:
getSceneryProperties()

getProperty

public final java.lang.Object getProperty(java.lang.Object key)
Gets a property with key key.

Parameters:
key - A property key.
Returns:
Value of property.
See Also:
putProperty(java.lang.Object, java.lang.Object)

putProperty

public final void putProperty(java.lang.Object key,
                              java.lang.Object value)
Sets property for the scenery. It allows to remove property specified by a key, when value is null.

Parameters:
key - A property key.
value - A property value. If null property will be removed.
See Also:
getProperty(java.lang.Object)

writeLock

protected final void writeLock()
Acquires a scenery lock for writing.

Throws:
java.lang.IllegalStateException - Thrown on illegal lock attempt.
See Also:
writeUnlock()

writeUnlock

protected final void writeUnlock()
Releases a write lock previously obtained via writeLock.

See Also:
writeLock()

readLock

public final void readLock()
Acquires a lock to begin reading from the scenery. There can be multiple readers at the same time.

See Also:
readUnlock()

readUnlock

public final void readUnlock()
Does a read unlock.

See Also:
readLock()

dump

public void dump(java.io.PrintStream psOut)
Dumps debugging info.

Parameters:
psOut - Print stream to output.

jET
1.0alpha5