artisynth.core.modelbase
Class ComponentList<C extends ModelComponent>

java.lang.Object
  extended by artisynth.core.modelbase.ModelComponentBase
      extended by artisynth.core.modelbase.ComponentList<C>
All Implemented Interfaces:
ComponentChangeListener, ComponentListView<C>, CompositeComponent, IndexedComponentList, ModelComponent, MutableCompositeComponent<C>, ParameterizedClass, java.lang.Cloneable, java.lang.Iterable<C>, java.util.Collection<C>, HasProperties, HierarchyNode, ListView<C>, Scannable
Direct Known Subclasses:
ForceEffectorList, ModelBase, ReferenceList, RenderableComponentList, ScalableList

public class ComponentList<C extends ModelComponent>
extends ModelComponentBase
implements ComponentListView<C>, MutableCompositeComponent<C>, java.lang.Iterable<C>, java.util.Collection<C>, ParameterizedClass


Nested Class Summary
 
Nested classes/interfaces inherited from interface artisynth.core.modelbase.CompositeComponent
CompositeComponent.NavpanelDisplay
 
Nested classes/interfaces inherited from interface artisynth.core.modelbase.ModelComponent
ModelComponent.NavpanelVisibility
 
Field Summary
static CompositeComponent.NavpanelDisplay DEFAULT_NAVPANEL_DISPLAY
           
static PropertyList myProps
           
 
Fields inherited from class artisynth.core.modelbase.ModelComponentBase
enforceUniqueCompositeNames, enforceUniqueNames, myNumber, NULL_OBJ, useCompactPathNames
 
Constructor Summary
ComponentList(java.lang.Class<C> type)
           
ComponentList(java.lang.Class<C> type, java.lang.String name)
           
ComponentList(java.lang.Class<C> type, java.lang.String name, java.lang.String shortName)
           
 
Method Summary
 boolean add(C comp)
          Adds a component to this MutableCompositeComponent.
 void add(C comp, int idx)
           
 boolean addAll(java.util.Collection<? extends C> c)
           
 void addComponents(ModelComponent[] comps, int[] indices, int ncomps)
          Adds a set of components to this MutableCompositeComponent.
 boolean addFixed(C comp)
           
 boolean addNumbered(C comp, int number)
           
 void clear()
           
 java.lang.Object clone()
           
 void componentChanged(ComponentChangeEvent e)
          Notifies this composite component that a change has occured within one or more of its descendants.
 boolean contains(C comp)
          Faster implementation using component parent pointer.
 boolean contains(java.lang.Object obj)
          Returns true if a particular element is contained in this list.
 boolean containsAll(java.util.Collection<?> c)
           
 ComponentList<C> copy(int flags, java.util.Map<ModelComponent,ModelComponent> copyMap)
           
 void ensureCapacity(int cap)
           
 C findComponent(java.lang.String path)
          Recursively searches for a sub-component of this ModelComponent, identified by a path of component names.
 C get(int idx)
          Get the component at a particular index, or null if there is no such component.
 C get(java.lang.String nameOrNumber)
          Get the component with particular name, or null if there is no such component.
 PropertyList getAllPropertyInfo()
          Returns a list giving static information about all properties exported by this object.
 C getByNumber(int num)
          Get the component with the specified number, or null if there is no such component.
 java.util.Iterator<? extends HierarchyNode> getChildren()
           
 CompositeComponent.NavpanelDisplay getNavpanelDisplay()
          Returns the DisplayMode for this component.
 int getNumberLimit()
          Returns the current upper limit for numbers among all sub-components in this composite.
 java.lang.String getShortName()
          Gets the short name of this component list.
 java.lang.Class<C> getTypeParameter()
          Returns the base type for the class parameterization.
 boolean hasChildren()
           
 boolean hasParameterizedType()
          Returns true if this class explicitly utilizes a parameterized type.
 boolean hierarchyContainsReferences()
          Returns true if the component hierarchy formed by this component and its descendents is closed with respect to references.
 int indexOf(ModelComponent comp)
          Get the index of a particular component in this list, or -1 if the specified component is not present.
 boolean isEmpty()
           
 java.util.Iterator<C> iterator()
          Return an iterator over all components in this list.
 int nextComponentNumber()
          Returns the number that will be assigned to the next component added to this list.
 int numComponents()
          Returns the number of components in this CompositeComponent.
 void postscan(java.util.Deque<ScanToken> tokens, CompositeComponent ancestor)
          Performs any required post-scanning for this component.
 C remove(int idx)
           
 boolean remove(java.lang.Object obj)
          Removes a component from this MutableCompositeComponent, returning true if the componet was in fact found and removed.
 void removeAll()
           
 boolean removeAll(java.util.Collection<?> c)
           
 void removeComponents(ModelComponent[] comps, int[] indices, int ncomps)
          Removes a set of components from this MutableCompositeComponent.
 boolean retainAll(java.util.Collection<?> c)
           
 void scan(ReaderTokenizer rtok, java.lang.Object ref)
          Scans this element from a ReaderTokenizer.
 void setNavpanelDisplay(CompositeComponent.NavpanelDisplay mode)
          Sets the display mode for this component.
 void setNumberingStartAtOne()
           
 void setShortName(java.lang.String name)
           
 int size()
          Get the number of components in this list.
 java.lang.Object[] toArray()
           
