01: /* ====================================================================
02: Licensed to the Apache Software Foundation (ASF) under one or more
03: contributor license agreements. See the NOTICE file distributed with
04: this work for additional information regarding copyright ownership.
05: The ASF licenses this file to You under the Apache License, Version 2.0
06: (the "License"); you may not use this file except in compliance with
07: the License. You may obtain a copy of the License at
08:
09: http://www.apache.org/licenses/LICENSE-2.0
10:
11: Unless required by applicable law or agreed to in writing, software
12: distributed under the License is distributed on an "AS IS" BASIS,
13: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: See the License for the specific language governing permissions and
15: limitations under the License.
16: ==================================================================== */
17: package org.apache.poi.hslf.model;
18:
19: import org.apache.poi.ddf.*;
20:
21: /**
22: * Create a <code>Shape</code> object depending on its type
23: *
24: * @author Yegor Kozlov
25: */
26: public class ShapeFactory {
27:
28: /**
29: * Create a new shape from the data provided.
30: */
31: public static Shape createShape(EscherContainerRecord spContainer,
32: Shape parent) {
33: if (spContainer.getRecordId() == EscherContainerRecord.SPGR_CONTAINER) {
34: return new ShapeGroup(spContainer, parent);
35: }
36:
37: Shape shape;
38: EscherSpRecord spRecord = spContainer
39: .getChildById(EscherSpRecord.RECORD_ID);
40:
41: int type = spRecord.getOptions() >> 4;
42: switch (type) {
43: case ShapeTypes.TextBox:
44: case ShapeTypes.Rectangle:
45: EscherTextboxRecord txtbox = (EscherTextboxRecord) Shape
46: .getEscherChild(spContainer,
47: EscherTextboxRecord.RECORD_ID);
48: if (txtbox == null)
49: shape = new AutoShape(spContainer, parent);
50: else
51: shape = new TextBox(spContainer, parent);
52: break;
53: case ShapeTypes.PictureFrame:
54: shape = new Picture(spContainer, parent);
55: break;
56: case ShapeTypes.Line:
57: shape = new Line(spContainer, parent);
58: break;
59: case ShapeTypes.NotPrimitive:
60: if ((spRecord.getFlags() & EscherSpRecord.FLAG_GROUP) != 0)
61: shape = new ShapeGroup(spContainer, parent);
62: else
63: shape = new AutoShape(spContainer, parent);
64: break;
65: default:
66: shape = new AutoShape(spContainer, parent);
67: break;
68: }
69: return shape;
70: }
71:
72: }
|