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.usermodel;
019:
020: /**
021: * An abstract shape.
022: *
023: * @author Glen Stampoultzis (glens at apache.org)
024: */
025: public abstract class HSSFShape {
026: public static final int LINEWIDTH_ONE_PT = 12700;
027: public static final int LINEWIDTH_DEFAULT = 9525;
028:
029: public static final int LINESTYLE_SOLID = 0; // Solid (continuous) pen
030: public static final int LINESTYLE_DASHSYS = 1; // PS_DASH system dash style
031: public static final int LINESTYLE_DOTSYS = 2; // PS_DOT system dash style
032: public static final int LINESTYLE_DASHDOTSYS = 3; // PS_DASHDOT system dash style
033: public static final int LINESTYLE_DASHDOTDOTSYS = 4; // PS_DASHDOTDOT system dash style
034: public static final int LINESTYLE_DOTGEL = 5; // square dot style
035: public static final int LINESTYLE_DASHGEL = 6; // dash style
036: public static final int LINESTYLE_LONGDASHGEL = 7; // long dash style
037: public static final int LINESTYLE_DASHDOTGEL = 8; // dash short dash
038: public static final int LINESTYLE_LONGDASHDOTGEL = 9; // long dash short dash
039: public static final int LINESTYLE_LONGDASHDOTDOTGEL = 10; // long dash short dash short dash
040: public static final int LINESTYLE_NONE = -1;
041:
042: HSSFShape parent;
043: HSSFAnchor anchor;
044: int lineStyleColor = 0x08000040;
045: int fillColor = 0x08000009;
046: int lineWidth = LINEWIDTH_DEFAULT; // 12700 = 1pt
047: int lineStyle = LINESTYLE_SOLID;
048: boolean noFill = false;
049:
050: /**
051: * Create a new shape with the specified parent and anchor.
052: */
053: HSSFShape(HSSFShape parent, HSSFAnchor anchor) {
054: this .parent = parent;
055: this .anchor = anchor;
056: }
057:
058: /**
059: * Gets the parent shape.
060: */
061: public HSSFShape getParent() {
062: return parent;
063: }
064:
065: /**
066: * @return the anchor that is used by this shape.
067: */
068: public HSSFAnchor getAnchor() {
069: return anchor;
070: }
071:
072: /**
073: * Sets a particular anchor. A top-level shape must have an anchor of
074: * HSSFClientAnchor. A child anchor must have an anchor of HSSFChildAnchor
075: *
076: * @param anchor the anchor to use.
077: * @throws IllegalArgumentException when the wrong anchor is used for
078: * this particular shape.
079: *
080: * @see HSSFChildAnchor
081: * @see HSSFClientAnchor
082: */
083: public void setAnchor(HSSFAnchor anchor) {
084: if (parent == null) {
085: if (anchor instanceof HSSFChildAnchor)
086: throw new IllegalArgumentException(
087: "Must use client anchors for shapes directly attached to sheet.");
088: } else {
089: if (anchor instanceof HSSFClientAnchor)
090: throw new IllegalArgumentException(
091: "Must use child anchors for shapes attached to groups.");
092: }
093:
094: this .anchor = anchor;
095: }
096:
097: /**
098: * The color applied to the lines of this shape.
099: */
100: public int getLineStyleColor() {
101: return lineStyleColor;
102: }
103:
104: /**
105: * The color applied to the lines of this shape.
106: */
107: public void setLineStyleColor(int lineStyleColor) {
108: this .lineStyleColor = lineStyleColor;
109: }
110:
111: /**
112: * The color applied to the lines of this shape.
113: */
114: public void setLineStyleColor(int red, int green, int blue) {
115: this .lineStyleColor = ((blue) << 16) | ((green) << 8) | red;
116: }
117:
118: /**
119: * The color used to fill this shape.
120: */
121: public int getFillColor() {
122: return fillColor;
123: }
124:
125: /**
126: * The color used to fill this shape.
127: */
128: public void setFillColor(int fillColor) {
129: this .fillColor = fillColor;
130: }
131:
132: /**
133: * The color used to fill this shape.
134: */
135: public void setFillColor(int red, int green, int blue) {
136: this .fillColor = ((blue) << 16) | ((green) << 8) | red;
137: }
138:
139: /**
140: * @return returns with width of the line in EMUs. 12700 = 1 pt.
141: */
142: public int getLineWidth() {
143: return lineWidth;
144: }
145:
146: /**
147: * Sets the width of the line. 12700 = 1 pt.
148: *
149: * @param lineWidth width in EMU's. 12700EMU's = 1 pt
150: *
151: * @see HSSFShape#LINEWIDTH_ONE_PT
152: */
153: public void setLineWidth(int lineWidth) {
154: this .lineWidth = lineWidth;
155: }
156:
157: /**
158: * @return One of the constants in LINESTYLE_*
159: */
160: public int getLineStyle() {
161: return lineStyle;
162: }
163:
164: /**
165: * Sets the line style.
166: *
167: * @param lineStyle One of the constants in LINESTYLE_*
168: */
169: public void setLineStyle(int lineStyle) {
170: this .lineStyle = lineStyle;
171: }
172:
173: /**
174: * @return true if this shape is not filled with a color.
175: */
176: public boolean isNoFill() {
177: return noFill;
178: }
179:
180: /**
181: * Sets whether this shape is filled or transparent.
182: */
183: public void setNoFill(boolean noFill) {
184: this .noFill = noFill;
185: }
186:
187: /**
188: * Count of all children and their childrens children.
189: */
190: public int countOfAllChildren() {
191: return 1;
192: }
193: }
|