Changed cell and area ref Ptgs to allow creation using CellReference and AreaReference

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@761553 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Josh Micich 2009-04-03 07:41:29 +00:00
parent 798d7e0098
commit 0b3c4a8e74
8 changed files with 40 additions and 44 deletions

View File

@ -17,6 +17,7 @@
package org.apache.poi.hssf.record.formula;
import org.apache.poi.ss.util.AreaReference;
import org.apache.poi.util.LittleEndianInput;
import org.apache.poi.util.LittleEndianOutput;
@ -29,6 +30,9 @@ public abstract class Area2DPtgBase extends AreaPtgBase {
protected Area2DPtgBase(int firstRow, int lastRow, int firstColumn, int lastColumn, boolean firstRowRelative, boolean lastRowRelative, boolean firstColRelative, boolean lastColRelative) {
super(firstRow, lastRow, firstColumn, lastColumn, firstRowRelative, lastRowRelative, firstColRelative, lastColRelative);
}
protected Area2DPtgBase(AreaReference ar) {
super(ar);
}
protected Area2DPtgBase(LittleEndianInput in) {
readCoordinates(in);
@ -41,10 +45,6 @@ public abstract class Area2DPtgBase extends AreaPtgBase {
writeCoordinates(out);
}
public Area2DPtgBase(String arearef) {
super(arearef);
}
public final int getSize() {
return SIZE;
}

View File

@ -17,6 +17,7 @@
package org.apache.poi.hssf.record.formula;
import org.apache.poi.hssf.util.AreaReference;
import org.apache.poi.ss.formula.ExternSheetReferenceToken;
import org.apache.poi.ss.formula.FormulaRenderingWorkbook;
import org.apache.poi.ss.formula.WorkbookDependentFormula;
@ -30,7 +31,6 @@ import org.apache.poi.util.LittleEndianOutput;
* @author Libin Roman (Vista Portal LDT. Developer)
* @author avik
* @author Jason Height (jheight at chariot dot net dot au)
* @version 1.0-pre
*/
public final class Area3DPtg extends AreaPtgBase implements WorkbookDependentFormula, ExternSheetReferenceToken {
public final static byte sid = 0x3b;
@ -39,9 +39,9 @@ public final class Area3DPtg extends AreaPtgBase implements WorkbookDependentFor
private int field_1_index_extern_sheet;
public Area3DPtg( String arearef, int externIdx ) {
super(arearef);
setExternSheetIndex( externIdx );
public Area3DPtg(String arearef, int externIdx) {
super(new AreaReference(arearef));
setExternSheetIndex(externIdx);
}
public Area3DPtg(LittleEndianInput in) {
@ -56,6 +56,11 @@ public final class Area3DPtg extends AreaPtgBase implements WorkbookDependentFor
setExternSheetIndex(externalSheetIndex);
}
public Area3DPtg(AreaReference arearef, int externIdx) {
super(arearef);
setExternSheetIndex(externIdx);
}
public String toString() {
StringBuffer sb = new StringBuffer();
sb.append(getClass().getName());

View File

@ -17,6 +17,7 @@
package org.apache.poi.hssf.record.formula;
import org.apache.poi.ss.util.AreaReference;
import org.apache.poi.util.LittleEndianInput;
/**
@ -33,7 +34,10 @@ public final class AreaPtg extends Area2DPtgBase {
super(in);
}
public AreaPtg(String arearef) {
super(arearef);
super(new AreaReference(arearef));
}
public AreaPtg(AreaReference areaRef) {
super(areaRef);
}
protected byte getSid() {
return sid;

View File

@ -55,8 +55,7 @@ public abstract class AreaPtgBase extends OperandPtg implements AreaI {
// do nothing
}
protected AreaPtgBase(String arearef) {
AreaReference ar = new AreaReference(arearef);
protected AreaPtgBase(AreaReference ar) {
CellReference firstCell = ar.getFirstCell();
CellReference lastCell = ar.getLastCell();
setFirstRow(firstCell.getRow());

View File

@ -17,6 +17,7 @@
package org.apache.poi.hssf.record.formula;
import org.apache.poi.ss.util.CellReference;
import org.apache.poi.util.LittleEndianInput;
import org.apache.poi.util.LittleEndianOutput;
@ -26,13 +27,6 @@ import org.apache.poi.util.LittleEndianOutput;
abstract class Ref2DPtgBase extends RefPtgBase {
private final static int SIZE = 5;
/**
* Takes in a String representation of a cell reference and fills out the
* numeric fields.
*/
protected Ref2DPtgBase(String cellref) {
super(cellref);
}
protected Ref2DPtgBase(int row, int column, boolean isRowRelative, boolean isColumnRelative) {
setRow(row);
@ -45,6 +39,10 @@ abstract class Ref2DPtgBase extends RefPtgBase {
readCoordinates(in);
}
protected Ref2DPtgBase(CellReference cr) {
super(cr);
}
public void write(LittleEndianOutput out) {
out.writeByte(getSid() + getPtgClass());
writeCoordinates(out);

View File

@ -30,7 +30,6 @@ import org.apache.poi.util.LittleEndianOutput;
* REFERENCE: <P>
* @author Libin Roman (Vista Portal LDT. Developer)
* @author Jason Height (jheight at chariot dot net dot au)
* @version 1.0-pre
*/
public final class Ref3DPtg extends RefPtgBase implements WorkbookDependentFormula, ExternSheetReferenceToken {
public final static byte sid = 0x3a;
@ -38,8 +37,6 @@ public final class Ref3DPtg extends RefPtgBase implements WorkbookDependentFormu
private final static int SIZE = 7; // 6 + 1 for Ptg
private int field_1_index_extern_sheet;
/** Creates new AreaPtg */
public Ref3DPtg() {}
public Ref3DPtg(LittleEndianInput in) {
field_1_index_extern_sheet = in.readShort();
@ -47,11 +44,11 @@ public final class Ref3DPtg extends RefPtgBase implements WorkbookDependentFormu
}
public Ref3DPtg(String cellref, int externIdx ) {
CellReference c= new CellReference(cellref);
setRow(c.getRow());
setColumn(c.getCol());
setColRelative(!c.isColAbsolute());
setRowRelative(!c.isRowAbsolute());
this(new CellReference(cellref), externIdx);
}
public Ref3DPtg(CellReference c, int externIdx) {
super(c);
setExternSheetIndex(externIdx);
}
@ -66,8 +63,8 @@ public final class Ref3DPtg extends RefPtgBase implements WorkbookDependentFormu
return sb.toString();
}
public void write(LittleEndianOutput out) {
out.writeByte(sid + getPtgClass());
public void write(LittleEndianOutput out) {
out.writeByte(sid + getPtgClass());
out.writeShort(getExternSheetIndex());
writeCoordinates(out);
}

View File

@ -17,6 +17,7 @@
package org.apache.poi.hssf.record.formula;
import org.apache.poi.ss.util.CellReference;
import org.apache.poi.util.LittleEndianInput;
/**
@ -32,7 +33,7 @@ public final class RefPtg extends Ref2DPtgBase {
* numeric fields.
*/
public RefPtg(String cellref) {
super(cellref);
super(new CellReference(cellref));
}
public RefPtg(int row, int column, boolean isRowRelative, boolean isColumnRelative) {
@ -43,6 +44,10 @@ public final class RefPtg extends Ref2DPtgBase {
super(in);
}
public RefPtg(CellReference cr) {
super(cr);
}
protected byte getSid() {
return sid;
}

View File

@ -17,7 +17,7 @@
package org.apache.poi.hssf.record.formula;
import org.apache.poi.hssf.util.CellReference;
import org.apache.poi.ss.util.CellReference;
import org.apache.poi.util.BitField;
import org.apache.poi.util.BitFieldFactory;
import org.apache.poi.util.LittleEndianInput;
@ -48,26 +48,14 @@ public abstract class RefPtgBase extends OperandPtg {
// Required for clone methods
}
/**
* Takes in a String representation of a cell reference and fills out the
* numeric fields.
*/
protected RefPtgBase(String cellref) {
CellReference c = new CellReference(cellref);
protected RefPtgBase(CellReference c) {
setRow(c.getRow());
setColumn(c.getCol());
setColRelative(!c.isColAbsolute());
setRowRelative(!c.isRowAbsolute());
}
protected RefPtgBase(int row, int column, boolean isRowRelative, boolean isColumnRelative) {
setRow(row);
setColumn(column);
setRowRelative(isRowRelative);
setColRelative(isColumnRelative);
}
protected final void readCoordinates(LittleEndianInput in) {
protected final void readCoordinates(LittleEndianInput in) {
field_1_row = in.readUShort();
field_2_col = in.readUShort();
}