You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by ba...@apache.org on 2006/12/22 21:56:06 UTC

svn commit: r489760 [3/8] - in /jakarta/poi/trunk/src: java/org/apache/poi/hssf/record/ java/org/apache/poi/hssf/record/formula/ java/org/apache/poi/hssf/util/ scratchpad/src/org/apache/poi/hslf/blip/ scratchpad/src/org/apache/poi/hslf/extractor/ scrat...

Modified: jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/PPGraphics2D.java
URL: http://svn.apache.org/viewvc/jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/PPGraphics2D.java?view=diff&rev=489760&r1=489759&r2=489760
==============================================================================
--- jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/PPGraphics2D.java (original)
+++ jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/PPGraphics2D.java Fri Dec 22 12:56:04 2006
@@ -1,512 +1,512 @@
-/* ====================================================================
-   Copyright 2002-2004   Apache Software Foundation
-
-   Licensed under the Apache License, Version 2.0 (the "License");
-   you may not use this file except in compliance with the License.
-   You may obtain a copy of the License at
-
-       http://www.apache.org/licenses/LICENSE-2.0
-
-   Unless required by applicable law or agreed to in writing, software
-   distributed under the License is distributed on an "AS IS" BASIS,
-   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-   See the License for the specific language governing permissions and
-   limitations under the License.
-==================================================================== */
-package org.apache.poi.hslf.model;
-
-
-import java.awt.*;
-import java.awt.Shape;
-import java.awt.font.FontRenderContext;
-import java.awt.font.GlyphVector;
-import java.awt.image.*;
-import java.awt.image.renderable.RenderableImage;
-import java.awt.geom.AffineTransform;
-import java.awt.geom.PathIterator;
-import java.text.AttributedCharacterIterator;
-import java.util.Map;
-import java.util.ArrayList;
-
-import org.apache.poi.ddf.EscherProperties;
-import org.apache.poi.hslf.usermodel.RichTextRun;
-
-/**
- * Translates Graphics2D calls into PowerPoint.
- *
- * @author Yegor Kozlov
- */
-public class PPGraphics2D extends Graphics2D {
-    //The group to write the graphics calls into.
-    private ShapeGroup group;
-
-    private AffineTransform transform;
-    private Stroke stroke;
-    private Paint paint;
-    private Font font;
-    private Color foreground;
-    private Color background = Color.white;
-    private Shape clip;
-    int count = 0;
-    /**
-     * Construct Java Graphics object which translates graphic calls in ppt drawing layer.
-     *
-     * @param group           The shape group to write the graphics calls into.
-     */
-    public PPGraphics2D(ShapeGroup group){
-        this.group = group;
-        transform = new AffineTransform();
-    }
-
-    /**
-     * @return  the shape group being used for drawing
-     */
-    public ShapeGroup getShapeGroup(){
-        return group;
-    }
-
-    public Font getFont(){
-        return font;
-    }
-
-    public void setFont(Font font){
-        this.font = font;
-    }
-
-    public Color getColor(){
-        return foreground;
-    }
-
-    public void setColor(Color color) {
-        this.foreground = color;
-    }
-
-    public Stroke getStroke(){
-        return stroke;
-    }
-
-    public void setStroke(Stroke s){
-        this.stroke = s;
-    }
-
-    public Paint getPaint(){
-        return paint;
-    }
-
-    public void setPaint(Paint paint){
-        this.paint = paint;
-        if (paint instanceof Color) setColor((Color)paint);
-    }
-
-    public AffineTransform getTransform(){
-        return (AffineTransform)transform.clone();
-    }
-
-    public void setTransform(AffineTransform trans) {
-        transform = (AffineTransform)trans.clone();
-    }
-
-    public void draw(Shape shape){
-        if(clip != null) {
-            java.awt.Rectangle bounds = getTransform().createTransformedShape(shape).getBounds();
-            if (bounds.width == 0) bounds.width = 1;
-            if (bounds.height == 0) bounds.height = 1;
-            if (!clip.getBounds().contains(bounds)) {
-                return;
-            }
-        }
-
-        PathIterator it = shape.getPathIterator(transform);
-        double[] prev = null;
-        double[] coords = new double[6];
-        double[] first = new double[6];
-        if(!it.isDone()) it.currentSegment(first); //first point
-        while(!it.isDone()){
-            int type = it.currentSegment(coords);
-            if (prev != null ){
-                Line line = new Line(group);
-                if (stroke instanceof BasicStroke){
-                    BasicStroke bs = (BasicStroke)stroke;
-                    line.setLineWidth(bs.getLineWidth());
-                    float[] dash = bs.getDashArray();
-                    if (dash != null) line.setLineDashing(Line.PEN_DASH);
-                }
-                if(getColor() != null) line.setLineColor(getColor());
-                if (type == PathIterator.SEG_LINETO) {
-                    line.setAnchor(new java.awt.Rectangle((int)prev[0],  (int)prev[1], (int)(coords[0] - prev[0]), (int)(coords[1] - prev[1])));
-                } else if (type == PathIterator.SEG_CLOSE){
-                    line.setAnchor(new java.awt.Rectangle((int)coords[0],  (int)coords[1], (int)(first[0] - coords[0]), (int)(first[1] - coords[1])));
-                }
-                group.addShape(line);
-            }
-            prev = new double[]{coords[0],  coords[1]};
-            it.next();
-        }
-
-    }
-
-    public void drawString(String string, float x, float y){
-         TextBox txt = new TextBox(group);
-         txt.getTextRun().supplySlideShow(group.getSheet().getSlideShow());
-         txt.getTextRun().setSheet(group.getSheet());
-         txt.setText(string);
-
-         RichTextRun rt = txt.getTextRun().getRichTextRuns()[0];
-         rt.setFontSize(font.getSize());
-         rt.setFontName(font.getFamily());
-
-        if(getColor() != null) rt.setFontColor(getColor());
-        if (font.isBold()) rt.setBold(true);
-        if (font.isItalic()) rt.setItalic(true);
-
-         txt.setMarginBottom(0);
-         txt.setMarginTop(0);
-         txt.setMarginLeft(0);
-         txt.setMarginRight(0);
-         txt.setWordWrap(TextBox.WrapNone);
-
-         if (!"".equals(string)) txt.resizeToFitText();
-         int height = (int)txt.getAnchor().getHeight();
-
-         /*
-           In powerpoint anchor of a shape is its top left corner.
-           Java graphics sets string coordinates by the baseline of the first character
-           so we need to shift down by the height of the textbox
-         */
-        txt.moveTo((int)x, (int)(y - height));
-
-        if(clip != null) {
-            if (!clip.getBounds().contains(txt.getAnchor())) {
-                ;//return;
-            }
-        }
-       group.addShape(txt);
-    }
-
-    public void fill(Shape shape){
-        if(clip != null) {
-            java.awt.Rectangle bounds = getTransform().createTransformedShape(shape).getBounds();
-            if (bounds.width == 0) bounds.width = 1;
-            if (bounds.height == 0) bounds.height = 1;
-             if (!clip.getBounds().contains(bounds)) {
-                return;
-            }
-        }
-        PathIterator it = shape.getPathIterator(transform);
-        ArrayList pnt = new ArrayList();
-        double[] coords = new double[6];
-        while(!it.isDone()){
-            int type = it.currentSegment(coords);
-            if (type != PathIterator.SEG_CLOSE) {
-                pnt.add(new Point((int)coords[0], (int)coords[1]));
-            }
-            it.next();
-        }
-        int[] xPoints= new int[pnt.size()];
-        int[] yPoints= new int[pnt.size()];
-        for (int i = 0; i < pnt.size(); i++) {
-            Point p = (Point)pnt.get(i);
-            xPoints[i] = p.x;
-            yPoints[i] = p.y;
-        }
-
-        AutoShape r = new AutoShape(ShapeTypes.Rectangle);
-        if (paint instanceof Color){
-            Color color = (Color)paint;
-            r.setFillColor(color);
-        }
-        if(getColor() != null) r.setLineColor(getColor());
-        if (stroke instanceof BasicStroke){
-            BasicStroke bs = (BasicStroke)stroke;
-            r.setLineWidth(bs.getLineWidth());
-            float[] dash = bs.getDashArray();
-            if (dash != null) r.setLineDashing(Line.PEN_DASH);
-        }
-
-        java.awt.Rectangle bounds = transform.createTransformedShape(shape).getBounds();
-        r.setAnchor(bounds);
-        group.addShape(r);
-    }
-
-    public void translate(int x, int y) {
-        AffineTransform at = new AffineTransform();
-        at.translate(x, y);
-        transform.concatenate(at);
-    }
-
-    public void clip(Shape shape) {
-        this.clip = transform.createTransformedShape(shape);
-        //update size of the escher group which holds the drawing
-        group.setAnchor(clip.getBounds());
-    }
-
-    public Shape getClip() {
-        return clip;
-    }
-
-    public void scale(double sx, double sy) {
-        AffineTransform at = new AffineTransform();
-        at.scale(sx, sy);
-        transform.concatenate(at);
-    }
-    //===============================================
-    public void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) {
-        throw new RuntimeException("Not implemented");
-    }
-
-    public void drawString(String str, int x, int y) {
-        throw new RuntimeException("Not implemented");
-    }
-
-    public void fillOval(int x, int y, int width, int height) {
-        throw new RuntimeException("Not implemented");
-    }
-
-    public void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) {
-        throw new RuntimeException("Not implemented");
-    }
-
-    public void fillArc(int x, int y, int width, int height,
-                        int startAngle, int arcAngle) {
-        throw new RuntimeException("Not implemented");
-    }
-
-    public void setPaintMode() {
-        throw new RuntimeException("Not implemented");
-    }
-
-    public void drawArc(int x, int y, int width, int height,
-                        int startAngle, int arcAngle) {
-        throw new RuntimeException("Not implemented");
-    }
-
-
-    public void drawPolyline(int xPoints[], int yPoints[],
-                             int nPoints) {
-        throw new RuntimeException("Not implemented");
-    }
-
-    public Graphics create() {
-        throw new RuntimeException("Not implemented");
-    }
-
-    public void drawOval(int x, int y, int width, int height) {
-        AutoShape ellipse = new AutoShape(ShapeTypes.Ellipse);
-        ellipse.setAnchor(new java.awt.Rectangle(x-width/2, y-height/2, width, height));
-        if (stroke instanceof BasicStroke){
-            BasicStroke bs = (BasicStroke)stroke;
-            ellipse.setLineWidth(bs.getLineWidth());
-        }
-        if(getColor() != null) ellipse.setLineColor(getColor());
-        if (paint instanceof Color){
-            Color color = (Color)paint;
-            ellipse.setFillColor(color);
-        }
-
-        group.addShape(ellipse);
-    }
-
-    public void setXORMode(Color color1) {
-        throw new RuntimeException("Not implemented");
-    }
-
-
-    public boolean drawImage(Image img, int x, int y,
-                             Color bgcolor,
-                             ImageObserver observer) {
-        throw new RuntimeException("Not implemented");
-    }
-
-    public boolean drawImage(Image img, int x, int y,
-                             int width, int height,
-                             Color bgcolor,
-                             ImageObserver observer) {
-        throw new RuntimeException("Not implemented");
-    }
-
-
-    public boolean drawImage(Image img,
-                             int dx1, int dy1, int dx2, int dy2,
-                             int sx1, int sy1, int sx2, int sy2,
-                             ImageObserver observer) {
-        throw new RuntimeException("Not implemented");
-    }
-
-    public boolean drawImage(Image img,
-                             int dx1, int dy1, int dx2, int dy2,
-                             int sx1, int sy1, int sx2, int sy2,
-                             Color bgcolor,
-                             ImageObserver observer) {
-        throw new RuntimeException("Not implemented");
-    }
-
-    public boolean drawImage(Image img, int x, int y,
-                             ImageObserver observer) {
-        throw new RuntimeException("Not implemented");
-    }
-
-    public boolean drawImage(Image img, int x, int y,
-                             int width, int height,
-                             ImageObserver observer) {
-        throw new RuntimeException("Not implemented");
-    }
-
-    public void dispose() {
-        throw new RuntimeException("Not implemented");
-    }
-
-    public void drawLine(int x1, int y1, int x2, int y2) {
-        Line line = new Line();
-        line.setAnchor(new java.awt.Rectangle(x1, y1, x2-x1, y2-y1));
-        if (stroke instanceof BasicStroke){
-            BasicStroke bs = (BasicStroke)stroke;
-            line.setLineWidth(bs.getLineWidth());
-        }
-        if(getColor() != null) line.setLineColor(getColor());
-        group.addShape(line);
-    }
-
-    public void fillPolygon(int xPoints[], int yPoints[],
-                            int nPoints) {
-        throw new RuntimeException("Not implemented");
-    }
-
-    public FontMetrics getFontMetrics(Font f) {
-        throw new RuntimeException("Not implemented");
-    }
-
-    public void fillRect(int x, int y, int width, int height) {
-        throw new RuntimeException("Not implemented");
-    }
-
-    public void drawPolygon(int xPoints[], int yPoints[],
-                            int nPoints) {
-        throw new RuntimeException("Not implemented");
-    }
-
-    public void clipRect(int x, int y, int width, int height) {
-        throw new RuntimeException("Not implemented");
-    }
-
-    public void setClip(Shape clip) {
-        throw new RuntimeException("Not implemented");
-    }
-
-    public java.awt.Rectangle getClipBounds() {
-        throw new RuntimeException("Not implemented");
-    }
-
-    public void drawString(AttributedCharacterIterator iterator, int x, int y) {
-        throw new RuntimeException("Not implemented");
-    }
-
-    public void clearRect(int x, int y, int width, int height) {
-        throw new RuntimeException("Not implemented");
-    }
-
-    public void copyArea(int x, int y, int width, int height, int dx, int dy) {
-        throw new RuntimeException("Not implemented");
-    }
-
-    public void setClip(int x, int y, int width, int height) {
-        throw new RuntimeException("Not implemented");
-    }
-
-    public void rotate(double d) {
-        throw new RuntimeException("Not implemented");
-
-    }
-
-    public void rotate(double d, double d1, double d2) {
-        throw new RuntimeException("Not implemented");
-    }
-
-    public void shear(double d, double d1) {
-        throw new RuntimeException("Not implemented");
-    }
-
-    public FontRenderContext getFontRenderContext() {
-        return new FontRenderContext(transform, true, true);
-    }
-
-    public void transform(AffineTransform affinetransform) {
-        throw new RuntimeException("Not implemented");
-    }
-
-    public void drawImage(BufferedImage bufferedimage, BufferedImageOp op, int x, int y) {
-        throw new RuntimeException("Not implemented");
-    }
-
-    public void setBackground(Color c) {
-        throw new RuntimeException("Not implemented");
-    }
-
-    public void drawRenderedImage(RenderedImage renderedimage, AffineTransform affinetransform) {
-        throw new RuntimeException("Not implemented");
-    }
-
-    public Color getBackground() {
-        throw new RuntimeException("Not implemented");
-    }
-
-    public void setComposite(Composite composite) {
-        throw new RuntimeException("Not implemented");
-
-    }
-
-    public Composite getComposite() {
-        throw new RuntimeException("Not implemented");
-    }
-
-    public Object getRenderingHint(java.awt.RenderingHints.Key key) {
-        throw new RuntimeException("Not implemented");
-    }
-
-    public boolean drawImage(Image image, AffineTransform affinetransform, ImageObserver imageobserver) {
-        throw new RuntimeException("Not implemented");
-    }
-
-    public void setRenderingHint(java.awt.RenderingHints.Key key, Object obj) {
-        throw new RuntimeException("Not implemented");
-    }
-
-
-    public void drawGlyphVector(GlyphVector g, float x, float y) {
-        throw new RuntimeException("Not implemented");
-
-    }
-
-    public GraphicsConfiguration getDeviceConfiguration() {
-        throw new RuntimeException("Not implemented");
-    }
-
-    public void addRenderingHints(Map map) {
-        throw new RuntimeException("Not implemented");
-    }
-
-    public void translate(double d, double d1) {
-
-        throw new RuntimeException("Not implemented");
-    }
-
-    public void drawString(AttributedCharacterIterator attributedcharacteriterator, float x, float y) {
-        throw new RuntimeException("Not implemented");
-    }
-
-    public boolean hit(java.awt.Rectangle rectangle, Shape shape, boolean flag) {
-        throw new RuntimeException("Not implemented");
-    }
-
-    public RenderingHints getRenderingHints() {
-        throw new RuntimeException("Not implemented");
-    }
-
-    public void setRenderingHints(Map map) {
-        throw new RuntimeException("Not implemented");
-
-    }
-
-    public void drawRenderableImage(RenderableImage renderableimage, AffineTransform affinetransform) {
-        throw new RuntimeException("Not implemented");
-    }
-}
+/* ====================================================================
+   Copyright 2002-2004   Apache Software Foundation
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+package org.apache.poi.hslf.model;
+
+
+import java.awt.*;
+import java.awt.Shape;
+import java.awt.font.FontRenderContext;
+import java.awt.font.GlyphVector;
+import java.awt.image.*;
+import java.awt.image.renderable.RenderableImage;
+import java.awt.geom.AffineTransform;
+import java.awt.geom.PathIterator;
+import java.text.AttributedCharacterIterator;
+import java.util.Map;
+import java.util.ArrayList;
+
+import org.apache.poi.ddf.EscherProperties;
+import org.apache.poi.hslf.usermodel.RichTextRun;
+
+/**
+ * Translates Graphics2D calls into PowerPoint.
+ *
+ * @author Yegor Kozlov
+ */
+public class PPGraphics2D extends Graphics2D {
+    //The group to write the graphics calls into.
+    private ShapeGroup group;
+
+    private AffineTransform transform;
+    private Stroke stroke;
+    private Paint paint;
+    private Font font;
+    private Color foreground;
+    private Color background = Color.white;
+    private Shape clip;
+    int count = 0;
+    /**
+     * Construct Java Graphics object which translates graphic calls in ppt drawing layer.
+     *
+     * @param group           The shape group to write the graphics calls into.
+     */
+    public PPGraphics2D(ShapeGroup group){
+        this.group = group;
+        transform = new AffineTransform();
+    }
+
+    /**
+     * @return  the shape group being used for drawing
+     */
+    public ShapeGroup getShapeGroup(){
+        return group;
+    }
+
+    public Font getFont(){
+        return font;
+    }
+
+    public void setFont(Font font){
+        this.font = font;
+    }
+
+    public Color getColor(){
+        return foreground;
+    }
+
+    public void setColor(Color color) {
+        this.foreground = color;
+    }
+
+    public Stroke getStroke(){
+        return stroke;
+    }
+
+    public void setStroke(Stroke s){
+        this.stroke = s;
+    }
+
+    public Paint getPaint(){
+        return paint;
+    }
+
+    public void setPaint(Paint paint){
+        this.paint = paint;
+        if (paint instanceof Color) setColor((Color)paint);
+    }
+
+    public AffineTransform getTransform(){
+        return (AffineTransform)transform.clone();
+    }
+
+    public void setTransform(AffineTransform trans) {
+        transform = (AffineTransform)trans.clone();
+    }
+
+    public void draw(Shape shape){
+        if(clip != null) {
+            java.awt.Rectangle bounds = getTransform().createTransformedShape(shape).getBounds();
+            if (bounds.width == 0) bounds.width = 1;
+            if (bounds.height == 0) bounds.height = 1;
+            if (!clip.getBounds().contains(bounds)) {
+                return;
+            }
+        }
+
+        PathIterator it = shape.getPathIterator(transform);
+        double[] prev = null;
+        double[] coords = new double[6];
+        double[] first = new double[6];
+        if(!it.isDone()) it.currentSegment(first); //first point
+        while(!it.isDone()){
+            int type = it.currentSegment(coords);
+            if (prev != null ){
+                Line line = new Line(group);
+                if (stroke instanceof BasicStroke){
+                    BasicStroke bs = (BasicStroke)stroke;
+                    line.setLineWidth(bs.getLineWidth());
+                    float[] dash = bs.getDashArray();
+                    if (dash != null) line.setLineDashing(Line.PEN_DASH);
+                }
+                if(getColor() != null) line.setLineColor(getColor());
+                if (type == PathIterator.SEG_LINETO) {
+                    line.setAnchor(new java.awt.Rectangle((int)prev[0],  (int)prev[1], (int)(coords[0] - prev[0]), (int)(coords[1] - prev[1])));
+                } else if (type == PathIterator.SEG_CLOSE){
+                    line.setAnchor(new java.awt.Rectangle((int)coords[0],  (int)coords[1], (int)(first[0] - coords[0]), (int)(first[1] - coords[1])));
+                }
+                group.addShape(line);
+            }
+            prev = new double[]{coords[0],  coords[1]};
+            it.next();
+        }
+
+    }
+
+    public void drawString(String string, float x, float y){
+         TextBox txt = new TextBox(group);
+         txt.getTextRun().supplySlideShow(group.getSheet().getSlideShow());
+         txt.getTextRun().setSheet(group.getSheet());
+         txt.setText(string);
+
+         RichTextRun rt = txt.getTextRun().getRichTextRuns()[0];
+         rt.setFontSize(font.getSize());
+         rt.setFontName(font.getFamily());
+
+        if(getColor() != null) rt.setFontColor(getColor());
+        if (font.isBold()) rt.setBold(true);
+        if (font.isItalic()) rt.setItalic(true);
+
+         txt.setMarginBottom(0);
+         txt.setMarginTop(0);
+         txt.setMarginLeft(0);
+         txt.setMarginRight(0);
+         txt.setWordWrap(TextBox.WrapNone);
+
+         if (!"".equals(string)) txt.resizeToFitText();
+         int height = (int)txt.getAnchor().getHeight();
+
+         /*
+           In powerpoint anchor of a shape is its top left corner.
+           Java graphics sets string coordinates by the baseline of the first character
+           so we need to shift down by the height of the textbox
+         */
+        txt.moveTo((int)x, (int)(y - height));
+
+        if(clip != null) {
+            if (!clip.getBounds().contains(txt.getAnchor())) {
+                ;//return;
+            }
+        }
+       group.addShape(txt);
+    }
+
+    public void fill(Shape shape){
+        if(clip != null) {
+            java.awt.Rectangle bounds = getTransform().createTransformedShape(shape).getBounds();
+            if (bounds.width == 0) bounds.width = 1;
+            if (bounds.height == 0) bounds.height = 1;
+             if (!clip.getBounds().contains(bounds)) {
+                return;
+            }
+        }
+        PathIterator it = shape.getPathIterator(transform);
+        ArrayList pnt = new ArrayList();
+        double[] coords = new double[6];
+        while(!it.isDone()){
+            int type = it.currentSegment(coords);
+            if (type != PathIterator.SEG_CLOSE) {
+                pnt.add(new Point((int)coords[0], (int)coords[1]));
+            }
+            it.next();
+        }
+        int[] xPoints= new int[pnt.size()];
+        int[] yPoints= new int[pnt.size()];
+        for (int i = 0; i < pnt.size(); i++) {
+            Point p = (Point)pnt.get(i);
+            xPoints[i] = p.x;
+            yPoints[i] = p.y;
+        }
+
+        AutoShape r = new AutoShape(ShapeTypes.Rectangle);
+        if (paint instanceof Color){
+            Color color = (Color)paint;
+            r.setFillColor(color);
+        }
+        if(getColor() != null) r.setLineColor(getColor());
+        if (stroke instanceof BasicStroke){
+            BasicStroke bs = (BasicStroke)stroke;
+            r.setLineWidth(bs.getLineWidth());
+            float[] dash = bs.getDashArray();
+            if (dash != null) r.setLineDashing(Line.PEN_DASH);
+        }
+
+        java.awt.Rectangle bounds = transform.createTransformedShape(shape).getBounds();
+        r.setAnchor(bounds);
+        group.addShape(r);
+    }
+
+    public void translate(int x, int y) {
+        AffineTransform at = new AffineTransform();
+        at.translate(x, y);
+        transform.concatenate(at);
+    }
+
+    public void clip(Shape shape) {
+        this.clip = transform.createTransformedShape(shape);
+        //update size of the escher group which holds the drawing
+        group.setAnchor(clip.getBounds());
+    }
+
+    public Shape getClip() {
+        return clip;
+    }
+
+    public void scale(double sx, double sy) {
+        AffineTransform at = new AffineTransform();
+        at.scale(sx, sy);
+        transform.concatenate(at);
+    }
+    //===============================================
+    public void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) {
+        throw new RuntimeException("Not implemented");
+    }
+
+    public void drawString(String str, int x, int y) {
+        throw new RuntimeException("Not implemented");
+    }
+
+    public void fillOval(int x, int y, int width, int height) {
+        throw new RuntimeException("Not implemented");
+    }
+
+    public void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) {
+        throw new RuntimeException("Not implemented");
+    }
+
+    public void fillArc(int x, int y, int width, int height,
+                        int startAngle, int arcAngle) {
+        throw new RuntimeException("Not implemented");
+    }
+
+    public void setPaintMode() {
+        throw new RuntimeException("Not implemented");
+    }
+
+    public void drawArc(int x, int y, int width, int height,
+                        int startAngle, int arcAngle) {
+        throw new RuntimeException("Not implemented");
+    }
+
+
+    public void drawPolyline(int xPoints[], int yPoints[],
+                             int nPoints) {
+        throw new RuntimeException("Not implemented");
+    }
+
+    public Graphics create() {
+        throw new RuntimeException("Not implemented");
+    }
+
+    public void drawOval(int x, int y, int width, int height) {
+        AutoShape ellipse = new AutoShape(ShapeTypes.Ellipse);
+        ellipse.setAnchor(new java.awt.Rectangle(x-width/2, y-height/2, width, height));
+        if (stroke instanceof BasicStroke){
+            BasicStroke bs = (BasicStroke)stroke;
+            ellipse.setLineWidth(bs.getLineWidth());
+        }
+        if(getColor() != null) ellipse.setLineColor(getColor());
+        if (paint instanceof Color){
+            Color color = (Color)paint;
+            ellipse.setFillColor(color);
+        }
+
+        group.addShape(ellipse);
+    }
+
+    public void setXORMode(Color color1) {
+        throw new RuntimeException("Not implemented");
+    }
+
+
+    public boolean drawImage(Image img, int x, int y,
+                             Color bgcolor,
+                             ImageObserver observer) {
+        throw new RuntimeException("Not implemented");
+    }
+
+    public boolean drawImage(Image img, int x, int y,
+                             int width, int height,
+                             Color bgcolor,
+                             ImageObserver observer) {
+        throw new RuntimeException("Not implemented");
+    }
+
+
+    public boolean drawImage(Image img,
+                             int dx1, int dy1, int dx2, int dy2,
+                             int sx1, int sy1, int sx2, int sy2,
+                             ImageObserver observer) {
+        throw new RuntimeException("Not implemented");
+    }
+
+    public boolean drawImage(Image img,
+                             int dx1, int dy1, int dx2, int dy2,
+                             int sx1, int sy1, int sx2, int sy2,
+                             Color bgcolor,
+                             ImageObserver observer) {
+        throw new RuntimeException("Not implemented");
+    }
+
+    public boolean drawImage(Image img, int x, int y,
+                             ImageObserver observer) {
+        throw new RuntimeException("Not implemented");
+    }
+
+    public boolean drawImage(Image img, int x, int y,
+                             int width, int height,
+                             ImageObserver observer) {
+        throw new RuntimeException("Not implemented");
+    }
+
+    public void dispose() {
+        throw new RuntimeException("Not implemented");
+    }
+
+    public void drawLine(int x1, int y1, int x2, int y2) {
+        Line line = new Line();
+        line.setAnchor(new java.awt.Rectangle(x1, y1, x2-x1, y2-y1));
+        if (stroke instanceof BasicStroke){
+            BasicStroke bs = (BasicStroke)stroke;
+            line.setLineWidth(bs.getLineWidth());
+        }
+        if(getColor() != null) line.setLineColor(getColor());
+        group.addShape(line);
+    }
+
+    public void fillPolygon(int xPoints[], int yPoints[],
+                            int nPoints) {
+        throw new RuntimeException("Not implemented");
+    }
+
+    public FontMetrics getFontMetrics(Font f) {
+        throw new RuntimeException("Not implemented");
+    }
+
+    public void fillRect(int x, int y, int width, int height) {
+        throw new RuntimeException("Not implemented");
+    }
+
+    public void drawPolygon(int xPoints[], int yPoints[],
+                            int nPoints) {
+        throw new RuntimeException("Not implemented");
+    }
+
+    public void clipRect(int x, int y, int width, int height) {
+        throw new RuntimeException("Not implemented");
+    }
+
+    public void setClip(Shape clip) {
+        throw new RuntimeException("Not implemented");
+    }
+
+    public java.awt.Rectangle getClipBounds() {
+        throw new RuntimeException("Not implemented");
+    }
+
+    public void drawString(AttributedCharacterIterator iterator, int x, int y) {
+        throw new RuntimeException("Not implemented");
+    }
+
+    public void clearRect(int x, int y, int width, int height) {
+        throw new RuntimeException("Not implemented");
+    }
+
+    public void copyArea(int x, int y, int width, int height, int dx, int dy) {
+        throw new RuntimeException("Not implemented");
+    }
+
+    public void setClip(int x, int y, int width, int height) {
+        throw new RuntimeException("Not implemented");
+    }
+
+    public void rotate(double d) {
+        throw new RuntimeException("Not implemented");
+
+    }
+
+    public void rotate(double d, double d1, double d2) {
+        throw new RuntimeException("Not implemented");
+    }
+
+    public void shear(double d, double d1) {
+        throw new RuntimeException("Not implemented");
+    }
+
+    public FontRenderContext getFontRenderContext() {
+        return new FontRenderContext(transform, true, true);
+    }
+
+    public void transform(AffineTransform affinetransform) {
+        throw new RuntimeException("Not implemented");
+    }
+
+    public void drawImage(BufferedImage bufferedimage, BufferedImageOp op, int x, int y) {
+        throw new RuntimeException("Not implemented");
+    }
+
+    public void setBackground(Color c) {
+        throw new RuntimeException("Not implemented");
+    }
+
+    public void drawRenderedImage(RenderedImage renderedimage, AffineTransform affinetransform) {
+        throw new RuntimeException("Not implemented");
+    }
+
+    public Color getBackground() {
+        throw new RuntimeException("Not implemented");
+    }
+
+    public void setComposite(Composite composite) {
+        throw new RuntimeException("Not implemented");
+
+    }
+
+    public Composite getComposite() {
+        throw new RuntimeException("Not implemented");
+    }
+
+    public Object getRenderingHint(java.awt.RenderingHints.Key key) {
+        throw new RuntimeException("Not implemented");
+    }
+
+    public boolean drawImage(Image image, AffineTransform affinetransform, ImageObserver imageobserver) {
+        throw new RuntimeException("Not implemented");
+    }
+
+    public void setRenderingHint(java.awt.RenderingHints.Key key, Object obj) {
+        throw new RuntimeException("Not implemented");
+    }
+
+
+    public void drawGlyphVector(GlyphVector g, float x, float y) {
+        throw new RuntimeException("Not implemented");
+
+    }
+
+    public GraphicsConfiguration getDeviceConfiguration() {
+        throw new RuntimeException("Not implemented");
+    }
+
+    public void addRenderingHints(Map map) {
+        throw new RuntimeException("Not implemented");
+    }
+
+    public void translate(double d, double d1) {
+
+        throw new RuntimeException("Not implemented");
+    }
+
+    public void drawString(AttributedCharacterIterator attributedcharacteriterator, float x, float y) {
+        throw new RuntimeException("Not implemented");
+    }
+
+    public boolean hit(java.awt.Rectangle rectangle, Shape shape, boolean flag) {
+        throw new RuntimeException("Not implemented");
+    }
+
+    public RenderingHints getRenderingHints() {
+        throw new RuntimeException("Not implemented");
+    }
+
+    public void setRenderingHints(Map map) {
+        throw new RuntimeException("Not implemented");
+
+    }
+
+    public void drawRenderableImage(RenderableImage renderableimage, AffineTransform affinetransform) {
+        throw new RuntimeException("Not implemented");
+    }
+}

