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.2KB

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