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 0e7da90f77
commit b558d99132
8 changed files with 40 additions and 44 deletions

View File

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

View File

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

View File

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

View File

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

View File

@ -17,6 +17,7 @@
package org.apache.poi.hssf.record.formula; 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.LittleEndianInput;
import org.apache.poi.util.LittleEndianOutput; import org.apache.poi.util.LittleEndianOutput;
@ -26,13 +27,6 @@ import org.apache.poi.util.LittleEndianOutput;
abstract class Ref2DPtgBase extends RefPtgBase { abstract class Ref2DPtgBase extends RefPtgBase {
private final static int SIZE = 5; 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) { protected Ref2DPtgBase(int row, int column, boolean isRowRelative, boolean isColumnRelative) {
setRow(row); setRow(row);
@ -45,6 +39,10 @@ abstract class Ref2DPtgBase extends RefPtgBase {
readCoordinates(in); readCoordinates(in);
} }
protected Ref2DPtgBase(CellReference cr) {
super(cr);
}
public void write(LittleEndianOutput out) { public void write(LittleEndianOutput out) {
out.writeByte(getSid() + getPtgClass()); out.writeByte(getSid() + getPtgClass());
writeCoordinates(out); writeCoordinates(out);

View File

@ -30,7 +30,6 @@ import org.apache.poi.util.LittleEndianOutput;
* REFERENCE: <P> * REFERENCE: <P>
* @author Libin Roman (Vista Portal LDT. Developer) * @author Libin Roman (Vista Portal LDT. Developer)
* @author Jason Height (jheight at chariot dot net dot au) * @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 class Ref3DPtg extends RefPtgBase implements WorkbookDependentFormula, ExternSheetReferenceToken {
public final static byte sid = 0x3a; 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 final static int SIZE = 7; // 6 + 1 for Ptg
private int field_1_index_extern_sheet; private int field_1_index_extern_sheet;
/** Creates new AreaPtg */
public Ref3DPtg() {}
public Ref3DPtg(LittleEndianInput in) { public Ref3DPtg(LittleEndianInput in) {
field_1_index_extern_sheet = in.readShort(); 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 ) { public Ref3DPtg(String cellref, int externIdx ) {
CellReference c= new CellReference(cellref); this(new CellReference(cellref), externIdx);
setRow(c.getRow()); }
setColumn(c.getCol());
setColRelative(!c.isColAbsolute()); public Ref3DPtg(CellReference c, int externIdx) {
setRowRelative(!c.isRowAbsolute()); super(c);
setExternSheetIndex(externIdx); setExternSheetIndex(externIdx);
} }

View File

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

View File

@ -17,7 +17,7 @@
package org.apache.poi.hssf.record.formula; 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.BitField;
import org.apache.poi.util.BitFieldFactory; import org.apache.poi.util.BitFieldFactory;
import org.apache.poi.util.LittleEndianInput; import org.apache.poi.util.LittleEndianInput;
@ -48,25 +48,13 @@ public abstract class RefPtgBase extends OperandPtg {
// Required for clone methods // Required for clone methods
} }
/** protected RefPtgBase(CellReference c) {
* Takes in a String representation of a cell reference and fills out the
* numeric fields.
*/
protected RefPtgBase(String cellref) {
CellReference c = new CellReference(cellref);
setRow(c.getRow()); setRow(c.getRow());
setColumn(c.getCol()); setColumn(c.getCol());
setColRelative(!c.isColAbsolute()); setColRelative(!c.isColAbsolute());
setRowRelative(!c.isRowAbsolute()); 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_1_row = in.readUShort();
field_2_col = in.readUShort(); field_2_col = in.readUShort();