Package net.sf.jpluck.plucker

Source Code of net.sf.jpluck.plucker.TableRecord

package net.sf.jpluck.plucker;

import net.sf.jpluck.palm.PdbOutputStream;
import java.awt.Color;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class TableRecord extends TextRecord {
    private int borderWidth;
    private Color linkColor;
    private Color borderColor;

    private List rowList = new ArrayList();

    public TableRecord(String uri, int borderWidth, Color borderColor, Color linkColor) {
        super(uri);
        outputEncoding="Windows-1252"; // Fix hard-coded encoding
        this.borderWidth = borderWidth;
        this.borderColor = borderColor;
        this.linkColor = linkColor;
    }

    public TableRecord(String uri, int borderWidth, Color borderColor) {
        this(uri, borderWidth, borderColor, null);
    }

    public TableRecord(String uri, int borderWidth) {
        this(uri, borderWidth, Color.BLACK, null);
    }

    protected Paragraph[] writeData(PdbOutputStream out) throws IOException {
        /*if (rowList.isEmpty()) {
            throw new IllegalStateException("No rows in table.");
        }*/
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        for (Iterator iterator = rowList.iterator(); iterator.hasNext();) {
            TableRow tableRow = (TableRow) iterator.next();
            tableRow.write(new PdbOutputStream(baos));
        }
        byte[] data = baos.toByteArray();
        out.writeShort(data.length);
        out.writeShort(getColumnCount());
        out.writeShort(rowList.size());
        out.writeByte(4); // TODO: Add bit depth
        out.writeByte(borderWidth);
        out.writeByte(0);
        out.writeByte(borderColor.getRed());
        out.writeByte(borderColor.getGreen());
        out.writeByte(borderColor.getBlue());
        // TODO: Obtain link color from text
        Color linkColor = this.linkColor;
        if (linkColor == null) {
            linkColor = document.getDefaultLinkColor();
        }
        if (linkColor == null) {
            linkColor = Color.BLACK;
        }
        out.writeByte(0);
        out.writeByte(linkColor.getRed());
        out.writeByte(linkColor.getGreen());
        out.writeByte(linkColor.getBlue());
        out.write(data);
        return new Paragraph[0];
    }

    public int getColumnCount() {
        int columnCount = 0;
        for (Iterator iterator = rowList.iterator(); iterator.hasNext();) {
            TableRow tableRow = (TableRow) iterator.next();
            if (tableRow.getCellCount() > columnCount) {
                columnCount = tableRow.getCellCount();
            }
        }
        return columnCount;
    }

    public int getRowCount() {
        return rowList.size();
    }

    protected int getType() {
        return TABLE;
    }
   
    public TableRow addRow() {
      TableRow row = new TableRow(this);
      rowList.add(row);
      return row;
    }
}
TOP

Related Classes of net.sf.jpluck.plucker.TableRecord

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.