Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /* ====================================================================
     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
  
         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.
 ==================================================================== */
 
 package org.apache.poi.hslf.model;
 
 import java.awt.Color;
 import java.util.List;
 
An abstract simple (non-group) shape. This is the parent class for all primitive shapes like Line, Rectangle, etc.

Author(s):
Yegor Kozlov
 
 public abstract class SimpleShape extends Shape {
 
     public final static double DEFAULT_LINE_WIDTH = 0.75;

    
Records stored in EscherClientDataRecord
 
     protected Record[] _clientRecords;
     protected EscherClientDataRecord _clientData;

    
Create a SimpleShape object and initialize it from the supplied Record container.

Parameters:
escherRecord EscherSpContainer container which holds information about this shape
parent the parent of the shape
 
     protected SimpleShape(EscherContainerRecord escherRecordShape parent){
         super(escherRecordparent);
     }

    
Create a new Shape

Parameters:
isChild true if the Line is inside a group, false otherwise
Returns:
the record container which holds this shape
 
     protected EscherContainerRecord createSpContainer(boolean isChild) {
          = new EscherContainerRecord();
         .setOptions((short)15);
 
         EscherSpRecord sp = new EscherSpRecord();
         if (isChildflags |= .;
         sp.setFlags(flags);
         .addChildRecord(sp);
 
         EscherOptRecord opt = new EscherOptRecord();
         opt.setRecordId(.);
         .addChildRecord(opt);
 
         EscherRecord anchor;
         if(isChildanchor = 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);
         }
         .addChildRecord(anchor);
 
         return ;
     }

    
Returns width of the line in in points
    public double getLineWidth(){
        double width = prop == null ?  : (double)prop.getPropertyValue()/;
        return width;
    }

    
Sets the width of line in in points

Parameters:
width the width of line in in points
    public void setLineWidth(double width){
    }

    
Sets the color of line

Parameters:
color new color of the line
    public void setLineColor(Color color){
        if (color == null) {
            setEscherProperty(opt., 0x80000);
        } else {
            int rgb = new Color(color.getBlue(), color.getGreen(), color.getRed(), 0).getRGB();
            setEscherProperty(opt.rgb);
            setEscherProperty(opt.color == null ? 0x180010 : 0x180018);
        }
    }

    

Returns:
color of the line. If color is not set returns java.awt.Color.black
    public Color getLineColor(){
        if(p != null && (p.getPropertyValue() & 0x8) == 0) return null;
        return clr == null ? . : clr;
    }

    
Gets line dashing. One of the PEN_* constants defined in this class.

Returns:
dashing of the line.
    public int getLineDashing(){
        return prop == null ? . : prop.getPropertyValue();
    }

    
Sets line dashing. One of the PEN_* constants defined in this class.

Parameters:
pen new style of the line.
    public void setLineDashing(int pen){
        setEscherProperty(opt.pen == . ? -1 : pen);
    }

    
Sets line style. One of the constants defined in this class.

Parameters:
style new style of the line.
    public void setLineStyle(int style){
        setEscherProperty(opt.style == . ? -1 : style);
    }

    
Returns line style. One of the constants defined in this class.

Returns:
style of the line.
    public int getLineStyle(){
        return prop == null ? . : prop.getPropertyValue();
    }

    
The color used to fill this shape.
    public Color getFillColor(){
        return getFill().getForegroundColor();
    }

    
The color used to fill this shape.

Parameters:
color the background color
    public void setFillColor(Color color){
        getFill().setForegroundColor(color);
    }

    
Whether the shape is horizontally flipped

Returns:
whether the shape is horizontally flipped
     public boolean getFlipHorizontal(){
        return (spRecord.getFlags()& .) != 0;
    }

    
Whether the shape is vertically flipped

Returns:
whether the shape is vertically flipped
    public boolean getFlipVertical(){
        return (spRecord.getFlags()& .) != 0;
    }

    
Rotation angle in degrees

Returns:
rotation angle in degrees
    public int getRotation(){
        int angle = (rot >> 16) % 360;
        return angle;
    }

    
Rotate this shape

Parameters:
theta the rotation angle in degrees
    public void setRotation(int theta){
        setEscherProperty(., (theta << 16));
    }

    

Returns:
'absolute' anchor of this shape relative to the parent sheet
        Rectangle2D anchor = getAnchor2D();
        //if it is a groupped shape see if we need to transform the coordinates
        if ( != null){
            List<Shapelst = new ArrayList<Shape>();
            lst.add();
            Shape top = ;
            while(top.getParent() != null) {
                top = top.getParent();
                lst.add(top);
            }
            AffineTransform tx = new AffineTransform();
            for(int i = lst.size() - 1; i >= 0; i--) {
                ShapeGroup prnt = (ShapeGroup)lst.get(i);
                Rectangle2D exterior = prnt.getAnchor2D();
                Rectangle2D interior = prnt.getCoordinates();
                double scaleX =  exterior.getWidth() / interior.getWidth();
                double scaleY = exterior.getHeight() / interior.getHeight();
                tx.translate(exterior.getX(), exterior.getY());
                tx.scale(scaleXscaleY);
                tx.translate(-interior.getX(), -interior.getY());
            }
            anchor = tx.createTransformedShape(anchor).getBounds2D();
        }
        int angle = getRotation();
        if(angle != 0){
            double centerX = anchor.getX() + anchor.getWidth()/2;
            double centerY = anchor.getY() + anchor.getHeight()/2;
            AffineTransform trans = new AffineTransform();
            trans.translate(centerXcenterY);
            trans.rotate(Math.toRadians(angle));
            trans.translate(-centerX, -centerY);
            Rectangle2D rect = trans.createTransformedShape(anchor).getBounds2D();
            if((anchor.getWidth() < anchor.getHeight() && rect.getWidth() > rect.getHeight()) ||
                (anchor.getWidth() > anchor.getHeight() && rect.getWidth() < rect.getHeight())    ){
                trans = new AffineTransform();
                trans.translate(centerXcenterY);
                trans.rotate(./2);
                trans.translate(-centerX, -centerY);
                anchor = trans.createTransformedShape(anchor).getBounds2D();
            }
        }
        return anchor;
    }
    public void draw(Graphics2D graphics){
        AffineTransform at = graphics.getTransform();
        ShapePainter.paint(thisgraphics);
        graphics.setTransform(at);
    }

    
