001: /* ====================================================================
002: Licensed to the Apache Software Foundation (ASF) under one or more
003: contributor license agreements. See the NOTICE file distributed with
004: this work for additional information regarding copyright ownership.
005: The ASF licenses this file to You under the Apache License, Version 2.0
006: (the "License"); you may not use this file except in compliance with
007: the License. You may obtain a copy of the License at
008:
009: http://www.apache.org/licenses/LICENSE-2.0
010:
011: Unless required by applicable law or agreed to in writing, software
012: distributed under the License is distributed on an "AS IS" BASIS,
013: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: See the License for the specific language governing permissions and
015: limitations under the License.
016: ==================================================================== */
017:
018: package org.apache.poi.hssf.model;
019:
020: import org.apache.poi.ddf.*;
021: import org.apache.poi.hssf.record.*;
022: import org.apache.poi.hssf.usermodel.*;
023:
024: /**
025: * Represents a line shape and creates all the line specific low level records.
026: *
027: * @author Glen Stampoultzis (glens at apache.org)
028: */
029: public class LineShape extends AbstractShape {
030: private EscherContainerRecord spContainer;
031: private ObjRecord objRecord;
032:
033: /**
034: * Creates the line shape from the highlevel user shape. All low level
035: * records are created at this point.
036: *
037: * @param hssfShape The user model shape.
038: * @param shapeId The identifier to use for this shape.
039: */
040: LineShape(HSSFSimpleShape hssfShape, int shapeId) {
041: spContainer = createSpContainer(hssfShape, shapeId);
042: objRecord = createObjRecord(hssfShape, shapeId);
043: }
044:
045: /**
046: * Creates the lowerlevel escher records for this shape.
047: */
048: private EscherContainerRecord createSpContainer(
049: HSSFSimpleShape hssfShape, int shapeId) {
050: HSSFShape shape = hssfShape;
051:
052: EscherContainerRecord spContainer = new EscherContainerRecord();
053: EscherSpRecord sp = new EscherSpRecord();
054: EscherOptRecord opt = new EscherOptRecord();
055: EscherRecord anchor = new EscherClientAnchorRecord();
056: EscherClientDataRecord clientData = new EscherClientDataRecord();
057:
058: spContainer.setRecordId(EscherContainerRecord.SP_CONTAINER);
059: spContainer.setOptions((short) 0x000F);
060: sp.setRecordId(EscherSpRecord.RECORD_ID);
061: sp.setOptions((short) ((EscherAggregate.ST_LINE << 4) | 0x2));
062:
063: sp.setShapeId(shapeId);
064: sp.setFlags(EscherSpRecord.FLAG_HAVEANCHOR
065: | EscherSpRecord.FLAG_HASSHAPETYPE);
066: opt.setRecordId(EscherOptRecord.RECORD_ID);
067: opt.addEscherProperty(new EscherShapePathProperty(
068: EscherProperties.GEOMETRY__SHAPEPATH,
069: EscherShapePathProperty.COMPLEX));
070: opt.addEscherProperty(new EscherBoolProperty(
071: EscherProperties.LINESTYLE__NOLINEDRAWDASH, 1048592));
072: addStandardOptions(shape, opt);
073: HSSFAnchor userAnchor = shape.getAnchor();
074: if (userAnchor.isHorizontallyFlipped())
075: sp.setFlags(sp.getFlags() | EscherSpRecord.FLAG_FLIPHORIZ);
076: if (userAnchor.isVerticallyFlipped())
077: sp.setFlags(sp.getFlags() | EscherSpRecord.FLAG_FLIPVERT);
078: anchor = createAnchor(userAnchor);
079: clientData.setRecordId(EscherClientDataRecord.RECORD_ID);
080: clientData.setOptions((short) 0x0000);
081:
082: spContainer.addChildRecord(sp);
083: spContainer.addChildRecord(opt);
084: spContainer.addChildRecord(anchor);
085: spContainer.addChildRecord(clientData);
086:
087: return spContainer;
088: }
089:
090: /**
091: * Creates the low level OBJ record for this shape.
092: */
093: private ObjRecord createObjRecord(HSSFShape hssfShape, int shapeId) {
094: HSSFShape shape = hssfShape;
095:
096: ObjRecord obj = new ObjRecord();
097: CommonObjectDataSubRecord c = new CommonObjectDataSubRecord();
098: c.setObjectType((short) ((HSSFSimpleShape) shape)
099: .getShapeType());
100: c.setObjectId((short) (shapeId));
101: c.setLocked(true);
102: c.setPrintable(true);
103: c.setAutofill(true);
104: c.setAutoline(true);
105: EndSubRecord e = new EndSubRecord();
106:
107: obj.addSubRecord(c);
108: obj.addSubRecord(e);
109:
110: return obj;
111: }
112:
113: public EscherContainerRecord getSpContainer() {
114: return spContainer;
115: }
116:
117: public ObjRecord getObjRecord() {
118: return objRecord;
119: }
120:
121: }
|