View | Details | Raw Unified | Return to bug 60520
Collapse All | Expand All

(-)src/java/org/apache/poi/ss/usermodel/ShapeContainer.java (+28 lines)
Line 0 Link Here
1
/* ====================================================================
2
   Licensed to the Apache Software Foundation (ASF) under one or more
3
   contributor license agreements.  See the NOTICE file distributed with
4
   this work for additional information regarding copyright ownership.
5
   The ASF licenses this file to You under the Apache License, Version 2.0
6
   (the "License"); you may not use this file except in compliance with
7
   the License.  You may obtain a copy of the License at
8
9
       http://www.apache.org/licenses/LICENSE-2.0
10
11
   Unless required by applicable law or agreed to in writing, software
12
   distributed under the License is distributed on an "AS IS" BASIS,
13
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
   See the License for the specific language governing permissions and
15
   limitations under the License.
16
==================================================================== */
17
18
package org.apache.poi.ss.usermodel;
19
20
/**
21
 * A common interface for shape groups.
22
 * 
23
 * @since POI 3.16-beta2
24
 */
25
public interface ShapeContainer<T extends Shape> extends Iterable<T> {
26
27
}
28
native
(-)src/java/org/apache/poi/ss/usermodel/Drawing.java (-3 / +1 lines)
Lines 18-27 Link Here
18
18
19
/**
19
/**
20
 * High level representation of spreadsheet drawing.
20
 * High level representation of spreadsheet drawing.
21
 * @author Yegor Kozlov
22
 * @author Roman Kashitsyn
23
 */
21
 */
