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.

Image.java 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * Copyright 2000-2018 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.ui;
  17. import com.vaadin.event.MouseEvents.ClickEvent;
  18. import com.vaadin.event.MouseEvents.ClickListener;
  19. import com.vaadin.server.Resource;
  20. import com.vaadin.shared.EventId;
  21. import com.vaadin.shared.MouseEventDetails;
  22. import com.vaadin.shared.Registration;
  23. import com.vaadin.shared.ui.image.ImageServerRpc;
  24. import com.vaadin.shared.ui.image.ImageState;
  25. /**
  26. * Component for embedding images.
  27. *
  28. * @author Vaadin Ltd.
  29. * @since 7.0
  30. */
  31. @SuppressWarnings("serial")
  32. public class Image extends AbstractEmbedded {
  33. protected ImageServerRpc rpc = (
  34. MouseEventDetails mouseDetails) -> fireEvent(
  35. new ClickEvent(Image.this, mouseDetails));
  36. /**
  37. * Creates a new empty Image.
  38. */
  39. public Image() {
  40. registerRpc(rpc);
  41. }
  42. /**
  43. * Creates a new empty Image with caption.
  44. *
  45. * @param caption
  46. */
  47. public Image(String caption) {
  48. this();
  49. setCaption(caption);
  50. }
  51. /**
  52. * Creates a new Image whose contents is loaded from given resource. The
  53. * dimensions are assumed if possible. The type is guessed from resource.
  54. *
  55. * @param caption
  56. * @param source
  57. * the Source of the embedded object.
  58. */
  59. public Image(String caption, Resource source) {
  60. this(caption);
  61. setSource(source);
  62. }
  63. @Override
  64. protected ImageState getState() {
  65. return (ImageState) super.getState();
  66. }
  67. @Override
  68. protected ImageState getState(boolean markAsDirty) {
  69. return (ImageState) super.getState(markAsDirty);
  70. }
  71. /**
  72. * Add a click listener to the component. The listener is called whenever
  73. * the user clicks inside the component. Depending on the content the event
  74. * may be blocked and in that case no event is fired.
  75. *
  76. * @see Registration
  77. *
  78. * @param listener
  79. * The listener to add, not null
  80. * @return a registration object for removing the listener
  81. * @since 8.0
  82. */
  83. public Registration addClickListener(ClickListener listener) {
  84. return addListener(EventId.CLICK_EVENT_IDENTIFIER, ClickEvent.class,
  85. listener, ClickListener.clickMethod);
  86. }
  87. /**
  88. * Remove a click listener from the component. The listener should earlier
  89. * have been added using {@link #addClickListener(ClickListener)}.
  90. *
  91. * @param listener
  92. * The listener to remove
  93. *
  94. * @deprecated As of 8.0, replaced by {@link Registration#remove()} in the
  95. * registration object returned from
  96. * {@link #addClickListener(ClickListener)}.
  97. */
  98. @Deprecated
  99. public void removeClickListener(ClickListener listener) {
  100. removeListener(EventId.CLICK_EVENT_IDENTIFIER, ClickEvent.class,
  101. listener);
  102. }
  103. }