|
@@ -40,46 +40,37 @@ |
40 |
40 |
|
* {@example com.google.gwt.examples.GlassPanelExample} |
41 |
41 |
|
* </p> |
42 |
42 |
|
*/ |
43 |
|
- |
public class GlassPanel extends Composite implements EventPreview |
44 |
|
- |
{ |
|
43 |
+ |
public class GlassPanel extends Composite implements EventPreview { |
45 |
44 |
|
/** |
46 |
45 |
|
* A FocusPanel which automatically focuses itself when |
47 |
46 |
|
* attached (in order to blur any currently focused widget) |
48 |
47 |
|
* and then removes itself. |
49 |
48 |
|
*/ |
50 |
|
- |
private static class FocusPanelImpl extends FocusPanel |
51 |
|
- |
{ |
52 |
|
- |
public FocusPanelImpl() |
53 |
|
- |
{ |
54 |
|
- |
addFocusListener( new FocusListener() |
55 |
|
- |
{ |
|
49 |
+ |
private static class FocusPanelImpl extends FocusPanel { |
|
50 |
+ |
public FocusPanelImpl() { |
|
51 |
+ |
addFocusListener( new FocusListener() { |
56 |
52 |
|
|
57 |
53 |
|
@Override |
58 |
|
- |
public void onFocus( Widget sender ) |
59 |
|
- |
{ |
|
54 |
+ |
public void onFocus( Widget sender ) { |
60 |
55 |
|
FocusPanelImpl.this.removeFromParent(); |
61 |
56 |
|
} |
62 |
57 |
|
|
63 |
58 |
|
@Override |
64 |
|
- |
public void onLostFocus( Widget sender ) |
65 |
|
- |
{ |
|
59 |
+ |
public void onLostFocus( Widget sender ) { |
66 |
60 |
|
} |
67 |
61 |
|
} ); |
68 |
62 |
|
} |
69 |
63 |
|
|
70 |
64 |
|
@Override |
71 |
|
- |
protected void onLoad() |
72 |
|
- |
{ |
|
65 |
+ |
protected void onLoad() { |
73 |
66 |
|
super.onLoad(); |
74 |
67 |
|
/** |
75 |
68 |
|
* Removed DeferredCommand if/when GWT issue 1849 is implemented |
76 |
69 |
|
* http://code.google.com/p/google-web-toolkit/issues/detail?id=1849 |
77 |
70 |
|
*/ |
78 |
|
- |
DeferredCommand.addCommand( new Command() |
79 |
|
- |
{ |
|
71 |
+ |
DeferredCommand.addCommand( new Command() { |
80 |
72 |
|
@Override |
81 |
|
- |
public void execute() |
82 |
|
- |
{ |
|
73 |
+ |
public void execute() { |
83 |
74 |
|
setFocus( true ); |
84 |
75 |
|
} |
85 |
76 |
|
} ); |
|
@@ -94,11 +85,9 @@ |
94 |
85 |
|
|
95 |
86 |
|
private WindowResizeListener resizeListener; |
96 |
87 |
|
|
97 |
|
- |
private final Timer timer = new Timer() |
98 |
|
- |
{ |
|
88 |
+ |
private final Timer timer = new Timer() { |
99 |
89 |
|
@Override |
100 |
|
- |
public void run() |
101 |
|
- |
{ |
|
90 |
+ |
public void run() { |
102 |
91 |
|
impl.matchDocumentSize( GlassPanel.this, false ); |
103 |
92 |
|
} |
104 |
93 |
|
}; |
|
@@ -111,8 +100,7 @@ |
111 |
100 |
|
* automatically hidden when the user clicks on it or presses |
112 |
101 |
|
* <code>ESC</code>. |
113 |
102 |
|
*/ |
114 |
|
- |
public GlassPanel( boolean autoHide ) |
115 |
|
- |
{ |
|
103 |
+ |
public GlassPanel( boolean autoHide ) { |
116 |
104 |
|
this.autoHide = autoHide; |
117 |
105 |
|
mySimplePanel = new SimplePanel(); |
118 |
106 |
|
initWidget( mySimplePanel ); |
|
@@ -124,23 +112,17 @@ |
124 |
112 |
|
} |
125 |
113 |
|
|
126 |
114 |
|
@Override |
127 |
|
- |
public boolean onEventPreview( Event event ) |
128 |
|
- |
{ |
|
115 |
+ |
public boolean onEventPreview( Event event ) { |
129 |
116 |
|
int type = DOM.eventGetType( event ); |
130 |
|
- |
switch ( type ) |
131 |
|
- |
{ |
132 |
|
- |
case Event.ONKEYPRESS: |
133 |
|
- |
{ |
134 |
|
- |
if ( DOM.eventGetKeyCode( event ) == KeyboardListener.KEY_ESCAPE ) |
135 |
|
- |
{ |
|
117 |
+ |
switch ( type ) { |
|
118 |
+ |
case Event.ONKEYPRESS: { |
|
119 |
+ |
if ( DOM.eventGetKeyCode( event ) == KeyboardListener.KEY_ESCAPE ) { |
136 |
120 |
|
removeFromParent(); |
137 |
121 |
|
return false; |
138 |
122 |
|
} |
139 |
123 |
|
} |
140 |
|
- |
case Event.ONCLICK: |
141 |
|
- |
{ |
142 |
|
- |
if ( DOM.isOrHasChild( getElement(), DOM.eventGetTarget( event ) ) ) |
143 |
|
- |
{ |
|
124 |
+ |
case Event.ONCLICK: { |
|
125 |
+ |
if ( DOM.isOrHasChild( getElement(), DOM.eventGetTarget( event ) ) ) { |
144 |
126 |
|
removeFromParent(); |
145 |
127 |
|
return false; |
146 |
128 |
|
} |
|
@@ -150,45 +132,35 @@ |
150 |
132 |
|
} |
151 |
133 |
|
|
152 |
134 |
|
@Override |
153 |
|
- |
public void setWidget( Widget widget ) |
154 |
|
- |
{ |
|
135 |
+ |
public void setWidget( Widget widget ) { |
155 |
136 |
|
mySimplePanel.setWidget( widget ); |
156 |
137 |
|
} |
157 |
138 |
|
|
158 |
139 |
|
@Override |
159 |
|
- |
protected void onAttach() |
160 |
|
- |
{ |
|
140 |
+ |
protected void onAttach() { |
161 |
141 |
|
super.onAttach(); |
162 |
142 |
|
AbsolutePanel parent; |
163 |
|
- |
try |
164 |
|
- |
{ |
|
143 |
+ |
try { |
165 |
144 |
|
parent = (AbsolutePanel) getParent(); |
166 |
145 |
|
} |
167 |
|
- |
catch ( RuntimeException e ) |
168 |
|
- |
{ |
|
146 |
+ |
catch ( RuntimeException e ) { |
169 |
147 |
|
throw new IllegalStateException( "Parent widget must be an instance of AbsolutePanel" ); |
170 |
148 |
|
} |
171 |
149 |
|
|
172 |
|
- |
if ( parent == RootPanel.get() ) |
173 |
|
- |
{ |
|
150 |
+ |
if ( parent == RootPanel.get() ) { |
174 |
151 |
|
impl.matchDocumentSize( this, false ); |
175 |
152 |
|
timer.scheduleRepeating( 100 ); |
176 |
|
- |
resizeListener = new WindowResizeListener() |
177 |
|
- |
{ |
|
153 |
+ |
resizeListener = new WindowResizeListener() { |
178 |
154 |
|
@Override |
179 |
|
- |
public void onWindowResized( int width, int height ) |
180 |
|
- |
{ |
|
155 |
+ |
public void onWindowResized( int width, int height ) { |
181 |
156 |
|
impl.matchDocumentSize( GlassPanel.this, true ); |
182 |
157 |
|
} |
183 |
158 |
|
}; |
184 |
159 |
|
Window.addWindowResizeListener( resizeListener ); |
185 |
|
- |
} |
186 |
|
- |
else |
187 |
|
- |
{ |
|
160 |
+ |
} else { |
188 |
161 |
|
impl.matchParentSize( this, parent ); |
189 |
162 |
|
} |
190 |
|
- |
if ( autoHide ) |
191 |
|
- |
{ |
|
163 |
+ |
if ( autoHide ) { |
192 |
164 |
|
DOM.addEventPreview( this ); |
193 |
165 |
|
} |
194 |
166 |
|
|
|
@@ -196,35 +168,30 @@ |
196 |
168 |
|
} |
197 |
169 |
|
|
198 |
170 |
|
@Override |
199 |
|
- |
protected void onDetach() |
200 |
|
- |
{ |
|
171 |
+ |
protected void onDetach() { |
201 |
172 |
|
super.onDetach(); |
202 |
173 |
|
timer.cancel(); |
203 |
|
- |
if ( resizeListener != null ) |
204 |
|
- |
{ |
|
174 |
+ |
if ( resizeListener != null ) { |
205 |
175 |
|
Window.removeWindowResizeListener( resizeListener ); |
206 |
176 |
|
resizeListener = null; |
207 |
177 |
|
} |
208 |
|
- |
if ( autoHide ) |
209 |
|
- |
{ |
|
178 |
+ |
if ( autoHide ) { |
210 |
179 |
|
DOM.removeEventPreview( this ); |
211 |
180 |
|
} |
212 |
181 |
|
} |
213 |
182 |
|
|
214 |
183 |
|
@Override |
215 |
|
- |
protected void onLoad() |
216 |
|
- |
{ |
|
184 |
+ |
protected void onLoad() { |
217 |
185 |
|
super.onLoad(); |
218 |
|
- |
if ( !GWT.isScript() ) |
219 |
|
- |
{ |
|
186 |
+ |
if ( !GWT.isScript() ) { |
220 |
187 |
|
// In Webkit quirks mode table cells refuse to take on |
221 |
188 |
|
// 'display: block', using 'display: table-cell' instead. |
222 |
|
- |
if ( !impl.isCSS1Compat() ) |
223 |
|
- |
{ |
|
189 |
+ |
if ( !impl.isCSS1Compat() ) { |
224 |
190 |
|
String nodeName = getParent().getElement().getNodeName(); |
225 |
|
- |
if ( nodeName.matches( "^(TD|TH)$" ) ) |
226 |
|
- |
{ |
227 |
|
- |
String msg = "SORRY: GlassPanel cannot properly cover a " + nodeName + " element in quirks mode due to CSS restrictions in certain browsers." + " Please consider using standards mode or try using a different type of element."; |
|
191 |
+ |
if ( nodeName.matches( "^(TD|TH)$" ) ) { |
|
192 |
+ |
String msg = |
|
193 |
+ |
"SORRY: GlassPanel cannot properly cover a " + nodeName + " element in quirks mode due to CSS restrictions in certain browsers." + |
|
194 |
+ |
" Please consider using standards mode or try using a different type of element."; |
228 |
195 |
|
GWT.log( msg, new UnsupportedOperationException() ); |
229 |
196 |
|
Window.alert( msg ); |
230 |
197 |
|
assert false : msg; |