<C> C[]
toArray(C[] array)
           
 void updateNameMap(java.lang.String newName, java.lang.String oldName, ModelComponent comp)
          
 
Methods inherited from class artisynth.core.modelbase.ModelComponentBase
checkFlag, checkName, checkNameUniqueness, clearFlag, connectToHierarchy, createTempFlag, disconnectFromHierarchy, getGrandParent, getHardReferences, getName, getNameRange, getNavpanelVisibility, getNavpanelVisibility, getNumber, getParent, getProperty, getSoftReferences, hasState, isFixed, isMarked, isSelected, isWritable, makeValidName, makeValidName, notifyParentOfChange, printReferences, recursivelyContained, recursivelyContains, removeTempFlag, setFixed, setFlag, setMarked, setName, setNavpanelVisibility, setNavpanelVisibility, setNumber, setParent, setSelected, updateReferences, write
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface artisynth.core.modelbase.ComponentListView
getName
 
Methods inherited from interface artisynth.core.modelbase.ModelComponent
connectToHierarchy, disconnectFromHierarchy, getHardReferences, getName, getNavpanelVisibility, getNumber, getParent, getSoftReferences, hasState, isFixed, isMarked, isSelected, notifyParentOfChange, setFixed, setMarked, setName, setNumber, setParent, setSelected, updateReferences
 
Methods inherited from interface maspack.properties.HasProperties
getProperty
 
Methods inherited from interface maspack.util.Scannable
isWritable, write
 
Methods inherited from interface java.util.Collection
equals, hashCode
 

Field Detail

DEFAULT_NAVPANEL_DISPLAY

public static CompositeComponent.NavpanelDisplay DEFAULT_NAVPANEL_DISPLAY

myProps

public static PropertyList myProps
Constructor Detail

ComponentList

public ComponentList(java.lang.Class<C> type)

ComponentList

public ComponentList(java.lang.Class<C> type,
                     java.lang.String name)

ComponentList

public ComponentList(java.lang.Class<C> type,
                     java.lang.String name,
                     java.lang.String shortName)
Method Detail

getAllPropertyInfo

public PropertyList getAllPropertyInfo()
Description copied from interface: HasProperties
Returns a list giving static information about all properties exported by this object.

Specified by:
getAllPropertyInfo in interface HasProperties
Overrides:
getAllPropertyInfo in class ModelComponentBase
Returns:
static information for all exported properties

get

public C get(java.lang.String nameOrNumber)
Get the component with particular name, or null if there is no such component.

Specified by:
get in interface ComponentListView<C extends ModelComponent>
Specified by:
get in interface CompositeComponent
Parameters:
nameOrNumber - name of the component
Returns:
component with specified name

getByNumber

public C getByNumber(int num)
Get the component with the specified number, or null if there is no such component.

Specified by:
getByNumber in interface ComponentListView<C extends ModelComponent>
Specified by:
getByNumber in interface CompositeComponent
Parameters:
num - number of the component
Returns:
component with specified number

numComponents

public int numComponents()
Returns the number of components in this CompositeComponent.

Specified by:
numComponents in interface CompositeComponent
Specified by:
numComponents in interface IndexedComponentList
Returns:
number of sub-components

indexOf

public int indexOf(ModelComponent comp)
Get the index of a particular component in this list, or -1 if the specified component is not present.

Specified by:
indexOf in interface ComponentListView<C extends ModelComponent>
Specified by:
indexOf in interface CompositeComponent
Parameters:
comp - component to search for
Returns:
index of the component within this list

findComponent

public C findComponent(java.lang.String path)
Recursively searches for a sub-component of this ModelComponent, identified by a path of component names.

Specified by:
findComponent in interface CompositeComponent
Parameters:
path - path leading to the sub-component
Returns:
named sub-component, or null if the component does not exist.

getNumberLimit

public int getNumberLimit()
Returns the current upper limit for numbers among all sub-components in this composite. This is one greater than the maximum sub-component number currently assigned. A value of 0 means that there are no sub-components. This method is useful for creating and sizing arrays whose contents are indexed by component numbers.

