Example #1
0
        /** Return the next HeirarchyNode after this one at the same level in the
         * entire heirarchy.  Return null if this is the last one (or if there is
         * no parent).  This proceeds as follows: If there is no parent, return
         * null.  If there is a child after this one in the parent, return it,
         * otherwise ask the parent for the nextInHeirarchy at its level.  If
         * there is none, return null.  If the next parent has children,
         * return return its first child. Otherwise, keep asking the parent
         * for its nextInHeirarchy until one is found with children.  If none,
         * return null.
         */
        public HeirarchyNode nextInHeirarchy()
        {
            if (_parent == null)
            {
                return(null);
            }

            int nextIndex = _index + 1;

            if (nextIndex < _parent.getChildCount())
            {
                return(_parent.getChild(nextIndex));
            }

            for (HeirarchyNode nextParent = _parent.nextInHeirarchy();
                 nextParent != null; nextParent = nextParent.nextInHeirarchy())
            {
                if (nextParent.getChildCount() > 0)
                {
                    return(nextParent.getChild(0));
                }
            }

            return(null);
        }
Example #2
0
        /** Return the previous HeirarchyNode before this one at the same level in the
         * entire heirarchy.  Return null if this is the first one (or if there is
         * no parent).  This proceeds as follows: If there is no parent, return
         * null.  If there is a child before this one in the parent, return it,
         * otherwise ask the parent for the previousInHeirarchy at its level.  If
         * there is none, return null.  If the previous parent has children,
         * return return its last child. Otherwise, keep asking the parent
         * for its previousInHeirarchy until one is found with children.  If none,
         * return null.
         */
        public HeirarchyNode previousInHeirarchy()
        {
            if (_parent == null)
            {
                return(null);
            }

            int previousIndex = _index - 1;

            if (previousIndex >= 0)
            {
                return(_parent.getChild(previousIndex));
            }

            for (HeirarchyNode previousParent = _parent.previousInHeirarchy();
                 previousParent != null;
                 previousParent = previousParent.previousInHeirarchy())
            {
                if (previousParent.getChildCount() > 0)
                {
                    return(previousParent.getChild(previousParent.getChildCount() - 1));
                }
            }

            return(null);
        }
Example #3
0
        /** Add the child to the end of the child node list and set its parent to this node.
         * It is expected that the subclass will define an add function which takes
         * a child of the correct type.
         *
         * @param child     the node to add as a child to this node.  The child's parent
         *          must be null.
         * @throws HeirarchyException if the child's parent is not null.  This ensures
         *          that the child does not have two parents.
         */
        protected void addChild(HeirarchyNode child)
        {
            if (child._parent != null)
            {
                throw new HeirarchyException("Child node to be added already has a parent.");
            }

            child._parent = this;

            // The child index is the one that will be assigned by the Vector
            child._index = _childNodes.Count;
            _childNodes.Add(child);
        }
Example #4
0
        /** Return the next instance of the given class type looking
         * forwards from this MusicSymbol in the entire score.
         * For example, nextInstanceOfInScore(Beam.class) gets the
         * next Beam.  To find the next instance of the same class,
         * see nextInstanceOfInScore()
         *
         * @param desiredClass  Class object for the MusicSymbol being sought
         * @return the next MusicSymbol of the desired class in the
         *          entire Score, or null if not found.
         */
        public MusicSymbol nextInstanceOfInScore(Type desiredClass)
        {
            for (HeirarchyNode next = nextInHeirarchy(); next != null;
                 next = next.nextInHeirarchy())
            {
                if (desiredClass.IsInstanceOfType(next))
                {
                    return((MusicSymbol)next);
                }
            }

            return(null);
        }
Example #5
0
        /** Return the previous instance of the given class type looking
         * backwards from this MusicSymbol in the entire score.
         * For example, previousInstanceOfInScore(Beam.class) gets the
         * previous Beam.
         *
         * @param desiredClass  Class object for the MusicSymbol being sought
         * @return the previous MusicSymbol of the desired class in the
         *          entire Score, or null if not found.
         */
        public MusicSymbol previousInstanceOfInScore(Type desiredClass)
        {
            for (HeirarchyNode previous = previousInHeirarchy(); previous != null;
                 previous = previous.previousInHeirarchy())
            {
                if (desiredClass.IsInstanceOfType(previous))
                {
                    return((MusicSymbol)previous);
                }
            }

            return(null);
        }
Example #6
0
        /** Add the child to the end of the child node list and set its parent to this node.
         * It is expected that the subclass will define an add function which takes
         * a child of the correct type.
         *
         * @param child     the node to add as a child to this node.  The child's parent
         *          must be null.
         * @throws HeirarchyException if the child's parent is not null.  This ensures
         *          that the child does not have two parents.
         */
        protected void addChild(HeirarchyNode child)
        {
            if (child._parent != null)
            throw new HeirarchyException("Child node to be added already has a parent.");

              child._parent = this;

              // The child index is the one that will be assigned by the Vector
              child._index = _childNodes.Count;
              _childNodes.Add(child);
        }