1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
/*
@VaadinApache2LicenseForJavaFiles@
*/
package com.vaadin.terminal.gwt.client.ui;
import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.NodeList;
import com.google.gwt.dom.client.PreElement;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.ui.HTML;
import com.vaadin.terminal.gwt.client.ApplicationConnection;
import com.vaadin.terminal.gwt.client.BrowserInfo;
import com.vaadin.terminal.gwt.client.Paintable;
import com.vaadin.terminal.gwt.client.UIDL;
import com.vaadin.terminal.gwt.client.Util;
import com.vaadin.terminal.gwt.client.VTooltip;
public class VLabel extends HTML implements Paintable {
public static final String CLASSNAME = "v-label";
private static final String CLASSNAME_UNDEFINED_WIDTH = "v-label-undef-w";
private ApplicationConnection client;
private int verticalPaddingBorder = 0;
private int horizontalPaddingBorder = 0;
public VLabel() {
super();
setStyleName(CLASSNAME);
sinkEvents(VTooltip.TOOLTIP_EVENTS);
}
public VLabel(String text) {
super(text);
setStyleName(CLASSNAME);
sinkEvents(VTooltip.TOOLTIP_EVENTS);
}
@Override
public void onBrowserEvent(Event event) {
super.onBrowserEvent(event);
if (event.getTypeInt() == Event.ONLOAD) {
Util.notifyParentOfSizeChange(this, true);
event.cancelBubble(true);
return;
}
if (client != null) {
client.handleTooltipEvent(event, this);
}
}
public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
if (client.updateComponent(this, uidl, true)) {
return;
}
this.client = client;
boolean sinkOnloads = false;
final String mode = uidl.getStringAttribute("mode");
if (mode == null || "text".equals(mode)) {
setText(uidl.getChildString(0));
} else if ("pre".equals(mode)) {
PreElement preElement = Document.get().createPreElement();
preElement.setInnerText(uidl.getChildUIDL(0).getChildString(0));
// clear existing content
setHTML("");
// add preformatted text to dom
getElement().appendChild(preElement);
} else if ("uidl".equals(mode)) {
setHTML(uidl.getChildrenAsXML());
} else if ("xhtml".equals(mode)) {
UIDL content = uidl.getChildUIDL(0).getChildUIDL(0);
if (content.getChildCount() > 0) {
setHTML(content.getChildString(0));
} else {
setHTML("");
}
sinkOnloads = true;
} else if ("xml".equals(mode)) {
setHTML(uidl.getChildUIDL(0).getChildString(0));
} else if ("raw".equals(mode)) {
setHTML(uidl.getChildUIDL(0).getChildString(0));
sinkOnloads = true;
} else {
setText("");
}
if (sinkOnloads) {
sinkOnloadsForContainedImgs();
}
}
private void sinkOnloadsForContainedImgs() {
NodeList<Element> images = getElement().getElementsByTagName("img");
for (int i = 0; i < images.getLength(); i++) {
Element img = images.getItem(i);
DOM.sinkEvents((com.google.gwt.user.client.Element) img,
Event.ONLOAD);
}
}
@Override
public void setHeight(String height) {
verticalPaddingBorder = Util.setHeightExcludingPaddingAndBorder(this,
height, verticalPaddingBorder);
}
@Override
public void setWidth(String width) {
horizontalPaddingBorder = Util.setWidthExcludingPaddingAndBorder(this,
width, horizontalPaddingBorder);
if (width == null || width.equals("")) {
setStyleName(getElement(), CLASSNAME_UNDEFINED_WIDTH, true);
} else {
setStyleName(getElement(), CLASSNAME_UNDEFINED_WIDTH, false);
}
}
@Override
public void setText(String text) {
if (BrowserInfo.get().isIE() && BrowserInfo.get().getIEVersion() < 9) {
// #3983 - IE6-IE8 incorrectly replaces \n with <br> so we do the
// escaping manually and set as HTML
super.setHTML(Util.escapeHTML(text));
} else {
super.setText(text);
}
}
}
|