You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "Tilman Hausherr (JIRA)" <ji...@apache.org> on 2015/02/14 13:19:11 UTC

[jira] [Closed] (PDFBOX-996) need to insert a child as the first child of an outline but you can only append to the outline.

     [ https://issues.apache.org/jira/browse/PDFBOX-996?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Tilman Hausherr closed PDFBOX-996.
----------------------------------
       Resolution: Duplicate
    Fix Version/s: 2.0.0

Done in PDFBOX-2677.

> 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: Writing
>    Affects Versions: 1.5.0
>            Reporter: Charles Simon
>             Fix For: 2.0.0
>
>
> 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.
> {code}
> ********* 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 *****************
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org