您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

RenderInformation.java 3.4KB

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