Modified: jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/Picture.java
URL: http://svn.apache.org/viewvc/jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/Picture.java?view=diff&rev=489760&r1=489759&r2=489760
==============================================================================
--- jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/Picture.java (original)
+++ jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/Picture.java Fri Dec 22 12:56:04 2006
@@ -1,179 +1,179 @@
-package org.apache.poi.hslf.model;
-
-import org.apache.poi.ddf.*;
-import org.apache.poi.hslf.usermodel.PictureData;
-import org.apache.poi.hslf.usermodel.SlideShow;
-import org.apache.poi.hslf.record.Document;
-import org.apache.poi.hslf.blip.Bitmap;
-
-import javax.imageio.ImageIO;
-import java.awt.image.BufferedImage;
-import java.awt.*;
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.util.List;
-import java.util.Arrays;
-
-
-/**
- * Represents a picture in a PowerPoint document.
- * <p>
- * The information about an image in PowerPoint document is stored in
- * two places:
- *  <li> EscherBSE container in the Document keeps information about image
- *    type, image index to refer by slides etc.
- *  <li> "Pictures" OLE stream holds the actual data of the image.
- * </p>
- *
- * @author Yegor Kozlov
- */
-public class Picture extends SimpleShape {
-
-    /**
-    *  Windows Enhanced Metafile (EMF)
-    */
-    public static final int EMF = 2;
-
-    /**
-    *  Windows Metafile (WMF)
-    */
-    public static final int WMF = 3;
-
-    /**
-    * Macintosh PICT
-    */
-    public static final int PICT = 4;
-
-    /**
-    *  JPEG
-    */
-    public static final int JPEG = 5;
-
-    /**
-    *  PNG
-    */
-    public static final int PNG = 6;
-
-    /**
-     * Windows DIB (BMP)
-     */
-    public static final byte DIB = 7;
-    
-    /**
-     * Create a new <code>Picture</code>
-     *
-    * @param idx the index of the picture
-     */
-    public Picture(int idx){
-        super(null, null);
-        _escherContainer = createSpContainer(idx);
-    }
-
-    /**
-      * Create a <code>Picture</code> object
-      *
-      * @param escherRecord the <code>EscherSpContainer</code> record which holds information about
-      *        this picture in the <code>Slide</code>
-      * @param parent the parent shape of this picture
-      */
-     protected Picture(EscherContainerRecord escherRecord, Shape parent){
-        super(escherRecord, parent);
-    }
-
-    /**
-     * Returns index associated with this picture.
-     * Index starts with 1 and points to a EscherBSE record which
-     * holds information about this picture.
-     *
-     * @return the index to this picture (1 based).
-     */
-    public int getPictureIndex(){
-        EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
-        EscherSimpleProperty prop = (EscherSimpleProperty)getEscherProperty(opt, EscherProperties.BLIP__BLIPTODISPLAY + 0x4000);
-        return prop.getPropertyValue();
-    }
-
-    /**
-     * Create a new Picture and populate the inital structure of the <code>EscherSp</code> record which holds information about this picture.
-
-     * @param idx the index of the picture which referes to <code>EscherBSE</code> container.
-     * @return the create Picture object
-     */
-    protected EscherContainerRecord createSpContainer(int idx) {
-        EscherContainerRecord spContainer = super.createSpContainer(false);
-        spContainer.setOptions((short)15);
-
-        EscherSpRecord spRecord = spContainer.getChildById(EscherSpRecord.RECORD_ID);
-        spRecord.setOptions((short)((ShapeTypes.PictureFrame << 4) | 0x2));
-
-        //set default properties for a picture
-        EscherOptRecord opt = (EscherOptRecord)getEscherChild(spContainer, EscherOptRecord.RECORD_ID);
-        setEscherProperty(opt, EscherProperties.PROTECTION__LOCKAGAINSTGROUPING, 8388736);
-
-        //another weird feature of powerpoint: for picture id we must add 0x4000.
-        setEscherProperty(opt, (short)(EscherProperties.BLIP__BLIPTODISPLAY + 0x4000), idx);
-
-        return spContainer;
-    }
-
-    /**
-     * Resize this picture to the default size.
-     */
-    public void setDefaultSize(){
-        PictureData pict = getPictureData();
-        if (pict  instanceof Bitmap){
-            BufferedImage img = null;
-            try {
-               	img = ImageIO.read(new ByteArrayInputStream(pict.getData()));
-            } 
-            catch (IOException e){}
-        	catch (NegativeArraySizeException ne) {}
-        	
-            if(img != null) {
-            	// Valid image, set anchor from it
-            	setAnchor(new java.awt.Rectangle(0, 0, img.getWidth(), img.getHeight()));
-            } else {
-            	// Invalid image, go with the default metafile size
-            	setAnchor(new java.awt.Rectangle(0, 0, 200, 200));
-            }
-        } else {
-            //default size of a metafile picture is 200x200 
-            setAnchor(new java.awt.Rectangle(50, 50, 200, 200));
-        }
-    }
-
-    /**
-     * Returns the picture data for this picture.
-     *
-     * @return the picture data for this picture.
-     */
-    public PictureData getPictureData(){
-        SlideShow ppt = getSheet().getSlideShow();
-        PictureData[] pict = ppt.getPictureData();
-        Document doc = ppt.getDocumentRecord();
-        EscherContainerRecord dggContainer = doc.getPPDrawingGroup().getDggContainer();
-        EscherContainerRecord bstore = (EscherContainerRecord)Shape.getEscherChild(dggContainer, EscherContainerRecord.BSTORE_CONTAINER);
-
-        List lst = bstore.getChildRecords();
-        int idx = getPictureIndex()-1;
-        EscherBSERecord bse = (EscherBSERecord)lst.get(idx);
-        for ( int i = 0; i < pict.length; i++ ) {
-			if (pict[i].getOffset() ==  bse.getOffset()){
-                return pict[i];
-            }
-        }
-		System.err.println("Warning - no picture found for our BSE offset " + bse.getOffset());
-        return null;
-    }
-
-    /**
-     * By default set the orininal image size
-     */
-    protected void afterInsert(Sheet sh){
-        java.awt.Rectangle anchor = getAnchor();
-        if (anchor.equals(new java.awt.Rectangle())){
-            setDefaultSize();
-        }
-    }
-
-}
+package org.apache.poi.hslf.model;
+
+import org.apache.poi.ddf.*;
+import org.apache.poi.hslf.usermodel.PictureData;
+import org.apache.poi.hslf.usermodel.SlideShow;
+import org.apache.poi.hslf.record.Document;
+import org.apache.poi.hslf.blip.Bitmap;
+
+import javax.imageio.ImageIO;
+import java.awt.image.BufferedImage;
+import java.awt.*;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.util.List;
+import java.util.Arrays;
+
+
+/**
+ * Represents a picture in a PowerPoint document.
+ * <p>
+ * The information about an image in PowerPoint document is stored in
+ * two places:
+ *  <li> EscherBSE container in the Document keeps information about image
+ *    type, image index to refer by slides etc.
+ *  <li> "Pictures" OLE stream holds the actual data of the image.
+ * </p>
+ *
+ * @author Yegor Kozlov
+ */
+public class Picture extends SimpleShape {
+
+    /**
+    *  Windows Enhanced Metafile (EMF)
+    */
+    public static final int EMF = 2;
+
+    /**
+    *  Windows Metafile (WMF)
+    */
+    public static final int WMF = 3;
+
+    /**
+    * Macintosh PICT
+    */
+    public static final int PICT = 4;
+
+    /**
+    *  JPEG
+    */
+    public static final int JPEG = 5;
+
+    /**
+    *  PNG
+    */
+    public static final int PNG = 6;
+
+    /**
+     * Windows DIB (BMP)
+     */
+    public static final byte DIB = 7;
+    
+    /**
+     * Create a new <code>Picture</code>
+     *
+    * @param idx the index of the picture
+     */
+    public Picture(int idx){
+        super(null, null);
+        _escherContainer = createSpContainer(idx);
+    }
+
+    /**
+      * Create a <code>Picture</code> object
+      *
+      * @param escherRecord the <code>EscherSpContainer</code> record which holds information about
+      *        this picture in the <code>Slide</code>
+      * @param parent the parent shape of this picture
+      */
+     protected Picture(EscherContainerRecord escherRecord, Shape parent){
+        super(escherRecord, parent);
+    }
+
+    /**
+     * Returns index associated with this picture.
+     * Index starts with 1 and points to a EscherBSE record which
+     * holds information about this picture.
+     *
+     * @return the index to this picture (1 based).
+     */
+    public int getPictureIndex(){
+        EscherOptRecord opt = (EscherOptRecord)getEscherChild(_escherContainer, EscherOptRecord.RECORD_ID);
+        EscherSimpleProperty prop = (EscherSimpleProperty)getEscherProperty(opt, EscherProperties.BLIP__BLIPTODISPLAY + 0x4000);
+        return prop.getPropertyValue();
+    }
+
+    /**
+     * Create a new Picture and populate the inital structure of the <code>EscherSp</code> record which holds information about this picture.
+
+     * @param idx the index of the picture which referes to <code>EscherBSE</code> container.
+     * @return the create Picture object
+     */
+    protected EscherContainerRecord createSpContainer(int idx) {
+        EscherContainerRecord spContainer = super.createSpContainer(false);
+        spContainer.setOptions((short)15);
+
+        EscherSpRecord spRecord = spContainer.getChildById(EscherSpRecord.RECORD_ID);
+        spRecord.setOptions((short)((ShapeTypes.PictureFrame << 4) | 0x2));
+
+        //set default properties for a picture
+        EscherOptRecord opt = (EscherOptRecord)getEscherChild(spContainer, EscherOptRecord.RECORD_ID);
+        setEscherProperty(opt, EscherProperties.PROTECTION__LOCKAGAINSTGROUPING, 8388736);
+
+        //another weird feature of powerpoint: for picture id we must add 0x4000.
+        setEscherProperty(opt, (short)(EscherProperties.BLIP__BLIPTODISPLAY + 0x4000), idx);
+
+        return spContainer;
+    }
+
+    /**
+     * Resize this picture to the default size.
+     */
+    public void setDefaultSize(){
+        PictureData pict = getPictureData();
+        if (pict  instanceof Bitmap){
+            BufferedImage img = null;
+            try {
+               	img = ImageIO.read(new ByteArrayInputStream(pict.getData()));
+            } 
+            catch (IOException e){}
+        	catch (NegativeArraySizeException ne) {}
+        	
+            if(img != null) {
+            	// Valid image, set anchor from it
+            	setAnchor(new java.awt.Rectangle(0, 0, img.getWidth(), img.getHeight()));
+            } else {
+            	// Invalid image, go with the default metafile size
+            	setAnchor(new java.awt.Rectangle(0, 0, 200, 200));
+            }
+        } else {
+            //default size of a metafile picture is 200x200 
+            setAnchor(new java.awt.Rectangle(50, 50, 200, 200));
+        }
+    }
+
+    /**
+     * Returns the picture data for this picture.
+     *
+     * @return the picture data for this picture.
+     */
+    public PictureData getPictureData(){
+        SlideShow ppt = getSheet().getSlideShow();
+        PictureData[] pict = ppt.getPictureData();
+        Document doc = ppt.getDocumentRecord();
+        EscherContainerRecord dggContainer = doc.getPPDrawingGroup().getDggContainer();
+        EscherContainerRecord bstore = (EscherContainerRecord)Shape.getEscherChild(dggContainer, EscherContainerRecord.BSTORE_CONTAINER);
+
+        List lst = bstore.getChildRecords();
+        int idx = getPictureIndex()-1;
+        EscherBSERecord bse = (EscherBSERecord)lst.get(idx);
+        for ( int i = 0; i < pict.length; i++ ) {
+			if (pict[i].getOffset() ==  bse.getOffset()){
+                return pict[i];
+            }
+        }
+		System.err.println("Warning - no picture found for our BSE offset " + bse.getOffset());
+        return null;
+    }
+
+    /**
+     * By default set the orininal image size
+     */
+    protected void afterInsert(Sheet sh){
+        java.awt.Rectangle anchor = getAnchor();
+        if (anchor.equals(new java.awt.Rectangle())){
+            setDefaultSize();
+        }
+    }
+
+}