Specified by:
getNumberLimit in interface CompositeComponent
Returns:
upper limit for numbers among all sub-components

getNavpanelDisplay

public CompositeComponent.NavpanelDisplay getNavpanelDisplay()
Returns the DisplayMode for this component. This specifies how the component should be displayed in a navigation panel.

Specified by:
getNavpanelDisplay in interface CompositeComponent
Returns:
display mode for this component

setNavpanelDisplay

public void setNavpanelDisplay(CompositeComponent.NavpanelDisplay mode)
Sets the display mode for this component. This controls how the component is displayed in a navigation panel. The default setting is NORMAL.

Parameters:
mode - new display mode

componentChanged

public void componentChanged(ComponentChangeEvent e)
Notifies this composite component that a change has occured within one or more of its descendants. When this occurs, the composite may need to invalidate cached information that depends on the descendants.

This method should propagate the notification up the component hierarchy by calling notifyParentOfChange.

Specified by:
componentChanged in interface ComponentChangeListener
Specified by:
componentChanged in interface CompositeComponent
Parameters:
e - optional argument giving specific information about the change

updateNameMap

public void updateNameMap(java.lang.String newName,
                          java.lang.String oldName,
                          ModelComponent comp)

Specified by:
updateNameMap in interface CompositeComponent

hierarchyContainsReferences

public boolean hierarchyContainsReferences()
Returns true if the component hierarchy formed by this component and its descendents is closed with respect to references. In other words, all components referenced by components within the hierarchy are themselves components within the hierarchy.

In particular, this means that one does not need to search outside the hierarchy when looking for dependencies.

Specified by:
hierarchyContainsReferences in interface CompositeComponent
Returns:
true if this component's hierarchy is closed with respect to references.

nextComponentNumber

public int nextComponentNumber()
Returns the number that will be assigned to the next component added to this list.

Specified by:
nextComponentNumber in interface ComponentListView<C extends ModelComponent>
Returns:
next component number for this list

size

public int size()
Description copied from interface: ComponentListView
Get the number of components in this list.

Specified by:
size in interface ComponentListView<C extends ModelComponent>
Specified by:
size in interface java.util.Collection<C extends ModelComponent>
Specified by:
size in interface ListView<C extends ModelComponent>
Returns:
number of components

get

public C get(int idx)
Description copied from interface: ComponentListView
Get the component at a particular index, or null if there is no such component.

Specified by:
get in interface ComponentListView<C extends ModelComponent>
Specified by:
get in interface CompositeComponent
Specified by:
get in interface IndexedComponentList
Specified by:
get in interface ListView<C extends ModelComponent>
Parameters:
idx - index of the component
Returns:
component at specified index

iterator

public java.util.Iterator<C> iterator()
Description copied from interface: ComponentListView
Return an iterator over all components in this list.

Specified by:
iterator in interface ComponentListView<C extends ModelComponent>
Specified by:
iterator in interface java.lang.Iterable<C extends ModelComponent>
Specified by:
iterator in interface java.util.Collection<C extends ModelComponent>
Specified by:
iterator in interface ListView<C extends ModelComponent>
Returns:
iterator over list components

contains

public boolean contains(java.lang.Object obj)
Description copied from interface: ListView
Returns true if a particular element is contained in this list.

Specified by:
contains in interface java.util.Collection<C extends ModelComponent>
Specified by:
contains in interface ListView<C extends ModelComponent>
Parameters:
obj - element to search for
Returns:
true if the element is contained in this list

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface java.util.Collection<C extends ModelComponent>

getTypeParameter

public java.lang.Class<C> getTypeParameter()
Description copied from interface: ParameterizedClass
Returns the base type for the class parameterization.

Specified by:
getTypeParameter in interface ParameterizedClass

hasParameterizedType

public boolean hasParameterizedType()
Description copied from interface: ParameterizedClass
Returns true if this class explicitly utilizes a parameterized type.

Specified by:
hasParameterizedType in interface ParameterizedClass

addAll

public boolean addAll(java.util.Collection<? extends C> c)
Specified by:
addAll in interface java.util.Collection<C extends ModelComponent>

getChildren

public java.util.Iterator<? extends HierarchyNode> getChildren()
Specified by:
getChildren in interface HierarchyNode
Overrides:
getChildren in class ModelComponentBase

hasChildren

public boolean hasChildren()
Specified by:
hasChildren in interface HierarchyNode
Overrides:
hasChildren in class ModelComponentBase

add

public boolean add(C comp)
Adds a component to this MutableCompositeComponent. The component is placed in the last position and its index value is set accordingly.

