need to insert a child as the first child of an outline but you can only append 
to the outline.
-----------------------------------------------------------------------------------------------

                 Key: PDFBOX-996
                 URL: https://issues.apache.org/jira/browse/PDFBOX-996
             Project: PDFBox
          Issue Type: Improvement
          Components: PDModel
    Affects Versions: 1.5.0
            Reporter: Charles Simon


After some investigation I determined that the new code needed to go into 
"PDOutlineNode.java" in package 
"org.apache.pdfbox.pdmodel.interactive.documentnavigation.outline".

The following is the code for a new method I wrote and tested.  Since I can not 
commit the code I will leave that to someone who can.  The code has been 
tested, but another pair of eyes never hurts.

********* Begin code for new method in PDOutlineNode.java *****************
    /**
     * Insert this node before the current first child node or as the only
     * node if there are no children.
     * @param outlineNode
     */
    public void insertFirstChild( PDOutlineItem outlineNode )
    {
        PDOutlineItem wasFirstNode = this.getFirstChild();
        int currentOpenCount = getOpenCount();
        int numberOfOpenNodesWeAreAdding = 1;
        outlineNode.setParent( this );
        PDOutlineItem lastAddedNode = outlineNode;
        while(lastAddedNode.getNextSibling() != null)
        {
            lastAddedNode = lastAddedNode.getNextSibling();
            lastAddedNode.setParent(this);
        }
        setFirstChild( outlineNode );
        //  1 for the the item we are adding;
        if( outlineNode.isNodeOpen() )
        {
            numberOfOpenNodesWeAreAdding += outlineNode.getOpenCount();
        }
        // now update the count like appendChild() does
        if( isNodeOpen() )
        {
            setOpenCount( currentOpenCount + numberOfOpenNodesWeAreAdding );
        }
        else
        {
            setOpenCount( currentOpenCount - numberOfOpenNodesWeAreAdding );
        }
        // link the 2 subsets together
        // end of added list -> to first of old set
        lastAddedNode.setNextSibling(wasFirstNode);
        // first of old set -> back to last of added set
        wasFirstNode.setPreviousSibling(lastAddedNode);
        // tell the parent about the new node(s) we just added
        updateParentOpenCount( numberOfOpenNodesWeAreAdding );
        // update last if there were no child nodes when we started.
        if ( wasFirstNode == null )
          setLastChild( lastAddedNode );
        // else previous last is still the last one
    }

********* end code *****************

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to