import org.apache.poi.openxml4j.exceptions.InvalidFormatException;\r
import org.apache.poi.sl.SlideShowFactory;\r
import org.apache.poi.sl.draw.Drawable;\r
-import org.apache.poi.sl.usermodel.Notes;\r
import org.apache.poi.sl.usermodel.Shape;\r
import org.apache.poi.sl.usermodel.ShapeContainer;\r
import org.apache.poi.sl.usermodel.Slide;\r
import org.apache.poi.util.JvmBugs;\r
\r
public abstract class SlideShowHandler extends POIFSFileHandler {\r
- public void handleSlideShow(SlideShow ss) throws IOException {\r
+ public void handleSlideShow(SlideShow<?,?> ss) throws IOException {\r
renderSlides(ss);\r
\r
readContent(ss);\r
readContent(ss);\r
\r
// read in the writen file\r
- SlideShow read;\r
+ SlideShow<?,?> read;\r
try {\r
read = SlideShowFactory.create(new ByteArrayInputStream(out.toByteArray()));\r
} catch (InvalidFormatException e) {\r
\r
}\r
\r
- private ByteArrayOutputStream writeToArray(SlideShow ss) throws IOException {\r
+ private ByteArrayOutputStream writeToArray(SlideShow<?,?> ss) throws IOException {\r
ByteArrayOutputStream stream = new ByteArrayOutputStream();\r
try {\r
ss.write(stream);\r
}\r
\r
\r
- private void readContent(SlideShow ss) {\r
- for (Slide<?,?,? extends Notes<?,?>> s : ss.getSlides()) {\r
+ private void readContent(SlideShow<?,?> ss) {\r
+ for (Slide<?,?> s : ss.getSlides()) {\r
s.getTitle();\r
readText(s);\r
readText(s.getNotes());\r
}\r
}\r
\r
- @SuppressWarnings("unchecked")\r
- private void readText(ShapeContainer<?> sc) {\r
+ private void readText(ShapeContainer<?,?> sc) {\r
if (sc == null) return;\r
- for (Shape s : sc) {\r
+ for (Shape<?,?> s : sc) {\r
if (s instanceof TextShape) {\r
- for (TextParagraph<? extends TextRun> tp : (TextShape<TextParagraph<? extends TextRun>>)s) {\r
+ for (TextParagraph<?,?,?> tp : (TextShape<?,?>)s) {\r
for (TextRun tr : tp) {\r
tr.getRawText();\r
}\r
}\r
}\r
\r
- private void renderSlides(SlideShow ss) {\r
+ private void renderSlides(SlideShow<?,?> ss) {\r
Dimension pgsize = ss.getPageSize();\r
\r
- for (Slide<?,?,?> s : ss.getSlides()) {\r
+ for (Slide<?,?> s : ss.getSlides()) {\r
BufferedImage img = new BufferedImage(pgsize.width, pgsize.height, BufferedImage.TYPE_INT_ARGB);\r
Graphics2D graphics = img.createGraphics();\r
fixFonts(graphics);\r
}
public void addChildBefore(EscherRecord record, int insertBeforeRecordId) {
- for (int i = 0; i < _childRecords.size(); i++) {
- EscherRecord rec = _childRecords.get(i);
- if(rec.getRecordId() == insertBeforeRecordId){
- _childRecords.add(i++, record);
- // TODO - keep looping? Do we expect multiple matches?
- }
+ int idx = 0;
+ for (EscherRecord rec : _childRecords) {
+ if(rec.getRecordId() == (short)insertBeforeRecordId) break;
+ // TODO - keep looping? Do we expect multiple matches?
+ idx++;
}
+ _childRecords.add(idx, record);
}
public String toString()
import org.apache.poi.sl.usermodel.*;\r
\r
\r
-public class DrawAutoShape<T extends AutoShape<? extends TextParagraph<? extends TextRun>>> extends DrawTextShape<T> {\r
- public DrawAutoShape(T shape) {\r
+public class DrawAutoShape extends DrawTextShape {\r
+ public DrawAutoShape(AutoShape<?,?> shape) {\r
super(shape);\r
}\r
}\r
\r
package org.apache.poi.sl.draw;\r
\r
-import java.awt.*;\r
+import java.awt.Dimension;\r
+import java.awt.Graphics2D;\r
+import java.awt.Paint;\r
import java.awt.geom.Rectangle2D;\r
\r
-import org.apache.poi.sl.usermodel.*;\r
-import org.apache.poi.sl.usermodel.Shape;\r
+import org.apache.poi.sl.usermodel.Background;\r
+import org.apache.poi.sl.usermodel.PlaceableShape;\r
+import org.apache.poi.sl.usermodel.ShapeContainer;\r
\r
\r
-public class DrawBackground<T extends Background> extends DrawShape<T> {\r
- public DrawBackground(T shape) {\r
+public class DrawBackground extends DrawShape {\r
+ public DrawBackground(Background<?,?> shape) {\r
super(shape);\r
}\r
\r
+ @SuppressWarnings("rawtypes")\r
public void draw(Graphics2D graphics) {\r
Dimension pg = shape.getSheet().getSlideShow().getPageSize();\r
final Rectangle2D anchor = new Rectangle2D.Double(0, 0, pg.getWidth(), pg.getHeight());\r
\r
- PlaceableShape ps = new PlaceableShape(){\r
- public ShapeContainer<? extends Shape> getParent() { return null; }\r
+ PlaceableShape<?,?> ps = new PlaceableShape(){\r
+ public ShapeContainer<?,?> getParent() { return null; }\r
public Rectangle2D getAnchor() { return anchor; }\r
public void setAnchor(Rectangle2D anchor) {}\r
public double getRotation() { return 0; }\r
\r
DrawFactory drawFact = DrawFactory.getInstance(graphics);\r
DrawPaint dp = drawFact.getPaint(ps);\r
- Paint fill = dp.getPaint(graphics, shape.getFillStyle().getPaint());\r
+ Paint fill = dp.getPaint(graphics, getShape().getFillStyle().getPaint());\r
Rectangle2D anchor2 = getAnchor(graphics, anchor);\r
\r
if(fill != null) {\r
}\r
}\r
\r
- \r
+ protected Background<?,?> getShape() {\r
+ return (Background<?,?>)shape;\r
+ }\r
}\r
\r
package org.apache.poi.sl.draw;\r
\r
-import org.apache.poi.sl.usermodel.*;\r
+import org.apache.poi.sl.usermodel.ConnectorShape;\r
\r
-public class DrawConnectorShape<T extends ConnectorShape> extends DrawSimpleShape<T> {\r
- public DrawConnectorShape(T shape) {\r
+public class DrawConnectorShape extends DrawSimpleShape {\r
+ public DrawConnectorShape(ConnectorShape<?,?> shape) {\r
super(shape);\r
}\r
}\r
import org.apache.poi.sl.usermodel.FreeformShape;\r
import org.apache.poi.sl.usermodel.GroupShape;\r
import org.apache.poi.sl.usermodel.MasterSheet;\r
-import org.apache.poi.sl.usermodel.Notes;\r
import org.apache.poi.sl.usermodel.PictureShape;\r
import org.apache.poi.sl.usermodel.PlaceableShape;\r
import org.apache.poi.sl.usermodel.Shape;\r
import org.apache.poi.sl.usermodel.Sheet;\r
import org.apache.poi.sl.usermodel.Slide;\r
-import org.apache.poi.sl.usermodel.SlideShow;\r
import org.apache.poi.sl.usermodel.TableShape;\r
import org.apache.poi.sl.usermodel.TextBox;\r
import org.apache.poi.sl.usermodel.TextParagraph;\r
-import org.apache.poi.sl.usermodel.TextRun;\r
import org.apache.poi.sl.usermodel.TextShape;\r
\r
public class DrawFactory {\r
return factory;\r
}\r
\r
- @SuppressWarnings("unchecked")\r
- public Drawable getDrawable(Shape shape) {\r
+ public Drawable getDrawable(Shape<?,?> shape) {\r
if (shape instanceof TextBox) {\r
- return getDrawable((TextBox<? extends TextParagraph<? extends TextRun>>)shape);\r
+ return getDrawable((TextBox<?,?>)shape);\r
} else if (shape instanceof FreeformShape) {\r
- return getDrawable((FreeformShape<? extends TextParagraph<? extends TextRun>>)shape);\r
+ return getDrawable((FreeformShape<?,?>)shape);\r
} else if (shape instanceof TextShape) {\r
- return getDrawable((TextShape<? extends TextParagraph<? extends TextRun>>)shape);\r
+ return getDrawable((TextShape<?,?>)shape);\r
+ } else if (shape instanceof TableShape) {\r
+ return getDrawable((TableShape<?,?>)shape);\r
} else if (shape instanceof GroupShape) {\r
- return getDrawable((GroupShape<? extends Shape>)shape);\r
+ return getDrawable((GroupShape<?,?>)shape);\r
} else if (shape instanceof PictureShape) {\r
- return getDrawable((PictureShape)shape);\r
+ return getDrawable((PictureShape<?,?>)shape);\r
} else if (shape instanceof Background) {\r
- return getDrawable((Background)shape);\r
+ return getDrawable((Background<?,?>)shape);\r
} else if (shape instanceof ConnectorShape) {\r
- return getDrawable((ConnectorShape)shape);\r
- } else if (shape instanceof TableShape) {\r
- return getDrawable((TableShape)shape);\r
+ return getDrawable((ConnectorShape<?,?>)shape);\r
} else if (shape instanceof Slide) {\r
- return getDrawable((Slide<? extends Shape, ? extends SlideShow, ? extends Notes<?,?>>)shape);\r
+ return getDrawable((Slide<?,?>)shape);\r
} else if (shape instanceof MasterSheet) {\r
- return getDrawable((MasterSheet<? extends Shape, ? extends SlideShow>)shape);\r
+ return getDrawable((MasterSheet<?,?>)shape);\r
} else if (shape instanceof Sheet) {\r
- return getDrawable((Sheet<? extends Shape, ? extends SlideShow>)shape);\r
+ return getDrawable((Sheet<?,?>)shape);\r
} else if (shape.getClass().isAnnotationPresent(DrawNotImplemented.class)) {\r
- return new DrawNothing<Shape>(shape);\r
+ return new DrawNothing(shape);\r
}\r
\r
throw new IllegalArgumentException("Unsupported shape type: "+shape.getClass());\r
}\r
\r
- public <T extends Slide<? extends Shape, ? extends SlideShow, ? extends Notes<?,?>>> DrawSlide<T> getDrawable(T sheet) {\r
- return new DrawSlide<T>(sheet);\r
+ public DrawSlide getDrawable(Slide<?,?> sheet) {\r
+ return new DrawSlide(sheet);\r
}\r
\r
- public <T extends Sheet<? extends Shape, ? extends SlideShow>> DrawSheet<T> getDrawable(T sheet) {\r
- return new DrawSheet<T>(sheet);\r
+ public DrawSheet getDrawable(Sheet<?,?> sheet) {\r
+ return new DrawSheet(sheet);\r
}\r
\r
- public <T extends MasterSheet<? extends Shape, ? extends SlideShow>> DrawMasterSheet<T> getDrawable(T sheet) {\r
- return new DrawMasterSheet<T>(sheet);\r
+ public DrawMasterSheet getDrawable(MasterSheet<?,?> sheet) {\r
+ return new DrawMasterSheet(sheet);\r
}\r
\r
- public <T extends TextBox<? extends TextParagraph<?>>> DrawTextBox<T> getDrawable(T shape) {\r
- return new DrawTextBox<T>(shape);\r
+ public DrawTextBox getDrawable(TextBox<?,?> shape) {\r
+ return new DrawTextBox(shape);\r
}\r
\r
- public <T extends FreeformShape<? extends TextParagraph<? extends TextRun>>> DrawFreeformShape<T> getDrawable(T shape) {\r
- return new DrawFreeformShape<T>(shape);\r
+ public DrawFreeformShape getDrawable(FreeformShape<?,?> shape) {\r
+ return new DrawFreeformShape(shape);\r
}\r
\r
- public <T extends ConnectorShape> DrawConnectorShape<T> getDrawable(T shape) {\r
- return new DrawConnectorShape<T>(shape);\r
+ public DrawConnectorShape getDrawable(ConnectorShape<?,?> shape) {\r
+ return new DrawConnectorShape(shape);\r
}\r
\r
- public <T extends TableShape> DrawTableShape<T> getDrawable(T shape) {\r
- return new DrawTableShape<T>(shape);\r
+ public DrawTableShape getDrawable(TableShape<?,?> shape) {\r
+ return new DrawTableShape(shape);\r
}\r
\r
- public <T extends TextShape<? extends TextParagraph<? extends TextRun>>> DrawTextShape<T> getDrawable(T shape) {\r
- return new DrawTextShape<T>(shape);\r
+ public DrawTextShape getDrawable(TextShape<?,?> shape) {\r
+ return new DrawTextShape(shape);\r
}\r
\r
- public <T extends GroupShape<? extends Shape>> DrawGroupShape<T> getDrawable(T shape) {\r
- return new DrawGroupShape<T>(shape);\r
+ public DrawGroupShape getDrawable(GroupShape<?,?> shape) {\r
+ return new DrawGroupShape(shape);\r
}\r
\r
- public <T extends PictureShape> DrawPictureShape<T> getDrawable(T shape) {\r
- return new DrawPictureShape<T>(shape);\r
+ public DrawPictureShape getDrawable(PictureShape<?,?> shape) {\r
+ return new DrawPictureShape(shape);\r
}\r
\r
- public <T extends TextRun> DrawTextParagraph<T> getDrawable(TextParagraph<T> paragraph) {\r
- return new DrawTextParagraph<T>(paragraph);\r
+ public DrawTextParagraph getDrawable(TextParagraph<?,?,?> paragraph) {\r
+ return new DrawTextParagraph(paragraph);\r
}\r
\r
- public <T extends Background> DrawBackground<T> getDrawable(T shape) {\r
- return new DrawBackground<T>(shape);\r
+ public DrawBackground getDrawable(Background<?,?> shape) {\r
+ return new DrawBackground(shape);\r
}\r
\r
public DrawTextFragment getTextFragment(TextLayout layout, AttributedString str) {\r
return new DrawTextFragment(layout, str);\r
}\r
\r
- public DrawPaint getPaint(PlaceableShape shape) {\r
+ public DrawPaint getPaint(PlaceableShape<?,?> shape) {\r
return new DrawPaint(shape);\r
}\r
}\r
import org.apache.poi.sl.usermodel.FillStyle;\r
import org.apache.poi.sl.usermodel.FreeformShape;\r
import org.apache.poi.sl.usermodel.StrokeStyle;\r
-import org.apache.poi.sl.usermodel.TextParagraph;\r
-import org.apache.poi.sl.usermodel.TextRun;\r
\r
-public class DrawFreeformShape<T extends FreeformShape<? extends TextParagraph<? extends TextRun>>> extends DrawAutoShape<T> {\r
- public DrawFreeformShape(T shape) {\r
+public class DrawFreeformShape extends DrawAutoShape {\r
+ public DrawFreeformShape(FreeformShape<?,?> shape) {\r
super(shape);\r
}\r
\r
protected Collection<Outline> computeOutlines(Graphics2D graphics) {\r
List<Outline> lst = new ArrayList<Outline>();\r
- java.awt.Shape sh = shape.getPath();\r
- FillStyle fs = shape.getFillStyle();\r
- StrokeStyle ss = shape.getStrokeStyle();\r
+ java.awt.Shape sh = getShape().getPath();\r
+ FillStyle fs = getShape().getFillStyle();\r
+ StrokeStyle ss = getShape().getStrokeStyle();\r
Path path = new Path(fs != null, ss != null);\r
lst.add(new Outline(sh, path));\r
return lst;\r
}\r
+\r
+ @Override\r
+ protected FreeformShape<?,?> getShape() {\r
+ return (FreeformShape<?,?>)shape;\r
+ }\r
}\r
import org.apache.poi.sl.usermodel.*;\r
\r
\r
-public class DrawGroupShape<T extends GroupShape<? extends Shape>> extends DrawShape<T> implements Drawable {\r
+public class DrawGroupShape extends DrawShape {\r
\r
- public DrawGroupShape(T shape) {\r
+ public DrawGroupShape(GroupShape<?,?> shape) {\r
super(shape);\r
}\r
\r
public void draw(Graphics2D graphics) {\r
\r
// the coordinate system of this group of shape\r
- Rectangle2D interior = shape.getInteriorAnchor();\r
+ Rectangle2D interior = getShape().getInteriorAnchor();\r
// anchor of this group relative to the parent shape\r
- Rectangle2D exterior = shape.getAnchor();\r
+ Rectangle2D exterior = getShape().getAnchor();\r
\r
AffineTransform tx = (AffineTransform)graphics.getRenderingHint(Drawable.GROUP_TRANSFORM);\r
AffineTransform tx0 = new AffineTransform(tx);\r
DrawFactory drawFact = DrawFactory.getInstance(graphics);\r
AffineTransform at2 = graphics.getTransform();\r
\r
- for (Shape child : shape) {\r
+ for (Shape<?,?> child : getShape()) {\r
// remember the initial transform and restore it after we are done with the drawing\r
AffineTransform at = graphics.getTransform();\r
graphics.setRenderingHint(Drawable.GSAVE, true);\r
graphics.setTransform(at2);\r
graphics.setRenderingHint(Drawable.GROUP_TRANSFORM, tx0);\r
}\r
+\r
+ @Override\r
+ protected GroupShape<?,?> getShape() {\r
+ return (GroupShape<?,?>)shape;\r
+ }\r
}\r
import org.apache.poi.sl.usermodel.*;\r
\r
\r
-public class DrawMasterSheet<T extends MasterSheet<? extends Shape, ? extends SlideShow>> extends DrawSheet<T> {\r
+public class DrawMasterSheet extends DrawSheet {\r
\r
- public DrawMasterSheet(T sheet) {\r
+ public DrawMasterSheet(MasterSheet<?,?> sheet) {\r
super(sheet);\r
}\r
\r
* Subclasses can override it and skip certain shapes from drawings,\r
* for instance, slide masters and layouts don't display placeholders\r
*/\r
- protected boolean canDraw(Shape shape){\r
- return !(shape instanceof SimpleShape) || !((SimpleShape)shape).isPlaceholder();\r
+ @Override\r
+ protected boolean canDraw(Shape<?,?> shape){\r
+ return !(shape instanceof SimpleShape) || !((SimpleShape<?,?>)shape).isPlaceholder();\r
}\r
}\r
import org.apache.poi.sl.usermodel.Shape;\r
\r
\r
-public class DrawNothing<T extends Shape> implements Drawable {\r
+public class DrawNothing implements Drawable {\r
\r
- protected final T shape;\r
+ protected final Shape<?,?> shape;\r
\r
- public DrawNothing(T shape) {\r
+ public DrawNothing(Shape<?,?> shape) {\r
this.shape = shape;\r
}\r
\r
\r
private final static POILogger LOG = POILogFactory.getLogger(DrawPaint.class);\r
\r
- protected PlaceableShape shape;\r
+ protected PlaceableShape<?,?> shape;\r
\r
- public DrawPaint(PlaceableShape shape) {\r
+ public DrawPaint(PlaceableShape<?,?> shape) {\r
this.shape = shape;\r
}\r
\r
import org.apache.poi.sl.usermodel.PictureShape;\r
\r
\r
-public class DrawPictureShape<T extends PictureShape> extends DrawSimpleShape<T> {\r
- public DrawPictureShape(T shape) {\r
+public class DrawPictureShape extends DrawSimpleShape {\r
+ public DrawPictureShape(PictureShape<?,?> shape) {\r
super(shape);\r
}\r
\r
@Override\r
public void drawContent(Graphics2D graphics) {\r
- PictureData data = shape.getPictureData();\r
+ PictureData data = getShape().getPictureData();\r
if(data == null) return;\r
\r
ImageRenderer renderer = (ImageRenderer)graphics.getRenderingHint(Drawable.IMAGE_RENDERER);\r
if (renderer == null) renderer = new ImageRenderer();\r
\r
- Rectangle2D anchor = getAnchor(graphics, shape);\r
+ Rectangle2D anchor = getAnchor(graphics, getShape());\r
\r
- Insets insets = shape.getClipping();\r
+ Insets insets = getShape().getClipping();\r
\r
try {\r
renderer.loadImage(data.getData(), data.getContentType());\r
throw new RuntimeException(e);\r
}\r
} \r
+\r
+ @Override\r
+ protected PictureShape<?,?> getShape() {\r
+ return (PictureShape<?,?>)shape;\r
+ }\r
}\r
import org.apache.poi.sl.usermodel.Shape;\r
\r
\r
-public class DrawShape<T extends Shape> implements Drawable {\r
+public class DrawShape implements Drawable {\r
\r
- protected final T shape;\r
- \r
- public DrawShape(T shape) {\r
+ protected final Shape<?,?> shape;\r
+\r
+ public DrawShape(Shape<?,?> shape) {\r
this.shape = shape;\r
}\r
- \r
+\r
/**\r
* Apply 2-D transforms before drawing this shape. This includes rotation and flipping.\r
*\r
*/\r
public void applyTransform(Graphics2D graphics) {\r
if (!(shape instanceof PlaceableShape)) return;\r
- \r
- PlaceableShape ps = (PlaceableShape)shape;\r
+\r
+ PlaceableShape<?,?> ps = (PlaceableShape<?,?>)shape;\r
AffineTransform tx = (AffineTransform)graphics.getRenderingHint(Drawable.GROUP_TRANSFORM);\r
if (tx == null) tx = new AffineTransform();\r
final Rectangle2D anchor = tx.createTransformedShape(ps.getAnchor()).getBounds2D();\r
\r
int quadrant = (((int)rotation+45)/90)%4;\r
double scaleX = 1.0, scaleY = 1.0;\r
- \r
+\r
// scale to bounding box (bug #53176)\r
if (quadrant == 1 || quadrant == 3) {\r
- // In quadrant 1 and 3, which is basically a shape in a more or less portrait orientation \r
- // (45-135 degrees and 225-315 degrees), we need to first rotate the shape by a multiple \r
- // of 90 degrees and then resize the bounding box to its original bbox. After that we can \r
+ // In quadrant 1 and 3, which is basically a shape in a more or less portrait orientation\r
+ // (45-135 degrees and 225-315 degrees), we need to first rotate the shape by a multiple\r
+ // of 90 degrees and then resize the bounding box to its original bbox. After that we can\r
// rotate the shape to the exact rotation amount.\r
// It's strange that you'll need to rotate the shape back and forth again, but you can\r
// think of it, as if you paint the shape on a canvas. First you rotate the canvas, which might\r
txs.translate(-centerX, -centerY);\r
txs.concatenate(tx);\r
}\r
- \r
+\r
txs.translate(centerX, centerY);\r
txs.rotate(Math.PI/2.);\r
txs.translate(-centerX, -centerY);\r
- \r
+\r
Rectangle2D anchor2 = txs.createTransformedShape(ps.getAnchor()).getBounds2D();\r
- \r
+\r
scaleX = anchor.getWidth() == 0. ? 1.0 : anchor.getWidth() / anchor2.getWidth();\r
scaleY = anchor.getHeight() == 0. ? 1.0 : anchor.getHeight() / anchor2.getHeight();\r
} else {\r
quadrant = 0;\r
}\r
- \r
+\r
// transformation is applied reversed ...\r
graphics.translate(centerX, centerY);\r
graphics.rotate(Math.toRadians(rotation-quadrant*90.));\r
public void draw(Graphics2D graphics) {\r
}\r
\r
- public void drawContent(Graphics2D context) {\r
+ public void drawContent(Graphics2D graphics) {\r
}\r
\r
- public static Rectangle2D getAnchor(Graphics2D graphics, PlaceableShape shape) {\r
+ public static Rectangle2D getAnchor(Graphics2D graphics, PlaceableShape<?,?> shape) {\r
return getAnchor(graphics, shape.getAnchor());\r
}\r
- \r
+\r
public static Rectangle2D getAnchor(Graphics2D graphics, Rectangle2D anchor) {\r
if(graphics == null) {\r
return anchor;\r
anchor = tx.createTransformedShape(anchor).getBounds2D();\r
}\r
return anchor;\r
- } \r
+ }\r
+ \r
+ protected Shape<?,?> getShape() {\r
+ return shape;\r
+ }\r
}\r
import org.apache.poi.sl.usermodel.*;\r
\r
\r
-public class DrawSheet<T extends Sheet<? extends Shape, ? extends SlideShow>> implements Drawable {\r
+public class DrawSheet implements Drawable {\r
\r
- protected final T sheet;\r
+ protected final Sheet<?,?> sheet;\r
\r
- public DrawSheet(T sheet) {\r
+ public DrawSheet(Sheet<?,?> sheet) {\r
this.sheet = sheet;\r
}\r
\r
graphics.fillRect(0, 0, (int)dim.getWidth(), (int)dim.getHeight());\r
\r
DrawFactory drawFact = DrawFactory.getInstance(graphics);\r
- MasterSheet<? extends Shape, ? extends SlideShow> master = sheet.getMasterSheet();\r
+ MasterSheet<?,?> master = sheet.getMasterSheet();\r
\r
if(sheet.getFollowMasterGraphics() && master != null) {\r
Drawable drawer = drawFact.getDrawable(master);\r
\r
graphics.setRenderingHint(Drawable.GROUP_TRANSFORM, new AffineTransform());\r
\r
- for (Shape shape : sheet.getShapes()) {\r
+ for (Shape<?,?> shape : sheet.getShapes()) {\r
if(!canDraw(shape)) continue;\r
\r
// remember the initial transform and restore it after we are done with drawing\r
* Subclasses can override it and skip certain shapes from drawings,\r
* for instance, slide masters and layouts don't display placeholders\r
*/\r
- protected boolean canDraw(Shape shape){\r
+ protected boolean canDraw(Shape<?,?> shape){\r
return true;\r
}\r
}\r
\r
package org.apache.poi.sl.draw;\r
\r
-import java.awt.*;\r
-import java.awt.geom.*;\r
-import java.io.*;\r
+import java.awt.BasicStroke;\r
+import java.awt.Color;\r
+import java.awt.Graphics2D;\r
+import java.awt.Paint;\r
+import java.awt.geom.AffineTransform;\r
+import java.awt.geom.Ellipse2D;\r
+import java.awt.geom.GeneralPath;\r
+import java.awt.geom.Rectangle2D;\r
+import java.io.InputStream;\r
+import java.io.InputStreamReader;\r
+import java.io.Reader;\r
import java.nio.charset.Charset;\r
-import java.util.*;\r
+import java.util.ArrayList;\r
+import java.util.Collection;\r
+import java.util.HashMap;\r
import java.util.List;\r
+import java.util.Map;\r
\r
-import javax.xml.bind.*;\r
-import javax.xml.stream.*;\r
+import javax.xml.bind.JAXBContext;\r
+import javax.xml.bind.JAXBElement;\r
+import javax.xml.bind.Unmarshaller;\r
import javax.xml.stream.EventFilter;\r
+import javax.xml.stream.XMLEventReader;\r
+import javax.xml.stream.XMLInputFactory;\r
import javax.xml.stream.events.StartElement;\r
import javax.xml.stream.events.XMLEvent;\r
\r
import org.apache.poi.sl.draw.binding.CTCustomGeometry2D;\r
-import org.apache.poi.sl.draw.geom.*;\r
-import org.apache.poi.sl.usermodel.*;\r
+import org.apache.poi.sl.draw.geom.Context;\r
+import org.apache.poi.sl.draw.geom.CustomGeometry;\r
+import org.apache.poi.sl.draw.geom.Outline;\r
+import org.apache.poi.sl.draw.geom.Path;\r
+import org.apache.poi.sl.usermodel.LineDecoration;\r
import org.apache.poi.sl.usermodel.LineDecoration.DecorationSize;\r
import org.apache.poi.sl.usermodel.PaintStyle.SolidPaint;\r
-import org.apache.poi.sl.usermodel.StrokeStyle.*;\r
+import org.apache.poi.sl.usermodel.Shadow;\r
+import org.apache.poi.sl.usermodel.SimpleShape;\r
+import org.apache.poi.sl.usermodel.StrokeStyle;\r
+import org.apache.poi.sl.usermodel.StrokeStyle.LineCap;\r
+import org.apache.poi.sl.usermodel.StrokeStyle.LineDash;\r
import org.apache.poi.util.Units;\r
\r
\r
-public class DrawSimpleShape<T extends SimpleShape> extends DrawShape<T> {\r
+public class DrawSimpleShape extends DrawShape {\r
\r
- public DrawSimpleShape(T shape) {\r
+ public DrawSimpleShape(SimpleShape<?,?> shape) {\r
super(shape);\r
}\r
\r
@Override\r
public void draw(Graphics2D graphics) {\r
- DrawPaint drawPaint = DrawFactory.getInstance(graphics).getPaint(shape);\r
- Paint fill = drawPaint.getPaint(graphics, shape.getFillStyle().getPaint());\r
- Paint line = drawPaint.getPaint(graphics, shape.getStrokeStyle().getPaint());\r
+ DrawPaint drawPaint = DrawFactory.getInstance(graphics).getPaint(getShape());\r
+ Paint fill = drawPaint.getPaint(graphics, getShape().getFillStyle().getPaint());\r
+ Paint line = drawPaint.getPaint(graphics, getShape().getStrokeStyle().getPaint());\r
BasicStroke stroke = getStroke(); // the stroke applies both to the shadow and the shape\r
graphics.setStroke(stroke);\r
\r
graphics.setPaint(line);\r
\r
List<Outline> lst = new ArrayList<Outline>();\r
- LineDecoration deco = shape.getLineDecoration();\r
+ LineDecoration deco = getShape().getLineDecoration();\r
Outline head = getHeadDecoration(graphics, deco, stroke);\r
if (head != null) lst.add(head);\r
Outline tail = getTailDecoration(graphics, deco, stroke);\r
\r
double lineWidth = Math.max(2.5, stroke.getLineWidth());\r
\r
- Rectangle2D anchor = getAnchor(graphics, shape);\r
+ Rectangle2D anchor = getAnchor(graphics, getShape());\r
double x2 = anchor.getX() + anchor.getWidth(),\r
y2 = anchor.getY() + anchor.getHeight();\r
\r
\r
double lineWidth = Math.max(2.5, stroke.getLineWidth());\r
\r
- Rectangle2D anchor = getAnchor(graphics, shape);\r
+ Rectangle2D anchor = getAnchor(graphics, getShape());\r
double x1 = anchor.getX(),\r
y1 = anchor.getY();\r
\r
}\r
\r
public BasicStroke getStroke() {\r
- StrokeStyle strokeStyle = shape.getStrokeStyle();\r
+ StrokeStyle strokeStyle = getShape().getStrokeStyle();\r
\r
float lineWidth = (float) strokeStyle.getLineWidth();\r
if (lineWidth == 0.0f) lineWidth = 0.25f; // Both PowerPoint and OOo draw zero-length lines as 0.25pt\r
, Paint fill\r
, Paint line\r
) {\r
- Shadow shadow = shape.getShadow();\r
+ Shadow shadow = getShape().getShadow();\r
if (shadow == null || (fill == null && line == null)) return;\r
\r
SolidPaint shadowPaint = shadow.getFillStyle();\r
Color shadowColor = DrawPaint.applyColorTransform(shadowPaint.getSolidColor());\r
\r
- double shapeRotation = shape.getRotation();\r
- if(shape.getFlipVertical()) {\r
+ double shapeRotation = getShape().getRotation();\r
+ if(getShape().getFlipVertical()) {\r
shapeRotation += 180;\r
}\r
double angle = shadow.getAngle() - shapeRotation;\r
protected Collection<Outline> computeOutlines(Graphics2D graphics) {\r
\r
List<Outline> lst = new ArrayList<Outline>();\r
- CustomGeometry geom = shape.getGeometry();\r
+ CustomGeometry geom = getShape().getGeometry();\r
if(geom == null) {\r
return lst;\r
}\r
\r
- Rectangle2D anchor = getAnchor(graphics, shape);\r
+ Rectangle2D anchor = getAnchor(graphics, getShape());\r
for (Path p : geom) {\r
\r
double w = p.getW() == -1 ? anchor.getWidth() * Units.EMU_PER_POINT : p.getW();\r
// so we build the path starting from (0,0).\r
final Rectangle2D pathAnchor = new Rectangle2D.Double(0,0,w,h);\r
\r
- Context ctx = new Context(geom, pathAnchor, shape);\r
+ Context ctx = new Context(geom, pathAnchor, getShape());\r
\r
java.awt.Shape gp = p.getPath(ctx);\r
\r
return lst;\r
}\r
\r
+ @Override\r
+ protected SimpleShape<?,?> getShape() {\r
+ return (SimpleShape<?,?>)shape;\r
+ }\r
}\r
import org.apache.poi.sl.usermodel.*;\r
\r
\r
-public class DrawSlide<T extends Slide<? extends Shape, ? extends SlideShow, ? extends Notes<?,?>>> extends DrawSheet<T> {\r
+public class DrawSlide extends DrawSheet {\r
\r
- public DrawSlide(T slide) {\r
+ public DrawSlide(Slide<?,?> slide) {\r
super(slide);\r
}\r
\r
public void draw(Graphics2D graphics) {\r
- Background bg = sheet.getBackground();\r
+ Background<?,?> bg = sheet.getBackground();\r
if(bg != null) {\r
DrawFactory drawFact = DrawFactory.getInstance(graphics);\r
Drawable db = drawFact.getDrawable(bg);\r
\r
package org.apache.poi.sl.draw;\r
\r
-import org.apache.poi.sl.usermodel.*;\r
+import java.awt.Graphics2D;\r
\r
-public class DrawTableShape<T extends TableShape> extends DrawShape<T> {\r
+import org.apache.poi.sl.usermodel.GroupShape;\r
+import org.apache.poi.sl.usermodel.TableShape;\r
+\r
+public class DrawTableShape extends DrawShape {\r
// to be implemented ...\r
- public DrawTableShape(T shape) {\r
+ public DrawTableShape(TableShape<?,?> shape) {\r
super(shape);\r
}\r
+ \r
+ protected Drawable getDrawable(Graphics2D graphics) {\r
+ if (shape instanceof GroupShape) {\r
+ DrawFactory df = DrawFactory.getInstance(graphics);\r
+ return df.getDrawable((GroupShape<?,?>)shape);\r
+ }\r
+ return null;\r
+ }\r
+\r
+ public void applyTransform(Graphics2D graphics) {\r
+ Drawable d = getDrawable(graphics);\r
+ if (d != null) {\r
+ d.applyTransform(graphics);\r
+ }\r
+ }\r
+\r
+ public void draw(Graphics2D graphics) {\r
+ Drawable d = getDrawable(graphics);\r
+ if (d != null) {\r
+ d.draw(graphics);\r
+ }\r
+ }\r
+\r
+ public void drawContent(Graphics2D graphics) {\r
+ Drawable d = getDrawable(graphics);\r
+ if (d != null) {\r
+ d.drawContent(graphics);\r
+ }\r
+ }\r
+\r
+ \r
}\r
\r
import org.apache.poi.sl.usermodel.*;\r
\r
-public class DrawTextBox<T extends TextBox<? extends TextParagraph<? extends TextRun>>> extends DrawAutoShape<T> {\r
- public DrawTextBox(T shape) {\r
+public class DrawTextBox extends DrawAutoShape {\r
+ public DrawTextBox(TextBox<?,?> shape) {\r
super(shape);\r
}\r
}\r
import org.apache.poi.sl.usermodel.Insets2D;\r
import org.apache.poi.sl.usermodel.PaintStyle;\r
import org.apache.poi.sl.usermodel.PlaceableShape;\r
-import org.apache.poi.sl.usermodel.Shape;\r
import org.apache.poi.sl.usermodel.ShapeContainer;\r
import org.apache.poi.sl.usermodel.TextParagraph;\r
import org.apache.poi.sl.usermodel.TextParagraph.BulletStyle;\r
import org.apache.poi.sl.usermodel.TextShape;\r
import org.apache.poi.util.Units;\r
\r
-public class DrawTextParagraph<T extends TextRun> implements Drawable {\r
- protected TextParagraph<T> paragraph;\r
+public class DrawTextParagraph implements Drawable {\r
+ protected TextParagraph<?,?,?> paragraph;\r
double x, y;\r
protected List<DrawTextFragment> lines = new ArrayList<DrawTextFragment>();\r
protected String rawText;\r
*/\r
protected double maxLineHeight;\r
\r
- public DrawTextParagraph(TextParagraph<T> paragraph) {\r
+ public DrawTextParagraph(TextParagraph<?,?,?> paragraph) {\r
this.paragraph = paragraph;\r
}\r
\r
if (buFont == null) buFont = paragraph.getDefaultFontFamily();\r
assert(buFont != null);\r
\r
- PlaceableShape ps = getParagraphShape();\r
+ PlaceableShape<?,?> ps = getParagraphShape();\r
PaintStyle fgPaintStyle = bulletStyle.getBulletFontColor();\r
Paint fgPaint;\r
if (fgPaintStyle == null) {\r
}\r
\r
double width;\r
- TextShape<? extends TextParagraph<T>> ts = paragraph.getParentShape();\r
+ TextShape<?,?> ts = paragraph.getParentShape();\r
if (!ts.getWordWrap()) {\r
// if wordWrap == false then we return the advance to the right border of the sheet\r
width = ts.getSheet().getSlideShow().getPageSize().getWidth() - anchor.getX();\r
/**\r
* Helper method for paint style relative to bounds, e.g. gradient paint\r
*/\r
- private PlaceableShape getParagraphShape() {\r
- PlaceableShape ps = new PlaceableShape(){\r
- public ShapeContainer<? extends Shape> getParent() { return null; }\r
+ @SuppressWarnings("rawtypes")\r
+ private PlaceableShape<?,?> getParagraphShape() {\r
+ PlaceableShape<?,?> ps = new PlaceableShape(){\r
+ public ShapeContainer<?,?> getParent() { return null; }\r
public Rectangle2D getAnchor() { return paragraph.getParentShape().getAnchor(); }\r
public void setAnchor(Rectangle2D anchor) {}\r
public double getRotation() { return 0; }\r
List<AttributedStringData> attList = new ArrayList<AttributedStringData>();\r
if (text == null) text = new StringBuilder();\r
\r
- PlaceableShape ps = getParagraphShape();\r
+ PlaceableShape<?,?> ps = getParagraphShape();\r
\r
DrawFontManager fontHandler = (DrawFontManager)graphics.getRenderingHint(Drawable.FONT_HANDLER);\r
\r
import org.apache.poi.sl.usermodel.TextParagraph.BulletStyle;\r
import org.apache.poi.util.JvmBugs;\r
\r
-public class DrawTextShape<T extends TextShape<? extends TextParagraph<? extends TextRun>>> extends DrawSimpleShape<T> {\r
+public class DrawTextShape extends DrawSimpleShape {\r
\r
- public DrawTextShape(T shape) {\r
+ public DrawTextShape(TextShape<?,?> shape) {\r
super(shape);\r
}\r
\r
public void drawContent(Graphics2D graphics) {\r
fixFonts(graphics);\r
\r
- Rectangle2D anchor = DrawShape.getAnchor(graphics, shape);\r
- Insets2D insets = shape.getInsets();\r
+ Rectangle2D anchor = DrawShape.getAnchor(graphics, getShape());\r
+ Insets2D insets = getShape().getInsets();\r
double x = anchor.getX() + insets.left;\r
double y = anchor.getY();\r
\r
// (see DrawShape#applyTransform ), but we need to restore it to avoid painting "upside down".\r
// See Bugzilla 54210.\r
\r
- if(shape.getFlipVertical()){\r
+ if(getShape().getFlipVertical()){\r
graphics.translate(anchor.getX(), anchor.getY() + anchor.getHeight());\r
graphics.scale(1, -1);\r
graphics.translate(-anchor.getX(), -anchor.getY());\r
\r
// Horizontal flipping applies only to shape outline and not to the text in the shape.\r
// Applying flip second time restores the original not-flipped transform\r
- if(shape.getFlipHorizontal()){\r
+ if(getShape().getFlipHorizontal()){\r
graphics.translate(anchor.getX() + anchor.getWidth(), anchor.getY());\r
graphics.scale(-1, 1);\r
graphics.translate(-anchor.getX() , -anchor.getY());\r
\r
\r
// first dry-run to calculate the total height of the text\r
- double textHeight = shape.getTextHeight();\r
+ double textHeight = getShape().getTextHeight();\r
\r
- switch (shape.getVerticalAlignment()){\r
+ switch (getShape().getVerticalAlignment()){\r
case TOP:\r
y += insets.top;\r
break;\r
DrawFactory fact = DrawFactory.getInstance(graphics);\r
\r
double y0 = y;\r
- Iterator<? extends TextParagraph<? extends TextRun>> paragraphs = shape.iterator();\r
+ Iterator<? extends TextParagraph<?,?,? extends TextRun>> paragraphs = getShape().iterator();\r
\r
boolean isFirstLine = true;\r
for (int autoNbrIdx=0; paragraphs.hasNext(); autoNbrIdx++){\r
- TextParagraph<? extends TextRun> p = paragraphs.next();\r
- DrawTextParagraph<? extends TextRun> dp = fact.getDrawable(p);\r
+ TextParagraph<?,?,? extends TextRun> p = paragraphs.next();\r
+ DrawTextParagraph dp = fact.getDrawable(p);\r
BulletStyle bs = p.getBulletStyle();\r
if (bs == null || bs.getAutoNumberingScheme() == null) {\r
autoNbrIdx = -1;\r
if (!fontMap.containsKey("Calibri")) fontMap.put("Calibri", "Lucida Sans");\r
if (!fontMap.containsKey("Cambria")) fontMap.put("Cambria", "Lucida Bright");\r
}\r
+\r
+ @Override\r
+ protected TextShape<?,?> getShape() {\r
+ return (TextShape<?,?>)shape;\r
+ }\r
}\r
package org.apache.poi.sl.usermodel;
-public interface AutoShape<T extends TextParagraph<? extends TextRun>> extends TextShape<T> {
+public interface AutoShape<
+ S extends Shape<S,P>,
+ P extends TextParagraph<S,P,? extends TextRun>
+> extends TextShape<S,P> {
}
package org.apache.poi.sl.usermodel;
-public interface Background extends Shape {
+public interface Background<
+ S extends Shape<S,P>,
+ P extends TextParagraph<S,P,? extends TextRun>
+> extends Shape<S,P> {
FillStyle getFillStyle();
}
\r
package org.apache.poi.sl.usermodel;\r
\r
-public interface ConnectorShape extends SimpleShape {\r
+public interface ConnectorShape<\r
+ S extends Shape<S,P>,\r
+ P extends TextParagraph<S,P,? extends TextRun>\r
+> extends SimpleShape<S,P> {\r
\r
}\r
\r
import java.awt.geom.GeneralPath;\r
\r
-public interface FreeformShape<T extends TextParagraph<? extends TextRun>> extends AutoShape<T> {\r
+public interface FreeformShape<\r
+ S extends Shape<S,P>,\r
+ P extends TextParagraph<S,P,? extends TextRun>\r
+> extends AutoShape<S,P> {\r
/**\r
* Gets the shape path.\r
* <p>\r
import java.awt.geom.Rectangle2D;
-public interface GroupShape<T extends Shape> extends Shape, ShapeContainer<T>, PlaceableShape {
+public interface GroupShape<
+ S extends Shape<S,P>,
+ P extends TextParagraph<S,P,? extends TextRun>
+> extends Shape<S,P>, ShapeContainer<S,P>, PlaceableShape<S,P> {
/**
* Gets the coordinate space of this group. All children are constrained
*/
@Internal
-public interface Line<T extends TextParagraph<? extends TextRun>> extends AutoShape<T> {
+public interface Line<
+ S extends Shape<S,P>,
+ P extends TextParagraph<S,P,? extends TextRun>
+> extends AutoShape<S,P> {
}
package org.apache.poi.sl.usermodel;
-public interface MasterSheet<T extends Shape, SS extends SlideShow> extends Sheet<T,SS> {
+public interface MasterSheet<
+ S extends Shape<S,P>,
+ P extends TextParagraph<S,P,? extends TextRun>
+> extends Sheet<S,P> {
}
import java.util.List;
-public interface Notes<T extends Shape, SS extends SlideShow> extends Sheet<T,SS> {
- List<? extends List<? extends TextParagraph<? extends TextRun>>> getTextParagraphs();
+public interface Notes<
+ S extends Shape<S,P>,
+ P extends TextParagraph<S,P,? extends TextRun>
+> extends Sheet<S,P> {
+ List<? extends List<P>> getTextParagraphs();
}
import java.awt.Insets;
-public interface PictureShape extends SimpleShape {
+public interface PictureShape<
+ S extends Shape<S,P>,
+ P extends TextParagraph<S,P,? extends TextRun>
+> extends SimpleShape<S,P> {
/**
* Returns the picture data for this picture.
*
\r
import java.awt.geom.Rectangle2D;\r
\r
-public interface PlaceableShape {\r
- ShapeContainer<? extends Shape> getParent();\r
+public interface PlaceableShape<\r
+ S extends Shape<S,P>,\r
+ P extends TextParagraph<S,P,? extends TextRun>\r
+> {\r
+ ShapeContainer<S,P> getParent();\r
\r
/**\r
* @return the position of this shape within the drawing canvas.\r
package org.apache.poi.sl.usermodel;
-public interface Shape {
- ShapeContainer<? extends Shape> getParent();
+public interface Shape<
+ S extends Shape<S,P>,
+ P extends TextParagraph<S,P,? extends TextRun>
+> {
+ ShapeContainer<S,P> getParent();
/**
*
* @return the sheet this shape belongs to
*/
- Sheet<? extends Shape, ? extends SlideShow> getSheet();
+ Sheet<S,P> getSheet();
}
import java.util.List;
-public interface ShapeContainer<T extends Shape> extends Iterable<T> {
+public interface ShapeContainer<
+ S extends Shape<S,P>,
+ P extends TextParagraph<S,P,? extends TextRun>
+> extends Iterable<S> {
/**
* Returns an list containing all of the elements in this container in proper
* sequence (from first to last element).
* @return an list containing all of the elements in this container in proper
* sequence
*/
- List<T> getShapes();
+ List<S> getShapes();
- void addShape(T shape);
+ void addShape(S shape);
/**
* Removes the specified shape from this sheet, if it is present
* @throws IllegalArgumentException if the type of the specified shape
* is incompatible with this sheet (optional)
*/
- boolean removeShape(T shape);
+ boolean removeShape(S shape);
+
+ /**
+ * create a new shape with a predefined geometry and add it to this shape container
+ */
+ AutoShape<S,P> createAutoShape();
+
+ /**
+ * create a new shape with a custom geometry
+ */
+ FreeformShape<S,P> createFreeform();
+
+ /**
+ * create a text box
+ */
+ TextBox<S,P> createTextBox();
+
+ /**
+ * create a connector
+ */
+ ConnectorShape<S,P> createConnector();
+
+ /**
+ * create a group of shapes belonging to this container
+ */
+ GroupShape<S,P> createGroup();
+
+ /**
+ * create a picture belonging to this container
+ */
+ PictureShape<S,P> createPicture(PictureData pictureData);
+
+ /**
+ * Create a new Table of the given number of rows and columns
+ *
+ * @param numrows the number of rows
+ * @param numcols the number of columns
+ */
+ TableShape<S,P> createTable(int numRows, int numCols);
}
/**
* Common parent of Slides, Notes and Masters
*/
-public interface Sheet<T extends Shape, SS extends SlideShow> extends ShapeContainer<T> {
- SS getSlideShow();
+public interface Sheet<
+ S extends Shape<S,P>,
+ P extends TextParagraph<S,P,? extends TextRun>
+> extends ShapeContainer<S,P> {
+ SlideShow<S,P> getSlideShow();
/**
* @return whether shapes on the master sheet should be shown. By default master graphics is turned off.
*/
boolean getFollowMasterGraphics();
- MasterSheet<T,SS> getMasterSheet();
+ MasterSheet<S,P> getMasterSheet();
- Background getBackground();
+ Background<S,P> getBackground();
/**
* Convenience method to draw a sheet to a graphics context
import org.apache.poi.sl.draw.geom.IAdjustableShape;
-public interface SimpleShape extends Shape, IAdjustableShape, PlaceableShape {
+public interface SimpleShape<
+ S extends Shape<S,P>,
+ P extends TextParagraph<S,P,? extends TextRun>
+> extends Shape<S,P>, IAdjustableShape, PlaceableShape<S,P> {
FillStyle getFillStyle();
LineDecoration getLineDecoration();
StrokeStyle getStrokeStyle();
package org.apache.poi.sl.usermodel;
-public interface Slide<T extends Shape, SS extends SlideShow, N extends Notes<T,SS>> extends Sheet<T, SS> {
- N getNotes();
- void setNotes(N notes);
+public interface Slide<
+ S extends Shape<S,P>,
+ P extends TextParagraph<S,P,? extends TextRun>
+> extends Sheet<S,P> {
+ Notes<S,P> getNotes();
+ void setNotes(Notes<S,P> notes);
boolean getFollowMasterBackground();
void setFollowMasterBackground(boolean follow);
import org.apache.poi.sl.usermodel.PictureData.PictureType;
-public interface SlideShow {
- Slide<? extends Shape, ? extends SlideShow, ? extends Notes<?,?>> createSlide() throws IOException;
+public interface SlideShow<
+ S extends Shape<S,P>,
+ P extends TextParagraph<S,P,? extends TextRun>
+> {
+ Slide<S,P> createSlide() throws IOException;
- List<? extends Slide<? extends Shape, ? extends SlideShow, ? extends Notes<?,?>>> getSlides();
+ List<? extends Slide<S,P>> getSlides();
- MasterSheet<? extends Shape, ? extends SlideShow> createMasterSheet() throws IOException;
+ MasterSheet<S,P> createMasterSheet() throws IOException;
/**
* Returns all slide masters.
* This doesn't include notes master and other arbitrary masters.
*/
- List<? extends MasterSheet<? extends Shape, ? extends SlideShow>> getSlideMasters();
+ List<? extends MasterSheet<S,P>> getSlideMasters();
Resources getResources();
--- /dev/null
+/* ====================================================================\r
+ Licensed to the Apache Software Foundation (ASF) under one or more\r
+ contributor license agreements. See the NOTICE file distributed with\r
+ this work for additional information regarding copyright ownership.\r
+ The ASF licenses this file to You under the Apache License, Version 2.0\r
+ (the "License"); you may not use this file except in compliance with\r
+ the License. You may obtain a copy of the License at\r
+\r
+ http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+ Unless required by applicable law or agreed to in writing, software\r
+ distributed under the License is distributed on an "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ See the License for the specific language governing permissions and\r
+ limitations under the License.\r
+==================================================================== */\r
+\r
+package org.apache.poi.sl.usermodel;\r
+\r
+public interface TableCell<\r
+ S extends Shape<S,P>,\r
+ P extends TextParagraph<S,P,? extends TextRun>\r
+> extends TextShape<S,P> {\r
+\r
+}\r
\r
package org.apache.poi.sl.usermodel;\r
\r
-public interface TableShape extends Shape, PlaceableShape {\r
+public interface TableShape<\r
+ S extends Shape<S,P>,\r
+ P extends TextParagraph<S,P,? extends TextRun>\r
+> extends Shape<S,P>, PlaceableShape<S,P> {\r
// to be defined ...\r
}\r
package org.apache.poi.sl.usermodel;
-public interface TextBox<T extends TextParagraph<? extends TextRun>> extends AutoShape<T> {
+public interface TextBox<
+ S extends Shape<S,P>,
+ P extends TextParagraph<S,P,? extends TextRun>
+> extends AutoShape<S,P> {
}
\r
\r
\r
-public interface TextParagraph<T extends TextRun> extends Iterable<T> {\r
+public interface TextParagraph<\r
+ S extends Shape<S,P>,\r
+ P extends TextParagraph<S,P,T>,\r
+ T extends TextRun\r
+> extends Iterable<T> {\r
\r
/**\r
* Specifies a list of text alignment types\r
Double getDefaultTabSize();\r
\r
\r
- TextShape<? extends TextParagraph<T>> getParentShape();\r
+ TextShape<S,P> getParentShape();\r
}\r
\r
package org.apache.poi.sl.usermodel;\r
\r
-import org.apache.poi.ss.usermodel.HorizontalAlignment;\r
+import java.util.List;\r
\r
-\r
-\r
-public interface TextShape<T extends TextParagraph<? extends TextRun>> extends SimpleShape, Iterable<T> {\r
+public interface TextShape<\r
+ S extends Shape<S,P>,\r
+ P extends TextParagraph<S,P,? extends TextRun>\r
+> extends SimpleShape<S,P>, Iterable<P> {\r
/**\r
* Vertical Text Types\r
*/\r
* </p>\r
*/\r
SHAPE\r
- } \r
+ }\r
\r
+ /**\r
+ * @return the TextParagraphs for this text box\r
+ */\r
+ List<? extends TextParagraph<S,P,? extends TextRun>> getTextParagraphs();\r
+\r
/**\r
* @return text shape margin\r
*/\r
Insets2D getInsets();\r
- \r
+\r
/**\r
* Compute the cumulative height occupied by the text\r
*/\r
double getTextHeight();\r
- \r
+\r
/**\r
* Returns the type of vertical alignment for the text.\r
*\r
* @return the type of vertical alignment\r
*/\r
VerticalAlignment getVerticalAlignment();\r
- \r
+\r
/**\r
* Returns if the text is centered.\r
* If true and if the individual paragraph settings allow it,\r
* the whole text block will be displayed centered, i.e. its left and right\r
* margin will be maximized while still keeping the alignment of the paragraphs\r
*\r
- * @return true, if the text anchor is horizontal centered \r
+ * @return true, if the text anchor is horizontal centered\r
*/\r
boolean isHorizontalCentered();\r
- \r
+\r
/**\r
* @return whether to wrap words within the bounding rectangle\r
*/\r
boolean getWordWrap();\r
- \r
+\r
/**\r
* @return vertical orientation of the text\r
*/\r
* top level object for creating new slides/etc.
*/
@Beta
-public class XMLSlideShow extends POIXMLDocument implements SlideShow {
+public class XMLSlideShow extends POIXMLDocument
+implements SlideShow<XSLFShape,XSLFTextParagraph> {
private static POILogger _logger = POILogFactory.getLogger(XMLSlideShow.class);
private CTPresentation _presentation;
return null;
}
- public MasterSheet<XSLFShape, XMLSlideShow> createMasterSheet() throws IOException {
+ @Override
+ public MasterSheet<XSLFShape,XSLFTextParagraph> createMasterSheet() throws IOException {
// TODO: implement!
throw new UnsupportedOperationException();
}
* @author Yegor Kozlov\r
*/\r
@Beta\r
-public class XSLFAutoShape extends XSLFTextShape implements AutoShape<XSLFTextParagraph> {\r
+public class XSLFAutoShape extends XSLFTextShape\r
+ implements AutoShape<XSLFShape,XSLFTextParagraph> {\r
\r
/*package*/ XSLFAutoShape(CTShape shape, XSLFSheet sheet) {\r
super(shape, sheet);\r
*\r
* @author Yegor Kozlov\r
*/\r
-public class XSLFBackground extends XSLFSimpleShape implements Background {\r
+public class XSLFBackground extends XSLFSimpleShape\r
+ implements Background<XSLFShape,XSLFTextParagraph> {\r
\r
/* package */XSLFBackground(CTBackground shape, XSLFSheet sheet) {\r
super(shape, sheet);\r
* @author Yegor Kozlov\r
*/\r
@Beta\r
-public class XSLFConnectorShape extends XSLFSimpleShape implements ConnectorShape {\r
+public class XSLFConnectorShape extends XSLFSimpleShape\r
+ implements ConnectorShape<XSLFShape,XSLFTextParagraph> {\r
\r
/*package*/ XSLFConnectorShape(CTConnector shape, XSLFSheet sheet) {\r
super(shape, sheet);\r
* @author Yegor Kozlov\r
*/\r
@Beta\r
-public class XSLFFreeformShape extends XSLFAutoShape implements FreeformShape<XSLFTextParagraph> {\r
+public class XSLFFreeformShape extends XSLFAutoShape\r
+ implements FreeformShape<XSLFShape,XSLFTextParagraph> {\r
\r
/*package*/ XSLFFreeformShape(CTShape shape, XSLFSheet sheet) {\r
super(shape, sheet);\r
import org.apache.poi.openxml4j.opc.PackageRelationship;\r
import org.apache.poi.openxml4j.opc.TargetMode;\r
import org.apache.poi.sl.usermodel.GroupShape;\r
+import org.apache.poi.sl.usermodel.PictureData;\r
import org.apache.poi.util.Beta;\r
import org.apache.poi.util.POILogFactory;\r
import org.apache.poi.util.POILogger;\r
* @author Yegor Kozlov\r
*/\r
@Beta\r
-public class XSLFGroupShape extends XSLFShape implements XSLFShapeContainer, GroupShape<XSLFShape> {\r
+public class XSLFGroupShape extends XSLFShape\r
+implements XSLFShapeContainer, GroupShape<XSLFShape,XSLFTextParagraph> {\r
private static POILogger _logger = POILogFactory.getLogger(XSLFGroupShape.class);\r
\r
private final List<XSLFShape> _shapes;\r
return sh;\r
}\r
\r
- public XSLFPictureShape createPicture(XSLFPictureData pictureData){\r
- PackagePart pic = pictureData.getPackagePart();\r
+ public XSLFPictureShape createPicture(PictureData pictureData){\r
+ if (!(pictureData instanceof XSLFPictureData)) {\r
+ throw new IllegalArgumentException("pictureData needs to be of type XSLFPictureData");\r
+ }\r
+ XSLFPictureData xPictureData = (XSLFPictureData)pictureData;\r
+ PackagePart pic = xPictureData.getPackagePart();\r
\r
PackageRelationship rel = getSheet().getPackagePart().addRelationship(\r
pic.getPartName(), TargetMode.INTERNAL, XSLFRelation.IMAGES.getRelation());\r
return sh;\r
}\r
\r
+ @Override\r
+ public XSLFTable createTable(int numRows, int numCols){\r
+ if (numRows < 1 || numCols < 1) {\r
+ throw new IllegalArgumentException("numRows and numCols must be greater than 0");\r
+ }\r
+ XSLFTable sh = getDrawing().createTable();\r
+ _shapes.add(sh);\r
+ sh.setParent(this);\r
+ for (int r=0; r<numRows; r++) {\r
+ XSLFTableRow row = sh.addRow();\r
+ for (int c=0; c<numCols; c++) {\r
+ row.addCell();\r
+ }\r
+ }\r
+ return sh;\r
+ }\r
+\r
+ \r
@Override\r
public void setFlipHorizontal(boolean flip){\r
getSafeXfrm().setFlipH(flip);\r
import org.openxmlformats.schemas.presentationml.x2006.main.NotesDocument;
@Beta
-public final class XSLFNotes extends XSLFSheet implements Notes<XSLFShape,XMLSlideShow> {
+public final class XSLFNotes extends XSLFSheet
+implements Notes<XSLFShape,XSLFTextParagraph> {
private CTNotesSlide _notes;
/**
return getMasterSheet().getTheme();
}
+ @Override
public XSLFNotesMaster getMasterSheet() {
for (POIXMLDocumentPart p : getRelations()) {
if (p instanceof XSLFNotesMaster){
* @author Yegor Kozlov
*/
@Beta
- public class XSLFNotesMaster extends XSLFSheet implements MasterSheet<XSLFShape,XMLSlideShow> {
+ public class XSLFNotesMaster extends XSLFSheet
+ implements MasterSheet<XSLFShape,XSLFTextParagraph> {
private CTNotesMaster _slide;
private XSLFTheme _theme;
}
@Override
- public MasterSheet<XSLFShape,XMLSlideShow> getMasterSheet() {
+ public MasterSheet<XSLFShape,XSLFTextParagraph> getMasterSheet() {
return null;
}
* Represents a picture shape\r
*/\r
@Beta\r
-public class XSLFPictureShape extends XSLFSimpleShape implements PictureShape {\r
+public class XSLFPictureShape extends XSLFSimpleShape\r
+ implements PictureShape<XSLFShape,XSLFTextParagraph> {\r
private XSLFPictureData _data;\r
\r
/*package*/ XSLFPictureShape(CTPicture shape, XSLFSheet sheet) {\r
* @author Yegor Kozlov\r
*/\r
@Beta\r
-public abstract class XSLFShape implements Shape {\r
+public abstract class XSLFShape implements Shape<XSLFShape,XSLFTextParagraph> {\r
private final XmlObject _shape;\r
private final XSLFSheet _sheet;\r
private XSLFShapeContainer _parent;\r
}\r
\r
if (this instanceof PlaceableShape) {\r
- PlaceableShape ps = (PlaceableShape)this;\r
- ps.setAnchor(((PlaceableShape)sh).getAnchor());\r
+ PlaceableShape<?,?> ps = (PlaceableShape<?,?>)this;\r
+ ps.setAnchor(((PlaceableShape<?,?>)sh).getAnchor());\r
}\r
\r
\r
package org.apache.poi.xslf.usermodel;
+import org.apache.poi.sl.usermodel.PictureData;
import org.apache.poi.sl.usermodel.ShapeContainer;
/**
* Common interface for shape containers, e.g. sheets or groups of shapes
*/
-public interface XSLFShapeContainer extends ShapeContainer<XSLFShape> {
+public interface XSLFShapeContainer
+ extends ShapeContainer<XSLFShape,XSLFTextParagraph> {
- /**
- * create a new shape with a predefined geometry and add it to this shape container
- */
+ @Override
XSLFAutoShape createAutoShape();
- /**
- * create a new shape with a custom geometry
- */
+ @Override
XSLFFreeformShape createFreeform();
- /**
- * create a text box
- */
+ @Override
XSLFTextBox createTextBox();
- /**
- *
- * create a connector
- */
+ @Override
XSLFConnectorShape createConnector();
- /**
- * create a group of shapes belonging to this container
- */
+ @Override
XSLFGroupShape createGroup();
- /**
- * create a picture belonging to this container
- */
- XSLFPictureShape createPicture(XSLFPictureData pictureData);
+ @Override
+ XSLFPictureShape createPicture(PictureData pictureData);
/**
* Removes all of the elements from this container (optional operation).
import org.apache.poi.openxml4j.opc.TargetMode;
import org.apache.poi.sl.draw.DrawFactory;
import org.apache.poi.sl.draw.Drawable;
+import org.apache.poi.sl.usermodel.PictureData;
import org.apache.poi.sl.usermodel.Sheet;
import org.apache.poi.util.Beta;
import org.apache.poi.util.IOUtils;
import org.openxmlformats.schemas.presentationml.x2006.main.CTShape;
@Beta
-public abstract class XSLFSheet extends POIXMLDocumentPart implements XSLFShapeContainer, Sheet<XSLFShape, XMLSlideShow> {
+public abstract class XSLFSheet extends POIXMLDocumentPart
+implements XSLFShapeContainer, Sheet<XSLFShape,XSLFTextParagraph> {
private XSLFCommonSlideData _commonSlideData;
private XSLFDrawing _drawing;
private List<XSLFShape> _shapes;
}
/**
- *
* @return the XMLSlideShow this sheet belongs to
*/
+ @Override
public XMLSlideShow getSlideShow() {
POIXMLDocumentPart p = getParent();
while(p != null) {
// shape factory methods
+ @Override
public XSLFAutoShape createAutoShape(){
XSLFAutoShape sh = getDrawing().createAutoShape();
getShapes().add(sh);
return sh;
}
+ @Override
public XSLFFreeformShape createFreeform(){
XSLFFreeformShape sh = getDrawing().createFreeform();
getShapes().add(sh);
return sh;
}
+ @Override
public XSLFTextBox createTextBox(){
XSLFTextBox sh = getDrawing().createTextBox();
getShapes().add(sh);
return sh;
}
+ @Override
public XSLFConnectorShape createConnector(){
XSLFConnectorShape sh = getDrawing().createConnector();
getShapes().add(sh);
return sh;
}
+ @Override
public XSLFGroupShape createGroup(){
XSLFGroupShape sh = getDrawing().createGroup();
getShapes().add(sh);
return sh;
}
- public XSLFPictureShape createPicture(XSLFPictureData pictureData){
- PackagePart pic = pictureData.getPackagePart();
+ @Override
+ public XSLFPictureShape createPicture(PictureData pictureData){
+ if (!(pictureData instanceof XSLFPictureData)) {
+ throw new IllegalArgumentException("pictureData needs to be of type XSLFPictureData");
+ }
+ XSLFPictureData xPictureData = (XSLFPictureData)pictureData;
+ PackagePart pic = xPictureData.getPackagePart();
PackageRelationship rel = getPackagePart().addRelationship(
pic.getPartName(), TargetMode.INTERNAL, XSLFRelation.IMAGES.getRelation());
return sh;
}
+ @Override
+ public XSLFTable createTable(int numRows, int numCols){
+ if (numRows < 1 || numCols < 1) {
+ throw new IllegalArgumentException("numRows and numCols must be greater than 0");
+ }
+ XSLFTable sh = getDrawing().createTable();
+ getShapes().add(sh);
+ sh.setParent(this);
+ for (int r=0; r<numRows; r++) {
+ XSLFTableRow row = sh.addRow();
+ for (int c=0; c<numCols; c++) {
+ row.addCell();
+ }
+ }
+ return sh;
+ }
+
+
/**
* Returns an iterator over the shapes in this sheet
*
}
/**
- *
* @return background for this sheet
*/
+ @Override
public XSLFBackground getBackground() {
return null;
}
* @author Yegor Kozlov\r
*/\r
@Beta\r
-public abstract class XSLFSimpleShape extends XSLFShape implements SimpleShape {\r
+public abstract class XSLFSimpleShape extends XSLFShape\r
+ implements SimpleShape<XSLFShape,XSLFTextParagraph> {\r
private static CTOuterShadowEffect NO_SHADOW = CTOuterShadowEffect.Factory.newInstance();\r
\r
/* package */XSLFSimpleShape(XmlObject shape, XSLFSheet sheet) {\r
import org.apache.poi.openxml4j.opc.PackageRelationship;
import org.apache.poi.sl.draw.DrawFactory;
import org.apache.poi.sl.draw.Drawable;
+import org.apache.poi.sl.usermodel.Notes;
import org.apache.poi.sl.usermodel.Slide;
import org.apache.poi.util.Beta;
import org.apache.xmlbeans.XmlException;
import org.openxmlformats.schemas.presentationml.x2006.main.SldDocument;
@Beta
-public final class XSLFSlide extends XSLFSheet implements Slide<XSLFShape, XMLSlideShow, XSLFNotes> {
+public final class XSLFSlide extends XSLFSheet
+implements Slide<XSLFShape,XSLFTextParagraph> {
private final CTSlide _slide;
private XSLFSlideLayout _layout;
private XSLFComments _comments;
throw new UnsupportedOperationException();
}
- public void setNotes(XSLFNotes notes) {
+ @Override
+ public void setNotes(Notes<XSLFShape,XSLFTextParagraph> notes) {
+ assert(notes instanceof XSLFNotes);
// TODO Auto-generated method stub
-
}
-
+
@Override
public int getSlideNumber() {
int idx = getSlideShow().getSlides().indexOf(this);
import org.openxmlformats.schemas.presentationml.x2006.main.SldLayoutDocument;
@Beta
-public class XSLFSlideLayout extends XSLFSheet implements MasterSheet<XSLFShape, XMLSlideShow> {
+public class XSLFSlideLayout extends XSLFSheet
+implements MasterSheet<XSLFShape,XSLFTextParagraph> {
private CTSlideLayout _layout;
private XSLFSlideMaster _master;
* @author Yegor Kozlov
*/
@Beta
- public class XSLFSlideMaster extends XSLFSheet implements MasterSheet<XSLFShape, XMLSlideShow> {
+ public class XSLFSlideMaster extends XSLFSheet
+ implements MasterSheet<XSLFShape,XSLFTextParagraph> {
private CTSlideMaster _slide;
private Map<String, XSLFSlideLayout> _layouts;
private XSLFTheme _theme;
}
@Override
- public MasterSheet<XSLFShape, XMLSlideShow> getMasterSheet() {
+ public XSLFSlideMaster getMasterSheet() {
return null;
}
*\r
* @author Yegor Kozlov\r
*/\r
-public class XSLFTable extends XSLFGraphicFrame implements Iterable<XSLFTableRow>, TableShape {\r
+public class XSLFTable extends XSLFGraphicFrame implements Iterable<XSLFTableRow>,\r
+ TableShape<XSLFShape,XSLFTextParagraph> {\r
static String TABLE_URI = "http://schemas.openxmlformats.org/drawingml/2006/table";\r
\r
private CTTable _table;\r
\r
import java.awt.Color;\r
\r
+import org.apache.poi.sl.usermodel.TableCell;\r
import org.apache.poi.sl.usermodel.VerticalAlignment;\r
import org.apache.poi.util.Units;\r
-import org.openxmlformats.schemas.drawingml.x2006.main.*;\r
+import org.openxmlformats.schemas.drawingml.x2006.main.CTLineEndProperties;\r
+import org.openxmlformats.schemas.drawingml.x2006.main.CTLineProperties;\r
+import org.openxmlformats.schemas.drawingml.x2006.main.CTSRgbColor;\r
+import org.openxmlformats.schemas.drawingml.x2006.main.CTSolidColorFillProperties;\r
+import org.openxmlformats.schemas.drawingml.x2006.main.CTTableCell;\r
+import org.openxmlformats.schemas.drawingml.x2006.main.CTTableCellProperties;\r
+import org.openxmlformats.schemas.drawingml.x2006.main.CTTextBody;\r
+import org.openxmlformats.schemas.drawingml.x2006.main.STCompoundLine;\r
+import org.openxmlformats.schemas.drawingml.x2006.main.STLineCap;\r
+import org.openxmlformats.schemas.drawingml.x2006.main.STLineEndLength;\r
+import org.openxmlformats.schemas.drawingml.x2006.main.STLineEndType;\r
+import org.openxmlformats.schemas.drawingml.x2006.main.STLineEndWidth;\r
+import org.openxmlformats.schemas.drawingml.x2006.main.STPenAlignment;\r
+import org.openxmlformats.schemas.drawingml.x2006.main.STPresetLineDashVal;\r
+import org.openxmlformats.schemas.drawingml.x2006.main.STTextAnchoringType;\r
\r
/**\r
* Represents a cell of a table in a .pptx presentation\r
*/\r
-public class XSLFTableCell extends XSLFTextShape {\r
+public class XSLFTableCell extends XSLFTextShape implements TableCell<XSLFShape,XSLFTextParagraph> {\r
static double defaultBorderWidth = 1.0;\r
private CTTableCellProperties _tcPr = null;\r
\r
\r
package org.apache.poi.xslf.usermodel;\r
\r
+import org.apache.poi.sl.usermodel.TextBox;\r
import org.apache.poi.util.Beta;\r
import org.openxmlformats.schemas.drawingml.x2006.main.*;\r
import org.openxmlformats.schemas.presentationml.x2006.main.CTShape;\r
* @author Yegor Kozlov\r
*/\r
@Beta\r
-public class XSLFTextBox extends XSLFAutoShape {\r
+public class XSLFTextBox extends XSLFAutoShape\r
+ implements TextBox<XSLFShape,XSLFTextParagraph> {\r
\r
/*package*/ XSLFTextBox(CTShape shape, XSLFSheet sheet){\r
super(shape, sheet);\r
* @since POI-3.8\r
*/\r
@Beta\r
-public class XSLFTextParagraph implements TextParagraph<XSLFTextRun> {\r
+public class XSLFTextParagraph implements TextParagraph<XSLFShape,XSLFTextParagraph,XSLFTextRun> {\r
private final CTTextParagraph _p;\r
private final List<XSLFTextRun> _runs;\r
private final XSLFTextShape _shape;\r
* Represents a shape that can hold text.
*/
@Beta
-public abstract class XSLFTextShape extends XSLFSimpleShape implements TextShape<XSLFTextParagraph> {
+public abstract class XSLFTextShape extends XSLFSimpleShape
+ implements TextShape<XSLFShape,XSLFTextParagraph> {
private final List<XSLFTextParagraph> _paragraphs;
@SuppressWarnings("deprecation")
addNewTextParagraph().addNewTextRun().setText(text);
}
- /**
- *
- * @return text paragraphs in this shape
- */
+ @Override
public List<XSLFTextParagraph> getTextParagraphs() {
return _paragraphs;
}
@Override
public double getTextHeight(){
DrawFactory drawFact = DrawFactory.getInstance(null);
- DrawTextShape<XSLFTextShape> dts = drawFact.getDrawable(this);
+ DrawTextShape dts = drawFact.getDrawable(this);
return dts.getTextHeight();
}
if (!quite) {\r
System.out.println("Processing " + file);\r
}\r
- SlideShow ss = SlideShowFactory.create(file, null, true);\r
- List<? extends Slide<?,?,?>> slides = ss.getSlides();\r
+ SlideShow<?,?> ss = SlideShowFactory.create(file, null, true);\r
+ List<? extends Slide<?,?>> slides = ss.getSlides();\r
\r
\r
if (slidenum < -1 || slidenum == 0 || slidenum > slides.size()) {\r
int height = (int) (pgsize.height * scale);\r
\r
int slideNo=1;\r
- for(Slide<?,?,?> slide : slides) {\r
+ for(Slide<?,?> slide : slides) {\r
if (slidenum == -1 || slideNo == slidenum) {\r
String title = slide.getTitle();\r
if (!quite) {\r
public class TestXSLFTextParagraph {\r
// private static POILogger _logger = POILogFactory.getLogger(XSLFTextParagraph.class);\r
\r
- static class DrawTextParagraphProxy extends DrawTextParagraph<XSLFTextRun> {\r
+ static class DrawTextParagraphProxy extends DrawTextParagraph {\r
DrawTextParagraphProxy(XSLFTextParagraph p) {\r
super(p);\r
}\r
import java.io.ByteArrayOutputStream;
import java.util.Iterator;
+import org.apache.poi.ddf.AbstractEscherOptRecord;
import org.apache.poi.ddf.EscherClientDataRecord;
import org.apache.poi.ddf.EscherComplexProperty;
import org.apache.poi.ddf.EscherContainerRecord;
-import org.apache.poi.ddf.EscherOptRecord;
import org.apache.poi.ddf.EscherProperties;
import org.apache.poi.ddf.EscherRecord;
import org.apache.poi.ddf.EscherSpRecord;
import org.apache.poi.hslf.record.OEShapeAtom;
import org.apache.poi.hslf.record.Record;
import org.apache.poi.hslf.record.RecordTypes;
-import org.apache.poi.hslf.usermodel.*;
+import org.apache.poi.hslf.usermodel.HSLFPictureData;
+import org.apache.poi.hslf.usermodel.HSLFPictureShape;
+import org.apache.poi.hslf.usermodel.HSLFShape;
+import org.apache.poi.hslf.usermodel.HSLFSheet;
+import org.apache.poi.hslf.usermodel.HSLFTextParagraph;
import org.apache.poi.sl.usermodel.ShapeContainer;
import org.apache.poi.sl.usermodel.ShapeType;
import org.apache.poi.util.LittleEndian;
* this picture in the <code>Slide</code>
* @param parent the parent shape of this picture
*/
- protected ActiveXShape(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape> parent){
+ protected ActiveXShape(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape,HSLFTextParagraph> parent){
super(escherRecord, parent);
}
String name = ctrl.getProgId() + "-" + getControlIndex() + '\u0000';
byte[] data = StringUtil.getToUnicodeLE(name);
EscherComplexProperty prop = new EscherComplexProperty(EscherProperties.GROUPSHAPE__SHAPENAME, false, data);
- EscherOptRecord opt = getEscherOptRecord();
+ AbstractEscherOptRecord opt = getEscherOptRecord();
opt.addEscherProperty(prop);
}
}
* @param pictureData the picture data
* @param parent the parent shape
*/
- public MovieShape(int movieIdx, HSLFPictureData pictureData, ShapeContainer<HSLFShape> parent) {
+ public MovieShape(int movieIdx, HSLFPictureData pictureData, ShapeContainer<HSLFShape,HSLFTextParagraph> parent) {
super(pictureData, parent);
setMovieIndex(movieIdx);
}
* this picture in the <code>Slide</code>
* @param parent the parent shape of this picture
*/
- public MovieShape(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape> parent){
+ public MovieShape(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape,HSLFTextParagraph> parent){
super(escherRecord, parent);
}
* @param data the picture data
* @param parent the parent shape
*/
- public OLEShape(HSLFPictureData data, ShapeContainer<HSLFShape> parent) {
+ public OLEShape(HSLFPictureData data, ShapeContainer<HSLFShape,HSLFTextParagraph> parent) {
super(data, parent);
}
* this picture in the <code>Slide</code>
* @param parent the parent shape of this picture
*/
- public OLEShape(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape> parent){
+ public OLEShape(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape,HSLFTextParagraph> parent){
super(escherRecord, parent);
}
import org.apache.poi.hslf.record.OEPlaceholderAtom;
import org.apache.poi.hslf.usermodel.HSLFShape;
import org.apache.poi.hslf.usermodel.HSLFTextBox;
+import org.apache.poi.hslf.usermodel.HSLFTextParagraph;
import org.apache.poi.hslf.exceptions.HSLFException;
import org.apache.poi.sl.usermodel.ShapeContainer;
*/
public final class Placeholder extends HSLFTextBox {
- protected Placeholder(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape> parent){
+ protected Placeholder(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape,HSLFTextParagraph> parent){
super(escherRecord, parent);
}
- public Placeholder(ShapeContainer<HSLFShape> parent){
+ public Placeholder(ShapeContainer<HSLFShape,HSLFTextParagraph> parent){
super(parent);
}
EscherClientDataRecord cldata = new EscherClientDataRecord();
cldata.setOptions((short)15);
- EscherOptRecord opt = getEscherOptRecord();
+ AbstractEscherOptRecord opt = getEscherOptRecord();
//Placeholders can't be grouped
setEscherProperty(opt, EscherProperties.PROTECTION__LOCKAGAINSTGROUPING, 262144);
* @param escherRecord <code>EscherSpContainer</code> container which holds information about this shape
* @param parent the parent of the shape
*/
- protected Polygon(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape> parent){
+ protected Polygon(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape,HSLFTextParagraph> parent){
super(escherRecord, parent);
}
* @param parent the parent of this Shape. For example, if this text box is a cell
* in a table then the parent is Table.
*/
- public Polygon(ShapeContainer<HSLFShape> parent){
+ public Polygon(ShapeContainer<HSLFShape,HSLFTextParagraph> parent){
super((EscherContainerRecord)null, parent);
_escherContainer = createSpContainer(ShapeType.NOT_PRIMITIVE, parent instanceof HSLFGroupShape);
}
float left = findSmallest(xPoints);
float top = findSmallest(yPoints);
- EscherOptRecord opt = getEscherOptRecord();
+ AbstractEscherOptRecord opt = getEscherOptRecord();
opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.GEOMETRY__RIGHT, Units.pointsToMaster(right - left)));
opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.GEOMETRY__BOTTOM, Units.pointsToMaster(bottom - top)));
*
* @author Yegor Kozlov
*/
-public class HSLFAutoShape extends HSLFTextShape implements AutoShape<HSLFTextParagraph> {
+public class HSLFAutoShape extends HSLFTextShape implements AutoShape<HSLFShape,HSLFTextParagraph> {
- protected HSLFAutoShape(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape> parent){
+ protected HSLFAutoShape(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape,HSLFTextParagraph> parent){
super(escherRecord, parent);
}
- public HSLFAutoShape(ShapeType type, ShapeContainer<HSLFShape> parent){
+ public HSLFAutoShape(ShapeType type, ShapeContainer<HSLFShape,HSLFTextParagraph> parent){
super(null, parent);
_escherContainer = createSpContainer(type, parent instanceof HSLFGroupShape);
}
*
* @author Yegor Kozlov
*/
-public final class HSLFBackground extends HSLFShape implements Background {
+public final class HSLFBackground extends HSLFShape implements Background<HSLFShape,HSLFTextParagraph> {
- protected HSLFBackground(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape> parent) {
+ protected HSLFBackground(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape,HSLFTextParagraph> parent) {
super(escherRecord, parent);
}
--- /dev/null
+/*\r
+ * ====================================================================\r
+ * Licensed to the Apache Software Foundation (ASF) under one or more\r
+ * contributor license agreements. See the NOTICE file distributed with\r
+ * this work for additional information regarding copyright ownership.\r
+ * The ASF licenses this file to You under the Apache License, Version 2.0\r
+ * (the "License"); you may not use this file except in compliance with\r
+ * the License. You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ====================================================================\r
+ */\r
+\r
+package org.apache.poi.hslf.usermodel;\r
+\r
+import org.apache.poi.ddf.EscherContainerRecord;\r
+import org.apache.poi.sl.usermodel.ConnectorShape;\r
+import org.apache.poi.sl.usermodel.ShapeContainer;\r
+import org.apache.poi.util.Beta;\r
+\r
+/**\r
+ * Specifies a connection shape.\r
+ * \r
+ * This is currently only a dummy implementation.\r
+ */\r
+@Beta\r
+public class HSLFConnectorShape extends HSLFSimpleShape\r
+implements ConnectorShape<HSLFShape,HSLFTextParagraph> {\r
+\r
+ /**\r
+ * Create a ConnectorShape object and initialize it from the supplied Record container.\r
+ *\r
+ * @param escherRecord <code>EscherSpContainer</code> container which holds information about this shape\r
+ * @param parent the parent of the shape\r
+ */\r
+ protected HSLFConnectorShape(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape,HSLFTextParagraph> parent){\r
+ super(escherRecord, parent);\r
+\r
+ }\r
+\r
+ /**\r
+ * Create a new ConnectorShape. This constructor is used when a new shape is created.\r
+ *\r
+ * @param parent the parent of this Shape. For example, if this text box is a cell\r
+ * in a table then the parent is Table.\r
+ */\r
+ public HSLFConnectorShape(ShapeContainer<HSLFShape,HSLFTextParagraph> parent){\r
+ super(null, parent);\r
+ _escherContainer = createSpContainer(parent instanceof HSLFGroupShape);\r
+ }\r
+\r
+ /**\r
+ * Create a new ConnectorShape. This constructor is used when a new shape is created.\r
+ *\r
+ */\r
+ public HSLFConnectorShape(){\r
+ this(null);\r
+ }\r
+}\r
import java.io.InputStream;
import java.util.List;
+import org.apache.poi.ddf.AbstractEscherOptRecord;
import org.apache.poi.ddf.EscherBSERecord;
import org.apache.poi.ddf.EscherContainerRecord;
-import org.apache.poi.ddf.EscherOptRecord;
import org.apache.poi.ddf.EscherProperties;
import org.apache.poi.ddf.EscherRecord;
import org.apache.poi.ddf.EscherSimpleProperty;
* @return type of fill
*/
public int getFillType(){
- EscherOptRecord opt = shape.getEscherOptRecord();
+ AbstractEscherOptRecord opt = shape.getEscherOptRecord();
EscherSimpleProperty prop = HSLFShape.getEscherProperty(opt, EscherProperties.FILL__FILLTYPE);
return prop == null ? FILL_SOLID : prop.getPropertyValue();
}
/**
*/
protected void afterInsert(HSLFSheet sh){
- EscherOptRecord opt = shape.getEscherOptRecord();
+ AbstractEscherOptRecord opt = shape.getEscherOptRecord();
EscherSimpleProperty p = HSLFShape.getEscherProperty(opt, EscherProperties.FILL__PATTERNTEXTURE);
if(p != null) {
int idx = p.getPropertyValue();
* @param type type of the fill
*/
public void setFillType(int type){
- EscherOptRecord opt = shape.getEscherOptRecord();
+ AbstractEscherOptRecord opt = shape.getEscherOptRecord();
HSLFShape.setEscherProperty(opt, EscherProperties.FILL__FILLTYPE, type);
}
* Foreground color
*/
public Color getForegroundColor(){
- EscherOptRecord opt = shape.getEscherOptRecord();
+ AbstractEscherOptRecord opt = shape.getEscherOptRecord();
EscherSimpleProperty p = HSLFShape.getEscherProperty(opt, EscherProperties.FILL__NOFILLHITTEST);
if(p != null && (p.getPropertyValue() & 0x10) == 0) return null;
* Foreground color
*/
public void setForegroundColor(Color color){
- EscherOptRecord opt = shape.getEscherOptRecord();
+ AbstractEscherOptRecord opt = shape.getEscherOptRecord();
if (color == null) {
HSLFShape.setEscherProperty(opt, EscherProperties.FILL__NOFILLHITTEST, 0x150000);
}
* Background color
*/
public Color getBackgroundColor(){
- EscherOptRecord opt = shape.getEscherOptRecord();
+ AbstractEscherOptRecord opt = shape.getEscherOptRecord();
EscherSimpleProperty p = HSLFShape.getEscherProperty(opt, EscherProperties.FILL__NOFILLHITTEST);
if(p != null && (p.getPropertyValue() & 0x10) == 0) return null;
* Background color
*/
public void setBackgroundColor(Color color){
- EscherOptRecord opt = shape.getEscherOptRecord();
+ AbstractEscherOptRecord opt = shape.getEscherOptRecord();
if (color == null) {
HSLFShape.setEscherProperty(opt, EscherProperties.FILL__FILLBACKCOLOR, -1);
}
* <code>PictureData</code> object used in a texture, pattern of picture fill.
*/
public HSLFPictureData getPictureData(){
- EscherOptRecord opt = shape.getEscherOptRecord();
+ AbstractEscherOptRecord opt = shape.getEscherOptRecord();
EscherSimpleProperty p = HSLFShape.getEscherProperty(opt, EscherProperties.FILL__PATTERNTEXTURE);
if (p == null) return null;
* @param data the picture data added to this ppt by {@link HSLFSlideShow#addPicture(byte[], org.apache.poi.sl.usermodel.PictureData.PictureType)} method.
*/
public void setPictureData(HSLFPictureData data){
- EscherOptRecord opt = shape.getEscherOptRecord();
+ AbstractEscherOptRecord opt = shape.getEscherOptRecord();
HSLFShape.setEscherProperty(opt, (short)(EscherProperties.FILL__PATTERNTEXTURE + 0x4000), (data == null ? 0 : data.getIndex()));
if(data != null && shape.getSheet() != null) {
EscherBSERecord bse = getEscherBSERecord(data.getIndex());
import java.util.Arrays;
import java.util.List;
+import org.apache.poi.ddf.AbstractEscherOptRecord;
import org.apache.poi.ddf.EscherArrayProperty;
import org.apache.poi.ddf.EscherContainerRecord;
-import org.apache.poi.ddf.EscherOptRecord;
import org.apache.poi.ddf.EscherProperties;
import org.apache.poi.ddf.EscherSimpleProperty;
import org.apache.poi.sl.usermodel.FreeformShape;
* </p>
* @author Yegor Kozlov
*/
-public final class HSLFFreeformShape extends HSLFAutoShape implements FreeformShape<HSLFTextParagraph> {
+public final class HSLFFreeformShape extends HSLFAutoShape implements FreeformShape<HSLFShape,HSLFTextParagraph> {
public static final byte[] SEGMENTINFO_MOVETO = new byte[]{0x00, 0x40};
public static final byte[] SEGMENTINFO_LINETO = new byte[]{0x00, (byte)0xAC};
* @param escherRecord <code>EscherSpContainer</code> container which holds information about this shape
* @param parent the parent of the shape
*/
- protected HSLFFreeformShape(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape> parent){
+ protected HSLFFreeformShape(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape,HSLFTextParagraph> parent){
super(escherRecord, parent);
}
* @param parent the parent of this Shape. For example, if this text box is a cell
* in a table then the parent is Table.
*/
- public HSLFFreeformShape(ShapeContainer<HSLFShape> parent){
+ public HSLFFreeformShape(ShapeContainer<HSLFShape,HSLFTextParagraph> parent){
super((EscherContainerRecord)null, parent);
_escherContainer = createSpContainer(ShapeType.NOT_PRIMITIVE, parent instanceof HSLFGroupShape);
}
if(!isClosed) segInfo.add(SEGMENTINFO_LINETO);
segInfo.add(new byte[]{0x00, (byte)0x80});
- EscherOptRecord opt = getEscherOptRecord();
+ AbstractEscherOptRecord opt = getEscherOptRecord();
opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.GEOMETRY__SHAPEPATH, 0x4));
EscherArrayProperty verticesProp = new EscherArrayProperty((short)(EscherProperties.GEOMETRY__VERTICES + 0x4000), false, null);
@Override
public GeneralPath getPath(){
- EscherOptRecord opt = getEscherOptRecord();
+ AbstractEscherOptRecord opt = getEscherOptRecord();
opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.GEOMETRY__SHAPEPATH, 0x4));
EscherArrayProperty verticesProp = getEscherProperty(opt, (short)(EscherProperties.GEOMETRY__VERTICES + 0x4000));
package org.apache.poi.hslf.usermodel;
+import java.awt.Rectangle;
import java.awt.geom.Rectangle2D;
-import java.util.*;
-
-import org.apache.poi.ddf.*;
-import org.apache.poi.sl.usermodel.*;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.poi.ddf.EscherChildAnchorRecord;
+import org.apache.poi.ddf.EscherClientAnchorRecord;
+import org.apache.poi.ddf.EscherContainerRecord;
+import org.apache.poi.ddf.EscherRecord;
+import org.apache.poi.ddf.EscherSpRecord;
+import org.apache.poi.ddf.EscherSpgrRecord;
+import org.apache.poi.sl.usermodel.GroupShape;
+import org.apache.poi.sl.usermodel.PictureData;
+import org.apache.poi.sl.usermodel.ShapeContainer;
+import org.apache.poi.sl.usermodel.ShapeType;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.POILogger;
import org.apache.poi.util.Units;
*
* @author Yegor Kozlov
*/
-public class HSLFGroupShape extends HSLFShape implements GroupShape<HSLFShape> {
+public class HSLFGroupShape extends HSLFShape
+implements HSLFShapeContainer, GroupShape<HSLFShape,HSLFTextParagraph> {
/**
* Create a new ShapeGroup. This constructor is used when a new shape is created.
}
/**
- * Create a ShapeGroup object and initilize it from the supplied Record container.
+ * Create a new ShapeGroup. This constructor is used when a new shape is created.
+ *
+ * @param parent the parent of the shape
+ */
+ public HSLFGroupShape(ShapeContainer<HSLFShape,HSLFTextParagraph> parent){
+ this(null, parent);
+ _escherContainer = createSpContainer(parent instanceof HSLFGroupShape);
+ }
+
+ /**
+ * Create a ShapeGroup object and initialize it from the supplied Record container.
*
* @param escherRecord <code>EscherSpContainer</code> container which holds information about this shape
* @param parent the parent of the shape
*/
- protected HSLFGroupShape(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape> parent){
+ protected HSLFGroupShape(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape,HSLFTextParagraph> parent){
super(escherRecord, parent);
}
return shapeList;
}
+ @Override
+ public HSLFTextBox createTextBox() {
+ HSLFTextBox s = new HSLFTextBox(this);
+ s.setHorizontalCentered(true);
+ s.setAnchor(new Rectangle(0, 0, 100, 100));
+ addShape(s);
+ return s;
+ }
+
+ @Override
+ public HSLFAutoShape createAutoShape() {
+ HSLFAutoShape s = new HSLFAutoShape(ShapeType.RECT, this);
+ s.setHorizontalCentered(true);
+ s.setAnchor(new Rectangle(0, 0, 100, 100));
+ addShape(s);
+ return s;
+ }
+
+ @Override
+ public HSLFFreeformShape createFreeform() {
+ HSLFFreeformShape s = new HSLFFreeformShape(this);
+ s.setHorizontalCentered(true);
+ s.setAnchor(new Rectangle(0, 0, 100, 100));
+ addShape(s);
+ return s;
+ }
+
+ @Override
+ public HSLFConnectorShape createConnector() {
+ HSLFConnectorShape s = new HSLFConnectorShape(this);
+ s.setAnchor(new Rectangle(0, 0, 100, 100));
+ addShape(s);
+ return s;
+ }
+
+ @Override
+ public HSLFGroupShape createGroup() {
+ HSLFGroupShape s = new HSLFGroupShape(this);
+ s.setAnchor(new Rectangle(0, 0, 100, 100));
+ addShape(s);
+ return s;
+ }
+
+ @Override
+ public HSLFPictureShape createPicture(PictureData pictureData) {
+ if (!(pictureData instanceof HSLFPictureData)) {
+ throw new IllegalArgumentException("pictureData needs to be of type HSLFPictureData");
+ }
+ HSLFPictureShape s = new HSLFPictureShape((HSLFPictureData)pictureData, this);
+ s.setAnchor(new Rectangle(0, 0, 100, 100));
+ addShape(s);
+ return s;
+ }
+
+ @Override
+ public HSLFTable createTable(int numRows, int numCols) {
+ if (numRows < 1 || numCols < 1) {
+ throw new IllegalArgumentException("numRows and numCols must be greater than 0");
+ }
+ HSLFTable s = new HSLFTable(numRows,numCols,this);
+ s.setAnchor(new Rectangle(0, 0, 100, 100));
+ addShape(s);
+ return s;
+ }
}
package org.apache.poi.hslf.usermodel;
+import org.apache.poi.ddf.AbstractEscherOptRecord;
import org.apache.poi.ddf.EscherContainerRecord;
-import org.apache.poi.ddf.EscherOptRecord;
import org.apache.poi.ddf.EscherProperties;
import org.apache.poi.ddf.EscherSpRecord;
import org.apache.poi.sl.usermodel.Line;
*
* @author Yegor Kozlov
*/
-public final class HSLFLine extends HSLFTextShape implements Line<HSLFTextParagraph> {
- public HSLFLine(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape> parent){
+public final class HSLFLine extends HSLFTextShape implements Line<HSLFShape,HSLFTextParagraph> {
+ public HSLFLine(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape,HSLFTextParagraph> parent){
super(escherRecord, parent);
}
- public HSLFLine(ShapeContainer<HSLFShape> parent){
+ public HSLFLine(ShapeContainer<HSLFShape,HSLFTextParagraph> parent){
super(null, parent);
_escherContainer = createSpContainer(parent instanceof HSLFGroupShape);
}
spRecord.setOptions(type);
//set default properties for a line
- EscherOptRecord opt = getEscherOptRecord();
+ AbstractEscherOptRecord opt = getEscherOptRecord();
//default line properties
setEscherProperty(opt, EscherProperties.GEOMETRY__SHAPEPATH, 4);
*
* @author Yegor Kozlov
*/
-public abstract class HSLFMasterSheet extends HSLFSheet implements MasterSheet<HSLFShape,HSLFSlideShow> {
+public abstract class HSLFMasterSheet extends HSLFSheet implements MasterSheet<HSLFShape,HSLFTextParagraph> {
public HSLFMasterSheet(SheetContainer container, int sheetNo){
super(container, sheetNo);
}
* @author Nick Burch
*/
-public final class HSLFNotes extends HSLFSheet implements Notes<HSLFShape, HSLFSlideShow> {
+public final class HSLFNotes extends HSLFSheet implements Notes<HSLFShape,HSLFTextParagraph> {
protected static final POILogger logger = POILogFactory.getLogger(HSLFNotes.class);
private List<List<HSLFTextParagraph>> _paragraphs = new ArrayList<List<HSLFTextParagraph>>();
import javax.imageio.ImageIO;
+import org.apache.poi.ddf.AbstractEscherOptRecord;
import org.apache.poi.ddf.EscherBSERecord;
import org.apache.poi.ddf.EscherComplexProperty;
import org.apache.poi.ddf.EscherContainerRecord;
-import org.apache.poi.ddf.EscherOptRecord;
import org.apache.poi.ddf.EscherProperties;
import org.apache.poi.ddf.EscherRecord;
import org.apache.poi.ddf.EscherSimpleProperty;
*
* @author Yegor Kozlov
*/
-public class HSLFPictureShape extends HSLFSimpleShape implements PictureShape {
+public class HSLFPictureShape extends HSLFSimpleShape implements PictureShape<HSLFShape,HSLFTextParagraph> {
/**
* Create a new <code>Picture</code>
* @param data the picture data
* @param parent the parent shape
*/
- public HSLFPictureShape(HSLFPictureData data, ShapeContainer<HSLFShape> parent) {
+ public HSLFPictureShape(HSLFPictureData data, ShapeContainer<HSLFShape,HSLFTextParagraph> parent) {
super(null, parent);
_escherContainer = createSpContainer(data.getIndex(), parent instanceof HSLFGroupShape);
}
* this picture in the <code>Slide</code>
* @param parent the parent shape of this picture
*/
- protected HSLFPictureShape(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape> parent){
+ protected HSLFPictureShape(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape,HSLFTextParagraph> parent){
super(escherRecord, parent);
}
* @return the index to this picture (1 based).
*/
public int getPictureIndex(){
- EscherOptRecord opt = getEscherOptRecord();
+ AbstractEscherOptRecord opt = getEscherOptRecord();
EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.BLIP__BLIPTODISPLAY);
return prop == null ? 0 : prop.getPropertyValue();
}
spRecord.setOptions((short)((ShapeType.FRAME.nativeId << 4) | 0x2));
//set default properties for a picture
- EscherOptRecord opt = getEscherOptRecord();
+ AbstractEscherOptRecord opt = getEscherOptRecord();
setEscherProperty(opt, EscherProperties.PROTECTION__LOCKAGAINSTGROUPING, 0x800080);
//another weird feature of powerpoint: for picture id we must add 0x4000.
* @return name of this picture
*/
public String getPictureName(){
- EscherOptRecord opt = getEscherOptRecord();
+ AbstractEscherOptRecord opt = getEscherOptRecord();
EscherComplexProperty prop = getEscherProperty(opt, EscherProperties.BLIP__BLIPFILENAME);
if (prop == null) return null;
String name = StringUtil.getFromUnicodeLE(prop.getComplexData());
* @param name of this picture
*/
public void setPictureName(String name){
- EscherOptRecord opt = getEscherOptRecord();
+ AbstractEscherOptRecord opt = getEscherOptRecord();
byte[] data = StringUtil.getToUnicodeLE(name + '\u0000');
EscherComplexProperty prop = new EscherComplexProperty(EscherProperties.BLIP__BLIPFILENAME, false, data);
opt.addEscherProperty(prop);
public Insets getClipping() {
// The anchor specified by the escher properties is the displayed size,
// i.e. the size of the already clipped image
- EscherOptRecord opt = getEscherOptRecord();
+ AbstractEscherOptRecord opt = getEscherOptRecord();
double top = getFractProp(opt, EscherProperties.BLIP__CROPFROMTOP);
double bottom = getFractProp(opt, EscherProperties.BLIP__CROPFROMBOTTOM);
/**
* @return the fractional property or 0 if not defined
*/
- private static double getFractProp(EscherOptRecord opt, short propertyId) {
+ private static double getFractProp(AbstractEscherOptRecord opt, short propertyId) {
EscherSimpleProperty prop = getEscherProperty(opt, propertyId);
if (prop == null) return 0;
int fixedPoint = prop.getPropertyValue();
*
* @author Yegor Kozlov
*/
-public abstract class HSLFShape implements Shape {
+public abstract class HSLFShape implements Shape<HSLFShape,HSLFTextParagraph> {
// For logging
protected POILogger logger = POILogFactory.getLogger(this.getClass());
* Parent of this shape.
* <code>null</code> for the topmost shapes.
*/
- protected ShapeContainer<HSLFShape> _parent;
+ protected ShapeContainer<HSLFShape,HSLFTextParagraph> _parent;
/**
* The <code>Sheet</code> this shape belongs to
* @param escherRecord <code>EscherSpContainer</code> container which holds information about this shape
* @param parent the parent of this Shape
*/
- protected HSLFShape(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape> parent){
+ protected HSLFShape(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape,HSLFTextParagraph> parent){
_escherContainer = escherRecord;
_parent = parent;
}
/**
* @return the parent of this shape
*/
- public ShapeContainer<HSLFShape> getParent(){
+ public ShapeContainer<HSLFShape,HSLFTextParagraph> getParent(){
return _parent;
}
*
* @return escher property or <code>null</code> if not found.
*/
- public static <T extends EscherProperty> T getEscherProperty(EscherOptRecord opt, int propId){
+ public static <T extends EscherProperty> T getEscherProperty(AbstractEscherOptRecord opt, int propId){
if (opt == null) return null;
return opt.lookup(propId);
}
* @param propId The id of the property. One of the constants defined in EscherOptRecord.
* @param value value of the property. If value = -1 then the property is removed.
*/
- public static void setEscherProperty(EscherOptRecord opt, short propId, int value){
+ public static void setEscherProperty(AbstractEscherOptRecord opt, short propId, int value){
java.util.List<EscherProperty> props = opt.getEscherProperties();
for ( Iterator<EscherProperty> iterator = props.iterator(); iterator.hasNext(); ) {
if (iterator.next().getPropertyNumber() == propId){
* @param value value of the property. If value = -1 then the property is removed.
*/
public void setEscherProperty(short propId, int value){
- EscherOptRecord opt = getEscherOptRecord();
+ AbstractEscherOptRecord opt = getEscherOptRecord();
setEscherProperty(opt, propId, value);
}
* @param propId The id of the property. One of the constants defined in EscherOptRecord.
*/
public int getEscherProperty(short propId){
- EscherOptRecord opt = getEscherOptRecord();
+ AbstractEscherOptRecord opt = getEscherOptRecord();
EscherSimpleProperty prop = getEscherProperty(opt, propId);
return prop == null ? 0 : prop.getPropertyValue();
}
* @param propId The id of the property. One of the constants defined in EscherOptRecord.
*/
public int getEscherProperty(short propId, int defaultValue){
- EscherOptRecord opt = getEscherOptRecord();
+ AbstractEscherOptRecord opt = getEscherOptRecord();
EscherSimpleProperty prop = getEscherProperty(opt, propId);
return prop == null ? defaultValue : prop.getPropertyValue();
}
}
Color getColor(short colorProperty, short opacityProperty, int defaultColor){
- EscherOptRecord opt = getEscherOptRecord();
+ AbstractEscherOptRecord opt = getEscherOptRecord();
EscherSimpleProperty p = getEscherProperty(opt, colorProperty);
if(p == null && defaultColor == -1) return null;
}
double getAlpha(short opacityProperty) {
- EscherOptRecord opt = getEscherOptRecord();
+ AbstractEscherOptRecord opt = getEscherOptRecord();
EscherSimpleProperty op = getEscherProperty(opt, opacityProperty);
int defaultOpacity = 0x00010000;
int opacity = (op == null) ? defaultOpacity : op.getPropertyValue();
logger.log(POILogger.INFO, "Rendering " + getShapeName());
}
- public EscherOptRecord getEscherOptRecord() {
- EscherOptRecord opt = getEscherChild(EscherOptRecord.RECORD_ID);
+ public AbstractEscherOptRecord getEscherOptRecord() {
+ AbstractEscherOptRecord opt = getEscherChild(EscherOptRecord.RECORD_ID);
if (opt == null) {
opt = getEscherChild(RecordTypes.EscherUserDefined);
}
--- /dev/null
+/*\r
+ * ====================================================================\r
+ * Licensed to the Apache Software Foundation (ASF) under one or more\r
+ * contributor license agreements. See the NOTICE file distributed with\r
+ * this work for additional information regarding copyright ownership.\r
+ * The ASF licenses this file to You under the Apache License, Version 2.0\r
+ * (the "License"); you may not use this file except in compliance with\r
+ * the License. You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ====================================================================\r
+ */\r
+\r
+package org.apache.poi.hslf.usermodel;\r
+\r
+import org.apache.poi.sl.usermodel.PictureData;\r
+import org.apache.poi.sl.usermodel.ShapeContainer;\r
+\r
+/**\r
+ * Common interface for shape containers, e.g. sheets or groups of shapes\r
+ */\r
+public interface HSLFShapeContainer extends ShapeContainer<HSLFShape,HSLFTextParagraph> {\r
+\r
+ @Override\r
+ HSLFAutoShape createAutoShape();\r
+\r
+ @Override\r
+ HSLFFreeformShape createFreeform();\r
+\r
+ @Override\r
+ HSLFTextBox createTextBox();\r
+\r
+ @Override\r
+ HSLFConnectorShape createConnector();\r
+\r
+ @Override\r
+ HSLFGroupShape createGroup();\r
+\r
+ @Override\r
+ HSLFPictureShape createPicture(PictureData pictureData);\r
+\r
+\r
+}\r
/**
* Create a new shape from the data provided.
*/
- public static HSLFShape createShape(EscherContainerRecord spContainer, ShapeContainer<HSLFShape> parent){
+ public static HSLFShape createShape(EscherContainerRecord spContainer, ShapeContainer<HSLFShape,HSLFTextParagraph> parent){
if (spContainer.getRecordId() == EscherContainerRecord.SPGR_CONTAINER){
return createShapeGroup(spContainer, parent);
}
return createSimpleShape(spContainer, parent);
}
- public static HSLFGroupShape createShapeGroup(EscherContainerRecord spContainer, ShapeContainer<HSLFShape> parent){
- HSLFGroupShape group = null;
- EscherRecord opt = HSLFShape.getEscherChild((EscherContainerRecord)spContainer.getChild(0), (short)0xF122);
- if(opt != null){
- try {
- EscherPropertyFactory f = new EscherPropertyFactory();
- List<EscherProperty> props = f.createProperties( opt.serialize(), 8, opt.getInstance() );
- EscherSimpleProperty p = (EscherSimpleProperty)props.get(0);
- if(p.getPropertyNumber() == 0x39F && p.getPropertyValue() == 1){
- group = new HSLFTable(spContainer, parent);
- } else {
- group = new HSLFGroupShape(spContainer, parent);
+ public static HSLFGroupShape createShapeGroup(EscherContainerRecord spContainer, ShapeContainer<HSLFShape,HSLFTextParagraph> parent){
+ boolean isTable = false;
+ EscherContainerRecord ecr = (EscherContainerRecord)spContainer.getChild(0);
+ EscherRecord opt = HSLFShape.getEscherChild(ecr, (short)RecordTypes.EscherUserDefined);
+
+ if (opt != null) {
+ EscherPropertyFactory f = new EscherPropertyFactory();
+ List<EscherProperty> props = f.createProperties( opt.serialize(), 8, opt.getInstance() );
+ for (EscherProperty ep : props) {
+ if (ep.getPropertyNumber() == 0x39F
+ && ep instanceof EscherSimpleProperty
+ && ((EscherSimpleProperty)ep).getPropertyValue() == 1) {
+ isTable = true;
+ break;
}
- } catch (Exception e){
- logger.log(POILogger.WARN, e.getMessage());
- group = new HSLFGroupShape(spContainer, parent);
}
- } else {
- group = new HSLFGroupShape(spContainer, parent);
}
-
+
+ HSLFGroupShape group = (isTable)
+ ? new HSLFTable(spContainer, parent)
+ : new HSLFGroupShape(spContainer, parent);
+
return group;
}
- public static HSLFShape createSimpleShape(EscherContainerRecord spContainer, ShapeContainer<HSLFShape> parent){
+ public static HSLFShape createSimpleShape(EscherContainerRecord spContainer, ShapeContainer<HSLFShape,HSLFTextParagraph> parent){
HSLFShape shape = null;
EscherSpRecord spRecord = spContainer.getChildById(EscherSpRecord.RECORD_ID);
shape = new HSLFLine(spContainer, parent);
break;
case NOT_PRIMITIVE: {
- EscherOptRecord opt = HSLFShape.getEscherChild(spContainer, EscherOptRecord.RECORD_ID);
+ AbstractEscherOptRecord opt = HSLFShape.getEscherChild(spContainer, EscherOptRecord.RECORD_ID);
EscherProperty prop = HSLFShape.getEscherProperty(opt, EscherProperties.GEOMETRY__VERTICES);
if(prop != null)
shape = new HSLFFreeformShape(spContainer, parent);
package org.apache.poi.hslf.usermodel;
import java.awt.Graphics2D;
-import java.util.*;
-
-import org.apache.poi.ddf.*;
-import org.apache.poi.hslf.record.*;
+import java.awt.Rectangle;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.poi.ddf.EscherContainerRecord;
+import org.apache.poi.ddf.EscherDgRecord;
+import org.apache.poi.ddf.EscherDggRecord;
+import org.apache.poi.ddf.EscherRecord;
+import org.apache.poi.hslf.record.CString;
+import org.apache.poi.hslf.record.ColorSchemeAtom;
+import org.apache.poi.hslf.record.OEPlaceholderAtom;
+import org.apache.poi.hslf.record.PPDrawing;
+import org.apache.poi.hslf.record.RecordContainer;
+import org.apache.poi.hslf.record.RecordTypes;
+import org.apache.poi.hslf.record.RoundTripHFPlaceholder12;
+import org.apache.poi.hslf.record.SheetContainer;
import org.apache.poi.sl.draw.DrawFactory;
import org.apache.poi.sl.draw.Drawable;
+import org.apache.poi.sl.usermodel.PictureData;
+import org.apache.poi.sl.usermodel.ShapeType;
import org.apache.poi.sl.usermodel.Sheet;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
/**
* This class defines the common format of "Sheets" in a powerpoint
* @author Yegor Kozlov
*/
-public abstract class HSLFSheet implements Sheet<HSLFShape,HSLFSlideShow> {
- private static POILogger logger = POILogFactory.getLogger(HSLFSheet.class);
-
+public abstract class HSLFSheet implements HSLFShapeContainer, Sheet<HSLFShape,HSLFTextParagraph> {
/**
* The <code>SlideShow</code> we belong to
*/
}
+ @Override
+ public HSLFTextBox createTextBox() {
+ HSLFTextBox s = new HSLFTextBox();
+ s.setHorizontalCentered(true);
+ s.setAnchor(new Rectangle(0, 0, 100, 100));
+ addShape(s);
+ return s;
+ }
+
+ @Override
+ public HSLFAutoShape createAutoShape() {
+ HSLFAutoShape s = new HSLFAutoShape(ShapeType.RECT);
+ s.setHorizontalCentered(true);
+ s.setAnchor(new Rectangle(0, 0, 100, 100));
+ addShape(s);
+ return s;
+ }
+
+ @Override
+ public HSLFFreeformShape createFreeform() {
+ HSLFFreeformShape s = new HSLFFreeformShape();
+ s.setHorizontalCentered(true);
+ s.setAnchor(new Rectangle(0, 0, 100, 100));
+ addShape(s);
+ return s;
+ }
+
+ @Override
+ public HSLFConnectorShape createConnector() {
+ HSLFConnectorShape s = new HSLFConnectorShape();
+ s.setAnchor(new Rectangle(0, 0, 100, 100));
+ addShape(s);
+ return s;
+ }
+
+ @Override
+ public HSLFGroupShape createGroup() {
+ HSLFGroupShape s = new HSLFGroupShape();
+ s.setAnchor(new Rectangle(0, 0, 100, 100));
+ addShape(s);
+ return s;
+ }
+
+ @Override
+ public HSLFPictureShape createPicture(PictureData pictureData) {
+ if (!(pictureData instanceof HSLFPictureData)) {
+ throw new IllegalArgumentException("pictureData needs to be of type HSLFPictureData");
+ }
+ HSLFPictureShape s = new HSLFPictureShape((HSLFPictureData)pictureData);
+ s.setAnchor(new Rectangle(0, 0, 100, 100));
+ addShape(s);
+ return s;
+ }
+
+ @Override
+ public HSLFTable createTable(int numRows, int numCols) {
+ if (numRows < 1 || numCols < 1) {
+ throw new IllegalArgumentException("numRows and numCols must be greater than 0");
+ }
+ HSLFTable s = new HSLFTable(numRows,numCols);
+ s.setAnchor(new Rectangle(0, 0, 100, 100));
+ addShape(s);
+ return s;
+ }
}
*
* @author Yegor Kozlov
*/
-public abstract class HSLFSimpleShape extends HSLFShape implements SimpleShape {
+public abstract class HSLFSimpleShape extends HSLFShape implements SimpleShape<HSLFShape,HSLFTextParagraph> {
public final static double DEFAULT_LINE_WIDTH = 0.75;
* @param escherRecord <code>EscherSpContainer</code> container which holds information about this shape
* @param parent the parent of the shape
*/
- protected HSLFSimpleShape(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape> parent){
+ protected HSLFSimpleShape(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape,HSLFTextParagraph> parent){
super(escherRecord, parent);
}
sp.setFlags(flags);
_escherContainer.addChildRecord(sp);
- EscherOptRecord opt = new EscherOptRecord();
+ AbstractEscherOptRecord opt = new EscherOptRecord();
opt.setRecordId(EscherOptRecord.RECORD_ID);
_escherContainer.addChildRecord(opt);
* Returns width of the line in in points
*/
public double getLineWidth(){
- EscherOptRecord opt = getEscherOptRecord();
+ AbstractEscherOptRecord opt = getEscherOptRecord();
EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.LINESTYLE__LINEWIDTH);
double width = (prop == null) ? DEFAULT_LINE_WIDTH : Units.toPoints(prop.getPropertyValue());
return width;
* @param width the width of line in in points
*/
public void setLineWidth(double width){
- EscherOptRecord opt = getEscherOptRecord();
+ AbstractEscherOptRecord opt = getEscherOptRecord();
setEscherProperty(opt, EscherProperties.LINESTYLE__LINEWIDTH, Units.toEMU(width));
}
* @param color new color of the line
*/
public void setLineColor(Color color){
- EscherOptRecord opt = getEscherOptRecord();
+ AbstractEscherOptRecord opt = getEscherOptRecord();
if (color == null) {
setEscherProperty(opt, EscherProperties.LINESTYLE__NOLINEDRAWDASH, 0x80000);
} else {
* @return color of the line. If color is not set returns <code>java.awt.Color.black</code>
*/
public Color getLineColor(){
- EscherOptRecord opt = getEscherOptRecord();
+ AbstractEscherOptRecord opt = getEscherOptRecord();
EscherSimpleProperty p = getEscherProperty(opt, EscherProperties.LINESTYLE__NOLINEDRAWDASH);
if(p != null && (p.getPropertyValue() & 0x8) == 0) return null;
* @return dashing of the line.
*/
public LineDash getLineDashing(){
- EscherOptRecord opt = getEscherOptRecord();
+ AbstractEscherOptRecord opt = getEscherOptRecord();
EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.LINESTYLE__LINEDASHING);
return (prop == null) ? LineDash.SOLID : LineDash.fromNativeId(prop.getPropertyValue());
}
* @param pen new style of the line.
*/
public void setLineDashing(LineDash pen){
- EscherOptRecord opt = getEscherOptRecord();
+ AbstractEscherOptRecord opt = getEscherOptRecord();
setEscherProperty(opt, EscherProperties.LINESTYLE__LINEDASHING, pen == LineDash.SOLID ? -1 : pen.nativeId);
}
* @return the compound style of the line.
*/
public LineCompound getLineCompound() {
- EscherOptRecord opt = getEscherOptRecord();
+ AbstractEscherOptRecord opt = getEscherOptRecord();
EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.LINESTYLE__LINESTYLE);
return (prop == null) ? LineCompound.SINGLE : LineCompound.fromNativeId(prop.getPropertyValue());
}
* @param style new compound style of the line.
*/
public void setLineCompound(LineCompound style){
- EscherOptRecord opt = getEscherOptRecord();
+ AbstractEscherOptRecord opt = getEscherOptRecord();
setEscherProperty(opt, EscherProperties.LINESTYLE__LINESTYLE, style == LineCompound.SINGLE ? -1 : style.nativeId);
}
public double getShadowAngle() {
- EscherOptRecord opt = getEscherOptRecord();
+ AbstractEscherOptRecord opt = getEscherOptRecord();
EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.SHADOWSTYLE__OFFSETX);
int offX = (prop == null) ? 0 : prop.getPropertyValue();
prop = getEscherProperty(opt, EscherProperties.SHADOWSTYLE__OFFSETY);
}
public double getShadowDistance() {
- EscherOptRecord opt = getEscherOptRecord();
+ AbstractEscherOptRecord opt = getEscherOptRecord();
EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.SHADOWSTYLE__OFFSETX);
int offX = (prop == null) ? 0 : prop.getPropertyValue();
prop = getEscherProperty(opt, EscherProperties.SHADOWSTYLE__OFFSETY);
}
public Shadow getShadow() {
- EscherOptRecord opt = getEscherOptRecord();
+ AbstractEscherOptRecord opt = getEscherOptRecord();
EscherProperty shadowType = opt.lookup(EscherProperties.SHADOWSTYLE__TYPE);
if (shadowType == null) return null;
return new Shadow(){
- public SimpleShape getShadowParent() {
+ public SimpleShape<HSLFShape,HSLFTextParagraph> getShadowParent() {
return HSLFSimpleShape.this;
}
import java.util.ArrayList;
import java.util.List;
-import org.apache.poi.ddf.*;
-import org.apache.poi.hslf.model.*;
-import org.apache.poi.hslf.record.*;
+import org.apache.poi.ddf.EscherContainerRecord;
+import org.apache.poi.ddf.EscherDgRecord;
+import org.apache.poi.ddf.EscherDggRecord;
+import org.apache.poi.ddf.EscherSpRecord;
+import org.apache.poi.hslf.model.Comment;
+import org.apache.poi.hslf.model.HeadersFooters;
+import org.apache.poi.hslf.model.Placeholder;
+import org.apache.poi.hslf.record.ColorSchemeAtom;
+import org.apache.poi.hslf.record.Comment2000;
+import org.apache.poi.hslf.record.EscherTextboxWrapper;
+import org.apache.poi.hslf.record.HeadersFootersContainer;
+import org.apache.poi.hslf.record.Record;
+import org.apache.poi.hslf.record.RecordContainer;
+import org.apache.poi.hslf.record.RecordTypes;
+import org.apache.poi.hslf.record.SSSlideInfoAtom;
+import org.apache.poi.hslf.record.SlideAtom;
import org.apache.poi.hslf.record.SlideListWithText.SlideAtomsSet;
+import org.apache.poi.hslf.record.StyleTextProp9Atom;
+import org.apache.poi.hslf.record.TextHeaderAtom;
import org.apache.poi.sl.draw.DrawFactory;
import org.apache.poi.sl.draw.Drawable;
+import org.apache.poi.sl.usermodel.Notes;
import org.apache.poi.sl.usermodel.ShapeType;
import org.apache.poi.sl.usermodel.Slide;
* @author Yegor Kozlov
*/
-public final class HSLFSlide extends HSLFSheet implements Slide<HSLFShape,HSLFSlideShow,HSLFNotes> {
+public final class HSLFSlide extends HSLFSheet implements Slide<HSLFShape,HSLFTextParagraph> {
private int _slideNo;
private SlideAtomsSet _atomSet;
private final List<List<HSLFTextParagraph>> _paragraphs = new ArrayList<List<HSLFTextParagraph>>();
* references in the records to point to the new ID
*/
@Override
- public void setNotes(HSLFNotes notes) {
- _notes = notes;
+ public void setNotes(Notes<HSLFShape,HSLFTextParagraph> notes) {
+ if (notes != null && !(notes instanceof HSLFNotes)) {
+ throw new IllegalArgumentException("notes needs to be of type HSLFNotes");
+ }
+ _notes = (HSLFNotes)notes;
// Update the Slide Atom's ID of where to point to
SlideAtom sa = getSlideRecord().getSlideAtom();
import org.apache.poi.sl.usermodel.MasterSheet;
import org.apache.poi.sl.usermodel.PictureData.PictureType;
import org.apache.poi.sl.usermodel.Resources;
-import org.apache.poi.sl.usermodel.Shape;
import org.apache.poi.sl.usermodel.SlideShow;
import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger;
* @author Nick Burch
* @author Yegor kozlov
*/
-public final class HSLFSlideShow implements SlideShow {
+public final class HSLFSlideShow implements SlideShow<HSLFShape,HSLFTextParagraph> {
// What we're based on
private HSLFSlideShowImpl _hslfSlideShow;
*
* @return the created <code>Slide</code>
*/
+ @Override
public HSLFSlide createSlide() {
SlideListWithText slist = null;
return psrId;
}
- public MasterSheet<? extends Shape, ? extends SlideShow> createMasterSheet()
- throws IOException {
+ public MasterSheet<HSLFShape,HSLFTextParagraph> createMasterSheet() throws IOException {
// TODO Auto-generated method stub
return null;
}
import java.util.Iterator;
import java.util.List;
+import org.apache.poi.ddf.AbstractEscherOptRecord;
import org.apache.poi.ddf.EscherArrayProperty;
import org.apache.poi.ddf.EscherContainerRecord;
import org.apache.poi.ddf.EscherOptRecord;
import org.apache.poi.ddf.EscherRecord;
import org.apache.poi.ddf.EscherSimpleProperty;
import org.apache.poi.ddf.EscherTextboxRecord;
+import org.apache.poi.hslf.record.RecordTypes;
import org.apache.poi.sl.usermodel.ShapeContainer;
import org.apache.poi.sl.usermodel.TableShape;
import org.apache.poi.util.LittleEndian;
*
* @author Yegor Kozlov
*/
-public final class HSLFTable extends HSLFGroupShape implements TableShape {
+public final class HSLFTable extends HSLFGroupShape
+implements HSLFShapeContainer, TableShape<HSLFShape,HSLFTextParagraph> {
protected static final int BORDER_TOP = 1;
protected static final int BORDER_RIGHT = 2;
/**
* Create a new Table of the given number of rows and columns
*
- * @param numrows the number of rows
- * @param numcols the number of columns
+ * @param numRows the number of rows
+ * @param numCols the number of columns
*/
- public HSLFTable(int numrows, int numcols) {
- super();
+ public HSLFTable(int numRows, int numCols) {
+ this(numRows, numCols, null);
+ }
+
+ /**
+ * Create a new Table of the given number of rows and columns
+ *
+ * @param numRows the number of rows
+ * @param numCols the number of columns
+ * @param parent the parent shape, or null if table is added to sheet
+ */
+ public HSLFTable(int numRows, int numCols, ShapeContainer<HSLFShape,HSLFTextParagraph> parent) {
+ super(parent);
- if(numrows < 1) throw new IllegalArgumentException("The number of rows must be greater than 1");
- if(numcols < 1) throw new IllegalArgumentException("The number of columns must be greater than 1");
+ if(numRows < 1) throw new IllegalArgumentException("The number of rows must be greater than 1");
+ if(numCols < 1) throw new IllegalArgumentException("The number of columns must be greater than 1");
int x=0, y=0, tblWidth=0, tblHeight=0;
- cells = new HSLFTableCell[numrows][numcols];
+ cells = new HSLFTableCell[numRows][numCols];
for (int i = 0; i < cells.length; i++) {
x = 0;
for (int j = 0; j < cells[i].length; j++) {
setAnchor(new Rectangle(0, 0, tblWidth, tblHeight));
EscherContainerRecord spCont = (EscherContainerRecord) getSpContainer().getChild(0);
- EscherOptRecord opt = new EscherOptRecord();
- opt.setRecordId((short)0xF122);
+ AbstractEscherOptRecord opt = new EscherOptRecord();
+ opt.setRecordId((short)RecordTypes.EscherUserDefined);
opt.addEscherProperty(new EscherSimpleProperty((short)0x39F, 1));
EscherArrayProperty p = new EscherArrayProperty((short)(0x4000 | 0x3A0), false, null);
p.setSizeOfElements(0x0004);
- p.setNumberOfElementsInArray(numrows);
- p.setNumberOfElementsInMemory(numrows);
+ p.setNumberOfElementsInArray(numRows);
+ p.setNumberOfElementsInMemory(numRows);
opt.addEscherProperty(p);
- List<EscherRecord> lst = spCont.getChildRecords();
- lst.add(lst.size()-1, opt);
- spCont.setChildRecords(lst);
+ spCont.addChildBefore(opt, RecordTypes.EscherClientAnchor);
}
/**
* @param escherRecord <code>EscherSpContainer</code> container which holds information about this shape
* @param parent the parent of the shape
*/
- public HSLFTable(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape> parent) {
+ public HSLFTable(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape,HSLFTextParagraph> parent) {
super(escherRecord, parent);
}
EscherContainerRecord spCont = (EscherContainerRecord) getSpContainer().getChild(0);
List<EscherRecord> lst = spCont.getChildRecords();
- EscherOptRecord opt = (EscherOptRecord)lst.get(lst.size()-2);
+ AbstractEscherOptRecord opt = (AbstractEscherOptRecord)lst.get(lst.size()-2);
EscherArrayProperty p = opt.lookup(0x3A0);
for (int i = 0; i < cells.length; i++) {
HSLFTableCell cell = cells[i][0];
public HSLFLine createBorder(){
HSLFLine line = new HSLFLine(this);
- EscherOptRecord opt = getEscherOptRecord();
+ AbstractEscherOptRecord opt = getEscherOptRecord();
setEscherProperty(opt, EscherProperties.GEOMETRY__SHAPEPATH, -1);
setEscherProperty(opt, EscherProperties.GEOMETRY__FILLOK, -1);
setEscherProperty(opt, EscherProperties.SHADOWSTYLE__SHADOWOBSURED, 0x20000);
import java.awt.Rectangle;
+import org.apache.poi.ddf.AbstractEscherOptRecord;
import org.apache.poi.ddf.EscherContainerRecord;
-import org.apache.poi.ddf.EscherOptRecord;
import org.apache.poi.ddf.EscherProperties;
import org.apache.poi.sl.usermodel.ShapeContainer;
import org.apache.poi.sl.usermodel.ShapeType;
+import org.apache.poi.sl.usermodel.TableCell;
/**
* Represents a cell in a ppt table
*
* @author Yegor Kozlov
*/
-public final class HSLFTableCell extends HSLFTextBox {
+public final class HSLFTableCell extends HSLFTextBox implements TableCell<HSLFShape,HSLFTextParagraph> {
protected static final int DEFAULT_WIDTH = 100;
protected static final int DEFAULT_HEIGHT = 40;
* @param escherRecord EscherSpContainer which holds information about this shape
* @param parent the parent of the shape
*/
- protected HSLFTableCell(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape> parent){
+ protected HSLFTableCell(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape,HSLFTextParagraph> parent){
super(escherRecord, parent);
}
* @param parent the parent of this Shape. For example, if this text box is a cell
* in a table then the parent is Table.
*/
- public HSLFTableCell(ShapeContainer<HSLFShape> parent){
+ public HSLFTableCell(ShapeContainer<HSLFShape,HSLFTextParagraph> parent){
super(parent);
setShapeType(ShapeType.RECT);
protected EscherContainerRecord createSpContainer(boolean isChild){
_escherContainer = super.createSpContainer(isChild);
- EscherOptRecord opt = getEscherOptRecord();
+ AbstractEscherOptRecord opt = getEscherOptRecord();
setEscherProperty(opt, EscherProperties.TEXT__TEXTID, 0);
setEscherProperty(opt, EscherProperties.TEXT__SIZE_TEXT_TO_FIT_SHAPE, 0x20000);
setEscherProperty(opt, EscherProperties.FILL__NOFILLHITTEST, 0x150001);
*
* @author Yegor Kozlov
*/
-public class HSLFTextBox extends HSLFTextShape {
+public class HSLFTextBox extends HSLFTextShape implements TextBox<HSLFShape,HSLFTextParagraph> {
/**
* Create a TextBox object and initialize it from the supplied Record container.
* @param escherRecord <code>EscherSpContainer</code> container which holds information about this shape
* @param parent the parent of the shape
*/
- protected HSLFTextBox(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape> parent){
+ protected HSLFTextBox(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape,HSLFTextParagraph> parent){
super(escherRecord, parent);
}
* @param parent the parent of this Shape. For example, if this text box is a cell
* in a table then the parent is Table.
*/
- public HSLFTextBox(ShapeContainer<HSLFShape> parent){
+ public HSLFTextBox(ShapeContainer<HSLFShape,HSLFTextParagraph> parent){
super(parent);
}
* @author Nick Burch\r
*/\r
\r
-public final class HSLFTextParagraph implements TextParagraph<HSLFTextRun> {\r
+public final class HSLFTextParagraph implements TextParagraph<HSLFShape,HSLFTextParagraph,HSLFTextRun> {\r
protected static final POILogger logger = POILogFactory.getLogger(HSLFTextParagraph.class);\r
\r
/**\r
*
* @author Yegor Kozlov
*/
-public abstract class HSLFTextShape extends HSLFSimpleShape implements TextShape<HSLFTextParagraph> {
+public abstract class HSLFTextShape extends HSLFSimpleShape
+implements TextShape<HSLFShape,HSLFTextParagraph> {
/**
* How to anchor the text
* @param escherRecord <code>EscherSpContainer</code> container which holds information about this shape
* @param parent the parent of the shape
*/
- protected HSLFTextShape(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape> parent){
+ protected HSLFTextShape(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape,HSLFTextParagraph> parent){
super(escherRecord, parent);
-
}
/**
* @param parent the parent of this Shape. For example, if this text box is a cell
* in a table then the parent is Table.
*/
- public HSLFTextShape(ShapeContainer<HSLFShape> parent){
+ public HSLFTextShape(ShapeContainer<HSLFShape,HSLFTextParagraph> parent){
super(null, parent);
_escherContainer = createSpContainer(parent instanceof HSLFGroupShape);
}
* @return the type of alignment
*/
/* package */ int getAlignment(){
- EscherOptRecord opt = getEscherOptRecord();
+ AbstractEscherOptRecord opt = getEscherOptRecord();
EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.TEXT__ANCHORTEXT);
int align = HSLFTextShape.AnchorTop;
if (prop == null){
* @return the inset in points
*/
private double getInset(short propId, double defaultInch) {
- EscherOptRecord opt = getEscherOptRecord();
+ AbstractEscherOptRecord opt = getEscherOptRecord();
EscherSimpleProperty prop = getEscherProperty(opt, propId);
int val = prop == null ? (int)(Units.toEMU(Units.POINT_DPI)*defaultInch) : prop.getPropertyValue();
return Units.toPoints(val);
* @see <a href="https://msdn.microsoft.com/en-us/library/dd948168(v=office.12).aspx">MSOWRAPMODE</a>
*/
public int getWordWrapEx() {
- EscherOptRecord opt = getEscherOptRecord();
+ AbstractEscherOptRecord opt = getEscherOptRecord();
EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.TEXT__WRAPTEXT);
return prop == null ? WrapSquare : prop.getPropertyValue();
}
* @return id for the text.
*/
public int getTextId(){
- EscherOptRecord opt = getEscherOptRecord();
+ AbstractEscherOptRecord opt = getEscherOptRecord();
EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.TEXT__TEXTID);
return prop == null ? 0 : prop.getPropertyValue();
}
setEscherProperty(EscherProperties.TEXT__TEXTID, id);
}
- /**
- * @return the TextParagraphs for this text box
- */
+ @Override
public List<HSLFTextParagraph> getTextParagraphs(){
if (!_paragraphs.isEmpty()) return _paragraphs;
@Override
public double getTextHeight(){
DrawFactory drawFact = DrawFactory.getInstance(null);
- DrawTextShape<HSLFTextShape> dts = drawFact.getDrawable(this);
+ DrawTextShape dts = drawFact.getDrawable(this);
return dts.getTextHeight();
}
import java.util.List;
import org.apache.poi.POIDataSamples;
+import org.apache.poi.ddf.AbstractEscherOptRecord;
import org.apache.poi.ddf.EscherBSERecord;
import org.apache.poi.ddf.EscherContainerRecord;
-import org.apache.poi.ddf.EscherOptRecord;
import org.apache.poi.ddf.EscherProperties;
import org.apache.poi.ddf.EscherRecord;
import org.apache.poi.ddf.EscherSimpleProperty;
}
private int getFillPictureRefCount(HSLFShape shape, HSLFFill fill) {
- EscherOptRecord opt = shape.getEscherOptRecord();
+ AbstractEscherOptRecord opt = shape.getEscherOptRecord();
EscherSimpleProperty p = HSLFShape.getEscherProperty(opt, EscherProperties.FILL__PATTERNTEXTURE);
if(p != null) {
int idx = p.getPropertyValue();
import java.util.List;
import org.apache.poi.POIDataSamples;
+import org.apache.poi.ddf.AbstractEscherOptRecord;
import org.apache.poi.ddf.EscherDgRecord;
import org.apache.poi.ddf.EscherDggRecord;
-import org.apache.poi.ddf.EscherOptRecord;
import org.apache.poi.ddf.EscherProperties;
import org.apache.poi.ddf.EscherSimpleProperty;
import org.apache.poi.hslf.usermodel.HSLFAutoShape;
import org.apache.poi.hslf.usermodel.HSLFGroupShape;
+import org.apache.poi.hslf.usermodel.HSLFLine;
import org.apache.poi.hslf.usermodel.HSLFPictureData;
import org.apache.poi.hslf.usermodel.HSLFPictureShape;
import org.apache.poi.hslf.usermodel.HSLFShape;
import org.apache.poi.hslf.usermodel.HSLFTextParagraph;
import org.apache.poi.hslf.usermodel.HSLFTextRun;
import org.apache.poi.hslf.usermodel.HSLFTextShape;
-import org.apache.poi.hslf.usermodel.HSLFLine;
import org.apache.poi.sl.usermodel.PictureData.PictureType;
import org.apache.poi.sl.usermodel.ShapeType;
import org.apache.poi.sl.usermodel.StrokeStyle.LineDash;
public void lineWidth() {
HSLFSimpleShape sh = new HSLFAutoShape(ShapeType.RT_TRIANGLE);
- EscherOptRecord opt = sh.getEscherOptRecord();
+ AbstractEscherOptRecord opt = sh.getEscherOptRecord();
EscherSimpleProperty prop = HSLFSimpleShape.getEscherProperty(opt, EscherProperties.LINESTYLE__LINEWIDTH);
assertNull(prop);
assertEquals(HSLFSimpleShape.DEFAULT_LINE_WIDTH, sh.getLineWidth(), 0);
*/
@Test
public void test57820() throws Exception {
- SlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("bug57820-initTableNullRefrenceException.ppt"));
+ SlideShow<?,?> ppt = new HSLFSlideShow(_slTests.openResourceAsStream("bug57820-initTableNullRefrenceException.ppt"));
- List<? extends Slide<?,?,?>> slides = ppt.getSlides();
+ List<? extends Slide<?,?>> slides = ppt.getSlides();
assertEquals(1, slides.size());
- List<? extends Shape> shapes = slides.get(0).getShapes(); //throws NullPointerException
+ List<? extends Shape<?,?>> shapes = slides.get(0).getShapes(); //throws NullPointerException
- TableShape tbl = null;
- for(Shape s : shapes) {
+ TableShape<?,?> tbl = null;
+ for(Shape<?,?> s : shapes) {
if(s instanceof TableShape) {
- tbl = (TableShape)s;
+ tbl = (TableShape<?,?>)s;
break;
}
}
import junit.framework.AssertionFailedError;
import org.apache.poi.POIDataSamples;
+import org.apache.poi.ddf.AbstractEscherOptRecord;
import org.apache.poi.ddf.EscherArrayProperty;
import org.apache.poi.ddf.EscherColorRef;
-import org.apache.poi.ddf.EscherOptRecord;
import org.apache.poi.ddf.EscherProperties;
import org.apache.poi.hslf.HSLFTestDataSamples;
import org.apache.poi.hslf.exceptions.OldPowerPointFormatException;
try {
HSLFSlideShow slideShow = new HSLFSlideShow(inputStream);
HSLFAutoShape as = (HSLFAutoShape)slideShow.getSlides().get(0).getShapes().get(0);
- EscherOptRecord opt = as.getEscherOptRecord();
+ AbstractEscherOptRecord opt = as.getEscherOptRecord();
EscherArrayProperty ep = HSLFShape.getEscherProperty(opt, EscherProperties.FILL__SHADECOLORS);
double exp[][] = {
// r, g, b, position
for (String file : files) {
InputStream is = _slTests.openResourceAsStream(file);
- SlideShow ss;
+ SlideShow<?,?> ss;
if (file.endsWith("pptx")) {
Class<?> cls = Class.forName("org.apache.poi.xslf.usermodel.XMLSlideShow");
Constructor<?> ct = cls.getDeclaredConstructor(InputStream.class);
- ss = (SlideShow)ct.newInstance(is);
+ ss = (SlideShow<?,?>)ct.newInstance(is);
} else {
ss = new HSLFSlideShow(is);
}
boolean debugOut = false;
Dimension pg = ss.getPageSize();
- for (Slide<?,?,?> slide : ss.getSlides()) {
+ for (Slide<?,?> slide : ss.getSlides()) {
int slideNo = slide.getSlideNumber();
if (!pages.get(slideNo-1)) {
if (pages.nextSetBit(slideNo-1) == -1) break; else continue;