You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by jo...@locus.apache.org on 2000/06/28 19:48:16 UTC

cvs commit: xml-fop/src/org/apache/fop/datatypes IDNode.java IDReferences.java

jordan      00/06/28 10:48:16

  Modified:    src/org/apache/fop/datatypes IDNode.java IDReferences.java
  Log:
  Now handles page number citations
  Now handles x position
  
  Revision  Changes    Path
  1.2       +39 -11    xml-fop/src/org/apache/fop/datatypes/IDNode.java
  
  Index: IDNode.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/datatypes/IDNode.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- IDNode.java	2000/06/21 01:20:41	1.1
  +++ IDNode.java	2000/06/28 17:48:14	1.2
  @@ -1,4 +1,4 @@
  -/*-- $Id: IDNode.java,v 1.1 2000/06/21 01:20:41 jordan Exp $ -- 
  +/*-- $Id: IDNode.java,v 1.2 2000/06/28 17:48:14 jordan Exp $ -- 
   
    ============================================================================
                      The Apache Software License, Version 1.1
  @@ -64,9 +64,11 @@
           internalLinkGoTo;
   
       private int 
  -        yPosition=0;  // position on page
  +    pageNumber = -1,
  +    xPosition = 0,  // x position on page
  +    yPosition = 0;  // y position on page
   
  -    
  +
       /**
        * Constructor for IDNode
        * 
  @@ -79,6 +81,28 @@
   
   
       /**
  +     * Sets the page number for this node
  +     * 
  +     * @param number page number of node
  +     */
  +    protected void setPageNumber(int number)
  +    {        
  +        pageNumber=number;     
  +    }
  +
  +
  +    /**
  +     * Returns the page number of this node
  +     * 
  +     * @return page number of this node
  +     */
  +    protected String getPageNumber()
  +    {             
  +        return(pageNumber != -1)?new Integer(pageNumber).toString():null;
  +    }
  +
  +
  +    /**
        * creates a new GoTo object for an internal link
        * 
        * @param objectNumber
  @@ -86,7 +110,7 @@
        */
       protected void createInternalLinkGoTo(int objectNumber)
       {
  -        if(internalLinkGoToPageReference==null)
  +        if ( internalLinkGoToPageReference==null )
           {
               internalLinkGoTo = new PDFGoTo(objectNumber,null);
           }
  @@ -95,8 +119,9 @@
               internalLinkGoTo = new PDFGoTo(objectNumber,internalLinkGoToPageReference);
           }
   
  -        if(yPosition!=0)
  +        if ( xPosition!=0 ) // if the position is known (if x is known, then y is known)
           {
  +            internalLinkGoTo.setXPosition(xPosition);
               internalLinkGoTo.setYPosition(yPosition);
           }
           
  @@ -113,7 +138,7 @@
        */
       protected void setInternalLinkGoToPageReference(String pageReference)
       {        
  -        if(internalLinkGoTo !=null)
  +        if ( internalLinkGoTo !=null )
           {
               internalLinkGoTo.setPageReference(pageReference);                 
           }
  @@ -173,18 +198,21 @@
   
   
        /**
  -      * Sets the x position of this node
  +     * Sets the position of this node
         * 
         * @param x      the x position
  +     * @param y      the y position
         */
  -     protected void setYPosition(int y)
  -     {
  -         if(internalLinkGoTo !=null)
  -        {            
  +    protected void setPosition(int x, int y)
  +    {
  +        if ( internalLinkGoTo !=null )
  +        {
  +            internalLinkGoTo.setXPosition(x);
               internalLinkGoTo.setYPosition(y);
           }
           else
           {
  +            xPosition=x;
               yPosition=y;
           }         
        }
  
  
  
  1.3       +82 -27    xml-fop/src/org/apache/fop/datatypes/IDReferences.java
  
  Index: IDReferences.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/datatypes/IDReferences.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- IDReferences.java	2000/06/21 23:40:41	1.2
  +++ IDReferences.java	2000/06/28 17:48:14	1.3
  @@ -1,4 +1,4 @@
  -/*-- $Id: IDReferences.java,v 1.2 2000/06/21 23:40:41 jordan Exp $ -- 
  +/*-- $Id: IDReferences.java,v 1.3 2000/06/28 17:48:14 jordan Exp $ -- 
   
    ============================================================================
                      The Apache Software License, Version 1.1
  @@ -64,8 +64,9 @@
   
   
   public class IDReferences {
  -    private Hashtable idReferences;
  -    private Vector idValidation;
  +    private Hashtable 
  +    idReferences,
  +    idValidation;    
   
       final static int ID_PADDING = 5000; // space to add before id y position
   
  @@ -75,12 +76,12 @@
       public IDReferences()
       {
           idReferences = new Hashtable();
  -        idValidation = new Vector();
  +        idValidation = new Hashtable();
       }
   
   
       /**
  -     * Initializes the specified id.  This should be called everytime an id is encountered
  +     * Creates and configures the specified id.  
        * 
        * @param id     The id to initialize
        * @param area   The area where this id was encountered
  @@ -88,6 +89,20 @@
        */
       public void initializeID(String id, Area area) throws FOPException
       {
  +        createID(id,area);
  +        configureID(id,area);        
  +    }
  +
  +
  +    /**
  +     * Creates id entry
  +     * 
  +     * @param id     The id to create
  +     * @param area   The area where this id was encountered
  +     * @exception FOPException
  +     */
  +    public void createID(String id, Area area) throws FOPException
  +    {
           if ( id!=null && !id.equals("") ) {
               if ( doesIDExist(id) ) {
                   throw new FOPException("The id \""+id+"\" already exists in this document");
  @@ -95,23 +110,38 @@
               else {
                   createNewId(id);
                   removeFromIdValidationList(id);                 
  -                setYPosition(id,area.getPage().getBody().getYPosition() - area.getAbsoluteHeight()+ID_PADDING);                    
  -                area.getPage().addToIDList(id);                                    
               }
  +            
           }
       }
   
  +
       /**
  +     * Configures this id
  +     * 
  +     * @param id     The id to configure
  +     * @param area   The area where the id was encountered
  +     */
  +    public void configureID(String id, Area area)
  +    {
  +        if ( id!=null && !id.equals("") ) {
  +            setPosition(id,area.getPage().getBody().getXPosition()-ID_PADDING,area.getPage().getBody().getYPosition() - area.getAbsoluteHeight()+ID_PADDING);                                                
  +            setPageNumber(id,area.getPage().getNumber());
  +                area.getPage().addToIDList(id);                                    
  +            }
  +        }
  +
  +    /**
        * Adds id to validation list to be validated .  This should be used if it is unsure whether the id is valid
        * 
        * @param id     id to be added
        */
       public void addToIdValidationList(String id)
       {     
  -        idValidation.addElement(id);
  +        idValidation.put(id,"");
       }
  +
   
  -    
   
       /**
        * Removes id from validation list. This should be used if the id has been determined to be valid
  @@ -120,7 +150,7 @@
        */
       public void removeFromIdValidationList(String id)
       {        
  -        idValidation.removeElement(id);
  +        idValidation.remove(id);     
       }
   
       /**
  @@ -130,7 +160,7 @@
        */
       public boolean isEveryIdValid()
       {
  -        return (idValidation.size()==0);
  +        return(idValidation.size()==0);
       }
   
   
  @@ -142,16 +172,8 @@
        */
       public String getNextInvalidId()
       {
  -        String id;
  -        try
  -        {            
  -            id = idValidation.firstElement().toString();
  -        }
  -        catch(NoSuchElementException nsee)
  -        {            
  -            id=null;    // should probably report error
  -        }
  -        return id;
  +        Enumeration enum=idValidation.keys();
  +        return enum.nextElement().toString();                
       }
   
   
  @@ -253,16 +275,49 @@
       }
   
   
  +    /**
  +     * Sets the page number for the specified id
  +     * 
  +     * @param id     The id whose page number is being set
  +     * @param pageNumber The page number of the specified id
  +     */
  +    public void setPageNumber(String id, int pageNumber)
  +    {        
  +        IDNode node=(IDNode)idReferences.get(id);                
  +        node.setPageNumber(pageNumber);        
  +    }
  +
  +
  +    /**
  +     * Returns the page number where the specified id is found
  +     * 
  +     * @param id     The id whose page number to return
  +     * @return the page number of the id, or null if the id does not exist
  +     */
  +    public String getPageNumber(String id)
  +    {        
  +        if ( doesIDExist(id) ) {
  +            IDNode node=(IDNode)idReferences.get(id);            
  +            return node.getPageNumber();          
  +        }
  +        else {
  +            addToIdValidationList(id);
  +            return null;
  +        }
  +    }
  +
  +
       /**
  -     * Sets the x position of specified id
  +     * Sets the x and y position of specified id
        * 
  -     * @param id     the id whose x position is to be set
  +     * @param id     the id whose position is to be set
  +     * @param x      x position of id
        * @param y      y position of id
        */
  -    public void setYPosition(String id, int y)
  +    public void setPosition(String id, int x, int y)
       {
           IDNode node=(IDNode)idReferences.get(id);
  -        node.setYPosition(y);
  -     }
  -       
  +        node.setPosition(x,y);        
  +    }
  +
   }