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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * Copyright 2000-2014 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;
  17. import com.google.gwt.user.client.Event;
  18. import com.google.gwt.user.client.ui.HTML;
  19. import com.vaadin.client.BrowserInfo;
  20. import com.vaadin.client.Util;
  21. import com.vaadin.client.VTooltip;
  22. import com.vaadin.client.WidgetUtil;
  23. public class VLabel extends HTML {
  24. public static final String CLASSNAME = "v-label";
  25. private static final String CLASSNAME_UNDEFINED_WIDTH = "v-label-undef-w";
  26. public VLabel() {
  27. super();
  28. setStyleName(CLASSNAME);
  29. sinkEvents(VTooltip.TOOLTIP_EVENTS);
  30. }
  31. public VLabel(String text) {
  32. super(text);
  33. setStyleName(CLASSNAME);
  34. }
  35. @Override
  36. public void onBrowserEvent(Event event) {
  37. super.onBrowserEvent(event);
  38. if (event.getTypeInt() == Event.ONLOAD) {
  39. Util.notifyParentOfSizeChange(this, true);
  40. event.stopPropagation();
  41. return;
  42. }
  43. }
  44. @Override
  45. public void setWidth(String width) {
  46. super.setWidth(width);
  47. if (width == null || width.equals("")) {
  48. setStyleName(getElement(), CLASSNAME_UNDEFINED_WIDTH, true);
  49. } else {
  50. setStyleName(getElement(), CLASSNAME_UNDEFINED_WIDTH, false);
  51. }
  52. }
  53. @Override
  54. public void setText(String text) {
  55. if (BrowserInfo.get().isIE8()) {
  56. // #3983 - IE8 incorrectly replaces \n with <br> so we do the
  57. // escaping manually and set as HTML
  58. super.setHTML(WidgetUtil.escapeHTML(text));
  59. } else {
  60. super.setText(text);
  61. }
  62. }
  63. }