simpleshape.java

来自「EXCEL read and write」· Java 代码 · 共 402 行 · 第 1/2 页

JAVA
402
字号
     */    public Color getFillColor(){        return getFill().getForegroundColor();    }    /**     * The color used to fill this shape.     *     * @param color the background color     */    public void setFillColor(Color color){        getFill().setForegroundColor(color);    }    /**     * Whether the shape is horizontally flipped     *     * @return whether the shape is horizontally flipped     */     public boolean getFlipHorizontal(){        EscherSpRecord spRecord = _escherContainer.getChildById(EscherSpRecord.RECORD_ID);        return (spRecord.getFlags()& EscherSpRecord.FLAG_FLIPHORIZ) != 0;    }    /**     * Whether the shape is vertically flipped     *     * @return whether the shape is vertically flipped     */    public boolean getFlipVertical(){        EscherSpRecord spRecord = _escherContainer.getChildById(EscherSpRecord.RECORD_ID);        return (spRecord.getFlags()& EscherSpRecord.FLAG_FLIPVERT) != 0;    }    /**     * Rotation angle in degrees     *     * @return rotation angle in degrees     */    public int getRotation(){        int rot = getEscherProperty(EscherProperties.TRANSFORM__ROTATION);        int angle = (rot >> 16) % 360;        return angle;    }    public Rectangle2D getLogicalAnchor2D(){        Rectangle2D anchor = getAnchor2D();        //if it is a groupped shape see if we need to transform the coordinates        if (_parent != null){            Shape top = _parent;            while(top.getParent() != null) top = top.getParent();            Rectangle2D clientAnchor = top.getAnchor2D();            Rectangle2D spgrAnchor = ((ShapeGroup)top).getCoordinates();            double scalex = (double)spgrAnchor.getWidth()/clientAnchor.getWidth();            double scaley = (double)spgrAnchor.getHeight()/clientAnchor.getHeight();            double x = clientAnchor.getX() + (anchor.getX() - spgrAnchor.getX())/scalex;            double y = clientAnchor.getY() + (anchor.getY() - spgrAnchor.getY())/scaley;            double width = anchor.getWidth()/scalex;            double height = anchor.getHeight()/scaley;            anchor = new Rectangle2D.Double(x, y, width, height);        }        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(centerX, centerY);            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(centerX, centerY);                trans.rotate(Math.PI/2);                trans.translate(-centerX, -centerY);                anchor = trans.createTransformedShape(anchor).getBounds2D();            }        }        return anchor;    }    public void draw(Graphics2D graphics){        AffineTransform at = graphics.getTransform();        ShapePainter.paint(this, graphics);        graphics.setTransform(at);    }    /**     *  Find a record in the underlying EscherClientDataRecord     *     * @param recordType type of the record to search     */    protected Record getClientDataRecord(int recordType) {        Record[] records = getClientRecords();        if(records != null) for (int i = 0; i < records.length; i++) {            if(records[i].getRecordType() == recordType){                return records[i];            }        }        return null;    }    protected Record[] getClientRecords() {        if(_clientData == null){            EscherRecord r = Shape.getEscherChild(getSpContainer(), EscherClientDataRecord.RECORD_ID);            //ddf can return EscherContainerRecord with recordId=EscherClientDataRecord.RECORD_ID            //convert in to EscherClientDataRecord on the fly            if(!(r instanceof EscherClientDataRecord)){                byte[] data = r.serialize();                r = new EscherClientDataRecord();                r.fillFields(data, 0, new DefaultEscherRecordFactory());            }            _clientData = (EscherClientDataRecord)r;        }        if(_clientData != null && _clientRecords == null){            byte[] data = _clientData.getRemainingData();            _clientRecords = Record.findChildRecords(data, 0, data.length);        }        return _clientRecords;    }    protected void updateClientData() {        if(_clientData != null && _clientRecords != null){            ByteArrayOutputStream out = new ByteArrayOutputStream();            try {                for (int i = 0; i < _clientRecords.length; i++) {                    _clientRecords[i].writeOut(out);                }            } catch(Exception e){                throw new HSLFException(e);            }            _clientData.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().getChildRecords().add(cldata);        InteractiveInfo info = new InteractiveInfo();        InteractiveInfoAtom infoAtom = info.getInteractiveInfoAtom();        switch(link.getType()){            case Hyperlink.LINK_FIRSTSLIDE:                infoAtom.setAction(InteractiveInfoAtom.ACTION_JUMP);                infoAtom.setJump(InteractiveInfoAtom.JUMP_FIRSTSLIDE);                infoAtom.setHyperlinkType(InteractiveInfoAtom.LINK_FirstSlide);                break;            case Hyperlink.LINK_LASTSLIDE:                infoAtom.setAction(InteractiveInfoAtom.ACTION_JUMP);                infoAtom.setJump(InteractiveInfoAtom.JUMP_LASTSLIDE);                infoAtom.setHyperlinkType(InteractiveInfoAtom.LINK_LastSlide);                break;            case Hyperlink.LINK_NEXTSLIDE:                infoAtom.setAction(InteractiveInfoAtom.ACTION_JUMP);                infoAtom.setJump(InteractiveInfoAtom.JUMP_NEXTSLIDE);                infoAtom.setHyperlinkType(InteractiveInfoAtom.LINK_NextSlide);                break;            case Hyperlink.LINK_PREVIOUSSLIDE:                infoAtom.setAction(InteractiveInfoAtom.ACTION_JUMP);                infoAtom.setJump(InteractiveInfoAtom.JUMP_PREVIOUSSLIDE);                infoAtom.setHyperlinkType(InteractiveInfoAtom.LINK_PreviousSlide);                break;            case Hyperlink.LINK_URL:                infoAtom.setAction(InteractiveInfoAtom.ACTION_HYPERLINK);                infoAtom.setJump(InteractiveInfoAtom.JUMP_NONE);                infoAtom.setHyperlinkType(InteractiveInfoAtom.LINK_Url);                break;          }        infoAtom.setHyperlinkID(link.getId());        ByteArrayOutputStream out = new ByteArrayOutputStream();        try {            info.writeOut(out);        } catch(Exception e){            throw new HSLFException(e);        }        cldata.setRemainingData(out.toByteArray());    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?