KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > poi > hssf > model > LineShape


1 /* ====================================================================
2    Copyright 2004 Apache Software Foundation
3
4    Licensed under the Apache License, Version 2.0 (the "License");
5    you may not use this file except in compliance with the License.
6    You may obtain a copy of the License at
7
8        http://www.apache.org/licenses/LICENSE-2.0
9
10    Unless required by applicable law or agreed to in writing, software
11    distributed under the License is distributed on an "AS IS" BASIS,
12    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13    See the License for the specific language governing permissions and
14    limitations under the License.
15 ==================================================================== */

16
17
18 package org.apache.poi.hssf.model;
19
20 import org.apache.poi.ddf.*;
21 import org.apache.poi.hssf.record.*;
22 import org.apache.poi.hssf.usermodel.*;
23
24 /**
25  * Represents a line shape and creates all the line specific low level records.
26  *
27  * @author Glen Stampoultzis (glens at apache.org)
28  */

29 public class LineShape
30         extends AbstractShape
31 {
32     private EscherContainerRecord spContainer;
33     private ObjRecord objRecord;
34
35     /**
36      * Creates the line shape from the highlevel user shape. All low level
37      * records are created at this point.
38      *
39      * @param hssfShape The user model shape.
40      * @param shapeId The identifier to use for this shape.
41      */

42     LineShape( HSSFSimpleShape hssfShape, int shapeId )
43     {
44         spContainer = createSpContainer(hssfShape, shapeId);
45         objRecord = createObjRecord(hssfShape, shapeId);
46     }
47
48     /**
49      * Creates the lowerlevel escher records for this shape.
50      */

51     private EscherContainerRecord createSpContainer(HSSFSimpleShape hssfShape, int shapeId)
52     {
53         HSSFShape shape = hssfShape;
54
55         EscherContainerRecord spContainer = new EscherContainerRecord();
56         EscherSpRecord sp = new EscherSpRecord();
57         EscherOptRecord opt = new EscherOptRecord();
58         EscherRecord anchor = new EscherClientAnchorRecord();
59         EscherClientDataRecord clientData = new EscherClientDataRecord();
60
61         spContainer.setRecordId( EscherContainerRecord.SP_CONTAINER );
62         spContainer.setOptions( (short) 0x000F );
63         sp.setRecordId( EscherSpRecord.RECORD_ID );
64         sp.setOptions( (short) ( (EscherAggregate.ST_LINE << 4) | 0x2 ) );
65
66         sp.setShapeId( shapeId );
67         sp.setFlags( EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_HASSHAPETYPE );
68         opt.setRecordId( EscherOptRecord.RECORD_ID );
69         opt.addEscherProperty( new EscherShapePathProperty( EscherProperties.GEOMETRY__SHAPEPATH, EscherShapePathProperty.COMPLEX ) );
70         opt.addEscherProperty( new EscherBoolProperty( EscherProperties.LINESTYLE__NOLINEDRAWDASH, 1048592 ) );
71         addStandardOptions(shape, opt);
72         HSSFAnchor userAnchor = shape.getAnchor();
73         if (userAnchor.isHorizontallyFlipped())
74             sp.setFlags(sp.getFlags() | EscherSpRecord.FLAG_FLIPHORIZ);
75         if (userAnchor.isVerticallyFlipped())
76             sp.setFlags(sp.getFlags() | EscherSpRecord.FLAG_FLIPVERT);
77         anchor = createAnchor(userAnchor);
78         clientData.setRecordId( EscherClientDataRecord.RECORD_ID );
79         clientData.setOptions( (short) 0x0000 );
80
81         spContainer.addChildRecord(sp);
82         spContainer.addChildRecord(opt);
83         spContainer.addChildRecord(anchor);
84         spContainer.addChildRecord(clientData);
85
86         return spContainer;
87     }
88
89     /**
90      * Creates the low level OBJ record for this shape.
91      */

92     private ObjRecord createObjRecord(HSSFShape hssfShape, int shapeId)
93     {
94         HSSFShape shape = hssfShape;
95
96         ObjRecord obj = new ObjRecord();
97         CommonObjectDataSubRecord c = new CommonObjectDataSubRecord();
98         c.setObjectType((short) ((HSSFSimpleShape)shape).getShapeType());
99         c.setObjectId((short) ( shapeId ));
100         c.setLocked(true);
101         c.setPrintable(true);
102         c.setAutofill(true);
103         c.setAutoline(true);
104         EndSubRecord e = new EndSubRecord();
105
106         obj.addSubRecord(c);
107         obj.addSubRecord(e);
108
109         return obj;
110     }
111
112     public EscherContainerRecord getSpContainer()
113     {
114         return spContainer;
115     }
116
117     public ObjRecord getObjRecord()
118     {
119         return objRecord;
120     }
121
122 }
123
Popular Tags