org.apache.poi.xslf.usermodel.XSLFBackground Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of poi-ooxml Show documentation
Show all versions of poi-ooxml Show documentation
Apache POI - Java API To Access Microsoft Format Files
/* ====================================================================
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.xslf.usermodel;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.geom.Rectangle2D;
import org.apache.poi.POIXMLException;
import org.apache.poi.sl.draw.DrawPaint;
import org.apache.poi.sl.usermodel.Background;
import org.apache.poi.sl.usermodel.ColorStyle;
import org.apache.poi.sl.usermodel.FillStyle;
import org.apache.poi.sl.usermodel.PaintStyle;
import org.apache.poi.sl.usermodel.Placeholder;
import org.apache.poi.sl.usermodel.PaintStyle.SolidPaint;
import org.openxmlformats.schemas.drawingml.x2006.main.CTTransform2D;
import org.openxmlformats.schemas.presentationml.x2006.main.CTBackground;
/**
* Background shape
*
* @author Yegor Kozlov
*/
public class XSLFBackground extends XSLFSimpleShape
implements Background {
/* package */XSLFBackground(CTBackground shape, XSLFSheet sheet) {
super(shape, sheet);
}
@Override
public Rectangle2D getAnchor(){
Dimension pg = getSheet().getSlideShow().getPageSize();
return new Rectangle2D.Double(0, 0, pg.getWidth(), pg.getHeight());
}
@Override
public Color getFillColor(){
FillStyle fs = getFillStyle();
PaintStyle ps = fs.getPaint();
if (ps instanceof SolidPaint) {
SolidPaint sp = (SolidPaint)ps;
ColorStyle cs = sp.getSolidColor();
return DrawPaint.applyColorTransform(cs);
}
return null;
}
/**
* background does not have a associated transform.
* we return a dummy transform object to prevent exceptions in inherited methods.
*
* @return dummy CTTransform2D bean
*/
@Override
protected CTTransform2D getXfrm() {
return CTTransform2D.Factory.newInstance();
}
@Override
public void setPlaceholder(Placeholder placeholder) {
// extending XSLFSimpleShape is a bit unlucky ...
throw new POIXMLException("Can't set a placeholder for a background");
}
}