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
/
org
/
synthful
/
gwt
/
widgets
/
client
/
ui
/
UnusableScrollableDialogBox.java
‹r75
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
package org.synthful.gwt.widgets.client.ui;
import java.util.ArrayList;
import com.google.gwt.dom.client.EventTarget;
import com.google.gwt.dom.client.NativeEvent;
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.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.ScrollPanel;
import com.google.gwt.user.client.ui.Widget;
/**
* This class is an attempt to patch DialogBox to give it a close
* button at the right corner of the captionTitle.<br>
*
* This class is unusable as explained in comments in the constructor
* below. It is retained as an illustration why we have to use the
* patch rather than subclass DialogBox.
*
* The patch is found as
* com.google.gwt.user.client.ui.ScrolledDialogBox .
*
* It has to be patched rather than over-riden because all the
* essential innards required to give a viable close button are
* either private or protected - as evidenced in the explanation
* in the constructor below.
*
* @author Icecream
*
*/
public class UnusableScrollableDialogBox
extends DialogBox
{
public UnusableScrollableDialogBox()
{
this(false);
}
public UnusableScrollableDialogBox(
boolean autoHide)
{
this(autoHide, true);
}
public UnusableScrollableDialogBox(
boolean autoHide, boolean modal)
{
super(autoHide, modal);
Element td01 = getCellElement(0, 1);
// We should reuse the captionTitle so that getCaption, getText and getHtml
// methods do not need to be rewritten and over-riden.
Widget caption = (Widget)this.getCaption();
// The following fails because removeFromParent requires
// parent's private widget = captionTitle, but captionTitle was adopted not added
// so the parent did not register it as a child widget.
caption.removeFromParent();
// Widget p = caption.getParent();
DOM.removeChild(td01, caption.getElement());
DOM.appendChild(td01, this.CaptionPanel.getElement());
// The following fails because add() function requires prospective child
// widget to have null parent, but earlier parent's failure to acknowledge
// captionTitle as a child aborted the parent removal procedure resulting
// in the child still acknowledging the parent.
CaptionPanel.add(caption);
adopt(this.CaptionPanel);
CaptionPanel.add(this.closer);
super.setWidget(this.BodyPanel);
this.setWidthPx(200);
this.CloserEventHandlers.add(new CloserHandler());
}
public void setAlwaysShowScrollBars(
boolean show)
{
this.BodyPanel.setAlwaysShowScrollBars(show);
}
public void setHeightPx(
int hgt)
{
this.BodyPanel.setWidth(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");
}
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;
}
@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;
}
super.onBrowserEvent(event);
}
// The events are not firing normally because DialogBox has over-ridden
// 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<org.synthful.gwt.widgets.client.ui.ScrollableDialogBox.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");
}
}
final public HorizontalPanel CaptionPanel = new HorizontalPanel();
final private Button closer = new Button("X");
final private ScrollPanel BodyPanel = new ScrollPanel();
public int Width, Height;
}
Show details
Hide details
Change log
r91
by BlessedGeek on Jul 19, 2010
Diff
[No log message]
Go to:
...ient/ui/ScrollableDialogBox.java
...t/widgets/client/ui/UIPopup.java
...gwt/widgets/client/ui/UITab.java
.../client/ui/UITabLayoutPanel.java
...UnusableScrollableDialogBox.java
Project members,
sign in
to write a code review
Older revisions
r75
by BlessedGeek on Apr 8, 2010
Diff
[No log message]
r34
by BlessedGeek on Jul 10, 2009
Diff
[No log message]
All revisions of this file
File info
Size: 6719 bytes, 220 lines
View raw file
Powered by
Google Project Hosting