Modified: jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/Placeholder.java
URL: http://svn.apache.org/viewvc/jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/Placeholder.java?view=diff&rev=489760&r1=489759&r2=489760
==============================================================================
--- jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/Placeholder.java (original)
+++ jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/Placeholder.java Fri Dec 22 12:56:04 2006
@@ -1,97 +1,97 @@
-/* ====================================================================
-   Copyright 2002-2004   Apache Software Foundation
-
-   Licensed under the Apache License, Version 2.0 (the "License");
-   you may not use this file except in compliance with the License.
-   You may obtain a copy of the License at
-
-       http://www.apache.org/licenses/LICENSE-2.0
-
-   Unless required by applicable law or agreed to in writing, software
-   distributed under the License is distributed on an "AS IS" BASIS,
-   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-   See the License for the specific language governing permissions and
-   limitations under the License.
-==================================================================== */
-
-package org.apache.poi.hslf.model;
-
-import org.apache.poi.ddf.*;
-import org.apache.poi.hslf.record.OEPlaceholderAtom;
-
-import java.util.List;
-import java.io.ByteArrayOutputStream;
-
-/**
- * Represents a Placeholder in PowerPoint.
- *
- * @author Yegor Kozlov
- */
-public class Placeholder extends TextBox {
-
-    protected Placeholder(EscherContainerRecord escherRecord, Shape parent){
-        super(escherRecord, parent);
-    }
-
-    public Placeholder(Shape parent){
-        super(parent);
-    }
-
-    public Placeholder(){
-        super();
-    }
-
-    /**
-     * Create a new Placeholder and initialize internal structures
-     *
-     * @return the created <code>EscherContainerRecord</code> which holds shape data
-     */
-    protected EscherContainerRecord createSpContainer(boolean isChild){
-        EscherContainerRecord spcont = super.createSpContainer(isChild);
-
-        EscherSpRecord spRecord = spcont.getChildById(EscherSpRecord.RECORD_ID);
-        spRecord.setFlags(EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_HAVEMASTER);
-
-        EscherClientDataRecord cldata = new EscherClientDataRecord();
-        cldata.setOptions((short)15);
-
-        EscherOptRecord opt = (EscherOptRecord)getEscherChild(spcont, EscherOptRecord.RECORD_ID);
-
-        //Placeholders can't be grouped
-        setEscherProperty(opt, EscherProperties.PROTECTION__LOCKAGAINSTGROUPING, 262144);
-
-        //OEPlaceholderAtom tells powerpoint that this shape is a placeholder
-        //
-        OEPlaceholderAtom oep = new OEPlaceholderAtom();
-        /**
-         * Extarct from MSDN:
-         *
-         * There is a special case when the placeholder does not have a position in the layout.
-         * This occurs when the user has moved the placeholder from its original position.
-         * In this case the placeholder ID is -1.
-         */
-        oep.setPlacementId(-1);
-
-        oep.setPlaceholderId(OEPlaceholderAtom.Body);
-
-        //convert hslf into ddf record
-        ByteArrayOutputStream out = new ByteArrayOutputStream();
-        try {
-            oep.writeOut(out);
-        } catch(Exception e){
-            throw new RuntimeException(e);
-        }
-        cldata.setRemainingData(out.toByteArray());
-
-        //append placeholder container before EscherTextboxRecord
-        List lst = spcont.getChildRecords();
-        for (int i = 0; i < lst.size(); i++) {
-              EscherRecord rec = (EscherRecord)lst.get(i);
-              if(rec.getRecordId() == EscherTextboxRecord.RECORD_ID){
-                  lst.add(i++, cldata);
-              }
-        }
-
-        return spcont;
-    }
-}
+/* ====================================================================
+   Copyright 2002-2004   Apache Software Foundation
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hslf.model;
+
+import org.apache.poi.ddf.*;
+import org.apache.poi.hslf.record.OEPlaceholderAtom;
+
+import java.util.List;
+import java.io.ByteArrayOutputStream;
+
+/**
+ * Represents a Placeholder in PowerPoint.
+ *
+ * @author Yegor Kozlov
+ */
+public class Placeholder extends TextBox {
+
+    protected Placeholder(EscherContainerRecord escherRecord, Shape parent){
+        super(escherRecord, parent);
+    }
+
+    public Placeholder(Shape parent){
+        super(parent);
+    }
+
+    public Placeholder(){
+        super();
+    }
+
+    /**
+     * Create a new Placeholder and initialize internal structures
+     *
+     * @return the created <code>EscherContainerRecord</code> which holds shape data
+     */
+    protected EscherContainerRecord createSpContainer(boolean isChild){
+        EscherContainerRecord spcont = super.createSpContainer(isChild);
+
+        EscherSpRecord spRecord = spcont.getChildById(EscherSpRecord.RECORD_ID);
+        spRecord.setFlags(EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_HAVEMASTER);
+
+        EscherClientDataRecord cldata = new EscherClientDataRecord();
+        cldata.setOptions((short)15);
+
+        EscherOptRecord opt = (EscherOptRecord)getEscherChild(spcont, EscherOptRecord.RECORD_ID);
+
+        //Placeholders can't be grouped
+        setEscherProperty(opt, EscherProperties.PROTECTION__LOCKAGAINSTGROUPING, 262144);
+
+        //OEPlaceholderAtom tells powerpoint that this shape is a placeholder
+        //
+        OEPlaceholderAtom oep = new OEPlaceholderAtom();
+        /**
+         * Extarct from MSDN:
+         *
+         * There is a special case when the placeholder does not have a position in the layout.
+         * This occurs when the user has moved the placeholder from its original position.
+         * In this case the placeholder ID is -1.
+         */
+        oep.setPlacementId(-1);
+
+        oep.setPlaceholderId(OEPlaceholderAtom.Body);
+
+        //convert hslf into ddf record
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        try {
+            oep.writeOut(out);
+        } catch(Exception e){
+            throw new RuntimeException(e);
+        }
+        cldata.setRemainingData(out.toByteArray());
+
+        //append placeholder container before EscherTextboxRecord
+        List lst = spcont.getChildRecords();
+        for (int i = 0; i < lst.size(); i++) {
+              EscherRecord rec = (EscherRecord)lst.get(i);
+              if(rec.getRecordId() == EscherTextboxRecord.RECORD_ID){
+                  lst.add(i++, cldata);
+              }
+        }
+
+        return spcont;
+    }
+}

