1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package org.vectomatic.svg.samples.client.widgets;
25
26 import org.vectomatic.dom.svg.OMSVGGElement;
27 import org.vectomatic.dom.svg.OMSVGPathElement;
28 import org.vectomatic.dom.svg.OMSVGTSpanElement;
29 import org.vectomatic.dom.svg.OMText;
30 import org.vectomatic.dom.svg.ui.SVGImage;
31 import org.vectomatic.dom.svg.ui.SVGPushButton;
32 import org.vectomatic.dom.svg.ui.SVGResource;
33 import org.vectomatic.svg.samples.client.Main;
34 import org.vectomatic.svg.samples.client.Main.MainBundle;
35 import org.vectomatic.svg.samples.client.SampleBase;
36
37 import com.google.gwt.core.client.GWT;
38 import com.google.gwt.dom.client.StyleInjector;
39 import com.google.gwt.event.dom.client.ClickEvent;
40 import com.google.gwt.event.dom.client.MouseDownEvent;
41 import com.google.gwt.event.dom.client.MouseEvent;
42 import com.google.gwt.event.dom.client.MouseOutEvent;
43 import com.google.gwt.event.dom.client.MouseOverEvent;
44 import com.google.gwt.event.shared.EventHandler;
45 import com.google.gwt.resources.client.ClientBundle;
46 import com.google.gwt.resources.client.CssResource;
47 import com.google.gwt.uibinder.client.UiBinder;
48 import com.google.gwt.uibinder.client.UiField;
49 import com.google.gwt.uibinder.client.UiHandler;
50 import com.google.gwt.user.client.Timer;
51 import com.google.gwt.user.client.Window;
52 import com.google.gwt.user.client.ui.HTML;
53 import com.google.gwt.user.client.ui.PopupPanel;
54 import com.google.gwt.user.client.ui.TabLayoutPanel;
55
56 public class WidgetsSample extends SampleBase {
57 private static class Tooltip extends PopupPanel {
58 private HTML contents;
59 private Timer timer;
60
61 public Tooltip() {
62 super(true);
63 contents = new HTML();
64 add(contents);
65 setStyleName(WidgetsSampleBundle.INSTANCE.getCss().tooltip());
66 }
67
68 public void show(int x, int y, final String text, final int delay) {
69 contents.setHTML(text);
70 setPopupPosition(x, y);
71 super.show();
72 if (timer != null) {
73 timer.cancel();
74 }
75 timer = new Timer() {
76 public void run() {
77 Tooltip.this.hide();
78 timer = null;
79 }
80 };
81 timer.schedule(delay);
82 }
83 }
84
85 public interface WidgetsSampleBundle extends ClientBundle {
86 public static WidgetsSampleBundle INSTANCE = GWT.create(WidgetsSampleBundle.class);
87
88 @Source("as_coeur_jean_victor_bal_.svg")
89 SVGResource hearts();
90 @Source("as_trefle_jean_victor_ba_.svg")
91 SVGResource clubs();
92 @Source("as_carreau_jean_victor_b_.svg")
93 SVGResource diamonds();
94 @Source("as_pique_jean_victor_bal_.svg")
95 SVGResource spades();
96 @Source("ledButton.svg")
97 SVGResource led();
98 @Source("play-pause.svg")
99 SVGResource playButton();
100 @Source("tooltip.css")
101 public TooltipCss getCss();
102 }
103
104 interface TooltipCss extends CssResource {
105 public String tooltip();
106 }
107
108 interface WidgetsSampleBinder extends UiBinder<TabLayoutPanel, WidgetsSample> {
109 }
110 private static WidgetsSampleBinder binder = GWT.create(WidgetsSampleBinder.class);
111
112
113 @UiField(provided=true)
114 public static MainBundle mainBundle = Main.mainBundle;
115 @UiField
116 SVGImage hearts;
117 @UiField
118 SVGImage clubs;
119 @UiField
120 SVGImage diamonds;
121 @UiField
122 SVGImage spades;
123 @UiField
124 SVGPushButton clickMeButton;
125 @UiField
126 SVGPushButton holdMeDownButton;
127 @UiField
128 OMSVGTSpanElement clickCount;
129
130
131 @UiField
132 OMSVGGElement eyes;
133 @UiField
134 OMSVGPathElement mouth;
135
136 private Tooltip tooltip;
137
138 @Override
139 public TabLayoutPanel getPanel() {
140 if (tabPanel == null) {
141 TooltipCss css = WidgetsSampleBundle.INSTANCE.getCss();
142
143
144 StyleInjector.inject(css.getText());
145
146 tooltip = new Tooltip();
147 tabPanel = binder.createAndBindUi(this);
148 tabPanel.setTabText(0, "Widgets");
149 createCodeTabs("WidgetsSample");
150 }
151 return tabPanel;
152 }
153
154 private void showTooltip(MouseEvent<? extends EventHandler> e, String text) {
155 tooltip.show(e.getClientX() + 20, e.getClientY() + 30, text, 3000);
156 }
157
158 @UiHandler("hearts")
159 public void onMouseOutHearts(MouseOutEvent event) {
160 tooltip.hide();
161 }
162
163 @UiHandler("hearts")
164 public void onMouseOverHearts(MouseOverEvent event) {
165 showTooltip(event, "hearts");
166 }
167
168 @UiHandler("clubs")
169 public void onMouseOutClubs(MouseOutEvent event) {
170 tooltip.hide();
171 }
172
173 @UiHandler("clubs")
174 public void onMouseOverClubs(MouseOverEvent event) {
175 showTooltip(event, "clubs");
176 }
177
178 @UiHandler("diamonds")
179 public void onMouseOutDiamonds(MouseOutEvent event) {
180 tooltip.hide();
181 }
182
183 @UiHandler("diamonds")
184 public void onMouseOverDiamonds(MouseOverEvent event) {
185 showTooltip(event, "diamonds");
186 }
187
188 @UiHandler("spades")
189 public void onMouseOutSpades(MouseOutEvent event) {
190 tooltip.hide();
191 }
192
193 @UiHandler("spades")
194 public void onMouseOverSpades(MouseOverEvent event) {
195 showTooltip(event, "spades");
196 }
197
198 @UiHandler("eyes")
199 public void onMouseOutEyes(MouseOutEvent event) {
200 tooltip.hide();
201 }
202
203 @UiHandler("eyes")
204 public void onMouseOverEyes(MouseOverEvent event) {
205 showTooltip(event, "eyes");
206 }
207
208 @UiHandler("mouth")
209 public void onMouseOutMouth(MouseOutEvent event) {
210 tooltip.hide();
211 }
212
213 @UiHandler("mouth")
214 public void onMouseOverMouth(MouseOverEvent event) {
215 showTooltip(event, "mouth");
216 }
217
218 @UiHandler("clickMeButton")
219 public void onClick(ClickEvent event) {
220 Window.alert("Ouch !");
221 }
222
223 @UiHandler("holdMeDownButton")
224 public void onMouseDown(MouseDownEvent event) {
225 OMText text = (OMText) clickCount.getFirstChild();
226 int count = Integer.parseInt(text.getData());
227 text.setData(Integer.toString(count + 1));
228 }
229 }