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

(-)src/java/org/apache/poi/ss/usermodel/ClientAnchor.java (-54 / +64 lines)
Lines 23-68 Link Here
23
 * @author Yegor Kozlov
23
 * @author Yegor Kozlov
24
 */
24
 */
25
public interface ClientAnchor {
25
public interface ClientAnchor {
26
    
27
    public static enum AnchorType {
28
        /**
29
         * Move and Resize With Anchor Cells (0)
30
         * <p>
31
         * Specifies that the current drawing shall move and
32
         * resize to maintain its row and column anchors (i.e. the
33
         * object is anchored to the actual from and to row and column)
34
         * </p>
35
         */
36
        MOVE_AND_RESIZE(0),
37
        
38
        /**
39
         * Don't Move but do Resize With Anchor Cells (0)
40
         * <p>
41
         * Specifies that the current drawing shall not move with its
42
         * row and column, but should be resized. This option is not normally
43
         * used, but is included for completeness.
44
         * </p>
45
         */
46
        DONT_MOVE_DO_RESIZE(1),
47
        
48
        /**
49
         * Move With Cells but Do Not Resize (2)
50
         * <p>
51
         * Specifies that the current drawing shall move with its
52
         * row and column (i.e. the object is anchored to the
53
         * actual from row and column), but that the size shall remain absolute.
54
         * </p>
55
         * <p>
56
         * If additional rows/columns are added between the from and to locations of the drawing,
57
         * the drawing shall move its to anchors as needed to maintain this same absolute size.
58
         * </p>
59
         */
60
        MOVE_DONT_RESIZE(2),
61
        
62
        /**
63
         * Do Not Move or Resize With Underlying Rows/Columns (3)
64
         * <p>
65
         * Specifies that the current start and end positions shall
66
         * be maintained with respect to the distances from the
67
         * absolute start point of the worksheet.
68
         * </p>
69
         * <p>
70
         * If additional rows/columns are added before the
71
         * drawing, the drawing shall move its anchors as needed
72
         * to maintain this same absolute position.
73
         * </p>
74
         */
75
        DONT_MOVE_AND_RESIZE(3);
76
        
77
        public final short value;
78
        AnchorType(int value) {
79
            this.value = (short) value;
80
        }
81
        
82
        public static AnchorType byId(int value) {
83
            return values()[value];
84
        }
85
    }
86
    
26
    /**
87
    /**
27
     * Move and Resize With Anchor Cells
28
     * <p>
29
     * Specifies that the current drawing shall move and
30
     * resize to maintain its row and column anchors (i.e. the
31
     * object is anchored to the actual from and to row and column)
32
     * </p>
33
     */
34
    public static final int MOVE_AND_RESIZE = 0;
35
36
    /**
37
     * Move With Cells but Do Not Resize
38
     * <p>
39
     * Specifies that the current drawing shall move with its
40
     * row and column (i.e. the object is anchored to the
41
     * actual from row and column), but that the size shall remain absolute.
42
     * </p>
43
     * <p>
44
     * If additional rows/columns are added between the from and to locations of the drawing,
45
     * the drawing shall move its to anchors as needed to maintain this same absolute size.
46
     * </p>
47
     */
48
    public static final int MOVE_DONT_RESIZE = 2;
49
50
    /**
51
     * Do Not Move or Resize With Underlying Rows/Columns
52
     * <p>
53
     * Specifies that the current start and end positions shall
54
     * be maintained with respect to the distances from the
55
     * absolute start point of the worksheet.
56
     * </p>
57
     * <p>
58
     * If additional rows/columns are added before the
59
     * drawing, the drawing shall move its anchors as needed
60
     * to maintain this same absolute position.
61
     * </p>
62
     */
63
    public static final int DONT_MOVE_AND_RESIZE = 3;
64
65
    /**
66
     * Returns the column (0 based) of the first cell.
88
     * Returns the column (0 based) of the first cell.
67
     *
89
     *
68
     * @return 0-based column of the first cell.
90
     * @return 0-based column of the first cell.
Lines 209-234 Link Here
209
231
210
    /**
232
    /**
211
     * Sets the anchor type
233
     * Sets the anchor type
212
     * <p>
234
     * @param anchorType the anchor type to set
213
     * 0 = Move and size with Cells, 2 = Move but don't size with cells, 3 = Don't move or size with cells.
214
     * </p>
215
     * @param anchorType the anchor type
216
     * @see #MOVE_AND_RESIZE
217
     * @see #MOVE_DONT_RESIZE
218
     * @see #DONT_MOVE_AND_RESIZE
219
     */
235
     */
220
    public void setAnchorType( int anchorType );
236
    public void setAnchorType( AnchorType anchorType );
221
237
222
    /**
238
    /**
223
     * Gets the anchor type
239
     * Gets the anchor type
224
     * <p>
225
     * 0 = Move and size with Cells, 2 = Move but don't size with cells, 3 = Don't move or size with cells.
226
     * </p>
227
     * @return the anchor type
240
     * @return the anchor type
228
     * @see #MOVE_AND_RESIZE
229
     * @see #MOVE_DONT_RESIZE
230
     * @see #DONT_MOVE_AND_RESIZE
231
     */
241
     */
232
    public int getAnchorType();
242
    public AnchorType getAnchorType();
233
243
234
}
244
}
(-)src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFClientAnchor.java (-7 / +10 lines)
Lines 28-34 Link Here
28
 * @author Yegor Kozlov