Modified: jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/Shape.java
URL: http://svn.apache.org/viewvc/jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/Shape.java?view=diff&rev=489760&r1=489759&r2=489760
==============================================================================
--- jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/Shape.java (original)
+++ jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/Shape.java Fri Dec 22 12:56:04 2006
@@ -1,307 +1,307 @@
-/* ====================================================================
-   Copyright 2002-2004   Apache Software Foundation
-
-   Licensed under the Apache License, Version 2.0 (the "License");
-   you may not use this file except in compliance with the License.
-   You may obtain a copy of the License at
-
-       http://www.apache.org/licenses/LICENSE-2.0
-
-   Unless required by applicable law or agreed to in writing, software
-   distributed under the License is distributed on an "AS IS" BASIS,
-   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-   See the License for the specific language governing permissions and
-   limitations under the License.
-==================================================================== */
-package org.apache.poi.hslf.model;
-
-import org.apache.poi.ddf.*;
-import org.apache.poi.hslf.model.ShapeTypes;
-import org.apache.poi.hslf.record.ColorSchemeAtom;
-
-import java.util.Iterator;
-import java.awt.*;
-
-/**
- *  <p>
-  * Represents a Shape which is the elemental object that composes a drawing.
- *  This class is a wrapper around EscherSpContainer which holds all information
- *  about a shape in PowerPoint document.
- *  </p>
- *  <p>
- *  When you add a shape, you usually specify the dimensions of the shape and the position
- *  of the upper�left corner of the bounding box for the shape relative to the upper�left
- *  corner of the page, worksheet, or slide. Distances in the drawing layer are measured
- *  in points (72 points = 1 inch).
- *  </p>
- * <p>
-  *
-  * @author Yegor Kozlov
- */
-public abstract class Shape {
-
-    /**
-     * In Escher absolute distances are specified in
-     * English Metric Units (EMUs), occasionally referred to as A units;
-     * there are 360000 EMUs per centimeter, 914400 EMUs per inch, 12700 EMUs per point.
-     */
-    public static final int EMU_PER_INCH = 914400;
-    public static final int EMU_PER_POINT = 12700;
-    public static final int EMU_PER_CENTIMETER = 360000;
-
-    /**
-     * Master DPI (576 pixels per inch).
-     * Used by the reference coordinate system in PowerPoint.
-     */
-    public static final int MASTER_DPI = 576;
-
-    /**
-     * Pixels DPI (96 pixels per inch)
-     */
-    public static final int PIXEL_DPI = 96;
-
-    /**
-     * Points DPI (72 pixels per inch)
-     */
-    public static final int POINT_DPI = 72;
-
-    /**
-     * Either EscherSpContainer or EscheSpgrContainer record
-     * which holds information about this shape.
-     */
-    protected EscherContainerRecord _escherContainer;
-
-    /**
-     * Parent of this shape.
-     * <code>null</code> for the topmost shapes.
-     */
-    protected Shape _parent;
-
-    /**
-     * The <code>Sheet</code> this shape belongs to
-     */
-    protected Sheet _sheet;
-
-    /**
-     * Create a Shape object. This constructor is used when an existing Shape is read from from a PowerPoint document.
-     *
-     * @param escherRecord       <code>EscherSpContainer</code> container which holds information about this shape
-     * @param parent             the parent of this Shape
-     */
-      protected Shape(EscherContainerRecord escherRecord, Shape parent){
-        _escherContainer = escherRecord;
-        _parent = parent;
-     }
-
-    /**
-     * Creates the lowerlevel escher records for this shape.
-     */
-    protected abstract EscherContainerRecord createSpContainer(boolean isChild);
-
-    /**
-     *  @return the parent of this shape
-     */
-    public Shape getParent(){
-        return _parent;
-    }
-
-    /**
-     * @return name of the shape.
-     */
-    public String getShapeName(){
-        EscherSpRecord spRecord = _escherContainer.getChildById(EscherSpRecord.RECORD_ID);
-        return ShapeTypes.typeName(spRecord.getOptions() >> 4);
-    }
-
-    /**
-     * @return type of the shape.
-     * @see org.apache.poi.hslf.record.RecordTypes
-     */
-    public int getShapeType(){
-        EscherSpRecord spRecord = _escherContainer.getChildById(EscherSpRecord.RECORD_ID);
-        return spRecord.getOptions() >> 4;
-    }
-
-    /**
-     * @param type type of the shape.
-     * @see org.apache.poi.hslf.record.RecordTypes
-     */
-    public void setShapeType(int type){
-        EscherSpRecord spRecord = _escherContainer.getChildById(EscherSpRecord.RECORD_ID);
-        spRecord.setOptions((short)(type << 4 | 0x2));
-    }
-
-    /**
-     * Returns the anchor (the bounding box rectangle) of this shape.
-     * All coordinates are expressed in points (72 dpi).
-     *
-     * @return the anchor of this shape
-     */
-    public java.awt.Rectangle getAnchor(){
-        EscherSpRecord spRecord = _escherContainer.getChildById(EscherSpRecord.RECORD_ID);
-        int flags = spRecord.getFlags();
-        java.awt.Rectangle anchor=null;
-        if ((flags & EscherSpRecord.FLAG_CHILD) != 0){
-            EscherChildAnchorRecord rec = (EscherChildAnchorRecord)getEscherChild(_escherContainer, EscherChildAnchorRecord.RECORD_ID);
-            anchor = new java.awt.Rectangle();
-            anchor.x = rec.getDx1()*POINT_DPI/MASTER_DPI;
-            anchor.y = rec.getDy1()*POINT_DPI/MASTER_DPI;
-            anchor.width = (rec.getDx2() - anchor.x)*POINT_DPI/MASTER_DPI;
-            anchor.height = (rec.getDy2() - anchor.y)*POINT_DPI/MASTER_DPI;
-        }
-        else {
-            EscherClientAnchorRecord rec = (EscherClientAnchorRecord)getEscherChild(_escherContainer, EscherClientAnchorRecord.RECORD_ID);
-            anchor = new java.awt.Rectangle();
-            anchor.y = rec.getFlag()*POINT_DPI/MASTER_DPI;
-            anchor.x = rec.getCol1()*POINT_DPI/MASTER_DPI;
-            anchor.width = (rec.getDx1() - rec.getCol1())*POINT_DPI/MASTER_DPI;
-            anchor.height = (rec.getRow1() - rec.getFlag())*POINT_DPI/MASTER_DPI;
-        }
-        return anchor;
-    }
-
-    /**
-     * Sets the anchor (the bounding box rectangle) of this shape.
-     * All coordinates should be expressed in points (72 dpi).
-     *
-     * @param anchor new anchor
-     */
-    public void setAnchor(java.awt.Rectangle anchor){
-        EscherSpRecord spRecord = _escherContainer.getChildById(EscherSpRecord.RECORD_ID);
-        int flags = spRecord.getFlags();
-        if ((flags & EscherSpRecord.FLAG_CHILD) != 0){
-            EscherChildAnchorRecord rec = (EscherChildAnchorRecord)getEscherChild(_escherContainer, EscherChildAnchorRecord.RECORD_ID);
-            rec.setDx1(anchor.x*MASTER_DPI/POINT_DPI);
-            rec.setDy1(anchor.y*MASTER_DPI/POINT_DPI);
-            rec.setDx2((anchor.width + anchor.x)*MASTER_DPI/POINT_DPI);
-            rec.setDy2((anchor.height + anchor.y)*MASTER_DPI/POINT_DPI);
-        }
-        else {
-            EscherClientAnchorRecord rec = (EscherClientAnchorRecord)getEscherChild(_escherContainer, EscherClientAnchorRecord.RECORD_ID);
-            rec.setFlag((short)(anchor.y*MASTER_DPI/POINT_DPI));
-            rec.setCol1((short)(anchor.x*MASTER_DPI/POINT_DPI));
-            rec.setDx1((short)((anchor.width + anchor.x)*MASTER_DPI/POINT_DPI));
-            rec.setRow1((short)((anchor.height + anchor.y)*MASTER_DPI/POINT_DPI));
-        }
-
-    }
-
-    /**
-     * Moves the top left corner of the shape to the specified point.
-     *
-     * @param x the x coordinate of the top left corner of the shape
-     * @param y the y coordinate of the top left corner of the shape
-     */
-    public void moveTo(int x, int y){
-        java.awt.Rectangle anchor = getAnchor();
-        anchor.setLocation(x, y);
-        setAnchor(anchor);
-    }
-
-    /**
-     * Helper method to return escher child by record ID
-     *
-     * @return escher record or <code>null</code> if not found.
-     */
-    public static EscherRecord getEscherChild(EscherContainerRecord owner, int recordId){
-        for ( Iterator iterator = owner.getChildRecords().iterator(); iterator.hasNext(); )
-        {
-            EscherRecord escherRecord = (EscherRecord) iterator.next();
-            if (escherRecord.getRecordId() == recordId)
-                return escherRecord;
-        }
-        return null;
-    }
-
-    /**
-     * Returns  escher property by id.
-     *
-     * @return escher property or <code>null</code> if not found.
-     */
-     public static EscherProperty getEscherProperty(EscherOptRecord opt, int propId){
-        for ( Iterator iterator = opt.getEscherProperties().iterator(); iterator.hasNext(); )
-        {
-            EscherProperty prop = (EscherProperty) iterator.next();
-            if (prop.getId() == propId)
-                return prop;
-        }
-        return null;
-    }
-
-    /**
-     * Set an escher property for this shape.
-     *
-     * @param opt       The opt record to set the properties to.
-     * @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){
-        java.util.List props = opt.getEscherProperties();
-        for ( Iterator iterator = props.iterator(); iterator.hasNext(); ) {
-            EscherProperty prop = (EscherProperty) iterator.next();
-            if (prop.getId() == propId){
-                iterator.remove();
-            }
-        }
-        if (value != -1) {
-            opt.addEscherProperty(new EscherSimpleProperty(propId, value));
-            opt.sortProperties();
-        }
-    }
-
-    /**
-     * @return  The shape container and it's children that can represent this
-     *          shape.
-     */
-    public EscherContainerRecord getSpContainer(){
-        return _escherContainer;
-    }
-
-    /**
-     * Event which fires when a shape is inserted in the sheet.
-     * In some cases we need to propagate changes to upper level containers.
-     * <br>
-     * Default implementation does nothing.
-     *
-     * @param sh - owning shape
-     */
-    protected void afterInsert(Sheet sh){
-
-    }
-
-    /**
-     *  @return the <code>SlideShow</code> this shape belongs to
-     */
-    public Sheet getSheet(){
-        return _sheet;
-    }
-
-    /**
-     * Assign the <code>SlideShow</code> this shape belongs to
-     *
-     * @param sheet owner of this shape
-     */
-    public void setSheet(Sheet sheet){
-        _sheet = sheet;
-    }
-
-    protected Color getColor(int rgb){
-        if (rgb >= 0x8000000) {
-            int idx = rgb - 0x8000000;
-            ColorSchemeAtom ca = getSheet().getColorScheme();
-            if(idx >= 0 && idx <= 7) rgb = ca.getColor(idx);
-        }
-        Color tmp = new Color(rgb, true);
-        return new Color(tmp.getBlue(), tmp.getGreen(), tmp.getRed());
-    }
-
-    /**
-     * Fill properties of this shape
-     *
-     * @return fill properties of this shape
-     */
-    public Fill getFill(){
-        return new Fill(this);
-    }
-
-}
+/* ====================================================================
+   Copyright 2002-2004   Apache Software Foundation
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+package org.apache.poi.hslf.model;
+
+import org.apache.poi.ddf.*;
+import org.apache.poi.hslf.model.ShapeTypes;
+import org.apache.poi.hslf.record.ColorSchemeAtom;
+
+import java.util.Iterator;
+import java.awt.*;
+
+/**
+ *  <p>
+  * Represents a Shape which is the elemental object that composes a drawing.
+ *  This class is a wrapper around EscherSpContainer which holds all information
+ *  about a shape in PowerPoint document.
+ *  </p>
+ *  <p>
+ *  When you add a shape, you usually specify the dimensions of the shape and the position
+ *  of the upper�left corner of the bounding box for the shape relative to the upper�left
+ *  corner of the page, worksheet, or slide. Distances in the drawing layer are measured
+ *  in points (72 points = 1 inch).
+ *  </p>
+ * <p>
+  *
+  * @author Yegor Kozlov
+ */
+public abstract class Shape {
+
+    /**
+     * In Escher absolute distances are specified in
+     * English Metric Units (EMUs), occasionally referred to as A units;
+     * there are 360000 EMUs per centimeter, 914400 EMUs per inch, 12700 EMUs per point.
+     */
+    public static final int EMU_PER_INCH = 914400;
+    public static final int EMU_PER_POINT = 12700;
+    public static final int EMU_PER_CENTIMETER = 360000;
+
+    /**
+     * Master DPI (576 pixels per inch).
+     * Used by the reference coordinate system in PowerPoint.
+     */
+    public static final int MASTER_DPI = 576;
+
+    /**
+     * Pixels DPI (96 pixels per inch)
+     */
+    public static final int PIXEL_DPI = 96;
+
+    /**
+     * Points DPI (72 pixels per inch)
+     */
+    public static final int POINT_DPI = 72;
+
+    /**
+     * Either EscherSpContainer or EscheSpgrContainer record
+     * which holds information about this shape.
+     */
+    protected EscherContainerRecord _escherContainer;
+
+    /**
+     * Parent of this shape.
+     * <code>null</code> for the topmost shapes.
+     */
+    protected Shape _parent;
+
+    /**
+     * The <code>Sheet</code> this shape belongs to
+     */
+    protected Sheet _sheet;
+
+    /**
+     * Create a Shape object. This constructor is used when an existing Shape is read from from a PowerPoint document.
+     *
+     * @param escherRecord       <code>EscherSpContainer</code> container which holds information about this shape
+     * @param parent             the parent of this Shape
+     */
+      protected Shape(EscherContainerRecord escherRecord, Shape parent){
+        _escherContainer = escherRecord;
+        _parent = parent;
+     }
+
+    /**
+     * Creates the lowerlevel escher records for this shape.
+     */
+    protected abstract EscherContainerRecord createSpContainer(boolean isChild);
+
+    /**
+     *  @return the parent of this shape
+     */
+    public Shape getParent(){
+        return _parent;
+    }
+
+    /**
+     * @return name of the shape.
+     */
+    public String getShapeName(){
+        EscherSpRecord spRecord = _escherContainer.getChildById(EscherSpRecord.RECORD_ID);
+        return ShapeTypes.typeName(spRecord.getOptions() >> 4);
+    }
+
+    /**
+     * @return type of the shape.
+     * @see org.apache.poi.hslf.record.RecordTypes
+     */
+    public int getShapeType(){
+        EscherSpRecord spRecord = _escherContainer.getChildById(EscherSpRecord.RECORD_ID);
+        return spRecord.getOptions() >> 4;
+    }
+
+    /**
+     * @param type type of the shape.
+     * @see org.apache.poi.hslf.record.RecordTypes
+     */
+    public void setShapeType(int type){
+        EscherSpRecord spRecord = _escherContainer.getChildById(EscherSpRecord.RECORD_ID);
+        spRecord.setOptions((short)(type << 4 | 0x2));
+    }
+
+    /**
+     * Returns the anchor (the bounding box rectangle) of this shape.
+     * All coordinates are expressed in points (72 dpi).
+     *
+     * @return the anchor of this shape
+     */
+    public java.awt.Rectangle getAnchor(){
+        EscherSpRecord spRecord = _escherContainer.getChildById(EscherSpRecord.RECORD_ID);
+        int flags = spRecord.getFlags();
+        java.awt.Rectangle anchor=null;
+        if ((flags & EscherSpRecord.FLAG_CHILD) != 0){
+            EscherChildAnchorRecord rec = (EscherChildAnchorRecord)getEscherChild(_escherContainer, EscherChildAnchorRecord.RECORD_ID);
+            anchor = new java.awt.Rectangle();
+            anchor.x = rec.getDx1()*POINT_DPI/MASTER_DPI;
+            anchor.y = rec.getDy1()*POINT_DPI/MASTER_DPI;
+            anchor.width = (rec.getDx2() - anchor.x)*POINT_DPI/MASTER_DPI;
+            anchor.height = (rec.getDy2() - anchor.y)*POINT_DPI/MASTER_DPI;
+        }
+        else {
+            EscherClientAnchorRecord rec = (EscherClientAnchorRecord)getEscherChild(_escherContainer, EscherClientAnchorRecord.RECORD_ID);
+            anchor = new java.awt.Rectangle();
+            anchor.y = rec.getFlag()*POINT_DPI/MASTER_DPI;
+            anchor.x = rec.getCol1()*POINT_DPI/MASTER_DPI;
+            anchor.width = (rec.getDx1() - rec.getCol1())*POINT_DPI/MASTER_DPI;
+            anchor.height = (rec.getRow1() - rec.getFlag())*POINT_DPI/MASTER_DPI;
+        }
+        return anchor;
+    }
+
+    /**
+     * Sets the anchor (the bounding box rectangle) of this shape.
+     * All coordinates should be expressed in points (72 dpi).
+     *
+     * @param anchor new anchor
+     */
+    public void setAnchor(java.awt.Rectangle anchor){
+        EscherSpRecord spRecord = _escherContainer.getChildById(EscherSpRecord.RECORD_ID);
+        int flags = spRecord.getFlags();
+        if ((flags & EscherSpRecord.FLAG_CHILD) != 0){
+            EscherChildAnchorRecord rec = (EscherChildAnchorRecord)getEscherChild(_escherContainer, EscherChildAnchorRecord.RECORD_ID);
+            rec.setDx1(anchor.x*MASTER_DPI/POINT_DPI);
+            rec.setDy1(anchor.y*MASTER_DPI/POINT_DPI);
+            rec.setDx2((anchor.width + anchor.x)*MASTER_DPI/POINT_DPI);
+            rec.setDy2((anchor.height + anchor.y)*MASTER_DPI/POINT_DPI);
+        }
+        else {
+            EscherClientAnchorRecord rec = (EscherClientAnchorRecord)getEscherChild(_escherContainer, EscherClientAnchorRecord.RECORD_ID);
+            rec.setFlag((short)(anchor.y*MASTER_DPI/POINT_DPI));
+            rec.setCol1((short)(anchor.x*MASTER_DPI/POINT_DPI));
+            rec.setDx1((short)((anchor.width + anchor.x)*MASTER_DPI/POINT_DPI));
+            rec.setRow1((short)((anchor.height + anchor.y)*MASTER_DPI/POINT_DPI));
+        }
+
+    }
+
+    /**
+     * Moves the top left corner of the shape to the specified point.
+     *
+     * @param x the x coordinate of the top left corner of the shape
+     * @param y the y coordinate of the top left corner of the shape
+     */
+    public void moveTo(int x, int y){
+        java.awt.Rectangle anchor = getAnchor();
+        anchor.setLocation(x, y);
+        setAnchor(anchor);
+    }
+
+    /**
+     * Helper method to return escher child by record ID
+     *
+     * @return escher record or <code>null</code> if not found.
+     */
+    public static EscherRecord getEscherChild(EscherContainerRecord owner, int recordId){
+        for ( Iterator iterator = owner.getChildRecords().iterator(); iterator.hasNext(); )
+        {
+            EscherRecord escherRecord = (EscherRecord) iterator.next();
+            if (escherRecord.getRecordId() == recordId)
+                return escherRecord;
+        }
+        return null;
+    }
+
+    /**
+     * Returns  escher property by id.
+     *
+     * @return escher property or <code>null</code> if not found.
+     */
+     public static EscherProperty getEscherProperty(EscherOptRecord opt, int propId){
+        for ( Iterator iterator = opt.getEscherProperties().iterator(); iterator.hasNext(); )
+        {
+            EscherProperty prop = (EscherProperty) iterator.next();
+            if (prop.getId() == propId)
+                return prop;
+        }
+        return null;
+    }
+
+    /**
+     * Set an escher property for this shape.
+     *
+     * @param opt       The opt record to set the properties to.
+     * @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){
+        java.util.List props = opt.getEscherProperties();
+        for ( Iterator iterator = props.iterator(); iterator.hasNext(); ) {
+            EscherProperty prop = (EscherProperty) iterator.next();
+            if (prop.getId() == propId){
+                iterator.remove();
+            }
+        }
+        if (value != -1) {
+            opt.addEscherProperty(new EscherSimpleProperty(propId, value));
+            opt.sortProperties();
+        }
+    }
+
+    /**
+     * @return  The shape container and it's children that can represent this
+     *          shape.
+     */
+    public EscherContainerRecord getSpContainer(){
+        return _escherContainer;
+    }
+
+    /**
+     * Event which fires when a shape is inserted in the sheet.
+     * In some cases we need to propagate changes to upper level containers.
+     * <br>
+     * Default implementation does nothing.
+     *
+     * @param sh - owning shape
+     */
+    protected void afterInsert(Sheet sh){
+
+    }
+
+    /**
+     *  @return the <code>SlideShow</code> this shape belongs to
+     */
+    public Sheet getSheet(){
+        return _sheet;
+    }
+
+    /**
+     * Assign the <code>SlideShow</code> this shape belongs to
+     *
+     * @param sheet owner of this shape
+     */
+    public void setSheet(Sheet sheet){
+        _sheet = sheet;
+    }
+
+    protected Color getColor(int rgb){
+        if (rgb >= 0x8000000) {
+            int idx = rgb - 0x8000000;
+            ColorSchemeAtom ca = getSheet().getColorScheme();
+            if(idx >= 0 && idx <= 7) rgb = ca.getColor(idx);
+        }
+        Color tmp = new Color(rgb, true);
+        return new Color(tmp.getBlue(), tmp.getGreen(), tmp.getRed());
+    }
+
+    /**
+     * Fill properties of this shape
+     *
+     * @return fill properties of this shape
+     */
+    public Fill getFill(){
+        return new Fill(this);
+    }
+
+}