Specified by:
add in interface MutableCompositeComponent<C extends ModelComponent>
Specified by:
add in interface java.util.Collection<C extends ModelComponent>
Parameters:
comp - component to be added

addFixed

public boolean addFixed(C comp)

add

public void add(C comp,
                int idx)

addNumbered

public boolean addNumbered(C comp,
                           int number)

addComponents

public void addComponents(ModelComponent[] comps,
                          int[] indices,
                          int ncomps)
Adds a set of components to this MutableCompositeComponent. This routine is intended to provide greater efficiency for adding a large number of components at one time. If the argument indices is not null, it specified the index locations at which the components should be added. It is up to the caller to insure that the specified index values make sense; in particular, they must not exceed the final size of the component and no two specified indices can be the same.

Specified by:
addComponents in interface MutableCompositeComponent<C extends ModelComponent>
Parameters:
comps - list of components to be added
indices - (optional) index locations of components
ncomps - number of components to be added

remove

public boolean remove(java.lang.Object obj)
Removes a component from this MutableCompositeComponent, returning true if the componet was in fact found and removed.

Specified by:
remove in interface MutableCompositeComponent<C extends ModelComponent>
Specified by:
remove in interface java.util.Collection<C extends ModelComponent>
Parameters:
obj - component to be added
Returns:
true if the component was removed

remove

public C remove(int idx)

removeComponents

public void removeComponents(ModelComponent[] comps,
                             int[] indices,
                             int ncomps)
Removes a set of components from this MutableCompositeComponent. This routine is intended to provide greater efficiency for adding a large number of components at one time. If the argument indices is not null, it is used to return the indices where the components were located.

Specified by:
removeComponents in interface MutableCompositeComponent<C extends ModelComponent>
Parameters:
comps - components to be removed
indices - (optional) stores the indices of the removed components
ncomps - number of components to be removed

removeAll

public void removeAll()

retainAll

public boolean retainAll(java.util.Collection<?> c)
Specified by:
retainAll in interface java.util.Collection<C extends ModelComponent>

removeAll

public boolean removeAll(java.util.Collection<?> c)
Specified by:
removeAll in interface java.util.Collection<C extends ModelComponent>

containsAll

public boolean containsAll(java.util.Collection<?> c)
Specified by:
containsAll in interface java.util.Collection<C extends ModelComponent>

toArray

public java.lang.Object[] toArray()
Specified by:
toArray in interface java.util.Collection<C extends ModelComponent>

toArray

public <C> C[] toArray(C[] array)
Specified by:
toArray in interface java.util.Collection<C extends ModelComponent>

clear

public void clear()
Specified by:
clear in interface java.util.Collection<C extends ModelComponent>

ensureCapacity

public void ensureCapacity(int cap)

setNumberingStartAtOne

public void setNumberingStartAtOne()

setShortName

public void setShortName(java.lang.String name)

getShortName

public java.lang.String getShortName()
Description copied from interface: ComponentListView
Gets the short name of this component list.

Specified by:
getShortName in interface ComponentListView<C extends ModelComponent>
Returns:
short name of this list

contains

public boolean contains(C comp)
Faster implementation using component parent pointer.

Specified by:
contains in interface ComponentListView<C extends ModelComponent>
Parameters:
comp - component to search for
Returns:
true if the component is contained in this list

scan

public void scan(ReaderTokenizer rtok,
                 java.lang.Object ref)
          throws java.io.IOException
Description copied from class: ModelComponentBase
Scans this element from a ReaderTokenizer. The expected text format is assumed to be compatible with that produced by write.

Specified by:
scan in interface ModelComponent
Specified by:
scan in interface Scannable
Overrides:
scan in class ModelComponentBase
Parameters:
rtok - Tokenizer from which to scan the element
ref - optional reference object which can be used for resolving references to other objects
Throws:
java.io.IOException - if an I/O or formatting error occured

postscan

public void postscan(java.util.Deque<ScanToken> tokens,
                     CompositeComponent ancestor)
              throws java.io.IOException
Description copied from interface: ModelComponent
Performs any required post-scanning for this component. This involves handling any information whose processing was deferred during the scan() method and stored in the token queue. The most common use of this method is to resolve the paths of component references, which may not have been created at the time of the initial scan() call.

Specified by:
postscan in interface ModelComponent
Overrides:
postscan in class ModelComponentBase
Parameters:
tokens - token information that was stored during scan().
ancestor - ancestor component with respect to which reference component paths are defined.
Throws:
java.io.IOException

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Overrides:
clone in class ModelComponentBase
Throws:
java.lang.CloneNotSupportedException

copy

public ComponentList<C> copy(int flags,
                             java.util.Map<ModelComponent,ModelComponent> copyMap)
Overrides:
copy in class ModelComponentBase