Find a record in the underlying EscherClientDataRecord

Parameters:
recordType type of the record to search
    protected Record getClientDataRecord(int recordType) {
        Record[] records = getClientRecords();
        if(records != nullfor (int i = 0; i < records.lengthi++) {
            if(records[i].getRecordType() == recordType){
                return records[i];
            }
        }
        return null;
    }

    
Search for EscherClientDataRecord, if found, convert its contents into an array of HSLF records

Returns:
an array of HSLF records contained in the shape's EscherClientDataRecord or null
    protected Record[] getClientRecords() {
        if( == null){
            //ddf can return EscherContainerRecord with recordId=EscherClientDataRecord.RECORD_ID
            //convert in to EscherClientDataRecord on the fly
            if(r != null && !(r instanceof EscherClientDataRecord)){
                byte[] data = r.serialize();
                r = new EscherClientDataRecord();
                r.fillFields(data, 0, new DefaultEscherRecordFactory());
            }
             = (EscherClientDataRecord)r;
        }
        if( != null &&  == null){
            byte[] data = .getRemainingData();
             = Record.findChildRecords(data, 0, data.length);
        }
        return ;
    }
    protected void updateClientData() {
        if( != null &&  != null){
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            try {
                for (int i = 0; i < .i++) {
                    [i].writeOut(out);
                }
            } catch(Exception e){
                throw new HSLFException(e);
            }
            .setRemainingData(out.toByteArray());
        }
    }
    public void setHyperlink(Hyperlink link){
        if(link.getId() == -1){
            throw new HSLFException("You must call SlideShow.addHyperlink(Hyperlink link) first");
        }
        EscherClientDataRecord cldata = new EscherClientDataRecord();
        cldata.setOptions((short)0xF);
        getSpContainer().addChildRecord(cldata); // TODO - junit to prove getChildRecords().add is wrong
        InteractiveInfo info = new InteractiveInfo();
        InteractiveInfoAtom infoAtom = info.getInteractiveInfoAtom();
        switch(link.getType()){
            case .:
                infoAtom.setAction(.);
                infoAtom.setJump(.);
                infoAtom.setHyperlinkType(.);
                break;
            case .:
                infoAtom.setAction(.);
                infoAtom.setJump(.);
                infoAtom.setHyperlinkType(.);
                break;
            case .:
                infoAtom.setAction(.);
                infoAtom.setJump(.);
                infoAtom.setHyperlinkType(.);
                break;
            case .:
                infoAtom.setAction(.);
                infoAtom.setJump(.);
                infoAtom.setHyperlinkType(.);
                break;
            case .:
                infoAtom.setAction(.);
                infoAtom.setJump(.);
                infoAtom.setHyperlinkType(.);
                break;
            case .:
                infoAtom.setAction(.);
                infoAtom.setJump(.);
                infoAtom.setHyperlinkType(.);
                break;
        }
        infoAtom.setHyperlinkID(link.getId());
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        try {
            info.writeOut(out);
        } catch(Exception e){
            throw new HSLFException(e);
        }
        cldata.setRemainingData(out.toByteArray());
    }
New to GrepCode? Check out our FAQ X