diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFComment.java b/src/java/org/apache/poi/hssf/usermodel/HSSFComment.java index 8ae7edbe7..8f4795b9b 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFComment.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFComment.java @@ -233,14 +233,14 @@ public class HSSFComment extends HSSFTextbox implements Comment { public void setBackgroundImage(int pictureIndex){ setPropertyValue(new EscherSimpleProperty( EscherProperties.FILL__PATTERNTEXTURE, false, true, pictureIndex)); setPropertyValue(new EscherSimpleProperty( EscherProperties.FILL__FILLTYPE, false, false, FILL_TYPE_PICTURE)); - EscherBSERecord bse = _patriarch.getSheet().getWorkbook().getWorkbook().getBSERecord(pictureIndex); + EscherBSERecord bse = getPatriarch().getSheet().getWorkbook().getWorkbook().getBSERecord(pictureIndex); bse.setRef(bse.getRef() + 1); } public void resetBackgroundImage(){ EscherSimpleProperty property = getOptRecord().lookup(EscherProperties.FILL__PATTERNTEXTURE); if (null != property){ - EscherBSERecord bse = _patriarch.getSheet().getWorkbook().getWorkbook().getBSERecord(property.getPropertyValue()); + EscherBSERecord bse = getPatriarch().getSheet().getWorkbook().getWorkbook().getBSERecord(property.getPropertyValue()); bse.setRef(bse.getRef() - 1); getOptRecord().removeEscherProperty(EscherProperties.FILL__PATTERNTEXTURE); } diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFPatriarch.java b/src/java/org/apache/poi/hssf/usermodel/HSSFPatriarch.java index 152762ba4..233a798dc 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFPatriarch.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFPatriarch.java @@ -90,6 +90,10 @@ public final class HSSFPatriarch implements HSSFShapeContainer, Drawing { return newPatriarch; } + /** + * @param shape to be removed + * @return true of shape is removed + */ public boolean removeShape(HSSFShape shape) { boolean isRemoved = _mainSpgrContainer.removeChildRecord(shape.getEscherContainer()); if (isRemoved){ @@ -225,7 +229,7 @@ public final class HSSFPatriarch implements HSSFShapeContainer, Drawing { } /** - * Returns a list of all shapes contained by the patriarch. + * Returns a unmodifiable list of all shapes contained by the patriarch. */ public List getChildren() { return Collections.unmodifiableList(_shapes); @@ -236,7 +240,7 @@ public final class HSSFPatriarch implements HSSFShapeContainer, Drawing { */ @Internal public void addShape(HSSFShape shape) { - shape._patriarch = this; + shape.setPatriarch(this); _shapes.add(shape); } @@ -331,18 +335,30 @@ public final class HSSFPatriarch implements HSSFShapeContainer, Drawing { return false; } + /** + * @return x coordinate of the left up corner + */ public int getX1() { return _spgrRecord.getRectX1(); } + /** + * @return y coordinate of the left up corner + */ public int getY1() { return _spgrRecord.getRectY1(); } + /** + * @return x coordinate of the right down corner + */ public int getX2() { return _spgrRecord.getRectX2(); } + /** + * @return y coordinate of the right down corner + */ public int getY2() { return _spgrRecord.getRectY2(); } @@ -377,6 +393,9 @@ public final class HSSFPatriarch implements HSSFShapeContainer, Drawing { } + /** + * create shape tree from existing escher records tree + */ void buildShapeTree() { EscherContainerRecord dgContainer = _boundAggregate.getEscherContainer(); if (dgContainer == null) { @@ -397,10 +416,10 @@ public final class HSSFPatriarch implements HSSFShapeContainer, Drawing { private void setFlipFlags(HSSFShape shape){ EscherSpRecord sp = shape.getEscherContainer().getChildById(EscherSpRecord.RECORD_ID); - if (shape.anchor.isHorizontallyFlipped()) { + if (shape.getAnchor().isHorizontallyFlipped()) { sp.setFlags(sp.getFlags() | EscherSpRecord.FLAG_FLIPHORIZ); } - if (shape.anchor.isVerticallyFlipped()) { + if (shape.getAnchor().isVerticallyFlipped()) { sp.setFlags(sp.getFlags() | EscherSpRecord.FLAG_FLIPVERT); } } diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFPicture.java b/src/java/org/apache/poi/hssf/usermodel/HSSFPicture.java index faffa20f0..1f20d9f0f 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFPicture.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFPicture.java @@ -206,7 +206,7 @@ public class HSSFPicture extends HSSFSimpleShape implements Picture { private float getColumnWidthInPixels(int column){ - int cw = _patriarch.getSheet().getColumnWidth(column); + int cw = getPatriarch().getSheet().getColumnWidth(column); float px = getPixelWidth(column); return cw/px; @@ -214,18 +214,18 @@ public class HSSFPicture extends HSSFSimpleShape implements Picture { private float getRowHeightInPixels(int i){ - HSSFRow row = _patriarch.getSheet().getRow(i); + HSSFRow row = getPatriarch().getSheet().getRow(i); float height; if(row != null) height = row.getHeight(); - else height = _patriarch.getSheet().getDefaultRowHeight(); + else height = getPatriarch().getSheet().getDefaultRowHeight(); return height/PX_ROW; } private float getPixelWidth(int column){ - int def = _patriarch.getSheet().getDefaultColumnWidth()*256; - int cw = _patriarch.getSheet().getColumnWidth(column); + int def = getPatriarch().getSheet().getDefaultColumnWidth()*256; + int cw = getPatriarch().getSheet().getColumnWidth(column); return cw == def ? PX_DEFAULT : PX_MODIFIED; } @@ -236,7 +236,7 @@ public class HSSFPicture extends HSSFSimpleShape implements Picture { * @return image dimension */ public Dimension getImageDimension(){ - EscherBSERecord bse = _patriarch.getSheet()._book.getBSERecord(getPictureIndex()); + EscherBSERecord bse = getPatriarch().getSheet()._book.getBSERecord(getPictureIndex()); byte[] data = bse.getBlipRecord().getPicturedata(); int type = bse.getBlipTypeWin32(); return ImageUtils.getImageDimension(new ByteArrayInputStream(data), type); @@ -248,7 +248,7 @@ public class HSSFPicture extends HSSFSimpleShape implements Picture { * @return picture data for this shape */ public HSSFPictureData getPictureData(){ - InternalWorkbook iwb = _patriarch.getSheet().getWorkbook().getWorkbook(); + InternalWorkbook iwb = getPatriarch().getSheet().getWorkbook().getWorkbook(); EscherBlipRecord blipRecord = iwb.getBSERecord(getPictureIndex()).getBlipRecord(); return new HSSFPictureData(blipRecord); } diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFShape.java b/src/java/org/apache/poi/hssf/usermodel/HSSFShape.java index daceee09a..f20239567 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFShape.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFShape.java @@ -54,9 +54,9 @@ public abstract class HSSFShape { public static final int LINESTYLE_DEFAULT = LINESTYLE_NONE; // TODO - make all these fields private - HSSFShape parent; + private HSSFShape parent; HSSFAnchor anchor; - HSSFPatriarch _patriarch; + private HSSFPatriarch _patriarch; private final EscherContainerRecord _escherContainer; private final ObjRecord _objRecord; @@ -93,6 +93,12 @@ public abstract class HSSFShape { protected abstract ObjRecord createObjRecord(); + /** + * remove escher container from the patriarch.escherAggregate + * remove obj, textObj and note records if it's necessary + * in case of ShapeGroup remove all contained shapes + * @param patriarch + */ protected abstract void afterRemove(HSSFPatriarch patriarch); /** @@ -379,4 +385,16 @@ public abstract class HSSFShape { } protected abstract HSSFShape cloneShape(); + + protected void setPatriarch(HSSFPatriarch _patriarch) { + this._patriarch = _patriarch; + } + + public HSSFPatriarch getPatriarch() { + return _patriarch; + } + + protected void setParent(HSSFShape parent) { + this.parent = parent; + } } diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFShapeGroup.java b/src/java/org/apache/poi/hssf/usermodel/HSSFShapeGroup.java index a80e5bb98..9f60d6eae 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFShapeGroup.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFShapeGroup.java @@ -129,18 +129,18 @@ public class HSSFShapeGroup extends HSSFShape implements HSSFShapeContainer { for ( int i=0; i