This class contains the Excel picture data in Escher format for the
entire workbook
| Method from jxl.biff.drawing.DrawingGroup Detail: |
public void add(MsoDrawingGroupRecord mso) {
addData(mso.getData());
}
/**
Adds in a drawing group record to this drawing group. The binary
data is extracted from the drawing group and added to a single
byte array |
public void add(Record cont) {
addData(cont.getData());
}
Adds a continue record to this drawing group. the binary data is
extracted and appended to the byte array |
public void add(Chart c) {
numCharts++;
}
Adds a chart to the drawing group |
public void add(DrawingGroupObject d) {
if (origin == Origin.READ)
{
origin = Origin.READ_WRITE;
BStoreContainer bsc = getBStoreContainer(); // force initialization
Dgg dgg = (Dgg) escherData.getChildren()[0];
drawingGroupId = dgg.getCluster(1).drawingGroupId - numBlips - 1;
numBlips = bsc != null ? bsc.getNumBlips() : 0;
if (bsc != null)
{
Assert.verify(numBlips == bsc.getNumBlips());
}
}
if (!(d instanceof Drawing))
{
// Assign a new object id and add it to the list
// drawings.add(d);
maxObjectId++;
maxShapeId++;
d.setDrawingGroup(this);
d.setObjectId(maxObjectId, numBlips + 1, maxShapeId);
if (drawings.size() > maxObjectId)
{
logger.warn("drawings length " + drawings.size() +
" exceeds the max object id " + maxObjectId);
}
// numBlips++;
return;
}
Drawing drawing = (Drawing) d;
// See if this is referenced elsewhere
Drawing refImage =
(Drawing) imageFiles.get(d.getImageFilePath());
if (refImage == null)
{
// There are no other references to this drawing, so assign
// a new object id and put it on the hash map
maxObjectId++;
maxShapeId++;
drawings.add(drawing);
drawing.setDrawingGroup(this);
drawing.setObjectId(maxObjectId, numBlips + 1, maxShapeId);
numBlips++;
imageFiles.put(drawing.getImageFilePath(), drawing);
}
else
{
// This drawing is used elsewhere in the workbook. Increment the
// reference count on the drawing, and set the object id of the drawing
// passed in
refImage.setReferenceCount(refImage.getReferenceCount() + 1);
drawing.setDrawingGroup(this);
drawing.setObjectId(refImage.getObjectId(),
refImage.getBlipId(),
refImage.getShapeId());
}
}
Adds a drawing from the public, writable interface |
final void addDrawing(DrawingGroupObject d) {
drawings.add(d);
maxObjectId = Math.max(maxObjectId, d.getObjectId());
maxShapeId = Math.max(maxShapeId, d.getShapeId());
}
Adds a drawing to the drawing group |
public byte[] getData() {
return drawingData;
}
Gets hold of the binary data |
byte[] getImageData(int blipId) {
numBlips = getBStoreContainer().getNumBlips();
Assert.verify(blipId < = numBlips);
Assert.verify(origin == Origin.READ || origin == Origin.READ_WRITE);
// Get the blip
EscherRecord[] children = getBStoreContainer().getChildren();
BlipStoreEntry bse = (BlipStoreEntry) children[blipId - 1];
return bse.getImageData();
}
Gets the drawing data for the given blip id. Called by the Drawing
object |
final int getNumberOfBlips() {
return numBlips;
}
Accessor for the number of blips in the drawing group |
public boolean hasDrawingsOmitted() {
return drawingsOmitted;
}
Accessor for the drawingsOmitted flag |
public void remove(DrawingGroupObject d) {
// Unless there are real images or some such, it is possible that
// a BStoreContainer will not be present. In that case simply return
if (getBStoreContainer() == null)
{
return;
}
if (origin == Origin.READ)
{
origin = Origin.READ_WRITE;
numBlips = getBStoreContainer().getNumBlips();
Dgg dgg = (Dgg) escherData.getChildren()[0];
drawingGroupId = dgg.getCluster(1).drawingGroupId - numBlips - 1;
}
// Get the blip
EscherRecord[] children = getBStoreContainer().getChildren();
BlipStoreEntry bse = (BlipStoreEntry) children[d.getBlipId() - 1];
bse.dereference();
if (bse.getReferenceCount() == 0)
{
// Remove the blip
getBStoreContainer().remove(bse);
// Adjust blipId on the other blips
for (Iterator i = drawings.iterator(); i.hasNext();)
{
DrawingGroupObject drawing = (DrawingGroupObject) i.next();
if (drawing.getBlipId() > d.getBlipId())
{
drawing.setObjectId(drawing.getObjectId(),
drawing.getBlipId() - 1,
drawing.getShapeId());
}
}
numBlips--;
}
}
Interface method to remove a drawing from the group |
public void setDrawingsOmitted(MsoDrawingRecord mso,
ObjRecord obj) {
drawingsOmitted = true;
if (obj != null)
{
maxObjectId = Math.max(maxObjectId, obj.getObjectId());
}
}
Indicates that at least one of the drawings has been omitted from
the worksheet |
public void updateData(DrawingGroup dg) {
drawingsOmitted = dg.drawingsOmitted;
maxObjectId = dg.maxObjectId;
maxShapeId = dg.maxShapeId;
}
Updates this with the appropriate data from the drawing group passed in
This is called during the copy process: this is first initialised as
an empty object, but during the copy, the source DrawingGroup may
change. After the copy process, this method is then called to update
the relevant fields. Unfortunately, the copy process required the
presence of a drawing group |
public void write(File outputFile) throws IOException {
if (origin == Origin.WRITE)
{
DggContainer dggContainer = new DggContainer();
Dgg dgg = new Dgg(numBlips + numCharts + 1, numBlips);
dgg.addCluster(1, 0);
dgg.addCluster(numBlips + 1, 0);
dggContainer.add(dgg);
int drawingsAdded = 0;
BStoreContainer bstoreCont = new BStoreContainer();
// Create a blip entry for each drawing
for (Iterator i = drawings.iterator(); i.hasNext();)
{
Object o = i.next();
if (o instanceof Drawing)
{
Drawing d = (Drawing) o;
BlipStoreEntry bse = new BlipStoreEntry(d);
bstoreCont.add(bse);
drawingsAdded++;
}
}
if (drawingsAdded > 0)
{
bstoreCont.setNumBlips(drawingsAdded);
dggContainer.add(bstoreCont);
}
Opt opt = new Opt();
dggContainer.add(opt);
SplitMenuColors splitMenuColors = new SplitMenuColors();
dggContainer.add(splitMenuColors);
drawingData = dggContainer.getData();
}
else if (origin == Origin.READ_WRITE)
{
DggContainer dggContainer = new DggContainer();
Dgg dgg = new Dgg(numBlips + numCharts + 1, numBlips);
dgg.addCluster(1, 0);
dgg.addCluster(drawingGroupId + numBlips + 1, 0);
dggContainer.add(dgg);
BStoreContainer bstoreCont = new BStoreContainer();
bstoreCont.setNumBlips(numBlips);
// Create a blip entry for each drawing that was read in
BStoreContainer readBStoreContainer = getBStoreContainer();
if (readBStoreContainer != null)
{
EscherRecord[] children = readBStoreContainer.getChildren();
for (int i = 0; i < children.length; i++)
{
BlipStoreEntry bse = (BlipStoreEntry) children[i];
bstoreCont.add(bse);
}
}
// Create a blip entry for each drawing that has been added
for (Iterator i = drawings.iterator(); i.hasNext();)
{
DrawingGroupObject dgo = (DrawingGroupObject) i.next();
if (dgo instanceof Drawing)
{
Drawing d = (Drawing) dgo;
if (d.getOrigin() == Origin.WRITE)
{
BlipStoreEntry bse = new BlipStoreEntry(d);
bstoreCont.add(bse);
}
}
}
dggContainer.add(bstoreCont);
Opt opt = new Opt();
opt.addProperty(191, false, false, 524296);
opt.addProperty(385, false, false, 134217737);
opt.addProperty(448, false, false, 134217792);
dggContainer.add(opt);
SplitMenuColors splitMenuColors = new SplitMenuColors();
dggContainer.add(splitMenuColors);
drawingData = dggContainer.getData();
}
MsoDrawingGroupRecord msodg = new MsoDrawingGroupRecord(drawingData);
outputFile.write(msodg);
}
Writes the drawing group to the output file |