My favorites
▼
|
Sign in
synthfuljava
Synthful Utilities Library for the Java Platform.
Project Home
Downloads
Wiki
Issues
Source
Checkout
Browse
Changes
Source path:
svn
/
trunk
/
gwt
/
widgets
/
com
/
google
/
gwt
/
user
/
client
/
ui
/
ScrolledDialogBox.java
‹r82
r105
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
/*
* Copyright 2009 Google Inc. Licensed under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
* or agreed to in writing, software distributed under the License is
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
/*
* Modified by Blessed Geek as a patch to allow caption region to host a close
* button that is sensitive to mouse events.
* Modified 2009-07-09.
*/
package com.google.gwt.user.client.ui;
import java.util.ArrayList;
import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.EventTarget;
import com.google.gwt.dom.client.NativeEvent;
import com.google.gwt.event.dom.client.HasAllMouseHandlers;
import com.google.gwt.event.dom.client.MouseDownEvent;
import com.google.gwt.event.dom.client.MouseDownHandler;
import com.google.gwt.event.dom.client.MouseMoveEvent;
import com.google.gwt.event.dom.client.MouseMoveHandler;
import com.google.gwt.event.dom.client.MouseOutEvent;
import com.google.gwt.event.dom.client.MouseOutHandler;
import com.google.gwt.event.dom.client.MouseOverEvent;
import com.google.gwt.event.dom.client.MouseOverHandler;
import com.google.gwt.event.dom.client.MouseUpEvent;
import com.google.gwt.event.dom.client.MouseUpHandler;
import com.google.gwt.event.logical.shared.ResizeEvent;
import com.google.gwt.event.logical.shared.ResizeHandler;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.Event.NativePreviewEvent;
/**
* A form of popup that has a caption area at the top and can be dragged by the
* user. Unlike a PopupPanel, calls to {@link #setWidth(String)} and
* {@link #setHeight(String)} will set the width and height of the dialog box
* itself, even if a widget has not been added as yet.
* <p>
* <img class='gallery' src='DialogBox.png'/>
* </p>
* <h3>CSS Style Rules</h3>
* <ul>
* <li>.gwt-DialogBox { the outside of the dialog }</li>
* <li>.gwt-DialogBox .Caption { the caption }</li>
* <li>.gwt-DialogBox .dialogContent { the wrapper around the content }</li>
* <li>.gwt-DialogBox .dialogTopLeft { the top left cell }</li>
* <li>.gwt-DialogBox .dialogTopLeftInner { the inner element of the cell }</li>
* <li>.gwt-DialogBox .dialogTopCenter { the top center cell, where the caption
* is located }</li>
* <li>.gwt-DialogBox .dialogTopCenterInner { the inner element of the cell }</li>
* <li>.gwt-DialogBox .dialogTopRight { the top right cell }</li>
* <li>.gwt-DialogBox .dialogTopRightInner { the inner element of the cell }</li>
* <li>.gwt-DialogBox .dialogMiddleLeft { the middle left cell }</li>
* <li>.gwt-DialogBox .dialogMiddleLeftInner { the inner element of the cell }</li>
* <li>.gwt-DialogBox .dialogMiddleCenter { the middle center cell, where the
* content is located }</li>
* <li>.gwt-DialogBox .dialogMiddleCenterInner { the inner element of the cell }
* </li>
* <li>.gwt-DialogBox .dialogMiddleRight { the middle right cell }</li>
* <li>.gwt-DialogBox .dialogMiddleRightInner { the inner element of the cell }</li>
* <li>.gwt-DialogBox .dialogBottomLeft { the bottom left cell }</li>
* <li>.gwt-DialogBox .dialogBottomLeftInner { the inner element of the cell }</li>
* <li>.gwt-DialogBox .dialogBottomCenter { the bottom center cell }</li>
* <li>.gwt-DialogBox .dialogBottomCenterInner { the inner element of the cell }
* </li>
* <li>.gwt-DialogBox .dialogBottomRight { the bottom right cell }</li>
* <li>.gwt-DialogBox .dialogBottomRightInner { the inner element of the cell }</li>
* </ul>
* <p>
* <h3>Example</h3> {@example com.google.gwt.examples.DialogBoxExample}
* </p>
*/
@SuppressWarnings("deprecation")
public class ScrolledDialogBox
extends DecoratedPopupPanel
implements HasHTML, HasText, MouseListener
{
/**
* Set of characteristic interfaces supported by the
* {@link ScrolledDialogBox} caption Note that this set might expand over
* time, so implement this interface at your own risk.
*/
public interface Caption
extends HasAllMouseHandlers
{
}
private class CaptionImpl
extends HTML
implements Caption
{
}
// The events are not firing normally because DialogBox has over-riden
// onBrowserEvent with some obtuse logic.
// So we have to create our own tiny system of event handling for the closer button
// in conjunction with List<AntiObtusedCloserHandler>
public interface CloserEventHandler
{
public void onClick(Event event);
public void onMouseOver(Event event);
public void onMouseOut(Event event);
}
/*
*
* @gwt.TypeArgs parameters <java.util.ArrayList<com.google.gwt.user.client.ui.ScrolledDialogBox.CloserEventHandler>>
*/
final public ArrayList<CloserEventHandler> CloserEventHandlers =
new ArrayList<CloserEventHandler>();
private class CloserHandler
implements CloserEventHandler
{
public void onClick(Event event)
{
hide();
}
public void onMouseOver(Event event)
{
DOM.setStyleAttribute(closer.getElement(), "color", "red");
}
public void onMouseOut(Event event)
{
DOM.setStyleAttribute(closer.getElement(), "color", "black");
}
}
private class MouseHandler
implements MouseDownHandler, MouseUpHandler, MouseOutHandler,
MouseOverHandler, MouseMoveHandler
{
public void onMouseDown(
MouseDownEvent event)
{
beginDragging(event);
}
public void onMouseMove(
MouseMoveEvent event)
{
continueDragging(event);
}
public void onMouseOut(
MouseOutEvent event)
{
ScrolledDialogBox.this.onMouseLeave(caption);
}
public void onMouseOver(
MouseOverEvent event)
{
ScrolledDialogBox.this.onMouseEnter(caption);
}
public void onMouseUp(
MouseUpEvent event)
{
endDragging(event);
}
}
/**
* The default style name.
*/
private static final String DEFAULT_STYLENAME = "gwt-DialogBox";
final public HorizontalPanel CaptionPanel = new HorizontalPanel();
final private Button closer = new Button("X");
final private ScrollPanel BodyPanel = new ScrollPanel();
public int Width, Height;
private CaptionImpl caption = new CaptionImpl();
protected boolean dragging;
protected int dragStartX, dragStartY;
protected int windowWidth;
protected int clientLeft;
protected int clientTop;
private HandlerRegistration resizeHandlerRegistration;
/**
* Creates an empty dialog box. It should not be shown until its child
* widget has been added using {@link #add(Widget)}.
*/
public ScrolledDialogBox()
{
this(false);
}
/**
* Creates an empty dialog box specifying its "auto-hide" property. It
* should not be shown until its child widget has been added using
* {@link #add(Widget)}.
*
* @param autoHide
* <code>true</code> if the dialog should be automatically hidden
* when the user clicks outside of it
*/
public ScrolledDialogBox(
boolean autoHide)
{
this(autoHide, true);
}
/**
* Creates an empty dialog box specifying its "auto-hide" property. It
* should not be shown until its child widget has been added using
* {@link #add(Widget)}.
*
* @param autoHide
* <code>true</code> if the dialog should be automatically hidden
* when the user clicks outside of it
* @param modal
* <code>true</code> if keyboard and mouse events for widgets not
* contained by the dialog should be ignored
*/
public ScrolledDialogBox(
boolean autoHide, boolean modal)
{
super(autoHide, modal, "dialog");
// Add the caption to the top row of the decorator panel. We need to
// logically adopt the caption panel so we can catch mouse events.
Element td01 = getCellElement(0, 1);
DOM.appendChild(td01, this.CaptionPanel.getElement());
adopt(this.CaptionPanel);
CaptionPanel.add(this.caption);
CaptionPanel.add(this.closer);
super.setWidget(this.BodyPanel);
this.setWidthPx(200);
this.CloserEventHandlers.add(new CloserHandler());
// closer.addClickHandler(closerHandler);
// closer.addMouseOutHandler(closerHandler);
// closer.addMouseOverHandler(closerHandler);
this.CaptionPanel.setStyleName("Caption");
// Set the style name
setStyleName(DEFAULT_STYLENAME);
windowWidth = Window.getClientWidth();
clientLeft = Document.get().getBodyOffsetLeft();
clientTop = Document.get().getBodyOffsetTop();
MouseHandler mouseHandler = new MouseHandler();
addDomHandler(mouseHandler, MouseDownEvent.getType());
addDomHandler(mouseHandler, MouseUpEvent.getType());
addDomHandler(mouseHandler, MouseMoveEvent.getType());
addDomHandler(mouseHandler, MouseOverEvent.getType());
addDomHandler(mouseHandler, MouseOutEvent.getType());
}
/**
* Provides access to the dialog's caption. This method is final because the
* Caption interface will expand. Therefore it is highly likely that
* subclasses which implemented this method would end up breaking.
*
* @return the logical caption for this dialog box
*/
public final Caption getCaption()
{
return caption;
}
public String getHTML()
{
return caption.getHTML();
}
public String getText()
{
return caption.getText();
}
@Override
public void hide()
{
if (resizeHandlerRegistration != null)
{
resizeHandlerRegistration.removeHandler();
resizeHandlerRegistration = null;
}
super.hide();
}
@Override
public void onBrowserEvent(
Event event)
{
if (isCaptionControlEvent(event))
{
for(CloserEventHandler handler: this.CloserEventHandlers)
{
switch (event.getTypeInt())
{
case Event.ONMOUSEUP:
case Event.ONCLICK:
handler.onClick(event);
break;
case Event.ONMOUSEOVER:
handler.onMouseOver(event);
break;
case Event.ONMOUSEOUT:
handler.onMouseOut(event);
break;
}
}
return;
}
// If we're not yet dragging, only trigger mouse events if the event
// occurs
// in the caption wrapper
switch (event.getTypeInt())
{
case Event.ONMOUSEDOWN:
case Event.ONMOUSEUP:
case Event.ONMOUSEMOVE:
case Event.ONMOUSEOVER:
case Event.ONMOUSEOUT:
if (!dragging)
{
if (!isCaptionEvent(event)) return;
}
}
super.onBrowserEvent(event);
}
/**
* @deprecated Use {@link #beginDragging} and {@link #getCaption} instead
*/
@Deprecated
public void onMouseDown(
Widget sender, int x, int y)
{
dragging = true;
DOM.setCapture(getElement());
dragStartX = x;
dragStartY = y;
// System.out.println("onMouseDown:"+sender);
}
/**
* @deprecated Use {@link Caption#addMouseOverHandler} instead
*/
@Deprecated
public void onMouseEnter(
Widget sender)
{
}
/**
* @deprecated Use {@link Caption#addMouseOutHandler} instead
*/
@Deprecated
public void onMouseLeave(
Widget sender)
{
}
/**
* @deprecated Use {@link #continueDragging} and {@link #getCaption} instead
*/
@Deprecated
public void onMouseMove(
Widget sender, int x, int y)
{
if (dragging)
{
int absX = x + getAbsoluteLeft();
int absY = y + getAbsoluteTop();
// if the mouse is off the screen to the left, right, or top, don't
// move the dialog box. This would let users lose dialog boxes,
// which
// would be bad for modal popups.
if (absX < clientLeft || absX >= windowWidth || absY < clientTop)
{
return;
}
setPopupPosition(absX - dragStartX, absY - dragStartY);
}
}
/**
* @deprecated Use {@link #endDragging} and {@link #getCaption} instead
*/
@Deprecated
public void onMouseUp(
Widget sender, int x, int y)
{
dragging = false;
DOM.releaseCapture(getElement());
// System.out.println("onMouseUp:"+sender);
}
/**
* Sets the html string inside the caption. Use {@link #setWidget(Widget)}
* to set the contents inside the {@link ScrolledDialogBox}.
*
* @param html
* the object's new HTML
*/
public void setHTML(
String html)
{
caption.setHTML(html);
}
/**
* Sets the text inside the caption. Use {@link #setWidget(Widget)} to set
* the contents inside the {@link ScrolledDialogBox}.
*
* @param text
* the object's new text
*/
public void setText(
String text)
{
caption.setText(text);
}
@Override
public void show()
{
if (resizeHandlerRegistration == null)
{
resizeHandlerRegistration =
Window.addResizeHandler(new ResizeHandler()
{
public void onResize(
ResizeEvent event)
{
windowWidth = event.getWidth();
}
});
}
super.show();
}
public void setAlwaysShowScrollBars(
boolean show)
{
this.BodyPanel.setAlwaysShowScrollBars(show);
}
public void setHeightPx(
int hgt)
{
this.BodyPanel.setHeight(hgt + "px");
this.Height = hgt;
}
public void setWidthPx(
int wid)
{
this.BodyPanel.setWidth(wid + "px");
this.initCaptionWidths(wid);
}
public void setSizePx(
int wid, int hgt)
{
this.BodyPanel.setSize(wid + "px", hgt + "px");
this.Height = hgt;
this.initCaptionWidths(wid);
}
@Override
public void setWidget(
Widget widget)
{
this.BodyPanel.setWidget(widget);
}
@Override
public Widget getWidget()
{
return this.BodyPanel.getWidget();
}
private void initCaptionWidths(
int wid)
{
this.Width = wid;
this.CaptionPanel.setWidth(this.Width + "px");
}
/**
* Called on mouse down in the caption area, begins the dragging loop by
* turning on event capture.
*
* @see DOM#setCapture
* @see #continueDragging
* @param event
* the mouse down event that triggered dragging
*/
protected void beginDragging(
MouseDownEvent event)
{
onMouseDown(caption, event.getX(), event.getY());
}
/**
* Called on mouse move in the caption area, continues dragging if it was
* started by {@link #beginDragging}.
*
* @see #beginDragging
* @see #endDragging
* @param event
* the mouse move event that continues dragging
*/
protected void continueDragging(
MouseMoveEvent event)
{
onMouseMove(caption, event.getX(), event.getY());
}
@Override
protected void doAttachChildren()
{
super.doAttachChildren();
// See comment in doDetachChildren for an explanation of this call
caption.onAttach();
}
@Override
protected void doDetachChildren()
{
super.doDetachChildren();
// We need to detach the caption specifically because it is not part of
// the
// iterator of Widgets that the {@link SimplePanel} super class returns.
// This is similar to a {@link ComplexPanel}, but we do not want to
// expose
// the caption widget, as its just an internal implementation.
caption.onDetach();
}
/**
* Called on mouse up in the caption area, ends dragging by ending event
* capture.
*
* @param event
* the mouse up event that ended dragging
* @see DOM#releaseCapture
* @see #beginDragging
* @see #endDragging
*/
protected void endDragging(
MouseUpEvent event)
{
onMouseUp(caption, event.getX(), event.getY());
}
/**
* <b>Affected Elements:</b>
* <ul>
* <li>-caption = text at the top of the {@link ScrolledDialogBox}.</li>
* <li>-content = the container around the content.</li>
* </ul>
*
* @see UIObject#onEnsureDebugId(String)
*/
@Override
protected void onEnsureDebugId(
String baseID)
{
super.onEnsureDebugId(baseID);
caption.ensureDebugId(baseID + "-caption");
ensureDebugId(getCellElement(1, 1), baseID, "content");
}
@Override
protected void onPreviewNativeEvent(
NativePreviewEvent event)
{
// We need to preventDefault() on mouseDown events (outside of the
// DialogBox content) to keep text from being selected when it
// is dragged.
NativeEvent nativeEvent = event.getNativeEvent();
if (!event.isCanceled() && (event.getTypeInt() == Event.ONMOUSEDOWN))
{
// System.out.println("nativeEvent:"+nativeEvent);
if (isCaptionEvent(nativeEvent)) nativeEvent.preventDefault();
}
super.onPreviewNativeEvent(event);
}
protected boolean isCaptionEvent(
NativeEvent event)
{
return isWidgetEvent(event, this.CaptionPanel.getWidget(0));
}
protected boolean isCaptionControlEvent(
NativeEvent event)
{
return isWidgetEvent(event, this.CaptionPanel.getWidget(1));
}
static protected boolean isWidgetEvent(
NativeEvent event, Widget w)
{
EventTarget target = event.getEventTarget();
if (Element.is(target))
{
boolean t = w.getElement().isOrHasChild(Element.as(target));
// if (t)
// System.out.println("isWidgetEvent:"+w+':'+target+':'+t);
return t;
}
return false;
}
}
Show details
Hide details
Change log
r86
by BlessedGeek on Jun 30, 2010
Diff
[No log message]
Go to:
...client/ui/ScrolledDialogBox.java
Project members,
sign in
to write a code review
Older revisions
r82
by BlessedGeek on Jun 30, 2010
Diff
[No log message]
All revisions of this file
File info
Size: 20017 bytes, 646 lines
View raw file
Powered by
Google Project Hosting