24
public interface Drawing {
22
public interface Drawing<T extends Shape> extends ShapeContainer<T> {
25
	/**
23
	/**
26
	 * Creates a picture.
24
	 * Creates a picture.
27
	 * @param anchor       the client anchor describes how this picture is
25
	 * @param anchor       the client anchor describes how this picture is
(-)src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFPicture.java (-7 / +35 lines)
Lines 20-25 Link Here
20
import org.apache.poi.openxml4j.opc.PackagePart;
20
import org.apache.poi.openxml4j.opc.PackagePart;
21
import org.apache.poi.ss.usermodel.Picture;
21
import org.apache.poi.ss.usermodel.Picture;
22
import org.apache.poi.ss.usermodel.Row;
22
import org.apache.poi.ss.usermodel.Row;
23
import org.apache.poi.ss.usermodel.Shape;
23
import org.apache.poi.ss.usermodel.Workbook;
24
import org.apache.poi.ss.usermodel.Workbook;
24
import org.apache.poi.ss.util.ImageUtils;
25
import org.apache.poi.ss.util.ImageUtils;
25
import org.apache.poi.util.Internal;
26
import org.apache.poi.util.Internal;
Lines 182-188 Link Here
182
    }
183
    }
183
184
184
    private float getColumnWidthInPixels(int columnIndex){
185
    private float getColumnWidthInPixels(int columnIndex){
185
        XSSFSheet sheet = getParent();
186
        XSSFSheet sheet = getSheet();
186
187
187
        CTCol col = sheet.getColumnHelper().getColumn(columnIndex, false);
188
        CTCol col = sheet.getColumnHelper().getColumn(columnIndex, false);
188
        double numChars = col == null || !col.isSetWidth() ? DEFAULT_COLUMN_WIDTH : col.getWidth();
189
        double numChars = col == null || !col.isSetWidth() ? DEFAULT_COLUMN_WIDTH : col.getWidth();
Lines 193-199 Link Here
193
    private float getRowHeightInPixels(int rowIndex) {
194
    private float getRowHeightInPixels(int rowIndex) {
194
        // THE FOLLOWING THREE LINES ARE THE MAIN CHANGE compared to the non-streaming version: use the SXSSF sheet,
195
        // THE FOLLOWING THREE LINES ARE THE MAIN CHANGE compared to the non-streaming version: use the SXSSF sheet,
195
		// not the XSSF sheet (which never contais rows when using SXSSF)
196
		// not the XSSF sheet (which never contais rows when using SXSSF)
196
        XSSFSheet xssfSheet = getParent();
197
        XSSFSheet xssfSheet = getSheet();
197
        SXSSFSheet sheet = _wb.getSXSSFSheet(xssfSheet);
198
        SXSSFSheet sheet = _wb.getSXSSFSheet(xssfSheet);
198
        Row row = sheet.getRow(rowIndex);
199
        Row row = sheet.getRow(rowIndex);
199
        float height = row != null ?  row.getHeightInPoints() : sheet.getDefaultRowHeightInPoints();
200
        float height = row != null ?  row.getHeightInPoints() : sheet.getDefaultRowHeightInPoints();
Lines 232-242 Link Here
232
        return getCTPicture().getSpPr();
233
        return getCTPicture().getSpPr();
233
    }
234
    }
234
235
235
    private XSSFSheet getParent() {
236
    @Override
236
        return (XSSFSheet)_picture.getDrawing().getParent();
237
    public XSSFAnchor getAnchor() {
237
    }
238
239
    private XSSFAnchor getAnchor() {
240
        return _picture.getAnchor();
238
        return _picture.getAnchor();
241
    }
239
    }
242
240
Lines 269-272 Link Here
269
    public XSSFSheet getSheet() {
267
    public XSSFSheet getSheet() {
270
        return _picture.getSheet();
268
        return _picture.getSheet();
271
    }
269
    }
270
271
    @Override
272
    public String getShapeName() {
273
        return _picture.getShapeName();
274
    }
275
276
    @Override
277
    public Shape getParent() {
278
        return _picture.getParent();
279
    }
280
281
    @Override
282
    public boolean isNoFill() {
283
        return _picture.isNoFill();
284
    }
285
286
    @Override
287
    public void setNoFill(boolean noFill) {
288
        _picture.setNoFill(noFill);
289
    }
290
291
    @Override
292
    public void setFillColor(int red, int green, int blue) {
293
        _picture.setFillColor(red, green, blue);
294
    }
295
    
296
    @Override
297
    public void setLineStyleColor( int red, int green, int blue ) {
298
        _picture.setLineStyleColor(red, green, blue);
299
    }
272
}
300
}
(-)src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFAnchor.java (-13 / +3 lines)
Lines 17-37 Link Here
17
17
18
package org.apache.poi.xssf.usermodel;
18
package org.apache.poi.xssf.usermodel;
19
19
20
import org.apache.poi.ss.usermodel.ChildAnchor;
21
20
/**
22
/**
21
 * An anchor is what specifics the position of a shape within a client object
23
 * An anchor is what specifics the position of a shape within a client object
22
 * or within another containing shape.
24
 * or within another containing shape.
23
 *
24
 * @author Yegor Kozlov
25
 */
25
 */
26
public abstract class XSSFAnchor {
26
public abstract class XSSFAnchor implements ChildAnchor {
27
28
    public abstract int getDx1();
29
    public abstract void setDx1( int dx1 );
30
    public abstract int getDy1();
31
    public abstract void setDy1( int dy1 );
32
    public abstract int getDy2();
33
    public abstract void setDy2( int dy2 );
34
    public abstract int getDx2();
35
    public abstract void setDx2( int dx2 );
36
37
}
27
}
(-)src/java/org/apache/poi/ss/usermodel/Shape.java (+65 lines)
Line 0 Link Here
1
/* ====================================================================
2
   Licensed to the Apache Software Foundation (ASF) under one or more
3
   contributor license agreements.  See the NOTICE file distributed with
4
   this work for additional information regarding copyright ownership.
5
   The ASF licenses this file to You under the Apache License, Version 2.0
6
   (the "License"); you may not use this file except in compliance with
7
   the License.  You may obtain a copy of the License at
8
9
       http://www.apache.org/licenses/LICENSE-2.0
10
11
   Unless required by applicable law or agreed to in writing, software
12
   distributed under the License is distributed on an "AS IS" BASIS,
13
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
   See the License for the specific language governing permissions and
15
   limitations under the License.
16
==================================================================== */
17
18
package org.apache.poi.ss.usermodel;
19
20
/**
21
 * Common interface for all drawing shapes
22
 * 
23
 * @since POI 3.16-beta2
24
 */
25
public interface Shape {
26
    /**
27
     * @return the name of this shape
28
     */
29
    String getShapeName();
30
    
31
    /**
32
     * @return the parent shape.
33
     */
34
    Shape getParent();
35
36
    /**
37
     * @return  the anchor that is used by this shape.
38
     */
39
    ChildAnchor getAnchor();
40
41
    /**
42
     * Whether this shape is not filled with a color
43
     *
44
     * @return true if this shape is not filled with a color.
45
     */
46
    boolean isNoFill();
47
48
    /**
49
     * Sets whether this shape is filled or transparent.
50
     *
51
     * @param noFill if true then no fill will be applied to the shape element.
52
     */
53
    void setNoFill(boolean noFill);
54
55
    /**
56
     * Sets the color used to fill this shape using the solid fill pattern.
57
     */
58
    void setFillColor(int red, int green, int blue);
59
60
    /**
61
     * The color applied to the lines of this shape.
62
     */
63
    void setLineStyleColor(int red, int green, int blue);
64
}
65
native
(-)src/java/org/apache/poi/hssf/usermodel/HSSFShape.java (-16 / +25 lines)
Lines 23-28 Link Here
23
import org.apache.poi.ddf.EscherBoolProperty;
23
import org.apache.poi.ddf.EscherBoolProperty;
24
import org.apache.poi.ddf.EscherChildAnchorRecord;
24
import org.apache.poi.ddf.EscherChildAnchorRecord;
25
import org.apache.poi.ddf.EscherClientAnchorRecord;
25
import org.apache.poi.ddf.EscherClientAnchorRecord;
26
import org.apache.poi.ddf.EscherComplexProperty;
26
import org.apache.poi.ddf.EscherContainerRecord;
27
import org.apache.poi.ddf.EscherContainerRecord;
27
import org.apache.poi.ddf.EscherOptRecord;
28
import org.apache.poi.ddf.EscherOptRecord;
28
import org.apache.poi.ddf.EscherProperties;
29
import org.apache.poi.ddf.EscherProperties;
Lines 32-40 Link Here
32
import org.apache.poi.ddf.EscherSpRecord;
33
import org.apache.poi.ddf.EscherSpRecord;
33
import org.apache.poi.hssf.record.CommonObjectDataSubRecord;
34
import org.apache.poi.hssf.record.CommonObjectDataSubRecord;
34
import org.apache.poi.hssf.record.ObjRecord;
35
import org.apache.poi.hssf.record.ObjRecord;
36
import org.apache.poi.ss.usermodel.Shape;
35
import org.apache.poi.util.LittleEndian;
37
import org.apache.poi.util.LittleEndian;
36
import org.apache.poi.util.POILogFactory;
38
import org.apache.poi.util.POILogFactory;
37
import org.apache.poi.util.POILogger;
39
import org.apache.poi.util.POILogger;
40
import org.apache.poi.util.StringUtil;
38
41
39
/**
42
/**
40
 * An abstract shape.
43
 * An abstract shape.
Lines 44-50 Link Here
44
 * reverse them and draw shapes vertically or horizontally flipped via
47
 * reverse them and draw shapes vertically or horizontally flipped via
45
 * setFlipVertical() or setFlipHorizontally(). 
48
 * setFlipVertical() or setFlipHorizontally(). 
46
 */
49
 */
47
public abstract class HSSFShape {
50
public abstract class HSSFShape implements Shape {
48
    private static final POILogger LOG = POILogFactory.getLogger(HSSFShape.class);
51
    private static final POILogger LOG = POILogFactory.getLogger(HSSFShape.class);
49
    
52
    
50
    public static final int LINEWIDTH_ONE_PT = 12700;
53
    public static final int LINEWIDTH_ONE_PT = 12700;
Lines 152-160 Link Here
152
        return _optRecord;
155
        return _optRecord;
153
    }
156
    }
154
157
155
    /**
158
    @Override
156
     * Gets the parent shape.
157
     */
158
    public HSSFShape getParent() {
159
    public HSSFShape getParent() {
159
        return parent;
160
        return parent;
160
    }
161
    }
Lines 162-167 Link Here
162
    /**
163
    /**
163
     * @return the anchor that is used by this shape.
164
     * @return the anchor that is used by this shape.
164
     */
165
     */
166
    @Override
165
    public HSSFAnchor getAnchor() {
167
    public HSSFAnchor getAnchor() {
166
        return anchor;
168
        return anchor;
167
    }
169
    }
Lines 231-239 Link Here
231
        setPropertyValue(new EscherRGBProperty(EscherProperties.LINESTYLE__COLOR, lineStyleColor));
233
        setPropertyValue(new EscherRGBProperty(EscherProperties.LINESTYLE__COLOR, lineStyleColor));
232
    }
234
    }
