aboutsummaryrefslogtreecommitdiffstats
path: root/server/src/com/vaadin/ui/Image.java
diff options
context:
space:
mode:
authorJohannes Dahlström <johannesd@vaadin.com>2012-08-23 18:58:00 +0300
committerJohannes Dahlström <johannesd@vaadin.com>2012-08-24 16:09:47 +0300
commitf2cb4a9d9b3d5e89e38446906e7b556946f0a82a (patch)
tree227ae56d856e0744da2abe63671dfc0d4ef11424 /server/src/com/vaadin/ui/Image.java
parente362dec1811c9872419c5ea627c9e157a7abf8a0 (diff)
downloadvaadin-framework-f2cb4a9d9b3d5e89e38446906e7b556946f0a82a.tar.gz
vaadin-framework-f2cb4a9d9b3d5e89e38446906e7b556946f0a82a.zip
Split Embedded into several components, migrate them to Vaadin 7 (#9087)
Diffstat (limited to 'server/src/com/vaadin/ui/Image.java')
-rw-r--r--server/src/com/vaadin/ui/Image.java94
1 files changed, 94 insertions, 0 deletions
diff --git a/server/src/com/vaadin/ui/Image.java b/server/src/com/vaadin/ui/Image.java
new file mode 100644
index 0000000000..b0dbc9e629
--- /dev/null
+++ b/server/src/com/vaadin/ui/Image.java
@@ -0,0 +1,94 @@
+/*
+@VaadinApache2LicenseForJavaFiles@
+ */
+
+package com.vaadin.ui;
+
+import com.vaadin.event.MouseEvents.ClickEvent;
+import com.vaadin.event.MouseEvents.ClickListener;
+import com.vaadin.shared.EventId;
+import com.vaadin.shared.MouseEventDetails;
+import com.vaadin.shared.ui.image.ImageServerRpc;
+import com.vaadin.shared.ui.image.ImageState;
+import com.vaadin.terminal.Resource;
+
+/**
+ * Component for embedding images.
+ *
+ * @author Vaadin Ltd.
+ * @version
+ * @VERSION@
+ * @since 7.0
+ */
+@SuppressWarnings("serial")
+public class Image extends AbstractEmbedded {
+
+ protected ImageServerRpc rpc = new ImageServerRpc() {
+ @Override
+ public void click(MouseEventDetails mouseDetails) {
+ fireEvent(new ClickEvent(Image.this, mouseDetails));
+ }
+ };
+
+ /**
+ * Creates a new empty Image.
+ */
+ public Image() {
+ registerRpc(rpc);
+ }
+
+ /**
+ * Creates a new empty Image with caption.
+ *
+ * @param caption
+ */
+ public Image(String caption) {
+ this();
+ setCaption(caption);
+ }
+
+ /**
+ * Creates a new Image whose contents is loaded from given resource. The
+ * dimensions are assumed if possible. The type is guessed from resource.
+ *
+ * @param caption
+ * @param source
+ * the Source of the embedded object.
+ */
+ public Image(String caption, Resource source) {
+ this(caption);
+ setSource(source);
+ }
+
+ @Override
+ public ImageState getState() {
+ return (ImageState) super.getState();
+ }
+
+ /**
+ * 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(EventId.CLICK_EVENT_IDENTIFIER, 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(EventId.CLICK_EVENT_IDENTIFIER, ClickEvent.class,
+ listener);
+ }
+}