PIRL

PIRL.Conductor.Maestro
Class Theater_List_Model

java.lang.Object
  extended by javax.swing.AbstractListModel
      extended by PIRL.Conductor.Maestro.Theater_List_Model
All Implemented Interfaces:
Serializable, ComboBoxModel, ListModel, MutableComboBoxModel

public class Theater_List_Model
extends AbstractListModel
implements MutableComboBoxModel

A Theater_List_Model extends the AbstractListModel to provide management of a list of Theater objects.

Version:
1.29
Author:
Bradford Castalia - UA/PIRL
See Also:
Serialized Form

Field Summary
static String ID
          Class identification name with source code version and date.
 
Fields inherited from class javax.swing.AbstractListModel
listenerList
 
Constructor Summary
Theater_List_Model()
           
 
Method Summary
 Theater_List_Model Add(Theater theater)
          Add a Theater to the data model.
 void addElement(Object element)
           
 void Clear()
          Clear the data model of all entries.
 boolean Close_All()
          Close all Theaters registered in the data model.
 boolean Close(int index)
          Close a Theater at an index in the data model.
 boolean Close(Theater theater)
          Close a Theater registered in the data model.
 Object getElementAt(int index)
          Get the Theater name at the data model index.
 Object getSelectedItem()
          Get the currently selected item location.
 int getSize()
          Get the number of entries in the data model.
 int Index(String location)
           
 int Index(Theater theater)
           
 void insertElementAt(Object element, int index)
           
 String Location(int index)
          Get the Theater location for a data model index.
 String Location(Messenger messenger)
           
 String Location(String messenger_address)
           
 String Location(Theater theater)
          Get the location for a Theater in the data model.
protected  boolean Location(Theater theater, String location, int index)
          Set a location at a data model index.
protected static int Matching_Index(Theater theater, List<Theater> theaters)
          Get the index of a Theater in a list of Theaters that matches.
 Theater Messenger_Theater(String messenger_address)
          Get the Theater for a Messenger address.
 boolean Opened(int index)
           
 boolean Opened(String location)
           
 String Previous_Location()
          Get the previously selected item location.
 void Receive_Timeout(int timeout)
          Set the maximum amount of time, in seconds, that will be used when waiting for a Theater protocol Message to be received.
 Theater Remove(int index)
           
 Theater Remove(Theater theater)
           
 void removeElement(Object element)
           
 void removeElementAt(int index)
           
 Theater_List_Model Replace(List<Theater> theaters)
           
 void setSelectedItem(Object item)
          Set the currently selected item.
 Theater Theater(int index)
           
 Theater Theater(Messenger messenger)
           
 Theater Theater(String location)
           
 int Total_Opened()
           
 void Update()
           
 void Update(int index)
           
 
Methods inherited from class javax.swing.AbstractListModel
addListDataListener, fireContentsChanged, fireIntervalAdded, fireIntervalRemoved, getListDataListeners, getListeners, removeListDataListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.swing.ListModel
addListDataListener, removeListDataListener
 

Field Detail

ID

public static final String ID
Class identification name with source code version and date.

See Also:
Constant Field Values
Constructor Detail

Theater_List_Model

public Theater_List_Model()
Method Detail

addElement

public void addElement(Object element)
Specified by:
addElement in interface MutableComboBoxModel

insertElementAt

public void insertElementAt(Object element,
                            int index)
Specified by:
insertElementAt in interface MutableComboBoxModel

removeElement

public void removeElement(Object element)
Specified by:
removeElement in interface MutableComboBoxModel

removeElementAt

public void removeElementAt(int index)
Specified by:
removeElementAt in interface MutableComboBoxModel

setSelectedItem

public void setSelectedItem(Object item)
Set the currently selected item.

If the item is null nothing is done.

If the item is a Theater its location is used. Otherwise the item must be a location String. The location is converted to the abbreviated location form.

If the item location is equal to the currently selected item location nothing is done.

The previously selected item location is set to the currently selected item location and the currently selected item location is then set to the new item location. All listeners are notified that the selected item has changed.

Specified by:
setSelectedItem in interface ComboBoxModel
Parameters:
item - A Theater or location String.

getSelectedItem

public Object getSelectedItem()
Get the currently selected item location.

N.B.: The abbreviated form of the Theater location is returned.

Specified by:
getSelectedItem in interface ComboBoxModel
Returns:
The currently selected item location String. This will be null if, and only if, no item has yet been selected.
See Also:
Theater.Location(String), Theater.Full_Location(String)

Previous_Location

public String Previous_Location()
Get the previously selected item location.

Each time the currently selected item is updated with a new value the previously selected item is set to the currently selected item before it is changed.

N.B.: The abbreviated form of the Theater location is returned.

Returns:
The previously selected item location String. This will always be different than the currently selected item location unless both are null. This will be null until the second change of the currently selected item.

getElementAt

public Object getElementAt(int index)
Get the Theater name at the data model index.