233
235
234
    /**
236
    @Override
235
     * The color applied to the lines of this shape.
236
     */
237
    public void setLineStyleColor(int red, int green, int blue) {
237
    public void setLineStyleColor(int red, int green, int blue) {
238
        int lineStyleColor = ((blue) << 16) | ((green) << 8) | red;
238
        int lineStyleColor = ((blue) << 16) | ((green) << 8) | red;
239
        setPropertyValue(new EscherRGBProperty(EscherProperties.LINESTYLE__COLOR, lineStyleColor));
239
        setPropertyValue(new EscherRGBProperty(EscherProperties.LINESTYLE__COLOR, lineStyleColor));
Lines 254-262 Link Here
254
        setPropertyValue(new EscherRGBProperty(EscherProperties.FILL__FILLCOLOR, fillColor));
254
        setPropertyValue(new EscherRGBProperty(EscherProperties.FILL__FILLCOLOR, fillColor));
255
    }
255
    }
256
256
257
    /**
257
    @Override
258
     * The color used to fill this shape.
259
     */
260
    public void setFillColor(int red, int green, int blue) {
258
    public void setFillColor(int red, int green, int blue) {
261
        int fillColor = ((blue) << 16) | ((green) << 8) | red;
259
        int fillColor = ((blue) << 16) | ((green) << 8) | red;
262
        setPropertyValue(new EscherRGBProperty(EscherProperties.FILL__FILLCOLOR, fillColor));
260
        setPropertyValue(new EscherRGBProperty(EscherProperties.FILL__FILLCOLOR, fillColor));
Lines 308-324 Link Here
308
        }
306
        }
