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.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /*
  2. * Copyright 2011 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.user.client.Element;
  18. /**
  19. * Contains size information about a rendered container and its content area.
  20. *
  21. * @author Artur Signell
  22. *
  23. */
  24. public class RenderInformation {
  25. private RenderSpace contentArea = new RenderSpace();
  26. private Size renderedSize = new Size(-1, -1);
  27. public void setContentAreaWidth(int w) {
  28. contentArea.setWidth(w);
  29. }
  30. public void setContentAreaHeight(int h) {
  31. contentArea.setHeight(h);
  32. }
  33. public RenderSpace getContentAreaSize() {
  34. return contentArea;
  35. }
  36. public Size getRenderedSize() {
  37. return renderedSize;
  38. }
  39. /**
  40. * Update the size of the widget.
  41. *
  42. * @param widget
  43. *
  44. * @return true if the size has changed since last update
  45. */
  46. public boolean updateSize(Element element) {
  47. Size newSize = new Size(element.getOffsetWidth(),
  48. element.getOffsetHeight());
  49. if (newSize.equals(renderedSize)) {
  50. return false;
  51. } else {
  52. renderedSize = newSize;
  53. return true;
  54. }
  55. }
  56. @Override
  57. public String toString() {
  58. return "RenderInformation [contentArea=" + contentArea
  59. + ",renderedSize=" + renderedSize + "]";
  60. }
  61. public static class FloatSize {
  62. private float width, height;
  63. public FloatSize(float width, float height) {
  64. this.width = width;
  65. this.height = height;
  66. }
  67. public float getWidth() {
  68. return width;
  69. }
  70. public void setWidth(float width) {
  71. this.width = width;
  72. }
  73. public float getHeight() {
  74. return height;
  75. }
  76. public void setHeight(float height) {
  77. this.height = height;
  78. }
  79. }
  80. public static class Size {
  81. private int width, height;
  82. @Override
  83. public boolean equals(Object obj) {
  84. if (!(obj instanceof Size)) {
  85. return false;
  86. }
  87. Size other = (Size) obj;
  88. return other.width == width && other.height == height;
  89. }
  90. @Override
  91. public int hashCode() {
  92. return (width << 8) | height;
  93. }
  94. public Size() {
  95. }
  96. public Size(int width, int height) {
  97. this.height = height;
  98. this.width = width;
  99. }
  100. public int getWidth() {
  101. return width;
  102. }
  103. public void setWidth(int width) {
  104. this.width = width;
  105. }
  106. public int getHeight() {
  107. return height;
  108. }
  109. public void setHeight(int height) {
  110. this.height = height;
  111. }
  112. @Override
  113. public String toString() {
  114. return "Size [width=" + width + ",height=" + height + "]";
  115. }
  116. }
  117. }