public class ComponentUtils
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static char |
componentPropertySeparator |
Constructor and Description |
---|
ComponentUtils() |
Modifier and Type | Method and Description |
---|---|
static void |
addComponents(java.util.List<? extends ModelComponent> list,
int[] indices,
java.util.List<MutableCompositeComponent<?>> parents) |
static void |
addComponents(java.util.List<? extends ModelComponent> list,
int[] indices,
java.util.List<MutableCompositeComponent<?>> parents,
boolean reverse) |
static void |
addComponents(java.util.List<? extends ModelComponent> list,
int[] indices,
MutableCompositeComponent<?> parent) |
static void |
addComponentsInReverse(java.util.List<? extends ModelComponent> list,
int[] indices,
java.util.List<MutableCompositeComponent<?>> parents) |
static boolean |
addCopyComponents(java.util.List<ModelComponent> list,
ModelComponent comp) |
static boolean |
addCopyReferences(java.util.List<ModelComponent> list,
ModelComponent comp,
ModelComponent ancestor) |
static boolean |
areConnected(ModelComponent comp1,
ModelComponent comp2)
Returns true if
comp2 is connected to the same
component hierarchy as comp1 . |
static boolean |
areConnectedVia(ModelComponent comp1,
ModelComponent comp2,
ModelComponent viacomp)
Returns
true if components comp1 and comp2 are
connected via the component hierarchy, with the path running through the
specified intermediate component viacomp (which may equal comp1 , comp2 , or any component on the path in between). |
static CompositeComponent |
castRefToAncestor(java.lang.Object ref) |
static int |
checkConnectivity(ModelComponent comp1,
ModelComponent comp2,
ModelComponent viacomp)
Returns 1 if components
comp1 and comp2 are
connected via the component hierarchy, with the path running through the
specified intermediate component viacomp (which may equal comp1 , comp2 , or any component on the path in between). |
static void |
checkReferenceContainment(ModelComponent comp) |
static void |
checkReferenceContainment(ModelComponent comp,
CompositeComponent ancestor) |
static boolean |
componentsAreDeletable(java.util.Collection<? extends ModelComponent> comps,
boolean ignoreEditable)
Returns true if all components in a list can be deleted.
|
static void |
deleteComponentAndDependencies(ModelComponent comp)
Deletes a single component, along with all its hard dependencies, and
updates its soft dependencies.
|
static void |
deleteComponentsAndDependencies(java.util.List<? extends ModelComponent> comps)
Takes a list of components and removes them along with all their
hard dependencies, and updates their soft dependencies.
|
static CompositeComponent |
farthestEncapsulatingAncestor(ModelComponent c)
Returns the farthest ancestor of a component (or the component
itself) for which
hierarchyContainsDependencies() returns true . |
static ModelComponent |
findCommonAncestor(java.util.List<? extends ModelComponent> comps)
Returns the common ancestor, if any, for a list of model components.
|
static ModelComponent |
findCommonAncestor(ModelComponent comp1,
ModelComponent comp2)
Returns the common ancestor, if any, for two model components.
|
static ModelComponent |
findComponent(ModelComponent comp,
java.lang.String path) |
static java.lang.Object |
findComponentOrProperty(ModelComponent comp,
java.lang.String path) |
static java.util.LinkedList<ModelComponent> |
findCopyComponents(java.util.List<ModelComponent> comps) |
static java.util.LinkedList<ModelComponent> |
findDependentComponents(java.util.List<ModelComponent> update,
java.util.List<? extends ModelComponent> comps) |
static Property |
findProperty(ModelComponent comp,
java.lang.String path) |
static int |
getDepth(ModelComponent comp)
Returns the depth of a component within the component hierarchy.
|
static java.lang.String |
getDiagnosticName(java.lang.Object obj)
Returns name information for an object suitable for diagnostic
printing.
|
static CompositeComponent |
getGrandParent(ModelComponent comp) |
static java.lang.String |
getPathName(ModelComponent comp) |
static java.lang.String |
getPathName(ModelComponent ancestor,
ModelComponent comp) |
static java.lang.String |
getPathName(ModelComponent reference,
ModelComponent target,
boolean compact)
Returns a path name from a reference component to a target component.
|
static ModelComponent |
getPropertyComponent(HasProperties host)
Returns the ModelComponent, if any, associated with a given property
host.
|
static ModelComponent |
getPropertyComponent(Property prop)
Returns the ModelComponent, if any, associated with a given property.
|
static java.lang.String |
getPropertyPathName(Property prop) |
static java.lang.String |
getPropertyPathName(Property prop,
ModelComponent topAncestor,
boolean excludeLeaf) |
static java.lang.String |
getWritePathName(CompositeComponent ancestor,
ModelComponent comp) |
static java.lang.String |
getWritePropertyPathName(Property prop,
ModelComponent topAncestor) |
static java.lang.String |
getWritePropertyPathName(java.lang.String name,
HasProperties host,
ModelComponent topAncestor) |
static boolean |
haveCommonAncestor(ModelComponent comp1,
ModelComponent comp2)
Returns
true if two components have a common ancestor. |
static boolean |
isAncestorOf(ModelComponent comp0,
ModelComponent comp1)
Returns true if comp0 is an ancestor of comp1.
|
static boolean |
isAncestorSelected(ModelComponent comp) |
static boolean |
isEditable(CompositeComponent parent,
boolean ignoreEditable)
Returns true if a composite component is editable, meaning that its
subcomponents can be removed via the GUI.
|
static <T extends ModelComponent> |
loadComponent(java.io.File file,
CompositeComponent ancestor,
java.lang.Class<T> expectedType) |
static ModelComponent |
loadComponent(java.lang.String fileName) |
static <T extends ModelComponent> |
loadComponent(java.lang.String fileName,
java.lang.Class<T> expectedType) |
static ModelComponent |
loadComponent(java.lang.String fileName,
CompositeComponent ancestor) |
static <T extends ModelComponent> |
loadComponent(java.lang.String fileName,
CompositeComponent ancestor,
java.lang.Class<T> expectedType) |
static java.util.LinkedList<ModelComponent> |
markInvalidSubcomps(ModelComponent comp)
Recursively finds all subcomponents of
comp which are invalid
according to ClassAliases.isClassValid(java.lang.Class<?>) , along with their hard
dependencies, marks them to be non-writable, and returns a list of them. |
static ModelComponent |
maybeCopy(int flags,
java.util.Map<ModelComponent,ModelComponent> copyMap,
CopyableComponent c) |
static ModelComponent |
maybeGetCopy(int flags,
java.util.Map<ModelComponent,ModelComponent> copyMap,
CopyableComponent c) |
static CompositeComponent |
nearestEncapsulatingAncestor(ModelComponent c)
Returns the closest ancestor of a component (or the component
itself) for which
hierarchyContainsDependencies() returns true . |
static java.util.ArrayList<Property> |
parseProperties(java.util.Deque<ScanToken> tokens,
CompositeComponent ancestor) |
static Property |
parseProperty(java.lang.Object obj,
CompositeComponent ancestor) |
static void |
recursivelyConnect(ModelComponent comp,
CompositeComponent connector) |
static void |
recursivelyDisconnect(ModelComponent comp,
CompositeComponent connector) |
static <E extends ModelComponent> |
recursivelyFindComponents(java.lang.Class<E> clazz,
CompositeComponent comp,
java.util.List<E> out) |
static boolean |
referencesContained(CompositeComponent ancestor,
ModelComponent comp)
Returns true if all references associated with a component are recursively
contained beneath a specified ancestor.
|
static java.util.LinkedList<MutableCompositeComponent<?>> |
removeComponents(java.util.List<? extends ModelComponent> list,
int[] indices) |
static void |
testPaths(CompositeComponent comp)
Used for debugging.
|
static void |
unmarkInvalidSubcomps(java.util.LinkedList<ModelComponent> nccomps)
Sets all components in a list to be writable.
|
static <C extends ModelComponent> |
updateReferences(ModelComponent c,
java.util.List<C> refs,
boolean undo,
java.util.Deque<java.lang.Object> undoInfo) |
static boolean |
withinHierarchy(ModelComponent comp,
ModelComponent ancestor)
Returns true if a component is equal to, or is a descendant of a
particular ancestor component.
|
static boolean |
withinHierarchy(ModelComponent comp,
TransformableGeometry topObject)
Returns true if a component is equal to, or is a descendant of a
particular object.
|
public static final char componentPropertySeparator
public static boolean isEditable(CompositeComponent parent, boolean ignoreEditable)
parent
- component to check for editabilityignoreEditable
- if true
, parent need only be an instance of
MutableCompositeComponent
, and the result of its MutableCompositeComponent.isEditable()
method is ignored.public static boolean componentsAreDeletable(java.util.Collection<? extends ModelComponent> comps, boolean ignoreEditable)
comps
- list of components to checkignoreEditable
- if true
, each component's parent need only
be an instance of MutableCompositeComponent
, and the result of
its MutableCompositeComponent.isEditable()
method is ignored.true
if all components can be deletedpublic static void deleteComponentAndDependencies(ModelComponent comp)
The effect of this method is the same as deleting the component in the graphical interface.
comp
- component to delete.public static void deleteComponentsAndDependencies(java.util.List<? extends ModelComponent> comps)
The effect of this method is the same as deleting a set of components in the graphical interface.
comps
- list of components to delete.public static java.util.LinkedList<ModelComponent> findDependentComponents(java.util.List<ModelComponent> update, java.util.List<? extends ModelComponent> comps)
public static java.util.LinkedList<MutableCompositeComponent<?>> removeComponents(java.util.List<? extends ModelComponent> list, int[] indices)
public static boolean isAncestorSelected(ModelComponent comp)
public static void addComponents(java.util.List<? extends ModelComponent> list, int[] indices, java.util.List<MutableCompositeComponent<?>> parents)
public static void addComponentsInReverse(java.util.List<? extends ModelComponent> list, int[] indices, java.util.List<MutableCompositeComponent<?>> parents)
public static void addComponents(java.util.List<? extends ModelComponent> list, int[] indices, MutableCompositeComponent<?> parent)
public static void addComponents(java.util.List<? extends ModelComponent> list, int[] indices, java.util.List<MutableCompositeComponent<?>> parents, boolean reverse)
public static boolean withinHierarchy(ModelComponent comp, ModelComponent ancestor)
comp
- component to checkancestor
- ancestor componentpublic static boolean withinHierarchy(ModelComponent comp, TransformableGeometry topObject)
comp
- component to checktopObject
- candidate ancestor componentpublic static boolean addCopyComponents(java.util.List<ModelComponent> list, ModelComponent comp)
public static java.util.LinkedList<ModelComponent> findCopyComponents(java.util.List<ModelComponent> comps)
public static boolean addCopyReferences(java.util.List<ModelComponent> list, ModelComponent comp, ModelComponent ancestor)
public static int getDepth(ModelComponent comp)
public static boolean haveCommonAncestor(ModelComponent comp1, ModelComponent comp2)
true
if two components have a common ancestor.public static boolean areConnected(ModelComponent comp1, ModelComponent comp2)
comp2
is connected to the same
component hierarchy as comp1
.public static ModelComponent findCommonAncestor(ModelComponent comp1, ModelComponent comp2)
public static int checkConnectivity(ModelComponent comp1, ModelComponent comp2, ModelComponent viacomp)
comp1
and comp2
are
connected via the component hierarchy, with the path running through the
specified intermediate component viacomp
(which may equal comp1
, comp2
, or any component on the path in between).
Otherwise, return 0 if the comp1
and comp2
are not connected, or -1 if they are connected but not via
viacomp
.comp1
- first componentcomp2
- second component to which path is being checkedviacomp
- required intermediate componentviacomp
, 0 if they are not connected, and -1 if
they are connected by not via viacomp
.public static boolean areConnectedVia(ModelComponent comp1, ModelComponent comp2, ModelComponent viacomp)
true
if components comp1
and comp2
are
connected via the component hierarchy, with the path running through the
specified intermediate component viacomp
(which may equal comp1
, comp2
, or any component on the path in between).comp1
- first componentcomp2
- second component to which path is being checkedviacomp
- required intermediate componenttrue
if components are connected via a path containing
viacomp
.public static ModelComponent findCommonAncestor(java.util.List<? extends ModelComponent> comps)
public static boolean isAncestorOf(ModelComponent comp0, ModelComponent comp1)
public static boolean referencesContained(CompositeComponent ancestor, ModelComponent comp)
ancestor
- ancestor component beneath which reference should be containedcomp
- component whose references should be checkedpublic static java.lang.String getDiagnosticName(java.lang.Object obj)
public static void checkReferenceContainment(ModelComponent comp)
public static void checkReferenceContainment(ModelComponent comp, CompositeComponent ancestor)
public static CompositeComponent nearestEncapsulatingAncestor(ModelComponent c)
hierarchyContainsDependencies()
returns true
.
That means all inter-component references are contained
within the ancestor's hierarchy. If no such ancestor is found,
null
is returned.public static CompositeComponent farthestEncapsulatingAncestor(ModelComponent c)
hierarchyContainsDependencies()
returns true
.
That means all inter-component references are contained
within the ancestor's hierarchy. If no such ancestor is found,
null
is returned.public static java.util.LinkedList<ModelComponent> markInvalidSubcomps(ModelComponent comp)
comp
which are invalid
according to ClassAliases.isClassValid(java.lang.Class<?>)
, along with their hard
dependencies, marks them to be non-writable, and returns a list of them.comp
- component whose subcomponents should be checkedpublic static void unmarkInvalidSubcomps(java.util.LinkedList<ModelComponent> nccomps)
markInvalidSubcomps(artisynth.core.modelbase.ModelComponent)
.nccomps
- list of invalid components and their hard dependencies
previously returned by markInvalidSubcomps(artisynth.core.modelbase.ModelComponent)
.public static <T extends ModelComponent> T loadComponent(java.io.File file, CompositeComponent ancestor, java.lang.Class<T> expectedType) throws java.io.IOException
java.io.IOException
public static <T extends ModelComponent> T loadComponent(java.lang.String fileName, CompositeComponent ancestor, java.lang.Class<T> expectedType) throws java.io.IOException
java.io.IOException
public static <T extends ModelComponent> T loadComponent(java.lang.String fileName, java.lang.Class<T> expectedType) throws java.io.IOException
java.io.IOException
public static ModelComponent loadComponent(java.lang.String fileName, CompositeComponent ancestor) throws java.io.IOException
java.io.IOException
public static ModelComponent loadComponent(java.lang.String fileName) throws java.io.IOException
java.io.IOException
public static ModelComponent getPropertyComponent(Property prop)
prop
- property to be queriedpublic static ModelComponent getPropertyComponent(HasProperties host)
host
- property host to be queriedpublic static ModelComponent findComponent(ModelComponent comp, java.lang.String path)
public static Property findProperty(ModelComponent comp, java.lang.String path)
public static java.lang.Object findComponentOrProperty(ModelComponent comp, java.lang.String path)
public static Property parseProperty(java.lang.Object obj, CompositeComponent ancestor) throws java.io.IOException
java.io.IOException
public static java.util.ArrayList<Property> parseProperties(java.util.Deque<ScanToken> tokens, CompositeComponent ancestor) throws java.io.IOException
java.io.IOException
public static java.lang.String getPathName(ModelComponent comp)
public static java.lang.String getPathName(ModelComponent ancestor, ModelComponent comp)
public static java.lang.String getPathName(ModelComponent reference, ModelComponent target, boolean compact)
public static java.lang.String getWritePropertyPathName(Property prop, ModelComponent topAncestor)
public static java.lang.String getWritePropertyPathName(java.lang.String name, HasProperties host, ModelComponent topAncestor)
public static java.lang.String getPropertyPathName(Property prop, ModelComponent topAncestor, boolean excludeLeaf)
public static java.lang.String getPropertyPathName(Property prop)
public static CompositeComponent getGrandParent(ModelComponent comp)
public static ModelComponent maybeGetCopy(int flags, java.util.Map<ModelComponent,ModelComponent> copyMap, CopyableComponent c)
public static ModelComponent maybeCopy(int flags, java.util.Map<ModelComponent,ModelComponent> copyMap, CopyableComponent c)
public static <E extends ModelComponent> void recursivelyFindComponents(java.lang.Class<E> clazz, CompositeComponent comp, java.util.List<E> out)
public static java.lang.String getWritePathName(CompositeComponent ancestor, ModelComponent comp)
public static void testPaths(CompositeComponent comp)
public static CompositeComponent castRefToAncestor(java.lang.Object ref) throws java.io.IOException
java.io.IOException
public static <C extends ModelComponent> boolean updateReferences(ModelComponent c, java.util.List<C> refs, boolean undo, java.util.Deque<java.lang.Object> undoInfo)
public static void recursivelyConnect(ModelComponent comp, CompositeComponent connector)
public static void recursivelyDisconnect(ModelComponent comp, CompositeComponent connector)