KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > poi > hssf > usermodel > HSSFShape


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 package org.apache.poi.hssf.usermodel;
18
19 /**
20  * An abstract shape.
21  *
22  * @author Glen Stampoultzis (glens at apache.org)
23  */

24 public abstract class HSSFShape
25 {
26     public static final int LINEWIDTH_ONE_PT = 12700;
27     public static final int LINEWIDTH_DEFAULT = 9525;
28
29     public static final int LINESTYLE_SOLID = 0; // Solid (continuous) pen
30
public static final int LINESTYLE_DASHSYS = 1; // PS_DASH system dash style
31
public static final int LINESTYLE_DOTSYS = 2; // PS_DOT system dash style
32
public static final int LINESTYLE_DASHDOTSYS = 3; // PS_DASHDOT system dash style
33
public static final int LINESTYLE_DASHDOTDOTSYS = 4; // PS_DASHDOTDOT system dash style
34
public static final int LINESTYLE_DOTGEL = 5; // square dot style
35
public static final int LINESTYLE_DASHGEL = 6; // dash style
36
public static final int LINESTYLE_LONGDASHGEL = 7; // long dash style
37
public static final int LINESTYLE_DASHDOTGEL = 8; // dash short dash
38
public static final int LINESTYLE_LONGDASHDOTGEL = 9; // long dash short dash
39
public static final int LINESTYLE_LONGDASHDOTDOTGEL = 10; // long dash short dash short dash
40
public static final int LINESTYLE_NONE = -1;
41
42     HSSFShape parent;
43     HSSFAnchor anchor;
44     int lineStyleColor = 0x08000040;
45     int fillColor = 0x08000009;
46     int lineWidth = LINEWIDTH_DEFAULT; // 12700 = 1pt
47
int lineStyle = LINESTYLE_SOLID;
48     boolean noFill = false;
49
50     /**
51      * Create a new shape with the specified parent and anchor.
52      */

53     HSSFShape( HSSFShape parent, HSSFAnchor anchor )
54     {
55         this.parent = parent;
56         this.anchor = anchor;
57     }
58
59     /**
60      * Gets the parent shape.
61      */

62     public HSSFShape getParent()
63     {
64         return parent;
65     }
66
67     /**
68      * @return the anchor that is used by this shape.
69      */

70     public HSSFAnchor getAnchor()
71     {
72         return anchor;
73     }
74
75     /**
76      * Sets a particular anchor. A top-level shape must have an anchor of
77      * HSSFClientAnchor. A child anchor must have an anchor of HSSFChildAnchor
78      *
79      * @param anchor the anchor to use.
80      * @throws IllegalArgumentException when the wrong anchor is used for
81      * this particular shape.
82      *
83      * @see HSSFChildAnchor
84      * @see HSSFClientAnchor
85      */

86     public void setAnchor( HSSFAnchor anchor )
87     {
88         if ( parent == null )
89         {
90             if ( anchor instanceof HSSFChildAnchor )
91                 throw new IllegalArgumentException JavaDoc( "Must use client anchors for shapes directly attached to sheet." );
92         }
93         else
94         {
95             if ( anchor instanceof HSSFClientAnchor )
96                 throw new IllegalArgumentException JavaDoc( "Must use child anchors for shapes attached to groups." );
97         }
98
99         this.anchor = anchor;
100     }
101
102     /**
103      * The color applied to the lines of this shape.
104      */

105     public int getLineStyleColor()
106     {
107         return lineStyleColor;
108     }
109
110     /**
111      * The color applied to the lines of this shape.
112      */

113     public void setLineStyleColor( int lineStyleColor )
114     {
115         this.lineStyleColor = lineStyleColor;
116     }
117
118     /**
119      * The color applied to the lines of this shape.
120      */

121     public void setLineStyleColor( int red, int green, int blue )
122     {
123         this.lineStyleColor = ((blue) << 16) | ((green) << 8) | red;
124     }
125
126     /**
127      * The color used to fill this shape.
128      */

129     public int getFillColor()
130     {
131         return fillColor;
132     }
133
134     /**
135      * The color used to fill this shape.
136      */

137     public void setFillColor( int fillColor )
138     {
139         this.fillColor = fillColor;
140     }
141
142     /**
143      * The color used to fill this shape.
144      */

145     public void setFillColor( int red, int green, int blue )
146     {
147         this.fillColor = ((blue) << 16) | ((green) << 8) | red;
148     }
149
150     /**
151      * @return returns with width of the line in EMUs. 12700 = 1 pt.
152      */

153     public int getLineWidth()
154     {
155         return lineWidth;
156     }
157
158     /**
159      * Sets the width of the line. 12700 = 1 pt.
160      *
161      * @param lineWidth width in EMU's. 12700EMU's = 1 pt
162      *
163      * @see HSSFShape#LINEWIDTH_ONE_PT
164      */

165     public void setLineWidth( int lineWidth )
166     {
167         this.lineWidth = lineWidth;
168     }
169
170     /**
171      * @return One of the constants in LINESTYLE_*
172      */

173     public int getLineStyle()
174     {
175         return lineStyle;
176     }
177
178     /**
179      * Sets the line style.
180      *
181      * @param lineStyle One of the constants in LINESTYLE_*
182      */

183     public void setLineStyle( int lineStyle )
184     {
185         this.lineStyle = lineStyle;
186     }
187
188     /**
189      * @return true if this shape is not filled with a color.
190      */

191     public boolean isNoFill()
192     {
193         return noFill;
194     }
195
196     /**
197      * Sets whether this shape is filled or transparent.
198      */

199     public void setNoFill( boolean noFill )
200     {
201         this.noFill = noFill;
202     }
203
204     /**
205      * Count of all children and their childrens children.
206      */

207     public int countOfAllChildren()
208     {
209         return 1;
210     }
211 }
212
Popular Tags