diff --git a/src/integrationtest/org/apache/poi/stress/SlideShowHandler.java b/src/integrationtest/org/apache/poi/stress/SlideShowHandler.java index a4de13e40..c1c130241 100644 --- a/src/integrationtest/org/apache/poi/stress/SlideShowHandler.java +++ b/src/integrationtest/org/apache/poi/stress/SlideShowHandler.java @@ -31,7 +31,6 @@ import java.util.Map; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.sl.SlideShowFactory; import org.apache.poi.sl.draw.Drawable; -import org.apache.poi.sl.usermodel.Notes; import org.apache.poi.sl.usermodel.Shape; import org.apache.poi.sl.usermodel.ShapeContainer; import org.apache.poi.sl.usermodel.Slide; @@ -42,7 +41,7 @@ import org.apache.poi.sl.usermodel.TextShape; import org.apache.poi.util.JvmBugs; public abstract class SlideShowHandler extends POIFSFileHandler { - public void handleSlideShow(SlideShow ss) throws IOException { + public void handleSlideShow(SlideShow ss) throws IOException { renderSlides(ss); readContent(ss); @@ -53,7 +52,7 @@ public abstract class SlideShowHandler extends POIFSFileHandler { readContent(ss); // read in the writen file - SlideShow read; + SlideShow read; try { read = SlideShowFactory.create(new ByteArrayInputStream(out.toByteArray())); } catch (InvalidFormatException e) { @@ -65,7 +64,7 @@ public abstract class SlideShowHandler extends POIFSFileHandler { } - private ByteArrayOutputStream writeToArray(SlideShow ss) throws IOException { + private ByteArrayOutputStream writeToArray(SlideShow ss) throws IOException { ByteArrayOutputStream stream = new ByteArrayOutputStream(); try { ss.write(stream); @@ -77,8 +76,8 @@ public abstract class SlideShowHandler extends POIFSFileHandler { } - private void readContent(SlideShow ss) { - for (Slide> s : ss.getSlides()) { + private void readContent(SlideShow ss) { + for (Slide s : ss.getSlides()) { s.getTitle(); readText(s); readText(s.getNotes()); @@ -86,12 +85,11 @@ public abstract class SlideShowHandler extends POIFSFileHandler { } } - @SuppressWarnings("unchecked") - private void readText(ShapeContainer sc) { + private void readText(ShapeContainer sc) { if (sc == null) return; - for (Shape s : sc) { + for (Shape s : sc) { if (s instanceof TextShape) { - for (TextParagraph tp : (TextShape>)s) { + for (TextParagraph tp : (TextShape)s) { for (TextRun tr : tp) { tr.getRawText(); } @@ -100,10 +98,10 @@ public abstract class SlideShowHandler extends POIFSFileHandler { } } - private void renderSlides(SlideShow ss) { + private void renderSlides(SlideShow ss) { Dimension pgsize = ss.getPageSize(); - for (Slide s : ss.getSlides()) { + for (Slide s : ss.getSlides()) { BufferedImage img = new BufferedImage(pgsize.width, pgsize.height, BufferedImage.TYPE_INT_ARGB); Graphics2D graphics = img.createGraphics(); fixFonts(graphics); diff --git a/src/java/org/apache/poi/ddf/EscherContainerRecord.java b/src/java/org/apache/poi/ddf/EscherContainerRecord.java index d6139436a..3cb6ddd52 100644 --- a/src/java/org/apache/poi/ddf/EscherContainerRecord.java +++ b/src/java/org/apache/poi/ddf/EscherContainerRecord.java @@ -221,13 +221,13 @@ public final class EscherContainerRecord extends EscherRecord { } 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() diff --git a/src/java/org/apache/poi/sl/draw/DrawAutoShape.java b/src/java/org/apache/poi/sl/draw/DrawAutoShape.java index 6af2b4b9c..9cda7a32a 100644 --- a/src/java/org/apache/poi/sl/draw/DrawAutoShape.java +++ b/src/java/org/apache/poi/sl/draw/DrawAutoShape.java @@ -20,8 +20,8 @@ package org.apache.poi.sl.draw; import org.apache.poi.sl.usermodel.*; -public class DrawAutoShape>> extends DrawTextShape { - public DrawAutoShape(T shape) { +public class DrawAutoShape extends DrawTextShape { + public DrawAutoShape(AutoShape shape) { super(shape); } } diff --git a/src/java/org/apache/poi/sl/draw/DrawBackground.java b/src/java/org/apache/poi/sl/draw/DrawBackground.java index 35c844d8d..4072fe4bc 100644 --- a/src/java/org/apache/poi/sl/draw/DrawBackground.java +++ b/src/java/org/apache/poi/sl/draw/DrawBackground.java @@ -17,24 +17,28 @@ package org.apache.poi.sl.draw; -import java.awt.*; +import java.awt.Dimension; +import java.awt.Graphics2D; +import java.awt.Paint; import java.awt.geom.Rectangle2D; -import org.apache.poi.sl.usermodel.*; -import org.apache.poi.sl.usermodel.Shape; +import org.apache.poi.sl.usermodel.Background; +import org.apache.poi.sl.usermodel.PlaceableShape; +import org.apache.poi.sl.usermodel.ShapeContainer; -public class DrawBackground extends DrawShape { - public DrawBackground(T shape) { +public class DrawBackground extends DrawShape { + public DrawBackground(Background shape) { super(shape); } + @SuppressWarnings("rawtypes") public void draw(Graphics2D graphics) { Dimension pg = shape.getSheet().getSlideShow().getPageSize(); final Rectangle2D anchor = new Rectangle2D.Double(0, 0, pg.getWidth(), pg.getHeight()); - PlaceableShape ps = new PlaceableShape(){ - public ShapeContainer getParent() { return null; } + PlaceableShape ps = new PlaceableShape(){ + public ShapeContainer getParent() { return null; } public Rectangle2D getAnchor() { return anchor; } public void setAnchor(Rectangle2D anchor) {} public double getRotation() { return 0; } @@ -47,7 +51,7 @@ public class DrawBackground extends DrawShape { DrawFactory drawFact = DrawFactory.getInstance(graphics); DrawPaint dp = drawFact.getPaint(ps); - Paint fill = dp.getPaint(graphics, shape.getFillStyle().getPaint()); + Paint fill = dp.getPaint(graphics, getShape().getFillStyle().getPaint()); Rectangle2D anchor2 = getAnchor(graphics, anchor); if(fill != null) { @@ -56,5 +60,7 @@ public class DrawBackground extends DrawShape { } } - + protected Background getShape() { + return (Background)shape; + } } diff --git a/src/java/org/apache/poi/sl/draw/DrawConnectorShape.java b/src/java/org/apache/poi/sl/draw/DrawConnectorShape.java index 0fee07cf6..00bcd1b58 100644 --- a/src/java/org/apache/poi/sl/draw/DrawConnectorShape.java +++ b/src/java/org/apache/poi/sl/draw/DrawConnectorShape.java @@ -17,10 +17,10 @@ package org.apache.poi.sl.draw; -import org.apache.poi.sl.usermodel.*; +import org.apache.poi.sl.usermodel.ConnectorShape; -public class DrawConnectorShape extends DrawSimpleShape { - public DrawConnectorShape(T shape) { +public class DrawConnectorShape extends DrawSimpleShape { + public DrawConnectorShape(ConnectorShape shape) { super(shape); } } diff --git a/src/java/org/apache/poi/sl/draw/DrawFactory.java b/src/java/org/apache/poi/sl/draw/DrawFactory.java index 8e75514e4..19d347647 100644 --- a/src/java/org/apache/poi/sl/draw/DrawFactory.java +++ b/src/java/org/apache/poi/sl/draw/DrawFactory.java @@ -28,17 +28,14 @@ import org.apache.poi.sl.usermodel.ConnectorShape; import org.apache.poi.sl.usermodel.FreeformShape; import org.apache.poi.sl.usermodel.GroupShape; import org.apache.poi.sl.usermodel.MasterSheet; -import org.apache.poi.sl.usermodel.Notes; import org.apache.poi.sl.usermodel.PictureShape; import org.apache.poi.sl.usermodel.PlaceableShape; import org.apache.poi.sl.usermodel.Shape; import org.apache.poi.sl.usermodel.Sheet; import org.apache.poi.sl.usermodel.Slide; -import org.apache.poi.sl.usermodel.SlideShow; import org.apache.poi.sl.usermodel.TableShape; import org.apache.poi.sl.usermodel.TextBox; import org.apache.poi.sl.usermodel.TextParagraph; -import org.apache.poi.sl.usermodel.TextRun; import org.apache.poi.sl.usermodel.TextShape; public class DrawFactory { @@ -77,90 +74,89 @@ public class DrawFactory { return factory; } - @SuppressWarnings("unchecked") - public Drawable getDrawable(Shape shape) { + public Drawable getDrawable(Shape shape) { if (shape instanceof TextBox) { - return getDrawable((TextBox>)shape); + return getDrawable((TextBox)shape); } else if (shape instanceof FreeformShape) { - return getDrawable((FreeformShape>)shape); + return getDrawable((FreeformShape)shape); } else if (shape instanceof TextShape) { - return getDrawable((TextShape>)shape); - } else if (shape instanceof GroupShape) { - return getDrawable((GroupShape)shape); - } else if (shape instanceof PictureShape) { - return getDrawable((PictureShape)shape); - } else if (shape instanceof Background) { - return getDrawable((Background)shape); - } else if (shape instanceof ConnectorShape) { - return getDrawable((ConnectorShape)shape); + return getDrawable((TextShape)shape); } else if (shape instanceof TableShape) { - return getDrawable((TableShape)shape); + return getDrawable((TableShape)shape); + } else if (shape instanceof GroupShape) { + return getDrawable((GroupShape)shape); + } else if (shape instanceof PictureShape) { + return getDrawable((PictureShape)shape); + } else if (shape instanceof Background) { + return getDrawable((Background)shape); + } else if (shape instanceof ConnectorShape) { + return getDrawable((ConnectorShape)shape); } else if (shape instanceof Slide) { - return getDrawable((Slide>)shape); + return getDrawable((Slide)shape); } else if (shape instanceof MasterSheet) { - return getDrawable((MasterSheet)shape); + return getDrawable((MasterSheet)shape); } else if (shape instanceof Sheet) { - return getDrawable((Sheet)shape); + return getDrawable((Sheet)shape); } else if (shape.getClass().isAnnotationPresent(DrawNotImplemented.class)) { - return new DrawNothing(shape); + return new DrawNothing(shape); } throw new IllegalArgumentException("Unsupported shape type: "+shape.getClass()); } - public >> DrawSlide getDrawable(T sheet) { - return new DrawSlide(sheet); + public DrawSlide getDrawable(Slide sheet) { + return new DrawSlide(sheet); } - public > DrawSheet getDrawable(T sheet) { - return new DrawSheet(sheet); + public DrawSheet getDrawable(Sheet sheet) { + return new DrawSheet(sheet); } - public > DrawMasterSheet getDrawable(T sheet) { - return new DrawMasterSheet(sheet); + public DrawMasterSheet getDrawable(MasterSheet sheet) { + return new DrawMasterSheet(sheet); } - public >> DrawTextBox getDrawable(T shape) { - return new DrawTextBox(shape); + public DrawTextBox getDrawable(TextBox shape) { + return new DrawTextBox(shape); } - public >> DrawFreeformShape getDrawable(T shape) { - return new DrawFreeformShape(shape); + public DrawFreeformShape getDrawable(FreeformShape shape) { + return new DrawFreeformShape(shape); } - public DrawConnectorShape getDrawable(T shape) { - return new DrawConnectorShape(shape); + public DrawConnectorShape getDrawable(ConnectorShape shape) { + return new DrawConnectorShape(shape); } - public DrawTableShape getDrawable(T shape) { - return new DrawTableShape(shape); + public DrawTableShape getDrawable(TableShape shape) { + return new DrawTableShape(shape); } - public >> DrawTextShape getDrawable(T shape) { - return new DrawTextShape(shape); + public DrawTextShape getDrawable(TextShape shape) { + return new DrawTextShape(shape); } - public > DrawGroupShape getDrawable(T shape) { - return new DrawGroupShape(shape); + public DrawGroupShape getDrawable(GroupShape shape) { + return new DrawGroupShape(shape); } - public DrawPictureShape getDrawable(T shape) { - return new DrawPictureShape(shape); + public DrawPictureShape getDrawable(PictureShape shape) { + return new DrawPictureShape(shape); } - public DrawTextParagraph getDrawable(TextParagraph paragraph) { - return new DrawTextParagraph(paragraph); + public DrawTextParagraph getDrawable(TextParagraph paragraph) { + return new DrawTextParagraph(paragraph); } - public DrawBackground getDrawable(T shape) { - return new DrawBackground(shape); + public DrawBackground getDrawable(Background shape) { + return new DrawBackground(shape); } public DrawTextFragment getTextFragment(TextLayout layout, AttributedString str) { return new DrawTextFragment(layout, str); } - public DrawPaint getPaint(PlaceableShape shape) { + public DrawPaint getPaint(PlaceableShape shape) { return new DrawPaint(shape); } } diff --git a/src/java/org/apache/poi/sl/draw/DrawFreeformShape.java b/src/java/org/apache/poi/sl/draw/DrawFreeformShape.java index 1c3d6c07b..ee3bebb1c 100644 --- a/src/java/org/apache/poi/sl/draw/DrawFreeformShape.java +++ b/src/java/org/apache/poi/sl/draw/DrawFreeformShape.java @@ -27,21 +27,24 @@ import org.apache.poi.sl.draw.geom.Path; import org.apache.poi.sl.usermodel.FillStyle; import org.apache.poi.sl.usermodel.FreeformShape; import org.apache.poi.sl.usermodel.StrokeStyle; -import org.apache.poi.sl.usermodel.TextParagraph; -import org.apache.poi.sl.usermodel.TextRun; -public class DrawFreeformShape>> extends DrawAutoShape { - public DrawFreeformShape(T shape) { +public class DrawFreeformShape extends DrawAutoShape { + public DrawFreeformShape(FreeformShape shape) { super(shape); } protected Collection computeOutlines(Graphics2D graphics) { List lst = new ArrayList(); - java.awt.Shape sh = shape.getPath(); - FillStyle fs = shape.getFillStyle(); - StrokeStyle ss = shape.getStrokeStyle(); + java.awt.Shape sh = getShape().getPath(); + FillStyle fs = getShape().getFillStyle(); + StrokeStyle ss = getShape().getStrokeStyle(); Path path = new Path(fs != null, ss != null); lst.add(new Outline(sh, path)); return lst; } + + @Override + protected FreeformShape getShape() { + return (FreeformShape)shape; + } } diff --git a/src/java/org/apache/poi/sl/draw/DrawGroupShape.java b/src/java/org/apache/poi/sl/draw/DrawGroupShape.java index 60af5f710..999e34c54 100644 --- a/src/java/org/apache/poi/sl/draw/DrawGroupShape.java +++ b/src/java/org/apache/poi/sl/draw/DrawGroupShape.java @@ -24,18 +24,18 @@ import java.awt.geom.Rectangle2D; import org.apache.poi.sl.usermodel.*; -public class DrawGroupShape> extends DrawShape implements Drawable { +public class DrawGroupShape extends DrawShape { - public DrawGroupShape(T shape) { + public DrawGroupShape(GroupShape shape) { super(shape); } public void draw(Graphics2D graphics) { // the coordinate system of this group of shape - Rectangle2D interior = shape.getInteriorAnchor(); + Rectangle2D interior = getShape().getInteriorAnchor(); // anchor of this group relative to the parent shape - Rectangle2D exterior = shape.getAnchor(); + Rectangle2D exterior = getShape().getAnchor(); AffineTransform tx = (AffineTransform)graphics.getRenderingHint(Drawable.GROUP_TRANSFORM); AffineTransform tx0 = new AffineTransform(tx); @@ -50,7 +50,7 @@ public class DrawGroupShape> extends DrawS DrawFactory drawFact = DrawFactory.getInstance(graphics); AffineTransform at2 = graphics.getTransform(); - for (Shape child : shape) { + for (Shape child : getShape()) { // remember the initial transform and restore it after we are done with the drawing AffineTransform at = graphics.getTransform(); graphics.setRenderingHint(Drawable.GSAVE, true); @@ -67,4 +67,9 @@ public class DrawGroupShape> extends DrawS graphics.setTransform(at2); graphics.setRenderingHint(Drawable.GROUP_TRANSFORM, tx0); } + + @Override + protected GroupShape getShape() { + return (GroupShape)shape; + } } diff --git a/src/java/org/apache/poi/sl/draw/DrawMasterSheet.java b/src/java/org/apache/poi/sl/draw/DrawMasterSheet.java index 6b5d0781d..76ae92de7 100644 --- a/src/java/org/apache/poi/sl/draw/DrawMasterSheet.java +++ b/src/java/org/apache/poi/sl/draw/DrawMasterSheet.java @@ -20,9 +20,9 @@ package org.apache.poi.sl.draw; import org.apache.poi.sl.usermodel.*; -public class DrawMasterSheet> extends DrawSheet { +public class DrawMasterSheet extends DrawSheet { - public DrawMasterSheet(T sheet) { + public DrawMasterSheet(MasterSheet sheet) { super(sheet); } @@ -32,7 +32,8 @@ public class DrawMasterSheet shape){ + return !(shape instanceof SimpleShape) || !((SimpleShape)shape).isPlaceholder(); } } diff --git a/src/java/org/apache/poi/sl/draw/DrawNothing.java b/src/java/org/apache/poi/sl/draw/DrawNothing.java index eb3288880..d1710b235 100644 --- a/src/java/org/apache/poi/sl/draw/DrawNothing.java +++ b/src/java/org/apache/poi/sl/draw/DrawNothing.java @@ -22,11 +22,11 @@ import java.awt.Graphics2D; import org.apache.poi.sl.usermodel.Shape; -public class DrawNothing implements Drawable { +public class DrawNothing implements Drawable { - protected final T shape; + protected final Shape shape; - public DrawNothing(T shape) { + public DrawNothing(Shape shape) { this.shape = shape; } diff --git a/src/java/org/apache/poi/sl/draw/DrawPaint.java b/src/java/org/apache/poi/sl/draw/DrawPaint.java index 4309d4ec5..7aed90811 100644 --- a/src/java/org/apache/poi/sl/draw/DrawPaint.java +++ b/src/java/org/apache/poi/sl/draw/DrawPaint.java @@ -50,9 +50,9 @@ public class DrawPaint { private final static POILogger LOG = POILogFactory.getLogger(DrawPaint.class); - protected PlaceableShape shape; + protected PlaceableShape shape; - public DrawPaint(PlaceableShape shape) { + public DrawPaint(PlaceableShape shape) { this.shape = shape; } diff --git a/src/java/org/apache/poi/sl/draw/DrawPictureShape.java b/src/java/org/apache/poi/sl/draw/DrawPictureShape.java index 3d00b4ec6..43586f111 100644 --- a/src/java/org/apache/poi/sl/draw/DrawPictureShape.java +++ b/src/java/org/apache/poi/sl/draw/DrawPictureShape.java @@ -26,22 +26,22 @@ import org.apache.poi.sl.usermodel.PictureData; import org.apache.poi.sl.usermodel.PictureShape; -public class DrawPictureShape extends DrawSimpleShape { - public DrawPictureShape(T shape) { +public class DrawPictureShape extends DrawSimpleShape { + public DrawPictureShape(PictureShape shape) { super(shape); } @Override public void drawContent(Graphics2D graphics) { - PictureData data = shape.getPictureData(); + PictureData data = getShape().getPictureData(); if(data == null) return; ImageRenderer renderer = (ImageRenderer)graphics.getRenderingHint(Drawable.IMAGE_RENDERER); if (renderer == null) renderer = new ImageRenderer(); - Rectangle2D anchor = getAnchor(graphics, shape); + Rectangle2D anchor = getAnchor(graphics, getShape()); - Insets insets = shape.getClipping(); + Insets insets = getShape().getClipping(); try { renderer.loadImage(data.getData(), data.getContentType()); @@ -51,4 +51,9 @@ public class DrawPictureShape extends DrawSimpleShape throw new RuntimeException(e); } } + + @Override + protected PictureShape getShape() { + return (PictureShape)shape; + } } diff --git a/src/java/org/apache/poi/sl/draw/DrawShape.java b/src/java/org/apache/poi/sl/draw/DrawShape.java index 13ef4292a..deca5d7a3 100644 --- a/src/java/org/apache/poi/sl/draw/DrawShape.java +++ b/src/java/org/apache/poi/sl/draw/DrawShape.java @@ -25,14 +25,14 @@ import org.apache.poi.sl.usermodel.PlaceableShape; import org.apache.poi.sl.usermodel.Shape; -public class DrawShape implements Drawable { +public class DrawShape implements Drawable { - protected final T shape; - - public DrawShape(T shape) { + protected final Shape shape; + + public DrawShape(Shape shape) { this.shape = shape; } - + /** * Apply 2-D transforms before drawing this shape. This includes rotation and flipping. * @@ -40,8 +40,8 @@ public class DrawShape implements Drawable { */ public void applyTransform(Graphics2D graphics) { if (!(shape instanceof PlaceableShape)) return; - - PlaceableShape ps = (PlaceableShape)shape; + + PlaceableShape ps = (PlaceableShape)shape; AffineTransform tx = (AffineTransform)graphics.getRenderingHint(Drawable.GROUP_TRANSFORM); if (tx == null) tx = new AffineTransform(); final Rectangle2D anchor = tx.createTransformedShape(ps.getAnchor()).getBounds2D(); @@ -59,12 +59,12 @@ public class DrawShape implements Drawable { int quadrant = (((int)rotation+45)/90)%4; double scaleX = 1.0, scaleY = 1.0; - + // scale to bounding box (bug #53176) if (quadrant == 1 || quadrant == 3) { - // In quadrant 1 and 3, which is basically a shape in a more or less portrait orientation - // (45-135 degrees and 225-315 degrees), we need to first rotate the shape by a multiple - // of 90 degrees and then resize the bounding box to its original bbox. After that we can + // In quadrant 1 and 3, which is basically a shape in a more or less portrait orientation + // (45-135 degrees and 225-315 degrees), we need to first rotate the shape by a multiple + // of 90 degrees and then resize the bounding box to its original bbox. After that we can // rotate the shape to the exact rotation amount. // It's strange that you'll need to rotate the shape back and forth again, but you can // think of it, as if you paint the shape on a canvas. First you rotate the canvas, which might @@ -82,19 +82,19 @@ public class DrawShape implements Drawable { txs.translate(-centerX, -centerY); txs.concatenate(tx); } - + txs.translate(centerX, centerY); txs.rotate(Math.PI/2.); txs.translate(-centerX, -centerY); - + Rectangle2D anchor2 = txs.createTransformedShape(ps.getAnchor()).getBounds2D(); - + scaleX = anchor.getWidth() == 0. ? 1.0 : anchor.getWidth() / anchor2.getWidth(); scaleY = anchor.getHeight() == 0. ? 1.0 : anchor.getHeight() / anchor2.getHeight(); } else { quadrant = 0; } - + // transformation is applied reversed ... graphics.translate(centerX, centerY); graphics.rotate(Math.toRadians(rotation-quadrant*90.)); @@ -122,13 +122,13 @@ public class DrawShape implements Drawable { public void draw(Graphics2D graphics) { } - public void drawContent(Graphics2D context) { + public void drawContent(Graphics2D graphics) { } - public static Rectangle2D getAnchor(Graphics2D graphics, PlaceableShape shape) { + public static Rectangle2D getAnchor(Graphics2D graphics, PlaceableShape shape) { return getAnchor(graphics, shape.getAnchor()); } - + public static Rectangle2D getAnchor(Graphics2D graphics, Rectangle2D anchor) { if(graphics == null) { return anchor; @@ -139,5 +139,9 @@ public class DrawShape implements Drawable { anchor = tx.createTransformedShape(anchor).getBounds2D(); } return anchor; - } + } + + protected Shape getShape() { + return shape; + } } diff --git a/src/java/org/apache/poi/sl/draw/DrawSheet.java b/src/java/org/apache/poi/sl/draw/DrawSheet.java index e4c7e185e..dbe82ea6c 100644 --- a/src/java/org/apache/poi/sl/draw/DrawSheet.java +++ b/src/java/org/apache/poi/sl/draw/DrawSheet.java @@ -26,11 +26,11 @@ import java.awt.geom.AffineTransform; import org.apache.poi.sl.usermodel.*; -public class DrawSheet> implements Drawable { +public class DrawSheet implements Drawable { - protected final T sheet; + protected final Sheet sheet; - public DrawSheet(T sheet) { + public DrawSheet(Sheet sheet) { this.sheet = sheet; } @@ -41,7 +41,7 @@ public class DrawSheet> im graphics.fillRect(0, 0, (int)dim.getWidth(), (int)dim.getHeight()); DrawFactory drawFact = DrawFactory.getInstance(graphics); - MasterSheet master = sheet.getMasterSheet(); + MasterSheet master = sheet.getMasterSheet(); if(sheet.getFollowMasterGraphics() && master != null) { Drawable drawer = drawFact.getDrawable(master); @@ -50,7 +50,7 @@ public class DrawSheet> im graphics.setRenderingHint(Drawable.GROUP_TRANSFORM, new AffineTransform()); - for (Shape shape : sheet.getShapes()) { + for (Shape shape : sheet.getShapes()) { if(!canDraw(shape)) continue; // remember the initial transform and restore it after we are done with drawing @@ -85,7 +85,7 @@ public class DrawSheet> im * Subclasses can override it and skip certain shapes from drawings, * for instance, slide masters and layouts don't display placeholders */ - protected boolean canDraw(Shape shape){ + protected boolean canDraw(Shape shape){ return true; } } diff --git a/src/java/org/apache/poi/sl/draw/DrawSimpleShape.java b/src/java/org/apache/poi/sl/draw/DrawSimpleShape.java index 8ffc57e60..37cd6d8b8 100644 --- a/src/java/org/apache/poi/sl/draw/DrawSimpleShape.java +++ b/src/java/org/apache/poi/sl/draw/DrawSimpleShape.java @@ -17,39 +17,60 @@ package org.apache.poi.sl.draw; -import java.awt.*; -import java.awt.geom.*; -import java.io.*; +import java.awt.BasicStroke; +import java.awt.Color; +import java.awt.Graphics2D; +import java.awt.Paint; +import java.awt.geom.AffineTransform; +import java.awt.geom.Ellipse2D; +import java.awt.geom.GeneralPath; +import java.awt.geom.Rectangle2D; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; import java.nio.charset.Charset; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; import java.util.List; +import java.util.Map; -import javax.xml.bind.*; -import javax.xml.stream.*; +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBElement; +import javax.xml.bind.Unmarshaller; import javax.xml.stream.EventFilter; +import javax.xml.stream.XMLEventReader; +import javax.xml.stream.XMLInputFactory; import javax.xml.stream.events.StartElement; import javax.xml.stream.events.XMLEvent; import org.apache.poi.sl.draw.binding.CTCustomGeometry2D; -import org.apache.poi.sl.draw.geom.*; -import org.apache.poi.sl.usermodel.*; +import org.apache.poi.sl.draw.geom.Context; +import org.apache.poi.sl.draw.geom.CustomGeometry; +import org.apache.poi.sl.draw.geom.Outline; +import org.apache.poi.sl.draw.geom.Path; +import org.apache.poi.sl.usermodel.LineDecoration; import org.apache.poi.sl.usermodel.LineDecoration.DecorationSize; import org.apache.poi.sl.usermodel.PaintStyle.SolidPaint; -import org.apache.poi.sl.usermodel.StrokeStyle.*; +import org.apache.poi.sl.usermodel.Shadow; +import org.apache.poi.sl.usermodel.SimpleShape; +import org.apache.poi.sl.usermodel.StrokeStyle; +import org.apache.poi.sl.usermodel.StrokeStyle.LineCap; +import org.apache.poi.sl.usermodel.StrokeStyle.LineDash; import org.apache.poi.util.Units; -public class DrawSimpleShape extends DrawShape { +public class DrawSimpleShape extends DrawShape { - public DrawSimpleShape(T shape) { + public DrawSimpleShape(SimpleShape shape) { super(shape); } @Override public void draw(Graphics2D graphics) { - DrawPaint drawPaint = DrawFactory.getInstance(graphics).getPaint(shape); - Paint fill = drawPaint.getPaint(graphics, shape.getFillStyle().getPaint()); - Paint line = drawPaint.getPaint(graphics, shape.getStrokeStyle().getPaint()); + DrawPaint drawPaint = DrawFactory.getInstance(graphics).getPaint(getShape()); + Paint fill = drawPaint.getPaint(graphics, getShape().getFillStyle().getPaint()); + Paint line = drawPaint.getPaint(graphics, getShape().getStrokeStyle().getPaint()); BasicStroke stroke = getStroke(); // the stroke applies both to the shadow and the shape graphics.setStroke(stroke); @@ -94,7 +115,7 @@ public class DrawSimpleShape extends DrawShape { graphics.setPaint(line); List lst = new ArrayList(); - LineDecoration deco = shape.getLineDecoration(); + LineDecoration deco = getShape().getLineDecoration(); Outline head = getHeadDecoration(graphics, deco, stroke); if (head != null) lst.add(head); Outline tail = getTailDecoration(graphics, deco, stroke); @@ -117,7 +138,7 @@ public class DrawSimpleShape extends DrawShape { double lineWidth = Math.max(2.5, stroke.getLineWidth()); - Rectangle2D anchor = getAnchor(graphics, shape); + Rectangle2D anchor = getAnchor(graphics, getShape()); double x2 = anchor.getX() + anchor.getWidth(), y2 = anchor.getY() + anchor.getHeight(); @@ -175,7 +196,7 @@ public class DrawSimpleShape extends DrawShape { double lineWidth = Math.max(2.5, stroke.getLineWidth()); - Rectangle2D anchor = getAnchor(graphics, shape); + Rectangle2D anchor = getAnchor(graphics, getShape()); double x1 = anchor.getX(), y1 = anchor.getY(); @@ -228,7 +249,7 @@ public class DrawSimpleShape extends DrawShape { } public BasicStroke getStroke() { - StrokeStyle strokeStyle = shape.getStrokeStyle(); + StrokeStyle strokeStyle = getShape().getStrokeStyle(); float lineWidth = (float) strokeStyle.getLineWidth(); if (lineWidth == 0.0f) lineWidth = 0.25f; // Both PowerPoint and OOo draw zero-length lines as 0.25pt @@ -275,14 +296,14 @@ public class DrawSimpleShape extends DrawShape { , Paint fill , Paint line ) { - Shadow shadow = shape.getShadow(); + Shadow shadow = getShape().getShadow(); if (shadow == null || (fill == null && line == null)) return; SolidPaint shadowPaint = shadow.getFillStyle(); Color shadowColor = DrawPaint.applyColorTransform(shadowPaint.getSolidColor()); - double shapeRotation = shape.getRotation(); - if(shape.getFlipVertical()) { + double shapeRotation = getShape().getRotation(); + if(getShape().getFlipVertical()) { shapeRotation += 180; } double angle = shadow.getAngle() - shapeRotation; @@ -366,12 +387,12 @@ public class DrawSimpleShape extends DrawShape { protected Collection computeOutlines(Graphics2D graphics) { List lst = new ArrayList(); - CustomGeometry geom = shape.getGeometry(); + CustomGeometry geom = getShape().getGeometry(); if(geom == null) { return lst; } - Rectangle2D anchor = getAnchor(graphics, shape); + Rectangle2D anchor = getAnchor(graphics, getShape()); for (Path p : geom) { double w = p.getW() == -1 ? anchor.getWidth() * Units.EMU_PER_POINT : p.getW(); @@ -381,7 +402,7 @@ public class DrawSimpleShape extends DrawShape { // so we build the path starting from (0,0). final Rectangle2D pathAnchor = new Rectangle2D.Double(0,0,w,h); - Context ctx = new Context(geom, pathAnchor, shape); + Context ctx = new Context(geom, pathAnchor, getShape()); java.awt.Shape gp = p.getPath(ctx); @@ -411,4 +432,8 @@ public class DrawSimpleShape extends DrawShape { return lst; } + @Override + protected SimpleShape getShape() { + return (SimpleShape)shape; + } } diff --git a/src/java/org/apache/poi/sl/draw/DrawSlide.java b/src/java/org/apache/poi/sl/draw/DrawSlide.java index cfa316738..ae4baa27f 100644 --- a/src/java/org/apache/poi/sl/draw/DrawSlide.java +++ b/src/java/org/apache/poi/sl/draw/DrawSlide.java @@ -22,14 +22,14 @@ import java.awt.Graphics2D; import org.apache.poi.sl.usermodel.*; -public class DrawSlide>> extends DrawSheet { +public class DrawSlide extends DrawSheet { - public DrawSlide(T slide) { + public DrawSlide(Slide slide) { super(slide); } public void draw(Graphics2D graphics) { - Background bg = sheet.getBackground(); + Background bg = sheet.getBackground(); if(bg != null) { DrawFactory drawFact = DrawFactory.getInstance(graphics); Drawable db = drawFact.getDrawable(bg); diff --git a/src/java/org/apache/poi/sl/draw/DrawTableShape.java b/src/java/org/apache/poi/sl/draw/DrawTableShape.java index ceb6450d0..b252ddfda 100644 --- a/src/java/org/apache/poi/sl/draw/DrawTableShape.java +++ b/src/java/org/apache/poi/sl/draw/DrawTableShape.java @@ -17,11 +17,45 @@ package org.apache.poi.sl.draw; -import org.apache.poi.sl.usermodel.*; +import java.awt.Graphics2D; -public class DrawTableShape extends DrawShape { +import org.apache.poi.sl.usermodel.GroupShape; +import org.apache.poi.sl.usermodel.TableShape; + +public class DrawTableShape extends DrawShape { // to be implemented ... - public DrawTableShape(T shape) { + public DrawTableShape(TableShape shape) { super(shape); } + + protected Drawable getDrawable(Graphics2D graphics) { + if (shape instanceof GroupShape) { + DrawFactory df = DrawFactory.getInstance(graphics); + return df.getDrawable((GroupShape)shape); + } + return null; + } + + public void applyTransform(Graphics2D graphics) { + Drawable d = getDrawable(graphics); + if (d != null) { + d.applyTransform(graphics); + } + } + + public void draw(Graphics2D graphics) { + Drawable d = getDrawable(graphics); + if (d != null) { + d.draw(graphics); + } + } + + public void drawContent(Graphics2D graphics) { + Drawable d = getDrawable(graphics); + if (d != null) { + d.drawContent(graphics); + } + } + + } diff --git a/src/java/org/apache/poi/sl/draw/DrawTextBox.java b/src/java/org/apache/poi/sl/draw/DrawTextBox.java index 89d69223f..d44d10807 100644 --- a/src/java/org/apache/poi/sl/draw/DrawTextBox.java +++ b/src/java/org/apache/poi/sl/draw/DrawTextBox.java @@ -19,8 +19,8 @@ package org.apache.poi.sl.draw; import org.apache.poi.sl.usermodel.*; -public class DrawTextBox>> extends DrawAutoShape { - public DrawTextBox(T shape) { +public class DrawTextBox extends DrawAutoShape { + public DrawTextBox(TextBox shape) { super(shape); } } diff --git a/src/java/org/apache/poi/sl/draw/DrawTextParagraph.java b/src/java/org/apache/poi/sl/draw/DrawTextParagraph.java index 1bdd1e829..8cfa48162 100644 --- a/src/java/org/apache/poi/sl/draw/DrawTextParagraph.java +++ b/src/java/org/apache/poi/sl/draw/DrawTextParagraph.java @@ -35,7 +35,6 @@ import org.apache.poi.sl.usermodel.AutoNumberingScheme; import org.apache.poi.sl.usermodel.Insets2D; import org.apache.poi.sl.usermodel.PaintStyle; import org.apache.poi.sl.usermodel.PlaceableShape; -import org.apache.poi.sl.usermodel.Shape; import org.apache.poi.sl.usermodel.ShapeContainer; import org.apache.poi.sl.usermodel.TextParagraph; import org.apache.poi.sl.usermodel.TextParagraph.BulletStyle; @@ -45,8 +44,8 @@ import org.apache.poi.sl.usermodel.TextRun.TextCap; import org.apache.poi.sl.usermodel.TextShape; import org.apache.poi.util.Units; -public class DrawTextParagraph implements Drawable { - protected TextParagraph paragraph; +public class DrawTextParagraph implements Drawable { + protected TextParagraph paragraph; double x, y; protected List lines = new ArrayList(); protected String rawText; @@ -58,7 +57,7 @@ public class DrawTextParagraph implements Drawable { */ protected double maxLineHeight; - public DrawTextParagraph(TextParagraph paragraph) { + public DrawTextParagraph(TextParagraph paragraph) { this.paragraph = paragraph; } @@ -266,7 +265,7 @@ public class DrawTextParagraph implements Drawable { if (buFont == null) buFont = paragraph.getDefaultFontFamily(); assert(buFont != null); - PlaceableShape ps = getParagraphShape(); + PlaceableShape ps = getParagraphShape(); PaintStyle fgPaintStyle = bulletStyle.getBulletFontColor(); Paint fgPaint; if (fgPaintStyle == null) { @@ -377,7 +376,7 @@ public class DrawTextParagraph implements Drawable { } double width; - TextShape> ts = paragraph.getParentShape(); + TextShape ts = paragraph.getParentShape(); if (!ts.getWordWrap()) { // if wordWrap == false then we return the advance to the right border of the sheet width = ts.getSheet().getSlideShow().getPageSize().getWidth() - anchor.getX(); @@ -413,9 +412,10 @@ public class DrawTextParagraph implements Drawable { /** * Helper method for paint style relative to bounds, e.g. gradient paint */ - private PlaceableShape getParagraphShape() { - PlaceableShape ps = new PlaceableShape(){ - public ShapeContainer getParent() { return null; } + @SuppressWarnings("rawtypes") + private PlaceableShape getParagraphShape() { + PlaceableShape ps = new PlaceableShape(){ + public ShapeContainer getParent() { return null; } public Rectangle2D getAnchor() { return paragraph.getParentShape().getAnchor(); } public void setAnchor(Rectangle2D anchor) {} public double getRotation() { return 0; } @@ -432,7 +432,7 @@ public class DrawTextParagraph implements Drawable { List attList = new ArrayList(); if (text == null) text = new StringBuilder(); - PlaceableShape ps = getParagraphShape(); + PlaceableShape ps = getParagraphShape(); DrawFontManager fontHandler = (DrawFontManager)graphics.getRenderingHint(Drawable.FONT_HANDLER); diff --git a/src/java/org/apache/poi/sl/draw/DrawTextShape.java b/src/java/org/apache/poi/sl/draw/DrawTextShape.java index 36896ba68..b1ec2d943 100644 --- a/src/java/org/apache/poi/sl/draw/DrawTextShape.java +++ b/src/java/org/apache/poi/sl/draw/DrawTextShape.java @@ -27,9 +27,9 @@ import org.apache.poi.sl.usermodel.*; import org.apache.poi.sl.usermodel.TextParagraph.BulletStyle; import org.apache.poi.util.JvmBugs; -public class DrawTextShape>> extends DrawSimpleShape { +public class DrawTextShape extends DrawSimpleShape { - public DrawTextShape(T shape) { + public DrawTextShape(TextShape shape) { super(shape); } @@ -37,8 +37,8 @@ public class DrawTextShape> paragraphs = shape.iterator(); + Iterator> paragraphs = getShape().iterator(); boolean isFirstLine = true; for (int autoNbrIdx=0; paragraphs.hasNext(); autoNbrIdx++){ - TextParagraph p = paragraphs.next(); - DrawTextParagraph dp = fact.getDrawable(p); + TextParagraph p = paragraphs.next(); + DrawTextParagraph dp = fact.getDrawable(p); BulletStyle bs = p.getBulletStyle(); if (bs == null || bs.getAutoNumberingScheme() == null) { autoNbrIdx = -1; @@ -180,4 +180,9 @@ public class DrawTextShape getShape() { + return (TextShape)shape; + } } diff --git a/src/java/org/apache/poi/sl/usermodel/AutoShape.java b/src/java/org/apache/poi/sl/usermodel/AutoShape.java index 1bf073dfb..bea050213 100644 --- a/src/java/org/apache/poi/sl/usermodel/AutoShape.java +++ b/src/java/org/apache/poi/sl/usermodel/AutoShape.java @@ -17,5 +17,8 @@ package org.apache.poi.sl.usermodel; -public interface AutoShape> extends TextShape { +public interface AutoShape< + S extends Shape, + P extends TextParagraph +> extends TextShape { } diff --git a/src/java/org/apache/poi/sl/usermodel/Background.java b/src/java/org/apache/poi/sl/usermodel/Background.java index 8d868b860..879879a20 100644 --- a/src/java/org/apache/poi/sl/usermodel/Background.java +++ b/src/java/org/apache/poi/sl/usermodel/Background.java @@ -17,6 +17,9 @@ package org.apache.poi.sl.usermodel; -public interface Background extends Shape { +public interface Background< + S extends Shape, + P extends TextParagraph +> extends Shape { FillStyle getFillStyle(); } diff --git a/src/java/org/apache/poi/sl/usermodel/ConnectorShape.java b/src/java/org/apache/poi/sl/usermodel/ConnectorShape.java index 7e2bbf065..8d356b655 100644 --- a/src/java/org/apache/poi/sl/usermodel/ConnectorShape.java +++ b/src/java/org/apache/poi/sl/usermodel/ConnectorShape.java @@ -17,6 +17,9 @@ package org.apache.poi.sl.usermodel; -public interface ConnectorShape extends SimpleShape { +public interface ConnectorShape< + S extends Shape, + P extends TextParagraph +> extends SimpleShape { } diff --git a/src/java/org/apache/poi/sl/usermodel/FreeformShape.java b/src/java/org/apache/poi/sl/usermodel/FreeformShape.java index ec288854a..19b5d313f 100644 --- a/src/java/org/apache/poi/sl/usermodel/FreeformShape.java +++ b/src/java/org/apache/poi/sl/usermodel/FreeformShape.java @@ -19,7 +19,10 @@ package org.apache.poi.sl.usermodel; import java.awt.geom.GeneralPath; -public interface FreeformShape> extends AutoShape { +public interface FreeformShape< + S extends Shape, + P extends TextParagraph +> extends AutoShape { /** * Gets the shape path. *

diff --git a/src/java/org/apache/poi/sl/usermodel/GroupShape.java b/src/java/org/apache/poi/sl/usermodel/GroupShape.java index 8133ac048..31f5be534 100644 --- a/src/java/org/apache/poi/sl/usermodel/GroupShape.java +++ b/src/java/org/apache/poi/sl/usermodel/GroupShape.java @@ -19,7 +19,10 @@ package org.apache.poi.sl.usermodel; import java.awt.geom.Rectangle2D; -public interface GroupShape extends Shape, ShapeContainer, PlaceableShape { +public interface GroupShape< + S extends Shape, + P extends TextParagraph +> extends Shape, ShapeContainer, PlaceableShape { /** * Gets the coordinate space of this group. All children are constrained diff --git a/src/java/org/apache/poi/sl/usermodel/Line.java b/src/java/org/apache/poi/sl/usermodel/Line.java index aa42eeab6..d2c2134e5 100644 --- a/src/java/org/apache/poi/sl/usermodel/Line.java +++ b/src/java/org/apache/poi/sl/usermodel/Line.java @@ -25,6 +25,9 @@ import org.apache.poi.util.Internal; */ @Internal -public interface Line> extends AutoShape { +public interface Line< + S extends Shape, + P extends TextParagraph +> extends AutoShape { } diff --git a/src/java/org/apache/poi/sl/usermodel/MasterSheet.java b/src/java/org/apache/poi/sl/usermodel/MasterSheet.java index 727217d3f..ac23bc3bb 100644 --- a/src/java/org/apache/poi/sl/usermodel/MasterSheet.java +++ b/src/java/org/apache/poi/sl/usermodel/MasterSheet.java @@ -17,6 +17,9 @@ package org.apache.poi.sl.usermodel; -public interface MasterSheet extends Sheet { +public interface MasterSheet< + S extends Shape, + P extends TextParagraph +> extends Sheet { } diff --git a/src/java/org/apache/poi/sl/usermodel/Notes.java b/src/java/org/apache/poi/sl/usermodel/Notes.java index 3e4b92472..377ad24c4 100644 --- a/src/java/org/apache/poi/sl/usermodel/Notes.java +++ b/src/java/org/apache/poi/sl/usermodel/Notes.java @@ -19,6 +19,9 @@ package org.apache.poi.sl.usermodel; import java.util.List; -public interface Notes extends Sheet { - List>> getTextParagraphs(); +public interface Notes< + S extends Shape, + P extends TextParagraph +> extends Sheet { + List> getTextParagraphs(); } diff --git a/src/java/org/apache/poi/sl/usermodel/PictureShape.java b/src/java/org/apache/poi/sl/usermodel/PictureShape.java index a2c0824e0..c7fb62941 100644 --- a/src/java/org/apache/poi/sl/usermodel/PictureShape.java +++ b/src/java/org/apache/poi/sl/usermodel/PictureShape.java @@ -19,7 +19,10 @@ package org.apache.poi.sl.usermodel; import java.awt.Insets; -public interface PictureShape extends SimpleShape { +public interface PictureShape< + S extends Shape, + P extends TextParagraph +> extends SimpleShape { /** * Returns the picture data for this picture. * diff --git a/src/java/org/apache/poi/sl/usermodel/PlaceableShape.java b/src/java/org/apache/poi/sl/usermodel/PlaceableShape.java index f81a344b1..f434b3cc6 100644 --- a/src/java/org/apache/poi/sl/usermodel/PlaceableShape.java +++ b/src/java/org/apache/poi/sl/usermodel/PlaceableShape.java @@ -19,8 +19,11 @@ package org.apache.poi.sl.usermodel; import java.awt.geom.Rectangle2D; -public interface PlaceableShape { - ShapeContainer getParent(); +public interface PlaceableShape< + S extends Shape, + P extends TextParagraph +> { + ShapeContainer getParent(); /** * @return the position of this shape within the drawing canvas. diff --git a/src/java/org/apache/poi/sl/usermodel/Shape.java b/src/java/org/apache/poi/sl/usermodel/Shape.java index 4de645d41..164c40643 100644 --- a/src/java/org/apache/poi/sl/usermodel/Shape.java +++ b/src/java/org/apache/poi/sl/usermodel/Shape.java @@ -18,12 +18,15 @@ package org.apache.poi.sl.usermodel; -public interface Shape { - ShapeContainer getParent(); +public interface Shape< + S extends Shape, + P extends TextParagraph +> { + ShapeContainer getParent(); /** * * @return the sheet this shape belongs to */ - Sheet getSheet(); + Sheet getSheet(); } diff --git a/src/java/org/apache/poi/sl/usermodel/ShapeContainer.java b/src/java/org/apache/poi/sl/usermodel/ShapeContainer.java index 0172fa770..b5c296098 100644 --- a/src/java/org/apache/poi/sl/usermodel/ShapeContainer.java +++ b/src/java/org/apache/poi/sl/usermodel/ShapeContainer.java @@ -20,7 +20,10 @@ package org.apache.poi.sl.usermodel; import java.util.List; -public interface ShapeContainer extends Iterable { +public interface ShapeContainer< + S extends Shape, + P extends TextParagraph +> extends Iterable { /** * Returns an list containing all of the elements in this container in proper * sequence (from first to last element). @@ -28,9 +31,9 @@ public interface ShapeContainer extends Iterable { * @return an list containing all of the elements in this container in proper * sequence */ - List getShapes(); + List getShapes(); - void addShape(T shape); + void addShape(S shape); /** * Removes the specified shape from this sheet, if it is present @@ -42,5 +45,43 @@ public interface ShapeContainer extends Iterable { * @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 createAutoShape(); + + /** + * create a new shape with a custom geometry + */ + FreeformShape createFreeform(); + + /** + * create a text box + */ + TextBox createTextBox(); + + /** + * create a connector + */ + ConnectorShape createConnector(); + + /** + * create a group of shapes belonging to this container + */ + GroupShape createGroup(); + + /** + * create a picture belonging to this container + */ + PictureShape 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 createTable(int numRows, int numCols); } diff --git a/src/java/org/apache/poi/sl/usermodel/Sheet.java b/src/java/org/apache/poi/sl/usermodel/Sheet.java index f94b7727a..923dac378 100644 --- a/src/java/org/apache/poi/sl/usermodel/Sheet.java +++ b/src/java/org/apache/poi/sl/usermodel/Sheet.java @@ -23,8 +23,11 @@ import java.awt.Graphics2D; /** * Common parent of Slides, Notes and Masters */ -public interface Sheet extends ShapeContainer { - SS getSlideShow(); +public interface Sheet< + S extends Shape, + P extends TextParagraph +> extends ShapeContainer { + SlideShow getSlideShow(); /** * @return whether shapes on the master sheet should be shown. By default master graphics is turned off. @@ -33,9 +36,9 @@ public interface Sheet extends ShapeConta */ boolean getFollowMasterGraphics(); - MasterSheet getMasterSheet(); + MasterSheet getMasterSheet(); - Background getBackground(); + Background getBackground(); /** * Convenience method to draw a sheet to a graphics context diff --git a/src/java/org/apache/poi/sl/usermodel/SimpleShape.java b/src/java/org/apache/poi/sl/usermodel/SimpleShape.java index e4e8efe3a..92612cf95 100644 --- a/src/java/org/apache/poi/sl/usermodel/SimpleShape.java +++ b/src/java/org/apache/poi/sl/usermodel/SimpleShape.java @@ -21,7 +21,10 @@ import org.apache.poi.sl.draw.geom.CustomGeometry; import org.apache.poi.sl.draw.geom.IAdjustableShape; -public interface SimpleShape extends Shape, IAdjustableShape, PlaceableShape { +public interface SimpleShape< + S extends Shape, + P extends TextParagraph +> extends Shape, IAdjustableShape, PlaceableShape { FillStyle getFillStyle(); LineDecoration getLineDecoration(); StrokeStyle getStrokeStyle(); diff --git a/src/java/org/apache/poi/sl/usermodel/Slide.java b/src/java/org/apache/poi/sl/usermodel/Slide.java index b992a5e3c..237e0229b 100644 --- a/src/java/org/apache/poi/sl/usermodel/Slide.java +++ b/src/java/org/apache/poi/sl/usermodel/Slide.java @@ -17,9 +17,12 @@ package org.apache.poi.sl.usermodel; -public interface Slide> extends Sheet { - N getNotes(); - void setNotes(N notes); +public interface Slide< + S extends Shape, + P extends TextParagraph +> extends Sheet { + Notes getNotes(); + void setNotes(Notes notes); boolean getFollowMasterBackground(); void setFollowMasterBackground(boolean follow); diff --git a/src/java/org/apache/poi/sl/usermodel/SlideShow.java b/src/java/org/apache/poi/sl/usermodel/SlideShow.java index ac2a7a7d9..2b04327e4 100644 --- a/src/java/org/apache/poi/sl/usermodel/SlideShow.java +++ b/src/java/org/apache/poi/sl/usermodel/SlideShow.java @@ -24,18 +24,21 @@ import java.util.List; import org.apache.poi.sl.usermodel.PictureData.PictureType; -public interface SlideShow { - Slide> createSlide() throws IOException; +public interface SlideShow< + S extends Shape, + P extends TextParagraph +> { + Slide createSlide() throws IOException; - List>> getSlides(); + List> getSlides(); - MasterSheet createMasterSheet() throws IOException; + MasterSheet createMasterSheet() throws IOException; /** * Returns all slide masters. * This doesn't include notes master and other arbitrary masters. */ - List> getSlideMasters(); + List> getSlideMasters(); Resources getResources(); diff --git a/src/java/org/apache/poi/sl/usermodel/TableCell.java b/src/java/org/apache/poi/sl/usermodel/TableCell.java new file mode 100644 index 000000000..30cb2da37 --- /dev/null +++ b/src/java/org/apache/poi/sl/usermodel/TableCell.java @@ -0,0 +1,25 @@ +/* ==================================================================== + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +==================================================================== */ + +package org.apache.poi.sl.usermodel; + +public interface TableCell< + S extends Shape, + P extends TextParagraph +> extends TextShape { + +} diff --git a/src/java/org/apache/poi/sl/usermodel/TableShape.java b/src/java/org/apache/poi/sl/usermodel/TableShape.java index 4fda40f2d..2ac2881d6 100644 --- a/src/java/org/apache/poi/sl/usermodel/TableShape.java +++ b/src/java/org/apache/poi/sl/usermodel/TableShape.java @@ -17,6 +17,9 @@ package org.apache.poi.sl.usermodel; -public interface TableShape extends Shape, PlaceableShape { +public interface TableShape< + S extends Shape, + P extends TextParagraph +> extends Shape, PlaceableShape { // to be defined ... } diff --git a/src/java/org/apache/poi/sl/usermodel/TextBox.java b/src/java/org/apache/poi/sl/usermodel/TextBox.java index 3fa3bbe20..94fd4de40 100644 --- a/src/java/org/apache/poi/sl/usermodel/TextBox.java +++ b/src/java/org/apache/poi/sl/usermodel/TextBox.java @@ -17,5 +17,8 @@ package org.apache.poi.sl.usermodel; -public interface TextBox> extends AutoShape { +public interface TextBox< + S extends Shape, + P extends TextParagraph +> extends AutoShape { } diff --git a/src/java/org/apache/poi/sl/usermodel/TextParagraph.java b/src/java/org/apache/poi/sl/usermodel/TextParagraph.java index 97296bb0b..00a016058 100644 --- a/src/java/org/apache/poi/sl/usermodel/TextParagraph.java +++ b/src/java/org/apache/poi/sl/usermodel/TextParagraph.java @@ -21,7 +21,11 @@ import java.awt.Color; -public interface TextParagraph extends Iterable { +public interface TextParagraph< + S extends Shape, + P extends TextParagraph, + T extends TextRun +> extends Iterable { /** * Specifies a list of text alignment types @@ -334,5 +338,5 @@ public interface TextParagraph extends Iterable { Double getDefaultTabSize(); - TextShape> getParentShape(); + TextShape getParentShape(); } diff --git a/src/java/org/apache/poi/sl/usermodel/TextShape.java b/src/java/org/apache/poi/sl/usermodel/TextShape.java index 927fdf1f9..5f55a1dc4 100644 --- a/src/java/org/apache/poi/sl/usermodel/TextShape.java +++ b/src/java/org/apache/poi/sl/usermodel/TextShape.java @@ -17,11 +17,12 @@ package org.apache.poi.sl.usermodel; -import org.apache.poi.ss.usermodel.HorizontalAlignment; +import java.util.List; - - -public interface TextShape> extends SimpleShape, Iterable { +public interface TextShape< + S extends Shape, + P extends TextParagraph +> extends SimpleShape, Iterable

{ /** * Vertical Text Types */ @@ -87,40 +88,45 @@ public interface TextShape> extends S *

*/ SHAPE - } + } + /** + * @return the TextParagraphs for this text box + */ + List> getTextParagraphs(); + /** * @return text shape margin */ Insets2D getInsets(); - + /** * Compute the cumulative height occupied by the text */ double getTextHeight(); - + /** * Returns the type of vertical alignment for the text. * * @return the type of vertical alignment */ VerticalAlignment getVerticalAlignment(); - + /** * Returns if the text is centered. * If true and if the individual paragraph settings allow it, * the whole text block will be displayed centered, i.e. its left and right * margin will be maximized while still keeping the alignment of the paragraphs * - * @return true, if the text anchor is horizontal centered + * @return true, if the text anchor is horizontal centered */ boolean isHorizontalCentered(); - + /** * @return whether to wrap words within the bounding rectangle */ boolean getWordWrap(); - + /** * @return vertical orientation of the text */ diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java index 2bbec18ab..2cf4bda98 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java @@ -68,7 +68,8 @@ import org.openxmlformats.schemas.presentationml.x2006.main.PresentationDocument * top level object for creating new slides/etc. */ @Beta -public class XMLSlideShow extends POIXMLDocument implements SlideShow { +public class XMLSlideShow extends POIXMLDocument +implements SlideShow { private static POILogger _logger = POILogFactory.getLogger(XMLSlideShow.class); private CTPresentation _presentation; @@ -512,7 +513,8 @@ public class XMLSlideShow extends POIXMLDocument implements SlideShow { return null; } - public MasterSheet createMasterSheet() throws IOException { + @Override + public MasterSheet createMasterSheet() throws IOException { // TODO: implement! throw new UnsupportedOperationException(); } diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFAutoShape.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFAutoShape.java index a87d91bd5..b9e400448 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFAutoShape.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFAutoShape.java @@ -36,7 +36,8 @@ import org.openxmlformats.schemas.presentationml.x2006.main.CTShapeNonVisual; * @author Yegor Kozlov */ @Beta -public class XSLFAutoShape extends XSLFTextShape implements AutoShape { +public class XSLFAutoShape extends XSLFTextShape + implements AutoShape { /*package*/ XSLFAutoShape(CTShape shape, XSLFSheet sheet) { super(shape, sheet); diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFBackground.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFBackground.java index e40494da2..6dbdf2d4f 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFBackground.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFBackground.java @@ -35,7 +35,8 @@ import org.openxmlformats.schemas.presentationml.x2006.main.CTBackground; * * @author Yegor Kozlov */ -public class XSLFBackground extends XSLFSimpleShape implements Background { +public class XSLFBackground extends XSLFSimpleShape + implements Background { /* package */XSLFBackground(CTBackground shape, XSLFSheet sheet) { super(shape, sheet); diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFConnectorShape.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFConnectorShape.java index e5362c4d2..ef8a2adf0 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFConnectorShape.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFConnectorShape.java @@ -34,7 +34,8 @@ import org.openxmlformats.schemas.presentationml.x2006.main.CTConnectorNonVisual * @author Yegor Kozlov */ @Beta -public class XSLFConnectorShape extends XSLFSimpleShape implements ConnectorShape { +public class XSLFConnectorShape extends XSLFSimpleShape + implements ConnectorShape { /*package*/ XSLFConnectorShape(CTConnector shape, XSLFSheet sheet) { super(shape, sheet); diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFFreeformShape.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFFreeformShape.java index 8acc12b44..1f2352393 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFFreeformShape.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFFreeformShape.java @@ -49,7 +49,8 @@ import org.openxmlformats.schemas.presentationml.x2006.main.CTShapeNonVisual; * @author Yegor Kozlov */ @Beta -public class XSLFFreeformShape extends XSLFAutoShape implements FreeformShape { +public class XSLFFreeformShape extends XSLFAutoShape + implements FreeformShape { /*package*/ XSLFFreeformShape(CTShape shape, XSLFSheet sheet) { super(shape, sheet); diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGroupShape.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGroupShape.java index 9115f0edd..619950117 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGroupShape.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGroupShape.java @@ -28,6 +28,7 @@ import org.apache.poi.openxml4j.opc.PackagePart; import org.apache.poi.openxml4j.opc.PackageRelationship; import org.apache.poi.openxml4j.opc.TargetMode; import org.apache.poi.sl.usermodel.GroupShape; +import org.apache.poi.sl.usermodel.PictureData; import org.apache.poi.util.Beta; import org.apache.poi.util.POILogFactory; import org.apache.poi.util.POILogger; @@ -49,7 +50,8 @@ import org.openxmlformats.schemas.presentationml.x2006.main.CTShape; * @author Yegor Kozlov */ @Beta -public class XSLFGroupShape extends XSLFShape implements XSLFShapeContainer, GroupShape { +public class XSLFGroupShape extends XSLFShape +implements XSLFShapeContainer, GroupShape { private static POILogger _logger = POILogFactory.getLogger(XSLFGroupShape.class); private final List _shapes; @@ -237,8 +239,12 @@ public class XSLFGroupShape extends XSLFShape implements XSLFShapeContainer, Gro return sh; } - public XSLFPictureShape createPicture(XSLFPictureData pictureData){ - PackagePart pic = pictureData.getPackagePart(); + 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 = getSheet().getPackagePart().addRelationship( pic.getPartName(), TargetMode.INTERNAL, XSLFRelation.IMAGES.getRelation()); @@ -257,6 +263,24 @@ public class XSLFGroupShape extends XSLFShape implements XSLFShapeContainer, Gro 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(); + _shapes.add(sh); + sh.setParent(this); + for (int r=0; r { +public final class XSLFNotes extends XSLFSheet +implements Notes { private CTNotesSlide _notes; /** @@ -83,6 +84,7 @@ public final class XSLFNotes extends XSLFSheet implements Notes { + public class XSLFNotesMaster extends XSLFSheet + implements MasterSheet { private CTNotesMaster _slide; private XSLFTheme _theme; @@ -94,7 +95,7 @@ import org.openxmlformats.schemas.presentationml.x2006.main.NotesMasterDocument; } @Override - public MasterSheet getMasterSheet() { + public MasterSheet getMasterSheet() { return null; } diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java index 73ec45b9a..0dc14844e 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java @@ -51,7 +51,8 @@ import org.openxmlformats.schemas.presentationml.x2006.main.CTPictureNonVisual; * Represents a picture shape */ @Beta -public class XSLFPictureShape extends XSLFSimpleShape implements PictureShape { +public class XSLFPictureShape extends XSLFSimpleShape + implements PictureShape { private XSLFPictureData _data; /*package*/ XSLFPictureShape(CTPicture shape, XSLFSheet sheet) { diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShape.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShape.java index d0c512382..37dbc33a2 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShape.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShape.java @@ -65,7 +65,7 @@ import org.openxmlformats.schemas.presentationml.x2006.main.STPlaceholderType; * @author Yegor Kozlov */ @Beta -public abstract class XSLFShape implements Shape { +public abstract class XSLFShape implements Shape { private final XmlObject _shape; private final XSLFSheet _sheet; private XSLFShapeContainer _parent; @@ -130,8 +130,8 @@ public abstract class XSLFShape implements Shape { } if (this instanceof PlaceableShape) { - PlaceableShape ps = (PlaceableShape)this; - ps.setAnchor(((PlaceableShape)sh).getAnchor()); + PlaceableShape ps = (PlaceableShape)this; + ps.setAnchor(((PlaceableShape)sh).getAnchor()); } diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShapeContainer.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShapeContainer.java index f7078029b..ddf832d3d 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShapeContainer.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShapeContainer.java @@ -19,43 +19,32 @@ 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 { +public interface XSLFShapeContainer + extends ShapeContainer { - /** - * 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). diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSheet.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSheet.java index 62ef3b7ec..627f97310 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSheet.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSheet.java @@ -37,6 +37,7 @@ import org.apache.poi.openxml4j.opc.PackageRelationship; 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; @@ -53,7 +54,8 @@ import org.openxmlformats.schemas.presentationml.x2006.main.CTPlaceholder; import org.openxmlformats.schemas.presentationml.x2006.main.CTShape; @Beta -public abstract class XSLFSheet extends POIXMLDocumentPart implements XSLFShapeContainer, Sheet { +public abstract class XSLFSheet extends POIXMLDocumentPart +implements XSLFShapeContainer, Sheet { private XSLFCommonSlideData _commonSlideData; private XSLFDrawing _drawing; private List _shapes; @@ -72,9 +74,9 @@ public abstract class XSLFSheet extends POIXMLDocumentPart implements XSLFShapeC } /** - * * @return the XMLSlideShow this sheet belongs to */ + @Override public XMLSlideShow getSlideShow() { POIXMLDocumentPart p = getParent(); while(p != null) { @@ -158,6 +160,7 @@ public abstract class XSLFSheet extends POIXMLDocumentPart implements XSLFShapeC // shape factory methods + @Override public XSLFAutoShape createAutoShape(){ XSLFAutoShape sh = getDrawing().createAutoShape(); getShapes().add(sh); @@ -165,6 +168,7 @@ public abstract class XSLFSheet extends POIXMLDocumentPart implements XSLFShapeC return sh; } + @Override public XSLFFreeformShape createFreeform(){ XSLFFreeformShape sh = getDrawing().createFreeform(); getShapes().add(sh); @@ -172,6 +176,7 @@ public abstract class XSLFSheet extends POIXMLDocumentPart implements XSLFShapeC return sh; } + @Override public XSLFTextBox createTextBox(){ XSLFTextBox sh = getDrawing().createTextBox(); getShapes().add(sh); @@ -179,6 +184,7 @@ public abstract class XSLFSheet extends POIXMLDocumentPart implements XSLFShapeC return sh; } + @Override public XSLFConnectorShape createConnector(){ XSLFConnectorShape sh = getDrawing().createConnector(); getShapes().add(sh); @@ -186,6 +192,7 @@ public abstract class XSLFSheet extends POIXMLDocumentPart implements XSLFShapeC return sh; } + @Override public XSLFGroupShape createGroup(){ XSLFGroupShape sh = getDrawing().createGroup(); getShapes().add(sh); @@ -193,8 +200,13 @@ public abstract class XSLFSheet extends POIXMLDocumentPart implements XSLFShapeC 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()); @@ -214,6 +226,24 @@ public abstract class XSLFSheet extends POIXMLDocumentPart implements XSLFShapeC 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 { private static CTOuterShadowEffect NO_SHADOW = CTOuterShadowEffect.Factory.newInstance(); /* package */XSLFSimpleShape(XmlObject shape, XSLFSheet sheet) { diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlide.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlide.java index 83453573c..cb66f697f 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlide.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlide.java @@ -24,6 +24,7 @@ import org.apache.poi.openxml4j.opc.PackagePart; 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; @@ -41,7 +42,8 @@ import org.openxmlformats.schemas.presentationml.x2006.main.CTSlide; import org.openxmlformats.schemas.presentationml.x2006.main.SldDocument; @Beta -public final class XSLFSlide extends XSLFSheet implements Slide { +public final class XSLFSlide extends XSLFSheet +implements Slide { private final CTSlide _slide; private XSLFSlideLayout _layout; private XSLFComments _comments; @@ -254,11 +256,12 @@ public final class XSLFSlide extends XSLFSheet implements Slide notes) { + assert(notes instanceof XSLFNotes); // TODO Auto-generated method stub - } - + @Override public int getSlideNumber() { int idx = getSlideShow().getSlides().indexOf(this); diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlideLayout.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlideLayout.java index b408d529e..48c5b2035 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlideLayout.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlideLayout.java @@ -31,7 +31,8 @@ import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideLayout; import org.openxmlformats.schemas.presentationml.x2006.main.SldLayoutDocument; @Beta -public class XSLFSlideLayout extends XSLFSheet implements MasterSheet { +public class XSLFSlideLayout extends XSLFSheet +implements MasterSheet { private CTSlideLayout _layout; private XSLFSlideMaster _master; diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlideMaster.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlideMaster.java index c1ed1bf0d..776cbf677 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlideMaster.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlideMaster.java @@ -54,7 +54,8 @@ import org.openxmlformats.schemas.presentationml.x2006.main.SldMasterDocument; * @author Yegor Kozlov */ @Beta - public class XSLFSlideMaster extends XSLFSheet implements MasterSheet { + public class XSLFSlideMaster extends XSLFSheet + implements MasterSheet { private CTSlideMaster _slide; private Map _layouts; private XSLFTheme _theme; @@ -83,7 +84,7 @@ import org.openxmlformats.schemas.presentationml.x2006.main.SldMasterDocument; } @Override - public MasterSheet getMasterSheet() { + public XSLFSlideMaster getMasterSheet() { return null; } diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTable.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTable.java index 9f2bb4903..3f1563166 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTable.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTable.java @@ -46,7 +46,8 @@ import org.openxmlformats.schemas.presentationml.x2006.main.CTGraphicalObjectFra * * @author Yegor Kozlov */ -public class XSLFTable extends XSLFGraphicFrame implements Iterable, TableShape { +public class XSLFTable extends XSLFGraphicFrame implements Iterable, + TableShape { static String TABLE_URI = "http://schemas.openxmlformats.org/drawingml/2006/table"; private CTTable _table; diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTableCell.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTableCell.java index 938115278..29f373929 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTableCell.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTableCell.java @@ -21,14 +21,29 @@ package org.apache.poi.xslf.usermodel; import java.awt.Color; +import org.apache.poi.sl.usermodel.TableCell; import org.apache.poi.sl.usermodel.VerticalAlignment; import org.apache.poi.util.Units; -import org.openxmlformats.schemas.drawingml.x2006.main.*; +import org.openxmlformats.schemas.drawingml.x2006.main.CTLineEndProperties; +import org.openxmlformats.schemas.drawingml.x2006.main.CTLineProperties; +import org.openxmlformats.schemas.drawingml.x2006.main.CTSRgbColor; +import org.openxmlformats.schemas.drawingml.x2006.main.CTSolidColorFillProperties; +import org.openxmlformats.schemas.drawingml.x2006.main.CTTableCell; +import org.openxmlformats.schemas.drawingml.x2006.main.CTTableCellProperties; +import org.openxmlformats.schemas.drawingml.x2006.main.CTTextBody; +import org.openxmlformats.schemas.drawingml.x2006.main.STCompoundLine; +import org.openxmlformats.schemas.drawingml.x2006.main.STLineCap; +import org.openxmlformats.schemas.drawingml.x2006.main.STLineEndLength; +import org.openxmlformats.schemas.drawingml.x2006.main.STLineEndType; +import org.openxmlformats.schemas.drawingml.x2006.main.STLineEndWidth; +import org.openxmlformats.schemas.drawingml.x2006.main.STPenAlignment; +import org.openxmlformats.schemas.drawingml.x2006.main.STPresetLineDashVal; +import org.openxmlformats.schemas.drawingml.x2006.main.STTextAnchoringType; /** * Represents a cell of a table in a .pptx presentation */ -public class XSLFTableCell extends XSLFTextShape { +public class XSLFTableCell extends XSLFTextShape implements TableCell { static double defaultBorderWidth = 1.0; private CTTableCellProperties _tcPr = null; diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextBox.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextBox.java index e27bedbb5..65635c4d3 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextBox.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextBox.java @@ -19,6 +19,7 @@ package org.apache.poi.xslf.usermodel; +import org.apache.poi.sl.usermodel.TextBox; import org.apache.poi.util.Beta; import org.openxmlformats.schemas.drawingml.x2006.main.*; import org.openxmlformats.schemas.presentationml.x2006.main.CTShape; @@ -29,7 +30,8 @@ import org.openxmlformats.schemas.presentationml.x2006.main.CTShapeNonVisual; * @author Yegor Kozlov */ @Beta -public class XSLFTextBox extends XSLFAutoShape { +public class XSLFTextBox extends XSLFAutoShape + implements TextBox { /*package*/ XSLFTextBox(CTShape shape, XSLFSheet sheet){ super(shape, sheet); diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextParagraph.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextParagraph.java index 6cffd9470..68d7438d4 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextParagraph.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextParagraph.java @@ -44,7 +44,7 @@ import org.openxmlformats.schemas.presentationml.x2006.main.STPlaceholderType; * @since POI-3.8 */ @Beta -public class XSLFTextParagraph implements TextParagraph { +public class XSLFTextParagraph implements TextParagraph { private final CTTextParagraph _p; private final List _runs; private final XSLFTextShape _shape; diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextShape.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextShape.java index ae5470c79..034b50cdd 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextShape.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextShape.java @@ -48,7 +48,8 @@ import org.openxmlformats.schemas.presentationml.x2006.main.CTPlaceholder; * Represents a shape that can hold text. */ @Beta -public abstract class XSLFTextShape extends XSLFSimpleShape implements TextShape { +public abstract class XSLFTextShape extends XSLFSimpleShape + implements TextShape { private final List _paragraphs; @SuppressWarnings("deprecation") @@ -96,10 +97,7 @@ public abstract class XSLFTextShape extends XSLFSimpleShape implements TextShape addNewTextParagraph().addNewTextRun().setText(text); } - /** - * - * @return text paragraphs in this shape - */ + @Override public List getTextParagraphs() { return _paragraphs; } @@ -459,7 +457,7 @@ public abstract class XSLFTextShape extends XSLFSimpleShape implements TextShape @Override public double getTextHeight(){ DrawFactory drawFact = DrawFactory.getInstance(null); - DrawTextShape dts = drawFact.getDrawable(this); + DrawTextShape dts = drawFact.getDrawable(this); return dts.getTextHeight(); } diff --git a/src/ooxml/java/org/apache/poi/xslf/util/PPTX2PNG.java b/src/ooxml/java/org/apache/poi/xslf/util/PPTX2PNG.java index 43fefedf5..cc59f04fd 100644 --- a/src/ooxml/java/org/apache/poi/xslf/util/PPTX2PNG.java +++ b/src/ooxml/java/org/apache/poi/xslf/util/PPTX2PNG.java @@ -116,8 +116,8 @@ public class PPTX2PNG { if (!quite) { System.out.println("Processing " + file); } - SlideShow ss = SlideShowFactory.create(file, null, true); - List> slides = ss.getSlides(); + SlideShow ss = SlideShowFactory.create(file, null, true); + List> slides = ss.getSlides(); if (slidenum < -1 || slidenum == 0 || slidenum > slides.size()) { @@ -130,7 +130,7 @@ public class PPTX2PNG { int height = (int) (pgsize.height * scale); int slideNo=1; - for(Slide slide : slides) { + for(Slide slide : slides) { if (slidenum == -1 || slideNo == slidenum) { String title = slide.getTitle(); if (!quite) { diff --git a/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTextParagraph.java b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTextParagraph.java index 1ad525011..a2ddfadbb 100644 --- a/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTextParagraph.java +++ b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTextParagraph.java @@ -44,7 +44,7 @@ import org.junit.Test; public class TestXSLFTextParagraph { // private static POILogger _logger = POILogFactory.getLogger(XSLFTextParagraph.class); - static class DrawTextParagraphProxy extends DrawTextParagraph { + static class DrawTextParagraphProxy extends DrawTextParagraph { DrawTextParagraphProxy(XSLFTextParagraph p) { super(p); } diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/ActiveXShape.java b/src/scratchpad/src/org/apache/poi/hslf/model/ActiveXShape.java index 25bb1aa13..5bcf98ab8 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/model/ActiveXShape.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/ActiveXShape.java @@ -20,10 +20,10 @@ package org.apache.poi.hslf.model; 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; @@ -34,7 +34,11 @@ import org.apache.poi.hslf.record.ExObjList; 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; @@ -66,7 +70,7 @@ public final class ActiveXShape extends HSLFPictureShape { * this picture in the Slide * @param parent the parent shape of this picture */ - protected ActiveXShape(EscherContainerRecord escherRecord, ShapeContainer parent){ + protected ActiveXShape(EscherContainerRecord escherRecord, ShapeContainer parent){ super(escherRecord, parent); } @@ -172,7 +176,7 @@ public final class ActiveXShape extends HSLFPictureShape { 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); } } diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/MovieShape.java b/src/scratchpad/src/org/apache/poi/hslf/model/MovieShape.java index 0e35a0e29..d4da2a310 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/model/MovieShape.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/MovieShape.java @@ -55,7 +55,7 @@ public final class MovieShape extends HSLFPictureShape { * @param pictureData the picture data * @param parent the parent shape */ - public MovieShape(int movieIdx, HSLFPictureData pictureData, ShapeContainer parent) { + public MovieShape(int movieIdx, HSLFPictureData pictureData, ShapeContainer parent) { super(pictureData, parent); setMovieIndex(movieIdx); } @@ -67,7 +67,7 @@ public final class MovieShape extends HSLFPictureShape { * this picture in the Slide * @param parent the parent shape of this picture */ - public MovieShape(EscherContainerRecord escherRecord, ShapeContainer parent){ + public MovieShape(EscherContainerRecord escherRecord, ShapeContainer parent){ super(escherRecord, parent); } diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/OLEShape.java b/src/scratchpad/src/org/apache/poi/hslf/model/OLEShape.java index 6f8792df2..c61c5ce5a 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/model/OLEShape.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/OLEShape.java @@ -51,7 +51,7 @@ public final class OLEShape extends HSLFPictureShape { * @param data the picture data * @param parent the parent shape */ - public OLEShape(HSLFPictureData data, ShapeContainer parent) { + public OLEShape(HSLFPictureData data, ShapeContainer parent) { super(data, parent); } @@ -62,7 +62,7 @@ public final class OLEShape extends HSLFPictureShape { * this picture in the Slide * @param parent the parent shape of this picture */ - public OLEShape(EscherContainerRecord escherRecord, ShapeContainer parent){ + public OLEShape(EscherContainerRecord escherRecord, ShapeContainer parent){ super(escherRecord, parent); } diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/Placeholder.java b/src/scratchpad/src/org/apache/poi/hslf/model/Placeholder.java index 78e7a4735..1e632b8dc 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/model/Placeholder.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/Placeholder.java @@ -21,6 +21,7 @@ import org.apache.poi.ddf.*; 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; @@ -33,11 +34,11 @@ import java.io.ByteArrayOutputStream; */ public final class Placeholder extends HSLFTextBox { - protected Placeholder(EscherContainerRecord escherRecord, ShapeContainer parent){ + protected Placeholder(EscherContainerRecord escherRecord, ShapeContainer parent){ super(escherRecord, parent); } - public Placeholder(ShapeContainer parent){ + public Placeholder(ShapeContainer parent){ super(parent); } @@ -59,7 +60,7 @@ public final class Placeholder extends HSLFTextBox { 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); diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/Polygon.java b/src/scratchpad/src/org/apache/poi/hslf/model/Polygon.java index 2a2697346..9c2cb24ed 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/model/Polygon.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/Polygon.java @@ -38,7 +38,7 @@ public final class Polygon extends HSLFAutoShape { * @param escherRecord EscherSpContainer container which holds information about this shape * @param parent the parent of the shape */ - protected Polygon(EscherContainerRecord escherRecord, ShapeContainer parent){ + protected Polygon(EscherContainerRecord escherRecord, ShapeContainer parent){ super(escherRecord, parent); } @@ -49,7 +49,7 @@ public final class Polygon extends HSLFAutoShape { * @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 parent){ + public Polygon(ShapeContainer parent){ super((EscherContainerRecord)null, parent); _escherContainer = createSpContainer(ShapeType.NOT_PRIMITIVE, parent instanceof HSLFGroupShape); } @@ -75,7 +75,7 @@ public final class Polygon extends HSLFAutoShape { 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))); diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFAutoShape.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFAutoShape.java index ceb655250..21c07010c 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFAutoShape.java +++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFAutoShape.java @@ -31,13 +31,13 @@ import org.apache.poi.ss.usermodel.ShapeTypes; * * @author Yegor Kozlov */ -public class HSLFAutoShape extends HSLFTextShape implements AutoShape { +public class HSLFAutoShape extends HSLFTextShape implements AutoShape { - protected HSLFAutoShape(EscherContainerRecord escherRecord, ShapeContainer parent){ + protected HSLFAutoShape(EscherContainerRecord escherRecord, ShapeContainer parent){ super(escherRecord, parent); } - public HSLFAutoShape(ShapeType type, ShapeContainer parent){ + public HSLFAutoShape(ShapeType type, ShapeContainer parent){ super(null, parent); _escherContainer = createSpContainer(type, parent instanceof HSLFGroupShape); } diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFBackground.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFBackground.java index 4b9846fd6..8f477f956 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFBackground.java +++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFBackground.java @@ -26,9 +26,9 @@ import org.apache.poi.sl.usermodel.ShapeContainer; * * @author Yegor Kozlov */ -public final class HSLFBackground extends HSLFShape implements Background { +public final class HSLFBackground extends HSLFShape implements Background { - protected HSLFBackground(EscherContainerRecord escherRecord, ShapeContainer parent) { + protected HSLFBackground(EscherContainerRecord escherRecord, ShapeContainer parent) { super(escherRecord, parent); } diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFConnectorShape.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFConnectorShape.java new file mode 100644 index 000000000..3c26c5a22 --- /dev/null +++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFConnectorShape.java @@ -0,0 +1,65 @@ +/* + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.apache.poi.hslf.usermodel; + +import org.apache.poi.ddf.EscherContainerRecord; +import org.apache.poi.sl.usermodel.ConnectorShape; +import org.apache.poi.sl.usermodel.ShapeContainer; +import org.apache.poi.util.Beta; + +/** + * Specifies a connection shape. + * + * This is currently only a dummy implementation. + */ +@Beta +public class HSLFConnectorShape extends HSLFSimpleShape +implements ConnectorShape { + + /** + * Create a ConnectorShape object and initialize it from the supplied Record container. + * + * @param escherRecord EscherSpContainer container which holds information about this shape + * @param parent the parent of the shape + */ + protected HSLFConnectorShape(EscherContainerRecord escherRecord, ShapeContainer parent){ + super(escherRecord, parent); + + } + + /** + * Create a new ConnectorShape. This constructor is used when a new shape is created. + * + * @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 HSLFConnectorShape(ShapeContainer parent){ + super(null, parent); + _escherContainer = createSpContainer(parent instanceof HSLFGroupShape); + } + + /** + * Create a new ConnectorShape. This constructor is used when a new shape is created. + * + */ + public HSLFConnectorShape(){ + this(null); + } +} diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFFill.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFFill.java index e0b056714..7940892e7 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFFill.java +++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFFill.java @@ -22,9 +22,9 @@ import java.io.ByteArrayInputStream; 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; @@ -155,7 +155,7 @@ public final class HSLFFill { * @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(); } @@ -163,7 +163,7 @@ public final class HSLFFill { /** */ 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(); @@ -197,7 +197,7 @@ public final class HSLFFill { * @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); } @@ -205,7 +205,7 @@ public final class HSLFFill { * 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; @@ -218,7 +218,7 @@ public final class HSLFFill { * 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); } @@ -233,7 +233,7 @@ public final class HSLFFill { * 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; @@ -245,7 +245,7 @@ public final class HSLFFill { * 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); } @@ -259,7 +259,7 @@ public final class HSLFFill { * PictureData 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; @@ -292,7 +292,7 @@ public final class HSLFFill { * @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()); diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFFreeformShape.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFFreeformShape.java index 7a2cd9bdf..e576cceef 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFFreeformShape.java +++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFFreeformShape.java @@ -26,9 +26,9 @@ import java.util.ArrayList; 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; @@ -47,7 +47,7 @@ import org.apache.poi.util.Units; *

* @author Yegor Kozlov */ -public final class HSLFFreeformShape extends HSLFAutoShape implements FreeformShape { +public final class HSLFFreeformShape extends HSLFAutoShape implements FreeformShape { public static final byte[] SEGMENTINFO_MOVETO = new byte[]{0x00, 0x40}; public static final byte[] SEGMENTINFO_LINETO = new byte[]{0x00, (byte)0xAC}; @@ -64,7 +64,7 @@ public final class HSLFFreeformShape extends HSLFAutoShape implements FreeformSh * @param escherRecord EscherSpContainer container which holds information about this shape * @param parent the parent of the shape */ - protected HSLFFreeformShape(EscherContainerRecord escherRecord, ShapeContainer parent){ + protected HSLFFreeformShape(EscherContainerRecord escherRecord, ShapeContainer parent){ super(escherRecord, parent); } @@ -75,7 +75,7 @@ public final class HSLFFreeformShape extends HSLFAutoShape implements FreeformSh * @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 parent){ + public HSLFFreeformShape(ShapeContainer parent){ super((EscherContainerRecord)null, parent); _escherContainer = createSpContainer(ShapeType.NOT_PRIMITIVE, parent instanceof HSLFGroupShape); } @@ -140,7 +140,7 @@ public final class HSLFFreeformShape extends HSLFAutoShape implements FreeformSh 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); @@ -178,7 +178,7 @@ public final class HSLFFreeformShape extends HSLFAutoShape implements FreeformSh @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)); diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFGroupShape.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFGroupShape.java index 41c08fdaa..0ba1d379b 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFGroupShape.java +++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFGroupShape.java @@ -17,11 +17,22 @@ package org.apache.poi.hslf.usermodel; +import java.awt.Rectangle; import java.awt.geom.Rectangle2D; -import java.util.*; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; -import org.apache.poi.ddf.*; -import org.apache.poi.sl.usermodel.*; +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; @@ -31,7 +42,8 @@ import org.apache.poi.util.Units; * * @author Yegor Kozlov */ -public class HSLFGroupShape extends HSLFShape implements GroupShape { +public class HSLFGroupShape extends HSLFShape +implements HSLFShapeContainer, GroupShape { /** * Create a new ShapeGroup. This constructor is used when a new shape is created. @@ -43,12 +55,22 @@ public class HSLFGroupShape extends HSLFShape implements GroupShape { } /** - * 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 parent){ + this(null, parent); + _escherContainer = createSpContainer(parent instanceof HSLFGroupShape); + } + + /** + * Create a ShapeGroup object and initialize it from the supplied Record container. * * @param escherRecord EscherSpContainer container which holds information about this shape * @param parent the parent of the shape */ - protected HSLFGroupShape(EscherContainerRecord escherRecord, ShapeContainer parent){ + protected HSLFGroupShape(EscherContainerRecord escherRecord, ShapeContainer parent){ super(escherRecord, parent); } @@ -273,4 +295,68 @@ public class HSLFGroupShape extends HSLFShape implements GroupShape { 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; + } } diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFLine.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFLine.java index 10b2bd099..21706db40 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFLine.java +++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFLine.java @@ -17,8 +17,8 @@ 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; @@ -30,12 +30,12 @@ import org.apache.poi.sl.usermodel.ShapeType; * * @author Yegor Kozlov */ -public final class HSLFLine extends HSLFTextShape implements Line { - public HSLFLine(EscherContainerRecord escherRecord, ShapeContainer parent){ +public final class HSLFLine extends HSLFTextShape implements Line { + public HSLFLine(EscherContainerRecord escherRecord, ShapeContainer parent){ super(escherRecord, parent); } - public HSLFLine(ShapeContainer parent){ + public HSLFLine(ShapeContainer parent){ super(null, parent); _escherContainer = createSpContainer(parent instanceof HSLFGroupShape); } @@ -54,7 +54,7 @@ public final class HSLFLine extends HSLFTextShape implements Line { +public abstract class HSLFMasterSheet extends HSLFSheet implements MasterSheet { public HSLFMasterSheet(SheetContainer container, int sheetNo){ super(container, sheetNo); } diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFNotes.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFNotes.java index 34cb8cf2c..50125ea48 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFNotes.java +++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFNotes.java @@ -32,7 +32,7 @@ import org.apache.poi.util.POILogger; * @author Nick Burch */ -public final class HSLFNotes extends HSLFSheet implements Notes { +public final class HSLFNotes extends HSLFSheet implements Notes { protected static final POILogger logger = POILogFactory.getLogger(HSLFNotes.class); private List> _paragraphs = new ArrayList>(); diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFPictureShape.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFPictureShape.java index 10e9555c8..639545c87 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFPictureShape.java +++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFPictureShape.java @@ -26,10 +26,10 @@ import java.util.List; 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; @@ -49,7 +49,7 @@ import org.apache.poi.util.Units; * * @author Yegor Kozlov */ -public class HSLFPictureShape extends HSLFSimpleShape implements PictureShape { +public class HSLFPictureShape extends HSLFSimpleShape implements PictureShape { /** * Create a new Picture @@ -66,7 +66,7 @@ public class HSLFPictureShape extends HSLFSimpleShape implements PictureShape { * @param data the picture data * @param parent the parent shape */ - public HSLFPictureShape(HSLFPictureData data, ShapeContainer parent) { + public HSLFPictureShape(HSLFPictureData data, ShapeContainer parent) { super(null, parent); _escherContainer = createSpContainer(data.getIndex(), parent instanceof HSLFGroupShape); } @@ -78,7 +78,7 @@ public class HSLFPictureShape extends HSLFSimpleShape implements PictureShape { * this picture in the Slide * @param parent the parent shape of this picture */ - protected HSLFPictureShape(EscherContainerRecord escherRecord, ShapeContainer parent){ + protected HSLFPictureShape(EscherContainerRecord escherRecord, ShapeContainer parent){ super(escherRecord, parent); } @@ -90,7 +90,7 @@ public class HSLFPictureShape extends HSLFSimpleShape implements PictureShape { * @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(); } @@ -109,7 +109,7 @@ public class HSLFPictureShape extends HSLFSimpleShape implements PictureShape { 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. @@ -189,7 +189,7 @@ public class HSLFPictureShape extends HSLFSimpleShape implements PictureShape { * @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()); @@ -202,7 +202,7 @@ public class HSLFPictureShape extends HSLFSimpleShape implements PictureShape { * @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); @@ -228,7 +228,7 @@ public class HSLFPictureShape extends HSLFSimpleShape implements PictureShape { 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); @@ -244,7 +244,7 @@ public class HSLFPictureShape extends HSLFSimpleShape implements PictureShape { /** * @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(); diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFShape.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFShape.java index 635402319..2af2678b2 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFShape.java +++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFShape.java @@ -44,7 +44,7 @@ import org.apache.poi.util.*; * * @author Yegor Kozlov */ -public abstract class HSLFShape implements Shape { +public abstract class HSLFShape implements Shape { // For logging protected POILogger logger = POILogFactory.getLogger(this.getClass()); @@ -59,7 +59,7 @@ public abstract class HSLFShape implements Shape { * Parent of this shape. * null for the topmost shapes. */ - protected ShapeContainer _parent; + protected ShapeContainer _parent; /** * The Sheet this shape belongs to @@ -77,7 +77,7 @@ public abstract class HSLFShape implements Shape { * @param escherRecord EscherSpContainer container which holds information about this shape * @param parent the parent of this Shape */ - protected HSLFShape(EscherContainerRecord escherRecord, ShapeContainer parent){ + protected HSLFShape(EscherContainerRecord escherRecord, ShapeContainer parent){ _escherContainer = escherRecord; _parent = parent; } @@ -90,7 +90,7 @@ public abstract class HSLFShape implements Shape { /** * @return the parent of this shape */ - public ShapeContainer getParent(){ + public ShapeContainer getParent(){ return _parent; } @@ -229,7 +229,7 @@ public abstract class HSLFShape implements Shape { * * @return escher property or null if not found. */ - public static T getEscherProperty(EscherOptRecord opt, int propId){ + public static T getEscherProperty(AbstractEscherOptRecord opt, int propId){ if (opt == null) return null; return opt.lookup(propId); } @@ -241,7 +241,7 @@ public abstract class HSLFShape implements Shape { * @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 props = opt.getEscherProperties(); for ( Iterator iterator = props.iterator(); iterator.hasNext(); ) { if (iterator.next().getPropertyNumber() == propId){ @@ -262,7 +262,7 @@ public abstract class HSLFShape implements Shape { * @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); } @@ -272,7 +272,7 @@ public abstract class HSLFShape implements Shape { * @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(); } @@ -283,7 +283,7 @@ public abstract class HSLFShape implements Shape { * @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(); } @@ -327,7 +327,7 @@ public abstract class HSLFShape implements Shape { } 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; @@ -367,7 +367,7 @@ public abstract class HSLFShape implements Shape { } 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(); @@ -444,8 +444,8 @@ public abstract class HSLFShape implements Shape { 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); } diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFShapeContainer.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFShapeContainer.java new file mode 100644 index 000000000..c09e2d6dd --- /dev/null +++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFShapeContainer.java @@ -0,0 +1,49 @@ +/* + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.apache.poi.hslf.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 HSLFShapeContainer extends ShapeContainer { + + @Override + HSLFAutoShape createAutoShape(); + + @Override + HSLFFreeformShape createFreeform(); + + @Override + HSLFTextBox createTextBox(); + + @Override + HSLFConnectorShape createConnector(); + + @Override + HSLFGroupShape createGroup(); + + @Override + HSLFPictureShape createPicture(PictureData pictureData); + + +} diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFShapeFactory.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFShapeFactory.java index 08db124d4..f2aac4da2 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFShapeFactory.java +++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFShapeFactory.java @@ -40,38 +40,39 @@ public final class HSLFShapeFactory { /** * Create a new shape from the data provided. */ - public static HSLFShape createShape(EscherContainerRecord spContainer, ShapeContainer parent){ + public static HSLFShape createShape(EscherContainerRecord spContainer, ShapeContainer parent){ if (spContainer.getRecordId() == EscherContainerRecord.SPGR_CONTAINER){ return createShapeGroup(spContainer, parent); } return createSimpleShape(spContainer, parent); } - public static HSLFGroupShape createShapeGroup(EscherContainerRecord spContainer, ShapeContainer parent){ - HSLFGroupShape group = null; - EscherRecord opt = HSLFShape.getEscherChild((EscherContainerRecord)spContainer.getChild(0), (short)0xF122); - if(opt != null){ - try { - EscherPropertyFactory f = new EscherPropertyFactory(); - List 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); - } - } catch (Exception e){ - logger.log(POILogger.WARN, e.getMessage()); - group = new HSLFGroupShape(spContainer, parent); - } - } else { - group = new HSLFGroupShape(spContainer, parent); - } + public static HSLFGroupShape createShapeGroup(EscherContainerRecord spContainer, ShapeContainer 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 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; + } + } + } + + HSLFGroupShape group = (isTable) + ? new HSLFTable(spContainer, parent) + : new HSLFGroupShape(spContainer, parent); + return group; } - public static HSLFShape createSimpleShape(EscherContainerRecord spContainer, ShapeContainer parent){ + public static HSLFShape createSimpleShape(EscherContainerRecord spContainer, ShapeContainer parent){ HSLFShape shape = null; EscherSpRecord spRecord = spContainer.getChildById(EscherSpRecord.RECORD_ID); @@ -106,7 +107,7 @@ public final class HSLFShapeFactory { 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); diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSheet.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSheet.java index d0c594fd8..419ded3a1 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSheet.java +++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSheet.java @@ -18,15 +18,28 @@ package org.apache.poi.hslf.usermodel; import java.awt.Graphics2D; -import java.util.*; +import java.awt.Rectangle; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; -import org.apache.poi.ddf.*; -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.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 @@ -36,9 +49,7 @@ import org.apache.poi.util.POILogger; * @author Yegor Kozlov */ -public abstract class HSLFSheet implements Sheet { - private static POILogger logger = POILogFactory.getLogger(HSLFSheet.class); - +public abstract class HSLFSheet implements HSLFShapeContainer, Sheet { /** * The SlideShow we belong to */ @@ -387,4 +398,68 @@ public abstract class HSLFSheet implements Sheet { } + @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; + } } diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSimpleShape.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSimpleShape.java index c6feb514e..aeb36beb5 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSimpleShape.java +++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSimpleShape.java @@ -39,7 +39,7 @@ import org.apache.poi.util.Units; * * @author Yegor Kozlov */ -public abstract class HSLFSimpleShape extends HSLFShape implements SimpleShape { +public abstract class HSLFSimpleShape extends HSLFShape implements SimpleShape { public final static double DEFAULT_LINE_WIDTH = 0.75; @@ -55,7 +55,7 @@ public abstract class HSLFSimpleShape extends HSLFShape implements SimpleShape { * @param escherRecord EscherSpContainer container which holds information about this shape * @param parent the parent of the shape */ - protected HSLFSimpleShape(EscherContainerRecord escherRecord, ShapeContainer parent){ + protected HSLFSimpleShape(EscherContainerRecord escherRecord, ShapeContainer parent){ super(escherRecord, parent); } @@ -76,7 +76,7 @@ public abstract class HSLFSimpleShape extends HSLFShape implements SimpleShape { sp.setFlags(flags); _escherContainer.addChildRecord(sp); - EscherOptRecord opt = new EscherOptRecord(); + AbstractEscherOptRecord opt = new EscherOptRecord(); opt.setRecordId(EscherOptRecord.RECORD_ID); _escherContainer.addChildRecord(opt); @@ -102,7 +102,7 @@ public abstract class HSLFSimpleShape extends HSLFShape implements SimpleShape { * 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; @@ -113,7 +113,7 @@ public abstract class HSLFSimpleShape extends HSLFShape implements SimpleShape { * @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)); } @@ -123,7 +123,7 @@ public abstract class HSLFSimpleShape extends HSLFShape implements SimpleShape { * @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 { @@ -137,7 +137,7 @@ public abstract class HSLFSimpleShape extends HSLFShape implements SimpleShape { * @return color of the line. If color is not set returns java.awt.Color.black */ 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; @@ -152,7 +152,7 @@ public abstract class HSLFSimpleShape extends HSLFShape implements SimpleShape { * @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()); } @@ -163,7 +163,7 @@ public abstract class HSLFSimpleShape extends HSLFShape implements SimpleShape { * @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); } @@ -173,7 +173,7 @@ public abstract class HSLFSimpleShape extends HSLFShape implements SimpleShape { * @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()); } @@ -184,7 +184,7 @@ public abstract class HSLFSimpleShape extends HSLFShape implements SimpleShape { * @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); } @@ -389,7 +389,7 @@ public abstract class HSLFSimpleShape extends HSLFShape implements SimpleShape { 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); @@ -398,7 +398,7 @@ public abstract class HSLFSimpleShape extends HSLFShape implements SimpleShape { } 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); @@ -415,12 +415,12 @@ public abstract class HSLFSimpleShape extends HSLFShape implements SimpleShape { } 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 getShadowParent() { return HSLFSimpleShape.this; } diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlide.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlide.java index bbffdc5e1..fad85f46a 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlide.java +++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlide.java @@ -21,12 +21,28 @@ import java.awt.Graphics2D; 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; @@ -39,7 +55,7 @@ import org.apache.poi.sl.usermodel.Slide; * @author Yegor Kozlov */ -public final class HSLFSlide extends HSLFSheet implements Slide { +public final class HSLFSlide extends HSLFSheet implements Slide { private int _slideNo; private SlideAtomsSet _atomSet; private final List> _paragraphs = new ArrayList>(); @@ -110,8 +126,11 @@ public final class HSLFSlide extends HSLFSheet implements Slide 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(); diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShow.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShow.java index 4af64ecb4..fd31be436 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShow.java +++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShow.java @@ -48,7 +48,6 @@ import org.apache.poi.poifs.filesystem.POIFSFileSystem; 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; @@ -63,7 +62,7 @@ import org.apache.poi.util.Units; * @author Nick Burch * @author Yegor kozlov */ -public final class HSLFSlideShow implements SlideShow { +public final class HSLFSlideShow implements SlideShow { // What we're based on private HSLFSlideShowImpl _hslfSlideShow; @@ -671,6 +670,7 @@ public final class HSLFSlideShow implements SlideShow { * * @return the created Slide */ + @Override public HSLFSlide createSlide() { SlideListWithText slist = null; @@ -1131,8 +1131,7 @@ public final class HSLFSlideShow implements SlideShow { return psrId; } - public MasterSheet createMasterSheet() - throws IOException { + public MasterSheet createMasterSheet() throws IOException { // TODO Auto-generated method stub return null; } diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTable.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTable.java index 9e7ff158e..2f785c433 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTable.java +++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTable.java @@ -24,6 +24,7 @@ import java.util.Comparator; 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; @@ -31,6 +32,7 @@ import org.apache.poi.ddf.EscherProperties; 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; @@ -41,7 +43,8 @@ import org.apache.poi.util.Units; * * @author Yegor Kozlov */ -public final class HSLFTable extends HSLFGroupShape implements TableShape { +public final class HSLFTable extends HSLFGroupShape +implements HSLFShapeContainer, TableShape { protected static final int BORDER_TOP = 1; protected static final int BORDER_RIGHT = 2; @@ -59,17 +62,28 @@ public final class HSLFTable extends HSLFGroupShape implements TableShape { /** * 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 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++) { @@ -85,17 +99,15 @@ public final class HSLFTable extends HSLFGroupShape implements TableShape { 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 lst = spCont.getChildRecords(); - lst.add(lst.size()-1, opt); - spCont.setChildRecords(lst); + spCont.addChildBefore(opt, RecordTypes.EscherClientAnchor); } /** @@ -104,7 +116,7 @@ public final class HSLFTable extends HSLFGroupShape implements TableShape { * @param escherRecord EscherSpContainer container which holds information about this shape * @param parent the parent of the shape */ - public HSLFTable(EscherContainerRecord escherRecord, ShapeContainer parent) { + public HSLFTable(EscherContainerRecord escherRecord, ShapeContainer parent) { super(escherRecord, parent); } @@ -131,7 +143,7 @@ public final class HSLFTable extends HSLFGroupShape implements TableShape { EscherContainerRecord spCont = (EscherContainerRecord) getSpContainer().getChild(0); List 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]; @@ -359,7 +371,7 @@ public final class HSLFTable extends HSLFGroupShape implements TableShape { 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); diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTableCell.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTableCell.java index e22db21ba..e3737e5e1 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTableCell.java +++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTableCell.java @@ -19,18 +19,19 @@ package org.apache.poi.hslf.usermodel; 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 { protected static final int DEFAULT_WIDTH = 100; protected static final int DEFAULT_HEIGHT = 40; @@ -45,7 +46,7 @@ public final class HSLFTableCell extends HSLFTextBox { * @param escherRecord EscherSpContainer which holds information about this shape * @param parent the parent of the shape */ - protected HSLFTableCell(EscherContainerRecord escherRecord, ShapeContainer parent){ + protected HSLFTableCell(EscherContainerRecord escherRecord, ShapeContainer parent){ super(escherRecord, parent); } @@ -55,7 +56,7 @@ public final class HSLFTableCell extends HSLFTextBox { * @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 parent){ + public HSLFTableCell(ShapeContainer parent){ super(parent); setShapeType(ShapeType.RECT); @@ -65,7 +66,7 @@ public final class HSLFTableCell extends HSLFTextBox { 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); diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextBox.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextBox.java index b7895a6ac..792928d1e 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextBox.java +++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextBox.java @@ -29,7 +29,7 @@ import org.apache.poi.sl.usermodel.*; * * @author Yegor Kozlov */ -public class HSLFTextBox extends HSLFTextShape { +public class HSLFTextBox extends HSLFTextShape implements TextBox { /** * Create a TextBox object and initialize it from the supplied Record container. @@ -37,7 +37,7 @@ public class HSLFTextBox extends HSLFTextShape { * @param escherRecord EscherSpContainer container which holds information about this shape * @param parent the parent of the shape */ - protected HSLFTextBox(EscherContainerRecord escherRecord, ShapeContainer parent){ + protected HSLFTextBox(EscherContainerRecord escherRecord, ShapeContainer parent){ super(escherRecord, parent); } @@ -48,7 +48,7 @@ public class HSLFTextBox extends HSLFTextShape { * @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 parent){ + public HSLFTextBox(ShapeContainer parent){ super(parent); } diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextParagraph.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextParagraph.java index 961c23410..9165bc1f3 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextParagraph.java +++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextParagraph.java @@ -42,7 +42,7 @@ import org.apache.poi.util.*; * @author Nick Burch */ -public final class HSLFTextParagraph implements TextParagraph { +public final class HSLFTextParagraph implements TextParagraph { protected static final POILogger logger = POILogFactory.getLogger(HSLFTextParagraph.class); /** diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextShape.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextShape.java index e2f73066e..5ca39b991 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextShape.java +++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextShape.java @@ -39,7 +39,8 @@ import org.apache.poi.util.Units; * * @author Yegor Kozlov */ -public abstract class HSLFTextShape extends HSLFSimpleShape implements TextShape { +public abstract class HSLFTextShape extends HSLFSimpleShape +implements TextShape { /** * How to anchor the text @@ -93,9 +94,8 @@ public abstract class HSLFTextShape extends HSLFSimpleShape implements TextShape * @param escherRecord EscherSpContainer container which holds information about this shape * @param parent the parent of the shape */ - protected HSLFTextShape(EscherContainerRecord escherRecord, ShapeContainer parent){ + protected HSLFTextShape(EscherContainerRecord escherRecord, ShapeContainer parent){ super(escherRecord, parent); - } /** @@ -104,7 +104,7 @@ public abstract class HSLFTextShape extends HSLFSimpleShape implements TextShape * @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 parent){ + public HSLFTextShape(ShapeContainer parent){ super(null, parent); _escherContainer = createSpContainer(parent instanceof HSLFGroupShape); } @@ -241,7 +241,7 @@ public abstract class HSLFTextShape extends HSLFSimpleShape implements TextShape * @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){ @@ -465,7 +465,7 @@ public abstract class HSLFTextShape extends HSLFSimpleShape implements TextShape * @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); @@ -494,7 +494,7 @@ public abstract class HSLFTextShape extends HSLFSimpleShape implements TextShape * @see MSOWRAPMODE */ public int getWordWrapEx() { - EscherOptRecord opt = getEscherOptRecord(); + AbstractEscherOptRecord opt = getEscherOptRecord(); EscherSimpleProperty prop = getEscherProperty(opt, EscherProperties.TEXT__WRAPTEXT); return prop == null ? WrapSquare : prop.getPropertyValue(); } @@ -513,7 +513,7 @@ public abstract class HSLFTextShape extends HSLFSimpleShape implements TextShape * @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(); } @@ -527,9 +527,7 @@ public abstract class HSLFTextShape extends HSLFSimpleShape implements TextShape setEscherProperty(EscherProperties.TEXT__TEXTID, id); } - /** - * @return the TextParagraphs for this text box - */ + @Override public List getTextParagraphs(){ if (!_paragraphs.isEmpty()) return _paragraphs; @@ -704,7 +702,7 @@ public abstract class HSLFTextShape extends HSLFSimpleShape implements TextShape @Override public double getTextHeight(){ DrawFactory drawFact = DrawFactory.getInstance(null); - DrawTextShape dts = drawFact.getDrawable(this); + DrawTextShape dts = drawFact.getDrawable(this); return dts.getTextHeight(); } diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestBackground.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestBackground.java index eaebd5c16..f8b4bccb5 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestBackground.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestBackground.java @@ -26,9 +26,9 @@ import java.io.ByteArrayOutputStream; 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; @@ -209,7 +209,7 @@ public final class TestBackground { } 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(); diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestShapes.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestShapes.java index 3fca4c257..3dfdd5783 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestShapes.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestShapes.java @@ -36,13 +36,14 @@ import java.util.ArrayList; 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; @@ -54,7 +55,6 @@ import org.apache.poi.hslf.usermodel.HSLFTextBox; 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; @@ -400,7 +400,7 @@ public final class TestShapes { 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); diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTable.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTable.java index 70028ba4b..8032d2da3 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTable.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTable.java @@ -126,17 +126,17 @@ public final class TestTable { */ @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> slides = ppt.getSlides(); + List> slides = ppt.getSlides(); assertEquals(1, slides.size()); - List shapes = slides.get(0).getShapes(); //throws NullPointerException + List> 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; } } diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java index 1dbd0f457..a8543924a 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java @@ -38,9 +38,9 @@ import java.util.Set; 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; @@ -612,7 +612,7 @@ public final class TestBugs { 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 diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestPicture.java b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestPicture.java index d7adf4000..a66065710 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestPicture.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestPicture.java @@ -172,11 +172,11 @@ public final class TestPicture { 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); } @@ -184,7 +184,7 @@ public final class TestPicture { 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;