Modified: jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/ShapeFactory.java
URL: http://svn.apache.org/viewvc/jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/ShapeFactory.java?view=diff&rev=489760&r1=489759&r2=489760
==============================================================================
--- jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/ShapeFactory.java (original)
+++ jakarta/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/model/ShapeFactory.java Fri Dec 22 12:56:04 2006
@@ -1,69 +1,69 @@
-/* ====================================================================
-   Copyright 2002-2004   Apache Software Foundation
-
-   Licensed under the Apache License, Version 2.0 (the "License");
-   you may not use this file except in compliance with the License.
-   You may obtain a copy of the License at
-
-       http://www.apache.org/licenses/LICENSE-2.0
-
-   Unless required by applicable law or agreed to in writing, software
-   distributed under the License is distributed on an "AS IS" BASIS,
-   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-   See the License for the specific language governing permissions and
-   limitations under the License.
-==================================================================== */
-package org.apache.poi.hslf.model;
-
-import org.apache.poi.ddf.*;
-
-/**
- * Create a <code>Shape</code> object depending on its type
- *
- * @author Yegor Kozlov
- */
-public class ShapeFactory {
-
-    /**
-     * Create a new shape from the data provided.  
-     */
-    public static Shape createShape(EscherContainerRecord spContainer, Shape parent){
-        if (spContainer.getRecordId() == EscherContainerRecord.SPGR_CONTAINER){
-            return new ShapeGroup(spContainer, parent);
-        }
-
-        Shape shape;
-        EscherSpRecord spRecord = spContainer.getChildById(EscherSpRecord.RECORD_ID);
-
-        int type = spRecord.getOptions() >> 4;
-        switch (type){
-            case ShapeTypes.TextBox:
-                shape = new TextBox(spContainer, parent);
-                break;
-            case ShapeTypes.Rectangle:
-                EscherTextboxRecord txtbox = (EscherTextboxRecord)Shape.getEscherChild(spContainer, EscherTextboxRecord.RECORD_ID);
-                if (txtbox == null)
-                    shape = new AutoShape(spContainer, parent);
-                else
-                    shape = new TextBox(spContainer, parent);
-                break;
-            case ShapeTypes.PictureFrame:
-                shape = new Picture(spContainer, parent);
-                break;
-            case ShapeTypes.Line:
-                shape = new Line(spContainer, parent);
-                break;
-            case ShapeTypes.NotPrimitive:
-                if ((spRecord.getFlags() & EscherSpRecord.FLAG_GROUP) != 0)
-                     shape = new ShapeGroup(spContainer, parent);
-                else
-                    shape = new AutoShape(spContainer, parent);
-                break;
-            default:
-                shape = new AutoShape(spContainer, parent);
-                break;
-        }
-        return shape;
-    }
-
-}
+/* ====================================================================
+   Copyright 2002-2004   Apache Software Foundation
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+package org.apache.poi.hslf.model;
+
+import org.apache.poi.ddf.*;
+
+/**
+ * Create a <code>Shape</code> object depending on its type
+ *
+ * @author Yegor Kozlov
+ */
+public class ShapeFactory {
+
+    /**
+     * Create a new shape from the data provided.  
+     */
+    public static Shape createShape(EscherContainerRecord spContainer, Shape parent){
+        if (spContainer.getRecordId() == EscherContainerRecord.SPGR_CONTAINER){
+            return new ShapeGroup(spContainer, parent);
+        }
+
+        Shape shape;
+        EscherSpRecord spRecord = spContainer.getChildById(EscherSpRecord.RECORD_ID);
+
+        int type = spRecord.getOptions() >> 4;
+        switch (type){
+            case ShapeTypes.TextBox:
+                shape = new TextBox(spContainer, parent);
+                break;
+            case ShapeTypes.Rectangle:
+                EscherTextboxRecord txtbox = (EscherTextboxRecord)Shape.getEscherChild(spContainer, EscherTextboxRecord.RECORD_ID);
+                if (txtbox == null)
+                    shape = new AutoShape(spContainer, parent);
+                else
+                    shape = new TextBox(spContainer, parent);
+                break;
+            case ShapeTypes.PictureFrame:
+                shape = new Picture(spContainer, parent);
+                break;
+            case ShapeTypes.Line:
+                shape = new Line(spContainer, parent);
+                break;
+            case ShapeTypes.NotPrimitive:
+                if ((spRecord.getFlags() & EscherSpRecord.FLAG_GROUP) != 0)
+                     shape = new ShapeGroup(spContainer, parent);
+                else
+                    shape = new AutoShape(spContainer, parent);
+                break;
+            default:
+                shape = new AutoShape(spContainer, parent);
+                break;
+        }
+        return shape;
+    }
+
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: poi-dev-unsubscribe@jakarta.apache.org
Mailing List:    http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta POI Project: http://jakarta.apache.org/poi/