FileDocCategorySizeDatePackage
SimpleShape.javaAPI DocApache Poi 3.0.18863Thu May 31 18:45:28 BST 2007org.apache.poi.hslf.model

SimpleShape

public class SimpleShape extends Shape
An abstract simple (non-group) shape. This is the parent class for all primitive shapes like Line, Rectangle, etc.
author
Yegor Kozlov

Fields Summary
Constructors Summary
protected SimpleShape(EscherContainerRecord escherRecord, Shape parent)
Create a SimpleShape object and initialize it from the supplied Record container.

param
escherRecord EscherSpContainer container which holds information about this shape
param
parent the parent of the shape

        super(escherRecord, parent);
    
Methods Summary
protected org.apache.poi.ddf.EscherContainerRecordcreateSpContainer(boolean isChild)
Create a new Shape

param
isChild true if the Line is inside a group, false otherwise
return
the record container which holds this shape

        EscherContainerRecord spContainer = new EscherContainerRecord();
        spContainer.setRecordId( EscherContainerRecord.SP_CONTAINER );
        spContainer.setOptions((short)15);

        EscherSpRecord sp = new EscherSpRecord();
        int flags = EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_HASSHAPETYPE;
        if (isChild) flags |= EscherSpRecord.FLAG_CHILD;
        sp.setFlags(flags);
        spContainer.addChildRecord(sp);

        EscherOptRecord opt = new EscherOptRecord();
        opt.setRecordId(EscherOptRecord.RECORD_ID);
        spContainer.addChildRecord(opt);

        EscherRecord anchor;
        if(isChild) anchor = new EscherChildAnchorRecord();
        else {
            anchor = new EscherClientAnchorRecord();

            //hack. internal variable EscherClientAnchorRecord.shortRecord can be
            //initialized only in fillFields(). We need to set shortRecord=false;
            byte[] header = new byte[16];
            LittleEndian.putUShort(header, 0, 0);
            LittleEndian.putUShort(header, 2, 0);
            LittleEndian.putInt(header, 4, 8);
            anchor.fillFields(header, 0, null);
        }
        spContainer.addChildRecord(anchor);

        return spContainer;
    
public java.awt.ColorgetFillColor()
The color used to fill this shape.

        EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
        EscherSimpleProperty p1 = (EscherSimpleProperty)getEscherProperty(opt, EscherProperties.FILL__FILLCOLOR);
        EscherSimpleProperty p2= (EscherSimpleProperty)getEscherProperty(opt, EscherProperties.FILL__NOFILLHITTEST);

        int p2val = p2 == null ? 0 : p2.getPropertyValue();

        Color clr = null;
        if (p1 != null && (p2val  & 0x10) != 0){
            int rgb = p1.getPropertyValue();
            if (rgb >= 0x8000000) {
                int idx = rgb % 0x8000000;
                ColorSchemeAtom ca = getSheet().getColorScheme();
                rgb = ca.getColor(idx);
            }
            Color tmp = new Color(rgb, true);
            clr = new Color(tmp.getBlue(), tmp.getGreen(), tmp.getRed());
        }
        return clr;
    
public java.awt.ColorgetLineColor()

return
color of the line. If color is not set returns java.awt.Color.black

        EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);

        EscherSimpleProperty p1 = (EscherSimpleProperty)getEscherProperty(opt, EscherProperties.LINESTYLE__COLOR);
        EscherSimpleProperty p2 = (EscherSimpleProperty)getEscherProperty(opt, EscherProperties.LINESTYLE__NOLINEDRAWDASH);
        int p2val = p2 == null ? 0 : p2.getPropertyValue();
        Color clr = null;
        if (p1 != null && (p2val  & 0x8) != 0){
            int rgb = p1.getPropertyValue();
            if (rgb >= 0x8000000) {
                int idx = rgb % 0x8000000;
                ColorSchemeAtom ca = getSheet().getColorScheme();
                if(idx >= 0 && idx <= 7) rgb = ca.getColor(idx);
            }
            Color tmp = new Color(rgb, true);
            clr = new Color(tmp.getBlue(), tmp.getGreen(), tmp.getRed());
        }
        return clr;
    
public intgetLineDashing()
Gets line dashing. One of the PEN_* constants defined in this class.

return
dashing of the line.

        EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);

        EscherSimpleProperty prop = (EscherSimpleProperty)getEscherProperty(opt, EscherProperties.LINESTYLE__LINEDASHING);
        return prop == null ? Line.PEN_SOLID : prop.getPropertyValue();
    
public intgetLineStyle()
Returns line style. One of the constants defined in this class.

return
style of the line.

        EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
        EscherSimpleProperty prop = (EscherSimpleProperty)getEscherProperty(opt, EscherProperties.LINESTYLE__LINESTYLE);
        return prop == null ? Line.LINE_SIMPLE : prop.getPropertyValue();
    
public doublegetLineWidth()
Returns width of the line in in points

        EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
        EscherSimpleProperty prop = (EscherSimpleProperty)getEscherProperty(opt, EscherProperties.LINESTYLE__LINEWIDTH);
        return prop == null ? 0 : (double)prop.getPropertyValue()/EMU_PER_POINT;
    
public voidsetFillColor(java.awt.Color color)
The color used to fill this shape.

param
color the background color

        EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
        int rgb = new Color(color.getBlue(), color.getGreen(), color.getRed(), 0).getRGB();
        setEscherProperty(opt, EscherProperties.FILL__FILLCOLOR, rgb);
        setEscherProperty(opt, EscherProperties.FILL__NOFILLHITTEST, color == null ? 0x150010 : 0x150011);
    
public voidsetLineColor(java.awt.Color color)
Sets the color of line

param
color new color of the line

        EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
        int rgb = new Color(color.getBlue(), color.getGreen(), color.getRed(), 0).getRGB();
        setEscherProperty(opt, EscherProperties.LINESTYLE__COLOR, rgb);
        setEscherProperty(opt, EscherProperties.LINESTYLE__NOLINEDRAWDASH, color == null ? 0x180010 : 0x180018);
    
public voidsetLineDashing(int pen)
Sets line dashing. One of the PEN_* constants defined in this class.

param
pen new style of the line.

        EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);

        setEscherProperty(opt, EscherProperties.LINESTYLE__LINEDASHING, pen == Line.PEN_SOLID ? -1 : pen);
    
public voidsetLineStyle(int style)
Sets line style. One of the constants defined in this class.

param
style new style of the line.

        EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
        setEscherProperty(opt, EscherProperties.LINESTYLE__LINESTYLE, style == Line.LINE_SIMPLE ? -1 : style);
    
public voidsetLineWidth(double width)
Sets the width of line in in points

param
width the width of line in in points

        EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
        setEscherProperty(opt, EscherProperties.LINESTYLE__LINEWIDTH, (int)(width*EMU_PER_POINT));