Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

LayoutEvents.java 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. @VaadinApache2LicenseForJavaFiles@
  3. */
  4. package com.vaadin.event;
  5. import java.io.Serializable;
  6. import java.lang.reflect.Method;
  7. import com.vaadin.event.MouseEvents.ClickEvent;
  8. import com.vaadin.shared.Connector;
  9. import com.vaadin.shared.MouseEventDetails;
  10. import com.vaadin.tools.ReflectTools;
  11. import com.vaadin.ui.Component;
  12. import com.vaadin.ui.ComponentContainer;
  13. public interface LayoutEvents {
  14. public interface LayoutClickListener extends ComponentEventListener {
  15. public static final Method clickMethod = ReflectTools.findMethod(
  16. LayoutClickListener.class, "layoutClick",
  17. LayoutClickEvent.class);
  18. /**
  19. * Layout has been clicked
  20. *
  21. * @param event
  22. * Component click event.
  23. */
  24. public void layoutClick(LayoutClickEvent event);
  25. }
  26. /**
  27. * The interface for adding and removing <code>LayoutClickEvent</code>
  28. * listeners. By implementing this interface a class explicitly announces
  29. * that it will generate a <code>LayoutClickEvent</code> when a component
  30. * inside it is clicked and a <code>LayoutClickListener</code> is
  31. * registered.
  32. * <p>
  33. * Note: The general Java convention is not to explicitly declare that a
  34. * class generates events, but to directly define the
  35. * <code>addListener</code> and <code>removeListener</code> methods. That
  36. * way the caller of these methods has no real way of finding out if the
  37. * class really will send the events, or if it just defines the methods to
  38. * be able to implement an interface.
  39. * </p>
  40. *
  41. * @since 6.5.2
  42. * @see LayoutClickListener
  43. * @see LayoutClickEvent
  44. */
  45. public interface LayoutClickNotifier extends Serializable {
  46. /**
  47. * Add a click listener to the layout. The listener is called whenever
  48. * the user clicks inside the layout. An event is also triggered when
  49. * the click targets a component inside a nested layout or Panel,
  50. * provided the targeted component does not prevent the click event from
  51. * propagating. A caption is not considered part of a component.
  52. *
  53. * The child component that was clicked is included in the
  54. * {@link LayoutClickEvent}.
  55. *
  56. * Use {@link #removeListener(LayoutClickListener)} to remove the
  57. * listener.
  58. *
  59. * @param listener
  60. * The listener to add
  61. */
  62. public void addListener(LayoutClickListener listener);
  63. /**
  64. * Removes an LayoutClickListener.
  65. *
  66. * @param listener
  67. * LayoutClickListener to be removed
  68. */
  69. public void removeListener(LayoutClickListener listener);
  70. }
  71. /**
  72. * An event fired when the layout has been clicked. The event contains
  73. * information about the target layout (component) and the child component
  74. * that was clicked. If no child component was found it is set to null.
  75. */
  76. public static class LayoutClickEvent extends ClickEvent {
  77. private final Component clickedComponent;
  78. private final Component childComponent;
  79. public LayoutClickEvent(Component source,
  80. MouseEventDetails mouseEventDetails,
  81. Component clickedComponent, Component childComponent) {
  82. super(source, mouseEventDetails);
  83. this.clickedComponent = clickedComponent;
  84. this.childComponent = childComponent;
  85. }
  86. /**
  87. * Returns the component that was clicked, which is somewhere inside the
  88. * parent layout on which the listener was registered.
  89. *
  90. * For the direct child component of the layout, see
  91. * {@link #getChildComponent()}.
  92. *
  93. * @return clicked {@link Component}, null if none found
  94. */
  95. public Component getClickedComponent() {
  96. return clickedComponent;
  97. }
  98. /**
  99. * Returns the direct child component of the layout which contains the
  100. * clicked component.
  101. *
  102. * For the clicked component inside that child component of the layout,
  103. * see {@link #getClickedComponent()}.
  104. *
  105. * @return direct child {@link Component} of the layout which contains
  106. * the clicked Component, null if none found
  107. */
  108. public Component getChildComponent() {
  109. return childComponent;
  110. }
  111. public static LayoutClickEvent createEvent(ComponentContainer layout,
  112. MouseEventDetails mouseDetails, Connector clickedConnector) {
  113. Component clickedComponent = (Component) clickedConnector;
  114. Component childComponent = clickedComponent;
  115. while (childComponent != null
  116. && childComponent.getParent() != layout) {
  117. childComponent = childComponent.getParent();
  118. }
  119. return new LayoutClickEvent(layout, mouseDetails, clickedComponent,
  120. childComponent);
  121. }
  122. }
  123. }