git-svn-id: https://svn.apache.org/repos/asf/poi/branches/gsoc2012@1364547 13f79535-47bb-0310-9956-ffa450edef68tags/3.10-beta1
* | * | ||||
* @author Glen Stampoultzis (glens at apache.org) | * @author Glen Stampoultzis (glens at apache.org) | ||||
*/ | */ | ||||
@Deprecated | |||||
public abstract class AbstractShape | public abstract class AbstractShape | ||||
{ | { | ||||
/** | /** |
* | * | ||||
* @author Yegor Kozlov | * @author Yegor Kozlov | ||||
*/ | */ | ||||
@Deprecated | |||||
public class ComboboxShape | public class ComboboxShape | ||||
extends AbstractShape { | extends AbstractShape { | ||||
private EscherContainerRecord spContainer; | private EscherContainerRecord spContainer; |
* | * | ||||
* @author Yegor Kozlov | * @author Yegor Kozlov | ||||
*/ | */ | ||||
@Deprecated | |||||
public final class CommentShape extends TextboxShape { | public final class CommentShape extends TextboxShape { | ||||
private NoteRecord _note; | private NoteRecord _note; |
* | * | ||||
* @author Glen Stampoultzis (glens at apache.org) | * @author Glen Stampoultzis (glens at apache.org) | ||||
*/ | */ | ||||
@Deprecated | |||||
public class LineShape | public class LineShape | ||||
extends AbstractShape | extends AbstractShape | ||||
{ | { |
import org.apache.poi.hssf.usermodel.HSSFPolygon; | import org.apache.poi.hssf.usermodel.HSSFPolygon; | ||||
import org.apache.poi.util.LittleEndian; | import org.apache.poi.util.LittleEndian; | ||||
@Deprecated | |||||
public class PolygonShape | public class PolygonShape | ||||
extends AbstractShape | extends AbstractShape | ||||
{ | { |
import org.apache.poi.hssf.usermodel.HSSFSimpleShape; | import org.apache.poi.hssf.usermodel.HSSFSimpleShape; | ||||
import org.apache.poi.hssf.usermodel.HSSFShape; | import org.apache.poi.hssf.usermodel.HSSFShape; | ||||
@Deprecated | |||||
public class SimpleFilledShape | public class SimpleFilledShape | ||||
extends AbstractShape | extends AbstractShape | ||||
{ | { |
* | * | ||||
* @author Glen Stampoultzis (glens at apache.org) | * @author Glen Stampoultzis (glens at apache.org) | ||||
*/ | */ | ||||
@Deprecated | |||||
public class TextboxShape | public class TextboxShape | ||||
extends AbstractShape | extends AbstractShape | ||||
{ | { |
_sheet.getDrawingPatriarch().removeShape(comment); | _sheet.getDrawingPatriarch().removeShape(comment); | ||||
} | } | ||||
/** | |||||
* Cell comment finder. | |||||
* Returns cell comment for the specified sheet, row and column. | |||||
* | |||||
* @return cell comment or <code>null</code> if not found | |||||
*/ | |||||
protected static HSSFComment findCellComment(InternalSheet sheet, int row, int column) { | |||||
// TODO - optimise this code by searching backwards, find NoteRecord first, quit if not found. Find one TXO by id | |||||
HSSFComment comment = null; | |||||
Map<Integer, TextObjectRecord> noteTxo = | |||||
new HashMap<Integer, TextObjectRecord>(); | |||||
int i = 0; | |||||
for (Iterator<RecordBase> it = sheet.getRecords().iterator(); it.hasNext();) { | |||||
RecordBase rec = it.next(); | |||||
if (rec instanceof NoteRecord) { | |||||
NoteRecord note = (NoteRecord) rec; | |||||
if (note.getRow() == row && note.getColumn() == column) { | |||||
if(i < noteTxo.size()) { | |||||
TextObjectRecord txo = noteTxo.get(note.getShapeId()); | |||||
if(txo != null){ | |||||
comment = new HSSFComment(note, txo); | |||||
comment.setRow(note.getRow()); | |||||
comment.setColumn(note.getColumn()); | |||||
comment.setAuthor(note.getAuthor()); | |||||
comment.setVisible(note.getFlags() == NoteRecord.NOTE_VISIBLE); | |||||
comment.setString(txo.getStr()); | |||||
} else{ | |||||
log.log(POILogger.WARN, "Failed to match NoteRecord and TextObjectRecord, row: " + row + ", column: " + column); | |||||
} | |||||
} else { | |||||
log.log(POILogger.WARN, "Failed to match NoteRecord and TextObjectRecord, row: " + row + ", column: " + column); | |||||
} | |||||
break; | |||||
} | |||||
i++; | |||||
} else if (rec instanceof ObjRecord) { | |||||
ObjRecord obj = (ObjRecord) rec; | |||||
SubRecord sub = obj.getSubRecords().get(0); | |||||
if (sub instanceof CommonObjectDataSubRecord) { | |||||
CommonObjectDataSubRecord cmo = (CommonObjectDataSubRecord) sub; | |||||
if (cmo.getObjectType() == CommonObjectDataSubRecord.OBJECT_TYPE_COMMENT) { | |||||
//map ObjectId and corresponding TextObjectRecord, | |||||
//it will be used to match NoteRecord and TextObjectRecord | |||||
while (it.hasNext()) { | |||||
rec = it.next(); | |||||
if (rec instanceof TextObjectRecord) { | |||||
noteTxo.put(cmo.getObjectId(), (TextObjectRecord) rec); | |||||
break; | |||||
} | |||||
} | |||||
} | |||||
} | |||||
} | |||||
} | |||||
return comment; | |||||
} | |||||
/** | /** | ||||
* @return hyperlink associated with this cell or <code>null</code> if not found | * @return hyperlink associated with this cell or <code>null</code> if not found | ||||
*/ | */ |
* | * | ||||
* @author Daniel Noll | * @author Daniel Noll | ||||
*/ | */ | ||||
public final class HSSFObjectData extends HSSFShape { | |||||
public final class HSSFObjectData extends HSSFPicture { | |||||
/** | /** | ||||
* Reference to the filesystem root, required for retrieving the object data. | * Reference to the filesystem root, required for retrieving the object data. | ||||
*/ | */ | ||||
EscherAggregate agg = patriarch._getBoundAggregate(); | EscherAggregate agg = patriarch._getBoundAggregate(); | ||||
agg.associateShapeToObjRecord(getEscherContainer().getChildById(EscherClientDataRecord.RECORD_ID), getObjRecord()); | agg.associateShapeToObjRecord(getEscherContainer().getChildById(EscherClientDataRecord.RECORD_ID), getObjRecord()); | ||||
EscherBSERecord bse = | EscherBSERecord bse = | ||||
patriarch._sheet.getWorkbook().getWorkbook().getBSERecord(getPictureIndex()); | |||||
patriarch.getSheet().getWorkbook().getWorkbook().getBSERecord(getPictureIndex()); | |||||
bse.setRef(bse.getRef() + 1); | bse.setRef(bse.getRef() + 1); | ||||
} | } | ||||
ObjRecord obj = (ObjRecord) getObjRecord().cloneViaReserialise(); | ObjRecord obj = (ObjRecord) getObjRecord().cloneViaReserialise(); | ||||
return new HSSFObjectData(spContainer, obj, _root); | return new HSSFObjectData(spContainer, obj, _root); | ||||
} | } | ||||
public int getPictureIndex() { | |||||
EscherSimpleProperty property = getOptRecord().lookup(EscherProperties.BLIP__BLIPTODISPLAY); | |||||
if (null == property) { | |||||
return -1; | |||||
} | |||||
return property.getPropertyValue(); | |||||
} | |||||
public void setPictureIndex(int pictureIndex) { | |||||
setPropertyValue(new EscherSimpleProperty(EscherProperties.BLIP__BLIPTODISPLAY, false, true, pictureIndex)); | |||||
} | |||||
@Override | |||||
void setShapeId(int shapeId) { | |||||
EscherSpRecord spRecord = getEscherContainer().getChildById(EscherSpRecord.RECORD_ID); | |||||
spRecord.setShapeId(shapeId); | |||||
CommonObjectDataSubRecord cod = (CommonObjectDataSubRecord) getObjRecord().getSubRecords().get(0); | |||||
cod.setObjectId((short) (shapeId % 1024)); | |||||
} | |||||
} | } |
package org.apache.poi.hssf.usermodel; | package org.apache.poi.hssf.usermodel; | ||||
import java.util.ArrayList; | import java.util.ArrayList; | ||||
import java.util.Collections; | |||||
import java.util.Iterator; | import java.util.Iterator; | ||||
import java.util.List; | import java.util.List; | ||||
* and building up our shapes from the records) | * and building up our shapes from the records) | ||||
*/ | */ | ||||
private EscherAggregate _boundAggregate; | private EscherAggregate _boundAggregate; | ||||
final HSSFSheet _sheet; // TODO make private | |||||
private final HSSFSheet _sheet; | |||||
/** | /** | ||||
* Creates the patriarch. | * Creates the patriarch. | ||||
addShape(shape); | addShape(shape); | ||||
//open existing file | //open existing file | ||||
onCreate(shape); | onCreate(shape); | ||||
EscherSpRecord sp = shape.getEscherContainer().getChildById(EscherSpRecord.RECORD_ID); | |||||
if (shape.anchor.isHorizontallyFlipped()) { | |||||
sp.setFlags(sp.getFlags() | EscherSpRecord.FLAG_FLIPHORIZ); | |||||
} | |||||
if (shape.anchor.isVerticallyFlipped()) { | |||||
sp.setFlags(sp.getFlags() | EscherSpRecord.FLAG_FLIPVERT); | |||||
} | |||||
return shape; | return shape; | ||||
} | } | ||||
addShape(shape); | addShape(shape); | ||||
//open existing file | //open existing file | ||||
onCreate(shape); | onCreate(shape); | ||||
EscherSpRecord sp = shape.getEscherContainer().getChildById(EscherSpRecord.RECORD_ID); | |||||
if (shape.anchor.isHorizontallyFlipped()) { | |||||
sp.setFlags(sp.getFlags() | EscherSpRecord.FLAG_FLIPHORIZ); | |||||
} | |||||
if (shape.anchor.isVerticallyFlipped()) { | |||||
sp.setFlags(sp.getFlags() | EscherSpRecord.FLAG_FLIPVERT); | |||||
} | |||||
return shape; | return shape; | ||||
} | } | ||||
* Returns a list of all shapes contained by the patriarch. | * Returns a list of all shapes contained by the patriarch. | ||||
*/ | */ | ||||
public List<HSSFShape> getChildren() { | public List<HSSFShape> getChildren() { | ||||
return _shapes; | |||||
return Collections.unmodifiableList(_shapes); | |||||
} | } | ||||
/** | /** | ||||
spgrContainer.addChildRecord(spContainer); | spgrContainer.addChildRecord(spContainer); | ||||
shape.afterInsert(this); | shape.afterInsert(this); | ||||
setFlipFlags(shape); | |||||
} | } | ||||
/** | /** | ||||
_spgrRecord.setRectX2(x2); | _spgrRecord.setRectX2(x2); | ||||
} | } | ||||
public void clear() { | |||||
ArrayList <HSSFShape> copy = new ArrayList<HSSFShape>(_shapes); | |||||
for (HSSFShape shape: copy){ | |||||
removeShape(shape); | |||||
} | |||||
} | |||||
int newShapeId() { | int newShapeId() { | ||||
DrawingManager2 dm = _sheet.getWorkbook().getWorkbook().getDrawingManager(); | DrawingManager2 dm = _sheet.getWorkbook().getWorkbook().getDrawingManager(); | ||||
EscherDgRecord dg = | EscherDgRecord dg = | ||||
} | } | ||||
} | } | ||||
} | } | ||||
private void setFlipFlags(HSSFShape shape){ | |||||
EscherSpRecord sp = shape.getEscherContainer().getChildById(EscherSpRecord.RECORD_ID); | |||||
if (shape.anchor.isHorizontallyFlipped()) { | |||||
sp.setFlags(sp.getFlags() | EscherSpRecord.FLAG_FLIPHORIZ); | |||||
} | |||||
if (shape.anchor.isVerticallyFlipped()) { | |||||
sp.setFlags(sp.getFlags() | EscherSpRecord.FLAG_FLIPVERT); | |||||
} | |||||
} | |||||
public Iterator<HSSFShape> iterator() { | |||||
return _shapes.iterator(); | |||||
} | |||||
protected HSSFSheet getSheet() { | |||||
return _sheet; | |||||
} | |||||
} | } |
* @author Glen Stampoultzis | * @author Glen Stampoultzis | ||||
* @author Yegor Kozlov (yegor at apache.org) | * @author Yegor Kozlov (yegor at apache.org) | ||||
*/ | */ | ||||
public final class HSSFPicture extends HSSFSimpleShape implements Picture { | |||||
public class HSSFPicture extends HSSFSimpleShape implements Picture { | |||||
public static final int PICTURE_TYPE_EMF = HSSFWorkbook.PICTURE_TYPE_EMF; // Windows Enhanced Metafile | public static final int PICTURE_TYPE_EMF = HSSFWorkbook.PICTURE_TYPE_EMF; // Windows Enhanced Metafile | ||||
public static final int PICTURE_TYPE_WMF = HSSFWorkbook.PICTURE_TYPE_WMF; // Windows Metafile | public static final int PICTURE_TYPE_WMF = HSSFWorkbook.PICTURE_TYPE_WMF; // Windows Metafile | ||||
public static final int PICTURE_TYPE_PICT = HSSFWorkbook.PICTURE_TYPE_PICT; // Macintosh PICT | public static final int PICTURE_TYPE_PICT = HSSFWorkbook.PICTURE_TYPE_PICT; // Macintosh PICT | ||||
private float getColumnWidthInPixels(int column){ | private float getColumnWidthInPixels(int column){ | ||||
int cw = _patriarch._sheet.getColumnWidth(column); | |||||
int cw = _patriarch.getSheet().getColumnWidth(column); | |||||
float px = getPixelWidth(column); | float px = getPixelWidth(column); | ||||
return cw/px; | return cw/px; | ||||
private float getRowHeightInPixels(int i){ | private float getRowHeightInPixels(int i){ | ||||
HSSFRow row = _patriarch._sheet.getRow(i); | |||||
HSSFRow row = _patriarch.getSheet().getRow(i); | |||||
float height; | float height; | ||||
if(row != null) height = row.getHeight(); | if(row != null) height = row.getHeight(); | ||||
else height = _patriarch._sheet.getDefaultRowHeight(); | |||||
else height = _patriarch.getSheet().getDefaultRowHeight(); | |||||
return height/PX_ROW; | return height/PX_ROW; | ||||
} | } | ||||
private float getPixelWidth(int column){ | private float getPixelWidth(int column){ | ||||
int def = _patriarch._sheet.getDefaultColumnWidth()*256; | |||||
int cw = _patriarch._sheet.getColumnWidth(column); | |||||
int def = _patriarch.getSheet().getDefaultColumnWidth()*256; | |||||
int cw = _patriarch.getSheet().getColumnWidth(column); | |||||
return cw == def ? PX_DEFAULT : PX_MODIFIED; | return cw == def ? PX_DEFAULT : PX_MODIFIED; | ||||
} | } | ||||
* @return image dimension | * @return image dimension | ||||
*/ | */ | ||||
public Dimension getImageDimension(){ | public Dimension getImageDimension(){ | ||||
EscherBSERecord bse = _patriarch._sheet._book.getBSERecord(getPictureIndex()); | |||||
EscherBSERecord bse = _patriarch.getSheet()._book.getBSERecord(getPictureIndex()); | |||||
byte[] data = bse.getBlipRecord().getPicturedata(); | byte[] data = bse.getBlipRecord().getPicturedata(); | ||||
int type = bse.getBlipTypeWin32(); | int type = bse.getBlipTypeWin32(); | ||||
return ImageUtils.getImageDimension(new ByteArrayInputStream(data), type); | return ImageUtils.getImageDimension(new ByteArrayInputStream(data), type); | ||||
* @return picture data for this shape | * @return picture data for this shape | ||||
*/ | */ | ||||
public HSSFPictureData getPictureData(){ | public HSSFPictureData getPictureData(){ | ||||
InternalWorkbook iwb = _patriarch._sheet.getWorkbook().getWorkbook(); | |||||
InternalWorkbook iwb = _patriarch.getSheet().getWorkbook().getWorkbook(); | |||||
EscherBlipRecord blipRecord = iwb.getBSERecord(getPictureIndex()).getBlipRecord(); | EscherBlipRecord blipRecord = iwb.getBSERecord(getPictureIndex()).getBlipRecord(); | ||||
return new HSSFPictureData(blipRecord); | return new HSSFPictureData(blipRecord); | ||||
} | } | ||||
EscherAggregate agg = patriarch._getBoundAggregate(); | EscherAggregate agg = patriarch._getBoundAggregate(); | ||||
agg.associateShapeToObjRecord(getEscherContainer().getChildById(EscherClientDataRecord.RECORD_ID), getObjRecord()); | agg.associateShapeToObjRecord(getEscherContainer().getChildById(EscherClientDataRecord.RECORD_ID), getObjRecord()); | ||||
EscherBSERecord bse = | EscherBSERecord bse = | ||||
patriarch._sheet.getWorkbook().getWorkbook().getBSERecord(getPictureIndex()); | |||||
patriarch.getSheet().getWorkbook().getWorkbook().getBSERecord(getPictureIndex()); | |||||
bse.setRef(bse.getRef() + 1); | bse.setRef(bse.getRef() + 1); | ||||
} | } | ||||
/** | /** | ||||
* The color applied to the lines of this shape. | * The color applied to the lines of this shape. | ||||
*/ | */ | ||||
public String getAdditionalData() { | |||||
public String getFileName() { | |||||
EscherComplexProperty propFile = (EscherComplexProperty) getOptRecord().lookup( | EscherComplexProperty propFile = (EscherComplexProperty) getOptRecord().lookup( | ||||
EscherProperties.BLIP__BLIPFILENAME); | EscherProperties.BLIP__BLIPFILENAME); | ||||
try { | try { | ||||
} | } | ||||
} | } | ||||
public void setAdditionalData(String data){ | |||||
public void setFileName(String data){ | |||||
try { | try { | ||||
EscherComplexProperty prop = new EscherComplexProperty(EscherProperties.BLIP__BLIPFILENAME, true, data.getBytes("UTF-16LE")); | EscherComplexProperty prop = new EscherComplexProperty(EscherProperties.BLIP__BLIPFILENAME, true, data.getBytes("UTF-16LE")); | ||||
setPropertyValue(prop); | setPropertyValue(prop); |
import org.apache.poi.ddf.*; | import org.apache.poi.ddf.*; | ||||
import org.apache.poi.hssf.record.CommonObjectDataSubRecord; | import org.apache.poi.hssf.record.CommonObjectDataSubRecord; | ||||
import org.apache.poi.hssf.record.ObjRecord; | import org.apache.poi.hssf.record.ObjRecord; | ||||
import org.apache.poi.util.LittleEndian; | |||||
import java.io.ByteArrayOutputStream; | |||||
import java.io.IOException; | |||||
import java.util.Iterator; | import java.util.Iterator; | ||||
/** | /** | ||||
EscherSpRecord spRecord = _escherContainer.getChildById(EscherSpRecord.RECORD_ID); | EscherSpRecord spRecord = _escherContainer.getChildById(EscherSpRecord.RECORD_ID); | ||||
spRecord.setShapeId(shapeId); | spRecord.setShapeId(shapeId); | ||||
CommonObjectDataSubRecord cod = (CommonObjectDataSubRecord) _objRecord.getSubRecords().get(0); | CommonObjectDataSubRecord cod = (CommonObjectDataSubRecord) _objRecord.getSubRecords().get(0); | ||||
cod.setObjectId((short) (shapeId-1024)); | |||||
cod.setObjectId((short) (shapeId%1024)); | |||||
} | } | ||||
int getShapeId(){ | int getShapeId(){ | ||||
protected void setPropertyValue(EscherProperty property){ | protected void setPropertyValue(EscherProperty property){ | ||||
_optRecord.setEscherProperty(property); | _optRecord.setEscherProperty(property); | ||||
} | } | ||||
public void setFlipVertical(boolean value){ | |||||
EscherSpRecord sp = getEscherContainer().getChildById(EscherSpRecord.RECORD_ID); | |||||
if (value){ | |||||
sp.setFlags(sp.getFlags() | EscherSpRecord.FLAG_FLIPVERT); | |||||
} else { | |||||
sp.setFlags(sp.getFlags() & (Integer.MAX_VALUE - EscherSpRecord.FLAG_FLIPVERT)); | |||||
} | |||||
} | |||||
public void setFlipHorizontal(boolean value){ | |||||
EscherSpRecord sp = getEscherContainer().getChildById(EscherSpRecord.RECORD_ID); | |||||
if (value){ | |||||
sp.setFlags(sp.getFlags() | EscherSpRecord.FLAG_FLIPHORIZ); | |||||
} else { | |||||
sp.setFlags(sp.getFlags() & (Integer.MAX_VALUE - EscherSpRecord.FLAG_FLIPHORIZ)); | |||||
} | |||||
} | |||||
public boolean isFlipVertical(){ | |||||
EscherSpRecord sp = getEscherContainer().getChildById(EscherSpRecord.RECORD_ID); | |||||
return (sp.getFlags() & EscherSpRecord.FLAG_FLIPVERT) != 0; | |||||
} | |||||
public boolean isFlipHorizontal(){ | |||||
EscherSpRecord sp = getEscherContainer().getChildById(EscherSpRecord.RECORD_ID); | |||||
return (sp.getFlags() & EscherSpRecord.FLAG_FLIPHORIZ) != 0; | |||||
} | |||||
public int getRotationDegree(){ | |||||
ByteArrayOutputStream bos = new ByteArrayOutputStream(); | |||||
EscherSimpleProperty property = getOptRecord().lookup(EscherProperties.TRANSFORM__ROTATION); | |||||
if (null == property){ | |||||
return 0; | |||||
} | |||||
try { | |||||
LittleEndian.putInt(property.getPropertyValue(), bos); | |||||
return LittleEndian.getShort(bos.toByteArray(), 2); | |||||
} catch (IOException e) { | |||||
e.printStackTrace(); | |||||
return 0; | |||||
} | |||||
} | |||||
public void setRotationDegree(short value){ | |||||
setPropertyValue(new EscherSimpleProperty(EscherProperties.TRANSFORM__ROTATION , (value << 16))); | |||||
} | |||||
/** | /** | ||||
* Count of all children and their children's children. | * Count of all children and their children's children. |
* | * | ||||
* @author Glen Stampoultzis (glens at apache.org) | * @author Glen Stampoultzis (glens at apache.org) | ||||
*/ | */ | ||||
public interface HSSFShapeContainer | |||||
public interface HSSFShapeContainer extends Iterable<HSSFShape> | |||||
{ | { | ||||
/** | /** | ||||
* @return Any children contained by this shape. | * @return Any children contained by this shape. | ||||
*/ | */ | ||||
List getChildren(); | |||||
List<HSSFShape> getChildren(); | |||||
/** | /** | ||||
* add shape to the list of child records | * add shape to the list of child records | ||||
*/ | */ | ||||
void setCoordinates( int x1, int y1, int x2, int y2 ); | void setCoordinates( int x1, int y1, int x2, int y2 ); | ||||
void clear(); | |||||
public int getX1(); | |||||
public int getY1(); | |||||
public int getX2(); | |||||
public int getY2(); | |||||
} | } |
package org.apache.poi.hssf.usermodel; | package org.apache.poi.hssf.usermodel; | ||||
import org.apache.poi.ddf.*; | import org.apache.poi.ddf.*; | ||||
import org.apache.poi.hssf.model.TextboxShape; | |||||
import org.apache.poi.hssf.record.*; | import org.apache.poi.hssf.record.*; | ||||
import java.util.ArrayList; | import java.util.ArrayList; | ||||
import java.util.Collections; | |||||
import java.util.List; | import java.util.List; | ||||
import java.util.Iterator; | import java.util.Iterator; | ||||
* @author Glen Stampoultzis (glens at apache.org) | * @author Glen Stampoultzis (glens at apache.org) | ||||
*/ | */ | ||||
public class HSSFShapeGroup extends HSSFShape implements HSSFShapeContainer { | public class HSSFShapeGroup extends HSSFShape implements HSSFShapeContainer { | ||||
List<HSSFShape> shapes = new ArrayList<HSSFShape>(); | |||||
private final List<HSSFShape> shapes = new ArrayList<HSSFShape>(); | |||||
private EscherSpgrRecord _spgrRecord; | private EscherSpgrRecord _spgrRecord; | ||||
public HSSFShapeGroup(EscherContainerRecord spgrContainer, ObjRecord objRecord) { | public HSSFShapeGroup(EscherContainerRecord spgrContainer, ObjRecord objRecord) { | ||||
shapes.add(shape); | shapes.add(shape); | ||||
} | } | ||||
public void addTextBox(TextboxShape textboxShape) { | |||||
// HSSFTextbox shape = new HSSFTextbox(this, textboxShape.geanchor); | |||||
// shapes.add(textboxShape); | |||||
} | |||||
/** | /** | ||||
* Create a new simple shape under this group. | * Create a new simple shape under this group. | ||||
* | * | ||||
* Return all children contained by this shape. | * Return all children contained by this shape. | ||||
*/ | */ | ||||
public List<HSSFShape> getChildren() { | public List<HSSFShape> getChildren() { | ||||
return shapes; | |||||
return Collections.unmodifiableList(shapes); | |||||
} | } | ||||
/** | /** | ||||
_spgrRecord.setRectY2(y2); | _spgrRecord.setRectY2(y2); | ||||
} | } | ||||
public void clear() { | |||||
ArrayList <HSSFShape> copy = new ArrayList<HSSFShape>(shapes); | |||||
for (HSSFShape shape: copy){ | |||||
removeShape(shape); | |||||
} | |||||
} | |||||
/** | /** | ||||
* The top left x coordinate of this group. | * The top left x coordinate of this group. | ||||
*/ | */ | ||||
} | } | ||||
return isRemoved; | return isRemoved; | ||||
} | } | ||||
public Iterator<HSSFShape> iterator() { | |||||
return shapes.iterator(); | |||||
} | |||||
} | } |
// If font is not set we must set the default one | // If font is not set we must set the default one | ||||
if (rtr.numFormattingRuns() == 0) rtr.applyFont((short) 0); | if (rtr.numFormattingRuns() == 0) rtr.applyFont((short) 0); | ||||
_textObjectRecord.setStr(rtr); | _textObjectRecord.setStr(rtr); | ||||
if (string.getString() != null){ | |||||
setPropertyValue(new EscherSimpleProperty(EscherProperties.TEXT__TEXTID, string.getString().hashCode())); | |||||
} | |||||
} | } | ||||
@Override | @Override |
return spContainer; | return spContainer; | ||||
} | } | ||||
@Override | |||||
public void setString(RichTextString string) { | |||||
HSSFRichTextString rtr = (HSSFRichTextString) string; | |||||
// If font is not set we must set the default one | |||||
if (rtr.numFormattingRuns() == 0) rtr.applyFont((short) 0); | |||||
getTextObjectRecord().setStr(rtr); | |||||
} | |||||
@Override | @Override | ||||
void afterInsert(HSSFPatriarch patriarch) { | void afterInsert(HSSFPatriarch patriarch) { | ||||
EscherAggregate agg = patriarch._getBoundAggregate(); | EscherAggregate agg = patriarch._getBoundAggregate(); |
rectangle.setNoFill(true); | rectangle.setNoFill(true); | ||||
rectangle.setString(new HSSFRichTextString("teeeest")); | rectangle.setString(new HSSFRichTextString("teeeest")); | ||||
assertEquals(rectangle.getLineStyleColor(), 1111); | assertEquals(rectangle.getLineStyleColor(), 1111); | ||||
assertEquals(((EscherSimpleProperty)((EscherOptRecord)rectangle.getEscherContainer().getChildById(EscherOptRecord.RECORD_ID)) | |||||
.lookup(EscherProperties.TEXT__TEXTID)).getPropertyValue(), "teeeest".hashCode()); | |||||
assertEquals(rectangle.isNoFill(), true); | assertEquals(rectangle.isNoFill(), true); | ||||
assertEquals(rectangle.getString().getString(), "teeeest"); | assertEquals(rectangle.getString().getString(), "teeeest"); | ||||
assertEquals(HexDump.toHex(shape.getFillColor()), shape.getFillColor(), 0x2CE03D); | assertEquals(HexDump.toHex(shape.getFillColor()), shape.getFillColor(), 0x2CE03D); | ||||
assertEquals(shape.getLineWidth(), HSSFShape.LINEWIDTH_ONE_PT * 2); | assertEquals(shape.getLineWidth(), HSSFShape.LINEWIDTH_ONE_PT * 2); | ||||
assertEquals(shape.getString().getString(), "POItest"); | assertEquals(shape.getString().getString(), "POItest"); | ||||
assertEquals(shape.getRotationDegree(), 27); | |||||
} | } | ||||
public void testShapeIds() { | public void testShapeIds() { | ||||
assertEquals(HSSFTestHelper.getEscherAggregate(patriarch).getTailRecords().size(), 0); | assertEquals(HSSFTestHelper.getEscherAggregate(patriarch).getTailRecords().size(), 0); | ||||
assertEquals(patriarch.getChildren().size(), 0); | assertEquals(patriarch.getChildren().size(), 0); | ||||
} | } | ||||
public void testShapeFlip(){ | |||||
HSSFWorkbook wb = new HSSFWorkbook(); | |||||
HSSFSheet sheet = wb.createSheet(); | |||||
HSSFPatriarch patriarch = sheet.createDrawingPatriarch(); | |||||
HSSFSimpleShape rectangle = patriarch.createSimpleShape(new HSSFClientAnchor()); | |||||
rectangle.setShapeType(HSSFSimpleShape.OBJECT_TYPE_RECTANGLE); | |||||
assertEquals(rectangle.isFlipVertical(), false); | |||||
assertEquals(rectangle.isFlipHorizontal(), false); | |||||
rectangle.setFlipVertical(true); | |||||
assertEquals(rectangle.isFlipVertical(), true); | |||||
rectangle.setFlipHorizontal(true); | |||||
assertEquals(rectangle.isFlipHorizontal(), true); | |||||
wb = HSSFTestDataSamples.writeOutAndReadBack(wb); | |||||
sheet = wb.getSheetAt(0); | |||||
patriarch = sheet.getDrawingPatriarch(); | |||||
rectangle = (HSSFSimpleShape) patriarch.getChildren().get(0); | |||||
assertEquals(rectangle.isFlipHorizontal(), true); | |||||
rectangle.setFlipHorizontal(false); | |||||
assertEquals(rectangle.isFlipHorizontal(), false); | |||||
assertEquals(rectangle.isFlipVertical(), true); | |||||
rectangle.setFlipVertical(false); | |||||
assertEquals(rectangle.isFlipVertical(), false); | |||||
wb = HSSFTestDataSamples.writeOutAndReadBack(wb); | |||||
sheet = wb.getSheetAt(0); | |||||
patriarch = sheet.getDrawingPatriarch(); | |||||
rectangle = (HSSFSimpleShape) patriarch.getChildren().get(0); | |||||
assertEquals(rectangle.isFlipVertical(), false); | |||||
assertEquals(rectangle.isFlipHorizontal(), false); | |||||
} | |||||
public void testRotation() { | |||||
HSSFWorkbook wb = new HSSFWorkbook(); | |||||
HSSFSheet sheet = wb.createSheet(); | |||||
HSSFPatriarch patriarch = sheet.createDrawingPatriarch(); | |||||
HSSFSimpleShape rectangle = patriarch.createSimpleShape(new HSSFClientAnchor(0,0,100,100, (short) 0,0,(short)5,5)); | |||||
rectangle.setShapeType(HSSFSimpleShape.OBJECT_TYPE_RECTANGLE); | |||||
assertEquals(rectangle.getRotationDegree(), 0); | |||||
rectangle.setRotationDegree((short) 45); | |||||
assertEquals(rectangle.getRotationDegree(), 45); | |||||
rectangle.setFlipHorizontal(true); | |||||
wb = HSSFTestDataSamples.writeOutAndReadBack(wb); | |||||
sheet = wb.getSheetAt(0); | |||||
patriarch = sheet.getDrawingPatriarch(); | |||||
rectangle = (HSSFSimpleShape) patriarch.getChildren().get(0); | |||||
assertEquals(rectangle.getRotationDegree(), 45); | |||||
rectangle.setRotationDegree((short) 30); | |||||
assertEquals(rectangle.getRotationDegree(), 30); | |||||
patriarch.setCoordinates(0, 0, 10, 10); | |||||
rectangle.setString(new HSSFRichTextString("1234")); | |||||
} | |||||
public void testShapeContainerImplementsIterable(){ | |||||
HSSFWorkbook wb = new HSSFWorkbook(); | |||||
HSSFSheet sheet = wb.createSheet(); | |||||
HSSFPatriarch patriarch = sheet.createDrawingPatriarch(); | |||||
patriarch.createSimpleShape(new HSSFClientAnchor()); | |||||
patriarch.createSimpleShape(new HSSFClientAnchor()); | |||||
int i=2; | |||||
for (HSSFShape shape: patriarch){ | |||||
i--; | |||||
} | |||||
assertEquals(i, 0); | |||||
} | |||||
public void testClearShapesForPatriarch(){ | |||||
HSSFWorkbook wb = new HSSFWorkbook(); | |||||
HSSFSheet sheet = wb.createSheet(); | |||||
HSSFPatriarch patriarch = sheet.createDrawingPatriarch(); | |||||
patriarch.createSimpleShape(new HSSFClientAnchor()); | |||||
patriarch.createSimpleShape(new HSSFClientAnchor()); | |||||
patriarch.createCellComment(new HSSFClientAnchor()); | |||||
EscherAggregate agg = HSSFTestHelper.getEscherAggregate(patriarch); | |||||
assertEquals(agg.getShapeToObjMapping().size(), 6); | |||||
assertEquals(agg.getTailRecords().size(), 1); | |||||
assertEquals(patriarch.getChildren().size(), 3); | |||||
patriarch.clear(); | |||||
assertEquals(agg.getShapeToObjMapping().size(), 0); | |||||
assertEquals(agg.getTailRecords().size(), 0); | |||||
assertEquals(patriarch.getChildren().size(), 0); | |||||
wb = HSSFTestDataSamples.writeOutAndReadBack(wb); | |||||
sheet = wb.getSheetAt(0); | |||||
patriarch = sheet.getDrawingPatriarch(); | |||||
assertEquals(agg.getShapeToObjMapping().size(), 0); | |||||
assertEquals(agg.getTailRecords().size(), 0); | |||||
assertEquals(patriarch.getChildren().size(), 0); | |||||
} | |||||
} | } |
assertEquals(1, drawing.getChildren().size()); | assertEquals(1, drawing.getChildren().size()); | ||||
HSSFPicture picture = (HSSFPicture) drawing.getChildren().get(0); | HSSFPicture picture = (HSSFPicture) drawing.getChildren().get(0); | ||||
assertEquals(picture.getAdditionalData(), "test"); | |||||
assertEquals(picture.getFileName(), "test"); | |||||
} | } | ||||
public void testSetGetProperties(){ | public void testSetGetProperties(){ | ||||
int idx1 = wb.addPicture(data1, Workbook.PICTURE_TYPE_JPEG); | int idx1 = wb.addPicture(data1, Workbook.PICTURE_TYPE_JPEG); | ||||
HSSFPicture p1 = dr.createPicture(anchor, idx1); | HSSFPicture p1 = dr.createPicture(anchor, idx1); | ||||
assertEquals(p1.getAdditionalData(), ""); | |||||
p1.setAdditionalData("aaa"); | |||||
assertEquals(p1.getAdditionalData(), "aaa"); | |||||
assertEquals(p1.getFileName(), ""); | |||||
p1.setFileName("aaa"); | |||||
assertEquals(p1.getFileName(), "aaa"); | |||||
wb = HSSFTestDataSamples.writeOutAndReadBack(wb); | wb = HSSFTestDataSamples.writeOutAndReadBack(wb); | ||||
sh = wb.getSheet("Pictures"); | sh = wb.getSheet("Pictures"); | ||||
dr = sh.getDrawingPatriarch(); | dr = sh.getDrawingPatriarch(); | ||||
p1 = (HSSFPicture) dr.getChildren().get(0); | p1 = (HSSFPicture) dr.getChildren().get(0); | ||||
assertEquals(p1.getAdditionalData(), "aaa"); | |||||
assertEquals(p1.getFileName(), "aaa"); | |||||
} | } | ||||
} | } |
import org.apache.poi.ddf.EscherContainerRecord; | import org.apache.poi.ddf.EscherContainerRecord; | ||||
import org.apache.poi.ddf.EscherSpgrRecord; | import org.apache.poi.ddf.EscherSpgrRecord; | ||||
import org.apache.poi.hssf.HSSFTestDataSamples; | import org.apache.poi.hssf.HSSFTestDataSamples; | ||||
import org.apache.poi.hssf.record.EscherAggregate; | |||||
import org.apache.poi.hssf.record.ObjRecord; | import org.apache.poi.hssf.record.ObjRecord; | ||||
import java.lang.reflect.Field; | import java.lang.reflect.Field; | ||||
} | } | ||||
return null; | return null; | ||||
} | } | ||||
public void testClearShapes(){ | |||||
HSSFWorkbook wb = new HSSFWorkbook(); | |||||
HSSFSheet sheet = wb.createSheet(); | |||||
HSSFPatriarch patriarch = sheet.createDrawingPatriarch(); | |||||
HSSFShapeGroup group = patriarch.createGroup(new HSSFClientAnchor()); | |||||
group.createShape(new HSSFChildAnchor()); | |||||
group.createShape(new HSSFChildAnchor()); | |||||
EscherAggregate agg = HSSFTestHelper.getEscherAggregate(patriarch); | |||||
assertEquals(agg.getShapeToObjMapping().size(), 5); | |||||
assertEquals(agg.getTailRecords().size(), 0); | |||||
assertEquals(group.getChildren().size(), 2); | |||||
group.clear(); | |||||
assertEquals(agg.getShapeToObjMapping().size(), 1); | |||||
assertEquals(agg.getTailRecords().size(), 0); | |||||
assertEquals(group.getChildren().size(), 0); | |||||
wb = HSSFTestDataSamples.writeOutAndReadBack(wb); | |||||
sheet = wb.getSheetAt(0); | |||||
patriarch = sheet.getDrawingPatriarch(); | |||||
group = (HSSFShapeGroup) patriarch.getChildren().get(0); | |||||
assertEquals(agg.getShapeToObjMapping().size(), 1); | |||||
assertEquals(agg.getTailRecords().size(), 0); | |||||
assertEquals(group.getChildren().size(), 0); | |||||
} | |||||
} | } |