Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

XDDFManualLayout.java 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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.xddf.usermodel.chart;
  16. import org.apache.poi.util.Beta;
  17. import org.apache.poi.util.Internal;
  18. import org.openxmlformats.schemas.drawingml.x2006.chart.CTLayout;
  19. import org.openxmlformats.schemas.drawingml.x2006.chart.CTManualLayout;
  20. import org.openxmlformats.schemas.drawingml.x2006.chart.CTPlotArea;
  21. /**
  22. * Represents a DrawingML manual layout.
  23. */
  24. @Beta
  25. public final class XDDFManualLayout {
  26. /**
  27. * Underlaying CTManualLayout bean.
  28. */
  29. private CTManualLayout layout;
  30. private static final LayoutMode defaultLayoutMode = LayoutMode.EDGE;
  31. private static final LayoutTarget defaultLayoutTarget = LayoutTarget.INNER;
  32. /**
  33. * Create a new DrawingML manual layout.
  34. *
  35. * @param ctLayout
  36. * a DrawingML layout that should be used as base.
  37. */
  38. public XDDFManualLayout(CTLayout ctLayout) {
  39. initializeLayout(ctLayout);
  40. }
  41. /**
  42. * Create a new DrawingML manual layout for chart.
  43. *
  44. * @param ctPlotArea
  45. * a chart's plot area to create layout for.
  46. */
  47. public XDDFManualLayout(CTPlotArea ctPlotArea) {
  48. CTLayout ctLayout = ctPlotArea.isSetLayout() ? ctPlotArea.getLayout() : ctPlotArea.addNewLayout();
  49. initializeLayout(ctLayout);
  50. }
  51. /**
  52. * Return the underlying CTManualLayout bean.
  53. *
  54. * @return the underlying CTManualLayout bean.
  55. */
  56. @Internal
  57. protected CTManualLayout getXmlObject() {
  58. return layout;
  59. }
  60. public void setExtensionList(XDDFChartExtensionList list) {
  61. if (list == null) {
  62. layout.unsetExtLst();
  63. } else {
  64. layout.setExtLst(list.getXmlObject());
  65. }
  66. }
  67. public XDDFChartExtensionList getExtensionList() {
  68. if (layout.isSetExtLst()) {
  69. return new XDDFChartExtensionList(layout.getExtLst());
  70. } else {
  71. return null;
  72. }
  73. }
  74. public void setWidthRatio(double ratio) {
  75. if (!layout.isSetW()) {
  76. layout.addNewW();
  77. }
  78. layout.getW().setVal(ratio);
  79. }
  80. public double getWidthRatio() {
  81. if (!layout.isSetW()) {
  82. return 0.0;
  83. }
  84. return layout.getW().getVal();
  85. }
  86. public void setHeightRatio(double ratio) {
  87. if (!layout.isSetH()) {
  88. layout.addNewH();
  89. }
  90. layout.getH().setVal(ratio);
  91. }
  92. public double getHeightRatio() {
  93. if (!layout.isSetH()) {
  94. return 0.0;
  95. }
  96. return layout.getH().getVal();
  97. }
  98. public LayoutTarget getTarget() {
  99. if (!layout.isSetLayoutTarget()) {
  100. return defaultLayoutTarget;
  101. }
  102. return LayoutTarget.valueOf(layout.getLayoutTarget().getVal());
  103. }
  104. public void setTarget(LayoutTarget target) {
  105. if (!layout.isSetLayoutTarget()) {
  106. layout.addNewLayoutTarget();
  107. }
  108. layout.getLayoutTarget().setVal(target.underlying);
  109. }
  110. public LayoutMode getXMode() {
  111. if (!layout.isSetXMode()) {
  112. return defaultLayoutMode;
  113. }
  114. return LayoutMode.valueOf(layout.getXMode().getVal());
  115. }
  116. public void setXMode(LayoutMode mode) {
  117. if (!layout.isSetXMode()) {
  118. layout.addNewXMode();
  119. }
  120. layout.getXMode().setVal(mode.underlying);
  121. }
  122. public LayoutMode getYMode() {
  123. if (!layout.isSetYMode()) {
  124. return defaultLayoutMode;
  125. }
  126. return LayoutMode.valueOf(layout.getYMode().getVal());
  127. }
  128. public void setYMode(LayoutMode mode) {
  129. if (!layout.isSetYMode()) {
  130. layout.addNewYMode();
  131. }
  132. layout.getYMode().setVal(mode.underlying);
  133. }
  134. public double getX() {
  135. if (!layout.isSetX()) {
  136. return 0.0;
  137. }
  138. return layout.getX().getVal();
  139. }
  140. public void setX(double x) {
  141. if (!layout.isSetX()) {
  142. layout.addNewX();
  143. }
  144. layout.getX().setVal(x);
  145. }
  146. public double getY() {
  147. if (!layout.isSetY()) {
  148. return 0.0;
  149. }
  150. return layout.getY().getVal();
  151. }
  152. public void setY(double y) {
  153. if (!layout.isSetY()) {
  154. layout.addNewY();
  155. }
  156. layout.getY().setVal(y);
  157. }
  158. public LayoutMode getWidthMode() {
  159. if (!layout.isSetWMode()) {
  160. return defaultLayoutMode;
  161. }
  162. return LayoutMode.valueOf(layout.getWMode().getVal());
  163. }
  164. public void setWidthMode(LayoutMode mode) {
  165. if (!layout.isSetWMode()) {
  166. layout.addNewWMode();
  167. }
  168. layout.getWMode().setVal(mode.underlying);
  169. }
  170. public LayoutMode getHeightMode() {
  171. if (!layout.isSetHMode()) {
  172. return defaultLayoutMode;
  173. }
  174. return LayoutMode.valueOf(layout.getHMode().getVal());
  175. }
  176. public void setHeightMode(LayoutMode mode) {
  177. if (!layout.isSetHMode()) {
  178. layout.addNewHMode();
  179. }
  180. layout.getHMode().setVal(mode.underlying);
  181. }
  182. private void initializeLayout(CTLayout ctLayout) {
  183. if (ctLayout.isSetManualLayout()) {
  184. this.layout = ctLayout.getManualLayout();
  185. } else {
  186. this.layout = ctLayout.addNewManualLayout();
  187. }
  188. }
  189. }