/*
 * Copyright (c) 2015 Raytheon BBN Technologies Corp. All rights reserved.
 */

package org.apache.poi.xdgf.usermodel;

import org.apache.poi.POIXMLException;
import org.apache.poi.util.Internal;
import org.apache.poi.xdgf.geom.Dimension2dDouble;

import com.microsoft.schemas.office.visio.x2012.main.PageType;

/**
 * Provides the API to work with an underlying page
 */
public class XDGFPage {

	PageType _page;
	XDGFPageContents _content;
	XDGFPages _pages;
	XDGFSheet _pageSheet = null;
	
	public XDGFPage(PageType page, XDGFPageContents content, XDGFDocument document, XDGFPages pages) {
		_page = page;
		_content = content;
		_pages = pages;
		content.setPage(this);
		
		if (page.isSetPageSheet())
			_pageSheet = new XDGFPageSheet(page.getPageSheet(),document);
	}
	
	@Internal
	PageType getXmlObject() {
		return _page;
	}
	
	public long getID() {
		return _page.getID();
	}
	
	public String getName() {
		return _page.getName();
	}
	
	public XDGFPageContents getContent() {
		return _content;
	}
	
	public XDGFSheet getPageSheet() {
		return _pageSheet;
	}
	
	public long getPageNumber() {
		return _pages.getPageList().indexOf(this) + 1;
	}
	
	public Dimension2dDouble getPageSize() {
		XDGFCell w = _pageSheet.getCell("PageWidth");
		XDGFCell h = _pageSheet.getCell("PageHeight");
		
		if (w == null || h == null)
			throw new POIXMLException("Cannot determine page size");
		
		return new Dimension2dDouble(Double.parseDouble(w.getValue()),
									 Double.parseDouble(h.getValue()));
	}
}

@@ -116,16 +116,81 @@
 model;%0A%0A
+import java.awt.geom.Point2D;%0Aimport java.awt.geom.Rectangle2D;%0A%0A
 import o
@@ -220,16 +220,16 @@
 eption;%0A
-
 import o
@@ -821,16 +821,17 @@
 Sheet(),
+ 
 document
@@ -1213,24 +1213,49 @@
 ) + 1;%0A%09%7D%0A%09%0A
+%09// height/width of page%0A
 %09public Dime
@@ -1542,16 +1542,16 @@
 lue()),%0A
-
 %09%09%09%09%09%09%09%09
@@ -1590,10 +1590,747 @@
 )));%0A%09%7D%0A
+%09%0A%09// origin of coordinate system%0A%09public Point2D.Double getPageOffset() %7B%0A%09%09XDGFCell xoffcell = _pageSheet.getCell(%22XRulerOrigin%22);%0A%09%09XDGFCell yoffcell = _pageSheet.getCell(%22YRulerOrigin%22);%0A%09%09%0A%09%09double xoffset = 0;%0A%09%09double yoffset = 0;%0A%09%09%0A%09%09if (xoffcell != null)%0A%09%09%09xoffset = Double.parseDouble(xoffcell.getValue());%0A%09%09%0A%09%09if (xoffcell != null)%0A%09%09%09yoffset = Double.parseDouble(yoffcell.getValue());%0A%09%09%0A%09%09return new Point2D.Double(xoffset, yoffset);%0A%09%7D%0A%09%0A%09// bounding box of page%0A%09public Rectangle2D getBoundingBox() %7B%0A%09%09Dimension2dDouble sz = getPageSize();%0A%09%09Point2D.Double offset = getPageOffset();%0A%09%09%0A%09%09return new Rectangle2D.Double(-offset.getX(),%0A%09%09%09%09%09%09%09%09%09  -offset.getY(),%0A%09%09%09%09%09%09%09%09%09  sz.getWidth(),%0A%09%09%09%09%09%09%09%09%09  sz.getHeight());%0A%09%7D%0A
 %7D%0A

Add more things to XDGFPage