2004-04-09 13:05:39 +00:00
|
|
|
/* ====================================================================
|
2006-12-22 19:18:16 +00:00
|
|
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
|
contributor license agreements. See the NOTICE file distributed with
|
|
|
|
|
this work for additional information regarding copyright ownership.
|
|
|
|
|
The ASF licenses this file to You under the Apache License, Version 2.0
|
|
|
|
|
(the "License"); you may not use this file except in compliance with
|
|
|
|
|
the License. You may obtain a copy of the License at
|
2004-04-09 13:05:39 +00:00
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
|
limitations under the License.
|
|
|
|
|
==================================================================== */
|
2004-08-23 08:52:54 +00:00
|
|
|
|
2004-04-09 11:45:38 +00:00
|
|
|
package org.apache.poi.hssf.usermodel;
|
|
|
|
|
|
2012-06-08 17:47:37 +00:00
|
|
|
import org.apache.poi.ddf.EscherContainerRecord;
|
|
|
|
|
import org.apache.poi.hssf.record.ObjRecord;
|
|
|
|
|
|
2004-04-09 11:45:38 +00:00
|
|
|
/**
|
|
|
|
|
* An abstract shape.
|
|
|
|
|
*
|
|
|
|
|
* @author Glen Stampoultzis (glens at apache.org)
|
|
|
|
|
*/
|
2009-02-13 22:11:16 +00:00
|
|
|
public abstract class HSSFShape {
|
2004-04-09 11:45:38 +00:00
|
|
|
public static final int LINEWIDTH_ONE_PT = 12700;
|
|
|
|
|
public static final int LINEWIDTH_DEFAULT = 9525;
|
|
|
|
|
|
|
|
|
|
public static final int LINESTYLE_SOLID = 0; // Solid (continuous) pen
|
|
|
|
|
public static final int LINESTYLE_DASHSYS = 1; // PS_DASH system dash style
|
|
|
|
|
public static final int LINESTYLE_DOTSYS = 2; // PS_DOT system dash style
|
|
|
|
|
public static final int LINESTYLE_DASHDOTSYS = 3; // PS_DASHDOT system dash style
|
|
|
|
|
public static final int LINESTYLE_DASHDOTDOTSYS = 4; // PS_DASHDOTDOT system dash style
|
|
|
|
|
public static final int LINESTYLE_DOTGEL = 5; // square dot style
|
|
|
|
|
public static final int LINESTYLE_DASHGEL = 6; // dash style
|
|
|
|
|
public static final int LINESTYLE_LONGDASHGEL = 7; // long dash style
|
|
|
|
|
public static final int LINESTYLE_DASHDOTGEL = 8; // dash short dash
|
|
|
|
|
public static final int LINESTYLE_LONGDASHDOTGEL = 9; // long dash short dash
|
|
|
|
|
public static final int LINESTYLE_LONGDASHDOTDOTGEL = 10; // long dash short dash short dash
|
|
|
|
|
public static final int LINESTYLE_NONE = -1;
|
|
|
|
|
|
2009-02-13 22:11:16 +00:00
|
|
|
// TODO - make all these fields private
|
2012-06-08 17:47:37 +00:00
|
|
|
HSSFShape parent;
|
2004-04-09 11:45:38 +00:00
|
|
|
HSSFAnchor anchor;
|
2011-07-20 07:38:01 +00:00
|
|
|
HSSFPatriarch _patriarch;
|
2009-02-13 22:11:16 +00:00
|
|
|
private int _lineStyleColor = 0x08000040;
|
|
|
|
|
int _fillColor = 0x08000009;
|
|
|
|
|
private int _lineWidth = LINEWIDTH_DEFAULT; // 12700 = 1pt
|
|
|
|
|
private int _lineStyle = LINESTYLE_SOLID;
|
|
|
|
|
private boolean _noFill = false;
|
2004-04-09 11:45:38 +00:00
|
|
|
|
2012-06-08 17:47:37 +00:00
|
|
|
private EscherContainerRecord spContainer;
|
|
|
|
|
private ObjRecord objRecord;
|
|
|
|
|
|
|
|
|
|
public HSSFShape(EscherContainerRecord spContainer, ObjRecord objRecord){
|
|
|
|
|
this.spContainer = spContainer;
|
|
|
|
|
this.objRecord = objRecord;
|
|
|
|
|
}
|
2004-04-09 11:45:38 +00:00
|
|
|
/**
|
|
|
|
|
* Create a new shape with the specified parent and anchor.
|
|
|
|
|
*/
|
2012-06-08 17:47:37 +00:00
|
|
|
public HSSFShape( HSSFShape parent, HSSFAnchor anchor )
|
2004-04-09 11:45:38 +00:00
|
|
|
{
|
|
|
|
|
this.parent = parent;
|
|
|
|
|
this.anchor = anchor;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-08 17:47:37 +00:00
|
|
|
public EscherContainerRecord getSpContainer() {
|
|
|
|
|
return spContainer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ObjRecord getObjRecord() {
|
|
|
|
|
return objRecord;
|
|
|
|
|
}
|
|
|
|
|
|
2004-04-09 11:45:38 +00:00
|
|
|
/**
|
|
|
|
|
* Gets the parent shape.
|
|
|
|
|
*/
|
|
|
|
|
public HSSFShape getParent()
|
|
|
|
|
{
|
|
|
|
|
return parent;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return the anchor that is used by this shape.
|
|
|
|
|
*/
|
|
|
|
|
public HSSFAnchor getAnchor()
|
|
|
|
|
{
|
|
|
|
|
return anchor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sets a particular anchor. A top-level shape must have an anchor of
|
|
|
|
|
* HSSFClientAnchor. A child anchor must have an anchor of HSSFChildAnchor
|
|
|
|
|
*
|
|
|
|
|
* @param anchor the anchor to use.
|
|
|
|
|
* @throws IllegalArgumentException when the wrong anchor is used for
|
|
|
|
|
* this particular shape.
|
|
|
|
|
*
|
|
|
|
|
* @see HSSFChildAnchor
|
|
|
|
|
* @see HSSFClientAnchor
|
|
|
|
|
*/
|
|
|
|
|
public void setAnchor( HSSFAnchor anchor )
|
|
|
|
|
{
|
|
|
|
|
if ( parent == null )
|
|
|
|
|
{
|
|
|
|
|
if ( anchor instanceof HSSFChildAnchor )
|
|
|
|
|
throw new IllegalArgumentException( "Must use client anchors for shapes directly attached to sheet." );
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if ( anchor instanceof HSSFClientAnchor )
|
|
|
|
|
throw new IllegalArgumentException( "Must use child anchors for shapes attached to groups." );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.anchor = anchor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The color applied to the lines of this shape.
|
|
|
|
|
*/
|
2009-02-13 22:11:16 +00:00
|
|
|
public int getLineStyleColor() {
|
|
|
|
|
return _lineStyleColor;
|
2004-04-09 11:45:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The color applied to the lines of this shape.
|
|
|
|
|
*/
|
2009-02-13 22:11:16 +00:00
|
|
|
public void setLineStyleColor(int lineStyleColor) {
|
|
|
|
|
_lineStyleColor = lineStyleColor;
|
2004-04-09 11:45:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The color applied to the lines of this shape.
|
|
|
|
|
*/
|
2009-02-13 22:11:16 +00:00
|
|
|
public void setLineStyleColor(int red, int green, int blue) {
|
|
|
|
|
this._lineStyleColor = ((blue) << 16) | ((green) << 8) | red;
|
2004-04-09 11:45:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The color used to fill this shape.
|
|
|
|
|
*/
|
|
|
|
|
public int getFillColor()
|
|
|
|
|
{
|
2009-02-13 22:11:16 +00:00
|
|
|
return _fillColor;
|
2004-04-09 11:45:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The color used to fill this shape.
|
|
|
|
|
*/
|
2009-02-13 22:11:16 +00:00
|
|
|
public void setFillColor(int fillColor) {
|
|
|
|
|
_fillColor = fillColor;
|
2004-04-09 11:45:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The color used to fill this shape.
|
|
|
|
|
*/
|
|
|
|
|
public void setFillColor( int red, int green, int blue )
|
|
|
|
|
{
|
2009-02-13 22:11:16 +00:00
|
|
|
this._fillColor = ((blue) << 16) | ((green) << 8) | red;
|
2004-04-09 11:45:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return returns with width of the line in EMUs. 12700 = 1 pt.
|
|
|
|
|
*/
|
2009-02-13 22:11:16 +00:00
|
|
|
public int getLineWidth() {
|
|
|
|
|
return _lineWidth;
|
2004-04-09 11:45:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sets the width of the line. 12700 = 1 pt.
|
|
|
|
|
*
|
|
|
|
|
* @param lineWidth width in EMU's. 12700EMU's = 1 pt
|
|
|
|
|
*
|
|
|
|
|
* @see HSSFShape#LINEWIDTH_ONE_PT
|
|
|
|
|
*/
|
2009-02-13 22:11:16 +00:00
|
|
|
public void setLineWidth(int lineWidth) {
|
|
|
|
|
_lineWidth = lineWidth;
|
2004-04-09 11:45:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return One of the constants in LINESTYLE_*
|
|
|
|
|
*/
|
2009-02-13 22:11:16 +00:00
|
|
|
public int getLineStyle() {
|
|
|
|
|
return _lineStyle;
|
2004-04-09 11:45:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sets the line style.
|
|
|
|
|
*
|
|
|
|
|
* @param lineStyle One of the constants in LINESTYLE_*
|
|
|
|
|
*/
|
2009-02-13 22:11:16 +00:00
|
|
|
public void setLineStyle(int lineStyle) {
|
|
|
|
|
_lineStyle = lineStyle;
|
2004-04-09 11:45:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2009-02-13 22:11:16 +00:00
|
|
|
* @return <code>true</code> if this shape is not filled with a color.
|
2004-04-09 11:45:38 +00:00
|
|
|
*/
|
2009-02-13 22:11:16 +00:00
|
|
|
public boolean isNoFill() {
|
|
|
|
|
return _noFill;
|
2004-04-09 11:45:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sets whether this shape is filled or transparent.
|
|
|
|
|
*/
|
2009-02-13 22:11:16 +00:00
|
|
|
public void setNoFill(boolean noFill) {
|
|
|
|
|
_noFill = noFill;
|
2004-04-09 11:45:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2009-02-13 22:11:16 +00:00
|
|
|
* Count of all children and their children's children.
|
2004-04-09 11:45:38 +00:00
|
|
|
*/
|
2009-02-13 22:11:16 +00:00
|
|
|
public int countOfAllChildren() {
|
2004-04-09 11:45:38 +00:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
}
|