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.

ImageConnector.java 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * Copyright 2000-2016 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.client.ui.image;
  17. import com.google.gwt.dom.client.NativeEvent;
  18. import com.google.gwt.event.dom.client.LoadEvent;
  19. import com.vaadin.client.communication.StateChangeEvent;
  20. import com.vaadin.client.ui.AbstractComponentConnector;
  21. import com.vaadin.client.ui.ClickEventHandler;
  22. import com.vaadin.client.ui.VImage;
  23. import com.vaadin.shared.MouseEventDetails;
  24. import com.vaadin.shared.ui.AbstractEmbeddedState;
  25. import com.vaadin.shared.ui.Connect;
  26. import com.vaadin.shared.ui.image.ImageServerRpc;
  27. import com.vaadin.shared.ui.image.ImageState;
  28. @Connect(com.vaadin.ui.Image.class)
  29. public class ImageConnector extends AbstractComponentConnector {
  30. @Override
  31. protected void init() {
  32. super.init();
  33. getWidget().addHandler(
  34. event -> getLayoutManager()
  35. .setNeedsMeasure(ImageConnector.this),
  36. LoadEvent.getType());
  37. }
  38. @Override
  39. public VImage getWidget() {
  40. return (VImage) super.getWidget();
  41. }
  42. @Override
  43. public ImageState getState() {
  44. return (ImageState) super.getState();
  45. }
  46. @Override
  47. public void onStateChanged(StateChangeEvent stateChangeEvent) {
  48. super.onStateChanged(stateChangeEvent);
  49. clickEventHandler.handleEventHandlerRegistration();
  50. String url = getResourceUrl(AbstractEmbeddedState.SOURCE_RESOURCE);
  51. getWidget().setUrl(url != null ? url : "");
  52. String alt = getState().alternateText;
  53. // Some browsers turn a null alt text into a literal "null"
  54. getWidget().setAltText(alt != null ? alt : "");
  55. }
  56. protected final ClickEventHandler clickEventHandler = new ClickEventHandler(
  57. this) {
  58. @Override
  59. protected void fireClick(NativeEvent event,
  60. MouseEventDetails mouseDetails) {
  61. getRpcProxy(ImageServerRpc.class).click(mouseDetails);
  62. }
  63. };
  64. }