309
    }
307
    }
310
308
311
    /**
309
    @Override
312
     * @return <code>true</code> if this shape is not filled with a color.
313
     */
314
    public boolean isNoFill() {
310
    public boolean isNoFill() {
315
        EscherBoolProperty property = _optRecord.lookup(EscherProperties.FILL__NOFILLHITTEST);
311
        EscherBoolProperty property = _optRecord.lookup(EscherProperties.FILL__NOFILLHITTEST);
316
        return property == null ? NO_FILL_DEFAULT : property.getPropertyValue() == NO_FILLHITTEST_TRUE;
312
        return property == null ? NO_FILL_DEFAULT : property.getPropertyValue() == NO_FILLHITTEST_TRUE;
317
    }
313
    }
318
314
319
    /**
315
    @Override
320
     * @param noFill sets whether this shape is filled or transparent.
321
     */
322
    public void setNoFill(boolean noFill) {
316
    public void setNoFill(boolean noFill) {
323
        setPropertyValue(new EscherBoolProperty(EscherProperties.FILL__NOFILLHITTEST, noFill ? NO_FILLHITTEST_TRUE : NO_FILLHITTEST_FALSE));
317
        setPropertyValue(new EscherBoolProperty(EscherProperties.FILL__NOFILLHITTEST, noFill ? NO_FILLHITTEST_TRUE : NO_FILLHITTEST_FALSE));
324
    }
318
    }
Lines 417-420 Link Here
417
    protected void setParent(HSSFShape parent) {
411
    protected void setParent(HSSFShape parent) {
418
        this.parent = parent;
412
        this.parent = parent;
419
    }
413
    }
414
415
    /**
416
     * @return the name of this shape
417
     */
418
    public String getShapeName() {
419
        EscherOptRecord eor = getOptRecord();
420
        if (eor == null) {
421
            return null;
422
        }
423
        EscherProperty ep = eor.lookup(EscherProperties.GROUPSHAPE__SHAPENAME);
424
        if (ep instanceof EscherComplexProperty) {
425
            return StringUtil.getFromUnicodeLE(((EscherComplexProperty)ep).getComplexData());
426
        }
427
        return null;
428
    }
420
}
429
}
(-)src/java/org/apache/poi/ss/usermodel/Picture.java (-3 / +1 lines)
Lines 21-30 Link Here
21
21
22
/**
22
/**
23
 * Repersents a picture in a SpreadsheetML document
23
 * Repersents a picture in a SpreadsheetML document
24
 *
25
 * @author Yegor Kozlov
26
 */
24
 */
