import org.apache.poi.ddf.EscherClientAnchorRecord;
import org.apache.poi.ddf.EscherContainerRecord;
import org.apache.poi.ddf.EscherRecord;
+import org.apache.poi.ss.usermodel.ChildAnchor;
/**
* An anchor is what specifics the position of a shape within a client object
* or within another containing shape.
*/
-public abstract class HSSFAnchor {
+public abstract class HSSFAnchor implements ChildAnchor {
protected boolean _isHorizontallyFlipped = false;
protected boolean _isVerticallyFlipped = false;
}
}
- /**
- * @return x coordinate of the left up corner
- */
- public abstract int getDx1();
-
- /**
- * @param dx1 x coordinate of the left up corner
- */
- public abstract void setDx1(int dx1);
-
- /**
- * @return y coordinate of the left up corner
- */
- public abstract int getDy1();
-
- /**
- * @param dy1 y coordinate of the left up corner
- */
- public abstract void setDy1(int dy1);
-
- /**
- * @return y coordinate of the right down corner
- */
- public abstract int getDy2();
-
- /**
- * @param dy2 y coordinate of the right down corner
- */
- public abstract void setDy2(int dy2);
-
- /**
- * @return x coordinate of the right down corner
- */
- public abstract int getDx2();
-
- /**
- * @param dx2 x coordinate of the right down corner
- */
- public abstract void setDx2(int dx2);
-
/**
* @return whether this shape is horizontally flipped
*/
* The patriarch is the toplevel container for shapes in a sheet. It does
* little other than act as a container for other shapes and groups.
*/
-public final class HSSFPatriarch implements HSSFShapeContainer, Drawing {
+public final class HSSFPatriarch implements HSSFShapeContainer, Drawing<HSSFShape> {
// private static POILogger log = POILogFactory.getLogger(HSSFPatriarch.class);
private final List<HSSFShape> _shapes = new ArrayList<HSSFShape>();
String entryName = "MBD"+HexDump.toHex(storageId);
DirectoryEntry oleRoot;
try {
- DirectoryNode dn = _sheet.getWorkbook().getRootDirectory();
+ DirectoryNode dn = _sheet.getWorkbook().getDirectory();
if (dn == null) throw new FileNotFoundException();
oleRoot = (DirectoryEntry)dn.getEntry(entryName);
} catch (FileNotFoundException e) {
for (int i = 0; i < spgrChildren.size(); i++) {
EscherContainerRecord spContainer = spgrChildren.get(i);
if (i != 0) {
- HSSFShapeFactory.createShapeTree(spContainer, _boundAggregate, this, _sheet.getWorkbook().getRootDirectory());
+ HSSFShapeFactory.createShapeTree(spContainer, _boundAggregate, this, _sheet.getWorkbook().getDirectory());
}
}
}
}
}
+ @Override
public Iterator<HSSFShape> iterator() {
return _shapes.iterator();
}
import org.apache.poi.ddf.EscherBoolProperty;
import org.apache.poi.ddf.EscherChildAnchorRecord;
import org.apache.poi.ddf.EscherClientAnchorRecord;
+import org.apache.poi.ddf.EscherComplexProperty;
import org.apache.poi.ddf.EscherContainerRecord;
import org.apache.poi.ddf.EscherOptRecord;
import org.apache.poi.ddf.EscherProperties;
import org.apache.poi.ddf.EscherSpRecord;
import org.apache.poi.hssf.record.CommonObjectDataSubRecord;
import org.apache.poi.hssf.record.ObjRecord;
+import org.apache.poi.ss.usermodel.Shape;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger;
+import org.apache.poi.util.StringUtil;
/**
* An abstract shape.
* reverse them and draw shapes vertically or horizontally flipped via
* setFlipVertical() or setFlipHorizontally().
*/
-public abstract class HSSFShape {
+public abstract class HSSFShape implements Shape {
private static final POILogger LOG = POILogFactory.getLogger(HSSFShape.class);
public static final int LINEWIDTH_ONE_PT = 12700;
return _optRecord;
}
- /**
- * Gets the parent shape.
- */
+ @Override
public HSSFShape getParent() {
return parent;
}
/**
* @return the anchor that is used by this shape.
*/
+ @Override
public HSSFAnchor getAnchor() {
return anchor;
}
setPropertyValue(new EscherRGBProperty(EscherProperties.LINESTYLE__COLOR, lineStyleColor));
}
- /**
- * The color applied to the lines of this shape.
- */
+ @Override
public void setLineStyleColor(int red, int green, int blue) {
int lineStyleColor = ((blue) << 16) | ((green) << 8) | red;
setPropertyValue(new EscherRGBProperty(EscherProperties.LINESTYLE__COLOR, lineStyleColor));
setPropertyValue(new EscherRGBProperty(EscherProperties.FILL__FILLCOLOR, fillColor));
}
- /**
- * The color used to fill this shape.
- */
+ @Override
public void setFillColor(int red, int green, int blue) {
int fillColor = ((blue) << 16) | ((green) << 8) | red;
setPropertyValue(new EscherRGBProperty(EscherProperties.FILL__FILLCOLOR, fillColor));
}
}
- /**
- * @return <code>true</code> if this shape is not filled with a color.
- */
+ @Override
public boolean isNoFill() {
EscherBoolProperty property = _optRecord.lookup(EscherProperties.FILL__NOFILLHITTEST);
return property == null ? NO_FILL_DEFAULT : property.getPropertyValue() == NO_FILLHITTEST_TRUE;
}
- /**
- * @param noFill sets whether this shape is filled or transparent.
- */
+ @Override
public void setNoFill(boolean noFill) {
setPropertyValue(new EscherBoolProperty(EscherProperties.FILL__NOFILLHITTEST, noFill ? NO_FILLHITTEST_TRUE : NO_FILLHITTEST_FALSE));
}
protected void setParent(HSSFShape parent) {
this.parent = parent;
}
+
+ /**
+ * @return the name of this shape
+ */
+ public String getShapeName() {
+ EscherOptRecord eor = getOptRecord();
+ if (eor == null) {
+ return null;
+ }
+ EscherProperty ep = eor.lookup(EscherProperties.GROUPSHAPE__SHAPENAME);
+ if (ep instanceof EscherComplexProperty) {
+ return StringUtil.getFromUnicodeLE(((EscherComplexProperty)ep).getComplexData());
+ }
+ return null;
+ }
}
import java.util.List;
+import org.apache.poi.ss.usermodel.ShapeContainer;
+
/**
* An interface that indicates whether a class can contain children.
*/
-public interface HSSFShapeContainer extends Iterable<HSSFShape>
+public interface HSSFShapeContainer extends ShapeContainer<HSSFShape>
{
/**
* @return Any children contained by this shape.
return isRemoved;
}
+ @Override
public Iterator<HSSFShape> iterator() {
return shapes.iterator();
}
package org.apache.poi.hssf.usermodel;
-import org.apache.poi.ddf.*;
-import org.apache.poi.hssf.record.*;
+import org.apache.poi.ddf.DefaultEscherRecordFactory;
+import org.apache.poi.ddf.EscherBoolProperty;
+import org.apache.poi.ddf.EscherClientDataRecord;
+import org.apache.poi.ddf.EscherContainerRecord;
+import org.apache.poi.ddf.EscherOptRecord;
+import org.apache.poi.ddf.EscherProperties;
+import org.apache.poi.ddf.EscherRGBProperty;
+import org.apache.poi.ddf.EscherShapePathProperty;
+import org.apache.poi.ddf.EscherSimpleProperty;
+import org.apache.poi.ddf.EscherSpRecord;
+import org.apache.poi.ddf.EscherTextboxRecord;
+import org.apache.poi.hssf.record.CommonObjectDataSubRecord;
+import org.apache.poi.hssf.record.EndSubRecord;
+import org.apache.poi.hssf.record.EscherAggregate;
+import org.apache.poi.hssf.record.ObjRecord;
+import org.apache.poi.hssf.record.TextObjectRecord;
import org.apache.poi.ss.usermodel.RichTextString;
+import org.apache.poi.ss.usermodel.SimpleShape;
/**
* Represents a simple shape such as a line, rectangle or oval.
*/
-public class HSSFSimpleShape extends HSSFShape
+public class HSSFSimpleShape extends HSSFShape implements SimpleShape
{
// The commented out ones haven't been tested yet or aren't supported
// by HSSFSimpleShape.
--- /dev/null
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.ss.usermodel;
+
+/**
+ * Common interface for anchors.<p>
+ *
+ * An anchor is what specifics the position of a shape within a client object
+ * or within another containing shape.
+ *
+ * @since POI 3.16-beta2
+ */
+public interface ChildAnchor {
+ /**
+ * @return x coordinate of the left up corner
+ */
+ int getDx1();
+
+ /**
+ * @param dx1 x coordinate of the left up corner
+ */
+ void setDx1(int dx1);
+
+ /**
+ * @return y coordinate of the left up corner
+ */
+ int getDy1();
+
+ /**
+ * @param dy1 y coordinate of the left up corner
+ */
+ void setDy1(int dy1);
+
+ /**
+ * @return y coordinate of the right down corner
+ */
+ int getDy2();
+
+ /**
+ * @param dy2 y coordinate of the right down corner
+ */
+ void setDy2(int dy2);
+
+ /**
+ * @return x coordinate of the right down corner
+ */
+ int getDx2();
+
+ /**
+ * @param dx2 x coordinate of the right down corner
+ */
+ void setDx2(int dx2);
+}
/**
* High level representation of spreadsheet drawing.
- * @author Yegor Kozlov
- * @author Roman Kashitsyn
*/
-public interface Drawing {
+public interface Drawing<T extends Shape> extends ShapeContainer<T> {
/**
* Creates a picture.
* @param anchor the client anchor describes how this picture is
/**
* Repersents a picture in a SpreadsheetML document
- *
- * @author Yegor Kozlov
*/
-public interface Picture {
+public interface Picture extends Shape {
/**
* Reset the image to the dimension of the embedded image
--- /dev/null
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.ss.usermodel;
+
+/**
+ * Common interface for all drawing shapes
+ *
+ * @since POI 3.16-beta2
+ */
+public interface Shape {
+ /**
+ * @return the name of this shape
+ */
+ String getShapeName();
+
+ /**
+ * @return the parent shape.
+ */
+ Shape getParent();
+
+ /**
+ * @return the anchor that is used by this shape.
+ */
+ ChildAnchor getAnchor();
+
+ /**
+ * Whether this shape is not filled with a color
+ *
+ * @return true if this shape is not filled with a color.
+ */
+ boolean isNoFill();
+
+ /**
+ * Sets whether this shape is filled or transparent.
+ *
+ * @param noFill if true then no fill will be applied to the shape element.
+ */
+ void setNoFill(boolean noFill);
+
+ /**
+ * Sets the color used to fill this shape using the solid fill pattern.
+ */
+ void setFillColor(int red, int green, int blue);
+
+ /**
+ * The color applied to the lines of this shape.
+ */
+ void setLineStyleColor(int red, int green, int blue);
+}
--- /dev/null
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.ss.usermodel;
+
+/**
+ * A common interface for shape groups.
+ *
+ * @since POI 3.16-beta2
+ */
+public interface ShapeContainer<T extends Shape> extends Iterable<T> {
+
+}
--- /dev/null
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.ss.usermodel;
+
+/**
+ * A common interface for simple shapes.
+ * (Currently the HSSF and XSSF classes don't share common method signatures ...)
+ *
+ * @since POI 3.16-beta2
+ */
+public interface SimpleShape extends Shape {
+
+}
package org.apache.poi.xssf.streaming;
+import java.util.Iterator;
+
import org.apache.poi.ss.usermodel.Chart;
import org.apache.poi.ss.usermodel.ClientAnchor;
import org.apache.poi.ss.usermodel.Comment;
import org.apache.poi.ss.usermodel.Drawing;
import org.apache.poi.xssf.usermodel.XSSFDrawing;
import org.apache.poi.xssf.usermodel.XSSFPicture;
+import org.apache.poi.xssf.usermodel.XSSFShape;
/**
* Streaming version of Drawing.
* Delegates most tasks to the non-streaming XSSF code.
* TODO: Potentially, Comment and Chart need a similar streaming wrapper like Picture.
*/
-public class SXSSFDrawing implements Drawing {
+public class SXSSFDrawing implements Drawing<XSSFShape> {
private final SXSSFWorkbook _wb;
private final XSSFDrawing _drawing;
public ClientAnchor createAnchor(int dx1, int dy1, int dx2, int dy2, int col1, int row1, int col2, int row2) {
return _drawing.createAnchor(dx1, dy1, dx2, dy2, col1, row1, col2, row2);
}
+
+ @Override
+ public Iterator<XSSFShape> iterator() {
+ return _drawing.getShapes().iterator();
+ }
}
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.ss.usermodel.Picture;
import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Shape;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.util.ImageUtils;
import org.apache.poi.util.Internal;
}
private float getColumnWidthInPixels(int columnIndex){
- XSSFSheet sheet = getParent();
+ XSSFSheet sheet = getSheet();
CTCol col = sheet.getColumnHelper().getColumn(columnIndex, false);
double numChars = col == null || !col.isSetWidth() ? DEFAULT_COLUMN_WIDTH : col.getWidth();
private float getRowHeightInPixels(int rowIndex) {
// THE FOLLOWING THREE LINES ARE THE MAIN CHANGE compared to the non-streaming version: use the SXSSF sheet,
// not the XSSF sheet (which never contais rows when using SXSSF)
- XSSFSheet xssfSheet = getParent();
+ XSSFSheet xssfSheet = getSheet();
SXSSFSheet sheet = _wb.getSXSSFSheet(xssfSheet);
Row row = sheet.getRow(rowIndex);
float height = row != null ? row.getHeightInPoints() : sheet.getDefaultRowHeightInPoints();
return getCTPicture().getSpPr();
}
- private XSSFSheet getParent() {
- return (XSSFSheet)_picture.getDrawing().getParent();
- }
-
- private XSSFAnchor getAnchor() {
+ @Override
+ public XSSFAnchor getAnchor() {
return _picture.getAnchor();
}
public XSSFSheet getSheet() {
return _picture.getSheet();
}
+
+ @Override
+ public String getShapeName() {
+ return _picture.getShapeName();
+ }
+
+ @Override
+ public Shape getParent() {
+ return _picture.getParent();
+ }
+
+ @Override
+ public boolean isNoFill() {
+ return _picture.isNoFill();
+ }
+
+ @Override
+ public void setNoFill(boolean noFill) {
+ _picture.setNoFill(noFill);
+ }
+
+ @Override
+ public void setFillColor(int red, int green, int blue) {
+ _picture.setFillColor(red, green, blue);
+ }
+
+ @Override
+ public void setLineStyleColor( int red, int green, int blue ) {
+ _picture.setLineStyleColor(red, green, blue);
+ }
}
package org.apache.poi.xssf.usermodel;
+import org.apache.poi.ss.usermodel.ChildAnchor;
+
/**
* An anchor is what specifics the position of a shape within a client object
* or within another containing shape.
- *
- * @author Yegor Kozlov
*/
-public abstract class XSSFAnchor {
-
- public abstract int getDx1();
- public abstract void setDx1( int dx1 );
- public abstract int getDy1();
- public abstract void setDy1( int dy1 );
- public abstract int getDy2();
- public abstract void setDy2( int dy2 );
- public abstract int getDx2();
- public abstract void setDx2( int dx2 );
-
+public abstract class XSSFAnchor implements ChildAnchor {
}
return ctShape.getSpPr();
}
+ @Override
+ public String getShapeName() {
+ return ctShape.getNvCxnSpPr().getCNvPr().getName();
+ }
}
protected CTShapeProperties getShapeProperties(){
return null;
}
+
+ @Override
+ public String getShapeName() {
+ return graphicFrame.getNvGraphicFramePr().getCNvPr().getName();
+ }
}
public XSSFSheet getSheet() {
return (XSSFSheet)getDrawing().getParent();
}
+
+ @Override
+ public String getShapeName() {
+ return ctPicture.getNvPicPr().getCNvPr().getName();
+ }
}
package org.apache.poi.xssf.usermodel;
+import org.apache.poi.ss.usermodel.Shape;
import org.openxmlformats.schemas.drawingml.x2006.main.CTLineProperties;
import org.openxmlformats.schemas.drawingml.x2006.main.CTNoFillProperties;
import org.openxmlformats.schemas.drawingml.x2006.main.CTPresetLineDashProperties;
/**
* Represents a shape in a SpreadsheetML drawing.
- *
- * @author Yegor Kozlov
*/
-public abstract class XSSFShape {
+public abstract class XSSFShape implements Shape {
public static final int EMU_PER_PIXEL = 9525;
public static final int EMU_PER_POINT = 12700;
return drawing;
}
- /**
- * Gets the parent shape.
- */
+ @Override
public XSSFShapeGroup getParent()
{
return parent;
/**
* @return the anchor that is used by this shape.
*/
+ @Override
public XSSFAnchor getAnchor()
{
return anchor;
*/
protected abstract CTShapeProperties getShapeProperties();
- /**
- * Whether this shape is not filled with a color
- *
- * @return true if this shape is not filled with a color.
- */
+ @Override
public boolean isNoFill() {
return getShapeProperties().isSetNoFill();
}
- /**
- * Sets whether this shape is filled or transparent.
- *
- * @param noFill if true then no fill will be applied to the shape element.
- */
+ @Override
public void setNoFill(boolean noFill) {
CTShapeProperties props = getShapeProperties();
//unset solid and pattern fills if they are set
props.setNoFill(CTNoFillProperties.Factory.newInstance());
}
- /**
- * Sets the color used to fill this shape using the solid fill pattern.
- */
+ @Override
public void setFillColor(int red, int green, int blue) {
CTShapeProperties props = getShapeProperties();
CTSolidColorFillProperties fill = props.isSetSolidFill() ? props.getSolidFill() : props.addNewSolidFill();
fill.setSrgbClr(rgb);
}
- /**
- * The color applied to the lines of this shape.
- */
+ @Override
public void setLineStyleColor( int red, int green, int blue ) {
CTShapeProperties props = getShapeProperties();
CTLineProperties ln = props.isSetLn() ? props.getLn() : props.addNewLn();
import java.util.Locale;
import org.apache.poi.hssf.util.HSSFColor;
+import org.apache.poi.ss.usermodel.SimpleShape;
import org.apache.poi.ss.usermodel.VerticalAlignment;
import org.apache.poi.util.Internal;
import org.apache.poi.util.Units;
* Represents a shape with a predefined geometry in a SpreadsheetML drawing.
* Possible shape types are defined in {@link org.apache.poi.ss.usermodel.ShapeTypes}
*/
-public class XSSFSimpleShape extends XSSFShape implements Iterable<XSSFTextParagraph> { // TODO - instantiable superclass
+public class XSSFSimpleShape extends XSSFShape implements Iterable<XSSFTextParagraph>, SimpleShape {
/**
* List of the paragraphs that make up the text in this shape
*/
}
}
}
+
+ @Override
+ public String getShapeName() {
+ return ctShape.getNvSpPr().getCNvPr().getName();
+ }
}