diff options
author | Glen Stampoultzis <glens@apache.org> | 2004-04-09 11:45:38 +0000 |
---|---|---|
committer | Glen Stampoultzis <glens@apache.org> | 2004-04-09 11:45:38 +0000 |
commit | b6ea214cc1e42332b7198954c63a783935b4bdf4 (patch) | |
tree | 9ffdd5aea352c9c258ed2df5fa1a4deb4d63792e /src/java/org/apache/poi/hssf/model/SimpleFilledShape.java | |
parent | 0873a633af2dc09fd9eab9ee1b2d5835e0d7fc2d (diff) | |
download | poi-b6ea214cc1e42332b7198954c63a783935b4bdf4.tar.gz poi-b6ea214cc1e42332b7198954c63a783935b4bdf4.zip |
Ported the drawing stuff from the rel_2_branch. Given the effort this took I'm really really wanting to move to subversion.
git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@353542 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/poi/hssf/model/SimpleFilledShape.java')
-rw-r--r-- | src/java/org/apache/poi/hssf/model/SimpleFilledShape.java | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/src/java/org/apache/poi/hssf/model/SimpleFilledShape.java b/src/java/org/apache/poi/hssf/model/SimpleFilledShape.java new file mode 100644 index 0000000000..dadb02d79d --- /dev/null +++ b/src/java/org/apache/poi/hssf/model/SimpleFilledShape.java @@ -0,0 +1,111 @@ +package org.apache.poi.hssf.model; + +import org.apache.poi.ddf.*; +import org.apache.poi.hssf.record.ObjRecord; +import org.apache.poi.hssf.record.EscherAggregate; +import org.apache.poi.hssf.record.CommonObjectDataSubRecord; +import org.apache.poi.hssf.record.EndSubRecord; +import org.apache.poi.hssf.usermodel.HSSFSimpleShape; +import org.apache.poi.hssf.usermodel.HSSFShape; + +public class SimpleFilledShape + extends AbstractShape +{ + private EscherContainerRecord spContainer; + private ObjRecord objRecord; + + /** + * Creates the low evel records for an oval. + * + * @param hssfShape The highlevel shape. + * @param shapeId The shape id to use for this shape. + */ + SimpleFilledShape( HSSFSimpleShape hssfShape, int shapeId ) + { + spContainer = createSpContainer( hssfShape, shapeId ); + objRecord = createObjRecord( hssfShape, shapeId ); + } + + /** + * Generates the shape records for this shape. + * + * @param hssfShape + * @param shapeId + * @return + */ + private EscherContainerRecord createSpContainer( HSSFSimpleShape hssfShape, int shapeId ) + { + HSSFShape shape = hssfShape; + + EscherContainerRecord spContainer = new EscherContainerRecord(); + EscherSpRecord sp = new EscherSpRecord(); + EscherOptRecord opt = new EscherOptRecord(); + EscherClientDataRecord clientData = new EscherClientDataRecord(); + + spContainer.setRecordId( EscherContainerRecord.SP_CONTAINER ); + spContainer.setOptions( (short) 0x000F ); + sp.setRecordId( EscherSpRecord.RECORD_ID ); + short shapeType = objTypeToShapeType( hssfShape.getShapeType() ); + sp.setOptions( (short) ( ( shapeType << 4 ) | 0x2 ) ); + sp.setShapeId( shapeId ); + sp.setFlags( EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_HASSHAPETYPE ); + opt.setRecordId( EscherOptRecord.RECORD_ID ); + addStandardOptions(shape, opt); + EscherRecord anchor = createAnchor( shape.getAnchor() ); + clientData.setRecordId( EscherClientDataRecord.RECORD_ID ); + clientData.setOptions( (short) 0x0000 ); + + spContainer.addChildRecord( sp ); + spContainer.addChildRecord( opt ); + spContainer.addChildRecord( anchor ); + spContainer.addChildRecord( clientData ); + + return spContainer; + } + + private short objTypeToShapeType( int objType ) + { + short shapeType; + if (objType == HSSFSimpleShape.OBJECT_TYPE_OVAL) + shapeType = EscherAggregate.ST_ELLIPSE; + else if (objType == HSSFSimpleShape.OBJECT_TYPE_RECTANGLE) + shapeType = EscherAggregate.ST_RECTANGLE; + else + throw new IllegalArgumentException("Unable to handle an object of this type"); + return shapeType; + } + + /** + * Creates the low level OBJ record for this shape. + */ + private ObjRecord createObjRecord( HSSFShape hssfShape, int shapeId ) + { + HSSFShape shape = hssfShape; + + ObjRecord obj = new ObjRecord(); + CommonObjectDataSubRecord c = new CommonObjectDataSubRecord(); + c.setObjectType( (short) ( (HSSFSimpleShape) shape ).getShapeType() ); + c.setObjectId( (short) ( shapeId ) ); + c.setLocked( true ); + c.setPrintable( true ); + c.setAutofill( true ); + c.setAutoline( true ); + EndSubRecord e = new EndSubRecord(); + + obj.addSubRecord( c ); + obj.addSubRecord( e ); + + return obj; + } + + public EscherContainerRecord getSpContainer() + { + return spContainer; + } + + public ObjRecord getObjRecord() + { + return objRecord; + } + +} |