27
public interface Picture {
25
public interface Picture extends Shape {
28
26
29
    /**
27
    /**
30
     * Reset the image to the dimension of the embedded image
28
     * Reset the image to the dimension of the embedded image
(-)src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFGraphicFrame.java (+5 lines)
Lines 187-190 Link Here
187
    protected CTShapeProperties getShapeProperties(){
187
    protected CTShapeProperties getShapeProperties(){
188
        return null;
188
        return null;
189
    }
189
    }
190
191
    @Override
192
    public String getShapeName() {
193
        return graphicFrame.getNvGraphicFramePr().getCNvPr().getName();
194
    }
190
}
195
}
(-)src/java/org/apache/poi/ss/usermodel/ChildAnchor.java (+69 lines)
Line 0 Link Here
1
/* ====================================================================
2
   Licensed to the Apache Software Foundation (ASF) under one or more
3
   contributor license agreements.  See the NOTICE file distributed with
4
   this work for additional information regarding copyright ownership.
5
   The ASF licenses this file to You under the Apache License, Version 2.0
6
   (the "License"); you may not use this file except in compliance with
7
   the License.  You may obtain a copy of the License at
8
9
       http://www.apache.org/licenses/LICENSE-2.0
10
11
   Unless required by applicable law or agreed to in writing, software
12
   distributed under the License is distributed on an "AS IS" BASIS,
13
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
   See the License for the specific language governing permissions and
15
   limitations under the License.
16
==================================================================== */
17
18
package org.apache.poi.ss.usermodel;
19
20
/**
21
 * Common interface for anchors.<p>
22
 * 
23
 * An anchor is what specifics the position of a shape within a client object
24
 * or within another containing shape.
25
 * 
26
 * @since POI 3.16-beta2
27
 */
28
public interface ChildAnchor {
29
    /**
30
     * @return x coordinate of the left up corner
31
     */
32
    int getDx1();
33
34
    /**
35
     * @param dx1 x coordinate of the left up corner
36
     */
37
    void setDx1(int dx1);
38
39
    /**
40
     * @return y coordinate of the left up corner
41
     */
42
    int getDy1();
43
44
    /**
45
     * @param dy1 y coordinate of the left up corner
46
     */
47
    void setDy1(int dy1);
48
49
    /**
50
     * @return y coordinate of the right down corner
51
     */
52
    int getDy2();
53
54
    /**
55
     * @param dy2 y coordinate of the right down corner
56
     */
57
    void setDy2(int dy2);
58
59
    /**
60
     * @return x coordinate of the right down corner
61
     */
62
    int getDx2();
63
64
    /**
65
     * @param dx2 x coordinate of the right down corner
66
     */
67
    void setDx2(int dx2);
68
}
69
native
(-)src/java/org/apache/poi/hssf/usermodel/HSSFAnchor.java (-41 / +2 lines)
Lines 22-33 Link Here
22
import org.apache.poi.ddf.EscherClientAnchorRecord;
22
import org.apache.poi.ddf.EscherClientAnchorRecord;
23
import org.apache.poi.ddf.EscherContainerRecord;
23
import org.apache.poi.ddf.EscherContainerRecord;
24
import org.apache.poi.ddf.EscherRecord;
24
import org.apache.poi.ddf.EscherRecord;
25
import org.apache.poi.ss.usermodel.ChildAnchor;
25
26
26
/**
27
/**
27
 * An anchor is what specifics the position of a shape within a client object
28
 * An anchor is what specifics the position of a shape within a client object
28
 * or within another containing shape.
29
 * or within another containing shape.
29
 */
30
 */
30
public abstract class HSSFAnchor {
31
public abstract class HSSFAnchor implements ChildAnchor {
31
32
32
    protected boolean _isHorizontallyFlipped = false;
33
    protected boolean _isHorizontallyFlipped = false;
33
    protected boolean _isVerticallyFlipped = false;
34
    protected boolean _isVerticallyFlipped = false;
Lines 56-101 Link Here
56
    }
57
    }
57
58
58
    /**
59
    /**
59
     * @return x coordinate of the left up corner
60
     */
61
    public abstract int getDx1();
62
63
    /**
64
     * @param dx1 x coordinate of the left up corner
65
     */
66
    public abstract void setDx1(int dx1);
67
68
    /**
69
     * @return y coordinate of the left up corner
70
     */
71
    public abstract int getDy1();
72
73
    /**
74
     * @param dy1 y coordinate of the left up corner
75
     */
76
    public abstract void setDy1(int dy1);
77
78
    /**
79
     * @return y coordinate of the right down corner
80
     */
81
    public abstract int getDy2();
82
83
    /**
84
     * @param dy2 y coordinate of the right down corner
85
     */
86
    public abstract void setDy2(int dy2);
87
88
    /**
89
     * @return x coordinate of the right down corner
90
     */
91
    public abstract int getDx2();
92
93
    /**
94
     * @param dx2 x coordinate of the right down corner
95
     */
96
    public abstract void setDx2(int dx2);
97
98
    /**
99
     * @return whether this shape is horizontally flipped
60
     * @return whether this shape is horizontally flipped
100
     */
61
     */
101
    public abstract boolean isHorizontallyFlipped();
62
    public abstract boolean isHorizontallyFlipped();
(-)src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFConnector.java (+4 lines)
Lines 134-137 Link Here
134
        return ctShape.getSpPr();
134
        return ctShape.getSpPr();
135
    }
135
    }
136
136
137
    @Override
138
    public String getShapeName() {
139
        return ctShape.getNvCxnSpPr().getCNvPr().getName();
140
    }
137
}
141
}
(-)src/java/org/apache/poi/hssf/usermodel/HSSFShapeGroup.java (+1 lines)
Lines 381-386 Link Here
381
        return isRemoved;
381
        return isRemoved;
382
    }
382
    }
383
383
384
    @Override
384
    public Iterator<HSSFShape> iterator() {
385
    public Iterator<HSSFShape> iterator() {
385
        return shapes.iterator();
386
        return shapes.iterator();
386
    }
387
    }
(-)src/java/org/apache/poi/hssf/usermodel/HSSFShapeContainer.java (-1 / +3 lines)
Lines 19-28 Link Here
19
19
20
import java.util.List;
20
import java.util.List;
21
21
22
import org.apache.poi.ss.usermodel.ShapeContainer;
23
22
/**
24
/**
23
 * An interface that indicates whether a class can contain children.
25
 * An interface that indicates whether a class can contain children.
24
 */
26
 */
