You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "Charles Simon (JIRA)" <ji...@apache.org> on 2011/06/14 21:08:47 UTC
[jira] [Commented] (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:comment-tabpanel&focusedCommentId=13049344#comment-13049344 ]
Charles Simon commented on PDFBOX-996:
--------------------------------------
Are you waiting for a DIFF from me? I believe that it will be just as easy to copy the code from this JIRA.
And like I said in my previous comment. I grant full rights to the code to Apache Software Foundation.
> 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