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.

HSLFTableCell.java 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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.hslf.usermodel;
  16. import java.awt.Rectangle;
  17. import org.apache.poi.ddf.EscherContainerRecord;
  18. import org.apache.poi.ddf.EscherOptRecord;
  19. import org.apache.poi.ddf.EscherProperties;
  20. import org.apache.poi.hslf.model.Line;
  21. import org.apache.poi.sl.usermodel.ShapeContainer;
  22. import org.apache.poi.sl.usermodel.ShapeType;
  23. /**
  24. * Represents a cell in a ppt table
  25. *
  26. * @author Yegor Kozlov
  27. */
  28. public final class HSLFTableCell extends HSLFTextBox {
  29. protected static final int DEFAULT_WIDTH = 100;
  30. protected static final int DEFAULT_HEIGHT = 40;
  31. private Line borderLeft;
  32. private Line borderRight;
  33. private Line borderTop;
  34. private Line borderBottom;
  35. /**
  36. * Create a TableCell object and initialize it from the supplied Record container.
  37. *
  38. * @param escherRecord {@link EscherSpContainer} container which holds information about this shape
  39. * @param parent the parent of the shape
  40. */
  41. protected HSLFTableCell(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape> parent){
  42. super(escherRecord, parent);
  43. }
  44. /**
  45. * Create a new TableCell. This constructor is used when a new shape is created.
  46. *
  47. * @param parent the parent of this Shape. For example, if this text box is a cell
  48. * in a table then the parent is Table.
  49. */
  50. public HSLFTableCell(ShapeContainer<HSLFShape> parent){
  51. super(parent);
  52. setShapeType(ShapeType.RECT);
  53. //_txtrun.setRunType(TextHeaderAtom.HALF_BODY_TYPE);
  54. //_txtrun.getRichTextRuns()[0].setFlag(false, 0, false);
  55. }
  56. protected EscherContainerRecord createSpContainer(boolean isChild){
  57. _escherContainer = super.createSpContainer(isChild);
  58. EscherOptRecord opt = getEscherOptRecord();
  59. setEscherProperty(opt, EscherProperties.TEXT__TEXTID, 0);
  60. setEscherProperty(opt, EscherProperties.TEXT__SIZE_TEXT_TO_FIT_SHAPE, 0x20000);
  61. setEscherProperty(opt, EscherProperties.FILL__NOFILLHITTEST, 0x150001);
  62. setEscherProperty(opt, EscherProperties.SHADOWSTYLE__SHADOWOBSURED, 0x20000);
  63. setEscherProperty(opt, EscherProperties.PROTECTION__LOCKAGAINSTGROUPING, 0x40000);
  64. return _escherContainer;
  65. }
  66. protected void anchorBorder(int type, Line line){
  67. Rectangle cellAnchor = getAnchor();
  68. Rectangle lineAnchor = new Rectangle();
  69. switch(type){
  70. case HSLFTable.BORDER_TOP:
  71. lineAnchor.x = cellAnchor.x;
  72. lineAnchor.y = cellAnchor.y;
  73. lineAnchor.width = cellAnchor.width;
  74. lineAnchor.height = 0;
  75. break;
  76. case HSLFTable.BORDER_RIGHT:
  77. lineAnchor.x = cellAnchor.x + cellAnchor.width;
  78. lineAnchor.y = cellAnchor.y;
  79. lineAnchor.width = 0;
  80. lineAnchor.height = cellAnchor.height;
  81. break;
  82. case HSLFTable.BORDER_BOTTOM:
  83. lineAnchor.x = cellAnchor.x;
  84. lineAnchor.y = cellAnchor.y + cellAnchor.height;
  85. lineAnchor.width = cellAnchor.width;
  86. lineAnchor.height = 0;
  87. break;
  88. case HSLFTable.BORDER_LEFT:
  89. lineAnchor.x = cellAnchor.x;
  90. lineAnchor.y = cellAnchor.y;
  91. lineAnchor.width = 0;
  92. lineAnchor.height = cellAnchor.height;
  93. break;
  94. default:
  95. throw new IllegalArgumentException("Unknown border type: " + type);
  96. }
  97. line.setAnchor(lineAnchor);
  98. }
  99. public Line getBorderLeft() {
  100. return borderLeft;
  101. }
  102. public void setBorderLeft(Line line) {
  103. if(line != null) anchorBorder(HSLFTable.BORDER_LEFT, line);
  104. this.borderLeft = line;
  105. }
  106. public Line getBorderRight() {
  107. return borderRight;
  108. }
  109. public void setBorderRight(Line line) {
  110. if(line != null) anchorBorder(HSLFTable.BORDER_RIGHT, line);
  111. this.borderRight = line;
  112. }
  113. public Line getBorderTop() {
  114. return borderTop;
  115. }
  116. public void setBorderTop(Line line) {
  117. if(line != null) anchorBorder(HSLFTable.BORDER_TOP, line);
  118. this.borderTop = line;
  119. }
  120. public Line getBorderBottom() {
  121. return borderBottom;
  122. }
  123. public void setBorderBottom(Line line) {
  124. if(line != null) anchorBorder(HSLFTable.BORDER_BOTTOM, line);
  125. this.borderBottom = line;
  126. }
  127. public void setAnchor(Rectangle anchor){
  128. super.setAnchor(anchor);
  129. if(borderTop != null) anchorBorder(HSLFTable.BORDER_TOP, borderTop);
  130. if(borderRight != null) anchorBorder(HSLFTable.BORDER_RIGHT, borderRight);
  131. if(borderBottom != null) anchorBorder(HSLFTable.BORDER_BOTTOM, borderBottom);
  132. if(borderLeft != null) anchorBorder(HSLFTable.BORDER_LEFT, borderLeft);
  133. }
  134. }