Specified by:
getElementAt in interface ListModel
Parameters:
index - A data model index.
Returns:
The Theater name for the data model idex, If the index is not valid null is returned.

getSize

public int getSize()
Get the number of entries in the data model.

Specified by:
getSize in interface ListModel
Returns:
The total number of entries in the data model.
See Also:
Total_Opened()

Add

public Theater_List_Model Add(Theater theater)
Add a Theater to the data model.

If a Theater at the location of the specified Theater is already in the data model that entry is replaced. Otherwise a new entry for the specified Theater is added to the data model.

If addition of the specified Theater resulted in a location name change, notification is sent to all listeners that the entire list may have changed; otherwise notification of a change to only the affected data model index is sent.

Parameters:
theater - A Theater to be added to the data model. If null nothing is done.
Returns:
This Theater_List_Model.

Location

protected boolean Location(Theater theater,
                           String location,
                           int index)
Set a location at a data model index.

If the theater is non-null the Theater location overrides the specified location. Otherwise, if the specified location is non-null it is set to the standard location format. The abbreviated theater name is obtained from the location.

If the name is different from the location the names list is searched for names not at the specified index that match the new name. If a match is found a name changed flag is set and all matching names are reset to the location (the name is changed to the location). This ensures that names will always be unique.

If the specified index equals the list size - the location is a new addition to the list - the name and location are added to their lists and a null place-holder entry is added to the Theaters list. Otherwise the location replaces an existing location and the name replaces the existing name.

The name changed flag is returned as a signal that a notification should be sent that the entire list may have changed due to the name change; the change is not limited to the specified index.

Parameters:
theater - A Theater object. If null and the location is null nothing is done and false is returned.
location - A Theater location String. If null or empty the Theater location is used.
index - A data model index where the location is to be set. If less than zero or greater than the list size nothing is done and false is returned.
Returns:
true if the list of Theater names was changed - the change is not limited to the specified index; false otherwise.

Replace

public Theater_List_Model Replace(List<Theater> theaters)

Remove

public Theater Remove(int index)

Remove

public Theater Remove(Theater theater)

Clear

public void Clear()
Clear the data model of all entries.

N.B.: The Theaters are not closed.

See Also:
Close_All()

Index

public int Index(Theater theater)

Index

public int Index(String location)

Matching_Index

protected static int Matching_Index(Theater theater,
                                    List<Theater> theaters)
Get the index of a Theater in a list of Theaters that matches.

Theaters match when their locations are equal.

Parameters:
theater - A Theater to be matched.
theaters - A List of Theater objects.
Returns:
The index of the first matching Theater in the list.

Theater

public Theater Theater(int index)

Theater

public Theater Theater(String location)

Theater

public Theater Theater(Messenger messenger)

Messenger_Theater

public Theater Messenger_Theater(String messenger_address)
Get the Theater for a Messenger address.

Parameters:
messenger_address - A Messenger address.
Returns:
The Theater for the Messenger address. This will be null the Messenger address is null or no Theater with a Messenger having the specified address can be found.

Location

public String Location(int index)
Get the Theater location for a data model index.

Parameters:
index - A data model index.
Returns:
The Theater location String for the data model index. This will be null if the index is invalid. N.B.: This will be the same as the Theater location for the Theater at the same index if the index has a Theater; but since there may be no Theater for an index the locations list is used instead.

Location

public String Location(Messenger messenger)

Location

public String Location(String messenger_address)

Location

public String Location(Theater theater)
Get the location for a Theater in the data model.

Parameters:
theater - A Theater.
Returns:
The location from the data model list associated with the Theater. This will be null if the theater is not in the data model.

Receive_Timeout

public void Receive_Timeout(int timeout)
Set the maximum amount of time, in seconds, that will be used when waiting for a Theater protocol Message to be received.

Parameters:
timeout - The timeout value to be applied to all Theaters in the data model.

Opened

public boolean Opened(int index)

Opened

public boolean Opened(String location)

Total_Opened

public int Total_Opened()

Update

public void Update(int index)

Update

public void Update()

Close

public boolean Close(int index)
Close a Theater at an index in the data model.

If the Theater is closed (the return value is true) a change notification is sent to all listeners.

Parameters:
index - A data model index. If the index is invalid or no Theater is present at the index nothing is done.
Returns:
true if an open theater was present at the index and it was closed; false otherwise.

Close

public boolean Close(Theater theater)
Close a Theater registered in the data model.

If the Theater is closed (the return value is true) a change notification is sent to all listeners.

Parameters:
theater - A Theater to be closed. N.B.: If the theater is not registered in this data model nothing is done.
Returns:
true if the theater is in this data model and it was closed, having been found to be open; false otherwise.

Close_All

public boolean Close_All()
Close all Theaters registered in the data model.

If any Theater is closed (the return value is true) a change notification is sent to all listeners.

Returns:
true if any Theater in the data model was found to be open and was closed; false if there was no Theater to be closed.

PIRL

Copyright (C) \ 2003-2009 Bradford Castalia, University of Arizona