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.

VLabel.java 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. @VaadinApache2LicenseForJavaFiles@
  3. */
  4. package com.vaadin.terminal.gwt.client.ui.label;
  5. import com.google.gwt.dom.client.Style.Display;
  6. import com.google.gwt.user.client.Event;
  7. import com.google.gwt.user.client.ui.HTML;
  8. import com.vaadin.terminal.gwt.client.ApplicationConnection;
  9. import com.vaadin.terminal.gwt.client.BrowserInfo;
  10. import com.vaadin.terminal.gwt.client.Util;
  11. import com.vaadin.terminal.gwt.client.VTooltip;
  12. public class VLabel extends HTML {
  13. public static final String CLASSNAME = "v-label";
  14. private static final String CLASSNAME_UNDEFINED_WIDTH = "v-label-undef-w";
  15. private ApplicationConnection connection;
  16. public VLabel() {
  17. super();
  18. setStyleName(CLASSNAME);
  19. sinkEvents(VTooltip.TOOLTIP_EVENTS);
  20. }
  21. public VLabel(String text) {
  22. super(text);
  23. setStyleName(CLASSNAME);
  24. sinkEvents(VTooltip.TOOLTIP_EVENTS);
  25. }
  26. @Override
  27. public void onBrowserEvent(Event event) {
  28. super.onBrowserEvent(event);
  29. if (event.getTypeInt() == Event.ONLOAD) {
  30. Util.notifyParentOfSizeChange(this, true);
  31. event.stopPropagation();
  32. return;
  33. }
  34. if (connection != null) {
  35. connection.handleTooltipEvent(event, this);
  36. }
  37. }
  38. @Override
  39. public void setWidth(String width) {
  40. super.setWidth(width);
  41. if (width == null || width.equals("")) {
  42. setStyleName(getElement(), CLASSNAME_UNDEFINED_WIDTH, true);
  43. getElement().getStyle().setDisplay(Display.INLINE_BLOCK);
  44. } else {
  45. setStyleName(getElement(), CLASSNAME_UNDEFINED_WIDTH, false);
  46. getElement().getStyle().clearDisplay();
  47. }
  48. }
  49. @Override
  50. public void setText(String text) {
  51. if (BrowserInfo.get().isIE8()) {
  52. // #3983 - IE8 incorrectly replaces \n with <br> so we do the
  53. // escaping manually and set as HTML
  54. super.setHTML(Util.escapeHTML(text));
  55. } else {
  56. super.setText(text);
  57. }
  58. }
  59. void setConnection(ApplicationConnection client) {
  60. connection = client;
  61. }
  62. }