import com.vaadin.event.MouseEvents.ClickEvent;
import com.vaadin.event.MouseEvents.ClickListener;
import com.vaadin.terminal.ExternalResource;
+import com.vaadin.terminal.gwt.client.MouseEventDetails;
import com.vaadin.ui.AbsoluteLayout;
import com.vaadin.ui.Component;
import com.vaadin.ui.Embedded;
setMainWindow(w);
HorizontalLayout hl = new HorizontalLayout();
w.setContent(hl);
- // Panel p = new Panel("My panel");
- // p.addListener(new ClickListener() {
- //
- // public void click(ClickEvent event) {
- // getMainWindow().showNotification("Clicked!");
- //
- // }
- // });
- // w.addComponent(p);
- // if (true) {
- // return;
- // }
- // VerticalLayout vl = new VerticalLayout();
final AbsoluteLayout al = new AbsoluteLayout();
al.setWidth("200px");
public void click(ClickEvent event) {
getMainWindow().showNotification(
"Clicked on " + event.getComponent() + " using "
- + event.getButton());
+ + getButton(event));
+ }
+
+ private String getButton(ClickEvent event) {
+ if (event.getButton() == MouseEventDetails.BUTTON_LEFT) {
+ return "left";
+ } else if (event.getButton() == MouseEventDetails.BUTTON_RIGHT) {
+ return "right";
+ } else {
+ return "middle";
+ }
}
public void focus(FocusEvent event) {
fireEvent(new LayoutClickEvent(this, mouseDetails, childComponent));
}
+ /**
+ * Add a click listener to the layout. The listener is called whenever the
+ * user clicks inside the layout. Also when the click targets a component
+ * inside the Panel, provided the targeted component does not prevent the
+ * click event from propagating. A caption is not considered part of a
+ * component.
+ *
+ * The child component that was clicked is included in the
+ * {@link LayoutClickEvent}.
+ *
+ * Use {@link #removeListener(LayoutClickListener)} to remove the listener.
+ *
+ * @param listener
+ * The listener to add
+ */
public void addListener(LayoutClickListener listener) {
addListener(CLICK_EVENT, LayoutClickEvent.class, listener,
LayoutClickListener.clickMethod);
}
+ /**
+ * Remove a click listener from the layout. The listener should earlier have
+ * been added using {@link #addListener(LayoutClickListener)}.
+ *
+ * @param listener
+ * The listener to remove
+ */
public void removeListener(LayoutClickListener listener) {
removeListener(CLICK_EVENT, LayoutClickEvent.class, listener);
}
fireEvent(new LayoutClickEvent(this, mouseDetails, childComponent));
}
+ /**
+ * Add a click listener to the layout. The listener is called whenever the
+ * user clicks inside the layout. Also when the click targets a component
+ * inside the Panel, provided the targeted component does not prevent the
+ * click event from propagating. A caption is not considered part of a
+ * component.
+ *
+ * The child component that was clicked is included in the
+ * {@link LayoutClickEvent}.
+ *
+ * Use {@link #removeListener(LayoutClickListener)} to remove the listener.
+ *
+ * @param listener
+ * The listener to add
+ */
public void addListener(LayoutClickListener listener) {
addListener(CLICK_EVENT, LayoutClickEvent.class, listener,
LayoutClickListener.clickMethod);
}
+ /**
+ * Remove a click listener from the layout. The listener should earlier have
+ * been added using {@link #addListener(LayoutClickListener)}.
+ *
+ * @param listener
+ * The listener to remove
+ */
public void removeListener(LayoutClickListener listener) {
removeListener(CLICK_EVENT, LayoutClickEvent.class, listener);
}
}
}
+ /**
+ * Add a click listener to the component. The listener is called whenever
+ * the user clicks inside the component. Depending on the content the event
+ * may be blocked and in that case no event is fired.
+ *
+ * Use {@link #removeListener(ClickListener)} to remove the listener.
+ *
+ * @param listener
+ * The listener to add
+ */
public void addListener(ClickListener listener) {
addListener(CLICK_EVENT, ClickEvent.class, listener,
ClickListener.clickMethod);
}
+ /**
+ * Remove a click listener from the component. The listener should earlier
+ * have been added using {@link #addListener(ClickListener)}.
+ *
+ * @param listener
+ * The listener to remove
+ */
public void removeListener(ClickListener listener) {
removeListener(CLICK_EVENT, ClickEvent.class, listener);
}
fireEvent(new LayoutClickEvent(this, mouseDetails, childComponent));
}
+ /**
+ * Add a click listener to the layout. The listener is called whenever the
+ * user clicks inside the layout. Also when the click targets a component
+ * inside the Panel, provided the targeted component does not prevent the
+ * click event from propagating. A caption is not considered part of a
+ * component.
+ *
+ * The child component that was clicked is included in the
+ * {@link LayoutClickEvent}.
+ *
+ * Use {@link #removeListener(LayoutClickListener)} to remove the listener.
+ *
+ * @param listener
+ * The listener to add
+ */
public void addListener(LayoutClickListener listener) {
addListener(CLICK_EVENT, LayoutClickEvent.class, listener,
LayoutClickListener.clickMethod);
}
+ /**
+ * Remove a click listener from the layout. The listener should earlier have
+ * been added using {@link #addListener(LayoutClickListener)}.
+ *
+ * @param listener
+ * The listener to remove
+ */
public void removeListener(LayoutClickListener listener) {
removeListener(CLICK_EVENT, LayoutClickEvent.class, listener);
}
}
}
+ /**
+ * Add a click listener to the Panel. The listener is called whenever the
+ * user clicks inside the Panel. Also when the click targets a component
+ * inside the Panel, provided the targeted component does not prevent the
+ * click event from propagating.
+ *
+ * Use {@link #removeListener(ClickListener)} to remove the listener.
+ *
+ * @param listener
+ * The listener to add
+ */
public void addListener(ClickListener listener) {
addListener(CLICK_EVENT, ClickEvent.class, listener,
ClickListener.clickMethod);
}
+ /**
+ * Remove a click listener from the Panel. The listener should earlier have
+ * been added using {@link #addListener(ClickListener)}.
+ *
+ * @param listener
+ * The listener to remove
+ */
public void removeListener(ClickListener listener) {
removeListener(CLICK_EVENT, ClickEvent.class, listener);
}