You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DrawingManager2.java 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. ==================================================================== */
  15. package org.apache.poi.hssf.model;
  16. import java.util.ArrayList;
  17. import java.util.List;
  18. import org.apache.poi.ddf.EscherDgRecord;
  19. import org.apache.poi.ddf.EscherDggRecord;
  20. /**
  21. * Provides utilities to manage drawing groups.
  22. */
  23. public class DrawingManager2 {
  24. private final EscherDggRecord dgg;
  25. private final List<EscherDgRecord> drawingGroups = new ArrayList<>();
  26. public DrawingManager2( EscherDggRecord dgg ) {
  27. this.dgg = dgg;
  28. }
  29. /**
  30. * Clears the cached list of drawing groups
  31. */
  32. public void clearDrawingGroups() {
  33. drawingGroups.clear();
  34. }
  35. /**
  36. * Creates a new drawing group
  37. *
  38. * @return a new drawing group
  39. */
  40. public EscherDgRecord createDgRecord() {
  41. EscherDgRecord dg = new EscherDgRecord();
  42. dg.setRecordId( EscherDgRecord.RECORD_ID );
  43. short dgId = findNewDrawingGroupId();
  44. dg.setOptions( (short) ( dgId << 4 ) );
  45. dg.setNumShapes( 0 );
  46. dg.setLastMSOSPID( -1 );
  47. drawingGroups.add(dg);
  48. dgg.addCluster( dgId, 0 );
  49. dgg.setDrawingsSaved( dgg.getDrawingsSaved() + 1 );
  50. return dg;
  51. }
  52. /**
  53. * Allocates new shape id for the drawing group
  54. *
  55. * @param dg the EscherDgRecord which receives the new shape
  56. *
  57. * @return a new shape id.
  58. */
  59. public int allocateShapeId(EscherDgRecord dg) {
  60. return dgg.allocateShapeId(dg, true);
  61. }
  62. /**
  63. * Finds the next available (1 based) drawing group id
  64. *
  65. * @return the next available drawing group id
  66. */
  67. public short findNewDrawingGroupId() {
  68. return dgg.findNewDrawingGroupId();
  69. }
  70. /**
  71. * Returns the drawing group container record
  72. *
  73. * @return the drawing group container record
  74. */
  75. public EscherDggRecord getDgg() {
  76. return dgg;
  77. }
  78. /**
  79. * Increment the drawing counter
  80. */
  81. public void incrementDrawingsSaved(){
  82. dgg.setDrawingsSaved(dgg.getDrawingsSaved()+1);
  83. }
  84. }