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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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(), element
  36. .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. Size other = (Size) obj;
  73. return other.width == width && other.height == height;
  74. }
  75. public Size() {
  76. }
  77. public Size(int width, int height) {
  78. this.height = height;
  79. this.width = width;
  80. }
  81. public int getWidth() {
  82. return width;
  83. }
  84. public void setWidth(int width) {
  85. this.width = width;
  86. }
  87. public int getHeight() {
  88. return height;
  89. }
  90. public void setHeight(int height) {
  91. this.height = height;
  92. }
  93. @Override
  94. public String toString() {
  95. return "Size [width=" + width + ",height=" + height + "]";
  96. }
  97. }
  98. }