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: package org.apache.poi.hslf.model;
018:
019: import org.apache.poi.ddf.*;
020: import org.apache.poi.hslf.record.EscherTextboxWrapper;
021: import org.apache.poi.hslf.record.TextHeaderAtom;
022: import org.apache.poi.hslf.usermodel.RichTextRun;
023:
024: import java.awt.*;
025:
026: /**
027: * Represents a cell in a ppt table
028: *
029: * @author Yegor Kozlov
030: */
031: public class TableCell extends TextBox {
032: protected static final int DEFAULT_WIDTH = 100;
033: protected static final int DEFAULT_HEIGHT = 40;
034:
035: private Line borderLeft;
036: private Line borderRight;
037: private Line borderTop;
038: private Line borderBottom;
039:
040: /**
041: * Create a TableCell object and initialize it from the supplied Record container.
042: *
043: * @param escherRecord <code>EscherSpContainer</code> container which holds information about this shape
044: * @param parent the parent of the shape
045: */
046: protected TableCell(EscherContainerRecord escherRecord, Shape parent) {
047: super (escherRecord, parent);
048: }
049:
050: /**
051: * Create a new TableCell. This constructor is used when a new shape is created.
052: *
053: * @param parent the parent of this Shape. For example, if this text box is a cell
054: * in a table then the parent is Table.
055: */
056: public TableCell(Shape parent) {
057: super (parent);
058:
059: setShapeType(ShapeTypes.Rectangle);
060: _txtrun.setRunType(TextHeaderAtom.HALF_BODY_TYPE);
061: _txtrun.getRichTextRuns()[0].setFlag(false, 0, false);
062: }
063:
064: protected EscherContainerRecord createSpContainer(boolean isChild) {
065: EscherContainerRecord spContainer = super
066: .createSpContainer(isChild);
067: EscherOptRecord opt = (EscherOptRecord) getEscherChild(
068: spContainer, EscherOptRecord.RECORD_ID);
069: setEscherProperty(opt, EscherProperties.TEXT__TEXTID, 0);
070: setEscherProperty(opt,
071: EscherProperties.TEXT__SIZE_TEXT_TO_FIT_SHAPE, 0x20000);
072: setEscherProperty(opt, EscherProperties.FILL__NOFILLHITTEST,
073: 0x150001);
074: setEscherProperty(opt,
075: EscherProperties.SHADOWSTYLE__SHADOWOBSURED, 0x20000);
076: setEscherProperty(opt,
077: EscherProperties.PROTECTION__LOCKAGAINSTGROUPING,
078: 0x40000);
079:
080: return spContainer;
081: }
082:
083: protected void anchorBorder(int type, Line line) {
084: Rectangle cellAnchor = getAnchor();
085: Rectangle lineAnchor = new Rectangle();
086: switch (type) {
087: case Table.BORDER_TOP:
088: lineAnchor.x = cellAnchor.x;
089: lineAnchor.y = cellAnchor.y;
090: lineAnchor.width = cellAnchor.width;
091: lineAnchor.height = 0;
092: break;
093: case Table.BORDER_RIGHT:
094: lineAnchor.x = cellAnchor.x + cellAnchor.width;
095: lineAnchor.y = cellAnchor.y;
096: lineAnchor.width = 0;
097: lineAnchor.height = cellAnchor.height;
098: break;
099: case Table.BORDER_BOTTOM:
100: lineAnchor.x = cellAnchor.x;
101: lineAnchor.y = cellAnchor.y + cellAnchor.height;
102: lineAnchor.width = cellAnchor.width;
103: lineAnchor.height = 0;
104: break;
105: case Table.BORDER_LEFT:
106: lineAnchor.x = cellAnchor.x;
107: lineAnchor.y = cellAnchor.y;
108: lineAnchor.width = 0;
109: lineAnchor.height = cellAnchor.height;
110: break;
111: default:
112: throw new IllegalArgumentException("Unknown border type: "
113: + type);
114: }
115: line.setAnchor(lineAnchor);
116: }
117:
118: public Line getBorderLeft() {
119: return borderLeft;
120: }
121:
122: public void setBorderLeft(Line line) {
123: if (line != null)
124: anchorBorder(Table.BORDER_LEFT, line);
125: this .borderLeft = line;
126: }
127:
128: public Line getBorderRight() {
129: return borderRight;
130: }
131:
132: public void setBorderRight(Line line) {
133: if (line != null)
134: anchorBorder(Table.BORDER_RIGHT, line);
135: this .borderRight = line;
136: }
137:
138: public Line getBorderTop() {
139: return borderTop;
140: }
141:
142: public void setBorderTop(Line line) {
143: if (line != null)
144: anchorBorder(Table.BORDER_TOP, line);
145: this .borderTop = line;
146: }
147:
148: public Line getBorderBottom() {
149: return borderBottom;
150: }
151:
152: public void setBorderBottom(Line line) {
153: if (line != null)
154: anchorBorder(Table.BORDER_BOTTOM, line);
155: this .borderBottom = line;
156: }
157:
158: public void setAnchor(Rectangle anchor) {
159: super.setAnchor(anchor);
160:
161: if (borderTop != null)
162: anchorBorder(Table.BORDER_TOP, borderTop);
163: if (borderRight != null)
164: anchorBorder(Table.BORDER_RIGHT, borderRight);
165: if (borderBottom != null)
166: anchorBorder(Table.BORDER_BOTTOM, borderBottom);
167: if (borderLeft != null)
168: anchorBorder(Table.BORDER_LEFT, borderLeft);
169: }
170: }
|