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.

RenderInformation.java 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /*
  2. * Copyright 2000-2018 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.client;
  17. import com.google.gwt.dom.client.Element;
  18. import com.google.gwt.user.client.DOM;
  19. /**
  20. * Contains size information about a rendered container and its content area.
  21. *
  22. * @author Artur Signell
  23. *
  24. */
  25. public class RenderInformation {
  26. private RenderSpace contentArea = new RenderSpace();
  27. private Size renderedSize = new Size(-1, -1);
  28. public void setContentAreaWidth(int w) {
  29. contentArea.setWidth(w);
  30. }
  31. public void setContentAreaHeight(int h) {
  32. contentArea.setHeight(h);
  33. }
  34. public RenderSpace getContentAreaSize() {
  35. return contentArea;
  36. }
  37. public Size getRenderedSize() {
  38. return renderedSize;
  39. }
  40. /**
  41. * Update the size of the widget.
  42. *
  43. * @param widget
  44. *
  45. * @return true if the size has changed since last update
  46. * @deprecated As of 7.2, call and override {@link #updateSize(Element)}
  47. * instead
  48. */
  49. @Deprecated
  50. public boolean updateSize(com.google.gwt.user.client.Element element) {
  51. Size newSize = new Size(element.getOffsetWidth(),
  52. element.getOffsetHeight());
  53. if (newSize.equals(renderedSize)) {
  54. return false;
  55. } else {
  56. renderedSize = newSize;
  57. return true;
  58. }
  59. }
  60. /**
  61. * Update the size of the widget.
  62. *
  63. * @param widget
  64. *
  65. * @return true if the size has changed since last update
  66. *
  67. * @since 7.2
  68. */
  69. public boolean updateSize(Element element) {
  70. return updateSize(DOM.asOld(element));
  71. }
  72. @Override
  73. public String toString() {
  74. return "RenderInformation [contentArea=" + contentArea
  75. + ",renderedSize=" + renderedSize + "]";
  76. }
  77. public static class FloatSize {
  78. private float width, height;
  79. public FloatSize(float width, float height) {
  80. this.width = width;
  81. this.height = height;
  82. }
  83. public float getWidth() {
  84. return width;
  85. }
  86. public void setWidth(float width) {
  87. this.width = width;
  88. }
  89. public float getHeight() {
  90. return height;
  91. }
  92. public void setHeight(float height) {
  93. this.height = height;
  94. }
  95. }
  96. public static class Size {
  97. private int width, height;
  98. @Override
  99. public boolean equals(Object obj) {
  100. if (!(obj instanceof Size)) {
  101. return false;
  102. }
  103. Size other = (Size) obj;
  104. return other.width == width && other.height == height;
  105. }
  106. @Override
  107. public int hashCode() {
  108. return (width << 8) | height;
  109. }
  110. public Size() {
  111. }
  112. public Size(int width, int height) {
  113. this.height = height;
  114. this.width = width;
  115. }
  116. public int getWidth() {
  117. return width;
  118. }
  119. public void setWidth(int width) {
  120. this.width = width;
  121. }
  122. public int getHeight() {
  123. return height;
  124. }
  125. public void setHeight(int height) {
  126. this.height = height;
  127. }
  128. @Override
  129. public String toString() {
  130. return "Size [width=" + width + ",height=" + height + "]";
  131. }
  132. }
  133. }