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
*
}
+ /**
+ * 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
*
*/
protected void createInternalLinkGoTo(int objectNumber)
{
- if(internalLinkGoToPageReference==null)
+ if ( internalLinkGoToPageReference==null )
{
internalLinkGoTo = new PDFGoTo(objectNumber,null);
}
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);
}
*/
protected void setInternalLinkGoToPageReference(String pageReference)
{
- if(internalLinkGoTo !=null)
+ if ( internalLinkGoTo !=null )
{
internalLinkGoTo.setPageReference(pageReference);
}
/**
- * 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;
}
}
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
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
* @exception FOPException
*/
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) ) {
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
*
*/
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
*/
public void removeFromIdValidationList(String id)
{
- idValidation.removeElement(id);
+ idValidation.remove(id);
}
/**
*/
public boolean isEveryIdValid()
{
- return (idValidation.size()==0);
+ return(idValidation.size()==0);
}
*/
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();
}
/**
- * Sets the x position of specified id
+ * 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 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);
+ }
+
}