1 16 17 package org.apache.poi.hssf.model; 18 19 import org.apache.poi.ddf.*; 20 import org.apache.poi.hssf.record.ObjRecord; 21 import org.apache.poi.hssf.usermodel.*; 22 23 28 public abstract class AbstractShape 29 { 30 35 public static AbstractShape createShape( HSSFShape hssfShape, int shapeId ) 36 { 37 AbstractShape shape = null; 38 if (hssfShape instanceof HSSFTextbox) 39 { 40 shape = new TextboxShape( (HSSFTextbox)hssfShape, shapeId ); 41 } 42 else if (hssfShape instanceof HSSFPolygon) 43 { 44 shape = new PolygonShape( (HSSFPolygon) hssfShape, shapeId ); 45 } 46 else if (hssfShape instanceof HSSFSimpleShape) 47 { 48 HSSFSimpleShape simpleShape = (HSSFSimpleShape) hssfShape; 49 switch ( simpleShape.getShapeType() ) 50 { 51 case HSSFSimpleShape.OBJECT_TYPE_LINE: 52 shape = new LineShape( simpleShape, shapeId ); 53 break; 54 case HSSFSimpleShape.OBJECT_TYPE_OVAL: 55 case HSSFSimpleShape.OBJECT_TYPE_RECTANGLE: 56 shape = new SimpleFilledShape( simpleShape, shapeId ); 57 break; 58 default: 59 throw new IllegalArgumentException ("Do not know how to handle this type of shape"); 60 } 61 } 62 else 63 { 64 throw new IllegalArgumentException ("Unknown shape type"); 65 } 66 EscherSpRecord sp = shape.getSpContainer().getChildById(EscherSpRecord.RECORD_ID); 67 if (hssfShape.getParent() != null) 68 sp.setFlags(sp.getFlags() | EscherSpRecord.FLAG_CHILD); 69 return shape; 70 } 71 72 protected AbstractShape() 73 { 74 } 75 76 80 public abstract EscherContainerRecord getSpContainer(); 81 82 85 public abstract ObjRecord getObjRecord(); 86 87 93 protected EscherRecord createAnchor( HSSFAnchor userAnchor ) 94 { 95 return ConvertAnchor.createAnchor(userAnchor); 96 } 97 98 106 protected int addStandardOptions( HSSFShape shape, EscherOptRecord opt ) 107 { 108 opt.addEscherProperty( new EscherBoolProperty( EscherProperties.TEXT__SIZE_TEXT_TO_FIT_SHAPE, 0x080000 ) ); 109 if ( shape.isNoFill() ) 111 { 112 opt.addEscherProperty( new EscherBoolProperty( EscherProperties.FILL__NOFILLHITTEST, 0x00110000 ) ); 114 } 115 else 116 { 117 opt.addEscherProperty( new EscherBoolProperty( EscherProperties.FILL__NOFILLHITTEST, 0x00010000 ) ); 118 } 119 opt.addEscherProperty( new EscherRGBProperty( EscherProperties.FILL__FILLCOLOR, shape.getFillColor() ) ); 120 opt.addEscherProperty( new EscherBoolProperty( EscherProperties.GROUPSHAPE__PRINT, 0x080000 ) ); 121 opt.addEscherProperty( new EscherRGBProperty( EscherProperties.LINESTYLE__COLOR, shape.getLineStyleColor() ) ); 122 int options = 5; 123 if (shape.getLineWidth() != HSSFShape.LINEWIDTH_DEFAULT) 124 { 125 opt.addEscherProperty( new EscherSimpleProperty( EscherProperties.LINESTYLE__LINEWIDTH, shape.getLineWidth())); 126 options++; 127 } 128 if (shape.getLineStyle() != HSSFShape.LINESTYLE_SOLID) 129 { 130 opt.addEscherProperty( new EscherSimpleProperty( EscherProperties.LINESTYLE__LINEDASHING, shape.getLineStyle())); 131 opt.addEscherProperty( new EscherSimpleProperty( EscherProperties.LINESTYLE__LINEENDCAPSTYLE, 0)); 132 if (shape.getLineStyle() == HSSFShape.LINESTYLE_NONE) 133 opt.addEscherProperty( new EscherBoolProperty( EscherProperties.LINESTYLE__NOLINEDRAWDASH, 0x00080000)); 134 else 135 opt.addEscherProperty( new EscherBoolProperty( EscherProperties.LINESTYLE__NOLINEDRAWDASH, 0x00080008)); 136 options += 3; 137 } 138 opt.sortProperties(); 139 return options; } 141 142 } 143 | Popular Tags |