/projects/iReport-3.7.5/ireport-designer/src/com/jaspersoft/ireport/designer/undo/BandChangeUndoableEdit.java

https://gitlab.com/essere.lab.public/qualitas.class-corpus · Java · 161 lines · 83 code · 27 blank · 51 comment · 8 complexity · ed885e99ef2f12212a8b6769cdd5cf4c MD5 · raw file

  1. /*
  2. * iReport - Visual Designer for JasperReports.
  3. * Copyright (C) 2002 - 2009 Jaspersoft Corporation. All rights reserved.
  4. * http://www.jaspersoft.com
  5. *
  6. * Unless you have purchased a commercial license agreement from Jaspersoft,
  7. * the following license terms apply:
  8. *
  9. * This program is part of iReport.
  10. *
  11. * iReport is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License as published by
  13. * the Free Software Foundation, either version 3 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * iReport is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License
  22. * along with iReport. If not, see <http://www.gnu.org/licenses/>.
  23. */
  24. package com.jaspersoft.ireport.designer.undo;
  25. import com.jaspersoft.ireport.designer.ModelUtils;
  26. import javax.swing.undo.CannotRedoException;
  27. import javax.swing.undo.CannotUndoException;
  28. import net.sf.jasperreports.engine.design.JRDesignBand;
  29. import net.sf.jasperreports.engine.design.JRDesignElement;
  30. import net.sf.jasperreports.engine.design.JasperDesign;
  31. /**
  32. *
  33. * @author gtoffoli
  34. */
  35. public class BandChangeUndoableEdit extends AggregatedUndoableEdit {
  36. private JRDesignBand oldBand = null;
  37. private JRDesignBand newBand = null;
  38. private JRDesignElement element = null;
  39. private JasperDesign jasperDesign = null;
  40. public BandChangeUndoableEdit(JasperDesign jasperDesign,
  41. JRDesignBand oldBand,
  42. JRDesignBand newBand,
  43. JRDesignElement element)
  44. {
  45. this.oldBand = oldBand;
  46. this.newBand = newBand;
  47. this.element = element;
  48. this.jasperDesign = jasperDesign;
  49. }
  50. @Override
  51. public void undo() throws CannotUndoException {
  52. super.undo();
  53. if (oldBand != null && newBand != oldBand)
  54. {
  55. int y1 = ModelUtils.getBandLocation(newBand, getJasperDesign());
  56. int y0 = ModelUtils.getBandLocation(oldBand, getJasperDesign());
  57. int deltaBand = y0 - y1;
  58. // Update element band...
  59. newBand.getChildren().remove(getElement());
  60. //oldBand.removeElement(dew.getElement());
  61. // Update the element coordinates...
  62. getElement().setElementGroup(oldBand);
  63. getElement().setY(getElement().getY() - deltaBand);
  64. oldBand.getChildren().add(getElement());
  65. newBand.getEventSupport().firePropertyChange(JRDesignBand.PROPERTY_CHILDREN, null, null);
  66. oldBand.getEventSupport().firePropertyChange(JRDesignBand.PROPERTY_CHILDREN, null, null);
  67. }
  68. }
  69. @Override
  70. public void redo() throws CannotRedoException {
  71. super.redo();
  72. if (newBand != null && newBand != oldBand)
  73. {
  74. int y1 = ModelUtils.getBandLocation(newBand, getJasperDesign());
  75. int y0 = ModelUtils.getBandLocation(oldBand, getJasperDesign());
  76. int deltaBand = y0 - y1;
  77. // Update element band...
  78. oldBand.getChildren().remove(getElement());
  79. //oldBand.removeElement(dew.getElement());
  80. // Update the element coordinates...
  81. getElement().setElementGroup(newBand);
  82. getElement().setY(getElement().getY() + deltaBand);
  83. newBand.getChildren().add(getElement());
  84. newBand.getEventSupport().firePropertyChange(JRDesignBand.PROPERTY_CHILDREN, null, null);
  85. oldBand.getEventSupport().firePropertyChange(JRDesignBand.PROPERTY_CHILDREN, null, null);
  86. }
  87. }
  88. @Override
  89. public String getPresentationName() {
  90. return "Element band change";
  91. }
  92. public JasperDesign getJasperDesign() {
  93. return jasperDesign;
  94. }
  95. public void setJasperDesign(JasperDesign jasperDesign) {
  96. this.jasperDesign = jasperDesign;
  97. }
  98. /**
  99. * @return the oldBand
  100. */
  101. public JRDesignBand getOldBand() {
  102. return oldBand;
  103. }
  104. /**
  105. * @param oldBand the oldBand to set
  106. */
  107. public void setOldBand(JRDesignBand oldBand) {
  108. this.oldBand = oldBand;
  109. }
  110. /**
  111. * @return the newBand
  112. */
  113. public JRDesignBand getNewBand() {
  114. return newBand;
  115. }
  116. /**
  117. * @param newBand the newBand to set
  118. */
  119. public void setNewBand(JRDesignBand newBand) {
  120. this.newBand = newBand;
  121. }
  122. /**
  123. * @return the element
  124. */
  125. public JRDesignElement getElement() {
  126. return element;
  127. }
  128. /**
  129. * @param element the element to set
  130. */
  131. public void setElement(JRDesignElement element) {
  132. this.element = element;
  133. }
  134. }