28
 * @author Yegor Kozlov
29
 */
29
 */
30
public final class XSSFClientAnchor extends XSSFAnchor implements ClientAnchor {
30
public final class XSSFClientAnchor extends XSSFAnchor implements ClientAnchor {
31
    private int anchorType;
31
    private AnchorType DEFAULT_ANCHOR_TYPE = AnchorType.MOVE_AND_RESIZE;
32
    private AnchorType anchorType;
32
33
33
    /**
34
    /**
34
     * Starting anchor point
35
     * Starting anchor point
Lines 44-49 Link Here
44
     * Creates a new client anchor and defaults all the anchor positions to 0.
45
     * Creates a new client anchor and defaults all the anchor positions to 0.
45
     */
46
     */
46
    public XSSFClientAnchor() {
47
    public XSSFClientAnchor() {
48
        anchorType = DEFAULT_ANCHOR_TYPE;
47
        cell1 = CTMarker.Factory.newInstance();
49
        cell1 = CTMarker.Factory.newInstance();
48
        cell1.setCol(0);
50
        cell1.setCol(0);
49
        cell1.setColOff(0);
51
        cell1.setColOff(0);
Lines 88-93 Link Here
88
     * @param cell2 ending anchor point
90
     * @param cell2 ending anchor point
89
     */
91
     */
90
    protected XSSFClientAnchor(CTMarker cell1, CTMarker cell2) {
92
    protected XSSFClientAnchor(CTMarker cell1, CTMarker cell2) {
93
        anchorType = DEFAULT_ANCHOR_TYPE;
91
        this.cell1 = cell1;
94
        this.cell1 = cell1;
92
        this.cell2 = cell2;
95
        this.cell2 = cell2;
93
    }
96
    }
Lines 214-223 Link Here
214
217
215
    /**
218
    /**
216
     * Sets the anchor type
219
     * Sets the anchor type
217
     * <p>
220
     * @param anchorType the anchor type to set
218
     * 0 = Move and size with Cells, 2 = Move but don't size with cells, 3 = Don't move or size with cells.
219
     */
221
     */
220
    public void setAnchorType( int anchorType )
222
    @Override
223
    public void setAnchorType( AnchorType anchorType )
221
    {
224
    {
222
        this.anchorType = anchorType;
225
        this.anchorType = anchorType;
223
    }
226
    }
Lines 224-233 Link Here
224
227
225
    /**
228
    /**
226
     * Gets the anchor type
229
     * Gets the anchor type
227
     * <p>
230
     * @return the anchor type
228
     * 0 = Move and size with Cells, 2 = Move but don't size with cells, 3 = Don't move or size with cells.
229
     */
231
     */
230
    public int getAnchorType()
232
    @Override
233
    public AnchorType getAnchorType()
231
    {
234
    {
232
        return anchorType;
235
        return anchorType;
233
    }
236
    }
(-)src/java/org/apache/poi/hssf/usermodel/HSSFClientAnchor.java (-8 / +8 lines)
Lines 250-269 Link Here
250
250
251
    /**
251
    /**
252
     * Gets the anchor type
252
     * Gets the anchor type
253
     * <p/>
253
     * @return the anchor type
254
     * 0 = Move and size with Cells, 2 = Move but don't size with cells, 3 = Don't move or size with cells.
255
     */
254
     */
256
    public int getAnchorType() {
255
    @Override
257
        return _escherClientAnchor.getFlag();
256
    public AnchorType getAnchorType() {
257
        return AnchorType.byId(_escherClientAnchor.getFlag());
258
    }
258
    }
259
259
260
    /**
260
    /**
261
     * Sets the anchor type
261
     * Sets the anchor type
262
     * <p/>
262
     * @param anchorType the anchor type to set
263
     * 0 = Move and size with Cells, 2 = Move but don't size with cells, 3 = Don't move or size with cells.
264
     */
263
     */
265
    public void setAnchorType(int anchorType) {
264
    @Override
266
        _escherClientAnchor.setFlag(Integer.valueOf(anchorType).shortValue());
265
    public void setAnchorType(AnchorType anchorType) {
266
        _escherClientAnchor.setFlag(anchorType.value);
267
    }
267
    }
268
268
269
    private void checkRange(int value, int minRange, int maxRange, String varName) {
269
    private void checkRange(int value, int minRange, int maxRange, String varName) {
(-)src/testcases/org/apache/poi/hssf/model/TestHSSFAnchor.java (-5 / +6 lines)
Lines 21-26 Link Here
21
import org.apache.poi.ddf.*;
21
import org.apache.poi.ddf.*;
22
import org.apache.poi.hssf.HSSFTestDataSamples;
22
import org.apache.poi.hssf.HSSFTestDataSamples;
23
import org.apache.poi.hssf.usermodel.*;
23
import org.apache.poi.hssf.usermodel.*;
24
import org.apache.poi.ss.usermodel.ClientAnchor.AnchorType;
24
25
25
/**
26
/**
26
 * @author Evgeniy Berlog
27
 * @author Evgeniy Berlog
Lines 30-36 Link Here
30
31
31
    public void testDefaultValues(){
32
    public void testDefaultValues(){
32
        HSSFClientAnchor clientAnchor = new HSSFClientAnchor();
33
        HSSFClientAnchor clientAnchor = new HSSFClientAnchor();
33
        assertEquals(clientAnchor.getAnchorType(), 0);
34
        assertEquals(clientAnchor.getAnchorType(), AnchorType.MOVE_AND_RESIZE);
34
        assertEquals(clientAnchor.getCol1(), 0);
35
        assertEquals(clientAnchor.getCol1(), 0);
35
        assertEquals(clientAnchor.getCol2(), 0);
36
        assertEquals(clientAnchor.getCol2(), 0);
36
        assertEquals(clientAnchor.getDx1(), 0);
37
        assertEquals(clientAnchor.getDx1(), 0);
Lines 41-47 Link Here
41
        assertEquals(clientAnchor.getRow2(), 0);
42
        assertEquals(clientAnchor.getRow2(), 0);
42
43
43
        clientAnchor = new HSSFClientAnchor(new EscherClientAnchorRecord());
44
        clientAnchor = new HSSFClientAnchor(new EscherClientAnchorRecord());
44
        assertEquals(clientAnchor.getAnchorType(), 0);
45
        assertEquals(clientAnchor.getAnchorType(), AnchorType.MOVE_AND_RESIZE);
45
        assertEquals(clientAnchor.getCol1(), 0);
46
        assertEquals(clientAnchor.getCol1(), 0);
46
        assertEquals(clientAnchor.getCol2(), 0);
47
        assertEquals(clientAnchor.getCol2(), 0);
47
        assertEquals(clientAnchor.getDx1(), 0);
48
        assertEquals(clientAnchor.getDx1(), 0);
Lines 143-149 Link Here
143
144
144
        HSSFPatriarch drawing = sheet.createDrawingPatriarch();
145
        HSSFPatriarch drawing = sheet.createDrawingPatriarch();
145
        HSSFClientAnchor anchor = new HSSFClientAnchor(10, 10, 200, 200, (short)2, 2, (short)15, 15);
146
        HSSFClientAnchor anchor = new HSSFClientAnchor(10, 10, 200, 200, (short)2, 2, (short)15, 15);
146
        anchor.setAnchorType(2);
147
        anchor.setAnchorType(AnchorType.MOVE_DONT_RESIZE);
147
148
148
        HSSFSimpleShape rectangle = drawing.createSimpleShape(anchor);
149
        HSSFSimpleShape rectangle = drawing.createSimpleShape(anchor);
149
        rectangle.setShapeType(HSSFSimpleShape.OBJECT_TYPE_RECTANGLE);
150
        rectangle.setShapeType(HSSFSimpleShape.OBJECT_TYPE_RECTANGLE);
Lines 362-370 Link Here
362
        clientAnchor2.setRow2(7);
363
        clientAnchor2.setRow2(7);
363
        assertEquals(clientAnchor1, clientAnchor2);
364
        assertEquals(clientAnchor1, clientAnchor2);
364
365
365
        clientAnchor2.setAnchorType(3);
366
        clientAnchor2.setAnchorType(AnchorType.DONT_MOVE_AND_RESIZE);
366
        assertNotSame(clientAnchor1, clientAnchor2);
367
        assertNotSame(clientAnchor1, clientAnchor2);
367
        clientAnchor2.setAnchorType(0);
368
        clientAnchor2.setAnchorType(AnchorType.MOVE_AND_RESIZE);
368
        assertEquals(clientAnchor1, clientAnchor2);
369
        assertEquals(clientAnchor1, clientAnchor2);
369
370
370
        HSSFChildAnchor childAnchor1 = new HSSFChildAnchor(0, 1, 2, 3);
371
        HSSFChildAnchor childAnchor1 = new HSSFChildAnchor(0, 1, 2, 3);
(-)src/java/org/apache/poi/hssf/model/ComboboxShape.java (-1 / +2 lines)
Lines 21-26 Link Here
21
import org.apache.poi.ddf.*;
21
import org.apache.poi.ddf.*;
22
import org.apache.poi.hssf.record.*;
22
import org.apache.poi.hssf.record.*;
23
import org.apache.poi.hssf.usermodel.*;
23
import org.apache.poi.hssf.usermodel.*;
24
import org.apache.poi.ss.usermodel.ClientAnchor.AnchorType;
24
25
25
/**
26
/**
26
 * Represents a combobox shape.
27
 * Represents a combobox shape.
Lines 92-98 Link Here
92
        opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.GROUPSHAPE__PRINT, 0x00020000));
93
        opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.GROUPSHAPE__PRINT, 0x00020000));
93
94
94
        HSSFClientAnchor userAnchor = (HSSFClientAnchor) shape.getAnchor();
95
        HSSFClientAnchor userAnchor = (HSSFClientAnchor) shape.getAnchor();
95
        userAnchor.setAnchorType(1);
96
        userAnchor.setAnchorType(AnchorType.DONT_MOVE_DO_RESIZE);
96
        EscherRecord anchor = createAnchor(userAnchor);
97
        EscherRecord anchor = createAnchor(userAnchor);
97
        clientData.setRecordId(EscherClientDataRecord.RECORD_ID);
98
        clientData.setRecordId(EscherClientDataRecord.RECORD_ID);
98
        clientData.setOptions((short) 0x0000);
99
        clientData.setOptions((short) 0x0000);
(-)src/java/org/apache/poi/hssf/model/ConvertAnchor.java (-1 / +1 lines)
Lines 38-44 Link Here
38
            EscherClientAnchorRecord anchor = new EscherClientAnchorRecord();
38
            EscherClientAnchorRecord anchor = new EscherClientAnchorRecord();
39
            anchor.setRecordId( EscherClientAnchorRecord.RECORD_ID );
39
            anchor.setRecordId( EscherClientAnchorRecord.RECORD_ID );
40
            anchor.setOptions( (short) 0x0000 );
40
            anchor.setOptions( (short) 0x0000 );
41
            anchor.setFlag( (short) a.getAnchorType() );
41
            anchor.setFlag( a.getAnchorType().value );
42
            anchor.setCol1( (short) Math.min(a.getCol1(), a.getCol2()) );
42
            anchor.setCol1( (short) Math.min(a.getCol1(), a.getCol2()) );
43
            anchor.setDx1( (short) a.getDx1() );
43
            anchor.setDx1( (short) a.getDx1() );
44
            anchor.setRow1( (short) Math.min(a.getRow1(), a.getRow2()) );
44
            anchor.setRow1( (short) Math.min(a.getRow1(), a.getRow2()) );
(-)src/java/org/apache/poi/hssf/usermodel/HSSFCombobox.java (-1 / +2 lines)
Lines 19-24 Link Here
19
19
20
import org.apache.poi.ddf.*;
20
import org.apache.poi.ddf.*;
21
import org.apache.poi.hssf.record.*;
21
import org.apache.poi.hssf.record.*;
22
import org.apache.poi.ss.usermodel.ClientAnchor.AnchorType;
22
23
23
/**
24
/**
24
 * 
25
 * 
Lines 61-67 Link Here
61
        opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.GROUPSHAPE__PRINT, 0x00020000));
62
        opt.addEscherProperty(new EscherSimpleProperty(EscherProperties.GROUPSHAPE__PRINT, 0x00020000));
62
63
63
        HSSFClientAnchor userAnchor = (HSSFClientAnchor) getAnchor();
64
        HSSFClientAnchor userAnchor = (HSSFClientAnchor) getAnchor();
64
        userAnchor.setAnchorType(1);
65
        userAnchor.setAnchorType(AnchorType.DONT_MOVE_DO_RESIZE);
65
        EscherRecord anchor = userAnchor.getEscherAnchor();
66
        EscherRecord anchor = userAnchor.getEscherAnchor();
66
        clientData.setRecordId(EscherClientDataRecord.RECORD_ID);
67
        clientData.setRecordId(EscherClientDataRecord.RECORD_ID);
67
        clientData.setOptions((short) 0x0000);
68
        clientData.setOptions((short) 0x0000);
(-)src/java/org/apache/poi/hssf/usermodel/HSSFPicture.java (-1 / +2 lines)
Lines 34-39 Link Here
34
import org.apache.poi.hssf.record.CommonObjectDataSubRecord;
34
import org.apache.poi.hssf.record.CommonObjectDataSubRecord;
35
import org.apache.poi.hssf.record.EscherAggregate;
35
import org.apache.poi.hssf.record.EscherAggregate;
36
import org.apache.poi.hssf.record.ObjRecord;
36
import org.apache.poi.hssf.record.ObjRecord;
37
import org.apache.poi.ss.usermodel.ClientAnchor.AnchorType;
37
import org.apache.poi.ss.usermodel.Picture;
38
import org.apache.poi.ss.usermodel.Picture;
38
import org.apache.poi.ss.util.ImageUtils;
39
import org.apache.poi.ss.util.ImageUtils;
39
import org.apache.poi.util.POILogFactory;
40
import org.apache.poi.util.POILogFactory;
Lines 134-140 Link Here
134
     */
135
     */
135
    public void resize(double scaleX, double scaleY) {
136
    public void resize(double scaleX, double scaleY) {
136
        HSSFClientAnchor anchor = getClientAnchor();
137
        HSSFClientAnchor anchor = getClientAnchor();
137
        anchor.setAnchorType(2);
138
        anchor.setAnchorType(AnchorType.MOVE_DONT_RESIZE);
138
139
139
        HSSFClientAnchor pref = getPreferredSize(scaleX,scaleY);
140
        HSSFClientAnchor pref = getPreferredSize(scaleX,scaleY);
140
141
(-)src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java (-4 / +3 lines)
Lines 34-40 Link Here
34
import org.apache.poi.ss.usermodel.ClientAnchor;
34
import org.apache.poi.ss.usermodel.ClientAnchor;
35
import org.apache.poi.ss.usermodel.Drawing;
35
import org.apache.poi.ss.usermodel.Drawing;
36
import org.apache.poi.ss.util.CellAddress;
36
import org.apache.poi.ss.util.CellAddress;
37
import org.apache.poi.ss.util.CellReference;
38
import org.apache.poi.util.Internal;
37
import org.apache.poi.util.Internal;
39
import org.apache.poi.util.Units;
38
import org.apache.poi.util.Units;
40
import org.apache.poi.xssf.model.CommentsTable;
39
import org.apache.poi.xssf.model.CommentsTable;
Lines 373-381 Link Here
373
        anchor.setFrom(ctAnchor.getFrom());
372
        anchor.setFrom(ctAnchor.getFrom());
374
        STEditAs.Enum aditAs;
373
        STEditAs.Enum aditAs;
375
        switch(anchor.getAnchorType()) {
374
        switch(anchor.getAnchorType()) {
376
            case ClientAnchor.DONT_MOVE_AND_RESIZE: aditAs = STEditAs.ABSOLUTE; break;
375
            case DONT_MOVE_AND_RESIZE: aditAs = STEditAs.ABSOLUTE; break;
377
            case ClientAnchor.MOVE_AND_RESIZE: aditAs = STEditAs.TWO_CELL; break;
376
            case MOVE_AND_RESIZE: aditAs = STEditAs.TWO_CELL; break;
378
            case ClientAnchor.MOVE_DONT_RESIZE: aditAs = STEditAs.ONE_CELL; break;
377
            case MOVE_DONT_RESIZE: aditAs = STEditAs.ONE_CELL; break;
379
            default: aditAs = STEditAs.ONE_CELL;
378
            default: aditAs = STEditAs.ONE_CELL;
380
        }
379
        }
381
        ctAnchor.setEditAs(aditAs);
380
        ctAnchor.setEditAs(aditAs);
(-)src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPicture.java (-4 / +4 lines)
Lines 23-29 Link Here
23
import java.util.List;
23
import java.util.List;
24
24
25
import org.apache.poi.ss.usermodel.BaseTestPicture;
25
import org.apache.poi.ss.usermodel.BaseTestPicture;
26
import org.apache.poi.ss.usermodel.ClientAnchor;
26
import org.apache.poi.ss.usermodel.ClientAnchor.AnchorType;
27
import org.apache.poi.util.LocaleUtil;
27
import org.apache.poi.util.LocaleUtil;
28
import org.apache.poi.xssf.XSSFITestDataProvider;
28
import org.apache.poi.xssf.XSSFITestDataProvider;
29
import org.apache.poi.xssf.XSSFTestDataSamples;
29
import org.apache.poi.xssf.XSSFTestDataSamples;
Lines 70-78 Link Here
70
        assertArrayEquals(jpegData, pictures.get(jpegIdx).getData());
70
        assertArrayEquals(jpegData, pictures.get(jpegIdx).getData());
71
71
72
        XSSFClientAnchor anchor = new XSSFClientAnchor(0, 0, 0, 0, 1, 1, 10, 30);
72
        XSSFClientAnchor anchor = new XSSFClientAnchor(0, 0, 0, 0, 1, 1, 10, 30);
73
        assertEquals(ClientAnchor.MOVE_AND_RESIZE, anchor.getAnchorType());
73
        assertEquals(AnchorType.MOVE_AND_RESIZE, anchor.getAnchorType());
74
        anchor.setAnchorType(ClientAnchor.DONT_MOVE_AND_RESIZE);
74
        anchor.setAnchorType(AnchorType.DONT_MOVE_AND_RESIZE);
75
        assertEquals(ClientAnchor.DONT_MOVE_AND_RESIZE, anchor.getAnchorType());
75
        assertEquals(AnchorType.DONT_MOVE_AND_RESIZE, anchor.getAnchorType());
76
76
77
        XSSFPicture shape = drawing.createPicture(anchor, jpegIdx);
77
        XSSFPicture shape = drawing.createPicture(anchor, jpegIdx);
78
        assertTrue(anchor.equals(shape.getAnchor()));
78
        assertTrue(anchor.equals(shape.getAnchor()));
(-)src/testcases/org/apache/poi/hssf/model/TestDrawingShapes.java (-2 / +3 lines)
Lines 35-40 Link Here
35
import org.apache.poi.hssf.record.EscherAggregate;
35
import org.apache.poi.hssf.record.EscherAggregate;
36
import org.apache.poi.hssf.record.ObjRecord;
36
import org.apache.poi.hssf.record.ObjRecord;
37
import org.apache.poi.hssf.usermodel.*;
37
import org.apache.poi.hssf.usermodel.*;
38
import org.apache.poi.ss.usermodel.ClientAnchor.AnchorType;
38
import org.apache.poi.ss.usermodel.Workbook;
39
import org.apache.poi.ss.usermodel.Workbook;
39
import org.apache.poi.util.HexDump;
40
import org.apache.poi.util.HexDump;
40
41
Lines 148-155 Link Here
148
149
149
        HSSFPatriarch drawing = sheet.createDrawingPatriarch();
150
        HSSFPatriarch drawing = sheet.createDrawingPatriarch();
150
        HSSFClientAnchor anchor = new HSSFClientAnchor(10, 10, 50, 50, (short) 2, 2, (short) 4, 4);
151
        HSSFClientAnchor anchor = new HSSFClientAnchor(10, 10, 50, 50, (short) 2, 2, (short) 4, 4);
151
        anchor.setAnchorType(2);
152
        anchor.setAnchorType(AnchorType.MOVE_DONT_RESIZE);
152
        assertEquals(anchor.getAnchorType(), 2);
153
        assertEquals(AnchorType.MOVE_DONT_RESIZE, anchor.getAnchorType());
153
154
154
        HSSFSimpleShape rectangle = drawing.createSimpleShape(anchor);
155
        HSSFSimpleShape rectangle = drawing.createSimpleShape(anchor);
155
        rectangle.setShapeType(HSSFSimpleShape.OBJECT_TYPE_RECTANGLE);
156
        rectangle.setShapeType(HSSFSimpleShape.OBJECT_TYPE_RECTANGLE);
(-)src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java (-1 / +2 lines)
Lines 70-75 Link Here
70
import org.apache.poi.ss.usermodel.BaseTestBugzillaIssues;
70
import org.apache.poi.ss.usermodel.BaseTestBugzillaIssues;
71
import org.apache.poi.ss.usermodel.Cell;
71
import org.apache.poi.ss.usermodel.Cell;
72
import org.apache.poi.ss.usermodel.CellStyle;
72
import org.apache.poi.ss.usermodel.CellStyle;
73
import org.apache.poi.ss.usermodel.ClientAnchor.AnchorType;
73
import org.apache.poi.ss.usermodel.DataFormatter;
74
import org.apache.poi.ss.usermodel.DataFormatter;
74
import org.apache.poi.ss.usermodel.FormulaEvaluator;
75
import org.apache.poi.ss.usermodel.FormulaEvaluator;
75
import org.apache.poi.ss.usermodel.Name;
76
import org.apache.poi.ss.usermodel.Name;
Lines 2966-2972 Link Here
2966
        assertNotNull("Did not find sheet", sheet);
2967
        assertNotNull("Did not find sheet", sheet);
2967
        HSSFPatriarch patriarch = (HSSFPatriarch) sheet.createDrawingPatriarch();
2968
        HSSFPatriarch patriarch = (HSSFPatriarch) sheet.createDrawingPatriarch();
2968
        HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 0, 0, (short) 1, 1, (short) 10, 22);
2969
        HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 0, 0, (short) 1, 1, (short) 10, 22);
2969
        anchor.setAnchorType(2);
2970
        anchor.setAnchorType(AnchorType.MOVE_DONT_RESIZE);
2970
        patriarch.createPicture(anchor, pict);
2971
        patriarch.createPicture(anchor, pict);
2971
2972
2972
        // Write out destination file
2973
        // Write out destination file
(-)src/testcases/org/apache/poi/hssf/usermodel/TestHSSFPatriarch.java (-1 / +2 lines)
Lines 18-23 Link Here
18
package org.apache.poi.hssf.usermodel;
18
package org.apache.poi.hssf.usermodel;
19
19
20
import org.apache.poi.hssf.HSSFTestDataSamples;
20
import org.apache.poi.hssf.HSSFTestDataSamples;
21
import org.apache.poi.ss.usermodel.ClientAnchor.AnchorType;
21
22
22
import junit.framework.AssertionFailedError;
23
import junit.framework.AssertionFailedError;
23
import junit.framework.TestCase;
24
import junit.framework.TestCase;
Lines 56-62 Link Here
56
57
57
		// 3. Use patriarch
58
		// 3. Use patriarch
58
		HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 600, 245, (short) 1, 1, (short) 1, 2);
59
		HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 600, 245, (short) 1, 1, (short) 1, 2);
59
		anchor.setAnchorType(3);
60
		anchor.setAnchorType(AnchorType.DONT_MOVE_AND_RESIZE);
60
		byte[] pictureData = HSSFTestDataSamples.getTestDataFileContent("logoKarmokar4.png");
61
		byte[] pictureData = HSSFTestDataSamples.getTestDataFileContent("logoKarmokar4.png");
61
		int idx1 = wb.addPicture(pictureData, HSSFWorkbook.PICTURE_TYPE_PNG);
62
		int idx1 = wb.addPicture(pictureData, HSSFWorkbook.PICTURE_TYPE_PNG);
62
		patr.createPicture(anchor, idx1);
63
		patr.createPicture(anchor, idx1);
(-)src/testcases/org/apache/poi/hssf/usermodel/TestOLE2Embeding.java (-5 / +5 lines)
Lines 31-37 Link Here
31
import org.apache.poi.poifs.filesystem.DirectoryNode;
31
import org.apache.poi.poifs.filesystem.DirectoryNode;
32
import org.apache.poi.poifs.filesystem.Ole10Native;
32
import org.apache.poi.poifs.filesystem.Ole10Native;
33
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
33
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
34
import org.apache.poi.ss.usermodel.ClientAnchor;
34
import org.apache.poi.ss.usermodel.ClientAnchor.AnchorType;
35
import org.apache.poi.ss.usermodel.CreationHelper;
35
import org.apache.poi.ss.usermodel.CreationHelper;
36
import org.apache.poi.util.LocaleUtil;
36
import org.apache.poi.util.LocaleUtil;
37
import org.junit.Test;
37
import org.junit.Test;
Lines 88-112 Link Here
88
        CreationHelper ch = wb1.getCreationHelper();
88
        CreationHelper ch = wb1.getCreationHelper();
89
        HSSFClientAnchor anchor = (HSSFClientAnchor)ch.createClientAnchor();
89
        HSSFClientAnchor anchor = (HSSFClientAnchor)ch.createClientAnchor();
90
        anchor.setAnchor((short)(2+coloffset), 1+rowoffset, 0, 0, (short)(3+coloffset), 5+rowoffset, 0, 0);
90
        anchor.setAnchor((short)(2+coloffset), 1+rowoffset, 0, 0, (short)(3+coloffset), 5+rowoffset, 0, 0);
91
        anchor.setAnchorType(ClientAnchor.DONT_MOVE_AND_RESIZE);
91
        anchor.setAnchorType(AnchorType.DONT_MOVE_AND_RESIZE);
92
    	
92
    	
93
        patriarch.createObjectData(anchor, pptIdx, imgPPT);
93
        patriarch.createObjectData(anchor, pptIdx, imgPPT);
94
94
95
        anchor = (HSSFClientAnchor)ch.createClientAnchor();
95
        anchor = (HSSFClientAnchor)ch.createClientAnchor();
96
        anchor.setAnchor((short)(5+coloffset), 1+rowoffset, 0, 0, (short)(6+coloffset), 5+rowoffset, 0, 0);
96
        anchor.setAnchor((short)(5+coloffset), 1+rowoffset, 0, 0, (short)(6+coloffset), 5+rowoffset, 0, 0);
97
        anchor.setAnchorType(ClientAnchor.DONT_MOVE_AND_RESIZE);
97
        anchor.setAnchorType(AnchorType.DONT_MOVE_AND_RESIZE);
98
        
98
        
99
        patriarch.createObjectData(anchor, xlsIdx, imgIdx);
99
        patriarch.createObjectData(anchor, xlsIdx, imgIdx);
100
        
100
        
101
        anchor = (HSSFClientAnchor)ch.createClientAnchor();
101
        anchor = (HSSFClientAnchor)ch.createClientAnchor();
102
        anchor.setAnchor((short)(3+coloffset), 10+rowoffset, 0, 0, (short)(5+coloffset), 11+rowoffset, 0, 0);
102
        anchor.setAnchor((short)(3+coloffset), 10+rowoffset, 0, 0, (short)(5+coloffset), 11+rowoffset, 0, 0);
103
        anchor.setAnchorType(ClientAnchor.DONT_MOVE_AND_RESIZE);
103
        anchor.setAnchorType(AnchorType.DONT_MOVE_AND_RESIZE);
104
        
104
        
105
        patriarch.createObjectData(anchor, txtIdx, imgIdx);
105
        patriarch.createObjectData(anchor, txtIdx, imgIdx);
106
        
106
        
107
        anchor = (HSSFClientAnchor)ch.createClientAnchor();
107
        anchor = (HSSFClientAnchor)ch.createClientAnchor();
108
        anchor.setAnchor((short)(1+coloffset), -2+rowoffset, 0, 0, (short)(7+coloffset), 14+rowoffset, 0, 0);
108
        anchor.setAnchor((short)(1+coloffset), -2+rowoffset, 0, 0, (short)(7+coloffset), 14+rowoffset, 0, 0);
109
        anchor.setAnchorType(ClientAnchor.DONT_MOVE_AND_RESIZE);
109
        anchor.setAnchorType(AnchorType.DONT_MOVE_AND_RESIZE);
110
110
111
        HSSFSimpleShape circle = patriarch.createSimpleShape(anchor);
111
        HSSFSimpleShape circle = patriarch.createSimpleShape(anchor);
112
        circle.setShapeType(HSSFSimpleShape.OBJECT_TYPE_OVAL);
112
        circle.setShapeType(HSSFSimpleShape.OBJECT_TYPE_OVAL);
(-)src/examples/src/org/apache/poi/hssf/usermodel/examples/AddDimensionedImage.java (-1 / +2 lines)
Lines 31-36 Link Here
31
import org.apache.poi.hssf.usermodel.HSSFClientAnchor;
31
import org.apache.poi.hssf.usermodel.HSSFClientAnchor;
32
import org.apache.poi.hssf.usermodel.HSSFPatriarch;
32
import org.apache.poi.hssf.usermodel.HSSFPatriarch;
33
import org.apache.poi.hssf.util.CellReference;
33
import org.apache.poi.hssf.util.CellReference;
34
import org.apache.poi.ss.usermodel.ClientAnchor.AnchorType;
34
35
35
36
36
/**
37
/**
Lines 291-297 Link Here
291
        // image as the size of the row/column is adjusted. This could easilly
292
        // image as the size of the row/column is adjusted. This could easilly
292
        // become another parameter passed to the method.
293
        // become another parameter passed to the method.
293
        //anchor.setAnchorType(HSSFClientAnchor.DONT_MOVE_AND_RESIZE);
294
        //anchor.setAnchorType(HSSFClientAnchor.DONT_MOVE_AND_RESIZE);
294
        anchor.setAnchorType(HSSFClientAnchor.MOVE_AND_RESIZE);
295
        anchor.setAnchorType(AnchorType.MOVE_AND_RESIZE);
295
        
296
        
296
        // Now, add the picture to the workbook. Note that the type is assumed
297
        // Now, add the picture to the workbook. Note that the type is assumed
297
        // to be a JPEG/JPG, this could easily (and should) be parameterised
298
        // to be a JPEG/JPG, this could easily (and should) be parameterised
(-)src/examples/src/org/apache/poi/hssf/usermodel/examples/OfficeDrawing.java (-3 / +4 lines)
Lines 18-23 Link Here
18
package org.apache.poi.hssf.usermodel.examples;
18
package org.apache.poi.hssf.usermodel.examples;
19
19
20
import org.apache.poi.hssf.usermodel.*;
20
import org.apache.poi.hssf.usermodel.*;
21
import org.apache.poi.ss.usermodel.ClientAnchor.AnchorType;
21
22
22
import java.io.*;
23
import java.io.*;
23
24
Lines 152-166 Link Here
152
153
153
        HSSFClientAnchor anchor;
154
        HSSFClientAnchor anchor;
154
        anchor = new HSSFClientAnchor(0,0,0,255,(short)2,2,(short)4,7);
155
        anchor = new HSSFClientAnchor(0,0,0,255,(short)2,2,(short)4,7);
155
        anchor.setAnchorType( 2 );
156
        anchor.setAnchorType( AnchorType.MOVE_DONT_RESIZE );
156
        patriarch.createPicture(anchor, loadPicture( "src/resources/logos/logoKarmokar4.png", wb ));
157
        patriarch.createPicture(anchor, loadPicture( "src/resources/logos/logoKarmokar4.png", wb ));
157
158
158
        anchor = new HSSFClientAnchor(0,0,0,255,(short)4,2,(short)5,7);
159
        anchor = new HSSFClientAnchor(0,0,0,255,(short)4,2,(short)5,7);
159
        anchor.setAnchorType( 2 );
160
        anchor.setAnchorType( AnchorType.MOVE_DONT_RESIZE );
160
        patriarch.createPicture(anchor, loadPicture( "src/resources/logos/logoKarmokar4edited.png", wb ));
161
        patriarch.createPicture(anchor, loadPicture( "src/resources/logos/logoKarmokar4edited.png", wb ));
161
162
162
        anchor = new HSSFClientAnchor(0,0,1023,255,(short)6,2,(short)8,7);
163
        anchor = new HSSFClientAnchor(0,0,1023,255,(short)6,2,(short)8,7);
163
        anchor.setAnchorType( 2 );
164
        anchor.setAnchorType( AnchorType.MOVE_DONT_RESIZE );
164
        HSSFPicture picture = patriarch.createPicture(anchor, loadPicture( "src/resources/logos/logoKarmokar4s.png", wb ));
165
        HSSFPicture picture = patriarch.createPicture(anchor, loadPicture( "src/resources/logos/logoKarmokar4s.png", wb ));
165
        //Reset the image to the original size.
166
        //Reset the image to the original size.
166
        picture.resize();
167
        picture.resize();
(-)src/examples/src/org/apache/poi/ss/examples/AddDimensionedImage.java (-4 / +5 lines)
Lines 28-33 Link Here
28
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
28
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
29
import org.apache.poi.hssf.usermodel.HSSFSheet;
29
import org.apache.poi.hssf.usermodel.HSSFSheet;
30
import org.apache.poi.ss.usermodel.ClientAnchor;
30
import org.apache.poi.ss.usermodel.ClientAnchor;
31
import org.apache.poi.ss.usermodel.ClientAnchor.AnchorType;
31
import org.apache.poi.ss.usermodel.Drawing;
32
import org.apache.poi.ss.usermodel.Drawing;
32
import org.apache.poi.ss.usermodel.Row;
33
import org.apache.poi.ss.usermodel.Row;
33
import org.apache.poi.ss.usermodel.Sheet;
34
import org.apache.poi.ss.usermodel.Sheet;
Lines 373-382 Link Here
373
        anchor.setRow2(rowClientAnchorDetail.getToIndex());
374
        anchor.setRow2(rowClientAnchorDetail.getToIndex());
374
375
375
        // For now, set the anchor type to do not move or resize the
376
        // For now, set the anchor type to do not move or resize the
376
        // image as the size of the row/column is adjusted. This could easilly
377
        // image as the size of the row/column is adjusted. This could easily
377
        // become another parameter passed to the method. Please read the note
378
        // become another parameter passed to the method. Please read the note
378
        // above regarding the behaviour of image resizing.
379
        // above regarding the behaviour of image resizing.
379
        anchor.setAnchorType(ClientAnchor.MOVE_AND_RESIZE);
380
        anchor.setAnchorType(AnchorType.MOVE_AND_RESIZE);
380
381
381
        // Now, add the picture to the workbook. Note that unlike the similar
382
        // Now, add the picture to the workbook. Note that unlike the similar
382
        // method in the HSSF Examples section, the image type is checked. First,
383
        // method in the HSSF Examples section, the image type is checked. First,
Lines 400-406 Link Here
400
    }
401
    }
401
402
402
    /**
403
    /**
403
     * Determines whether the sheets columns should be re-sized to accomodate
404
     * Determines whether the sheets columns should be re-sized to accommodate
404
     * the image, adjusts the columns width if necessary and creates then
405
     * the image, adjusts the columns width if necessary and creates then
405
     * returns a ClientAnchorDetail object that facilitates construction of
406
     * returns a ClientAnchorDetail object that facilitates construction of
406
     * an ClientAnchor that will fix the image on the sheet and establish
407
     * an ClientAnchor that will fix the image on the sheet and establish
Lines 407-413 Link Here
407
     * it's size.
408
     * it's size.
408
     *
409
     *
409
     * @param sheet A reference to the sheet that will 'contain' the image.
410
     * @param sheet A reference to the sheet that will 'contain' the image.
410
     * @param colNumber A primtive int that contains the index number of a
411
     * @param colNumber A primitive int that contains the index number of a
411
     *                  column on the sheet.
412
     *                  column on the sheet.
412
     * @param reqImageWidthMM A primitive double that contains the required
413
     * @param reqImageWidthMM A primitive double that contains the required
413
     *                        width of the image in millimetres
414
     *                        width of the image in millimetres

Return to bug 58636