001: package com.xoetrope.export.pdf;
002:
003: import com.xoetrope.export.FragmentBlock;
004: import com.xoetrope.export.RowBlock;
005: import com.xoetrope.export.XMLHelper;
006: import java.awt.Point;
007: import java.io.Reader;
008: import java.util.Vector;
009: import net.xoetrope.xml.XmlElement;
010: import net.xoetrope.xml.XmlSource;
011: import net.xoetrope.xui.XProject;
012: import net.xoetrope.xui.XProjectManager;
013:
014: /**
015: *
016: * <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
017: * the GNU Public License (GPL), please see license.txt for more details. If
018: * you make commercial use of this software you must purchase a commercial
019: * license from Xoetrope.</p>
020: * <p> $Revision: 1.2 $</p>
021: */
022: public class PdfFragmentBlock extends FragmentBlock {
023: int row, col;
024: int offsetX, offsetY;
025: PdfExporter PdfExporter;
026:
027: /**
028: * The owner project and the context in which this object operates.
029: */
030: protected XProject currentProject = XProjectManager
031: .getCurrentProject();
032:
033: public PdfFragmentBlock(PdfExporter exporter) {
034: PdfExporter = exporter;
035: }
036:
037: public void processFragment(String fragmentName) {
038: try {
039: Reader reader = currentProject.getBufferedReader(
040: fragmentName + "_Pdf.xml", null);
041: XmlElement ele = XmlSource.read(reader);
042: Vector rows = ele.getChildren();
043: PdfTableBlock tableExporter = (PdfTableBlock) PdfExporter
044: .getTableBlock();
045:
046: int numRows = rows.size();
047: for (int row = 0; row < numRows; row++) {
048: XmlElement rowEle = (XmlElement) rows.get(row);
049: Vector cells = rowEle.getChildren();
050: RowBlock rowBlockItem = tableExporter.addRow();
051: blocks.add(rowBlockItem);
052: int numCells = cells.size();
053: for (int cell = 0; cell < numCells; cell++) {
054: XmlElement cellEle = (XmlElement) cells.get(cell);
055: String value = cellEle.getAttribute("value");
056: String style = cellEle.getAttribute("style");
057: int offsetX = XMLHelper.getAttribAsInt(cellEle,
058: "offsetx", 1);
059: int offsetY = XMLHelper.getAttribAsInt(cellEle,
060: "offsety", 1);
061: int colspan = XMLHelper.getAttribAsInt(cellEle,
062: "colspan", 1);
063: int rowspan = XMLHelper.getAttribAsInt(cellEle,
064: "rowspan", 1);
065: rowBlockItem
066: .addCell(value, style, colspan, rowspan);
067: }
068: }
069: } catch (Exception e) {
070: e.printStackTrace();
071: }
072: }
073:
074: public void setOffset(int x, int y) {
075: offsetX = x;
076: offsetY = y;
077: }
078:
079: public Point getOffset() {
080: return new Point(offsetX, offsetY);
081: }
082:
083: public void setRow(int value) {
084: row = value;
085: }
086:
087: public void setColumn(int value) {
088: col = value;
089: }
090:
091: public int getRow() {
092: return row;
093: }
094:
095: public int getColumn() {
096: return col;
097: }
098:
099: public int getColumnCount() {
100: return col + offsetX;
101: }
102:
103: public int getRowCount() {
104: return row + offsetY;
105: }
106:
107: }
|