Exemplo n.º 1
0
        /**
         * Adds a drawing from the public, writable interface
         *
         * @param d the drawing to add
         */
        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 is 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.Count > maxobjectId)
                {
                    //logger.warn("drawings length " + drawings.Count +
                    //            " exceeds the max object id " + maxobjectId);
                }
                //      numBlips++;
                return;
            }

            Drawing drawing = (Drawing)d;

            // See if this is referenced elsewhere
            Drawing refImage = null;

            if (imageFiles.ContainsKey(d.getImageFilePath()))
            {
                refImage = imageFiles[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.Add(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());
            }
        }