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 2.9KB

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