Since GWT was released, they make a possible for me to be in Javascript world, using my favorite language Java.
And now, when i need to get something simple, for example the light box effect, i found at internet several wrappers of JavaScript libraries, who does it for me. And ... to use them, i need to add to my project several kilobytes of JavaSript code ... :(
Since i'm trying to avoid this, i did simple example how to do the background effect with GWT without a dependencies from other libraries... Plain GWT ;)
There is a sources snapshot, as well, you can get sources from: gwtFuse
An Altetnative to GWT Java-only AJAX framework. Server side. Very straightforward coding.www.desisoft.com/jaxcent/gwt.htmlProfessional GWT Training In depth hands on lab sessions Demystifying GWTwww.maartenvolders.co
/**
* LightBox dialog provide an example of using 'Background Screen' behind dialogs
*
* @author Viktor Zaprudnev
*
* More information here:
* http://gwtfuse.blogspot.com/
* Source code can be found here:
* http://code.google.com/p/gwtfuse
*
*/
public class LightBoxDialog extends DialogBox {
protected String backgroundScreenHtmlTemplate =
"< div style= ' "
+" background-color: navy; "
+"/*needs to be BELOW popup*//*z-index: 3;*/ "
+" filter: alpha(opacity=20); opacity:0.2;"
+" height: DIV_HEIGHTpx; width: DIV_WIDTHpx; "
+" position: absolute; "
+" top: 0px; left: 0px; "
+"'>
";
protected HTML backgroundScreen ;
@Override
protected void onLoad() {
super.onLoad();
attachBackgroundScreenToRootPanel();
}
private void attachBackgroundScreenToRootPanel() {
if (backgroundScreen == null) {
String html = backgroundScreenHtmlTemplate.replaceAll("DIV_WIDTH", ""+RootPanel.get().getOffsetWidth());
html = html.replaceAll("DIV_HEIGHT", ""+RootPanel.get().getOffsetHeight());
backgroundScreen = new HTML(html);
}
if ( RootPanel.get().getWidgetIndex(backgroundScreen) > 0) {
// background already attached
} else {
backgroundScreen.setVisible( false );
RootPanel.get().add( backgroundScreen );
}
}
/**********************************
* Constructors
**********************************/
public LightBoxDialog() {
super();
}
public LightBoxDialog(boolean autoHide) {
super(autoHide);
}
/**
* accept custom HTML template for the background:
* @param backgroundScreenHTMLTemplate
*/
public LightBoxDialog(String backgroundScreenHTMLTemplate) {
this();
this.backgroundScreenHtmlTemplate = backgroundScreenHTMLTemplate;
}
/**
* accept custom HTML template for the background:
* @param backgroundScreenHTMLTemplate
*/
public LightBoxDialog(String backgroundScreenHTMLTemplate, boolean autoHide) {
this(autoHide);
this.backgroundScreenHtmlTemplate = backgroundScreenHTMLTemplate;
}
/***********************************************************
* Overriden methods, for supporting an background fading
***********************************************************/
@Override
public void show() {
super.show();
backgroundScreen.setVisible( true );
}
@Override
public void hide() {
super.hide();
backgroundScreen.setVisible( false );
}
@Override
public void hide(boolean autoClosed) {
super.hide(autoClosed);
backgroundScreen.setVisible( false );
}
}
Enjoy! This approach can be used not only for a Dialogs, but everywhere you want ;)