25
public interface HSSFShapeContainer extends Iterable<HSSFShape>
27
public interface HSSFShapeContainer extends ShapeContainer<HSSFShape>
26
{
28
{
27
    /**
29
    /**
28
     * @return  Any children contained by this shape.
30
     * @return  Any children contained by this shape.
(-)src/java/org/apache/poi/hssf/usermodel/HSSFSimpleShape.java (-3 / +18 lines)
Lines 17-30 Link Here
17
17
18
package org.apache.poi.hssf.usermodel;
18
package org.apache.poi.hssf.usermodel;
19
19
20
import org.apache.poi.ddf.*;
20
import org.apache.poi.ddf.DefaultEscherRecordFactory;
21
import org.apache.poi.hssf.record.*;
21
import org.apache.poi.ddf.EscherBoolProperty;
22
import org.apache.poi.ddf.EscherClientDataRecord;
23
import org.apache.poi.ddf.EscherContainerRecord;
24
import org.apache.poi.ddf.EscherOptRecord;
25
import org.apache.poi.ddf.EscherProperties;
26
import org.apache.poi.ddf.EscherRGBProperty;
27
import org.apache.poi.ddf.EscherShapePathProperty;
28
import org.apache.poi.ddf.EscherSimpleProperty;
29
import org.apache.poi.ddf.EscherSpRecord;
30
import org.apache.poi.ddf.EscherTextboxRecord;
31
import org.apache.poi.hssf.record.CommonObjectDataSubRecord;
32
import org.apache.poi.hssf.record.EndSubRecord;
33
import org.apache.poi.hssf.record.EscherAggregate;
34
import org.apache.poi.hssf.record.ObjRecord;
35
import org.apache.poi.hssf.record.TextObjectRecord;
22
import org.apache.poi.ss.usermodel.RichTextString;
36
import org.apache.poi.ss.usermodel.RichTextString;
37
import org.apache.poi.ss.usermodel.SimpleShape;
23
38
24
/**
39
/**
25
 * Represents a simple shape such as a line, rectangle or oval.
40
 * Represents a simple shape such as a line, rectangle or oval.
26
 */
41
 */
27
public class HSSFSimpleShape extends HSSFShape
42
public class HSSFSimpleShape extends HSSFShape implements SimpleShape
28
{
43
{
29
    // The commented out ones haven't been tested yet or aren't supported
44
    // The commented out ones haven't been tested yet or aren't supported
30
    // by HSSFSimpleShape.
45
    // by HSSFSimpleShape.
(-)src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFDrawing.java (-1 / +9 lines)
Lines 17-22 Link Here
17
17
18
package org.apache.poi.xssf.streaming;
18
package org.apache.poi.xssf.streaming;
19
19
20
import java.util.Iterator;
21
20
import org.apache.poi.ss.usermodel.Chart;
22
import org.apache.poi.ss.usermodel.Chart;
21
import org.apache.poi.ss.usermodel.ClientAnchor;
23
import org.apache.poi.ss.usermodel.ClientAnchor;
22
import org.apache.poi.ss.usermodel.Comment;
24
import org.apache.poi.ss.usermodel.Comment;
Lines 23-28 Link Here
23
import org.apache.poi.ss.usermodel.Drawing;
25
import org.apache.poi.ss.usermodel.Drawing;
24
import org.apache.poi.xssf.usermodel.XSSFDrawing;
26
import org.apache.poi.xssf.usermodel.XSSFDrawing;
25
import org.apache.poi.xssf.usermodel.XSSFPicture;
27
import org.apache.poi.xssf.usermodel.XSSFPicture;
28
import org.apache.poi.xssf.usermodel.XSSFShape;
26
29
27
/**
30
/**
28
 * Streaming version of Drawing.
31
 * Streaming version of Drawing.
Lines 29-35 Link Here
29
 * Delegates most tasks to the non-streaming XSSF code.
32
 * Delegates most tasks to the non-streaming XSSF code.
30
 * TODO: Potentially, Comment and Chart need a similar streaming wrapper like Picture.
33
 * TODO: Potentially, Comment and Chart need a similar streaming wrapper like Picture.
31
 */
34
 */
32
public class SXSSFDrawing implements Drawing {
35
public class SXSSFDrawing implements Drawing<XSSFShape> {
33
    private final SXSSFWorkbook _wb;
36
    private final SXSSFWorkbook _wb;
34
    private final XSSFDrawing _drawing;
37
    private final XSSFDrawing _drawing;
35
38
Lines 58-62 Link Here
58
    public ClientAnchor createAnchor(int dx1, int dy1, int dx2, int dy2, int col1, int row1, int col2, int row2) {
61
    public ClientAnchor createAnchor(int dx1, int dy1, int dx2, int dy2, int col1, int row1, int col2, int row2) {
59
        return _drawing.createAnchor(dx1, dy1, dx2, dy2, col1, row1, col2, row2);
62
        return _drawing.createAnchor(dx1, dy1, dx2, dy2, col1, row1, col2, row2);
60
    }
63
    }
64
65
    @Override
66
    public Iterator<XSSFShape> iterator() {
67
        return _drawing.getShapes().iterator();
68
    }
61
}
69
}
62
70
(-)src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFShape.java (-22 / +8 lines)
Lines 17-22 Link Here
17
17
18
package org.apache.poi.xssf.usermodel;
18
package org.apache.poi.xssf.usermodel;
19
19
20
import org.apache.poi.ss.usermodel.Shape;
20
import org.openxmlformats.schemas.drawingml.x2006.main.CTLineProperties;
21
import org.openxmlformats.schemas.drawingml.x2006.main.CTLineProperties;
21
import org.openxmlformats.schemas.drawingml.x2006.main.CTNoFillProperties;
22
import org.openxmlformats.schemas.drawingml.x2006.main.CTNoFillProperties;
22
import org.openxmlformats.schemas.drawingml.x2006.main.CTPresetLineDashProperties;
23
import org.openxmlformats.schemas.drawingml.x2006.main.CTPresetLineDashProperties;
Lines 27-36 Link Here
27
28
28
/**
29
/**
29
 * Represents a shape in a SpreadsheetML drawing.
30
 * Represents a shape in a SpreadsheetML drawing.
30
 *
31
 * @author Yegor Kozlov
32
 */
31
 */
33
public abstract class XSSFShape {
32
public abstract class XSSFShape implements Shape {
34
    public static final int EMU_PER_PIXEL = 9525;
33
    public static final int EMU_PER_PIXEL = 9525;
35
    public static final int EMU_PER_POINT = 12700;
34
    public static final int EMU_PER_POINT = 12700;
36
35
Lines 61-69 Link Here
61
        return drawing;
60
        return drawing;
62
    }
61
    }
63
62
64
    /**
63
    @Override
65
     * Gets the parent shape.
66
     */
67
    public XSSFShapeGroup getParent()
64
    public XSSFShapeGroup getParent()
68
    {
65
    {
69
        return parent;
66
        return parent;
Lines 72-77 Link Here
72
    /**
69
    /**
73
     * @return  the anchor that is used by this shape.
70
     * @return  the anchor that is used by this shape.
74
     */
71
     */
72
    @Override
75
    public XSSFAnchor getAnchor()
73
    public XSSFAnchor getAnchor()
76
    {
74
    {
77
        return anchor;
75
        return anchor;
Lines 84-103 Link Here
84
     */
82
     */
85
    protected abstract CTShapeProperties getShapeProperties();
83
    protected abstract CTShapeProperties getShapeProperties();
86
84
87
    /**
85
    @Override
88
     * Whether this shape is not filled with a color
89
     *
90
     * @return true if this shape is not filled with a color.
91
     */
92
    public boolean isNoFill() {
86
    public boolean isNoFill() {
93
        return getShapeProperties().isSetNoFill();
87
        return getShapeProperties().isSetNoFill();
94
    }
88
    }
95
89
96
    /**
90
    @Override
97
     * Sets whether this shape is filled or transparent.
98
     *
99
     * @param noFill if true then no fill will be applied to the shape element.
100
     */
101
    public void setNoFill(boolean noFill) {
91
    public void setNoFill(boolean noFill) {
102
        CTShapeProperties props = getShapeProperties();
92
        CTShapeProperties props = getShapeProperties();
103
        //unset solid and pattern fills if they are set
93
        //unset solid and pattern fills if they are set
Lines 107-115 Link Here
107
        props.setNoFill(CTNoFillProperties.Factory.newInstance());
97
        props.setNoFill(CTNoFillProperties.Factory.newInstance());
108
    }
98
    }
109
99
110
    /**
100
    @Override
111
     * Sets the color used to fill this shape using the solid fill pattern.
112
     */
113
    public void setFillColor(int red, int green, int blue) {
101
    public void setFillColor(int red, int green, int blue) {
114
        CTShapeProperties props = getShapeProperties();
102
        CTShapeProperties props = getShapeProperties();
115
        CTSolidColorFillProperties fill = props.isSetSolidFill() ? props.getSolidFill() : props.addNewSolidFill();
103
        CTSolidColorFillProperties fill = props.isSetSolidFill() ? props.getSolidFill() : props.addNewSolidFill();
Lines 118-126 Link Here
118
        fill.setSrgbClr(rgb);
106
        fill.setSrgbClr(rgb);
119
    }
107
    }
120
108
121
    /**
109
    @Override
122
     * The color applied to the lines of this shape.
123
     */
124
    public void setLineStyleColor( int red, int green, int blue ) {
110
    public void setLineStyleColor( int red, int green, int blue ) {
125
        CTShapeProperties props = getShapeProperties();
111
        CTShapeProperties props = getShapeProperties();
126
        CTLineProperties ln = props.isSetLn() ? props.getLn() : props.addNewLn();
112
        CTLineProperties ln = props.isSetLn() ? props.getLn() : props.addNewLn();
(-)src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSimpleShape.java (-1 / +7 lines)
Lines 23-28 Link Here
23
import java.util.Locale;
23
import java.util.Locale;
24
24
25
import org.apache.poi.hssf.util.HSSFColor;
25
import org.apache.poi.hssf.util.HSSFColor;
26
import org.apache.poi.ss.usermodel.SimpleShape;
26
import org.apache.poi.ss.usermodel.VerticalAlignment;
27
import org.apache.poi.ss.usermodel.VerticalAlignment;
27
import org.apache.poi.util.Internal;
28
import org.apache.poi.util.Internal;
28
import org.apache.poi.util.Units;
29
import org.apache.poi.util.Units;
Lines 37-43 Link Here
37
 * Represents a shape with a predefined geometry in a SpreadsheetML drawing.
38
 * Represents a shape with a predefined geometry in a SpreadsheetML drawing.
38
 * Possible shape types are defined in {@link org.apache.poi.ss.usermodel.ShapeTypes}
39
 * Possible shape types are defined in {@link org.apache.poi.ss.usermodel.ShapeTypes}
39
 */
40
 */
40
public class XSSFSimpleShape extends XSSFShape implements Iterable<XSSFTextParagraph> { // TODO - instantiable superclass
41
public class XSSFSimpleShape extends XSSFShape implements Iterable<XSSFTextParagraph>, SimpleShape {
41
	/**
42
	/**
42
	 * List of the paragraphs that make up the text in this shape
43
	 * List of the paragraphs that make up the text in this shape
43
	 */
44
	 */
Lines 863-866 Link Here
863
            }
864
            }
864
        }
865
        }
865
    }
866
    }
867
868
    @Override
869
    public String getShapeName() {
870
        return ctShape.getNvSpPr().getCNvPr().getName();
871
    }
866
}
872
}
(-)src/java/org/apache/poi/hssf/usermodel/HSSFPatriarch.java (-1 / +2 lines)
Lines 57-63 Link Here
57
 * The patriarch is the toplevel container for shapes in a sheet.  It does
57
 * The patriarch is the toplevel container for shapes in a sheet.  It does
58
 * little other than act as a container for other shapes and groups.
58
 * little other than act as a container for other shapes and groups.
59
 */
59
 */
60
public final class HSSFPatriarch implements HSSFShapeContainer, Drawing {
60
public final class HSSFPatriarch implements HSSFShapeContainer, Drawing<HSSFShape> {
61
    // private static POILogger log = POILogFactory.getLogger(HSSFPatriarch.class);
61
    // private static POILogger log = POILogFactory.getLogger(HSSFPatriarch.class);
62
    private final List<HSSFShape> _shapes = new ArrayList<HSSFShape>();
62
    private final List<HSSFShape> _shapes = new ArrayList<HSSFShape>();
63
63
Lines 556-561 Link Here
556
        }
556
        }
557
    }
557
    }
558
558
559
    @Override
559
    public Iterator<HSSFShape> iterator() {
560
    public Iterator<HSSFShape> iterator() {
560
        return _shapes.iterator();
561
        return _shapes.iterator();
561
    }
562
    }
(-)src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPicture.java (+5 lines)
Lines 284-287 Link Here
284
    public XSSFSheet getSheet() {
284
    public XSSFSheet getSheet() {
285
        return (XSSFSheet)getDrawing().getParent();
285
        return (XSSFSheet)getDrawing().getParent();
286
    }
286
    }
287
288
    @Override
289
    public String getShapeName() {
290
        return ctPicture.getNvPicPr().getCNvPr().getName();
291
    }
287
}
292
}
(-)src/java/org/apache/poi/ss/usermodel/SimpleShape.java (+29 lines)
Line 0 Link Here
1
/* ====================================================================
2
   Licensed to the Apache Software Foundation (ASF) under one or more
3
   contributor license agreements.  See the NOTICE file distributed with
4
   this work for additional information regarding copyright ownership.
5
   The ASF licenses this file to You under the Apache License, Version 2.0
6
   (the "License"); you may not use this file except in compliance with
7
   the License.  You may obtain a copy of the License at
8
9
       http://www.apache.org/licenses/LICENSE-2.0
10
11
   Unless required by applicable law or agreed to in writing, software
12
   distributed under the License is distributed on an "AS IS" BASIS,
13
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
   See the License for the specific language governing permissions and
15
   limitations under the License.
16
==================================================================== */
17
18
package org.apache.poi.ss.usermodel;
19
20
/**
21
 * A common interface for simple shapes.
22
 * (Currently the HSSF and XSSF classes don't share common method signatures ...)
23
 * 
24
 * @since POI 3.16-beta2
25
 */
26
public interface SimpleShape extends Shape {
27
28
}
29
native

Return to bug 60520