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.

Paintable.java 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. @VaadinApache2LicenseForJavaFiles@
  3. */
  4. package com.vaadin.terminal;
  5. import java.io.Serializable;
  6. import java.util.EventObject;
  7. /**
  8. * Interface implemented by all classes that can be painted. Classes
  9. * implementing this interface know how to output themselves to a UIDL stream
  10. * and that way describing to the terminal how it should be displayed in the UI.
  11. *
  12. * @author Vaadin Ltd.
  13. * @version
  14. * @VERSION@
  15. * @since 3.0
  16. */
  17. public interface Paintable extends java.util.EventListener, Serializable {
  18. /**
  19. * <p>
  20. * Paints the Paintable into a UIDL stream. This method creates the UIDL
  21. * sequence describing it and outputs it to the given UIDL stream.
  22. * </p>
  23. *
  24. * <p>
  25. * It is called when the contents of the component should be painted in
  26. * response to the component first being shown or having been altered so
  27. * that its visual representation is changed.
  28. * </p>
  29. *
  30. * @param target
  31. * the target UIDL stream where the component should paint itself
  32. * to.
  33. * @throws PaintException
  34. * if the paint operation failed.
  35. */
  36. public void paint(PaintTarget target) throws PaintException;
  37. /**
  38. * Requests that the paintable should be repainted as soon as possible.
  39. */
  40. public void requestRepaint();
  41. /**
  42. * Adds an unique id for component that get's transferred to terminal for
  43. * testing purposes. Keeping identifiers unique throughout the Application
  44. * instance is on programmers responsibility.
  45. * <p>
  46. * Note, that with the current terminal implementation the identifier cannot
  47. * be changed while the component is visible. This means that the identifier
  48. * should be set before the component is painted for the first time and kept
  49. * the same while visible in the client.
  50. *
  51. * @param id
  52. * A short (< 20 chars) alphanumeric id
  53. */
  54. public void setDebugId(String id);
  55. /**
  56. * Get's currently set debug identifier
  57. *
  58. * @return current debug id, null if not set
  59. */
  60. public String getDebugId();
  61. /**
  62. * Repaint request event is thrown when the paintable needs to be repainted.
  63. * This is typically done when the <code>paint</code> method would return
  64. * dissimilar UIDL from the previous call of the method.
  65. */
  66. @SuppressWarnings("serial")
  67. public class RepaintRequestEvent extends EventObject {
  68. /**
  69. * Constructs a new event.
  70. *
  71. * @param source
  72. * the paintable needing repaint.
  73. */
  74. public RepaintRequestEvent(Paintable source) {
  75. super(source);
  76. }
  77. /**
  78. * Gets the paintable needing repainting.
  79. *
  80. * @return Paintable for which the <code>paint</code> method will return
  81. * dissimilar UIDL from the previous call of the method.
  82. */
  83. public Paintable getPaintable() {
  84. return (Paintable) getSource();
  85. }
  86. }
  87. /**
  88. * Listens repaint requests. The <code>repaintRequested</code> method is
  89. * called when the paintable needs to be repainted. This is typically done
  90. * when the <code>paint</code> method would return dissimilar UIDL from the
  91. * previous call of the method.
  92. */
  93. public interface RepaintRequestListener extends Serializable {
  94. /**
  95. * Receives repaint request events.
  96. *
  97. * @param event
  98. * the repaint request event specifying the paintable source.
  99. */
  100. public void repaintRequested(RepaintRequestEvent event);
  101. }
  102. /**
  103. * Adds repaint request listener. In order to assure that no repaint
  104. * requests are missed, the new repaint listener should paint the paintable
  105. * right after adding itself as listener.
  106. *
  107. * @param listener
  108. * the listener to be added.
  109. */
  110. public void addListener(RepaintRequestListener listener);
  111. /**
  112. * Removes repaint request listener.
  113. *
  114. * @param listener
  115. * the listener to be removed.
  116. */
  117. public void removeListener(RepaintRequestListener listener);
  118. /**
  119. * Request sending of repaint events on any further visible changes.
  120. * Normally the paintable only send up to one repaint request for listeners
  121. * after paint as the paintable as the paintable assumes that the listeners
  122. * already know about the repaint need. This method resets the assumtion.
  123. * Paint implicitly does the assumtion reset functionality implemented by
  124. * this method.
  125. * <p>
  126. * This method is normally used only by the terminals to note paintables
  127. * about implicit repaints (painting the component without actually invoking
  128. * paint method).
  129. * </p>
  130. */
  131. public void requestRepaintRequests();
  132. }