mirror of https://github.com/apache/poi.git
code refactoring
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/gsoc2012@1368211 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
7305869f20
commit
3c170100d7
|
@ -1482,6 +1482,7 @@ public final class InternalSheet {
|
|||
* if none currently exist
|
||||
* @param drawingManager The DrawingManager2 for our workbook
|
||||
* @param createIfMissing Should one be created if missing?
|
||||
* @return location of EscherAggregate record. if no EscherAggregate record is found return -1
|
||||
*/
|
||||
public int aggregateDrawingRecords(DrawingManager2 drawingManager, boolean createIfMissing) {
|
||||
int loc = findFirstRecordLocBySid(DrawingRecord.sid);
|
||||
|
|
|
@ -306,7 +306,7 @@ public final class EscherAggregate extends AbstractEscherHolderRecord {
|
|||
/**
|
||||
* list of "tail" records that need to be serialized after all drawing group records
|
||||
*/
|
||||
private Map<Integer, NoteRecord> tailRec = new HashMap<Integer, NoteRecord>();
|
||||
private Map<Integer, NoteRecord> tailRec = new HashMap<Integer, NoteRecord>();
|
||||
|
||||
public EscherAggregate() {
|
||||
buildBaseTree();
|
||||
|
@ -517,9 +517,9 @@ public final class EscherAggregate extends AbstractEscherHolderRecord {
|
|||
// write records that need to be serialized after all drawing group records
|
||||
Map<Integer, NoteRecord> tailCopy = new HashMap<Integer, NoteRecord>(tailRec);
|
||||
// at first we should save records in correct order which were already in the file during EscherAggregate.createAggregate()
|
||||
for (Integer id : _tailIds){
|
||||
for (Integer id : _tailIds) {
|
||||
NoteRecord note = tailCopy.get(id);
|
||||
if (null != note){
|
||||
if (null != note) {
|
||||
pos += note.serialize(pos, data);
|
||||
tailCopy.remove(id);
|
||||
}
|
||||
|
@ -539,14 +539,18 @@ public final class EscherAggregate extends AbstractEscherHolderRecord {
|
|||
//First record in drawing layer MUST be DrawingRecord
|
||||
if (writtenEscherBytes + drawingData.length > RecordInputStream.MAX_RECORD_DATA_SIZE && i != 1) {
|
||||
for (int j = 0; j < drawingData.length; j += RecordInputStream.MAX_RECORD_DATA_SIZE) {
|
||||
ContinueRecord drawing = new ContinueRecord(Arrays.copyOfRange(drawingData, j, Math.min(j + RecordInputStream.MAX_RECORD_DATA_SIZE, drawingData.length)));
|
||||
byte[] buf = new byte[Math.min(RecordInputStream.MAX_RECORD_DATA_SIZE, drawingData.length - j)];
|
||||
System.arraycopy(drawingData, j, buf, 0, Math.min(RecordInputStream.MAX_RECORD_DATA_SIZE, drawingData.length - j));
|
||||
ContinueRecord drawing = new ContinueRecord(buf);
|
||||
temp += drawing.serialize(pos + temp, data);
|
||||
}
|
||||
} else {
|
||||
for (int j = 0; j < drawingData.length; j += RecordInputStream.MAX_RECORD_DATA_SIZE) {
|
||||
if (j == 0) {
|
||||
DrawingRecord drawing = new DrawingRecord();
|
||||
drawing.setData(Arrays.copyOfRange(drawingData, j, Math.min(j + RecordInputStream.MAX_RECORD_DATA_SIZE, drawingData.length)));
|
||||
byte[] buf = new byte[Math.min(RecordInputStream.MAX_RECORD_DATA_SIZE, drawingData.length - j)];
|
||||
System.arraycopy(drawingData, j, buf, 0, Math.min(RecordInputStream.MAX_RECORD_DATA_SIZE, drawingData.length - j));
|
||||
drawing.setData(buf);
|
||||
temp += drawing.serialize(pos + temp, data);
|
||||
} else {
|
||||
ContinueRecord drawing = new ContinueRecord(Arrays.copyOfRange(drawingData, j, Math.min(j + RecordInputStream.MAX_RECORD_DATA_SIZE, drawingData.length)));
|
||||
|
@ -628,7 +632,7 @@ public final class EscherAggregate extends AbstractEscherHolderRecord {
|
|||
return shapeToObj.put(r, objRecord);
|
||||
}
|
||||
|
||||
public void removeShapeToObjRecord(EscherRecord rec){
|
||||
public void removeShapeToObjRecord(EscherRecord rec) {
|
||||
shapeToObj.remove(rec);
|
||||
}
|
||||
|
||||
|
@ -667,7 +671,7 @@ public final class EscherAggregate extends AbstractEscherHolderRecord {
|
|||
dgContainer.setRecordId(EscherContainerRecord.DG_CONTAINER);
|
||||
dgContainer.setOptions((short) 0x000F);
|
||||
EscherDgRecord dg = new EscherDgRecord();
|
||||
dg.setRecordId( EscherDgRecord.RECORD_ID );
|
||||
dg.setRecordId(EscherDgRecord.RECORD_ID);
|
||||
short dgId = 1;
|
||||
dg.setOptions((short) (dgId << 4));
|
||||
dg.setNumShapes(0);
|
||||
|
@ -702,7 +706,7 @@ public final class EscherAggregate extends AbstractEscherHolderRecord {
|
|||
dg.setOptions((short) (dgId << 4));
|
||||
}
|
||||
|
||||
public void setMainSpRecordId(int shapeId){
|
||||
public void setMainSpRecordId(int shapeId) {
|
||||
EscherContainerRecord dgContainer = getEscherContainer();
|
||||
EscherContainerRecord spContainer = (EscherContainerRecord) dgContainer.getChildById(EscherContainerRecord.SPGR_CONTAINER).getChild(0);
|
||||
EscherSpRecord sp = (EscherSpRecord) spContainer.getChildById(EscherSpRecord.RECORD_ID);
|
||||
|
@ -757,11 +761,11 @@ public final class EscherAggregate extends AbstractEscherHolderRecord {
|
|||
return tailRec.get(cod.getObjectId());
|
||||
}
|
||||
|
||||
public void addTailRecord(NoteRecord note){
|
||||
public void addTailRecord(NoteRecord note) {
|
||||
tailRec.put(note.getShapeId(), note);
|
||||
}
|
||||
|
||||
public void removeTailRecord(NoteRecord note){
|
||||
public void removeTailRecord(NoteRecord note) {
|
||||
tailRec.remove(note.getShapeId());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,4 +51,6 @@ public interface HSSFShapeContainer extends Iterable<HSSFShape>
|
|||
public int getX2();
|
||||
|
||||
public int getY2();
|
||||
|
||||
public boolean removeShape(HSSFShape shape);
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,40 @@
|
|||
package org.apache.poi.hssf.usermodel;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.apache.poi.ddf.EscherDgRecord;
|
||||
import org.apache.poi.hssf.HSSFTestDataSamples;
|
||||
import org.apache.poi.hssf.record.EscherAggregate;
|
||||
|
||||
/**
|
||||
* @author Evgeniy Berlog
|
||||
* @date 01.08.12
|
||||
*/
|
||||
public class TestPatriarch extends TestCase {
|
||||
|
||||
public void testGetPatriarch(){
|
||||
HSSFWorkbook wb = new HSSFWorkbook();
|
||||
HSSFSheet sh = wb.createSheet();
|
||||
assertNull(sh.getDrawingPatriarch());
|
||||
|
||||
HSSFPatriarch patriarch = sh.createDrawingPatriarch();
|
||||
assertNotNull(patriarch);
|
||||
patriarch.createSimpleShape(new HSSFClientAnchor());
|
||||
patriarch.createSimpleShape(new HSSFClientAnchor());
|
||||
|
||||
assertSame(patriarch, sh.getDrawingPatriarch());
|
||||
|
||||
EscherAggregate agg = patriarch._getBoundAggregate();
|
||||
|
||||
EscherDgRecord dg = agg.getEscherContainer().getChildById(EscherDgRecord.RECORD_ID);
|
||||
int lastId = dg.getLastMSOSPID();
|
||||
|
||||
assertSame(patriarch, sh.createDrawingPatriarch());
|
||||
|
||||
wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
|
||||
sh = wb.getSheetAt(0);
|
||||
patriarch = sh.createDrawingPatriarch();
|
||||
dg = patriarch._getBoundAggregate().getEscherContainer().getChildById(EscherDgRecord.RECORD_ID);
|
||||
|
||||
assertEquals(lastId, dg.getLastMSOSPID());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue